Search in sources :

Example 1 with SimpleSecurityManager

use of org.apache.jackrabbit.core.security.simple.SimpleSecurityManager in project jackrabbit by apache.

the class SecurityConfigTest method testConfig1.

public void testConfig1() throws ConfigurationException {
    Element xml = parseXML(new InputSource(new StringReader(CONFIG_1)), 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 SimpleSecurityManager);
    assertNull(smc.getWorkspaceAccessConfig());
    assertNull(smc.getWorkspaceName());
    assertNotNull(config.getAccessManagerConfig());
    assertTrue(config.getAccessManagerConfig().newInstance(AccessManager.class) instanceof SimpleAccessManager);
    assertNull(config.getLoginModuleConfig());
}
Also used : InputSource(org.xml.sax.InputSource) SimpleAccessManager(org.apache.jackrabbit.core.security.simple.SimpleAccessManager) Element(org.w3c.dom.Element) StringReader(java.io.StringReader) SimpleSecurityManager(org.apache.jackrabbit.core.security.simple.SimpleSecurityManager)

Example 2 with SimpleSecurityManager

use of org.apache.jackrabbit.core.security.simple.SimpleSecurityManager in project jackrabbit by apache.

the class RepositoryImpl method initSecurityManager.

/**
     * Creates the {@link org.apache.jackrabbit.core.security.JackrabbitSecurityManager SecurityManager}
     * of this <code>Repository</code> and adds it to the repository context.
     *
     * @throws RepositoryException if an error occurs.
     */
private synchronized void initSecurityManager() throws RepositoryException {
    SecurityManagerConfig smc = getConfig().getSecurityConfig().getSecurityManagerConfig();
    if (smc == null) {
        log.debug("No configuration entry for SecurityManager. Using org.apache.jackrabbit.core.security.simple.SimpleSecurityManager");
        securityMgr = new SimpleSecurityManager();
    } else {
        securityMgr = smc.newInstance(JackrabbitSecurityManager.class);
    }
    log.info("SecurityManager = " + securityMgr.getClass());
    context.setSecurityManager(securityMgr);
    String workspaceName = getConfig().getDefaultWorkspaceName();
    if (smc != null && smc.getWorkspaceName() != null) {
        workspaceName = smc.getWorkspaceName();
    }
    // mark the workspace as 'active' for that it does not get disposed
    // by the workspace-janitor
    // TODO: There should be a cleaner way to do this
    markWorkspaceActive(workspaceName);
    // FIXME: Note that this call must be done *after* the security
    // manager has been added to the repository context, since the
    // initialisation code may invoke code that depends on the presence
    // of a security manager. It would be better if this was not the case.
    SystemSession systemSession = getSystemSession(workspaceName);
    securityMgr.init(this, systemSession);
    // initial security specific repository descriptors that are defined
    // by JackrabbitRepository
    ValueFactory vf = ValueFactoryImpl.getInstance();
    boolean hasUserMgt;
    try {
        securityMgr.getUserManager(systemSession);
        hasUserMgt = true;
    } catch (RepositoryException e) {
        hasUserMgt = false;
    }
    setDescriptor(JackrabbitRepository.OPTION_USER_MANAGEMENT_SUPPORTED, vf.createValue(hasUserMgt));
    boolean hasPrincipalMgt;
    try {
        securityMgr.getPrincipalManager(systemSession);
        hasPrincipalMgt = true;
    } catch (RepositoryException e) {
        hasPrincipalMgt = false;
    }
    setDescriptor(JackrabbitRepository.OPTION_PRINCIPAL_MANAGEMENT_SUPPORTED, vf.createValue(hasPrincipalMgt));
    setDescriptor(JackrabbitRepository.OPTION_PRIVILEGE_MANAGEMENT_SUPPORTED, vf.createValue(true));
}
Also used : JackrabbitSecurityManager(org.apache.jackrabbit.core.security.JackrabbitSecurityManager) SecurityManagerConfig(org.apache.jackrabbit.core.config.SecurityManagerConfig) RepositoryException(javax.jcr.RepositoryException) ValueFactory(javax.jcr.ValueFactory) SimpleSecurityManager(org.apache.jackrabbit.core.security.simple.SimpleSecurityManager)

Aggregations

SimpleSecurityManager (org.apache.jackrabbit.core.security.simple.SimpleSecurityManager)2 StringReader (java.io.StringReader)1 RepositoryException (javax.jcr.RepositoryException)1 ValueFactory (javax.jcr.ValueFactory)1 SecurityManagerConfig (org.apache.jackrabbit.core.config.SecurityManagerConfig)1 JackrabbitSecurityManager (org.apache.jackrabbit.core.security.JackrabbitSecurityManager)1 SimpleAccessManager (org.apache.jackrabbit.core.security.simple.SimpleAccessManager)1 Element (org.w3c.dom.Element)1 InputSource (org.xml.sax.InputSource)1