Overriding RequestEventListenerAdapter methods on Spring Boot (Stormpath)

272 views Asked by At

I've been trying to override Stormpath's RequestEventListenerAdapter methods to populate an account's Custom Data when the user logs in or creates an account.

I created a class that extends RequestEventListenerAdapter and am trying to override the on SuccessfulAuthenticationRequestEvent and the on LogoutRequestEvent to make some simple outputs to the console to test if they are working (A simple "Hello world!" for example). But when I do any of these actions on the application, none of these events are triggering. So I was wondering if anyone here could help me out, I'm not sure if the bean I'm supposed to declare is in the right place or if I'm missing some kind of configuration for the events to trigger. Thanks for any help and let me know if more information is needed.

This is my custom class:

import com.stormpath.sdk.servlet.authc.LogoutRequestEvent;
import com.stormpath.sdk.servlet.authc.SuccessfulAuthenticationRequestEvent;
import com.stormpath.sdk.servlet.event.RequestEventListenerAdapter;

public class CustomRequestEventListener extends RequestEventListenerAdapter {

@Override
public void on(SuccessfulAuthenticationRequestEvent e) {
    System.out.println("Received successful authentication request event: {}\n" + e);
}

@Override
public void on(LogoutRequestEvent e) {
    System.out.println("Received logout request event: {}\n" + e);
}
}

This is the bean that I'm not sure where to place:

@Bean
public RequestEventListener stormpathRequestEventListener() {
    return new CustomRequestEventListener();
}
1

There are 1 answers

4
mario On BEST ANSWER

What you are doing looks exactly right. I have created a sample project demonstrating how to get things working. You could take a look at it (it is very simple) and compare it with what you have.

I also added instructions on how to get it running so you can see that it does indeed work.