While implementing spring security with my GWT based web application. I found that. Everything is working fine as expected, except the below fact:
I opened login.jsp
Alternatively you can create a Servlet Filter:
public class LoginPageFilter implements Filter
{
public void init(FilterConfig filterConfig) throws ServletException {
}
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException
{
HttpServletRequest request = (HttpServletRequest) servletRequest;
HttpServletResponse response = (HttpServletResponse) servletResponse;
if(request.getUserPrincipal() != null){ //If user is already authenticated
response.sendRedirect("");// or, forward using RequestDispatcher
} else{
filterChain.doFilter(servletRequest, servletResponse);
}
}
public void destroy() {
}
}
web.xml:
LoginPageFilter com.xxx.xx.LoginPageFilter
LoginPageFilter
/login