Search in sources :

Example 1 with BeanConfig

use of org.apache.jackrabbit.core.config.BeanConfig in project sling by apache.

the class DelegatingLoginModule method initialize.

public void initialize(Subject subject, CallbackHandler callbackHandler, Map<String, ?> sharedState, Map<String, ?> options) {
    Configuration config = null;
    try {
        config = Configuration.getInstance(JAAS_CONFIG_ALGO_NAME, null, providerName);
    } catch (NoSuchProviderException e) {
        logger.debug("No provider " + providerName + "found so far", e);
    } catch (NoSuchAlgorithmException e) {
        logger.debug("No provider " + providerName + "found so far for fetching JAAS " + "config with algorithm name " + JAAS_CONFIG_ALGO_NAME, e);
    }
    if (config != null) {
        final Thread current = Thread.currentThread();
        final ClassLoader orig = current.getContextClassLoader();
        try {
            current.setContextClassLoader(DelegatingLoginModule.class.getClassLoader());
            loginContext = new LoginContext(appName, subject, callbackHandler, config);
        } catch (LoginException e) {
            loginException = e;
        } finally {
            current.setContextClassLoader(orig);
        }
    } else {
        //No support so far from OSGi so would use default logic used by Jackrabbit
        //to construct the LoginModule
        Properties p = new Properties();
        p.putAll(options);
        BeanConfig bc = new BeanConfig(delegateLoginModuleClass, p);
        LoginModuleConfig lmc = new LoginModuleConfig(bc);
        try {
            delegate = lmc.getLoginModule();
            delegate.initialize(subject, callbackHandler, sharedState, options);
            logger.info("No JAAS Configuration provider found would be directly invoking LoginModule {}", delegateLoginModuleClass);
        } catch (ConfigurationException e) {
            //Behaviour is same as org.apache.jackrabbit.core.security.authentication.LocalAuthContext.login()
            loginException = new LoginException(e.getMessage());
        }
    }
}
Also used : BeanConfig(org.apache.jackrabbit.core.config.BeanConfig) LoginContext(javax.security.auth.login.LoginContext) Configuration(javax.security.auth.login.Configuration) ConfigurationException(org.apache.jackrabbit.core.config.ConfigurationException) LoginModuleConfig(org.apache.jackrabbit.core.config.LoginModuleConfig) LoginException(javax.security.auth.login.LoginException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) NoSuchProviderException(java.security.NoSuchProviderException) Properties(java.util.Properties)

Example 2 with BeanConfig

use of org.apache.jackrabbit.core.config.BeanConfig in project jackrabbit by apache.

the class AccessControlProviderFactoryImpl method createProvider.

/**
     * @see AccessControlProviderFactory#createProvider(Session, WorkspaceSecurityConfig)
     */
public AccessControlProvider createProvider(Session systemSession, WorkspaceSecurityConfig config) throws RepositoryException {
    String workspaceName = systemSession.getWorkspace().getName();
    AccessControlProvider prov;
    Map props;
    if (config != null && config.getAccessControlProviderConfig() != null) {
        BeanConfig bc = config.getAccessControlProviderConfig();
        prov = bc.newInstance(AccessControlProvider.class);
        props = bc.getParameters();
    } else {
        log.debug("No ac-provider configuration for workspace " + workspaceName + " -> using defaults.");
        if (workspaceName.equals(secWorkspaceName) && !workspaceName.equals(defaultWorkspaceName)) {
            // UserAccessControlProvider is designed to work with an extra
            // workspace storing user and groups. therefore avoid returning
            // this ac provider for the default workspace.
            prov = new UserAccessControlProvider();
        } else {
            prov = new ACLProvider();
        }
        log.debug("Default provider for workspace " + workspaceName + " = " + prov.getClass().getName());
        props = Collections.emptyMap();
    }
    prov.init(systemSession, props);
    return prov;
}
Also used : BeanConfig(org.apache.jackrabbit.core.config.BeanConfig) UserAccessControlProvider(org.apache.jackrabbit.core.security.user.UserAccessControlProvider) ACLProvider(org.apache.jackrabbit.core.security.authorization.acl.ACLProvider) UserAccessControlProvider(org.apache.jackrabbit.core.security.user.UserAccessControlProvider) Map(java.util.Map)

Aggregations

BeanConfig (org.apache.jackrabbit.core.config.BeanConfig)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 NoSuchProviderException (java.security.NoSuchProviderException)1 Map (java.util.Map)1 Properties (java.util.Properties)1 Configuration (javax.security.auth.login.Configuration)1 LoginContext (javax.security.auth.login.LoginContext)1 LoginException (javax.security.auth.login.LoginException)1 ConfigurationException (org.apache.jackrabbit.core.config.ConfigurationException)1 LoginModuleConfig (org.apache.jackrabbit.core.config.LoginModuleConfig)1 ACLProvider (org.apache.jackrabbit.core.security.authorization.acl.ACLProvider)1 UserAccessControlProvider (org.apache.jackrabbit.core.security.user.UserAccessControlProvider)1