Advertisement
Guest User

Untitled

a guest
Apr 24th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. package zti;
  2.  
  3. import java.io.IOException;
  4. import java.io.PrintWriter;
  5.  
  6. import javax.servlet.ServletException;
  7. import javax.servlet.annotation.WebServlet;
  8. import javax.servlet.http.HttpServlet;
  9. import javax.servlet.http.HttpServletRequest;
  10. import javax.servlet.http.HttpServletResponse;
  11.  
  12. import javax.security.auth.Subject;
  13. import javax.security.auth.login.LoginContext;
  14. import javax.security.auth.login.LoginException;
  15.  
  16. /**
  17. * Servlet implementation class LoginServlet
  18. */
  19. @WebServlet("/loginAction")
  20. public class LoginServlet extends HttpServlet
  21. {
  22. private static final long serialVersionUID = 1L;
  23.  
  24. private LoginContext loginContext = null;
  25.  
  26. protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  27. String username = request.getParameterValues("username")[0] ;
  28. String password = request.getParameterValues("password")[0] ;
  29.  
  30. PrintWriter out = response.getWriter();
  31.  
  32. try {
  33. loginContext = new LoginContext("system.WEB_INBOUND", new MyCallbackHandler(username));
  34. loginContext.login();
  35. }catch(LoginException e)
  36. {
  37. out.println("Login failed with " + e.getMessage());
  38. return;
  39. }catch(SecurityException e)
  40. {
  41. out.println("Login faiaed with " + e.getMessage());
  42. return;
  43. }
  44.  
  45. out.println ("login succeeded");
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement