diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/server/GenericServer.java b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/server/GenericServer.java index b49b98f3873d0aa0b3472a00182dba7ee615805b..91c933de0d8642cc840501e9aaf4751296d39385 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/server/GenericServer.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/server/GenericServer.java @@ -48,6 +48,22 @@ import ch.systemsx.cisd.openbis.generic.server.dataaccess.IDAOFactory; import ch.systemsx.cisd.openbis.generic.server.plugin.IDataSetTypeSlaveServerPlugin; import ch.systemsx.cisd.openbis.generic.server.plugin.ISampleTypeSlaveServerPlugin; import ch.systemsx.cisd.openbis.generic.shared.ICommonServer; +import ch.systemsx.cisd.openbis.generic.shared.authorization.annotation.AuthorizationGuard; +import ch.systemsx.cisd.openbis.generic.shared.authorization.annotation.Capability; +import ch.systemsx.cisd.openbis.generic.shared.authorization.annotation.RolesAllowed; +import ch.systemsx.cisd.openbis.generic.shared.authorization.predicate.AbstractTechIdPredicate.DataSetTechIdPredicate; +import ch.systemsx.cisd.openbis.generic.shared.authorization.predicate.AbstractTechIdPredicate.ExperimentTechIdPredicate; +import ch.systemsx.cisd.openbis.generic.shared.authorization.predicate.AbstractTechIdPredicate.ProjectTechIdPredicate; +import ch.systemsx.cisd.openbis.generic.shared.authorization.predicate.DataSetUpdatesPredicate; +import ch.systemsx.cisd.openbis.generic.shared.authorization.predicate.ExperimentUpdatesPredicate; +import ch.systemsx.cisd.openbis.generic.shared.authorization.predicate.NewDataSetsWithTypePredicate; +import ch.systemsx.cisd.openbis.generic.shared.authorization.predicate.NewExperimentPredicate; +import ch.systemsx.cisd.openbis.generic.shared.authorization.predicate.NewExperimentsWithTypePredicate; +import ch.systemsx.cisd.openbis.generic.shared.authorization.predicate.NewSamplePredicate; +import ch.systemsx.cisd.openbis.generic.shared.authorization.predicate.NewSamplesWithTypePredicate; +import ch.systemsx.cisd.openbis.generic.shared.authorization.predicate.SampleTechIdPredicate; +import ch.systemsx.cisd.openbis.generic.shared.authorization.predicate.SampleUpdatesPredicate; +import ch.systemsx.cisd.openbis.generic.shared.authorization.predicate.UpdatedExperimentsWithTypePredicate; import ch.systemsx.cisd.openbis.generic.shared.basic.TechId; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.AttachmentWithContent; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Code; @@ -68,6 +84,7 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewExperimentsWithType; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewMaterialsWithTypes; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewSample; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewSamplesWithTypes; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.RoleWithHierarchy; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Sample; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.SampleBatchUpdateDetails; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.SampleParentWithDerived; @@ -172,15 +189,19 @@ public final class GenericServer extends AbstractServer<IGenericServer> implemen } @Override - public final SampleParentWithDerived getSampleInfo(final String sessionToken, - final TechId sampleId) + @RolesAllowed(RoleWithHierarchy.SPACE_OBSERVER) + public SampleParentWithDerived getSampleInfo(final String sessionToken, + @AuthorizationGuard(guardClass = SampleTechIdPredicate.class) + final TechId sampleId) throws UserFailureException { return commonServer.getSampleInfo(sessionToken, sampleId); } @Override - public final void registerSample(final String sessionToken, final NewSample newSample, - final Collection<NewAttachment> attachments) + @RolesAllowed(RoleWithHierarchy.SPACE_USER) + public void registerSample(final String sessionToken, + @AuthorizationGuard(guardClass = NewSamplePredicate.class) + final NewSample newSample, final Collection<NewAttachment> attachments) { assert sessionToken != null : "Unspecified session token."; assert newSample != null : "Unspecified new sample."; @@ -229,14 +250,19 @@ public final class GenericServer extends AbstractServer<IGenericServer> implemen } @Override - public ExternalData getDataSetInfo(final String sessionToken, final TechId datasetId) + @RolesAllowed(RoleWithHierarchy.SPACE_OBSERVER) + public ExternalData getDataSetInfo(String sessionToken, + @AuthorizationGuard(guardClass = DataSetTechIdPredicate.class) + TechId datasetId) { return commonServer.getDataSetInfo(sessionToken, datasetId); } @Override - public AttachmentWithContent getExperimentFileAttachment(final String sessionToken, - final TechId experimentId, final String filename, final Integer versionOrNull) + @RolesAllowed(RoleWithHierarchy.SPACE_OBSERVER) + public AttachmentWithContent getExperimentFileAttachment(String sessionToken, + @AuthorizationGuard(guardClass = ExperimentTechIdPredicate.class) + TechId experimentId, String filename, Integer versionOrNull) throws UserFailureException { final Session session = getSession(sessionToken); @@ -247,7 +273,10 @@ public final class GenericServer extends AbstractServer<IGenericServer> implemen } @Override - public final void registerOrUpdateSamples(final String sessionToken, + @RolesAllowed(RoleWithHierarchy.SPACE_USER) + @Capability("WRITE_SAMPLE") + public void registerOrUpdateSamples(final String sessionToken, + @AuthorizationGuard(guardClass = NewSamplesWithTypePredicate.class) final List<NewSamplesWithTypes> newSamplesWithType) throws UserFailureException { assert sessionToken != null : "Unspecified session token."; @@ -362,7 +391,10 @@ public final class GenericServer extends AbstractServer<IGenericServer> implemen } @Override - public final void registerSamples(final String sessionToken, + @RolesAllowed(RoleWithHierarchy.SPACE_USER) + @Capability("WRITE_SAMPLE") + public void registerSamples(final String sessionToken, + @AuthorizationGuard(guardClass = NewSamplesWithTypePredicate.class) final List<NewSamplesWithTypes> newSamplesWithType) throws UserFailureException { assert sessionToken != null : "Unspecified session token."; @@ -374,8 +406,11 @@ public final class GenericServer extends AbstractServer<IGenericServer> implemen } @Override - public void updateSamples(String sessionToken, List<NewSamplesWithTypes> newSamplesWithType) - throws UserFailureException + @RolesAllowed(RoleWithHierarchy.SPACE_USER) + @Capability("WRITE_SAMPLE") + public void updateSamples(final String sessionToken, + @AuthorizationGuard(guardClass = NewSamplesWithTypePredicate.class) + final List<NewSamplesWithTypes> newSamplesWithType) throws UserFailureException { assert sessionToken != null : "Unspecified session token."; final Session session = getSession(sessionToken); @@ -386,8 +421,11 @@ public final class GenericServer extends AbstractServer<IGenericServer> implemen } @Override - public void updateDataSets(String sessionToken, NewDataSetsWithTypes dataSets) - throws UserFailureException + @RolesAllowed(RoleWithHierarchy.SPACE_POWER_USER) + @Capability("WRITE_DATASET") + public void updateDataSets(final String sessionToken, + @AuthorizationGuard(guardClass = NewDataSetsWithTypePredicate.class) + final NewDataSetsWithTypes dataSets) throws UserFailureException { assert sessionToken != null : "Unspecified session token."; final Session session = getSession(sessionToken); @@ -527,8 +565,12 @@ public final class GenericServer extends AbstractServer<IGenericServer> implemen } @Override - public void registerExperiment(String sessionToken, NewExperiment newExperiment, - final Collection<NewAttachment> attachments) + @RolesAllowed(RoleWithHierarchy.SPACE_USER) + @Capability("WRITE_EXPERIMENT_SAMPLE") + public void registerExperiment(String sessionToken, + @AuthorizationGuard(guardClass = NewExperimentPredicate.class) + final NewExperiment newExperiment, final Collection<NewAttachment> attachments) + throws UserFailureException { assert sessionToken != null : "Unspecified session token."; assert newExperiment != null : "Unspecified new experiment."; @@ -585,8 +627,10 @@ public final class GenericServer extends AbstractServer<IGenericServer> implemen } @Override - public void registerMaterials(String sessionToken, - final List<NewMaterialsWithTypes> newMaterials) + @RolesAllowed(RoleWithHierarchy.INSTANCE_ADMIN) + @Capability("WRITE_MATERIAL") + public void registerMaterials(String sessionToken, List<NewMaterialsWithTypes> newMaterials) + throws UserFailureException { assert sessionToken != null : "Unspecified session token."; Session session = getSession(sessionToken); @@ -605,8 +649,10 @@ public final class GenericServer extends AbstractServer<IGenericServer> implemen } @Override - public int updateMaterials(String sessionToken, final List<NewMaterialsWithTypes> newMaterials, - final boolean ignoreUnregisteredMaterials) throws UserFailureException + @RolesAllowed(RoleWithHierarchy.INSTANCE_ADMIN) + @Capability("WRITE_MATERIAL") + public int updateMaterials(String sessionToken, List<NewMaterialsWithTypes> newMaterials, + boolean ignoreUnregisteredMaterials) throws UserFailureException { assert sessionToken != null : "Unspecified session token."; Session session = getSession(sessionToken); @@ -622,8 +668,10 @@ public final class GenericServer extends AbstractServer<IGenericServer> implemen } @Override - public AttachmentWithContent getProjectFileAttachment(String sessionToken, TechId projectId, - String fileName, Integer versionOrNull) + @RolesAllowed(RoleWithHierarchy.SPACE_OBSERVER) + public AttachmentWithContent getProjectFileAttachment(String sessionToken, + @AuthorizationGuard(guardClass = ProjectTechIdPredicate.class) + TechId projectId, String fileName, Integer versionOrNull) { final Session session = getSession(sessionToken); final IProjectBO bo = businessObjectFactory.createProjectBO(session); @@ -633,8 +681,10 @@ public final class GenericServer extends AbstractServer<IGenericServer> implemen } @Override - public AttachmentWithContent getSampleFileAttachment(String sessionToken, TechId sampleId, - String fileName, Integer versionOrNull) + @RolesAllowed(RoleWithHierarchy.SPACE_OBSERVER) + public AttachmentWithContent getSampleFileAttachment(String sessionToken, + @AuthorizationGuard(guardClass = SampleTechIdPredicate.class) + TechId sampleId, String fileName, Integer versionOrNull) { final Session session = getSession(sessionToken); final ISampleBO bo = businessObjectFactory.createSampleBO(session); @@ -644,6 +694,7 @@ public final class GenericServer extends AbstractServer<IGenericServer> implemen } @Override + @RolesAllowed(RoleWithHierarchy.SPACE_OBSERVER) public List<String> generateCodes(String sessionToken, String prefix, ch.systemsx.cisd.openbis.generic.shared.basic.dto.EntityKind entityKind, int number) { @@ -658,7 +709,11 @@ public final class GenericServer extends AbstractServer<IGenericServer> implemen } @Override - public ExperimentUpdateResult updateExperiment(String sessionToken, ExperimentUpdatesDTO updates) + @RolesAllowed(RoleWithHierarchy.SPACE_USER) + @Capability("WRITE_EXPERIMENT_SAMPLE") + public ExperimentUpdateResult updateExperiment(String sessionToken, + @AuthorizationGuard(guardClass = ExperimentUpdatesPredicate.class) + ExperimentUpdatesDTO updates) { final Session session = getSession(sessionToken); if (updates.isRegisterSamples()) @@ -676,6 +731,8 @@ public final class GenericServer extends AbstractServer<IGenericServer> implemen } @Override + @RolesAllowed(RoleWithHierarchy.INSTANCE_ADMIN) + @Capability("WRITE_MATERIAL") public Date updateMaterial(String sessionToken, TechId materialId, List<IEntityProperty> properties, Date version) { @@ -683,19 +740,29 @@ public final class GenericServer extends AbstractServer<IGenericServer> implemen } @Override - public SampleUpdateResult updateSample(String sessionToken, SampleUpdatesDTO updates) + @RolesAllowed(RoleWithHierarchy.SPACE_USER) + public SampleUpdateResult updateSample(String sessionToken, + @AuthorizationGuard(guardClass = SampleUpdatesPredicate.class) + SampleUpdatesDTO updates) { return commonServer.updateSample(sessionToken, updates); } @Override - public DataSetUpdateResult updateDataSet(String sessionToken, DataSetUpdatesDTO updates) + @RolesAllowed(RoleWithHierarchy.SPACE_POWER_USER) + @Capability("WRITE_DATASET") + public DataSetUpdateResult updateDataSet(String sessionToken, + @AuthorizationGuard(guardClass = DataSetUpdatesPredicate.class) + DataSetUpdatesDTO updates) { return commonServer.updateDataSet(sessionToken, updates); } @Override + @RolesAllowed(RoleWithHierarchy.INSTANCE_ADMIN) + @Capability("WRITE_MATERIAL") public void registerOrUpdateMaterials(String sessionToken, List<NewMaterialsWithTypes> materials) + throws UserFailureException { assert sessionToken != null : "Unspecified session token."; final Session session = getSession(sessionToken); @@ -715,8 +782,11 @@ public final class GenericServer extends AbstractServer<IGenericServer> implemen } @Override - public void registerExperiments(String sessionToken, NewExperimentsWithType experiments) - throws UserFailureException + @RolesAllowed(RoleWithHierarchy.SPACE_USER) + @Capability("WRITE_EXPERIMENT_SAMPLE") + public void registerExperiments(String sessionToken, + @AuthorizationGuard(guardClass = NewExperimentsWithTypePredicate.class) + final NewExperimentsWithType experiments) throws UserFailureException { assert experiments != null : "Unspecified experiments."; assert sessionToken != null : "Unspecified session token."; @@ -751,8 +821,11 @@ public final class GenericServer extends AbstractServer<IGenericServer> implemen * collection of {@link UpdatedBasicExperiment} objects. */ @Override - public void updateExperiments(String sessionToken, UpdatedExperimentsWithType experiments) - throws UserFailureException + @RolesAllowed(RoleWithHierarchy.SPACE_USER) + @Capability("WRITE_EXPERIMENT_SAMPLE") + public void updateExperiments(String sessionToken, + @AuthorizationGuard(guardClass = UpdatedExperimentsWithTypePredicate.class) + final UpdatedExperimentsWithType experiments) throws UserFailureException { assert experiments != null : "Unspecified experiments."; assert sessionToken != null : "Unspecified session token."; @@ -839,9 +912,11 @@ public final class GenericServer extends AbstractServer<IGenericServer> implemen } @Override + @RolesAllowed(RoleWithHierarchy.INSTANCE_ADMIN) + @Capability("WRITE_EXPERIMENT_SAMPLE_MATERIAL") public void registerOrUpdateSamplesAndMaterials(final String sessionToken, final List<NewSamplesWithTypes> newSamplesWithType, - final List<NewMaterialsWithTypes> newMaterialsWithType) throws UserFailureException + List<NewMaterialsWithTypes> newMaterialsWithType) throws UserFailureException { EntityExistenceChecker entityExistenceChecker = new EntityExistenceChecker(getDAOFactory()); entityExistenceChecker.checkNewMaterials(newMaterialsWithType); @@ -851,6 +926,7 @@ public final class GenericServer extends AbstractServer<IGenericServer> implemen } @Override + @RolesAllowed(RoleWithHierarchy.INSTANCE_ADMIN) public void registerOrUpdateSamplesAndMaterialsAsync(final String sessionToken, final List<NewSamplesWithTypes> newSamplesWithType, final List<NewMaterialsWithTypes> newMaterialsWithType, String userEmail) diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/shared/IGenericServer.java b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/shared/IGenericServer.java index e2074fb2e86f8a52a5d3f09e0a4e9faa32a60307..8ffa484c91c8dca7e6ef69ed72bb8cf0ae4ae969 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/shared/IGenericServer.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/plugin/generic/shared/IGenericServer.java @@ -26,22 +26,6 @@ import ch.systemsx.cisd.common.exceptions.UserFailureException; import ch.systemsx.cisd.openbis.generic.shared.DatabaseCreateOrDeleteModification; import ch.systemsx.cisd.openbis.generic.shared.DatabaseUpdateModification; import ch.systemsx.cisd.openbis.generic.shared.IServer; -import ch.systemsx.cisd.openbis.generic.shared.authorization.annotation.AuthorizationGuard; -import ch.systemsx.cisd.openbis.generic.shared.authorization.annotation.Capability; -import ch.systemsx.cisd.openbis.generic.shared.authorization.annotation.RolesAllowed; -import ch.systemsx.cisd.openbis.generic.shared.authorization.predicate.AbstractTechIdPredicate.DataSetTechIdPredicate; -import ch.systemsx.cisd.openbis.generic.shared.authorization.predicate.AbstractTechIdPredicate.ExperimentTechIdPredicate; -import ch.systemsx.cisd.openbis.generic.shared.authorization.predicate.AbstractTechIdPredicate.ProjectTechIdPredicate; -import ch.systemsx.cisd.openbis.generic.shared.authorization.predicate.DataSetUpdatesPredicate; -import ch.systemsx.cisd.openbis.generic.shared.authorization.predicate.ExperimentUpdatesPredicate; -import ch.systemsx.cisd.openbis.generic.shared.authorization.predicate.NewDataSetsWithTypePredicate; -import ch.systemsx.cisd.openbis.generic.shared.authorization.predicate.NewExperimentPredicate; -import ch.systemsx.cisd.openbis.generic.shared.authorization.predicate.NewExperimentsWithTypePredicate; -import ch.systemsx.cisd.openbis.generic.shared.authorization.predicate.NewSamplePredicate; -import ch.systemsx.cisd.openbis.generic.shared.authorization.predicate.NewSamplesWithTypePredicate; -import ch.systemsx.cisd.openbis.generic.shared.authorization.predicate.SampleTechIdPredicate; -import ch.systemsx.cisd.openbis.generic.shared.authorization.predicate.SampleUpdatesPredicate; -import ch.systemsx.cisd.openbis.generic.shared.authorization.predicate.UpdatedExperimentsWithTypePredicate; import ch.systemsx.cisd.openbis.generic.shared.basic.TechId; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.AttachmentWithContent; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataSetUpdateResult; @@ -57,7 +41,6 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewExperimentsWithType; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewMaterialsWithTypes; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewSample; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewSamplesWithTypes; -import ch.systemsx.cisd.openbis.generic.shared.basic.dto.RoleWithHierarchy; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Sample; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.SampleParentWithDerived; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.SampleUpdateResult; @@ -87,37 +70,28 @@ public interface IGenericServer extends IServer * uniquely identified by given <var>sampleId</var> does not exist. */ @Transactional(readOnly = true) - @RolesAllowed(RoleWithHierarchy.SPACE_OBSERVER) - public SampleParentWithDerived getSampleInfo(final String sessionToken, - @AuthorizationGuard(guardClass = SampleTechIdPredicate.class) - final TechId sampleId) throws UserFailureException; + public SampleParentWithDerived getSampleInfo(final String sessionToken, final TechId sampleId) + throws UserFailureException; /** * Registers a new sample. */ @Transactional - @RolesAllowed(RoleWithHierarchy.SPACE_USER) @DatabaseCreateOrDeleteModification(value = ObjectKind.SAMPLE) - public void registerSample(final String sessionToken, - @AuthorizationGuard(guardClass = NewSamplePredicate.class) - final NewSample newSample, final Collection<NewAttachment> attachments); + public void registerSample(final String sessionToken, final NewSample newSample, + final Collection<NewAttachment> attachments); /** * For given {@link TechId} returns the corresponding {@link ExternalData}. */ @Transactional(readOnly = true) - @RolesAllowed(RoleWithHierarchy.SPACE_OBSERVER) - public ExternalData getDataSetInfo(String sessionToken, - @AuthorizationGuard(guardClass = DataSetTechIdPredicate.class) - TechId datasetId); + public ExternalData getDataSetInfo(String sessionToken, TechId datasetId); /** * Returns attachment described by given experiment identifier, filename and version. */ @Transactional - @RolesAllowed(RoleWithHierarchy.SPACE_OBSERVER) public AttachmentWithContent getExperimentFileAttachment(String sessionToken, - @AuthorizationGuard(guardClass = ExperimentTechIdPredicate.class) TechId experimentId, String filename, Integer versionOrNull) throws UserFailureException; @@ -125,32 +99,24 @@ public interface IGenericServer extends IServer * Registers samples of different types in batches. */ @Transactional - @RolesAllowed(RoleWithHierarchy.SPACE_USER) @DatabaseCreateOrDeleteModification(value = ObjectKind.SAMPLE) - @Capability("WRITE_SAMPLE") public void registerSamples(final String sessionToken, - @AuthorizationGuard(guardClass = NewSamplesWithTypePredicate.class) final List<NewSamplesWithTypes> newSamplesWithType) throws UserFailureException; /** * Registers or updates samples of different types in batches. */ @Transactional - @RolesAllowed(RoleWithHierarchy.SPACE_USER) @DatabaseCreateOrDeleteModification(value = ObjectKind.SAMPLE) - @Capability("WRITE_SAMPLE") public void registerOrUpdateSamples(final String sessionToken, - @AuthorizationGuard(guardClass = NewSamplesWithTypePredicate.class) final List<NewSamplesWithTypes> newSamplesWithType) throws UserFailureException; /** * Registers or updates samples and materials of different types in batches. */ @Transactional - @RolesAllowed(RoleWithHierarchy.INSTANCE_ADMIN) @DatabaseCreateOrDeleteModification(value = { ObjectKind.SAMPLE, ObjectKind.MATERIAL }) - @Capability("WRITE_EXPERIMENT_SAMPLE_MATERIAL") public void registerOrUpdateSamplesAndMaterials(final String sessionToken, final List<NewSamplesWithTypes> newSamplesWithType, List<NewMaterialsWithTypes> newMaterialsWithType) throws UserFailureException; @@ -159,7 +125,6 @@ public interface IGenericServer extends IServer * Asynchronously registers or updates samples and materials of different types in batches. */ @Transactional - @RolesAllowed(RoleWithHierarchy.INSTANCE_ADMIN) @DatabaseCreateOrDeleteModification(value = { ObjectKind.SAMPLE, ObjectKind.MATERIAL }) public void registerOrUpdateSamplesAndMaterialsAsync(final String sessionToken, @@ -171,56 +136,41 @@ public interface IGenericServer extends IServer * Updates samples of different types in batches. */ @Transactional - @RolesAllowed(RoleWithHierarchy.SPACE_USER) @DatabaseUpdateModification(value = ObjectKind.SAMPLE) - @Capability("WRITE_SAMPLE") public void updateSamples(final String sessionToken, - @AuthorizationGuard(guardClass = NewSamplesWithTypePredicate.class) final List<NewSamplesWithTypes> newSamplesWithType) throws UserFailureException; /** * Registers experiment. At the same time samples may be registered or updated. */ @Transactional - @RolesAllowed(RoleWithHierarchy.SPACE_USER) @DatabaseCreateOrDeleteModification(value = { ObjectKind.EXPERIMENT, ObjectKind.SAMPLE }) @DatabaseUpdateModification(value = ObjectKind.SAMPLE) - @Capability("WRITE_EXPERIMENT_SAMPLE") - public void registerExperiment(String sessionToken, - @AuthorizationGuard(guardClass = NewExperimentPredicate.class) - final NewExperiment experiment, final Collection<NewAttachment> attachments) - throws UserFailureException; + public void registerExperiment(String sessionToken, final NewExperiment experiment, + final Collection<NewAttachment> attachments) throws UserFailureException; /** * Registers experiments in batch. */ @Transactional - @RolesAllowed(RoleWithHierarchy.SPACE_USER) @DatabaseCreateOrDeleteModification(value = ObjectKind.EXPERIMENT) - @Capability("WRITE_EXPERIMENT_SAMPLE") - public void registerExperiments(String sessionToken, - @AuthorizationGuard(guardClass = NewExperimentsWithTypePredicate.class) - final NewExperimentsWithType experiments) throws UserFailureException; + public void registerExperiments(String sessionToken, final NewExperimentsWithType experiments) + throws UserFailureException; /** * Update experiments in batch. */ @Transactional - @RolesAllowed(RoleWithHierarchy.SPACE_USER) @DatabaseUpdateModification(value = ObjectKind.EXPERIMENT) - @Capability("WRITE_EXPERIMENT_SAMPLE") - public void updateExperiments(String sessionToken, - @AuthorizationGuard(guardClass = UpdatedExperimentsWithTypePredicate.class) - final UpdatedExperimentsWithType experiments) throws UserFailureException; + public void updateExperiments(String sessionToken, final UpdatedExperimentsWithType experiments) + throws UserFailureException; /** * Registers materials in batch. */ @Transactional - @RolesAllowed(RoleWithHierarchy.INSTANCE_ADMIN) @DatabaseCreateOrDeleteModification(value = ObjectKind.MATERIAL) - @Capability("WRITE_MATERIAL") public void registerMaterials(String sessionToken, List<NewMaterialsWithTypes> newMaterials) throws UserFailureException; @@ -230,9 +180,7 @@ public interface IGenericServer extends IServer * @return number of actually updated materials */ @Transactional - @RolesAllowed(RoleWithHierarchy.INSTANCE_ADMIN) @DatabaseCreateOrDeleteModification(value = ObjectKind.MATERIAL) - @Capability("WRITE_MATERIAL") public int updateMaterials(String sessionToken, List<NewMaterialsWithTypes> newMaterials, boolean ignoreUnregisteredMaterials) throws UserFailureException; @@ -241,9 +189,7 @@ public interface IGenericServer extends IServer * are not mentioned stay unchanged). */ @Transactional - @RolesAllowed(RoleWithHierarchy.INSTANCE_ADMIN) @DatabaseCreateOrDeleteModification(value = ObjectKind.MATERIAL) - @Capability("WRITE_MATERIAL") public void registerOrUpdateMaterials(String sessionToken, List<NewMaterialsWithTypes> materials) throws UserFailureException; @@ -251,25 +197,20 @@ public interface IGenericServer extends IServer * Returns attachment described by given sample identifier, filename and version. */ @Transactional - @RolesAllowed(RoleWithHierarchy.SPACE_OBSERVER) - public AttachmentWithContent getSampleFileAttachment(String sessionToken, - @AuthorizationGuard(guardClass = SampleTechIdPredicate.class) - TechId sampleId, String fileName, Integer versionOrNull); + public AttachmentWithContent getSampleFileAttachment(String sessionToken, TechId sampleId, + String fileName, Integer versionOrNull); /** * Returns attachment described by given project identifier, filename and version. */ @Transactional - @RolesAllowed(RoleWithHierarchy.SPACE_OBSERVER) - public AttachmentWithContent getProjectFileAttachment(String sessionToken, - @AuthorizationGuard(guardClass = ProjectTechIdPredicate.class) - TechId projectId, String fileName, Integer versionOrNull); + public AttachmentWithContent getProjectFileAttachment(String sessionToken, TechId projectId, + String fileName, Integer versionOrNull); /** * Returns a list of unique codes. */ @Transactional - @RolesAllowed(RoleWithHierarchy.SPACE_OBSERVER) public List<String> generateCodes(String sessionToken, String prefix, EntityKind entityKind, int number); @@ -277,21 +218,15 @@ public interface IGenericServer extends IServer * Saves changed experiment. */ @Transactional - @RolesAllowed(RoleWithHierarchy.SPACE_USER) @DatabaseUpdateModification(value = { ObjectKind.EXPERIMENT, ObjectKind.SAMPLE }) - @Capability("WRITE_EXPERIMENT_SAMPLE") - public ExperimentUpdateResult updateExperiment(String sessionToken, - @AuthorizationGuard(guardClass = ExperimentUpdatesPredicate.class) - ExperimentUpdatesDTO updates); + public ExperimentUpdateResult updateExperiment(String sessionToken, ExperimentUpdatesDTO updates); /** * Saves changed material. */ @Transactional - @RolesAllowed(RoleWithHierarchy.INSTANCE_ADMIN) @DatabaseUpdateModification(value = ObjectKind.MATERIAL) - @Capability("WRITE_MATERIAL") public Date updateMaterial(String sessionToken, TechId materialId, List<IEntityProperty> properties, Date version); @@ -299,32 +234,22 @@ public interface IGenericServer extends IServer * Saves changed sample. */ @Transactional - @RolesAllowed(RoleWithHierarchy.SPACE_USER) @DatabaseUpdateModification(value = ObjectKind.SAMPLE) - public SampleUpdateResult updateSample(String sessionToken, - @AuthorizationGuard(guardClass = SampleUpdatesPredicate.class) - SampleUpdatesDTO updates); + public SampleUpdateResult updateSample(String sessionToken, SampleUpdatesDTO updates); /** * Saves changed data set. */ @Transactional - @RolesAllowed(RoleWithHierarchy.SPACE_POWER_USER) @DatabaseUpdateModification(value = ObjectKind.DATA_SET) - @Capability("WRITE_DATASET") - public DataSetUpdateResult updateDataSet(String sessionToken, - @AuthorizationGuard(guardClass = DataSetUpdatesPredicate.class) - DataSetUpdatesDTO updates); + public DataSetUpdateResult updateDataSet(String sessionToken, DataSetUpdatesDTO updates); /** * Updates data sets of different types in batches. */ @Transactional - @RolesAllowed(RoleWithHierarchy.SPACE_POWER_USER) @DatabaseUpdateModification(value = ObjectKind.DATA_SET) - @Capability("WRITE_DATASET") - public void updateDataSets(final String sessionToken, - @AuthorizationGuard(guardClass = NewDataSetsWithTypePredicate.class) - final NewDataSetsWithTypes newSamplesWithType) throws UserFailureException; + public void updateDataSets(final String sessionToken, final NewDataSetsWithTypes dataSets) + throws UserFailureException; } diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/ServerInterfaceRegressionTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/ServerInterfaceRegressionTest.java similarity index 81% rename from openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/ServerInterfaceRegressionTest.java rename to openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/ServerInterfaceRegressionTest.java index 141ca7d11c8a94eb65b77d4b9d493c310a649d94..b924e1b485c16b11307b1c7c64648f8a69fe03de 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/ServerInterfaceRegressionTest.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/ServerInterfaceRegressionTest.java @@ -14,12 +14,13 @@ * limitations under the License. */ -package ch.systemsx.cisd.openbis.generic.shared; +package ch.systemsx.cisd.openbis.generic.server; import org.testng.annotations.Test; -import ch.systemsx.cisd.openbis.generic.server.CommonServer; -import ch.systemsx.cisd.openbis.generic.server.ETLService; +import ch.systemsx.cisd.openbis.generic.shared.ICommonServer; +import ch.systemsx.cisd.openbis.generic.shared.IETLLIMSService; +import ch.systemsx.cisd.openbis.generic.shared.RegressionTestCase; /** * @author Franz-Josef Elmer diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/plugin/generic/shared/ServerInterfaceRegressionTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/plugin/generic/server/ServerInterfaceRegressionTest.java similarity index 80% rename from openbis/sourceTest/java/ch/systemsx/cisd/openbis/plugin/generic/shared/ServerInterfaceRegressionTest.java rename to openbis/sourceTest/java/ch/systemsx/cisd/openbis/plugin/generic/server/ServerInterfaceRegressionTest.java index fa1b29caf25739d2052210d1f145e43fbb860223..57bc3d06688f9286ae81a9a09ed0bda417e4c83a 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/plugin/generic/shared/ServerInterfaceRegressionTest.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/plugin/generic/server/ServerInterfaceRegressionTest.java @@ -14,11 +14,12 @@ * limitations under the License. */ -package ch.systemsx.cisd.openbis.plugin.generic.shared; +package ch.systemsx.cisd.openbis.plugin.generic.server; import org.testng.annotations.Test; import ch.systemsx.cisd.openbis.generic.shared.RegressionTestCase; +import ch.systemsx.cisd.openbis.plugin.generic.shared.IGenericServer; /** * @author Franz-Josef Elmer @@ -28,6 +29,6 @@ public class ServerInterfaceRegressionTest extends RegressionTestCase @Test public void testIGenericServer() { - assertMandatoryMethodAnnotations(IGenericServer.class); + assertMandatoryMethodAnnotations(IGenericServer.class, GenericServer.class); } } diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/authorization/GenericServerAuthorizationTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/authorization/GenericServerAuthorizationTest.java new file mode 100644 index 0000000000000000000000000000000000000000..718ac25771d4c5bf0293995575ace728478048b1 --- /dev/null +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/authorization/GenericServerAuthorizationTest.java @@ -0,0 +1,51 @@ +/* + * Copyright 2012 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.systemtest.authorization; + +import java.util.Collections; + +import org.testng.annotations.Test; + +import ch.systemsx.cisd.common.exceptions.AuthorizationFailureException; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewAttachment; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewSample; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.RoleWithHierarchy; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.SampleType; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Space; +import ch.systemsx.cisd.openbis.systemtest.base.BaseTest; + +/** + * @author Franz-Josef Elmer + */ +public class GenericServerAuthorizationTest extends BaseTest +{ + @Test(expectedExceptions = AuthorizationFailureException.class) + public void testRegisterSampleInASpaceWithNoAccessRight() + { + Space space = create(aSpace()); + Space anotherSpace = create(aSpace()); + SampleType sampleType = create(aSample()).getSampleType(); + String sessionToken = + create(aSession().withSpaceRole(RoleWithHierarchy.SPACE_POWER_USER, space)); + NewSample sample = new NewSample(); + sample.setIdentifier(anotherSpace.getIdentifier() + "/SAMPLE-1"); + sample.setSampleType(sampleType); + + genericServer.registerSample(sessionToken, sample, Collections.<NewAttachment> emptySet()); + + } +} diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/base/builder/ExperimentBuilder.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/base/builder/ExperimentBuilder.java index 1e2eac0e2e09015b0e6b321ae5131647d6bf210f..b9ecb827962509378b26ae0c19ca5dce82f6a025 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/base/builder/ExperimentBuilder.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/base/builder/ExperimentBuilder.java @@ -18,7 +18,6 @@ package ch.systemsx.cisd.openbis.systemtest.base.builder; import java.util.ArrayList; import java.util.List; -import java.util.UUID; import ch.systemsx.cisd.openbis.generic.server.ICommonServerForInternalUse; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Experiment; @@ -35,6 +34,8 @@ import ch.systemsx.cisd.openbis.plugin.generic.shared.IGenericServer; public class ExperimentBuilder extends Builder<Experiment> { + private static int number; + private String code; private Project project; @@ -51,7 +52,7 @@ public class ExperimentBuilder extends Builder<Experiment> this.session = systemSession; this.samples = new String[0]; this.newSamples = null; - this.code = UUID.randomUUID().toString(); + this.code = "E" + number++; } @SuppressWarnings("hiding") @@ -82,7 +83,7 @@ public class ExperimentBuilder extends Builder<Experiment> public Experiment create() { - String experimentTypeCode = UUID.randomUUID().toString(); + String experimentTypeCode = "ET" + number++; ExperimentType experimentType = new ExperimentType(); experimentType.setCode(experimentTypeCode); experimentType.setDatabaseInstance(this.project.getSpace().getInstance()); diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/base/builder/ProjectBuilder.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/base/builder/ProjectBuilder.java index dd47fc5dc5877ad83fea82a3bd4a1ab480525758..96c3ed8665da9ba19ccaa650e6a5547d517d819b 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/base/builder/ProjectBuilder.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/base/builder/ProjectBuilder.java @@ -17,7 +17,6 @@ package ch.systemsx.cisd.openbis.systemtest.base.builder; import java.util.ArrayList; -import java.util.UUID; import ch.systemsx.cisd.openbis.generic.server.ICommonServerForInternalUse; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.NewAttachment; @@ -28,6 +27,8 @@ import ch.systemsx.cisd.openbis.plugin.generic.shared.IGenericServer; public class ProjectBuilder extends Builder<Project> { + private static int number; + private Space space; private String code; @@ -35,7 +36,7 @@ public class ProjectBuilder extends Builder<Project> public ProjectBuilder(ICommonServerForInternalUse commonServer, IGenericServer genericServer) { super(commonServer, genericServer); - this.code = UUID.randomUUID().toString(); + this.code = "P" + number++; } @SuppressWarnings("hiding") @@ -56,8 +57,7 @@ public class ProjectBuilder extends Builder<Project> public Project create() { ProjectIdentifier projectId = - new ProjectIdentifier(space.getInstance().getCode(), space.getCode(), - this.code); + new ProjectIdentifier(space.getInstance().getCode(), space.getCode(), this.code); commonServer.registerProject(systemSession, projectId, "description", "system", new ArrayList<NewAttachment>()); diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/base/builder/SampleBuilder.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/base/builder/SampleBuilder.java index 4fce0c8773b6cdee3442dab53c6485dccac4f47e..0dd3d149f31d10fed15c7afced4d4014d6b5638c 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/base/builder/SampleBuilder.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/base/builder/SampleBuilder.java @@ -18,7 +18,6 @@ package ch.systemsx.cisd.openbis.systemtest.base.builder; import java.util.ArrayList; import java.util.List; -import java.util.UUID; import ch.systemsx.cisd.openbis.generic.server.ICommonServerForInternalUse; import ch.systemsx.cisd.openbis.generic.shared.basic.IEntityInformationHolderWithPermId; @@ -37,6 +36,8 @@ import ch.systemsx.cisd.openbis.plugin.generic.shared.IGenericServer; public class SampleBuilder extends Builder<Sample> { + private static int number; + private Experiment experiment; private Space space; @@ -52,7 +53,7 @@ public class SampleBuilder extends Builder<Sample> super(commonServer, genericServer); this.parents = new ArrayList<Sample>(); this.container = null; - this.id = UUID.randomUUID().toString(); + this.id = "S" + number++; } @SuppressWarnings("hiding") @@ -100,7 +101,7 @@ public class SampleBuilder extends Builder<Sample> { SampleType sampleType = new SampleType(); - sampleType.setCode(UUID.randomUUID().toString()); + sampleType.setCode("ST" + number++); sampleType.setContainerHierarchyDepth(0); if (this.experiment != null) @@ -120,12 +121,12 @@ public class SampleBuilder extends Builder<Sample> String identifier; if (this.experiment != null) { - identifier = "/" + this.experiment.getProject().getSpace().getCode() + "/" - + this.id.toUpperCase(); + identifier = + "/" + this.experiment.getProject().getSpace().getCode() + "/" + + this.id.toUpperCase(); } else if (this.space != null) { - identifier = "/" + this.space.getCode() + "/" - + this.id.toUpperCase(); + identifier = "/" + this.space.getCode() + "/" + this.id.toUpperCase(); } else { identifier = "/" + this.id.toUpperCase(); diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/base/builder/SessionBuilder.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/base/builder/SessionBuilder.java index 3d670c0b609eabf7fe53b5fe268aa41866c767ec..2f050bf6485b36e019efcf758a8584ccb3144316 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/base/builder/SessionBuilder.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/base/builder/SessionBuilder.java @@ -18,7 +18,6 @@ package ch.systemsx.cisd.openbis.systemtest.base.builder; import java.util.ArrayList; import java.util.List; -import java.util.UUID; import ch.systemsx.cisd.openbis.generic.server.ICommonServerForInternalUse; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Grantee; @@ -30,6 +29,7 @@ import ch.systemsx.cisd.openbis.plugin.generic.shared.IGenericServer; public class SessionBuilder extends Builder<String> { + private static int number; private String userName; @@ -40,7 +40,7 @@ public class SessionBuilder extends Builder<String> public SessionBuilder(ICommonServerForInternalUse commonServer, IGenericServer genericServer) { super(commonServer, genericServer); - this.userName = UUID.randomUUID().toString(); + this.userName = "U" + number++; this.spaceRoles = new ArrayList<Pair<RoleCode, Space>>(); this.instanceRoles = new ArrayList<RoleCode>(); } @@ -91,15 +91,15 @@ public class SessionBuilder extends Builder<String> for (Pair<RoleCode, Space> role : spaceRoles) { - commonServer.registerSpaceRole(systemSession, role.first, - new SpaceIdentifier(role.second.getInstance().getCode(), role.second - .getCode()), Grantee.createPerson(this.userName)); + commonServer.registerSpaceRole(systemSession, role.first, new SpaceIdentifier( + role.second.getInstance().getCode(), role.second.getCode()), Grantee + .createPerson(this.userName)); } for (RoleCode role : instanceRoles) { - commonServer.registerInstanceRole(systemSession, role, Grantee - .createPerson(this.userName)); + commonServer.registerInstanceRole(systemSession, role, + Grantee.createPerson(this.userName)); } return commonServer.tryToAuthenticate(userName, "pwd").getSessionToken(); diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/base/builder/SpaceBuilder.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/base/builder/SpaceBuilder.java index f060e997603cf806d23a4dea755c9a2d33bf98e8..13ea7d3d9454b7e62bd7f98bcf54944a030c2881 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/base/builder/SpaceBuilder.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/base/builder/SpaceBuilder.java @@ -16,8 +16,6 @@ package ch.systemsx.cisd.openbis.systemtest.base.builder; -import java.util.UUID; - import ch.systemsx.cisd.openbis.generic.server.ICommonServerForInternalUse; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Space; import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.DatabaseInstanceIdentifier; @@ -25,13 +23,14 @@ import ch.systemsx.cisd.openbis.plugin.generic.shared.IGenericServer; public class SpaceBuilder extends Builder<Space> { + private static int number; private String code; public SpaceBuilder(ICommonServerForInternalUse commonServer, IGenericServer genericServer) { super(commonServer, genericServer); - this.code = UUID.randomUUID().toString(); + this.code = "S" + number++; } public SpaceBuilder withCode(String spaceCode) @@ -49,8 +48,8 @@ public class SpaceBuilder extends Builder<Space> private Space getSpace(String spaceCode) { - for (Space space : commonServer.listSpaces(systemSession, - new DatabaseInstanceIdentifier("CISD"))) + for (Space space : commonServer.listSpaces(systemSession, new DatabaseInstanceIdentifier( + "CISD"))) { if (space.getCode().equalsIgnoreCase(spaceCode)) {