11
I implemented a class to intercept some urls and check if I have a logged-in user in the session, if yes access url, otherwise I am automatically "played" to the login screen.
It happens that on a login page I have a link to register a user on my system, but as I do not have a user in the session because I am a user who will still register, I would like to know how to release my action adicionaUsuario
and let me register the user. Today when registering a user I am taken back to the login screen.
Debugging, when I click on the button that calls the action adicionaUsuario
he doesn’t even get to the method, he returns true
in the Interceptor and already takes me to the login page.
Follow my method below preHandle
of my Interceptor and my method for adding user that comes from the controller:
public class AutorizadorInterceptor extends HandlerInterceptorAdapter {
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object controller) throws Exception {
String uri = request.getRequestURI();
if( uri.endsWith("loginForm") || uri.endsWith("efetuaLogin") || uri.contains("resources") || uri.endsWith("mainUsuario") || uri.endsWith("adicionaUsuario") ) {
return true;
}
if(request.getSession().getAttribute("usuarioLogado") != null) {
return true;
}
response.sendRedirect("loginForm");
return false;
}
}
Controller:
@RequestMapping(value = "adicionaUsuario")
public String adicionaUsuario(Usuario usuario) {
usuarioService.adicionaUsuario(usuario);
return "usuarioSuccess";
}
but if you return "true" you are not saying that you MUST intercept the event?
– deFreitas
Any reason not to use Spring Security?
– utluiz
How about in the method
adicionaUsuario
put the user in session?– utluiz