Example usage for org.springframework.security.config.annotation.authentication.builders AuthenticationManagerBuilder apply

List of usage examples for org.springframework.security.config.annotation.authentication.builders AuthenticationManagerBuilder apply

Introduction

In this page you can find the example usage for org.springframework.security.config.annotation.authentication.builders AuthenticationManagerBuilder apply.

Prototype

private <C extends UserDetailsAwareConfigurer<AuthenticationManagerBuilder, ? extends UserDetailsService>> C apply(
        C configurer) throws Exception 

Source Link

Document

Captures the UserDetailsService from any UserDetailsAwareConfigurer .

Usage

From source file:io.gravitee.management.security.config.basic.BasicSecurityConfigurerAdapter.java

@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
    LOGGER.info("Loading authentication identity providers for Basic authentication");
    List<String> providers = loadingAuthenticationIdentityProviders();

    for (int idx = 0; idx < providers.size(); idx++) {
        String providerType = providers.get(idx);
        LOGGER.info("Loading identity provider of type {} at position {}", providerType, idx);

        boolean found = false;
        Collection<IdentityProvider> identityProviders = identityProviderManager.getAll();
        for (IdentityProvider identityProvider : identityProviders) {
            if (identityProvider.type().equalsIgnoreCase(providerType)) {
                AuthenticationProvider authenticationProviderPlugin = identityProviderManager
                        .loadIdentityProvider(identityProvider.type(), identityProviderProperties(idx));

                if (authenticationProviderPlugin != null) {
                    Object authenticationProvider = authenticationProviderPlugin.configure();

                    if (authenticationProvider instanceof org.springframework.security.authentication.AuthenticationProvider) {
                        auth.authenticationProvider(
                                (org.springframework.security.authentication.AuthenticationProvider) authenticationProvider);
                    } else if (authenticationProvider instanceof SecurityConfigurer) {
                        auth.apply((SecurityConfigurer) authenticationProvider);
                    }/*from   w  w w.  jav a  2s  .c o  m*/
                    found = true;
                    break;
                }
            }
        }

        if (!found) {
            LOGGER.error("No authentication provider found for type: {}", providerType);
        }
    }
}

From source file:org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration.java

public AuthenticationManager getAuthenticationManager() throws Exception {
    if (this.authenticationManagerInitialized) {
        return this.authenticationManager;
    }//from   ww  w .  ja v  a  2 s.  com
    AuthenticationManagerBuilder authBuilder = this.applicationContext
            .getBean(AuthenticationManagerBuilder.class);
    if (this.buildingAuthenticationManager.getAndSet(true)) {
        return new AuthenticationManagerDelegator(authBuilder);
    }

    for (GlobalAuthenticationConfigurerAdapter config : globalAuthConfigurers) {
        authBuilder.apply(config);
    }

    authenticationManager = authBuilder.build();

    if (authenticationManager == null) {
        authenticationManager = getAuthenticationManagerBean();
    }

    this.authenticationManagerInitialized = true;
    return authenticationManager;
}