コード例 #1
0
 /**
  * Generate an EzSecurityToken with just the basics set on it
  *
  * @param securityId the apps security ID, if null, defaultSecurityId will be used
  * @param targetSecurityId the target security ID, if null, securityId will be used
  * @param expiration how long the token should live before expiring
  * @return the initialized EzSecurityToken
  */
 public static EzSecurityToken getBlankToken(
     String securityId, String targetSecurityId, long expiration) {
   EzSecurityToken token = new EzSecurityToken();
   token.setValidity(
       new ValidityCaveats(
           "EzSecurity",
           securityId == null ? defaultSecurityId : securityId,
           getExpires(expiration),
           ""));
   token
       .getValidity()
       .setIssuedFor(
           (targetSecurityId == null) ? token.getValidity().getIssuedTo() : targetSecurityId);
   token.setTokenPrincipal(new EzSecurityPrincipal("", token.getValidity()));
   token.setAuthorizations(new Authorizations());
   return token;
 }
コード例 #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;
  }