Better than pure filter does not exist. Springsecurity also filter, but specific and plastered.
Example:
/**
* Filter para tratar login no sistema
*/
@WebFilter(
filterName = "all", urlPatterns = { "/*" }, dispatcherTypes = { DispatcherType.ASYNC, DispatcherType.FORWARD,
DispatcherType.INCLUDE, DispatcherType.REQUEST, DispatcherType.ERROR })
public class NossoFilterAllRequest implements Filter
{
/**
* urlPatterns = { "/*" } isso vai fazer com todas as resições passem por aqui
*/
/**
* @Objetivo Implementar o filtro de logar no sistema
*/
@Override
public void doFilter(ServletRequest requestServlet, ServletResponse responseServlet, FilterChain chain)
throws IOException, ServletException
{
try
{
final HttpServletRequest rq = (HttpServletRequest) request;
final HttpServletResponse rp = (HttpServletResponse) response;
final SeuObjetoSessaoLogin objSession = (SeuObjetoSessaoLogin) rq.getSession().getAttribute("login");
//sua lógica
chain.doFilter(request, response);
}
catch (Exception e)
{
e.printStackTrace();
}
}
@Override
public void destroy()
{
//se precisar logicas de baixar algum serviço, executa quando para o serviço
}
@Override
public void init(FilterConfig config) throws ServletException
{
//se precisar iniciar alguma lógica.. executa quando inicia o serviço
}
}
Basically you can put a manual check on each call that checks the type of user and gives or does not access. In the menus you can hide the items that he should not access. On the screens you check if you have access is throws an error if you do not have, in case a smart guy access the URL directly. How this is done depends on how your system is implemented. For something more advanced you can try Spring Security, but I’d say it’s not worth the effort if it’s an academic system. There are other questions and answers about Spring Security here just search.
– utluiz