Search in sources :

Example 11 with Configuration

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

the class HdfsProducer method doStart.

@Override
protected void doStart() throws Exception {
    // need to remember auth as Hadoop will override that, which otherwise means the Auth is broken afterwards
    Configuration auth = HdfsComponent.getJAASConfiguration();
    try {
        super.doStart();
        // setup hdfs if configured to do on startup
        if (getEndpoint().getConfig().isConnectOnStartup()) {
            ostream = setupHdfs(true);
        }
        SplitStrategy idleStrategy = null;
        for (SplitStrategy strategy : config.getSplitStrategies()) {
            if (strategy.type == SplitStrategyType.IDLE) {
                idleStrategy = strategy;
                break;
            }
        }
        if (idleStrategy != null) {
            scheduler = getEndpoint().getCamelContext().getExecutorServiceManager().newSingleThreadScheduledExecutor(this, "HdfsIdleCheck");
            log.debug("Creating IdleCheck task scheduled to run every {} millis", config.getCheckIdleInterval());
            scheduler.scheduleAtFixedRate(new IdleCheck(idleStrategy), config.getCheckIdleInterval(), config.getCheckIdleInterval(), TimeUnit.MILLISECONDS);
        }
    } finally {
        HdfsComponent.setJAASConfiguration(auth);
    }
}
Also used : Configuration(javax.security.auth.login.Configuration)

Example 12 with Configuration

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

the class HdfsProducer method doStart.

@Override
protected void doStart() throws Exception {
    // need to remember auth as Hadoop will override that, which otherwise means the Auth is broken afterwards
    Configuration auth = HdfsComponent.getJAASConfiguration();
    try {
        super.doStart();
        // setup hdfs if configured to do on startup
        if (getEndpoint().getConfig().isConnectOnStartup()) {
            ostream = setupHdfs(true);
        }
        SplitStrategy idleStrategy = null;
        for (SplitStrategy strategy : config.getSplitStrategies()) {
            if (strategy.type == SplitStrategyType.IDLE) {
                idleStrategy = strategy;
                break;
            }
        }
        if (idleStrategy != null) {
            scheduler = getEndpoint().getCamelContext().getExecutorServiceManager().newSingleThreadScheduledExecutor(this, "HdfsIdleCheck");
            log.debug("Creating IdleCheck task scheduled to run every {} millis", config.getCheckIdleInterval());
            scheduler.scheduleAtFixedRate(new IdleCheck(idleStrategy), config.getCheckIdleInterval(), config.getCheckIdleInterval(), TimeUnit.MILLISECONDS);
        }
    } finally {
        HdfsComponent.setJAASConfiguration(auth);
    }
}
Also used : Configuration(javax.security.auth.login.Configuration)

Example 13 with Configuration

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

the class ITJaasWithConfigBasedLoginModule method testJaasConfigPassing.

/**
 * Validates that OSGi config do gets passed as part of options to the LoginModule
 */
@Test
public void testJaasConfigPassing() throws Exception {
    String realmName = name.getMethodName();
    // 1. Create sample config
    org.osgi.service.cm.Configuration config = ca.createFactoryConfiguration("org.apache.felix.jaas.Configuration.factory", null);
    Dictionary<String, Object> p = new Hashtable<String, Object>();
    p.put("jaas.classname", "org.apache.felix.jaas.integration.sample1.ConfigLoginModule");
    p.put("jaas.realmName", realmName);
    // Following passed config gets validated in
    // org.apache.felix.jaas.integration.sample1.ConfigLoginModule.validateConfig()
    p.put("validateConfig", Boolean.TRUE);
    p.put("key0", "val0");
    p.put("key1", "val1");
    p.put("key2", "val2");
    // Override the value directly passed in config via options value explicitly
    p.put("jaas.options", new String[] { "key3=val3", "key4=val4", "key0=valNew" });
    config.update(p);
    delay();
    // 2. Validate the login passes with this config. LoginModule would validate
    // the config also
    CallbackHandler handler = new SimpleCallbackHandler("foo", "foo");
    Configuration jaasConfig = Configuration.getInstance("JavaLoginConfig", null, "FelixJaasProvider");
    Subject s = new Subject();
    final ClassLoader cl = Thread.currentThread().getContextClassLoader();
    try {
        Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
        LoginContext lc = new LoginContext(realmName, s, handler, jaasConfig);
        lc.login();
    } finally {
        Thread.currentThread().setContextClassLoader(cl);
    }
    assertFalse(s.getPrincipals().isEmpty());
}
Also used : SimpleCallbackHandler(org.apache.felix.jaas.integration.common.SimpleCallbackHandler) CallbackHandler(javax.security.auth.callback.CallbackHandler) Configuration(javax.security.auth.login.Configuration) Hashtable(java.util.Hashtable) SimpleCallbackHandler(org.apache.felix.jaas.integration.common.SimpleCallbackHandler) Subject(javax.security.auth.Subject) LoginContext(javax.security.auth.login.LoginContext) Test(org.junit.Test)

Example 14 with Configuration

use of javax.security.auth.login.Configuration in project airlift by airlift.

the class SpnegoAuthentication method getSession.

private synchronized Session getSession() throws LoginException, GSSException {
    if (clientSession == null || clientSession.getClientCredential().getRemainingLifetime() < MIN_CREDENTIAL_LIFE_TIME.getValue(TimeUnit.SECONDS)) {
        // TODO: do we need to call logout() on the LoginContext?
        LoginContext loginContext = new LoginContext("", null, null, new Configuration() {

            @Override
            public AppConfigurationEntry[] getAppConfigurationEntry(String name) {
                ImmutableMap.Builder<String, String> optionsBuilder = ImmutableMap.builder();
                optionsBuilder.put("refreshKrb5Config", "true");
                optionsBuilder.put("doNotPrompt", "true");
                optionsBuilder.put("useKeyTab", "true");
                if (LOG.isDebugEnabled()) {
                    optionsBuilder.put("debug", "true");
                }
                if (keytab != null) {
                    optionsBuilder.put("keyTab", keytab.getAbsolutePath());
                }
                if (credentialCache != null) {
                    optionsBuilder.put("ticketCache", credentialCache.getAbsolutePath());
                    optionsBuilder.put("useTicketCache", "true");
                    optionsBuilder.put("renewTGT", "true");
                }
                if (principal != null) {
                    optionsBuilder.put("principal", principal);
                }
                return new AppConfigurationEntry[] { new AppConfigurationEntry(Krb5LoginModule.class.getName(), REQUIRED, optionsBuilder.build()) };
            }
        });
        loginContext.login();
        Subject subject = loginContext.getSubject();
        Principal clientPrincipal = subject.getPrincipals().iterator().next();
        GSSCredential clientCredential = doAs(subject, () -> GSS_MANAGER.createCredential(GSS_MANAGER.createName(clientPrincipal.getName(), NT_USER_NAME), DEFAULT_LIFETIME, KERBEROS_OID, INITIATE_ONLY));
        clientSession = new Session(loginContext, clientCredential);
    }
    return clientSession;
}
Also used : AppConfigurationEntry(javax.security.auth.login.AppConfigurationEntry) LoginContext(javax.security.auth.login.LoginContext) Configuration(javax.security.auth.login.Configuration) GSSCredential(org.ietf.jgss.GSSCredential) Subject(javax.security.auth.Subject) Principal(java.security.Principal)

Example 15 with Configuration

use of javax.security.auth.login.Configuration in project simba-os by cegeka.

the class JaasLoginCommandTest method setupJAAS.

private void setupJAAS() {
    Configuration configurationMock = mock(Configuration.class);
    AppConfigurationEntry entry = new AppConfigurationEntry(TestLoginModule.class.getName(), LoginModuleControlFlag.REQUIRED, Collections.<String, Object>emptyMap());
    when(configurationMock.getAppConfigurationEntry(LOGIN_MODULE_NAME)).thenReturn(new AppConfigurationEntry[] { entry });
    Configuration.setConfiguration(configurationMock);
}
Also used : AppConfigurationEntry(javax.security.auth.login.AppConfigurationEntry) 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