Example usage for org.springframework.security.authentication.jaas DefaultJaasAuthenticationProvider setAuthorityGranters

List of usage examples for org.springframework.security.authentication.jaas DefaultJaasAuthenticationProvider setAuthorityGranters

Introduction

In this page you can find the example usage for org.springframework.security.authentication.jaas DefaultJaasAuthenticationProvider setAuthorityGranters.

Prototype

public void setAuthorityGranters(AuthorityGranter[] authorityGranters) 

Source Link

Document

Set the AuthorityGranters that should be consulted for role names to be granted to the Authentication.

Usage

From source file:com.thinkbiganalytics.auth.jaas.config.JaasAuthConfig.java

@Bean(name = UI_AUTH_PROVIDER)
public AuthenticationProvider uiAuthenticationProvider(
        @Named("jaasConfiguration") javax.security.auth.login.Configuration config,
        List<AuthorityGranter> authorityGranters) {
    DefaultJaasAuthenticationProvider provider = new DefaultJaasAuthenticationProvider();
    provider.setConfiguration(config);/*from w w  w  .ja  va2  s .  c  o  m*/
    provider.setAuthorityGranters(authorityGranters.toArray(new AuthorityGranter[authorityGranters.size()]));
    provider.setLoginContextName(JAAS_UI);
    return provider;
}

From source file:com.thinkbiganalytics.auth.jaas.config.JaasAuthConfig.java

@Bean(name = SERVICES_AUTH_PROVIDER)
public AuthenticationProvider servicesAuthenticationProvider(
        @Named("jaasConfiguration") javax.security.auth.login.Configuration config,
        List<AuthorityGranter> authorityGranters) {
    DefaultJaasAuthenticationProvider provider = new DefaultJaasAuthenticationProvider();
    provider.setConfiguration(config);/*  www  .ja v a  2  s.co  m*/
    provider.setAuthorityGranters(authorityGranters.toArray(new AuthorityGranter[authorityGranters.size()]));
    provider.setLoginContextName(JAAS_SERVICES);
    return provider;
}

From source file:org.apache.atlas.web.security.AtlasPamAuthenticationProvider.java

private Authentication getPamAuthentication(Authentication authentication) {
    try {//from ww w  . j a v a2  s. c o  m
        DefaultJaasAuthenticationProvider jaasAuthenticationProvider = new DefaultJaasAuthenticationProvider();
        String loginModuleName = "org.apache.atlas.web.security.PamLoginModule";
        AppConfigurationEntry.LoginModuleControlFlag controlFlag = AppConfigurationEntry.LoginModuleControlFlag.REQUIRED;
        Properties properties = ConfigurationConverter
                .getProperties(ApplicationProperties.get().subset("atlas.authentication.method.pam"));
        Map<String, String> options = new HashMap<>();
        for (String key : properties.stringPropertyNames()) {
            String value = properties.getProperty(key);
            options.put(key, value);
        }
        if (!options.containsKey("service"))
            options.put("service", "atlas-login");
        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();

        String userName = authentication.getName();
        String userPassword = "";
        if (authentication.getCredentials() != null) {
            userPassword = authentication.getCredentials().toString();
        }

        // getting user authenticated
        if (userName != null && userPassword != null && !userName.trim().isEmpty()
                && !userPassword.trim().isEmpty()) {
            final List<GrantedAuthority> grantedAuths = getAuthorities(userName);

            final UserDetails principal = new User(userName, userPassword, grantedAuths);

            final Authentication finalAuthentication = new UsernamePasswordAuthenticationToken(principal,
                    userPassword, grantedAuths);

            authentication = jaasAuthenticationProvider.authenticate(finalAuthentication);
            authentication = getAuthenticationWithGrantedAuthority(authentication);
            return authentication;
        } else {
            return authentication;
        }

    } catch (Exception e) {
        logger.debug("Pam Authentication Failed:", e);
    }
    return authentication;
}