Search in sources :

Example 46 with AppConfigurationEntry

use of javax.security.auth.login.AppConfigurationEntry in project cxf by apache.

the class JAASLoginInterceptorTest method createTestJaasLoginInterceptor.

private JAASLoginInterceptor createTestJaasLoginInterceptor() {
    JAASLoginInterceptor jaasInt = new JAASLoginInterceptor();
    jaasInt.setReportFault(true);
    Configuration config = new Configuration() {

        @Override
        public AppConfigurationEntry[] getAppConfigurationEntry(String name) {
            Map<String, String> options = new HashMap<>();
            AppConfigurationEntry configEntry = new AppConfigurationEntry(TestUserPasswordLoginModule.class.getName(), LoginModuleControlFlag.REQUIRED, options);
            return Collections.singleton(configEntry).toArray(new AppConfigurationEntry[] {});
        }
    };
    jaasInt.setLoginConfig(config);
    return jaasInt;
}
Also used : AppConfigurationEntry(javax.security.auth.login.AppConfigurationEntry) Configuration(javax.security.auth.login.Configuration) HashMap(java.util.HashMap)

Example 47 with AppConfigurationEntry

use of javax.security.auth.login.AppConfigurationEntry in project Payara by payara.

the class AuthenticationServiceImpl method initialize.

/**
 * Initialize the Authentication Service configuration.
 *
 * Create the JAAS Configuration using the specified LoginModule configurations
 */
@Override
public void initialize(SecurityConfiguration securityServiceConfiguration) {
    // org.glassfish.security.services.config.AuthenticationService as = (org.glassfish.security.services.config.AuthenticationService) securityServiceConfiguration;
    // LOG.info("*** AuthenticationServiceImpl auth svc file realm provider module class: ");
    // for (SecurityProvider sp : as.getSecurityProviders()) {
    // LOG.info("   *** Provider name/type" + sp.getName() + "/" + sp.getType());
    // if (sp.getSecurityProviderConfig() == null) {
    // LOG.info("   *** getSecurityProviderConfig returned null");
    // } else {
    // for (SecurityProviderConfig spc : sp.getSecurityProviderConfig()) {
    // LOG.info("      *** " + spc.getName());
    // if (sp.getType().equals("LoginModule")) {
    // LoginModuleConfig lmc = (LoginModuleConfig) spc;
    // LOG.info("      *** LoginModule config: class is " + lmc.getModuleClass());
    // }
    // }
    // }
    // }
    config = (org.glassfish.security.services.config.AuthenticationService) securityServiceConfiguration;
    if (config == null)
        return;
    // JAAS LoginContext Name
    name = config.getName();
    // Determine if handling Realm password credential
    usePasswordCredential = Boolean.valueOf(config.getUsePasswordCredential());
    // Build JAAS Configuration based on the individual LoginModuleConfig settings
    List<SecurityProvider> providers = config.getSecurityProviders();
    if (providers != null) {
        ArrayList<AppConfigurationEntry> lmEntries = new ArrayList<AppConfigurationEntry>();
        for (SecurityProvider provider : providers) {
            // If the provider is a LoginModule look for the LoginModuleConfig
            if ("LoginModule".equalsIgnoreCase(provider.getType())) {
                List<SecurityProviderConfig> providerConfig = provider.getSecurityProviderConfig();
                if ((providerConfig != null) && (!providerConfig.isEmpty())) {
                    // Create the JAAS AppConfigurationEntry from the LoginModule settings
                    LoginModuleConfig lmConfig = (LoginModuleConfig) providerConfig.get(0);
                    Map<String, ?> lmOptions = lmConfig.getModuleOptions();
                    lmEntries.add(new AppConfigurationEntry(lmConfig.getModuleClass(), getLoginModuleControlFlag(lmConfig.getControlFlag()), lmOptions));
                    // Use the first LoginModule with auth-realm (i.e. unable to stack Realms)
                    if (usePasswordCredential && (realmName == null)) {
                        String authRealm = (String) lmOptions.get("auth-realm");
                        if ((authRealm != null) && (!authRealm.isEmpty()))
                            realmName = authRealm;
                    }
                }
            }
        }
        if (!lmEntries.isEmpty())
            configuration = new AuthenticationJaasConfiguration(name, lmEntries);
    }
    // TODO - Reconcile initialization with SecurityLifeCycle
    if (usePasswordCredential && (realmName != null)) {
        RealmsManager realmsManager = locator.getService(RealmsManager.class);
        realmsManager.createRealms();
    }
}
Also used : ArrayList(java.util.ArrayList) AppConfigurationEntry(javax.security.auth.login.AppConfigurationEntry) RealmsManager(com.sun.enterprise.security.auth.realm.RealmsManager) LoginModuleConfig(org.glassfish.security.services.config.LoginModuleConfig) SecurityProvider(org.glassfish.security.services.config.SecurityProvider) SecurityProviderConfig(org.glassfish.security.services.config.SecurityProviderConfig)

Example 48 with AppConfigurationEntry

use of javax.security.auth.login.AppConfigurationEntry in project kafka by apache.

the class TestJaasConfig method createOrUpdateEntry.

public void createOrUpdateEntry(String name, String loginModule, Map<String, Object> options) {
    AppConfigurationEntry entry = new AppConfigurationEntry(loginModule, LoginModuleControlFlag.REQUIRED, options);
    entryMap.put(name, new AppConfigurationEntry[] { entry });
}
Also used : AppConfigurationEntry(javax.security.auth.login.AppConfigurationEntry)

Example 49 with AppConfigurationEntry

use of javax.security.auth.login.AppConfigurationEntry in project kafka by apache.

the class JaasContextTest method checkConfiguration.

private void checkConfiguration(String jaasConfigProp, String loginModule, LoginModuleControlFlag controlFlag, Map<String, Object> options) throws Exception {
    AppConfigurationEntry dynamicEntry = configurationEntry(JaasContext.Type.CLIENT, jaasConfigProp);
    checkEntry(dynamicEntry, loginModule, controlFlag, options);
    assertNull("Static configuration updated", Configuration.getConfiguration().getAppConfigurationEntry(JaasContext.Type.CLIENT.name()));
    writeConfiguration(JaasContext.Type.SERVER.name(), jaasConfigProp);
    AppConfigurationEntry staticEntry = configurationEntry(JaasContext.Type.SERVER, null);
    checkEntry(staticEntry, loginModule, controlFlag, options);
}
Also used : AppConfigurationEntry(javax.security.auth.login.AppConfigurationEntry)

Example 50 with AppConfigurationEntry

use of javax.security.auth.login.AppConfigurationEntry in project hbase by apache.

the class DemoClient method getSubject.

static Subject getSubject() throws Exception {
    if (!secure)
        return new Subject();
    /*
     * To authenticate the DemoClient, kinit should be invoked ahead.
     * Here we try to get the Kerberos credential from the ticket cache.
     */
    LoginContext context = new LoginContext("", new Subject(), null, new Configuration() {

        @Override
        public AppConfigurationEntry[] getAppConfigurationEntry(String name) {
            Map<String, String> options = new HashMap<>();
            options.put("useKeyTab", "false");
            options.put("storeKey", "false");
            options.put("doNotPrompt", "true");
            options.put("useTicketCache", "true");
            options.put("renewTGT", "true");
            options.put("refreshKrb5Config", "true");
            options.put("isInitiator", "true");
            String ticketCache = System.getenv("KRB5CCNAME");
            if (ticketCache != null) {
                options.put("ticketCache", ticketCache);
            }
            options.put("debug", "true");
            return new AppConfigurationEntry[] { new AppConfigurationEntry("com.sun.security.auth.module.Krb5LoginModule", AppConfigurationEntry.LoginModuleControlFlag.REQUIRED, options) };
        }
    });
    context.login();
    return context.getSubject();
}
Also used : AppConfigurationEntry(javax.security.auth.login.AppConfigurationEntry) LoginContext(javax.security.auth.login.LoginContext) HBaseConfiguration(org.apache.hadoop.hbase.HBaseConfiguration) Configuration(javax.security.auth.login.Configuration) HashMap(java.util.HashMap) Map(java.util.Map) Subject(javax.security.auth.Subject)

Aggregations

AppConfigurationEntry (javax.security.auth.login.AppConfigurationEntry)76 HashMap (java.util.HashMap)31 Configuration (javax.security.auth.login.Configuration)26 Map (java.util.Map)13 Test (org.junit.Test)11 Subject (javax.security.auth.Subject)10 LoginContext (javax.security.auth.login.LoginContext)10 SSOException (com.iplanet.sso.SSOException)7 SMSException (com.sun.identity.sm.SMSException)7 HashSet (java.util.HashSet)7 JaasRealm (org.apache.karaf.jaas.config.JaasRealm)7 Set (java.util.Set)6 LoginException (javax.security.auth.login.LoginException)5 IOException (java.io.IOException)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 CallbackHandler (javax.security.auth.callback.CallbackHandler)4 LoginModuleControlFlag (javax.security.auth.login.AppConfigurationEntry.LoginModuleControlFlag)4 LoginModuleImpl (org.apache.jackrabbit.oak.security.authentication.user.LoginModuleImpl)4 File (java.io.File)3 Principal (java.security.Principal)3