コード例 #1
0
 /**
  * Sets the authorization levels on the token
  *
  * @param token an EzSecurityToken to populate with authorizations
  * @param level the authorization level. if null, defaultAuthorizationLevel will be used
  * @param auths the auths. if null, defaultAuthorizations will be used
  */
 public static void populateAuthorizations(
     final EzSecurityToken token, String level, Set<String> auths) {
   token
       .getAuthorizations()
       .setFormalAuthorizations((auths == null) ? defaultAuthorizations : auths);
   token.setAuthorizationLevel((level == null) ? defaultAuthorizationLevel : level);
 }
コード例 #2
0
  public static EzSecurityToken getMockEzSecurityToken(
      String applicationSecurityId,
      String targetApplicationSecurityId,
      String principal,
      String appPrincipal,
      String citizenship,
      String organization,
      String authorizationLevel,
      Set<String> authorizations,
      Map<String, List<String>> projectGroups,
      TokenType type,
      long tokenExpiration,
      boolean admin,
      boolean validForExternalRequests) {
    EzSecurityToken ezToken = new EzSecurityToken();
    ezToken.setValidity(
        new ValidityCaveats(
            "EzSecurity", applicationSecurityId, System.currentTimeMillis() + tokenExpiration, ""));
    ezToken.getValidity().setIssuedFor(targetApplicationSecurityId);
    ezToken.getAuthorizations().setFormalAuthorizations(authorizations);
    ezToken.setAuthorizationLevel(authorizationLevel);

    ezToken.setType(type);
    switch (type) {
      case USER:
        populateUserInfo(ezToken, principal, citizenship, organization);
        break;
      case APP:
        populateAppInfo(ezToken, applicationSecurityId, appPrincipal);
        break;
    }

    populateExternalProjectGroups(ezToken, projectGroups, admin);

    return ezToken;
  }