diff --git a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/shared/authorization/SpaceValidator.java b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/shared/authorization/SpaceValidator.java new file mode 100644 index 0000000000000000000000000000000000000000..218d6ea8daec9a59c08d67d13883f64358bcd494 --- /dev/null +++ b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/shared/authorization/SpaceValidator.java @@ -0,0 +1,63 @@ +/* + * Copyright 2010 ETH Zuerich, CISD + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ch.systemsx.cisd.openbis.plugin.screening.shared.authorization; + +import java.util.Set; + +import ch.systemsx.cisd.openbis.generic.shared.authorization.validator.AbstractValidator; +import ch.systemsx.cisd.openbis.generic.shared.dto.PersonPE; +import ch.systemsx.cisd.openbis.generic.shared.dto.RoleAssignmentPE; +import ch.systemsx.cisd.openbis.generic.shared.dto.SpacePE; + +/** + * A validator of objects which are connected to a space. Note: we assume that we operate on _the + * only_ db instance (the home db)! + * + * @author Tomasz Pylak + */ +abstract class SpaceValidator<T> extends AbstractValidator<T> +{ + abstract protected String getSpace(T value); + + @Override + public boolean doValidation(PersonPE person, T value) + { + final String spaceCode = getSpace(value); + return validateSpace(person, spaceCode); + } + + private boolean validateSpace(PersonPE person, final String spaceCode) + { + final Set<RoleAssignmentPE> roleAssignments = person.getAllPersonRoles(); + for (final RoleAssignmentPE roleAssignment : roleAssignments) + { + if (roleAssignment.getDatabaseInstance() != null) + { + // All roles on the db level allow full read access. + // Note: Here we assume that we operate on _the only_ db instance (the home db)! + return true; + } + final SpacePE group = roleAssignment.getSpace(); + if (group != null && group.getCode().equals(spaceCode)) + { + return true; + } + } + return false; + } + +} diff --git a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/shared/authorization/WellContentValidator.java b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/shared/authorization/WellContentValidator.java index c6e1458a33a65dd20a2bd6e6a8f7ff14a699095a..5956c43da6207aa45c135d5fd40c1cc8579d253d 100644 --- a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/shared/authorization/WellContentValidator.java +++ b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/shared/authorization/WellContentValidator.java @@ -16,12 +16,6 @@ package ch.systemsx.cisd.openbis.plugin.screening.shared.authorization; -import java.util.Set; - -import ch.systemsx.cisd.openbis.generic.shared.authorization.validator.AbstractValidator; -import ch.systemsx.cisd.openbis.generic.shared.dto.SpacePE; -import ch.systemsx.cisd.openbis.generic.shared.dto.PersonPE; -import ch.systemsx.cisd.openbis.generic.shared.dto.RoleAssignmentPE; import ch.systemsx.cisd.openbis.plugin.screening.shared.basic.dto.WellContent; /** @@ -29,29 +23,12 @@ import ch.systemsx.cisd.openbis.plugin.screening.shared.basic.dto.WellContent; * * @author Tomasz Pylak */ -public class WellContentValidator extends AbstractValidator<WellContent> +public class WellContentValidator extends SpaceValidator<WellContent> { - @Override - public boolean doValidation(PersonPE person, WellContent value) + protected String getSpace(WellContent value) { - final String spaceCode = value.getExperiment().getSpaceCode(); - final Set<RoleAssignmentPE> roleAssignments = person.getAllPersonRoles(); - for (final RoleAssignmentPE roleAssignment : roleAssignments) - { - if (roleAssignment.getDatabaseInstance() != null) - { - // All roles on the db level allow full read access. - // Note: Here we assume that we operate on _the only_ db instance (the home db)! - return true; - } - final SpacePE group = roleAssignment.getSpace(); - if (group != null && group.getCode().equals(spaceCode)) - { - return true; - } - } - return false; + return value.getExperiment().getSpaceCode(); } }