You cannot programmatically hook on /j_security_check
. This is a security restriction.
Your best bet is to determine the first-time login by manually checking the user principal in the HttpSession
and put it there if absent and then do your thing. I've posted a similar answer before here. Here's an extract of the filter code, you just need to map the filter on the desired url-pattern
covering the secured pages.
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) {
HttpServletRequest httpRequest = (HttpServletRequest) request;
UserPrincipal user = httpRequest.getUserPrincipal();
HttpSession session = httpRequest.getSession();
if (user != null && session.getAttribute("user") == null) {
session.setAttribute("user", user);
// First-time login. You can do your intercepting thing here.
}
chain.doFilter(request, response);
}