View Javadoc

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