Search in sources :

Example 1 with AccessControlProvider

use of org.apache.jackrabbit.core.security.authorization.AccessControlProvider 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 2 with AccessControlProvider

use of org.apache.jackrabbit.core.security.authorization.AccessControlProvider 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 3 with AccessControlProvider

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

the class CombinedProvider method getEditor.

/**
     * @see AccessControlProvider#getEditor(javax.jcr.Session)
     */
public AccessControlEditor getEditor(Session editingSession) {
    checkInitialized();
    List<AccessControlEditor> editors = new ArrayList<AccessControlEditor>();
    for (AccessControlProvider provider : providers) {
        try {
            editors.add(provider.getEditor(editingSession));
        } catch (RepositoryException e) {
            log.debug(e.getMessage());
        // ignore.
        }
    }
    if (!editors.isEmpty()) {
        return new CombinedEditor(editors.toArray(new AccessControlEditor[editors.size()]));
    } else {
        log.debug("None of the derived access control providers supports editing.");
        return null;
    }
}
Also used : ArrayList(java.util.ArrayList) AbstractAccessControlProvider(org.apache.jackrabbit.core.security.authorization.AbstractAccessControlProvider) AccessControlProvider(org.apache.jackrabbit.core.security.authorization.AccessControlProvider) RepositoryException(javax.jcr.RepositoryException) AccessControlEditor(org.apache.jackrabbit.core.security.authorization.AccessControlEditor)

Example 4 with AccessControlProvider

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

the class DefaultSecurityManager method getAccessManager.

/**
     * @see JackrabbitSecurityManager#getAccessManager(Session,AMContext)
     */
public AccessManager getAccessManager(Session session, AMContext amContext) throws RepositoryException {
    checkInitialized();
    AccessManagerConfig amConfig = repository.getConfig().getSecurityConfig().getAccessManagerConfig();
    try {
        String wspName = session.getWorkspace().getName();
        AccessControlProvider pp = getAccessControlProvider(wspName);
        AccessManager accessMgr;
        if (amConfig == null) {
            log.debug("No configuration entry for AccessManager. Using org.apache.jackrabbit.core.security.DefaultAccessManager");
            accessMgr = new DefaultAccessManager();
        } else {
            accessMgr = amConfig.newInstance(AccessManager.class);
        }
        accessMgr.init(amContext, pp, workspaceAccessManager);
        return accessMgr;
    } catch (AccessDeniedException e) {
        // re-throw
        throw e;
    } catch (Exception e) {
        // wrap in RepositoryException
        String clsName = (amConfig == null) ? "-- missing access manager configuration --" : amConfig.getClassName();
        String msg = "Failed to instantiate AccessManager (" + clsName + ")";
        log.error(msg, e);
        throw new RepositoryException(msg, e);
    }
}
Also used : AccessManager(org.apache.jackrabbit.core.security.AccessManager) WorkspaceAccessManager(org.apache.jackrabbit.core.security.authorization.WorkspaceAccessManager) DefaultAccessManager(org.apache.jackrabbit.core.security.DefaultAccessManager) AccessDeniedException(javax.jcr.AccessDeniedException) AccessManagerConfig(org.apache.jackrabbit.core.config.AccessManagerConfig) AccessControlProvider(org.apache.jackrabbit.core.security.authorization.AccessControlProvider) RepositoryException(javax.jcr.RepositoryException) DefaultAccessManager(org.apache.jackrabbit.core.security.DefaultAccessManager) NoSuchWorkspaceException(javax.jcr.NoSuchWorkspaceException) AccessDeniedException(javax.jcr.AccessDeniedException) AccessControlException(javax.jcr.security.AccessControlException) RepositoryException(javax.jcr.RepositoryException)

Example 5 with AccessControlProvider

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

the class DefaultSecurityManager method getAccessControlProvider.

//--------------------------------------------------------------------------
/**
     * Returns the access control provider for the specified
     * <code>workspaceName</code>.
     *
     * @param workspaceName Name of the workspace.
     * @return access control provider
     * @throws NoSuchWorkspaceException If no workspace with 'workspaceName' exists.
     * @throws RepositoryException
     */
private AccessControlProvider getAccessControlProvider(String workspaceName) throws NoSuchWorkspaceException, RepositoryException {
    checkInitialized();
    AccessControlProvider provider = acProviders.get(workspaceName);
    if (provider == null || !provider.isLive()) {
        // mark this workspace as 'active' so the workspace does not
        // get disposed by the workspace-janitor
        // TODO: There should be a cleaner way to do this.
        repository.markWorkspaceActive(workspaceName);
        WorkspaceSecurityConfig secConf = null;
        WorkspaceConfig conf = repository.getConfig().getWorkspaceConfig(workspaceName);
        if (conf != null) {
            secConf = conf.getSecurityConfig();
        }
        provider = acProviderFactory.createProvider(repository.getSystemSession(workspaceName), secConf);
        synchronized (acProviders) {
            acProviders.put(workspaceName, provider);
        }
    }
    return provider;
}
Also used : WorkspaceSecurityConfig(org.apache.jackrabbit.core.config.WorkspaceSecurityConfig) AccessControlProvider(org.apache.jackrabbit.core.security.authorization.AccessControlProvider) WorkspaceConfig(org.apache.jackrabbit.core.config.WorkspaceConfig)

Aggregations

AccessControlProvider (org.apache.jackrabbit.core.security.authorization.AccessControlProvider)6 RepositoryException (javax.jcr.RepositoryException)3 Principal (java.security.Principal)2 HashMap (java.util.HashMap)2 AccessDeniedException (javax.jcr.AccessDeniedException)2 ItemBasedPrincipal (org.apache.jackrabbit.api.security.principal.ItemBasedPrincipal)2 NodeImpl (org.apache.jackrabbit.core.NodeImpl)2 AccessManagerConfig (org.apache.jackrabbit.core.config.AccessManagerConfig)2 AccessManager (org.apache.jackrabbit.core.security.AccessManager)2 CompiledPermissions (org.apache.jackrabbit.core.security.authorization.CompiledPermissions)2 WorkspaceAccessManager (org.apache.jackrabbit.core.security.authorization.WorkspaceAccessManager)2 ArrayList (java.util.ArrayList)1 NoSuchWorkspaceException (javax.jcr.NoSuchWorkspaceException)1 UnsupportedRepositoryOperationException (javax.jcr.UnsupportedRepositoryOperationException)1 AccessControlException (javax.jcr.security.AccessControlException)1 WorkspaceConfig (org.apache.jackrabbit.core.config.WorkspaceConfig)1 WorkspaceSecurityConfig (org.apache.jackrabbit.core.config.WorkspaceSecurityConfig)1 DefaultAccessManager (org.apache.jackrabbit.core.security.DefaultAccessManager)1 AbstractAccessControlProvider (org.apache.jackrabbit.core.security.authorization.AbstractAccessControlProvider)1 AccessControlEditor (org.apache.jackrabbit.core.security.authorization.AccessControlEditor)1