Guest User

Untitled

a guest
Jan 9th, 2019
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. <html>
  2. <body>
  3. <form action='/webapp/secret' method='post'>
  4. username: <input type='text' name ='username'><br>
  5. password: <input type='password' name ='password'><br>
  6. <input type='submit', value='login'>
  7. </form>
  8. </body>
  9. </html>
  10.  
  11. @WebFilter(filterName = "AuthFilter",urlPatterns = "/secret")
  12. public class AuthFilter implements Filter {
  13. @Override
  14. public void init(FilterConfig filterConfig) throws ServletException {}
  15.  
  16. @Override
  17. public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException {
  18. String username = req.getParameter("username");
  19. String password = req.getParameter("password");
  20.  
  21. if(username == null || password == null){
  22. PrintWriter out = resp.getWriter();
  23. out.println("access denied");
  24. req.getRequestDispatcher("/basic/login.jsp").include(req,resp);
  25. out.println("Access to this page is restricted to authorised people only.");
  26. return;
  27. }
  28.  
  29. Credentials creds = new Credentials(username,password, false);
  30. if(validate(creds)){
  31. req.setAttribute(AuthConstants.ATTR_ACTIVE_USER,creds);
  32. chain.doFilter(req,resp);
  33. } else{
  34. PrintWriter out = resp.getWriter();
  35. out.println("<font color='red'><b>username or pasword is incorrect</b></font>");
  36. req.getRequestDispatcher("/basic/login.jsp").include(req,resp);
  37. out.println("Please try again.");
  38. }
  39. }
  40.  
  41. ...
  42.  
  43. }
  44.  
  45. out.println("access denied");
  46.  
  47. out.println("<font color='red'><b>username or pasword is incorrect</b></font>");
Add Comment
Please, Sign In to add comment