Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package zti;
- import java.io.IOException;
- import java.io.PrintWriter;
- import javax.servlet.ServletException;
- import javax.servlet.annotation.WebServlet;
- import javax.servlet.http.HttpServlet;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import javax.security.auth.Subject;
- import javax.security.auth.login.LoginContext;
- import javax.security.auth.login.LoginException;
- /**
- * Servlet implementation class LoginServlet
- */
- @WebServlet("/loginAction")
- public class LoginServlet extends HttpServlet
- {
- private static final long serialVersionUID = 1L;
- private LoginContext loginContext = null;
- protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
- String username = request.getParameterValues("username")[0] ;
- String password = request.getParameterValues("password")[0] ;
- Boolean success = login(username, password);
- PrintWriter out = response.getWriter();
- if(success)
- {
- out.println ("login succeeded");
- }else
- {
- out.println ("login failed");
- }
- }
- private Boolean login(String username, String password){
- try {
- loginContext = new LoginContext("system.WEB_INBOUND", new MyCallbackHandler(username));
- } catch(LoginException le) {
- return false;
- } catch(SecurityException se) {
- return false;
- }
- try {
- loginContext.login();
- } catch(LoginException le) {
- return false;
- }
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement