View Javadoc
1   package com.atlassian.sal.core.auth;
2   
3   import com.atlassian.sal.api.auth.AuthenticationController;
4   import com.atlassian.sal.core.util.Assert;
5   import com.atlassian.seraph.auth.RoleMapper;
6   import com.atlassian.seraph.config.SecurityConfigFactory;
7   import com.atlassian.seraph.filter.BaseLoginFilter;
8   
9   import javax.servlet.http.HttpServletRequest;
10  import java.security.Principal;
11  
12  /**
13   * Implementation of the {@link AuthenticationController} to integrate with Atlassian Seraph.
14   */
15  public class SeraphAuthenticationController implements AuthenticationController {
16      private final RoleMapper roleMapper;
17  
18      /**
19       * @throws IllegalArgumentException if the roleMapper is <code>null</code>.
20       */
21      public SeraphAuthenticationController() {
22          RoleMapper roleMapper = SecurityConfigFactory.getInstance().getRoleMapper();
23          this.roleMapper = Assert.notNull(roleMapper, "roleMapper");
24      }
25  
26      /**
27       * Checks the {@link RoleMapper} on whether or not the principal can login.
28       *
29       * @see AuthenticationController#canLogin(Principal, HttpServletRequest)
30       */
31      public boolean canLogin(final Principal principal, final HttpServletRequest request) {
32          return roleMapper.canLogin(principal, request);
33      }
34  
35      /**
36       * Checks the request attibutes for the {@link BaseLoginFilter#OS_AUTHSTATUS_KEY}. Will return <code>true</code> if
37       * the key is not present.
38       */
39      public boolean shouldAttemptAuthentication(final HttpServletRequest request) {
40          return request.getAttribute(BaseLoginFilter.OS_AUTHSTATUS_KEY) == null;
41      }
42  }