01: package ru.emdev.EmForge.web;
02:
03: import java.io.IOException;
04:
05: import javax.servlet.ServletException;
06: import javax.servlet.http.Cookie;
07: import javax.servlet.http.HttpServletRequest;
08: import javax.servlet.http.HttpServletResponse;
09:
10: import org.acegisecurity.context.SecurityContextHolder;
11: import org.acegisecurity.ui.rememberme.TokenBasedRememberMeServices;
12:
13: /**
14: * Servlet implementation class for Servlet: LogoutServlet
15: *
16: * @web.servlet
17: * name="LogoutServlet"
18: * display-name="LogoutServlet"
19: *
20: * @web.servlet-mapping
21: * url-pattern="/logout"
22: *
23: */
24: public class LogoutServlet extends javax.servlet.http.HttpServlet
25: implements javax.servlet.Servlet {
26: private static final long serialVersionUID = 2101646943730989254L;
27:
28: /* (non-Java-doc)
29: * @see javax.servlet.http.HttpServlet#HttpServlet()
30: */
31: public LogoutServlet() {
32: super ();
33: }
34:
35: /* (non-Java-doc)
36: * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
37: */
38: protected void doGet(HttpServletRequest i_request,
39: HttpServletResponse o_response) throws ServletException,
40: IOException {
41: i_request.getSession().invalidate();
42:
43: Cookie terminate = new Cookie(
44: TokenBasedRememberMeServices.ACEGI_SECURITY_HASHED_REMEMBER_ME_COOKIE_KEY,
45: null);
46: terminate.setMaxAge(0);
47: terminate.setPath(i_request.getContextPath() + "/");
48: o_response.addCookie(terminate);
49:
50: SecurityContextHolder.clearContext();
51:
52: o_response.sendRedirect("index.jsp");
53:
54: /* WebApplicationContext appContext =
55: WebApplicationContextUtils.getWebApplicationContext(i_request.getSession().getServletContext());
56: assert appContext != null;
57:
58:
59: //get entryPointBean
60: AuthenticationEntryPoint entryPoint = (AuthenticationEntryPoint)appContext.getBean("authenticationEntryPoint");
61: assert entryPoint != null;
62:
63: AuthenticationException authException = new AccountExpiredException("Logout user");
64: entryPoint.commence(i_request, o_response, authException);
65:
66: i_request.getSession().setAttribute(
67: AuthenticationProcessingFilter.ACEGI_SECURITY_TARGET_URL_KEY,
68: "index.jsp");
69: */
70:
71: }
72: }
|