Search in sources :

Example 21 with Configuration

use of javax.security.auth.login.Configuration in project 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);
    }
}
Also used : AppConfigurationEntry(javax.security.auth.login.AppConfigurationEntry) InMemoryConfiguration(org.springframework.security.authentication.jaas.memory.InMemoryConfiguration) Configuration(javax.security.auth.login.Configuration) InMemoryConfiguration(org.springframework.security.authentication.jaas.memory.InMemoryConfiguration) HashMap(java.util.HashMap) AuthenticationException(org.springframework.security.core.AuthenticationException)

Example 22 with Configuration

use of javax.security.auth.login.Configuration in project tomcat70 by apache.

the class JAASRealm method getConfig.

/**
 * Load custom JAAS Configuration
 */
protected Configuration getConfig() {
    try {
        if (jaasConfigurationLoaded) {
            return jaasConfiguration;
        }
        synchronized (this) {
            if (configFile == null) {
                jaasConfigurationLoaded = true;
                return null;
            }
            URL resource = Thread.currentThread().getContextClassLoader().getResource(configFile);
            URI uri = resource.toURI();
            @SuppressWarnings("unchecked") Class<Configuration> sunConfigFile = (Class<Configuration>) Class.forName("com.sun.security.auth.login.ConfigFile");
            Constructor<Configuration> constructor = sunConfigFile.getConstructor(URI.class);
            Configuration config = constructor.newInstance(uri);
            this.jaasConfiguration = config;
            this.jaasConfigurationLoaded = true;
            return this.jaasConfiguration;
        }
    } catch (URISyntaxException ex) {
        throw new RuntimeException(ex);
    } catch (NoSuchMethodException ex) {
        throw new RuntimeException(ex);
    } catch (SecurityException ex) {
        throw new RuntimeException(ex);
    } catch (InstantiationException ex) {
        throw new RuntimeException(ex);
    } catch (IllegalAccessException ex) {
        throw new RuntimeException(ex);
    } catch (IllegalArgumentException ex) {
        throw new RuntimeException(ex);
    } catch (InvocationTargetException ex) {
        throw new RuntimeException(ex.getCause());
    } catch (ClassNotFoundException ex) {
        throw new RuntimeException(ex);
    }
}
Also used : Configuration(javax.security.auth.login.Configuration) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) URL(java.net.URL) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 23 with Configuration

use of javax.security.auth.login.Configuration in project storm by nathanmarz.

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)) {
        try {
            URI config_uri = new File(loginConfigurationFile).toURI();
            login_conf = Configuration.getInstance("JavaLoginConfig", new URIParameter(config_uri));
        } catch (NoSuchAlgorithmException ex1) {
            if (ex1.getCause() instanceof FileNotFoundException)
                throw new RuntimeException("configuration file " + loginConfigurationFile + " could not be found");
            else
                throw new RuntimeException(ex1);
        } catch (Exception ex2) {
            throw new RuntimeException(ex2);
        }
    }
    return login_conf;
}
Also used : URIParameter(java.security.URIParameter) Configuration(javax.security.auth.login.Configuration) FileNotFoundException(java.io.FileNotFoundException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) URI(java.net.URI) File(java.io.File) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 24 with Configuration

use of javax.security.auth.login.Configuration in project spring-security by spring-projects.

the class JaasApiIntegrationFilterTests method onBeforeTests.

@BeforeEach
public void onBeforeTests() throws Exception {
    this.filter = new JaasApiIntegrationFilter();
    this.request = new MockHttpServletRequest();
    this.response = new MockHttpServletResponse();
    this.authenticatedSubject = new Subject();
    this.authenticatedSubject.getPrincipals().add(() -> "principal");
    this.authenticatedSubject.getPrivateCredentials().add("password");
    this.authenticatedSubject.getPublicCredentials().add("username");
    this.callbackHandler = (callbacks) -> {
        for (Callback callback : callbacks) {
            if (callback instanceof NameCallback) {
                ((NameCallback) callback).setName("user");
            } else if (callback instanceof PasswordCallback) {
                ((PasswordCallback) callback).setPassword("password".toCharArray());
            } else if (callback instanceof TextInputCallback) {
            // ignore
            } else {
                throw new UnsupportedCallbackException(callback, "Unrecognized Callback " + callback);
            }
        }
    };
    this.testConfiguration = new Configuration() {

        @Override
        public void refresh() {
        }

        @Override
        public AppConfigurationEntry[] getAppConfigurationEntry(String name) {
            return new AppConfigurationEntry[] { new AppConfigurationEntry(TestLoginModule.class.getName(), LoginModuleControlFlag.REQUIRED, new HashMap<>()) };
        }
    };
    LoginContext ctx = new LoginContext("SubjectDoAsFilterTest", this.authenticatedSubject, this.callbackHandler, this.testConfiguration);
    ctx.login();
    this.token = new JaasAuthenticationToken("username", "password", AuthorityUtils.createAuthorityList("ROLE_ADMIN"), ctx);
    // just in case someone forgot to clear the context
    SecurityContextHolder.clearContext();
}
Also used : Configuration(javax.security.auth.login.Configuration) HashMap(java.util.HashMap) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Subject(javax.security.auth.Subject) TextInputCallback(javax.security.auth.callback.TextInputCallback) AppConfigurationEntry(javax.security.auth.login.AppConfigurationEntry) TextInputCallback(javax.security.auth.callback.TextInputCallback) PasswordCallback(javax.security.auth.callback.PasswordCallback) NameCallback(javax.security.auth.callback.NameCallback) Callback(javax.security.auth.callback.Callback) NameCallback(javax.security.auth.callback.NameCallback) LoginContext(javax.security.auth.login.LoginContext) JaasAuthenticationToken(org.springframework.security.authentication.jaas.JaasAuthenticationToken) PasswordCallback(javax.security.auth.callback.PasswordCallback) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 25 with Configuration

use of javax.security.auth.login.Configuration in project spring-security by spring-projects.

the class DefaultJaasAuthenticationProviderTests method setUp.

@BeforeEach
public void setUp() throws Exception {
    Configuration configuration = mock(Configuration.class);
    this.publisher = mock(ApplicationEventPublisher.class);
    this.log = mock(Log.class);
    this.provider = new DefaultJaasAuthenticationProvider();
    this.provider.setConfiguration(configuration);
    this.provider.setApplicationEventPublisher(this.publisher);
    this.provider.setAuthorityGranters(new AuthorityGranter[] { new TestAuthorityGranter() });
    this.provider.afterPropertiesSet();
    AppConfigurationEntry[] aces = new AppConfigurationEntry[] { new AppConfigurationEntry(TestLoginModule.class.getName(), LoginModuleControlFlag.REQUIRED, Collections.<String, Object>emptyMap()) };
    given(configuration.getAppConfigurationEntry(this.provider.getLoginContextName())).willReturn(aces);
    this.token = new UsernamePasswordAuthenticationToken("user", "password");
    ReflectionTestUtils.setField(this.provider, "log", this.log);
}
Also used : AppConfigurationEntry(javax.security.auth.login.AppConfigurationEntry) Configuration(javax.security.auth.login.Configuration) Log(org.apache.commons.logging.Log) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

Configuration (javax.security.auth.login.Configuration)89 AppConfigurationEntry (javax.security.auth.login.AppConfigurationEntry)42 LoginContext (javax.security.auth.login.LoginContext)27 HashMap (java.util.HashMap)23 Subject (javax.security.auth.Subject)20 Test (org.junit.Test)16 IOException (java.io.IOException)13 LoginException (javax.security.auth.login.LoginException)12 CallbackHandler (javax.security.auth.callback.CallbackHandler)8 File (java.io.File)7 Principal (java.security.Principal)7 URI (java.net.URI)6 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)5 ArrayList (java.util.ArrayList)5 Test (org.junit.jupiter.api.Test)5 URIParameter (java.security.URIParameter)4 Map (java.util.Map)4 Callback (javax.security.auth.callback.Callback)4 PasswordCallback (javax.security.auth.callback.PasswordCallback)4 LoginModuleImpl (org.apache.jackrabbit.oak.security.authentication.user.LoginModuleImpl)4