ユーザーがシステムにログインした後、アクセスを制御したいと思います。
例えば:
administrator : can add, delete and give rights to employee
employee : fill forms only
...
したがって、ユーザーがどの権利を持っているかを知り、データベースをチェックインした後、このユーザーが表示および実行できる内容を制限したいと思います。それを行う簡単な方法はありますか?
編集
@WebFilter("/integra/user/*")
public class LoginFilter implements Filter {
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException, IOException {
HttpServletRequest req = (HttpServletRequest) request;
Authorization authorization = (Authorization) req.getSession().getAttribute("authorization");
if (authorization != null && authorization.isLoggedIn()) {
// User is logged in, so just continue request.
chain.doFilter(request, response);
} else {
// User is not logged in, so redirect to index.
HttpServletResponse res = (HttpServletResponse) response;
res.sendRedirect(req.getContextPath() + "/integra/login.xhtml");
}
}
// You need to override init() and destroy() as well, but they can be kept empty.
@Override
public void init(FilterConfig filterConfig) throws ServletException {
}
@Override
public void destroy() {
}
}