Java Code Examples for javax.servlet.http.HttpServletRequest.logout()

The following are Jave code examples for showing how to use logout() of the javax.servlet.http.HttpServletRequest class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: tomcat7   File: TestRequest.java   View Source Code Vote up 8 votes
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {

    req.login(USER, PWD);

    if (!req.getRemoteUser().equals(USER))
        throw new ServletException();
    if (!req.getUserPrincipal().getName().equals(USER))
        throw new ServletException();

    req.logout();

    if (req.getRemoteUser() != null)
        throw new ServletException();
    if (req.getUserPrincipal() != null)
        throw new ServletException();

    resp.getWriter().write(OK);
}
 
Example 2
Project: aws-photosharing-example   File: UserFacade.java   View Source Code Vote up 6 votes
public boolean login(String p_username, String p_password, HttpServletRequest req) {		
	try {			
		req.logout();
		beginTx();
			User u = findUser(p_username);
		
			if (u == null) {
                   _logger.info("User with username " + p_username + " not found");
                   commitTx();	
                   return false;
               }
		
			req.login(u.getId().toString(), Security.getPasswordHash(p_password, u.getSalt()));
			
			u.updatePassword(p_password);				
			u.setLastLogin(new Date());
		commitTx();			
		return true;
	} catch (ServletException e) {
		_logger.error(e.getMessage(), e);
		return false;
	}		
}
 
Example 3
Project: apache-tomcat-7.0.73-with-comment   File: TestRequest.java   View Source Code Vote up 6 votes
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {

    req.login(USER, PWD);

    if (!req.getRemoteUser().equals(USER))
        throw new ServletException();
    if (!req.getUserPrincipal().getName().equals(USER))
        throw new ServletException();

    req.logout();

    if (req.getRemoteUser() != null)
        throw new ServletException();
    if (req.getUserPrincipal() != null)
        throw new ServletException();

    resp.getWriter().write(OK);
}
 
Example 4
Project: servlet-auth   File: MyLogoutServlet.java   View Source Code Vote up 5 votes
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    HttpSession session = request.getSession(false);
    if (session != null) {
        session.invalidate();
    }
    request.logout();
    response.sendRedirect(request.getContextPath() + "/");
}
 
Example 5
Project: istio-ola   File: OlaController.java   View Source Code Vote up 5 votes
@CrossOrigin
@RequestMapping(method = RequestMethod.GET, value = "/logout", produces = "text/plain")
@ApiOperation("Logout")
public String logout() throws ServletException {
  HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest();
  request.logout();
  return "Logged out";
}
 
Example 6
Project: boutique-de-jus   File: AuthAction.java   View Source Code Vote up 5 votes
/**
 * Logs out the user and invalidates the session
 * @return
 *  the method always returns SUCCESS or throws an error if logout fails.
 * @throws ServletException
 */
public String logout() throws ServletException {
    final HttpServletRequest request = ServletActionContext.getRequest();
    final HttpSession session = request.getSession();

    //perform container login
    request.logout();
    session.invalidate();
    return SUCCESS;
}
 
Example 7
Project: aws-photosharing-example   File: UserFacade.java   View Source Code Vote up 5 votes
public void logout(HttpServletRequest req) {		
	req.getSession().invalidate();				
	try {
		req.logout();
	} catch (ServletException e) {
		_logger.error(e.getMessage(), e);
	}
}
 
Example 8
Project: task-app   File: AuthResource.java   View Source Code Vote up 5 votes
@POST
@Path("/logout")
public void logout(@Context HttpServletRequest httpRequest) {
    try {
        httpRequest.logout();
    } catch (ServletException ex) {
        Logger.getLogger(AuthResource.class.getName()).log(Level.SEVERE, null, ex);
    }
}
 
Example 9
Project: servlet-auth   File: MyLoginServlet.java   View Source Code Vote up 4 votes
@Override
protected void doDelete(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    request.logout();
}
 
Example 10
Project: servlet-auth   File: MyLogoutServlet.java   View Source Code Vote up 4 votes
@Override
protected void doDelete(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    request.logout();
}
 
Example 11
Project: keycloak_training   File: Controller.java   View Source Code Vote up 4 votes
public void handleLogout(HttpServletRequest req) throws ServletException {
    if (req.getParameter("logout") != null) {
        req.logout();
    }
}
 
Example 12
Project: keycloak_training   File: Controller.java   View Source Code Vote up 4 votes
public void handleLogout(HttpServletRequest req) throws ServletException {
    if (isLogoutAction(req)) {
        req.logout();
    }
}
 
Example 13
Project: keycloak_training   File: Controller.java   View Source Code Vote up 4 votes
public void handleLogout(HttpServletRequest req) throws ServletException {
    if (isLogoutAction(req)) {
        req.logout();
    }
}
 
Example 14
Project: keycloak_training   File: Controller.java   View Source Code Vote up 4 votes
public void handleLogout(HttpServletRequest req) throws ServletException {
    if (req.getParameter("logout") != null) {
        req.logout();
    }
}
 
Example 15
Project: web-framework-for-java   File: UserController.java   View Source Code Vote up 4 votes
@ApiOperation(value = "Logout")
@RequestMapping(value = "/logout", method = RequestMethod.GET)
public void logout(HttpServletRequest request) throws ServletException {
    request.logout();
}