Elytron Undertow ServletExtension/HttpHandler
pcarrollnf Feb 20, 2018 4:17 PMHello, I am using Wildfly 11.0.0 and Elytron security.
I am trying to configure a HttpHandler that will handle login and logout security events. I want to log some information when these events are fired. The ServletExtension and the HttpHandler appear to be configured correctly. However, the handleNotification method of the NotificationReceiver class never seems to be called when I login or logout of my application. The following is my configuration and classes.
The ServletExtension
import javax.servlet.ServletContext; import io.undertow.servlet.ServletExtension; import io.undertow.servlet.api.DeploymentInfo; public class MyHandlerExtension implements ServletExtension { @Override public void handleDeployment( final DeploymentInfo deploymentInfo, final ServletContext servletContext ) { deploymentInfo.addInnerHandlerChainWrapper( handler -> new MyAuthenticationEventHandler( handler ) ); } }
The HttpHandler
import io.undertow.server.HttpHandler; import io.undertow.server.HttpServerExchange; public final class MyAuthenticationEventHandler implements HttpHandler { private final HttpHandler next; public MyAuthenticationEventHandler( final HttpHandler next ) { this.next = next; } @Override public void handleRequest( HttpServerExchange exchange ) throws Exception { SecurityContext securityContext = exchange.getSecurityContext(); securityContext.registerNotificationReceiver( new MySecurityNotificationReceiver() ); next.handleRequest( exchange ); } }
The NotificationReceiver
import io.undertow.security.api.NotificationReceiver; import io.undertow.security.api.SecurityNotification; import io.undertow.security.api.SecurityNotification.EventType; public class MySecurityNotificationReceiver implements NotificationReceiver { @Override public void handleNotification( final SecurityNotification notification ) { switch( notification.getEventType() ) { case AUTHENTICATED: System.out.println( "****Firing AUTHENTICATED Event****" ); break; case LOGGED_OUT: System.out.println( "****Firing LOGGED_OUT Event****" ); break; default: System.out.println( "****Firing " + notification.getEventType() + " Event****" ); break; } } }
I also created a file named io.undertow.servlet.ServletExtension and placed it in the myWar\META-INF\services directory.
myCompany.MyHandlerExtension
Am I missing a configuration step or does the NotificationReceiver no work properly with Elytron security? Or possibly I do not completely understand how it is supposed to work.
Thanks