Search in sources :

Example 1 with CompiledPermissions

use of org.apache.jackrabbit.core.security.authorization.CompiledPermissions in project jackrabbit by apache.

the class UserAccessControlProviderTest method testAnonymousDefaultAccess.

public void testAnonymousDefaultAccess() throws Exception {
    Set<Principal> anonymousPrincipals = getAnonymousPrincipals();
    assertTrue(provider.canAccessRoot(anonymousPrincipals));
    CompiledPermissions cp = provider.compilePermissions(anonymousPrincipals);
    assertTrue(cp.canReadAll());
    assertFalse(CompiledPermissions.NO_PERMISSION.equals(cp));
}
Also used : CompiledPermissions(org.apache.jackrabbit.core.security.authorization.CompiledPermissions) Principal(java.security.Principal) ItemBasedPrincipal(org.apache.jackrabbit.api.security.principal.ItemBasedPrincipal)

Example 2 with CompiledPermissions

use of org.apache.jackrabbit.core.security.authorization.CompiledPermissions in project jackrabbit by apache.

the class UserAccessControlProviderTest method testAnonymousAccessDenied2.

public void testAnonymousAccessDenied2() throws Exception {
    Map<String, String> config = new HashMap<String, String>();
    config.put(UserAccessControlProvider.PARAM_ANONYMOUS_ACCESS, "false");
    config.put(UserAccessControlProvider.PARAM_ANONYMOUS_ID, "abc");
    AccessControlProvider p2 = new UserAccessControlProvider();
    try {
        p2.init(s, config);
        Principal princ = new Principal() {

            public String getName() {
                return "abc";
            }
        };
        Set<Principal> anonymousPrincipals = Collections.singleton(princ);
        assertFalse(p2.canAccessRoot(anonymousPrincipals));
        CompiledPermissions cp = p2.compilePermissions(anonymousPrincipals);
        try {
            assertEquals(CompiledPermissions.NO_PERMISSION, cp);
            assertFalse(cp.canReadAll());
            assertFalse(cp.grants(((NodeImpl) s.getRootNode()).getPrimaryPath(), Permission.READ));
        } finally {
            cp.close();
        }
    } finally {
        p2.close();
    }
}
Also used : NodeImpl(org.apache.jackrabbit.core.NodeImpl) HashMap(java.util.HashMap) AccessControlProvider(org.apache.jackrabbit.core.security.authorization.AccessControlProvider) CompiledPermissions(org.apache.jackrabbit.core.security.authorization.CompiledPermissions) Principal(java.security.Principal) ItemBasedPrincipal(org.apache.jackrabbit.api.security.principal.ItemBasedPrincipal)

Example 3 with CompiledPermissions

use of org.apache.jackrabbit.core.security.authorization.CompiledPermissions in project jackrabbit by apache.

the class UserAccessControlProviderTest method testNoNodeForPrincipal.

/**
     * @see <a href="https://issues.apache.org/jira/browse/JCR-2630">JCR-2630</a>
     */
public void testNoNodeForPrincipal() throws RepositoryException {
    final Principal testPrincipal = getTestPrincipal();
    String path = "/home/users/t/" + testPrincipal.getName();
    while (s.nodeExists(path)) {
        path += "_";
    }
    final String principalPath = path;
    List<Set<Principal>> principalSets = new ArrayList<Set<Principal>>();
    principalSets.add(Collections.<Principal>singleton(testPrincipal));
    principalSets.add(Collections.<Principal>singleton(new ItemBasedPrincipal() {

        public String getPath() {
            return principalPath;
        }

        public String getName() {
            return testPrincipal.getName();
        }
    }));
    Path rootPath = ((SessionImpl) s).getQPath("/");
    for (Set<Principal> principals : principalSets) {
        CompiledPermissions cp = provider.compilePermissions(principals);
        assertFalse(cp.canReadAll());
        assertFalse(cp.grants(rootPath, Permission.READ));
        assertTrue(cp.getPrivilegeSet(rootPath).isEmpty());
        assertSame(CompiledPermissions.NO_PERMISSION, cp);
    }
}
Also used : Path(org.apache.jackrabbit.spi.Path) Set(java.util.Set) HashSet(java.util.HashSet) ArrayList(java.util.ArrayList) ItemBasedPrincipal(org.apache.jackrabbit.api.security.principal.ItemBasedPrincipal) SessionImpl(org.apache.jackrabbit.core.SessionImpl) CompiledPermissions(org.apache.jackrabbit.core.security.authorization.CompiledPermissions) Principal(java.security.Principal) ItemBasedPrincipal(org.apache.jackrabbit.api.security.principal.ItemBasedPrincipal)

Example 4 with CompiledPermissions

use of org.apache.jackrabbit.core.security.authorization.CompiledPermissions in project jackrabbit by apache.

the class UserAccessControlProviderTest method testAnonymousAccessDenied.

public void testAnonymousAccessDenied() throws Exception {
    Map<String, String> config = new HashMap<String, String>();
    config.put(UserAccessControlProvider.PARAM_ANONYMOUS_ACCESS, "false");
    AccessControlProvider p2 = new UserAccessControlProvider();
    try {
        p2.init(s, config);
        Set<Principal> anonymousPrincipals = getAnonymousPrincipals();
        assertFalse(p2.canAccessRoot(anonymousPrincipals));
        CompiledPermissions cp = p2.compilePermissions(anonymousPrincipals);
        try {
            assertEquals(CompiledPermissions.NO_PERMISSION, cp);
            assertFalse(cp.canReadAll());
            assertFalse(cp.grants(((NodeImpl) s.getRootNode()).getPrimaryPath(), Permission.READ));
        } finally {
            cp.close();
        }
    } finally {
        p2.close();
    }
}
Also used : NodeImpl(org.apache.jackrabbit.core.NodeImpl) HashMap(java.util.HashMap) AccessControlProvider(org.apache.jackrabbit.core.security.authorization.AccessControlProvider) CompiledPermissions(org.apache.jackrabbit.core.security.authorization.CompiledPermissions) Principal(java.security.Principal) ItemBasedPrincipal(org.apache.jackrabbit.api.security.principal.ItemBasedPrincipal)

Example 5 with CompiledPermissions

use of org.apache.jackrabbit.core.security.authorization.CompiledPermissions in project jackrabbit by apache.

the class DefaultAccessManager method getPrivileges.

/**
     * @see org.apache.jackrabbit.api.security.JackrabbitAccessControlManager#getPrivileges(String, Set)
     */
public Privilege[] getPrivileges(String absPath, Set<Principal> principals) throws PathNotFoundException, RepositoryException {
    checkInitialized();
    checkValidNodePath(absPath);
    checkPermission(absPath, Permission.READ_AC);
    CompiledPermissions perms = acProvider.compilePermissions(principals);
    try {
        Set<Privilege> privs = perms.getPrivilegeSet(getPath(absPath));
        return privs.toArray(new Privilege[privs.size()]);
    } finally {
        perms.close();
    }
}
Also used : CompiledPermissions(org.apache.jackrabbit.core.security.authorization.CompiledPermissions) Privilege(javax.jcr.security.Privilege)

Aggregations

CompiledPermissions (org.apache.jackrabbit.core.security.authorization.CompiledPermissions)7 Principal (java.security.Principal)5 ItemBasedPrincipal (org.apache.jackrabbit.api.security.principal.ItemBasedPrincipal)5 Path (org.apache.jackrabbit.spi.Path)3 HashMap (java.util.HashMap)2 NodeImpl (org.apache.jackrabbit.core.NodeImpl)2 SessionImpl (org.apache.jackrabbit.core.SessionImpl)2 AccessControlProvider (org.apache.jackrabbit.core.security.authorization.AccessControlProvider)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 Privilege (javax.jcr.security.Privilege)1 User (org.apache.jackrabbit.api.security.user.User)1