View Javadoc
1   package com.atlassian.refapp.auth.internal;
2   
3   import com.atlassian.seraph.auth.Authenticator;
4   import com.atlassian.seraph.auth.AuthenticatorException;
5   
6   import javax.servlet.ServletException;
7   import javax.servlet.http.HttpServlet;
8   import javax.servlet.http.HttpServletRequest;
9   import javax.servlet.http.HttpServletResponse;
10  import java.io.IOException;
11  
12  /**
13   * Handles log out for the reference app.  Used instead of the Seraph {@link com.atlassian.seraph.logout.LogoutServlet}
14   * because that requires a hardcoded redirect URL.
15   */
16  public class LogoutServlet extends HttpServlet {
17      private final Authenticator auth;
18  
19      public LogoutServlet(Authenticator auth) {
20          this.auth = auth;
21      }
22  
23      @Override
24      protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
25          try {
26              auth.logout(request, response);
27              request.getSession().invalidate();
28              RedirectHelper.redirect(request, response);
29          } catch (AuthenticatorException e) {
30              throw new ServletException(e);
31          }
32      }
33  }