Search in sources :

Example 6 with Configuration

use of javax.security.auth.login.Configuration in project zm-mailbox by Zimbra.

the class SaslAuthenticator method getLoginContext.

private LoginContext getLoginContext() throws LoginException {
    Map<String, String> options = new HashMap<String, String>();
    options.put("debug", Boolean.toString(config.getLogger().isDebugEnabled()));
    options.put("principal", getPrincipal());
    // options.put("useTicketCache", "true");
    // options.put("storeKey", "true");
    final AppConfigurationEntry ace = new AppConfigurationEntry(LOGIN_MODULE_NAME, AppConfigurationEntry.LoginModuleControlFlag.REQUIRED, options);
    Configuration config = new Configuration() {

        @Override
        public AppConfigurationEntry[] getAppConfigurationEntry(String name) {
            return new AppConfigurationEntry[] { ace };
        }

        @Override
        public void refresh() {
        }
    };
    return new LoginContext("krb5", null, new SaslCallbackHandler(), config);
}
Also used : AppConfigurationEntry(javax.security.auth.login.AppConfigurationEntry) LoginContext(javax.security.auth.login.LoginContext) Configuration(javax.security.auth.login.Configuration) HashMap(java.util.HashMap)

Example 7 with Configuration

use of javax.security.auth.login.Configuration in project jackrabbit-oak by apache.

the class TokenDefaultLoginModuleTest method getConfiguration.

@Override
protected Configuration getConfiguration() {
    return new Configuration() {

        @Override
        public AppConfigurationEntry[] getAppConfigurationEntry(String s) {
            AppConfigurationEntry tokenEntry = new AppConfigurationEntry(TokenLoginModule.class.getName(), AppConfigurationEntry.LoginModuleControlFlag.SUFFICIENT, Collections.<String, Object>emptyMap());
            AppConfigurationEntry defaultEntry = new AppConfigurationEntry(LoginModuleImpl.class.getName(), AppConfigurationEntry.LoginModuleControlFlag.REQUIRED, Collections.<String, Object>emptyMap());
            return new AppConfigurationEntry[] { tokenEntry, defaultEntry };
        }
    };
}
Also used : AppConfigurationEntry(javax.security.auth.login.AppConfigurationEntry) LoginModuleImpl(org.apache.jackrabbit.oak.security.authentication.user.LoginModuleImpl) Configuration(javax.security.auth.login.Configuration)

Example 8 with Configuration

use of javax.security.auth.login.Configuration in project jackrabbit-oak by apache.

the class GuestDefaultLoginModuleTest method getConfiguration.

@Override
protected Configuration getConfiguration() {
    return new Configuration() {

        @Override
        public AppConfigurationEntry[] getAppConfigurationEntry(String s) {
            AppConfigurationEntry guestEntry = new AppConfigurationEntry(GuestLoginModule.class.getName(), AppConfigurationEntry.LoginModuleControlFlag.OPTIONAL, Collections.<String, Object>emptyMap());
            AppConfigurationEntry defaultEntry = new AppConfigurationEntry(LoginModuleImpl.class.getName(), AppConfigurationEntry.LoginModuleControlFlag.REQUIRED, Collections.<String, Object>emptyMap());
            return new AppConfigurationEntry[] { guestEntry, defaultEntry };
        }
    };
}
Also used : AppConfigurationEntry(javax.security.auth.login.AppConfigurationEntry) LoginModuleImpl(org.apache.jackrabbit.oak.security.authentication.user.LoginModuleImpl) Configuration(javax.security.auth.login.Configuration) GuestLoginModule(org.apache.jackrabbit.oak.spi.security.authentication.GuestLoginModule)

Example 9 with Configuration

use of javax.security.auth.login.Configuration 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 10 with Configuration

use of javax.security.auth.login.Configuration in project camel by apache.

the class HdfsComponent method getJAASConfiguration.

static Configuration getJAASConfiguration() {
    Configuration auth = null;
    try {
        auth = Configuration.getConfiguration();
        LOG.trace("Existing JAAS Configuration {}", auth);
    } catch (SecurityException e) {
        LOG.trace("Cannot load existing JAAS configuration", e);
    }
    return auth;
}
Also used : Configuration(javax.security.auth.login.Configuration)

Aggregations

Configuration (javax.security.auth.login.Configuration)89 AppConfigurationEntry (javax.security.auth.login.AppConfigurationEntry)42 LoginContext (javax.security.auth.login.LoginContext)27 HashMap (java.util.HashMap)23 Subject (javax.security.auth.Subject)20 Test (org.junit.Test)16 IOException (java.io.IOException)13 LoginException (javax.security.auth.login.LoginException)12 CallbackHandler (javax.security.auth.callback.CallbackHandler)8 File (java.io.File)7 Principal (java.security.Principal)7 URI (java.net.URI)6 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)5 ArrayList (java.util.ArrayList)5 Test (org.junit.jupiter.api.Test)5 URIParameter (java.security.URIParameter)4 Map (java.util.Map)4 Callback (javax.security.auth.callback.Callback)4 PasswordCallback (javax.security.auth.callback.PasswordCallback)4 LoginModuleImpl (org.apache.jackrabbit.oak.security.authentication.user.LoginModuleImpl)4