use of javax.security.auth.login.Configuration in project storm by apache.
the class ClientAuthUtils method getConfiguration.
/**
* Construct a JAAS configuration object per storm configuration file.
*
* @param topoConf Storm configuration
* @return JAAS configuration object
*/
public static Configuration getConfiguration(Map<String, Object> topoConf) {
Configuration loginConf = null;
// find login file configuration from Storm configuration
String loginConfigurationFile = getJaasConf(topoConf);
if ((loginConfigurationFile != null) && (loginConfigurationFile.length() > 0)) {
File configFile = new File(loginConfigurationFile);
if (!configFile.canRead()) {
throw new RuntimeException("File " + loginConfigurationFile + " cannot be read.");
}
try {
URI configUri = configFile.toURI();
loginConf = Configuration.getInstance("JavaLoginConfig", new URIParameter(configUri));
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
return loginConf;
}
use of javax.security.auth.login.Configuration in project storm by apache.
the class Login method login.
private synchronized LoginContext login(final String loginContextName, String jaasConfFile) throws LoginException {
if (loginContextName == null) {
throw new LoginException("loginContext name (JAAS file section header) was null. " + "Please check your java.security.login.auth.config (=" + System.getProperty("java.security.login.auth.config") + ") and your " + ZooKeeperSaslClient.LOGIN_CONTEXT_NAME_KEY + "(=" + System.getProperty(ZooKeeperSaslClient.LOGIN_CONTEXT_NAME_KEY, "Client") + ")");
}
Configuration configuration = this.getConfiguration(jaasConfFile);
LoginContext loginContext;
try {
loginContext = new LoginContext(loginContextName, null, callbackHandler, configuration);
loginContext.login();
} catch (LoginException e) {
LOG.error("Login using jaas conf " + jaasConfFile + " failed");
throw e;
}
LOG.info("Successfully logged in to context " + loginContextName + " using " + jaasConfFile);
return loginContext;
}
use of javax.security.auth.login.Configuration in project jstorm by alibaba.
the class AutoTGT method populateCredentials.
@Override
public void populateCredentials(Map<String, String> credentials) {
// Log the user in and get the TGT
try {
Configuration login_conf = AuthUtils.GetConfiguration(conf);
ClientCallbackHandler client_callback_handler = new ClientCallbackHandler(login_conf);
// login our user
Configuration.setConfiguration(login_conf);
LoginContext lc = new LoginContext(AuthUtils.LOGIN_CONTEXT_CLIENT, client_callback_handler);
try {
lc.login();
final Subject subject = lc.getSubject();
KerberosTicket tgt = getTGT(subject);
if (tgt == null) {
// error
throw new RuntimeException("Fail to verify user principal with section \"" + AuthUtils.LOGIN_CONTEXT_CLIENT + "\" in login configuration file " + login_conf);
}
if (!tgt.isForwardable()) {
throw new RuntimeException("The TGT found is not forwardable");
}
if (!tgt.isRenewable()) {
throw new RuntimeException("The TGT found is not renewable");
}
LOG.info("Pushing TGT for " + tgt.getClient() + " to topology.");
saveTGT(tgt, credentials);
} finally {
lc.logout();
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of javax.security.auth.login.Configuration in project jstorm by alibaba.
the class AuthUtils method GetConfiguration.
/**
* Construct a JAAS configuration object per storm configuration file
*
* @param storm_conf Storm configuration
* @return JAAS configuration object
*/
public static Configuration GetConfiguration(Map storm_conf) {
Configuration login_conf = null;
// find login file configuration from Storm configuration
String loginConfigurationFile = (String) storm_conf.get("java.security.auth.login.config");
if ((loginConfigurationFile != null) && (loginConfigurationFile.length() > 0)) {
File config_file = new File(loginConfigurationFile);
if (!config_file.canRead()) {
throw new RuntimeException("File " + loginConfigurationFile + " cannot be read.");
}
try {
URI config_uri = config_file.toURI();
login_conf = Configuration.getInstance("JavaLoginConfig", new URIParameter(config_uri));
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
return login_conf;
}
use of javax.security.auth.login.Configuration in project kafka by apache.
the class JaasContext method defaultContext.
private static JaasContext defaultContext(JaasContext.Type contextType, String listenerContextName, String globalContextName) {
String jaasConfigFile = System.getProperty(JaasUtils.JAVA_LOGIN_CONFIG_PARAM);
if (jaasConfigFile == null) {
if (contextType == Type.CLIENT) {
LOG.debug("System property '" + JaasUtils.JAVA_LOGIN_CONFIG_PARAM + "' and Kafka SASL property '" + SaslConfigs.SASL_JAAS_CONFIG + "' are not set, using default JAAS configuration.");
} else {
LOG.debug("System property '" + JaasUtils.JAVA_LOGIN_CONFIG_PARAM + "' is not set, using default JAAS " + "configuration.");
}
}
Configuration jaasConfig = Configuration.getConfiguration();
AppConfigurationEntry[] configEntries = null;
String contextName = globalContextName;
if (listenerContextName != null) {
configEntries = jaasConfig.getAppConfigurationEntry(listenerContextName);
if (configEntries != null)
contextName = listenerContextName;
}
if (configEntries == null)
configEntries = jaasConfig.getAppConfigurationEntry(globalContextName);
if (configEntries == null) {
String listenerNameText = listenerContextName == null ? "" : " or '" + listenerContextName + "'";
String errorMessage = "Could not find a '" + globalContextName + "'" + listenerNameText + " entry in the JAAS " + "configuration. System property '" + JaasUtils.JAVA_LOGIN_CONFIG_PARAM + "' is " + (jaasConfigFile == null ? "not set" : jaasConfigFile);
throw new IllegalArgumentException(errorMessage);
}
return new JaasContext(contextName, contextType, jaasConfig, null);
}
Aggregations