Skip to content

Can't use custom authenticationEventPublisher on last ProviderManager #4400

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mondaka opened this issue Jun 16, 2017 · 1 comment
Closed
Assignees
Labels
in: web An issue in web modules (web, webmvc) type: enhancement A general enhancement
Milestone

Comments

@mondaka
Copy link

mondaka commented Jun 16, 2017

Summary

When you extend WebSecurityConfigurerAdapter and override the method
protected final void configure(AuthenticationManagerBuilder auth) throws Exception
to set auth.authenticationEventPublisher(defaultAuthenticationEventPublisher);
it doesn't work propertly.

Actual Behavior

When you use the auth.authenticationEventPublisher(defaultAuthenticationEventPublisher) method
to set a custom AuthenticationEventPublisher, the localConfigureAuthenticationBldr (that is an AuthenticationManagerBuilder instance which manage AuthenticationManager buiding) on WebSecurityConfigurerAdapter doesn't build anything (returns null, because it needs AuthenticationProviders to be built).

I have tried a workaround using a "dummy" AuthenticationProvider, but in this case, the structure of built ProviderManagers on WebSecurityConfigurerAdapter is: the one that is built by the localConfigureAuthenticationBldr is set as parent of the other one created by authenticationBuilder.

This causes that we can't set an AuthenticationEventPublisher at the ProviderManager built by authenticationBuilder and consequently, the exceptions thrown by this ProviderManager don't fire any event.

Expected Behavior

Set an AuthenticationEventPublisher on "last" ProviderManager (the one created by authenticationBuilder on WebSecurityConfigurerAdapter), that fire events on this ProviderManager and not in his parent.

Configuration

Version

4.1.0

Sample

@EnableWebSecurity
@Configuration
public abstract class MySecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        
        http.x509()
            .authenticationUserDetailsService(authenticationUserDetailsService);
    }

    @Override
    protected final void configure(AuthenticationManagerBuilder auth) throws Exception {
    	auth.authenticationEventPublisher(defaultAuthenticationEventPublisher);
    }

   @Bean
   public DefaultAuthenticationEventPublisher defaultAuthenticationEventPublisher() {
         return   new DefaultAuthenticationEventPublisher();
   }
}
@Component
public class MyAppListener implements ApplicationListener<AbstractAuthenticationEvent>, ApplicationContextAware {
    
    private static final org.slf4j.Logger LOG =     
       org.slf4j.LoggerFactory.getLogger(MyAppListener .class);

    @Override
    public void onApplicationEvent(AbstractAuthenticationEvent authEvent) {
       LOG.debug("Event: " + authEvent.getClass().getName() + " throwed");
    }
}
@mondaka mondaka changed the title Can't use custom authenticationEventPublisher on button ProviderManager Can't use custom authenticationEventPublisher on bottom ProviderManager Jun 25, 2017
@mondaka mondaka changed the title Can't use custom authenticationEventPublisher on bottom ProviderManager Can't use custom authenticationEventPublisher on last ProviderManager Sep 6, 2017
@anhquande
Copy link

anhquande commented Dec 14, 2017

+1
I encounter the same problem

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label May 7, 2019
jzheaux added a commit to jzheaux/spring-security that referenced this issue Jan 14, 2020
@jzheaux jzheaux self-assigned this Mar 4, 2020
@jzheaux jzheaux added in: web An issue in web modules (web, webmvc) type: enhancement A general enhancement labels Mar 4, 2020
@jzheaux jzheaux added this to the 5.3.0.RC1 milestone Mar 4, 2020
@jzheaux jzheaux removed the status: waiting-for-triage An issue we've not yet triaged label Aug 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web An issue in web modules (web, webmvc) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

4 participants