I have pages in my web application which are accessible only by the administrator. I wrote filter, but I don't understand how to return HTTP error code(403) from the filter if user isn't the admin.
public class AdminFilter implements Filter {
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
String username = servletRequest.getParameter("username");
String password = servletRequest.getParameter("password");
UserDao userDaoImpl = new UserDaoImpl();
if(userDaoImpl.findByUsername(username).getPassword().equals(password)) {
filterChain.doFilter(servletRequest, servletResponse);
} else {
//respond with 403
}
}
}
I understand that I can redirect to my custom 403 page but I'm wondering how to return HTTP error code.