Search in sources :

Example 1 with DefaultAccessManager

use of org.apache.jackrabbit.core.security.DefaultAccessManager in project jackrabbit by apache.

the class SecurityConfigTest method testConfig2.

public void testConfig2() throws ConfigurationException {
    Element xml = parseXML(new InputSource(new StringReader(CONFIG_2)), true);
    SecurityConfig config = parser.parseSecurityConfig(xml);
    assertNotNull(config.getAppName());
    assertEquals("Jackrabbit", config.getAppName());
    SecurityManagerConfig smc = config.getSecurityManagerConfig();
    assertNotNull(smc);
    assertTrue(smc.newInstance(JackrabbitSecurityManager.class) instanceof DefaultSecurityManager);
    assertNull(smc.getWorkspaceAccessConfig());
    assertEquals("security", smc.getWorkspaceName());
    assertNull(smc.getUserManagerConfig());
    AccessManagerConfig amc = config.getAccessManagerConfig();
    assertNotNull(amc);
    assertTrue(amc.newInstance(AccessManager.class) instanceof DefaultAccessManager);
    LoginModuleConfig lmc = config.getLoginModuleConfig();
    assertNotNull(lmc);
    assertTrue(lmc.getLoginModule() instanceof DefaultLoginModule);
    Properties options = lmc.getParameters();
    assertNotNull(options);
    assertEquals("anonymous", options.getProperty("anonymousId"));
    assertEquals("admin", options.getProperty("adminId"));
    assertEquals("org.apache.jackrabbit.TestPrincipalProvider", options.getProperty("principalProvider"));
}
Also used : InputSource(org.xml.sax.InputSource) Element(org.w3c.dom.Element) StringReader(java.io.StringReader) DefaultSecurityManager(org.apache.jackrabbit.core.DefaultSecurityManager) DefaultLoginModule(org.apache.jackrabbit.core.security.authentication.DefaultLoginModule) Properties(java.util.Properties) DefaultAccessManager(org.apache.jackrabbit.core.security.DefaultAccessManager)

Example 2 with DefaultAccessManager

use of org.apache.jackrabbit.core.security.DefaultAccessManager 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)

Aggregations

DefaultAccessManager (org.apache.jackrabbit.core.security.DefaultAccessManager)2 StringReader (java.io.StringReader)1 Properties (java.util.Properties)1 AccessDeniedException (javax.jcr.AccessDeniedException)1 NoSuchWorkspaceException (javax.jcr.NoSuchWorkspaceException)1 RepositoryException (javax.jcr.RepositoryException)1 AccessControlException (javax.jcr.security.AccessControlException)1 DefaultSecurityManager (org.apache.jackrabbit.core.DefaultSecurityManager)1 AccessManagerConfig (org.apache.jackrabbit.core.config.AccessManagerConfig)1 AccessManager (org.apache.jackrabbit.core.security.AccessManager)1 DefaultLoginModule (org.apache.jackrabbit.core.security.authentication.DefaultLoginModule)1 AccessControlProvider (org.apache.jackrabbit.core.security.authorization.AccessControlProvider)1 WorkspaceAccessManager (org.apache.jackrabbit.core.security.authorization.WorkspaceAccessManager)1 Element (org.w3c.dom.Element)1 InputSource (org.xml.sax.InputSource)1