Search in sources :

Example 16 with Configuration

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

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

the class RemoteConfigurationRegistryClientServiceTest method setupAndStartSecureTestZooKeeper.

/**
 * Setup and start a secure test ZooKeeper cluster.
 */
private TestingCluster setupAndStartSecureTestZooKeeper(String principal, String digestPassword) throws Exception {
    final boolean applyAuthentication = (principal != null);
    // Configure security for the ZK cluster instances
    Map<String, Object> customInstanceSpecProps = new HashMap<>();
    if (applyAuthentication) {
        customInstanceSpecProps.put("authProvider.1", "org.apache.zookeeper.server.auth.SASLAuthenticationProvider");
        customInstanceSpecProps.put("requireClientAuthScheme", "sasl");
    }
    // Define the test cluster
    List<InstanceSpec> instanceSpecs = new ArrayList<>();
    for (int i = 0; i < 3; i++) {
        InstanceSpec is = new InstanceSpec(null, -1, -1, -1, false, (i + 1), -1, -1, customInstanceSpecProps);
        instanceSpecs.add(is);
    }
    TestingCluster zkCluster = new TestingCluster(instanceSpecs);
    if (applyAuthentication) {
        // Setup ZooKeeper server SASL
        Map<String, String> digestOptions = new HashMap<>();
        digestOptions.put("user_" + principal, digestPassword);
        final AppConfigurationEntry[] serverEntries = { new AppConfigurationEntry("org.apache.zookeeper.server.auth.DigestLoginModule", AppConfigurationEntry.LoginModuleControlFlag.REQUIRED, digestOptions) };
        Configuration.setConfiguration(new Configuration() {

            @Override
            public AppConfigurationEntry[] getAppConfigurationEntry(String name) {
                return ("Server".equalsIgnoreCase(name)) ? serverEntries : null;
            }
        });
    }
    // Start the cluster
    zkCluster.start();
    return zkCluster;
}
Also used : InstanceSpec(org.apache.curator.test.InstanceSpec) Configuration(javax.security.auth.login.Configuration) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) AppConfigurationEntry(javax.security.auth.login.AppConfigurationEntry) TestingCluster(org.apache.curator.test.TestingCluster)

Example 18 with Configuration

use of javax.security.auth.login.Configuration in project wildfly-camel by wildfly-extras.

the class LoginContextBuilder method getClientLoginContext.

// Provides a RunAs client login context
private LoginContext getClientLoginContext() throws LoginException {
    Configuration config = new Configuration() {

        @Override
        public AppConfigurationEntry[] getAppConfigurationEntry(String name) {
            Map<String, String> options = new HashMap<String, String>();
            options.put("multi-threaded", "true");
            options.put("restore-login-identity", "true");
            AppConfigurationEntry clmEntry = new AppConfigurationEntry(ClientLoginModule.class.getName(), LoginModuleControlFlag.REQUIRED, options);
            return new AppConfigurationEntry[] { clmEntry };
        }
    };
    return getLoginContext(config);
}
Also used : AppConfigurationEntry(javax.security.auth.login.AppConfigurationEntry) ClientLoginModule(org.jboss.security.ClientLoginModule) Configuration(javax.security.auth.login.Configuration) HashMap(java.util.HashMap)

Example 19 with Configuration

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

the class JaasLoginContextTest method before.

@Before
public void before() {
    Configuration c = ConfigurationUtil.getDefaultConfiguration(ConfigurationParameters.EMPTY);
    Configuration.setConfiguration(c);
}
Also used : Configuration(javax.security.auth.login.Configuration) Before(org.junit.Before)

Example 20 with Configuration

use of javax.security.auth.login.Configuration in project polymap4-core by Polymap4.

the class SpnegoFilterConfig method doClientModule.

private void doClientModule(final String moduleName) {
    assert moduleExists("client", moduleName);
    this.clientLoginModule = moduleName;
    // client must not have any options
    // confirm that runtime loaded the login file
    final Configuration config = Configuration.getConfiguration();
    // we only expect one entry
    final AppConfigurationEntry entry = config.getAppConfigurationEntry(moduleName)[0];
    // get login module options
    final Map<String, ?> opt = entry.getOptions();
    // assert
    if (!opt.isEmpty()) {
        for (Map.Entry<String, ?> option : opt.entrySet()) {
            // unless they are jboss options
            if (!option.getKey().startsWith("jboss")) {
                throw new UnsupportedOperationException("Login Module for client must not " + "specify any options: " + opt.size() + "; moduleName=" + moduleName + "; options=" + opt.toString());
            }
        }
    }
}
Also used : AppConfigurationEntry(javax.security.auth.login.AppConfigurationEntry) Configuration(javax.security.auth.login.Configuration) Map(java.util.Map)

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