View Javadoc

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