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, final HttpServletResponse response) {
16          request.getSession().setAttribute(DefaultAuthenticator.LOGGED_IN_KEY, result.getPrincipal());
17          request.getSession().setAttribute(DefaultAuthenticator.LOGGED_OUT_KEY, null);
18  
19          // This must be set to indicate to Crowd that authentication was successful on this request, so don't invalidate
20          // it if other credentials such as SSO tokens are not found
21          request.setAttribute(BaseLoginFilter.OS_AUTHSTATUS_KEY, BaseLoginFilter.LOGIN_SUCCESS);
22  
23          // This must be set because the OAuth filter is plugged in before the login filter, which overwrites the
24          // OS_AUTHSTATUS_KEY attribute, thus this listener will break for SSO providers like Crowd
25          request.setAttribute(ALREADY_FILTERED, Boolean.TRUE);
26      }
27  
28      public void authenticationError(final Authenticator.Result result, final HttpServletRequest request, final HttpServletResponse response) {
29      }
30  
31      public void authenticationFailure(final Authenticator.Result result, final HttpServletRequest request, final HttpServletResponse response) {
32      }
33  
34      public void authenticationNotAttempted(final HttpServletRequest request, final HttpServletResponse response) {
35      }
36  }