There is no such event in Java EE. Yet. Under JSR375 , container-managed security will be completely redesigned as it is currently scattered across different container implementations and is not compatible with containers. This is stated in the presentation of the Java EE 8 Security API .
There is already a reference implementation of the Soteria security API , developed by Arjan Tijms among my other colleagues. With the new security API, CDI will be used to trigger authentication events that you can simply @Observes . Discussion of this specification took place in this mailing list chain . This is not yet implemented in Soteria.
Until then, provided that FORM based authentication, in which the user-user will be stored internally in the session, your best choice is checked manually in servlet filters, if the request contains a user principle, while your representation of the registered user is a user absent in an HTTP session.
@Override public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) { HttpServletRequest request = (HttpServletRequest) req; String username = request.getRemoteUser(); if (username != null && request.getSession().getAttribute("user") == null) {
Please note that registering a filter on /j_security_check not guaranteed, since a decent container will process it inside before the first filters are deleted, for obvious security reasons (filters provided by the user can poorly manipulate the request, either by accident or deliberately) .
If you, however, use a Java EE server, use an Undertow servletcontainer, such as WildFly , then there is a cleaner way to connect to your internal notification events and then fire custom CDI events. This is featured on this Arjan Tijms blog . As the blog post shows, you can end up creating a CDI bean as follows:
@SessionScoped public class SessionAuthListener implements Serializable { private static final long serialVersionUID = 1L; public void onAuthenticated(@Observes AuthenticatedEvent event) { String username = event.getUserPrincipal().getName();