CCM NG: Changes for the PermissionManager to pass tests.

git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4535 8810af33-2d31-482b-a856-94f89814c4df

Former-commit-id: 39b74d511a
pull/2/head
jensp 2017-01-24 16:32:57 +00:00
parent c0315684c7
commit 60a545456a
5 changed files with 125 additions and 120 deletions

View File

@ -241,9 +241,6 @@ public class ContentItem extends CcmObject implements Serializable,
@Column(name = "ANCESTORS", length = 1024)
private String ancestors;
@RecursivePermissions(privileges = {AssetPrivileges.EDIT,
AssetPrivileges.DELETE,
AssetPrivileges.VIEW})
@OneToMany(mappedBy = "item")
private List<AttachmentList> attachments;

View File

@ -142,7 +142,7 @@ public class PermissionManager {
return;
}
if (field.getType().equals(Collection.class)) {
if (Collection.class.isAssignableFrom(field.getType())) {
final Collection<?> collection = (Collection<?>) value;
collection.stream()
.filter(obj -> obj instanceof CcmObject)
@ -154,9 +154,9 @@ public class PermissionManager {
.filter(relation -> relation.getRelatedObject() != null)
.map(relation -> relation.getRelatedObject())
.forEach(obj -> grantPrivilege(privilege, grantee, obj));
} else if (field.getType().equals(CcmObject.class)) {
} else if (CcmObject.class.isAssignableFrom(field.getType())) {
grantPrivilege(privilege, grantee, (CcmObject) value);
} else if (field.getType().equals(Relation.class)) {
} else if (Relation.class.isAssignableFrom(field.getType())) {
final Relation relation = (Relation) value;
if (relation.getRelatedObject() != null) {
grantPrivilege(privilege, grantee, relation.getRelatedObject());

View File

@ -105,38 +105,38 @@ public class PermissionManagerTest {
@Deployment
public static WebArchive createDeployment() {
return ShrinkWrap
.create(WebArchive.class,
"LibreCCM-org.libreccm.security.PermissionManagerTest.war")
.addPackage(org.libreccm.categorization.Categorization.class
.getPackage())
.addPackage(org.libreccm.configuration.Configuration.class
.getPackage())
.addPackage(org.libreccm.core.CcmObject.class.getPackage())
.addPackage(org.libreccm.jpa.EntityManagerProducer.class
.getPackage())
.addPackage(org.libreccm.jpa.utils.MimeTypeConverter.class
.getPackage())
.addPackage(org.libreccm.l10n.LocalizedString.class.getPackage())
.addPackage(org.libreccm.security.User.class.getPackage())
.addPackage(org.libreccm.tests.categories.IntegrationTest.class
.getPackage())
.addPackage(org.libreccm.testutils.EqualsVerifier.class
.getPackage())
.addPackage(org.libreccm.web.CcmApplication.class.getPackage())
.addPackage(org.libreccm.workflow.Workflow.class.getPackage())
.addPackage(com.arsdigita.kernel.KernelConfig.class.getPackage())
.addPackage(com.arsdigita.kernel.security.SecurityConfig.class
.getPackage())
.addPackage(com.arsdigita.util.UncheckedWrapperException.class
.getPackage())
.addPackage(org.libreccm.cdi.utils.CdiUtil.class.getPackage())
.addClass(org.libreccm.portation.Portable.class)
.addAsLibraries(getModuleDependencies())
.addAsResource("test-persistence.xml",
"META-INF/persistence.xml")
.addAsResource("configs/shiro.ini", "shiro.ini")
.addAsWebInfResource("test-web.xml", "web.xml")
.addAsWebInfResource("META-INF/beans.xml", "beans.xml");
.create(WebArchive.class,
"LibreCCM-org.libreccm.security.PermissionManagerTest.war").
addPackage(org.libreccm.categorization.Categorization.class
.getPackage())
.addPackage(org.libreccm.configuration.Configuration.class
.getPackage())
.addPackage(org.libreccm.core.CcmObject.class.getPackage())
.addPackage(org.libreccm.jpa.EntityManagerProducer.class
.getPackage())
.addPackage(org.libreccm.jpa.utils.MimeTypeConverter.class
.getPackage())
.addPackage(org.libreccm.l10n.LocalizedString.class.getPackage()).
addPackage(org.libreccm.security.User.class.getPackage())
.addPackage(org.libreccm.tests.categories.IntegrationTest.class
.getPackage())
.addPackage(org.libreccm.testutils.EqualsVerifier.class
.getPackage())
.addPackage(org.libreccm.web.CcmApplication.class.getPackage())
.addPackage(org.libreccm.workflow.Workflow.class.getPackage())
.addPackage(com.arsdigita.kernel.KernelConfig.class.getPackage()).
addPackage(com.arsdigita.kernel.security.SecurityConfig.class
.getPackage())
.addPackage(com.arsdigita.util.UncheckedWrapperException.class
.getPackage())
.addPackage(org.libreccm.cdi.utils.CdiUtil.class.getPackage())
.addClass(org.libreccm.portation.Portable.class)
.addAsLibraries(getModuleDependencies())
.addAsResource("test-persistence.xml",
"META-INF/persistence.xml")
.addAsResource("configs/shiro.ini", "shiro.ini")
.addAsWebInfResource("test-web.xml", "web.xml")
.addAsWebInfResource("META-INF/beans.xml", "beans.xml");
}
/**
@ -175,11 +175,11 @@ public class PermissionManagerTest {
*/
@Test
@UsingDataSet(
"datasets/org/libreccm/security/PermissionManagerTest/data.yml")
"datasets/org/libreccm/security/PermissionManagerTest/data.yml")
@ShouldMatchDataSet(
value = "datasets/org/libreccm/security/PermissionManagerTest/"
+ "after-grant.yml",
excludeColumns = {"permission_id"})
value = "datasets/org/libreccm/security/PermissionManagerTest/"
+ "after-grant.yml",
excludeColumns = {"permission_id"})
@InSequence(200)
public void grantPermission() {
final Role role2 = roleRepository.findByName("role2");
@ -200,10 +200,10 @@ public class PermissionManagerTest {
*/
@Test
@UsingDataSet(
"datasets/org/libreccm/security/PermissionManagerTest/data.yml")
"datasets/org/libreccm/security/PermissionManagerTest/data.yml")
@ShouldMatchDataSet(
value = "datasets/org/libreccm/security/PermissionManagerTest/"
+ "data.yml")
value = "datasets/org/libreccm/security/PermissionManagerTest/"
+ "data.yml")
@InSequence(210)
public void grantPermissionAgain() {
final Role role1 = roleRepository.findByName("role1");
@ -222,11 +222,12 @@ public class PermissionManagerTest {
*/
@Test
@UsingDataSet("datasets/org/libreccm/security/PermissionManagerTest/"
+ "data-recursivly.yml")
+ "data-recursivly.yml")
@ShouldMatchDataSet(
value = "datasets/org/libreccm/security/PermissionManagerTest/"
+ "after-grant-recursivly.yml",
excludeColumns = {"permission_id"})
value = "datasets/org/libreccm/security/PermissionManagerTest/"
+ "after-grant-recursivly.yml",
excludeColumns = {"permission_id"},
orderBy = {"permissions.permission_id desc"})
@InSequence(211)
public void grantPermissionRecursively() {
final Role role1 = roleRepository.findByName("role1");
@ -244,11 +245,11 @@ public class PermissionManagerTest {
*/
@Test
@UsingDataSet("datasets/org/libreccm/security/PermissionManagerTest/"
+ "after-grant-recursivly.yml")
+ "after-grant-recursivly.yml")
@ShouldMatchDataSet(
value = "datasets/org/libreccm/security/PermissionManagerTest/"
+ "after-grant-inherited.yml",
excludeColumns = {"permission_id"})
value = "datasets/org/libreccm/security/PermissionManagerTest/"
+ "after-grant-inherited.yml",
excludeColumns = {"permission_id"})
@InSequence(212)
public void grantInheritedPermission() {
final Role role1 = roleRepository.findByName("role1");
@ -269,7 +270,7 @@ public class PermissionManagerTest {
*/
@Test(expected = IllegalArgumentException.class)
@UsingDataSet(
"datasets/org/libreccm/security/PermissionManagerTest/data.yml")
"datasets/org/libreccm/security/PermissionManagerTest/data.yml")
@ShouldThrowException(IllegalArgumentException.class)
@InSequence(220)
public void grantPermissionPrivilegeNull() throws Throwable {
@ -277,7 +278,7 @@ public class PermissionManagerTest {
try {
shiro.getSystemUser().execute(
() -> permissionManager.grantPrivilege(null, role1));
() -> permissionManager.grantPrivilege(null, role1));
} catch (ExecutionException ex) {
throw ex.getCause();
}
@ -293,7 +294,7 @@ public class PermissionManagerTest {
*/
@Test(expected = IllegalArgumentException.class)
@UsingDataSet(
"datasets/org/libreccm/security/PermissionManagerTest/data.yml")
"datasets/org/libreccm/security/PermissionManagerTest/data.yml")
@ShouldThrowException(IllegalArgumentException.class)
@InSequence(225)
public void grantPermissionOnObjectPrivilegeNull() throws Throwable {
@ -302,7 +303,7 @@ public class PermissionManagerTest {
try {
shiro.getSystemUser().execute(
() -> permissionManager.grantPrivilege(null, role1, object1));
() -> permissionManager.grantPrivilege(null, role1, object1));
} catch (ExecutionException ex) {
throw ex.getCause();
}
@ -318,7 +319,7 @@ public class PermissionManagerTest {
*/
@Test(expected = IllegalArgumentException.class)
@UsingDataSet(
"datasets/org/libreccm/security/PermissionManagerTest/data.yml")
"datasets/org/libreccm/security/PermissionManagerTest/data.yml")
@ShouldThrowException(IllegalArgumentException.class)
@InSequence(230)
public void grantPermissionEmptyPrivilege() throws Throwable {
@ -326,7 +327,7 @@ public class PermissionManagerTest {
try {
shiro.getSystemUser().execute(
() -> permissionManager.grantPrivilege("", role1));
() -> permissionManager.grantPrivilege("", role1));
} catch (ExecutionException ex) {
throw ex.getCause();
}
@ -342,7 +343,7 @@ public class PermissionManagerTest {
*/
@Test(expected = IllegalArgumentException.class)
@UsingDataSet(
"datasets/org/libreccm/security/PermissionManagerTest/data.yml")
"datasets/org/libreccm/security/PermissionManagerTest/data.yml")
@ShouldThrowException(IllegalArgumentException.class)
@InSequence(235)
public void grantPermissionOnObjectEmptyPrivilege() throws Throwable {
@ -351,7 +352,7 @@ public class PermissionManagerTest {
try {
shiro.getSystemUser().execute(
() -> permissionManager.grantPrivilege("", role1, object1));
() -> permissionManager.grantPrivilege("", role1, object1));
} catch (ExecutionException ex) {
throw ex.getCause();
}
@ -367,13 +368,13 @@ public class PermissionManagerTest {
*/
@Test(expected = IllegalArgumentException.class)
@UsingDataSet(
"datasets/org/libreccm/security/PermissionManagerTest/data.yml")
"datasets/org/libreccm/security/PermissionManagerTest/data.yml")
@ShouldThrowException(IllegalArgumentException.class)
@InSequence(240)
public void grantPermissionToRoleNull() throws Throwable {
try {
shiro.getSystemUser().execute(
() -> permissionManager.grantPrivilege("privilege", null));
() -> permissionManager.grantPrivilege("privilege", null));
} catch (ExecutionException ex) {
throw ex.getCause();
}
@ -389,7 +390,7 @@ public class PermissionManagerTest {
*/
@Test(expected = IllegalArgumentException.class)
@UsingDataSet(
"datasets/org/libreccm/security/PermissionManagerTest/data.yml")
"datasets/org/libreccm/security/PermissionManagerTest/data.yml")
@ShouldThrowException(IllegalArgumentException.class)
@InSequence(240)
public void grantPermissionOnObjectToRoleNull() throws Throwable {
@ -397,9 +398,9 @@ public class PermissionManagerTest {
try {
shiro.getSystemUser().execute(
() -> permissionManager.grantPrivilege("privilege",
null,
object1));
() -> permissionManager.grantPrivilege("privilege",
null,
object1));
} catch (ExecutionException ex) {
throw ex.getCause();
}
@ -415,7 +416,7 @@ public class PermissionManagerTest {
*/
@Test(expected = IllegalArgumentException.class)
@UsingDataSet(
"datasets/org/libreccm/security/PermissionManagerTest/data.yml")
"datasets/org/libreccm/security/PermissionManagerTest/data.yml")
@ShouldThrowException(IllegalArgumentException.class)
@InSequence(250)
public void grantPermissionNullObject() throws Throwable {
@ -423,9 +424,9 @@ public class PermissionManagerTest {
try {
shiro.getSystemUser().execute(
() -> permissionManager.grantPrivilege("privilege1",
role1,
null));
() -> permissionManager.grantPrivilege("privilege1",
role1,
null));
} catch (ExecutionException ex) {
throw ex.getCause();
}
@ -440,11 +441,11 @@ public class PermissionManagerTest {
*/
@Test
@UsingDataSet(
"datasets/org/libreccm/security/PermissionManagerTest/data.yml")
"datasets/org/libreccm/security/PermissionManagerTest/data.yml")
@ShouldMatchDataSet(
value = "datasets/org/libreccm/security/PermissionManagerTest/"
+ "after-revoke.yml",
excludeColumns = {"permission_id"})
value = "datasets/org/libreccm/security/PermissionManagerTest/"
+ "after-revoke.yml",
excludeColumns = {"permission_id"})
@InSequence(300)
public void revokePermission() {
final Role role1 = roleRepository.findByName("role1");
@ -466,16 +467,16 @@ public class PermissionManagerTest {
*/
@Test
@UsingDataSet(
"datasets/org/libreccm/security/PermissionManagerTest/data.yml")
"datasets/org/libreccm/security/PermissionManagerTest/data.yml")
@ShouldMatchDataSet(
value = "datasets/org/libreccm/security/PermissionManagerTest/"
+ "data.yml")
value = "datasets/org/libreccm/security/PermissionManagerTest/"
+ "data.yml")
@InSequence(310)
public void revokeNotExistingPermission() throws Throwable {
final Role role1 = roleRepository.findByName("role1");
shiro.getSystemUser().execute(
() -> permissionManager.revokePrivilege("privilege999", role1));
() -> permissionManager.revokePrivilege("privilege999", role1));
}
/**
@ -484,13 +485,13 @@ public class PermissionManagerTest {
*/
@Test
@UsingDataSet("datasets/org/libreccm/security/PermissionManagerTest/"
+ "after-grant-recursivly.yml")
+ "after-grant-recursivly.yml")
@ShouldMatchDataSet(
value = "datasets/org/libreccm/security/PermissionManagerTest/"
+ "after-revoke-recursivly.yml")
value = "datasets/org/libreccm/security/PermissionManagerTest/"
+ "after-revoke-recursivly.yml")
@InSequence(311)
public void revokePermissionRecursivly() {
final Role role1 = roleRepository.findByName("role1");
final Role role1 = roleRepository.findByName("role1");
final CcmObject category1 = ccmObjectRepository.findById(-20001L);
shiro.getSystemUser().execute(() -> {
@ -507,19 +508,19 @@ public class PermissionManagerTest {
*/
@Test
@UsingDataSet(
"datasets/org/libreccm/security/PermissionManagerTest/data.yml")
"datasets/org/libreccm/security/PermissionManagerTest/data.yml")
@ShouldMatchDataSet(
value = "datasets/org/libreccm/security/PermissionManagerTest/"
+ "data.yml")
value = "datasets/org/libreccm/security/PermissionManagerTest/"
+ "data.yml")
@InSequence(310)
public void revokeNotExistingPermissionOnObject() {
final Role role1 = roleRepository.findByName("role1");
final CcmObject object1 = ccmObjectRepository.findById(-20001L);
shiro.getSystemUser().execute(
() -> permissionManager.revokePrivilege("privilege999",
role1,
object1));
() -> permissionManager.revokePrivilege("privilege999",
role1,
object1));
}
/**
@ -532,7 +533,7 @@ public class PermissionManagerTest {
*/
@Test(expected = IllegalArgumentException.class)
@UsingDataSet(
"datasets/org/libreccm/security/PermissionManagerTest/data.yml")
"datasets/org/libreccm/security/PermissionManagerTest/data.yml")
@ShouldThrowException(IllegalArgumentException.class)
@InSequence(320)
public void revokePermissionPrivilegeNull() throws Throwable {
@ -540,7 +541,7 @@ public class PermissionManagerTest {
try {
shiro.getSystemUser().execute(
() -> permissionManager.revokePrivilege(null, role1));
() -> permissionManager.revokePrivilege(null, role1));
} catch (ExecutionException ex) {
throw ex.getCause();
}
@ -556,7 +557,7 @@ public class PermissionManagerTest {
*/
@Test(expected = IllegalArgumentException.class)
@UsingDataSet(
"datasets/org/libreccm/security/PermissionManagerTest/data.yml")
"datasets/org/libreccm/security/PermissionManagerTest/data.yml")
@ShouldThrowException(IllegalArgumentException.class)
@InSequence(320)
public void revokePermissionOnObjectPrivilegeNull() throws Throwable {
@ -565,7 +566,8 @@ public class PermissionManagerTest {
try {
shiro.getSystemUser().execute(
() -> permissionManager.revokePrivilege(null, role1, object1));
() -> permissionManager.
revokePrivilege(null, role1, object1));
} catch (ExecutionException ex) {
throw ex.getCause();
}
@ -581,7 +583,7 @@ public class PermissionManagerTest {
*/
@Test(expected = IllegalArgumentException.class)
@UsingDataSet(
"datasets/org/libreccm/security/PermissionManagerTest/data.yml")
"datasets/org/libreccm/security/PermissionManagerTest/data.yml")
@ShouldThrowException(IllegalArgumentException.class)
@InSequence(330)
public void revokePermissionEmptyPrivilege() throws Throwable {
@ -589,7 +591,7 @@ public class PermissionManagerTest {
try {
shiro.getSystemUser().execute(
() -> permissionManager.revokePrivilege("", role1));
() -> permissionManager.revokePrivilege("", role1));
} catch (ExecutionException ex) {
throw ex.getCause();
}
@ -604,9 +606,9 @@ public class PermissionManagerTest {
* @throws Throwable
*/
@Test(expected
= IllegalArgumentException.class)
= IllegalArgumentException.class)
@UsingDataSet(
"datasets/org/libreccm/security/PermissionManagerTest/data.yml")
"datasets/org/libreccm/security/PermissionManagerTest/data.yml")
@ShouldThrowException(IllegalArgumentException.class)
@InSequence(320)
public void revokePermissionOnObjectEmptyPrivilege() throws Throwable {
@ -615,7 +617,7 @@ public class PermissionManagerTest {
try {
shiro.getSystemUser().execute(
() -> permissionManager.revokePrivilege("", role1, object1));
() -> permissionManager.revokePrivilege("", role1, object1));
} catch (ExecutionException ex) {
throw ex.getCause();
}
@ -630,15 +632,15 @@ public class PermissionManagerTest {
* @throws Throwable
*/
@Test(expected
= IllegalArgumentException.class)
= IllegalArgumentException.class)
@UsingDataSet(
"datasets/org/libreccm/security/PermissionManagerTest/data.yml")
"datasets/org/libreccm/security/PermissionManagerTest/data.yml")
@ShouldThrowException(IllegalArgumentException.class)
@InSequence(340)
public void revokePermissionFromRoleNull() throws Throwable {
try {
shiro.getSystemUser().execute(
() -> permissionManager.revokePrivilege("privilege1", null));
() -> permissionManager.revokePrivilege("privilege1", null));
} catch (ExecutionException ex) {
throw ex.getCause();
}
@ -654,7 +656,7 @@ public class PermissionManagerTest {
*/
@Test(expected = IllegalArgumentException.class)
@UsingDataSet(
"datasets/org/libreccm/security/PermissionManagerTest/data.yml")
"datasets/org/libreccm/security/PermissionManagerTest/data.yml")
@ShouldThrowException(IllegalArgumentException.class)
@InSequence(345)
public void revokePermissionOnObjectFromRoleNull() throws Throwable {
@ -662,9 +664,9 @@ public class PermissionManagerTest {
try {
shiro.getSystemUser().execute(
() -> permissionManager.revokePrivilege("privilege1",
null,
object1));
() -> permissionManager.revokePrivilege("privilege1",
null,
object1));
} catch (ExecutionException ex) {
throw ex.getCause();
}
@ -680,7 +682,7 @@ public class PermissionManagerTest {
*/
@Test(expected = IllegalArgumentException.class)
@UsingDataSet(
"datasets/org/libreccm/security/PermissionManagerTest/data.yml")
"datasets/org/libreccm/security/PermissionManagerTest/data.yml")
@ShouldThrowException(IllegalArgumentException.class)
@InSequence(350)
public void revokePermissionNullObject() throws Throwable {
@ -688,9 +690,9 @@ public class PermissionManagerTest {
try {
shiro.getSystemUser().execute(
() -> permissionManager.revokePrivilege("privilege2",
role1,
null));
() -> permissionManager.revokePrivilege("privilege2",
role1,
null));
} catch (ExecutionException ex) {
throw ex.getCause();
}
@ -705,18 +707,18 @@ public class PermissionManagerTest {
*/
@Test
@UsingDataSet(
"datasets/org/libreccm/security/PermissionManagerTest/data.yml")
"datasets/org/libreccm/security/PermissionManagerTest/data.yml")
@ShouldMatchDataSet(
value = "datasets/org/libreccm/security/PermissionManagerTest/"
+ "after-copy.yml",
excludeColumns = {"permission_id"})
value = "datasets/org/libreccm/security/PermissionManagerTest/"
+ "after-copy.yml",
excludeColumns = {"permission_id"})
@InSequence(400)
public void copyPermissions() throws Throwable {
final CcmObject object2 = ccmObjectRepository.findById(-20002L);
final CcmObject object3 = ccmObjectRepository.findById(-20003L);
shiro.getSystemUser().execute(
() -> permissionManager.copyPermissions(object2, object3));
() -> permissionManager.copyPermissions(object2, object3));
}
/**
@ -729,7 +731,7 @@ public class PermissionManagerTest {
*/
@Test(expected = IllegalArgumentException.class)
@UsingDataSet(
"datasets/org/libreccm/security/PermissionManagerTest/data.yml")
"datasets/org/libreccm/security/PermissionManagerTest/data.yml")
@ShouldThrowException(IllegalArgumentException.class)
@InSequence(410)
public void copyPermissionsNullSource() throws Throwable {
@ -737,7 +739,7 @@ public class PermissionManagerTest {
try {
shiro.getSystemUser().execute(
() -> permissionManager.copyPermissions(null, object3));
() -> permissionManager.copyPermissions(null, object3));
} catch (ExecutionException ex) {
throw ex.getCause();
}
@ -753,7 +755,7 @@ public class PermissionManagerTest {
*/
@Test(expected = IllegalArgumentException.class)
@UsingDataSet(
"datasets/org/libreccm/security/PermissionManagerTest/data.yml")
"datasets/org/libreccm/security/PermissionManagerTest/data.yml")
@ShouldThrowException(IllegalArgumentException.class)
@InSequence(420)
public void copyPermissionsNullTarget() throws Throwable {
@ -761,7 +763,7 @@ public class PermissionManagerTest {
try {
shiro.getSystemUser().execute(
() -> permissionManager.copyPermissions(object2, null));
() -> permissionManager.copyPermissions(object2, null));
} catch (ExecutionException ex) {
throw ex.getCause();
}
@ -777,9 +779,9 @@ public class PermissionManagerTest {
public void verifyListPrivileges() {
final List<String> corePrivileges = permissionManager
.listDefiniedPrivileges(CoreConstants.class);
.listDefiniedPrivileges(CoreConstants.class);
final List<String> catPrivileges = permissionManager
.listDefiniedPrivileges(CategorizationConstants.class);
.listDefiniedPrivileges(CategorizationConstants.class);
assertThat(corePrivileges, is(not(nullValue())));
assertThat(corePrivileges.isEmpty(), is(false));

View File

@ -43,6 +43,9 @@ ccm_core.categorizations:
- categorization_id: -40001
category_id: -20003
object_id: -20004
category_index: false
category_order: 0
object_order: 0
ccm_core.permissions:
- permission_id: -30001
granted_privilege: privilege1

View File

@ -43,6 +43,9 @@ ccm_core.categorizations:
- categorization_id: -40001
category_id: -20003
object_id: -20004
category_index: false
category_order: 0
object_order: 0
ccm_core.permissions:
- permission_id: -30001
granted_privilege: privilege1