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);
}
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);
}
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
}
}
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());
}
}
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"));
}
Aggregations