Search in sources :

Example 11 with AppConfigurationEntry

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

the class JaasContext method load.

static JaasContext load(JaasContext.Type contextType, String listenerContextName, String globalContextName, Map<String, ?> configs) {
    Password jaasConfigArgs = (Password) configs.get(SaslConfigs.SASL_JAAS_CONFIG);
    if (jaasConfigArgs != null) {
        if (contextType == JaasContext.Type.SERVER)
            throw new IllegalArgumentException("JAAS config property not supported for server");
        else {
            JaasConfig jaasConfig = new JaasConfig(globalContextName, jaasConfigArgs.value());
            AppConfigurationEntry[] clientModules = jaasConfig.getAppConfigurationEntry(globalContextName);
            int numModules = clientModules == null ? 0 : clientModules.length;
            if (numModules != 1)
                throw new IllegalArgumentException("JAAS config property contains " + numModules + " login modules, should be 1 module");
            return new JaasContext(globalContextName, contextType, jaasConfig);
        }
    } else
        return defaultContext(contextType, listenerContextName, globalContextName);
}
Also used : AppConfigurationEntry(javax.security.auth.login.AppConfigurationEntry) Password(org.apache.kafka.common.config.types.Password)

Example 12 with AppConfigurationEntry

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

the class TestJaasConfig method addEntry.

public void addEntry(String name, String loginModule, Map<String, Object> options) {
    AppConfigurationEntry entry = new AppConfigurationEntry(loginModule, LoginModuleControlFlag.REQUIRED, options);
    AppConfigurationEntry[] existing = entryMap.get(name);
    AppConfigurationEntry[] newEntries = existing == null ? new AppConfigurationEntry[1] : Arrays.copyOf(existing, existing.length + 1);
    newEntries[newEntries.length - 1] = entry;
    entryMap.put(name, newEntries);
}
Also used : AppConfigurationEntry(javax.security.auth.login.AppConfigurationEntry)

Example 13 with AppConfigurationEntry

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

the class JaasContextTest method checkInvalidConfiguration.

private void checkInvalidConfiguration(String jaasConfigProp) throws IOException {
    try {
        writeConfiguration(JaasContext.Type.SERVER.name(), jaasConfigProp);
        AppConfigurationEntry entry = configurationEntry(JaasContext.Type.SERVER, null);
        fail("Invalid JAAS configuration file didn't throw exception, entry=" + entry);
    } catch (SecurityException e) {
    // Expected exception
    }
    try {
        AppConfigurationEntry entry = configurationEntry(JaasContext.Type.CLIENT, jaasConfigProp);
        fail("Invalid JAAS configuration property didn't throw exception, entry=" + entry);
    } catch (IllegalArgumentException e) {
    // Expected exception
    }
}
Also used : AppConfigurationEntry(javax.security.auth.login.AppConfigurationEntry)

Example 14 with AppConfigurationEntry

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

the class JaasContextTest method testMultipleLoginModules.

@Test
public void testMultipleLoginModules() throws Exception {
    StringBuilder builder = new StringBuilder();
    int moduleCount = 3;
    Map<Integer, Map<String, Object>> moduleOptions = new HashMap<>();
    for (int i = 0; i < moduleCount; i++) {
        Map<String, Object> options = new HashMap<>();
        options.put("index", "Index" + i);
        options.put("module", "Module" + i);
        moduleOptions.put(i, options);
        String module = jaasConfigProp("test.Module" + i, LoginModuleControlFlag.REQUIRED, options);
        builder.append(' ');
        builder.append(module);
    }
    String jaasConfigProp = builder.toString();
    String clientContextName = "CLIENT";
    Configuration configuration = new JaasConfig(clientContextName, jaasConfigProp);
    AppConfigurationEntry[] dynamicEntries = configuration.getAppConfigurationEntry(clientContextName);
    assertEquals(moduleCount, dynamicEntries.length);
    for (int i = 0; i < moduleCount; i++) {
        AppConfigurationEntry entry = dynamicEntries[i];
        checkEntry(entry, "test.Module" + i, LoginModuleControlFlag.REQUIRED, moduleOptions.get(i));
    }
    String serverContextName = "SERVER";
    writeConfiguration(serverContextName, jaasConfigProp);
    AppConfigurationEntry[] staticEntries = Configuration.getConfiguration().getAppConfigurationEntry(serverContextName);
    for (int i = 0; i < moduleCount; i++) {
        AppConfigurationEntry staticEntry = staticEntries[i];
        checkEntry(staticEntry, dynamicEntries[i].getLoginModuleName(), LoginModuleControlFlag.REQUIRED, dynamicEntries[i].getOptions());
    }
}
Also used : Configuration(javax.security.auth.login.Configuration) HashMap(java.util.HashMap) AppConfigurationEntry(javax.security.auth.login.AppConfigurationEntry) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 15 with AppConfigurationEntry

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

the class AuthUtilsTest method getNonExistentSectionTest.

@Test
public void getNonExistentSectionTest() throws IOException {
    Map<String, String> optionMap = new HashMap<String, String>();
    AppConfigurationEntry entry = Mockito.mock(AppConfigurationEntry.class);
    Mockito.<Map<String, ?>>when(entry.getOptions()).thenReturn(optionMap);
    String section = "bogus-section";
    Configuration mockConfig = Mockito.mock(Configuration.class);
    Mockito.when(mockConfig.getAppConfigurationEntry(section)).thenReturn(new AppConfigurationEntry[] { entry });
    Assert.assertNull(AuthUtils.get(mockConfig, section, "nonexistent-key"));
}
Also used : AppConfigurationEntry(javax.security.auth.login.AppConfigurationEntry) Configuration(javax.security.auth.login.Configuration) HashMap(java.util.HashMap) Test(org.junit.Test)

Aggregations

AppConfigurationEntry (javax.security.auth.login.AppConfigurationEntry)74 HashMap (java.util.HashMap)30 Configuration (javax.security.auth.login.Configuration)25 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