Search in sources :

Example 1 with PrincipalProvider

use of org.apache.jackrabbit.core.security.principal.PrincipalProvider in project jackrabbit by apache.

the class DefaultSecurityManager method createDefaultPrincipalProvider.

/**
     * Creates the default principal provider used to create the
     * {@link PrincipalProviderRegistry}.
     * 
     * @return An new instance of <code>DefaultPrincipalProvider</code>.
     * @throws RepositoryException If an error occurs.
     */
protected PrincipalProvider createDefaultPrincipalProvider(Properties[] moduleConfig) throws RepositoryException {
    boolean initialized = false;
    PrincipalProvider defaultPP = new DefaultPrincipalProvider(this.systemSession, (UserManagerImpl) systemUserManager);
    for (Properties props : moduleConfig) {
        //GRANITE-4470: apply config to DefaultPrincipalProvider if there is no explicit PrincipalProvider configured
        if (!props.containsKey(LoginModuleConfig.PARAM_PRINCIPAL_PROVIDER_CLASS) && props.containsKey(AbstractPrincipalProvider.MAXSIZE_KEY)) {
            defaultPP.init(props);
            initialized = true;
            break;
        }
    }
    if (!initialized) {
        defaultPP.init(new Properties());
    }
    return defaultPP;
}
Also used : AbstractPrincipalProvider(org.apache.jackrabbit.core.security.principal.AbstractPrincipalProvider) DefaultPrincipalProvider(org.apache.jackrabbit.core.security.principal.DefaultPrincipalProvider) PrincipalProvider(org.apache.jackrabbit.core.security.principal.PrincipalProvider) DefaultPrincipalProvider(org.apache.jackrabbit.core.security.principal.DefaultPrincipalProvider) Properties(java.util.Properties)

Example 2 with PrincipalProvider

use of org.apache.jackrabbit.core.security.principal.PrincipalProvider in project jackrabbit by apache.

the class SimpleSecurityManager method init.

//------------------------------------------< JackrabbitSecurityManager >---
/**
     * @see JackrabbitSecurityManager#init(Repository, Session)
     */
public void init(Repository repository, Session systemSession) throws RepositoryException {
    if (initialized) {
        throw new IllegalStateException("already initialized");
    }
    if (!(repository instanceof RepositoryImpl)) {
        throw new RepositoryException("RepositoryImpl expected");
    }
    this.systemSession = systemSession;
    config = ((RepositoryImpl) repository).getConfig().getSecurityConfig();
    // read the LoginModule configuration
    LoginModuleConfig loginModConf = config.getLoginModuleConfig();
    authCtxProvider = new AuthContextProvider(config.getAppName(), loginModConf);
    if (authCtxProvider.isLocal()) {
        log.info("init: using Repository LoginModule configuration for " + config.getAppName());
    } else if (authCtxProvider.isJAAS()) {
        log.info("init: using JAAS LoginModule configuration for " + config.getAppName());
    } else {
        String msg = "No valid LoginModule configuriation for " + config.getAppName();
        log.error(msg);
        throw new RepositoryException(msg);
    }
    Properties[] moduleConfig = authCtxProvider.getModuleConfig();
    // retrieve default-ids (admin and anonymous) from login-module-configuration.
    for (Properties aModuleConfig1 : moduleConfig) {
        if (aModuleConfig1.containsKey(LoginModuleConfig.PARAM_ADMIN_ID)) {
            adminID = aModuleConfig1.getProperty(LoginModuleConfig.PARAM_ADMIN_ID);
        }
        if (aModuleConfig1.containsKey(LoginModuleConfig.PARAM_ANONYMOUS_ID)) {
            anonymID = aModuleConfig1.getProperty(LoginModuleConfig.PARAM_ANONYMOUS_ID);
        }
    }
    // fallback:
    if (adminID == null) {
        log.debug("No adminID defined in LoginModule/JAAS config -> using default.");
        adminID = SecurityConstants.ADMIN_ID;
    }
    if (anonymID == null) {
        log.debug("No anonymousID defined in LoginModule/JAAS config -> using default.");
        anonymID = SecurityConstants.ANONYMOUS_ID;
    }
    // most simple principal provider registry, that does not read anything
    // from configuration
    PrincipalProvider principalProvider = new SimplePrincipalProvider();
    // skip init of provider (nop)
    principalProviderRegistry = new ProviderRegistryImpl(principalProvider);
    // register all configured principal providers.
    for (Properties aModuleConfig : moduleConfig) {
        principalProviderRegistry.registerProvider(aModuleConfig);
    }
    SecurityManagerConfig smc = config.getSecurityManagerConfig();
    if (smc != null && smc.getWorkspaceAccessConfig() != null) {
        workspaceAccessManager = smc.getWorkspaceAccessConfig().newInstance(WorkspaceAccessManager.class);
    } else {
        // fallback -> the default simple implementation
        log.debug("No WorkspaceAccessManager configured; using default.");
        workspaceAccessManager = new SimpleWorkspaceAccessManager();
    }
    workspaceAccessManager.init(systemSession);
    initialized = true;
}
Also used : PrincipalProvider(org.apache.jackrabbit.core.security.principal.PrincipalProvider) RepositoryException(javax.jcr.RepositoryException) Properties(java.util.Properties) AuthContextProvider(org.apache.jackrabbit.core.security.authentication.AuthContextProvider) LoginModuleConfig(org.apache.jackrabbit.core.config.LoginModuleConfig) RepositoryImpl(org.apache.jackrabbit.core.RepositoryImpl) SecurityManagerConfig(org.apache.jackrabbit.core.config.SecurityManagerConfig) WorkspaceAccessManager(org.apache.jackrabbit.core.security.authorization.WorkspaceAccessManager) ProviderRegistryImpl(org.apache.jackrabbit.core.security.principal.ProviderRegistryImpl)

Example 3 with PrincipalProvider

use of org.apache.jackrabbit.core.security.principal.PrincipalProvider in project jackrabbit by apache.

the class SecurityConfigTest method testPrincipalProviderConfig.

/**
     * 
     * @throws Exception
     */
public void testPrincipalProviderConfig() throws Exception {
    PrincipalProviderRegistry ppr = new ProviderRegistryImpl(null);
    // standard config
    Element xml = parseXML(new InputSource(new StringReader(PRINCIPAL_PROVIDER_CONFIG)), true);
    LoginModuleConfig lmc = parser.parseSecurityConfig(xml).getLoginModuleConfig();
    PrincipalProvider pp = ppr.registerProvider(lmc.getParameters());
    assertEquals(pp, ppr.getProvider(pp.getClass().getName()));
    assertEquals("org.apache.jackrabbit.core.security.principal.FallbackPrincipalProvider", pp.getClass().getName());
    // config specifying an extra name
    xml = parseXML(new InputSource(new StringReader(PRINCIPAL_PROVIDER_CONFIG1)), true);
    lmc = parser.parseSecurityConfig(xml).getLoginModuleConfig();
    pp = ppr.registerProvider(lmc.getParameters());
    assertEquals(pp, ppr.getProvider("test"));
    assertEquals("org.apache.jackrabbit.core.security.principal.FallbackPrincipalProvider", pp.getClass().getName());
    // use alternative class config
    xml = parseXML(new InputSource(new StringReader(PRINCIPAL_PROVIDER_CONFIG2)), true);
    lmc = parser.parseSecurityConfig(xml).getLoginModuleConfig();
    pp = ppr.registerProvider(lmc.getParameters());
    assertEquals(pp, ppr.getProvider("test2"));
    assertEquals("org.apache.jackrabbit.core.security.principal.FallbackPrincipalProvider", pp.getClass().getName());
    // all 3 providers must be registered despite the fact the all configs
    // specify the same provider class
    assertEquals(3, ppr.getProviders().length);
}
Also used : InputSource(org.xml.sax.InputSource) PrincipalProvider(org.apache.jackrabbit.core.security.principal.PrincipalProvider) Element(org.w3c.dom.Element) StringReader(java.io.StringReader) PrincipalProviderRegistry(org.apache.jackrabbit.core.security.principal.PrincipalProviderRegistry) ProviderRegistryImpl(org.apache.jackrabbit.core.security.principal.ProviderRegistryImpl)

Example 4 with PrincipalProvider

use of org.apache.jackrabbit.core.security.principal.PrincipalProvider in project sling by apache.

the class PrincipalProviderTracker method addingService.

//~-------------------------------------< ServiceTracker >
@Override
public Object addingService(ServiceReference reference) {
    PrincipalProvider provider = (PrincipalProvider) super.addingService(reference);
    addProvider(provider, reference);
    reloadProviders();
    return provider;
}
Also used : PrincipalProvider(org.apache.jackrabbit.core.security.principal.PrincipalProvider)

Example 5 with PrincipalProvider

use of org.apache.jackrabbit.core.security.principal.PrincipalProvider in project jackrabbit by apache.

the class UserPerWorkspaceSecurityManager method getPrincipalProviderRegistry.

private PrincipalProviderRegistry getPrincipalProviderRegistry(SessionImpl s) throws RepositoryException {
    String wspName = s.getWorkspace().getName();
    synchronized (monitor) {
        PrincipalProviderRegistry p = ppRegistries.get(wspName);
        if (p == null) {
            SystemSession systemSession;
            if (s instanceof SystemSession) {
                systemSession = (SystemSession) s;
            } else {
                RepositoryImpl repo = (RepositoryImpl) getRepository();
                systemSession = repo.getSystemSession(wspName);
                // TODO: review again... this workaround is used in several places.
                repo.markWorkspaceActive(wspName);
            }
            Properties[] moduleConfig = new AuthContextProvider("", ((RepositoryImpl) getRepository()).getConfig().getSecurityConfig().getLoginModuleConfig()).getModuleConfig();
            PrincipalProvider defaultPP = new DefaultPrincipalProvider(systemSession, (UserManagerImpl) getUserManager(systemSession));
            boolean initialized = false;
            for (Properties props : moduleConfig) {
                //GRANITE-4470: apply config to DefaultPrincipalProvider if there is no explicit PrincipalProvider configured
                if (!props.containsKey(LoginModuleConfig.PARAM_PRINCIPAL_PROVIDER_CLASS) && props.containsKey(AbstractPrincipalProvider.MAXSIZE_KEY)) {
                    defaultPP.init(props);
                    initialized = true;
                    break;
                }
            }
            if (!initialized) {
                defaultPP.init(new Properties());
            }
            p = new WorkspaceBasedPrincipalProviderRegistry(defaultPP);
            ppRegistries.put(wspName, p);
        }
        return p;
    }
}
Also used : DefaultPrincipalProvider(org.apache.jackrabbit.core.security.principal.DefaultPrincipalProvider) AbstractPrincipalProvider(org.apache.jackrabbit.core.security.principal.AbstractPrincipalProvider) PrincipalProvider(org.apache.jackrabbit.core.security.principal.PrincipalProvider) DefaultPrincipalProvider(org.apache.jackrabbit.core.security.principal.DefaultPrincipalProvider) Properties(java.util.Properties) PrincipalProviderRegistry(org.apache.jackrabbit.core.security.principal.PrincipalProviderRegistry) AuthContextProvider(org.apache.jackrabbit.core.security.authentication.AuthContextProvider)

Aggregations

PrincipalProvider (org.apache.jackrabbit.core.security.principal.PrincipalProvider)6 Properties (java.util.Properties)4 AuthContextProvider (org.apache.jackrabbit.core.security.authentication.AuthContextProvider)3 AbstractPrincipalProvider (org.apache.jackrabbit.core.security.principal.AbstractPrincipalProvider)3 DefaultPrincipalProvider (org.apache.jackrabbit.core.security.principal.DefaultPrincipalProvider)3 ProviderRegistryImpl (org.apache.jackrabbit.core.security.principal.ProviderRegistryImpl)3 RepositoryException (javax.jcr.RepositoryException)2 LoginModuleConfig (org.apache.jackrabbit.core.config.LoginModuleConfig)2 SecurityManagerConfig (org.apache.jackrabbit.core.config.SecurityManagerConfig)2 WorkspaceAccessManager (org.apache.jackrabbit.core.security.authorization.WorkspaceAccessManager)2 PrincipalProviderRegistry (org.apache.jackrabbit.core.security.principal.PrincipalProviderRegistry)2 StringReader (java.io.StringReader)1 RepositoryImpl (org.apache.jackrabbit.core.RepositoryImpl)1 SecurityConfig (org.apache.jackrabbit.core.config.SecurityConfig)1 WorkspaceSecurityConfig (org.apache.jackrabbit.core.config.WorkspaceSecurityConfig)1 AccessControlProviderFactoryImpl (org.apache.jackrabbit.core.security.authorization.AccessControlProviderFactoryImpl)1 Element (org.w3c.dom.Element)1 InputSource (org.xml.sax.InputSource)1