View Javadoc
1   package com.atlassian.sal.core.auth;
2   
3   import com.atlassian.sal.api.auth.AuthenticationListener;
4   import com.atlassian.sal.api.auth.Authenticator;
5   import com.atlassian.seraph.auth.DefaultAuthenticator;
6   import com.atlassian.seraph.filter.BaseLoginFilter;
7   
8   import javax.servlet.http.HttpServletRequest;
9   import javax.servlet.http.HttpServletResponse;
10  
11  public class SeraphAuthenticationListener implements AuthenticationListener {
12      // This is equal to BaseLoginFilter.ALREADY_FILTERED, which has protected access and so can't be referenced
13      private static final String ALREADY_FILTERED = "loginfilter.already.filtered";
14  
15      public void authenticationSuccess(final Authenticator.Result result, final HttpServletRequest request,
16                                        final HttpServletResponse response) {
17          request.getSession().setAttribute(DefaultAuthenticator.LOGGED_IN_KEY, result.getPrincipal());
18          request.getSession().setAttribute(DefaultAuthenticator.LOGGED_OUT_KEY, null);
19  
20          // This must be set to indicate to Crowd that authentication was successful on this request, so don't invalidate
21          // it if other credentials such as SSO tokens are not found
22          request.setAttribute(BaseLoginFilter.OS_AUTHSTATUS_KEY, BaseLoginFilter.LOGIN_SUCCESS);
23  
24          // This must be set because the OAuth filter is plugged in before the login filter, which overwrites the
25          // OS_AUTHSTATUS_KEY attribute, thus this listener will break for SSO providers like Crowd
26          request.setAttribute(ALREADY_FILTERED, Boolean.TRUE);
27      }
28  
29      public void authenticationError(final Authenticator.Result result, final HttpServletRequest request,
30                                      final HttpServletResponse response) {
31      }
32  
33      public void authenticationFailure(final Authenticator.Result result, final HttpServletRequest request,
34                                        final HttpServletResponse response) {
35      }
36  
37      public void authenticationNotAttempted(final HttpServletRequest request, final HttpServletResponse response) {
38      }
39  }