Search in sources :

Example 1 with PrivilegeCollection

use of org.apache.jackrabbit.api.security.authorization.PrivilegeCollection in project jackrabbit by apache.

the class AbstractACLTemplateTest method testRemoveInvalidEntry.

public void testRemoveInvalidEntry() throws RepositoryException {
    JackrabbitAccessControlList pt = createEmptyTemplate(getTestPath());
    try {
        pt.removeAccessControlEntry(new JackrabbitAccessControlEntry() {

            public boolean isAllow() {
                return false;
            }

            public String[] getRestrictionNames() {
                return new String[0];
            }

            public Value getRestriction(String restrictionName) {
                return null;
            }

            public Value[] getRestrictions(String restrictionName) throws RepositoryException {
                return null;
            }

            @Override
            public PrivilegeCollection getPrivilegeCollection() throws RepositoryException {
                throw new UnsupportedRepositoryOperationException();
            }

            public Principal getPrincipal() {
                return testPrincipal;
            }

            public Privilege[] getPrivileges() {
                try {
                    return privilegesFromName(Privilege.JCR_READ);
                } catch (Exception e) {
                    return new Privilege[0];
                }
            }
        });
        fail("Passing an unknown ACE should fail");
    } catch (AccessControlException e) {
    // success
    }
}
Also used : UnsupportedRepositoryOperationException(javax.jcr.UnsupportedRepositoryOperationException) JackrabbitAccessControlEntry(org.apache.jackrabbit.api.security.JackrabbitAccessControlEntry) PrivilegeCollection(org.apache.jackrabbit.api.security.authorization.PrivilegeCollection) Value(javax.jcr.Value) AccessControlException(javax.jcr.security.AccessControlException) RepositoryException(javax.jcr.RepositoryException) Privilege(javax.jcr.security.Privilege) JackrabbitAccessControlList(org.apache.jackrabbit.api.security.JackrabbitAccessControlList) TestPrincipal(org.apache.jackrabbit.core.security.TestPrincipal) Principal(java.security.Principal) AccessControlException(javax.jcr.security.AccessControlException) UnsupportedRepositoryOperationException(javax.jcr.UnsupportedRepositoryOperationException) RepositoryException(javax.jcr.RepositoryException) NotExecutableException(org.apache.jackrabbit.test.NotExecutableException)

Example 2 with PrivilegeCollection

use of org.apache.jackrabbit.api.security.authorization.PrivilegeCollection in project jackrabbit by apache.

the class AbstractACLTemplateTest method testRemoveInvalidEntry2.

public void testRemoveInvalidEntry2() throws RepositoryException {
    JackrabbitAccessControlList pt = createEmptyTemplate(getTestPath());
    try {
        pt.removeAccessControlEntry(new JackrabbitAccessControlEntry() {

            public boolean isAllow() {
                return false;
            }

            public int getPrivilegeBits() {
                return 0;
            }

            public String[] getRestrictionNames() {
                return new String[0];
            }

            public Value getRestriction(String restrictionName) {
                return null;
            }

            public Value[] getRestrictions(String restrictionName) throws RepositoryException {
                return null;
            }

            @Override
            public PrivilegeCollection getPrivilegeCollection() throws RepositoryException {
                throw new UnsupportedRepositoryOperationException();
            }

            public Principal getPrincipal() {
                return testPrincipal;
            }

            public Privilege[] getPrivileges() {
                return new Privilege[0];
            }
        });
        fail("Passing a ACE with invalid privileges should fail");
    } catch (AccessControlException e) {
    // success
    }
}
Also used : UnsupportedRepositoryOperationException(javax.jcr.UnsupportedRepositoryOperationException) JackrabbitAccessControlEntry(org.apache.jackrabbit.api.security.JackrabbitAccessControlEntry) PrivilegeCollection(org.apache.jackrabbit.api.security.authorization.PrivilegeCollection) Value(javax.jcr.Value) AccessControlException(javax.jcr.security.AccessControlException) RepositoryException(javax.jcr.RepositoryException) JackrabbitAccessControlList(org.apache.jackrabbit.api.security.JackrabbitAccessControlList) TestPrincipal(org.apache.jackrabbit.core.security.TestPrincipal) Principal(java.security.Principal)

Example 3 with PrivilegeCollection

use of org.apache.jackrabbit.api.security.authorization.PrivilegeCollection in project jackrabbit by apache.

the class AbstractEntryTest method testGetPrivilegeCollection.

public void testGetPrivilegeCollection() throws RepositoryException, NotExecutableException {
    JackrabbitAccessControlEntry entry = createEntry(new String[] { Privilege.JCR_READ, Privilege.JCR_WRITE }, true);
    PrivilegeCollection pc = entry.getPrivilegeCollection();
    assertArrayEquals(entry.getPrivileges(), pc.getPrivileges());
    assertTrue(pc.includes(Privilege.JCR_READ));
    assertTrue(pc.includes(Privilege.JCR_WRITE));
    assertTrue(pc.includes(Privilege.JCR_READ, Privilege.JCR_WRITE));
    assertTrue(pc.includes(Privilege.JCR_READ, Privilege.JCR_MODIFY_PROPERTIES, Privilege.JCR_REMOVE_CHILD_NODES));
    assertFalse(pc.includes(Privilege.JCR_READ, Privilege.JCR_LIFECYCLE_MANAGEMENT));
    assertFalse(pc.includes(Privilege.JCR_VERSION_MANAGEMENT));
    assertFalse(pc.includes(Privilege.JCR_ALL));
}
Also used : JackrabbitAccessControlEntry(org.apache.jackrabbit.api.security.JackrabbitAccessControlEntry) PrivilegeCollection(org.apache.jackrabbit.api.security.authorization.PrivilegeCollection)

Aggregations

JackrabbitAccessControlEntry (org.apache.jackrabbit.api.security.JackrabbitAccessControlEntry)3 PrivilegeCollection (org.apache.jackrabbit.api.security.authorization.PrivilegeCollection)3 Principal (java.security.Principal)2 RepositoryException (javax.jcr.RepositoryException)2 UnsupportedRepositoryOperationException (javax.jcr.UnsupportedRepositoryOperationException)2 Value (javax.jcr.Value)2 AccessControlException (javax.jcr.security.AccessControlException)2 JackrabbitAccessControlList (org.apache.jackrabbit.api.security.JackrabbitAccessControlList)2 TestPrincipal (org.apache.jackrabbit.core.security.TestPrincipal)2 Privilege (javax.jcr.security.Privilege)1 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)1