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) @Column(name = "ANCESTORS", length = 1024)
private String ancestors; private String ancestors;
@RecursivePermissions(privileges = {AssetPrivileges.EDIT,
AssetPrivileges.DELETE,
AssetPrivileges.VIEW})
@OneToMany(mappedBy = "item") @OneToMany(mappedBy = "item")
private List<AttachmentList> attachments; private List<AttachmentList> attachments;

View File

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

View File

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

View File

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

View File

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