I am studying Java Web and need to make an application with access restriction. Restricting access if the user is not logged in (ie the session created), if the user accesses a URL without being logged in, he should redirect to the login screen. However I am getting a response from the browser that many redirects have been made.
Would anyone know how to guide me because of this error?
Authorization Interceptor.java:
public class AutorizacaoInterceptor extends HandlerInterceptorAdapter {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object controller) throws Exception {
if(!request.getRequestURI().endsWith("login") && null != request.getSession().getAttribute("userId")){
return true;
}
response.sendRedirect("login");
return false;
}
}
dispatcher-servlet.xml:
<context:component-scan base-package="br.com.infnet" />
<mvc:annotation-driven />
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/WEB-INF/jsp/"
p:suffix=".jsp" />
<mvc:resources mapping="/assets/**" location="/assets/"/>
<mvc:interceptors>
<bean class="br.com.infnet.model.AutorizacaoInterceptor" />
</mvc:interceptors>