/**
  * 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;
 }
 /**
  * Sets the appropriate fields on the EzSecurityToken for the passed in application information
  *
  * @param token an EzSecurityToken to populate with AppInfo. This object will only have AppInfo
  *     updated on it
  * @param appId the application security id, defaultSecurityId will be used if null
  * @param appPrincipal the application's principal, defaultSecurityId will be used if null
  */
 public static void populateAppInfo(
     final EzSecurityToken token, String appId, String appPrincipal) {
   token.getValidity().setIssuedTo((appId == null) ? defaultSecurityId : appId);
   token.getTokenPrincipal().setPrincipal((appId == null) ? defaultSecurityId : appId);
   token
       .getTokenPrincipal()
       .setExternalID((appPrincipal == null) ? defaultSecurityId : appPrincipal);
 }
  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;
  }