use of javax.security.auth.login.Configuration in project SSM by Intel-bigdata.
the class SecurityUtil method loginUsingKeytab.
public static Subject loginUsingKeytab(String principal, File keytabFile) throws IOException {
Set<Principal> principals = new HashSet<Principal>();
principals.add(new KerberosPrincipal(principal));
Subject subject = new Subject(false, principals, new HashSet<Object>(), new HashSet<Object>());
Configuration conf = useKeytab(principal, keytabFile);
String confName = "KeytabConf";
LoginContext loginContext = null;
try {
loginContext = new LoginContext(confName, subject, null, conf);
LOG.info("Login successful for user " + subject.getPrincipals().iterator().next().getName());
} catch (LoginException e) {
throw new IOException("Faill to create LoginContext for " + e);
}
try {
loginContext.login();
} catch (LoginException e) {
throw new IOException("Login failure for " + e);
}
return loginContext.getSubject();
}
use of javax.security.auth.login.Configuration in project kafka by apache.
the class JaasUtils method isZkSaslEnabled.
public static boolean isZkSaslEnabled() {
// Technically a client must also check if TLS mutual authentication has been configured,
// but we will leave that up to the client code to determine since direct connectivity to ZooKeeper
// has been deprecated in many clients and we don't wish to re-introduce a ZooKeeper jar dependency here.
boolean zkSaslEnabled = Boolean.parseBoolean(System.getProperty(ZK_SASL_CLIENT, DEFAULT_ZK_SASL_CLIENT));
String zkLoginContextName = System.getProperty(ZK_LOGIN_CONTEXT_NAME_KEY, DEFAULT_ZK_LOGIN_CONTEXT_NAME);
LOG.debug("Checking login config for Zookeeper JAAS context {}", zkSecuritySysConfigString());
boolean foundLoginConfigEntry;
try {
Configuration loginConf = Configuration.getConfiguration();
foundLoginConfigEntry = loginConf.getAppConfigurationEntry(zkLoginContextName) != null;
} catch (Exception e) {
throw new KafkaException("Exception while loading Zookeeper JAAS login context " + zkSecuritySysConfigString(), e);
}
if (foundLoginConfigEntry && !zkSaslEnabled) {
LOG.error("JAAS configuration is present, but system property " + ZK_SASL_CLIENT + " is set to false, which disables " + "SASL in the ZooKeeper client");
throw new KafkaException("Exception while determining if ZooKeeper is secure " + zkSecuritySysConfigString());
}
return foundLoginConfigEntry;
}
use of javax.security.auth.login.Configuration 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.Configuration in project kafka by apache.
the class BasicAuthSecurityRestExtensionTest method testJaasConfigurationNotOverwritten.
@SuppressWarnings("unchecked")
@Test
public void testJaasConfigurationNotOverwritten() {
ArgumentCaptor<JaasBasicAuthFilter> jaasFilter = ArgumentCaptor.forClass(JaasBasicAuthFilter.class);
Configurable<? extends Configurable<?>> configurable = mock(Configurable.class);
when(configurable.register(jaasFilter.capture())).thenReturn(null);
ConnectRestExtensionContext context = mock(ConnectRestExtensionContext.class);
when(context.configurable()).thenReturn((Configurable) configurable);
BasicAuthSecurityRestExtension extension = new BasicAuthSecurityRestExtension();
Configuration overwrittenConfiguration = mock(Configuration.class);
Configuration.setConfiguration(overwrittenConfiguration);
extension.register(context);
assertNotEquals(overwrittenConfiguration, jaasFilter.getValue().configuration, "Overwritten JAAS configuration should not be used by basic auth REST extension");
}
use of javax.security.auth.login.Configuration in project incubator-atlas by apache.
the class AtlasPamAuthenticationProvider method init.
private void init() {
try {
AppConfigurationEntry appConfigurationEntry = new AppConfigurationEntry(loginModuleName, controlFlag, options);
AppConfigurationEntry[] appConfigurationEntries = new AppConfigurationEntry[] { appConfigurationEntry };
Map<String, AppConfigurationEntry[]> appConfigurationEntriesOptions = new HashMap<String, AppConfigurationEntry[]>();
appConfigurationEntriesOptions.put("SPRINGSECURITY", appConfigurationEntries);
Configuration configuration = new InMemoryConfiguration(appConfigurationEntriesOptions);
jaasAuthenticationProvider.setConfiguration(configuration);
UserAuthorityGranter authorityGranter = new UserAuthorityGranter();
UserAuthorityGranter[] authorityGranters = new UserAuthorityGranter[] { authorityGranter };
jaasAuthenticationProvider.setAuthorityGranters(authorityGranters);
jaasAuthenticationProvider.afterPropertiesSet();
} catch (Exception e) {
LOG.error("Failed to init PAM Authentication", e);
}
}
Aggregations