Search in sources :

Example 1 with AuthenticationManagerBuilder

use of org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder in project spring-security by spring-projects.

the class WebSecurityConfigurerAdapter method setObjectPostProcessor.

@Autowired
public void setObjectPostProcessor(ObjectPostProcessor<Object> objectPostProcessor) {
    this.objectPostProcessor = objectPostProcessor;
    authenticationBuilder = new AuthenticationManagerBuilder(objectPostProcessor);
    localConfigureAuthenticationBldr = new AuthenticationManagerBuilder(objectPostProcessor) {

        @Override
        public AuthenticationManagerBuilder eraseCredentials(boolean eraseCredentials) {
            authenticationBuilder.eraseCredentials(eraseCredentials);
            return super.eraseCredentials(eraseCredentials);
        }
    };
}
Also used : AuthenticationManagerBuilder(org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder) Autowired(org.springframework.beans.factory.annotation.Autowired)

Example 2 with AuthenticationManagerBuilder

use of org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder in project cas by apereo.

the class BaseCasLdapUserDetailsManagerConfigurerTests method verifyUserDetails.

@Test
public void verifyUserDetails() throws Exception {
    final CasLdapUserDetailsManagerConfigurer cfg = new CasLdapUserDetailsManagerConfigurer(casProperties.getAdminPagesSecurity());
    final AuthenticationManagerBuilder builder = new AuthenticationManagerBuilder(new AuthenticationObjectPostProcessor());
    cfg.configure(builder);
    final AuthenticationManager mgr = builder.build();
    assertNotNull(mgr);
}
Also used : AuthenticationManager(org.springframework.security.authentication.AuthenticationManager) AuthenticationManagerBuilder(org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with AuthenticationManagerBuilder

use of org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder in project gravitee-management-rest-api by gravitee-io.

the class BasicSecurityConfigurerAdapter method configure.

@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
    LOGGER.info("Loading authentication identity providers for Basic authentication");
    List<io.gravitee.management.security.authentication.AuthenticationProvider> providers = authenticationProviderManager.getIdentityProviders().stream().filter(authenticationProvider -> !authenticationProvider.external()).collect(Collectors.toList());
    for (io.gravitee.management.security.authentication.AuthenticationProvider provider : providers) {
        LOGGER.info("Loading authentication provider of type {} at position {}", provider.type(), provider.index());
        boolean found = false;
        Collection<IdentityProvider> identityProviders = identityProviderManager.getAll();
        for (IdentityProvider identityProvider : identityProviders) {
            if (identityProvider.type().equalsIgnoreCase(provider.type())) {
                AuthenticationProvider authenticationProviderPlugin = identityProviderManager.loadIdentityProvider(identityProvider.type(), provider.configuration());
                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);
                    }
                    found = true;
                    break;
                }
            }
        }
        if (!found) {
            LOGGER.error("No authentication provider found for type: {}", provider.type());
            throw new IllegalStateException("No authentication provider found for type: " + provider.type());
        }
    }
}
Also used : JWTCookieGenerator(io.gravitee.management.security.cookies.JWTCookieGenerator) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) HttpSecurity(org.springframework.security.config.annotation.web.builders.HttpSecurity) CorsConfigurationSource(org.springframework.web.cors.CorsConfigurationSource) WebSecurityConfigurerAdapter(org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter) AuthenticationManagerBuilder(org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder) ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) AuthenticationProviderManager(io.gravitee.management.security.authentication.AuthenticationProviderManager) Arrays.asList(java.util.Arrays.asList) SecurityConfigurer(org.springframework.security.config.annotation.SecurityConfigurer) DEFAULT_JWT_ISSUER(io.gravitee.management.service.common.JWTHelper.DefaultValues.DEFAULT_JWT_ISSUER) IdentityProvider(io.gravitee.management.idp.api.IdentityProvider) DEFAULT_JWT_EXPIRE_AFTER(io.gravitee.management.service.common.JWTHelper.DefaultValues.DEFAULT_JWT_EXPIRE_AFTER) BasicAuthenticationFilter(org.springframework.security.web.authentication.www.BasicAuthenticationFilter) IdentityProviderManager(io.gravitee.management.idp.core.plugin.IdentityProviderManager) Logger(org.slf4j.Logger) AuthenticationSuccessFilter(io.gravitee.management.security.filter.AuthenticationSuccessFilter) Collection(java.util.Collection) HttpMethod(org.springframework.http.HttpMethod) UrlBasedCorsConfigurationSource(org.springframework.web.cors.UrlBasedCorsConfigurationSource) CorsConfiguration(org.springframework.web.cors.CorsConfiguration) Profile(org.springframework.context.annotation.Profile) Collectors(java.util.stream.Collectors) Configuration(org.springframework.context.annotation.Configuration) JWTAuthenticationFilter(io.gravitee.management.security.filter.JWTAuthenticationFilter) List(java.util.List) MembershipService(io.gravitee.management.service.MembershipService) EnableWebSecurity(org.springframework.security.config.annotation.web.configuration.EnableWebSecurity) AuthenticationSuccessListener(io.gravitee.management.security.listener.AuthenticationSuccessListener) SessionCreationPolicy(org.springframework.security.config.http.SessionCreationPolicy) Bean(org.springframework.context.annotation.Bean) Collections(java.util.Collections) AuthenticationProvider(io.gravitee.management.idp.api.authentication.AuthenticationProvider) SecurityConfigurer(org.springframework.security.config.annotation.SecurityConfigurer) AuthenticationProvider(io.gravitee.management.idp.api.authentication.AuthenticationProvider) IdentityProvider(io.gravitee.management.idp.api.IdentityProvider)

Example 4 with AuthenticationManagerBuilder

use of org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder in project credhub by cloudfoundry-incubator.

the class Oauth2TestConfiguration method authenticationManagerBuilder.

@Bean
public AuthenticationManagerBuilder authenticationManagerBuilder() {
    final ObjectPostProcessor<Object> objectPostProcessor = new ObjectPostProcessor<Object>() {

        @Override
        public <O extends Object> O postProcess(O object) {
            return object;
        }
    };
    final AuthenticationManagerBuilder authenticationManagerBuilder = new AuthenticationManagerBuilder(objectPostProcessor);
    authenticationManagerBuilder.parentAuthenticationManager(authenticationManager());
    return authenticationManagerBuilder;
}
Also used : ObjectPostProcessor(org.springframework.security.config.annotation.ObjectPostProcessor) AuthenticationManagerBuilder(org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder) Bean(org.springframework.context.annotation.Bean)

Example 5 with AuthenticationManagerBuilder

use of org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder in project spring-security by spring-projects.

the class AuthenticationConfiguration method getAuthenticationManager.

public AuthenticationManager getAuthenticationManager() throws Exception {
    if (this.authenticationManagerInitialized) {
        return this.authenticationManager;
    }
    AuthenticationManagerBuilder authBuilder = this.applicationContext.getBean(AuthenticationManagerBuilder.class);
    if (this.buildingAuthenticationManager.getAndSet(true)) {
        return new AuthenticationManagerDelegator(authBuilder);
    }
    for (GlobalAuthenticationConfigurerAdapter config : this.globalAuthConfigurers) {
        authBuilder.apply(config);
    }
    this.authenticationManager = authBuilder.build();
    if (this.authenticationManager == null) {
        this.authenticationManager = getAuthenticationManagerBean();
    }
    this.authenticationManagerInitialized = true;
    return this.authenticationManager;
}
Also used : AuthenticationManagerBuilder(org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder)

Aggregations

AuthenticationManagerBuilder (org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder)18 Test (org.junit.jupiter.api.Test)7 Bean (org.springframework.context.annotation.Bean)4 AuthenticationManager (org.springframework.security.authentication.AuthenticationManager)3 AuthenticationProvider (org.springframework.security.authentication.AuthenticationProvider)3 ObjectPostProcessor (org.springframework.security.config.annotation.ObjectPostProcessor)3 HttpSecurity (org.springframework.security.config.annotation.web.builders.HttpSecurity)3 Autowired (org.springframework.beans.factory.annotation.Autowired)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 DefaultSpringSecurityContextSource (org.springframework.security.ldap.DefaultSpringSecurityContextSource)2 Integration (com.epam.ta.reportportal.entity.integration.Integration)1 ReportPortalException (com.epam.ta.reportportal.exception.ReportPortalException)1 IdentityProvider (io.gravitee.management.idp.api.IdentityProvider)1 AuthenticationProvider (io.gravitee.management.idp.api.authentication.AuthenticationProvider)1 IdentityProviderManager (io.gravitee.management.idp.core.plugin.IdentityProviderManager)1 AuthenticationProviderManager (io.gravitee.management.security.authentication.AuthenticationProviderManager)1 JWTCookieGenerator (io.gravitee.management.security.cookies.JWTCookieGenerator)1 AuthenticationSuccessFilter (io.gravitee.management.security.filter.AuthenticationSuccessFilter)1 JWTAuthenticationFilter (io.gravitee.management.security.filter.JWTAuthenticationFilter)1 AuthenticationSuccessListener (io.gravitee.management.security.listener.AuthenticationSuccessListener)1