コード例 #1
0
 @Override
 protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
   UserContext userContext = (UserContext) principals.getPrimaryPrincipal();
   HeaderAuthToken headerAuthToken = new HeaderAuthToken();
   headerAuthToken.setUserContext(userContext);
   return populateAccount(headerAuthToken);
 }
コード例 #2
0
  private HeaderAccount populateAccount(HeaderAuthToken headerAuthToken) {
    HeaderAccount headerAccount = new HeaderAccount();

    UserContext userContext = headerAuthToken.getUserContext();
    boolean admin = false;
    if (userContext == null) {
      ServiceProxy serviceProxy = new ServiceProxy();

      if (StringUtils.isBlank(headerAuthToken.getUsername())) {
        // They shouldn't get here unless open am is not configured
        throw new AuthenticationException(
            "Unable to login.  No credentials passed.  Auth filter not set.");
      }

      UserProfile userProfile = new UserProfile();
      userProfile.setUsername(headerAuthToken.getUsername());
      userProfile.setFirstName(headerAuthToken.getFirstname());
      userProfile.setLastName(headerAuthToken.getLastname());
      userProfile.setOrganization(headerAuthToken.getOrganization());
      userProfile.setEmail(headerAuthToken.getEmail());
      userProfile.setExternalGuid(headerAuthToken.getGuid());

      if (StringUtils.isNotBlank(headerAuthToken.getGroup())
          && StringUtils.isNotBlank(headerAuthToken.getAdminGroupName())) {
        admin = headerAuthToken.getGroup().contains(headerAuthToken.getAdminGroupName());
      }
      userContext =
          serviceProxy
              .getUserService()
              .handleLogin(userProfile, headerAuthToken.getRequest(), admin);
    } else {
      admin = userContext.isAdmin();
    }
    headerAccount.setCredentials(userContext);
    headerAccount.getSimplePrincipals().add(userContext, "Open Am Header User");
    if (admin) {
      headerAccount.getRoles().add(SecurityUtil.ADMIN_ROLE);
    }

    return headerAccount;
  }