Skip to content
Snippets Groups Projects
Commit 60cea84c authored by pkupczyk's avatar pkupczyk
Browse files

SSDM-5416 : Project Authorization - sample predicates and validators - more tests

SVN: 38570
parent 747d046e
No related branches found
No related tags found
No related merge requests found
Showing
with 562 additions and 34 deletions
/*
* Copyright 2017 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.datastoreserver.systemtests.authorization.common;
import ch.systemsx.cisd.openbis.datastoreserver.systemtests.authorization.CommonAuthorizationSystemTest;
import ch.systemsx.cisd.openbis.datastoreserver.systemtests.authorization.CommonAuthorizationSystemTest.SampleKind;
import ch.systemsx.cisd.openbis.generic.shared.basic.TechId;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Deletion;
import ch.systemsx.cisd.openbis.generic.shared.dto.ExperimentPE;
import ch.systemsx.cisd.openbis.generic.shared.dto.ProjectPE;
import ch.systemsx.cisd.openbis.generic.shared.dto.SamplePE;
import ch.systemsx.cisd.openbis.generic.shared.dto.SpacePE;
/**
* @author pkupczyk
*/
public class DeletionUtil
{
public static TechId createNonexistentObject(Object param)
{
return new TechId(-1);
}
public static TechId createObjectWithExperiment(CommonAuthorizationSystemTest test, SpacePE spacePE, ProjectPE projectPE, Object param)
{
ExperimentPE experiment = test.getExperimentEmpty(spacePE, projectPE);
Deletion deletion = test.getCommonService().trashExperiment(experiment);
return new TechId(deletion.getId());
}
public static TechId createObjectWithSample(CommonAuthorizationSystemTest test, SpacePE spacePE, ProjectPE projectPE, Object param)
{
SamplePE sample;
switch ((SampleKind) param)
{
case SHARED_READ:
case SHARED_READ_WRITE:
if (test.getSpace1().equals(spacePE))
{
sample = test.getSharedSample1();
} else if (test.getSpace2().equals(spacePE))
{
sample = test.getSharedSample2();
} else
{
throw new RuntimeException();
}
break;
default:
sample = test.getSample(spacePE, projectPE, (SampleKind) param);
}
Deletion deletion = test.getCommonService().trashSample(sample);
return new TechId(deletion.getId());
}
}
......@@ -19,6 +19,7 @@ package ch.systemsx.cisd.openbis.datastoreserver.systemtests.authorization.predi
import java.util.List;
import ch.systemsx.cisd.common.exceptions.UserFailureException;
import ch.systemsx.cisd.openbis.datastoreserver.systemtests.authorization.common.DeletionUtil;
import ch.systemsx.cisd.openbis.datastoreserver.systemtests.authorization.predicate.CommonPredicateSystemTest;
import ch.systemsx.cisd.openbis.generic.shared.basic.TechId;
import ch.systemsx.cisd.openbis.generic.shared.dto.IAuthSessionProvider;
......@@ -40,7 +41,7 @@ public abstract class DeletionTechIdCollectionPredicateSystemTest extends Common
@Override
protected TechId createNonexistentObject(Object param)
{
return new TechId(-1);
return DeletionUtil.createNonexistentObject(param);
}
@Override
......
......@@ -16,9 +16,8 @@
package ch.systemsx.cisd.openbis.datastoreserver.systemtests.authorization.predicate.deletion;
import ch.systemsx.cisd.openbis.datastoreserver.systemtests.authorization.common.DeletionUtil;
import ch.systemsx.cisd.openbis.generic.shared.basic.TechId;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Deletion;
import ch.systemsx.cisd.openbis.generic.shared.dto.ExperimentPE;
import ch.systemsx.cisd.openbis.generic.shared.dto.ProjectPE;
import ch.systemsx.cisd.openbis.generic.shared.dto.SpacePE;
......@@ -31,9 +30,7 @@ public class DeletionTechIdCollectionPredicateWithExperimentSystemTest extends D
@Override
protected TechId createObject(SpacePE spacePE, ProjectPE projectPE, Object param)
{
ExperimentPE experiment = getExperimentEmpty(spacePE, projectPE);
Deletion deletion = getCommonService().trashExperiment(experiment);
return new TechId(deletion.getId());
return DeletionUtil.createObjectWithExperiment(this, spacePE, projectPE, param);
}
}
\ No newline at end of file
......@@ -19,13 +19,12 @@ package ch.systemsx.cisd.openbis.datastoreserver.systemtests.authorization.predi
import java.util.List;
import ch.systemsx.cisd.common.exceptions.UserFailureException;
import ch.systemsx.cisd.openbis.datastoreserver.systemtests.authorization.common.DeletionUtil;
import ch.systemsx.cisd.openbis.datastoreserver.systemtests.authorization.predicate.CommonSamplePredicateSystemTest;
import ch.systemsx.cisd.openbis.generic.shared.basic.TechId;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Deletion;
import ch.systemsx.cisd.openbis.generic.shared.dto.IAuthSessionProvider;
import ch.systemsx.cisd.openbis.generic.shared.dto.PersonPE;
import ch.systemsx.cisd.openbis.generic.shared.dto.ProjectPE;
import ch.systemsx.cisd.openbis.generic.shared.dto.SamplePE;
import ch.systemsx.cisd.openbis.generic.shared.dto.SpacePE;
import ch.systemsx.cisd.openbis.systemtest.authorization.predicate.deletion.DeletionPredicateTestService;
......@@ -44,40 +43,19 @@ public class DeletionTechIdCollectionPredicateWithSampleSystemTest extends Commo
@Override
protected SampleKind getSharedSampleKind()
{
return SampleKind.SHARED_READ;
return SampleKind.SHARED_READ_WRITE;
}
@Override
protected TechId createNonexistentObject(Object param)
{
return new TechId(-1);
return DeletionUtil.createNonexistentObject(param);
}
@Override
protected TechId createObject(SpacePE spacePE, ProjectPE projectPE, Object param)
{
SamplePE sample;
switch ((SampleKind) param)
{
case SHARED_READ:
if (getSpace1().equals(spacePE))
{
sample = getSharedSample1();
} else if (getSpace2().equals(spacePE))
{
sample = getSharedSample2();
} else
{
throw new RuntimeException();
}
break;
default:
sample = getSample(spacePE, projectPE, (SampleKind) param);
}
Deletion deletion = getCommonService().trashSample(sample);
return new TechId(deletion.getId());
return DeletionUtil.createObjectWithSample(this, spacePE, projectPE, param);
}
@Override
......
/*
* Copyright 2017 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.datastoreserver.systemtests.authorization.predicate.deletion;
import java.util.List;
import ch.systemsx.cisd.common.exceptions.UserFailureException;
import ch.systemsx.cisd.openbis.datastoreserver.systemtests.authorization.common.DeletionUtil;
import ch.systemsx.cisd.openbis.datastoreserver.systemtests.authorization.predicate.CommonPredicateSystemTest;
import ch.systemsx.cisd.openbis.generic.shared.basic.TechId;
import ch.systemsx.cisd.openbis.generic.shared.dto.IAuthSessionProvider;
import ch.systemsx.cisd.openbis.generic.shared.dto.PersonPE;
import ch.systemsx.cisd.openbis.systemtest.authorization.predicate.deletion.DeletionPredicateTestService;
/**
* @author pkupczyk
*/
public abstract class RevertDeletionPredicateSystemTest extends CommonPredicateSystemTest<TechId>
{
@Override
protected boolean isCollectionPredicate()
{
return true;
}
@Override
protected TechId createNonexistentObject(Object param)
{
return DeletionUtil.createNonexistentObject(param);
}
@Override
protected void evaluateObjects(IAuthSessionProvider sessionProvider, List<TechId> objects, Object param)
{
try
{
getBean(DeletionPredicateTestService.class).testRevertDeletionPredicate(sessionProvider, objects);
} finally
{
if (objects != null)
{
for (TechId object : objects)
{
if (object != null)
{
getCommonService().untrash(object.getId());
}
}
}
}
}
@Override
protected void assertWithNull(PersonPE person, Throwable t, Object param)
{
assertException(t, NullPointerException.class, null);
}
@Override
protected void assertWithNullForInstanceUser(PersonPE person, Throwable t, Object param)
{
assertNoException(t);
}
@Override
protected void assertWithNullCollection(PersonPE person, Throwable t, Object param)
{
assertException(t, UserFailureException.class, "No revert deletion technical id specified.");
}
@Override
protected void assertWithNonexistentObject(PersonPE person, Throwable t, Object param)
{
assertNoException(t);
}
}
\ No newline at end of file
/*
* Copyright 2017 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.datastoreserver.systemtests.authorization.predicate.deletion;
import ch.systemsx.cisd.openbis.datastoreserver.systemtests.authorization.common.DeletionUtil;
import ch.systemsx.cisd.openbis.generic.shared.basic.TechId;
import ch.systemsx.cisd.openbis.generic.shared.dto.ProjectPE;
import ch.systemsx.cisd.openbis.generic.shared.dto.SpacePE;
/**
* @author pkupczyk
*/
public class RevertDeletionPredicateWithExperimentSystemTest extends RevertDeletionPredicateSystemTest
{
@Override
protected TechId createObject(SpacePE spacePE, ProjectPE projectPE, Object param)
{
return DeletionUtil.createObjectWithExperiment(this, spacePE, projectPE, param);
}
}
\ No newline at end of file
/*
* Copyright 2017 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.datastoreserver.systemtests.authorization.predicate.deletion;
import java.util.List;
import ch.systemsx.cisd.common.exceptions.UserFailureException;
import ch.systemsx.cisd.openbis.datastoreserver.systemtests.authorization.common.DeletionUtil;
import ch.systemsx.cisd.openbis.datastoreserver.systemtests.authorization.predicate.CommonSamplePredicateSystemTest;
import ch.systemsx.cisd.openbis.generic.shared.basic.TechId;
import ch.systemsx.cisd.openbis.generic.shared.dto.IAuthSessionProvider;
import ch.systemsx.cisd.openbis.generic.shared.dto.PersonPE;
import ch.systemsx.cisd.openbis.generic.shared.dto.ProjectPE;
import ch.systemsx.cisd.openbis.generic.shared.dto.SpacePE;
import ch.systemsx.cisd.openbis.systemtest.authorization.predicate.deletion.DeletionPredicateTestService;
/**
* @author pkupczyk
*/
public class RevertDeletionPredicateWithSampleSystemTest extends CommonSamplePredicateSystemTest<TechId>
{
@Override
protected boolean isCollectionPredicate()
{
return true;
}
@Override
protected SampleKind getSharedSampleKind()
{
return SampleKind.SHARED_READ_WRITE;
}
@Override
protected TechId createNonexistentObject(Object param)
{
return DeletionUtil.createNonexistentObject(param);
}
@Override
protected TechId createObject(SpacePE spacePE, ProjectPE projectPE, Object param)
{
return DeletionUtil.createObjectWithSample(this, spacePE, projectPE, param);
}
@Override
protected void evaluateObjects(IAuthSessionProvider sessionProvider, List<TechId> objects, Object param)
{
try
{
getBean(DeletionPredicateTestService.class).testRevertDeletionPredicate(sessionProvider, objects);
} finally
{
if (objects != null)
{
for (TechId object : objects)
{
if (object != null)
{
getCommonService().untrash(object.getId());
}
}
}
}
}
@Override
protected void assertWithNull(PersonPE person, Throwable t, Object param)
{
assertException(t, NullPointerException.class, null);
}
@Override
protected void assertWithNullForInstanceUser(PersonPE person, Throwable t, Object param)
{
assertNoException(t);
}
@Override
protected void assertWithNullCollection(PersonPE person, Throwable t, Object param)
{
assertException(t, UserFailureException.class, "No revert deletion technical id specified.");
}
@Override
protected void assertWithNonexistentObject(PersonPE person, Throwable t, Object param)
{
assertNoException(t);
}
}
\ No newline at end of file
/*
* Copyright 2017 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.datastoreserver.systemtests.authorization.predicate.deletion;
import java.util.List;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.deletion.id.DeletionTechId;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.deletion.id.IDeletionId;
import ch.systemsx.cisd.common.exceptions.UserFailureException;
import ch.systemsx.cisd.openbis.datastoreserver.systemtests.authorization.predicate.CommonPredicateSystemTest;
import ch.systemsx.cisd.openbis.generic.shared.dto.IAuthSessionProvider;
import ch.systemsx.cisd.openbis.generic.shared.dto.PersonPE;
import ch.systemsx.cisd.openbis.systemtest.authorization.predicate.deletion.DeletionPredicateTestService;
/**
* @author pkupczyk
*/
public abstract class V3DeletionIdPredicateSystemTest extends CommonPredicateSystemTest<IDeletionId>
{
@Override
protected boolean isCollectionPredicate()
{
return true;
}
@Override
protected IDeletionId createNonexistentObject(Object param)
{
return new DeletionTechId(-1L);
}
@Override
protected void evaluateObjects(IAuthSessionProvider sessionProvider, List<IDeletionId> objects, Object param)
{
try
{
getBean(DeletionPredicateTestService.class).testV3DeletionIdPredicate(sessionProvider, objects);
} finally
{
if (objects != null)
{
for (IDeletionId object : objects)
{
if (object != null)
{
getCommonService().untrash(((DeletionTechId) object).getTechId());
}
}
}
}
}
@Override
protected void assertWithNull(PersonPE person, Throwable t, Object param)
{
assertException(t, NullPointerException.class, null);
}
@Override
protected void assertWithNullCollection(PersonPE person, Throwable t, Object param)
{
assertException(t, UserFailureException.class, "No v3 deletion id object specified.");
}
@Override
protected void assertWithNonexistentObject(PersonPE person, Throwable t, Object param)
{
assertNoException(t);
}
}
\ No newline at end of file
/*
* Copyright 2017 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.datastoreserver.systemtests.authorization.predicate.deletion;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.deletion.id.DeletionTechId;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.deletion.id.IDeletionId;
import ch.systemsx.cisd.openbis.datastoreserver.systemtests.authorization.common.DeletionUtil;
import ch.systemsx.cisd.openbis.generic.shared.basic.TechId;
import ch.systemsx.cisd.openbis.generic.shared.dto.ProjectPE;
import ch.systemsx.cisd.openbis.generic.shared.dto.SpacePE;
/**
* @author pkupczyk
*/
public class V3DeletionIdPredicateWithExperimentSystemTest extends V3DeletionIdPredicateSystemTest
{
@Override
protected IDeletionId createObject(SpacePE spacePE, ProjectPE projectPE, Object param)
{
TechId techId = DeletionUtil.createObjectWithExperiment(this, spacePE, projectPE, param);
return new DeletionTechId(techId.getId());
}
}
\ No newline at end of file
/*
* Copyright 2017 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.datastoreserver.systemtests.authorization.predicate.deletion;
import java.util.List;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.deletion.id.DeletionTechId;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.deletion.id.IDeletionId;
import ch.systemsx.cisd.common.exceptions.UserFailureException;
import ch.systemsx.cisd.openbis.datastoreserver.systemtests.authorization.common.DeletionUtil;
import ch.systemsx.cisd.openbis.datastoreserver.systemtests.authorization.predicate.CommonSamplePredicateSystemTest;
import ch.systemsx.cisd.openbis.generic.shared.basic.TechId;
import ch.systemsx.cisd.openbis.generic.shared.dto.IAuthSessionProvider;
import ch.systemsx.cisd.openbis.generic.shared.dto.PersonPE;
import ch.systemsx.cisd.openbis.generic.shared.dto.ProjectPE;
import ch.systemsx.cisd.openbis.generic.shared.dto.SpacePE;
import ch.systemsx.cisd.openbis.systemtest.authorization.predicate.deletion.DeletionPredicateTestService;
/**
* @author pkupczyk
*/
public class V3DeletionIdPredicateWithSampleSystemTest extends CommonSamplePredicateSystemTest<IDeletionId>
{
@Override
protected boolean isCollectionPredicate()
{
return true;
}
@Override
protected SampleKind getSharedSampleKind()
{
return SampleKind.SHARED_READ_WRITE;
}
@Override
protected IDeletionId createNonexistentObject(Object param)
{
return new DeletionTechId(-1L);
}
@Override
protected IDeletionId createObject(SpacePE spacePE, ProjectPE projectPE, Object param)
{
TechId techId = DeletionUtil.createObjectWithSample(this, spacePE, projectPE, param);
return new DeletionTechId(techId.getId());
}
@Override
protected void evaluateObjects(IAuthSessionProvider sessionProvider, List<IDeletionId> objects, Object param)
{
try
{
getBean(DeletionPredicateTestService.class).testV3DeletionIdPredicate(sessionProvider, objects);
} finally
{
if (objects != null)
{
for (IDeletionId object : objects)
{
if (object != null)
{
getCommonService().untrash(((DeletionTechId) object).getTechId());
}
}
}
}
}
@Override
protected void assertWithNull(PersonPE person, Throwable t, Object param)
{
assertException(t, NullPointerException.class, null);
}
@Override
protected void assertWithNullCollection(PersonPE person, Throwable t, Object param)
{
assertException(t, UserFailureException.class, "No v3 deletion id object specified.");
}
@Override
protected void assertWithNonexistentObject(PersonPE person, Throwable t, Object param)
{
assertNoException(t);
}
}
\ No newline at end of file
......@@ -43,7 +43,7 @@ public class DeletionTechIdCollectionPredicate extends AbstractSpacePredicate<Li
public DeletionTechIdCollectionPredicate()
{
this.experimentAccessPECollectionPredicate = new ExperimentAccessPECollectionPredicate();
this.sampleAccessPECollectionPredicate = new SampleAccessPECollectionPredicate();
this.sampleAccessPECollectionPredicate = new SampleAccessPECollectionPredicate(false);
}
@Override
......
......@@ -97,7 +97,7 @@ public class RevertDeletionPredicate extends AbstractPredicate<List<TechId>>
final Set<RoleAssignmentPE> roleAssignments = person.getAllPersonRoles();
for (final RoleAssignmentPE roleAssignment : roleAssignments)
{
if (roleAssignment.getSpace() == null && roleAssignment.getRole().equals(RoleCode.ADMIN))
if (roleAssignment.getSpace() == null && roleAssignment.getProject() == null && roleAssignment.getRole().equals(RoleCode.ADMIN))
{
return true;
}
......
......@@ -21,9 +21,12 @@ import java.util.List;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import ch.ethz.sis.openbis.generic.asapi.v3.dto.deletion.id.IDeletionId;
import ch.systemsx.cisd.openbis.generic.server.authorization.annotation.AuthorizationGuard;
import ch.systemsx.cisd.openbis.generic.server.authorization.annotation.RolesAllowed;
import ch.systemsx.cisd.openbis.generic.server.authorization.predicate.DeletionTechIdCollectionPredicate;
import ch.systemsx.cisd.openbis.generic.server.authorization.predicate.RevertDeletionPredicate;
import ch.systemsx.cisd.openbis.generic.server.authorization.predicate.V3DeletionIdPredicate;
import ch.systemsx.cisd.openbis.generic.shared.basic.TechId;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.RoleWithHierarchy;
import ch.systemsx.cisd.openbis.generic.shared.dto.IAuthSessionProvider;
......@@ -42,4 +45,18 @@ public class DeletionPredicateTestService
{
}
@Transactional
@RolesAllowed(value = { RoleWithHierarchy.PROJECT_OBSERVER })
public void testRevertDeletionPredicate(IAuthSessionProvider sessionProvider,
@AuthorizationGuard(guardClass = RevertDeletionPredicate.class) List<TechId> deletionTechIds)
{
}
@Transactional
@RolesAllowed(value = { RoleWithHierarchy.PROJECT_OBSERVER })
public void testV3DeletionIdPredicate(IAuthSessionProvider sessionProvider,
@AuthorizationGuard(guardClass = V3DeletionIdPredicate.class) List<IDeletionId> deletionIds)
{
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment