Search in sources :

Example 86 with Configuration

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;
}
Also used : URIParameter(java.security.URIParameter) Configuration(javax.security.auth.login.Configuration) File(java.io.File) URI(java.net.URI) IOException(java.io.IOException)

Example 87 with Configuration

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;
}
Also used : LoginContext(javax.security.auth.login.LoginContext) Configuration(javax.security.auth.login.Configuration) LoginException(javax.security.auth.login.LoginException)

Example 88 with Configuration

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);
    }
}
Also used : LoginContext(javax.security.auth.login.LoginContext) Configuration(javax.security.auth.login.Configuration) KerberosTicket(javax.security.auth.kerberos.KerberosTicket) Subject(javax.security.auth.Subject) LoginException(javax.security.auth.login.LoginException) DestroyFailedException(javax.security.auth.DestroyFailedException) RefreshFailedException(javax.security.auth.RefreshFailedException)

Example 89 with Configuration

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;
}
Also used : URIParameter(java.security.URIParameter) Configuration(javax.security.auth.login.Configuration) File(java.io.File) URI(java.net.URI) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 90 with Configuration

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);
}
Also used : AppConfigurationEntry(javax.security.auth.login.AppConfigurationEntry) Configuration(javax.security.auth.login.Configuration)

Aggregations

Configuration (javax.security.auth.login.Configuration)100 AppConfigurationEntry (javax.security.auth.login.AppConfigurationEntry)47 LoginContext (javax.security.auth.login.LoginContext)30 HashMap (java.util.HashMap)27 Subject (javax.security.auth.Subject)22 Test (org.junit.Test)17 IOException (java.io.IOException)15 LoginException (javax.security.auth.login.LoginException)13 File (java.io.File)8 Principal (java.security.Principal)7 CallbackHandler (javax.security.auth.callback.CallbackHandler)7 URI (java.net.URI)6 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)6 ArrayList (java.util.ArrayList)6 Test (org.junit.jupiter.api.Test)5 URIParameter (java.security.URIParameter)4 Map (java.util.Map)4 Callback (javax.security.auth.callback.Callback)4 LoginModuleImpl (org.apache.jackrabbit.oak.security.authentication.user.LoginModuleImpl)4 NoSuchProviderException (java.security.NoSuchProviderException)3