01 import javax.servlet.*;
02 import javax.servlet.http.HttpServletRequest;
03 import java.io.IOException;
04 import java.security.Principal;
05
06 public class SecurityFilter implements Filter {
07
08 public void init(FilterConfig config) { }
09
10 public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
11 throws IOException, ServletException {
12 Principal principal = ((HttpServletRequest) req).getUserPrincipal();
13 if (principal == null) {
14 req.setAttribute("errorMessage","Nie ste prihlásený!");
15 req.getRequestDispatcher("/login.jsp").forward(req,res);
16 } else {
17 // toto je inštancia pomocnej triedy MyFilterChain
18 chain.doFilter(req,res);
19 }
20 }
21
22 public void destroy() { }
23 }
|