예제 #1
0
 private TokenUtil tokenUtils() {
   TokenUtil tokenUtil = tokenUtilsMap.get(SecurityConstants.AUTH_PROVIDER.get());
   if (tokenUtil == null || !tokenUtil.isConfigured()) {
     throw new ClientVisibleException(
         ResponseCodes.INTERNAL_SERVER_ERROR, "TokenUtilNotConfigured");
   }
   return tokenUtil;
 }
예제 #2
0
  private Token createToken(ApiRequest request) {
    Token token = null;
    if (SecurityConstants.AUTH_PROVIDER.get() == null
        || SecurityConstants.NO_PROVIDER.equalsIgnoreCase(SecurityConstants.AUTH_PROVIDER.get())) {
      throw new ClientVisibleException(
          ResponseCodes.INTERNAL_SERVER_ERROR,
          "NoAuthProvider",
          "No Auth provider is configured.",
          null);
    }
    for (TokenCreator tokenCreator : tokenCreators) {
      if (tokenCreator.isConfigured()
          && tokenCreator.providerType().equalsIgnoreCase(SecurityConstants.AUTH_PROVIDER.get())) {
        token = tokenCreator.getToken(request);
        break;
      }
    }
    if (token == null) {
      throw new ClientVisibleException(
          ResponseCodes.BAD_REQUEST, "codeInvalid", "Code provided is invalid.", null);
    }

    Identity[] identities = token.getIdentities();
    List<Identity> transFormedIdentities = new ArrayList<>();
    for (Identity identity : identities) {
      transFormedIdentities.add(identityManager.untransform(identity, true));
    }
    token.setIdentities(transFormedIdentities);
    token.setUserIdentity(identityManager.untransform(token.getUserIdentity(), true));
    token.setJwt(
        authTokenDao
            .createToken(
                token.getJwt(),
                token.getAuthProvider(),
                ((Policy) ApiContext.getContext().getPolicy()).getAccountId())
            .getKey());
    return token;
  }
예제 #3
0
 @Override
 public boolean isConfigured() {
   return StringUtils.isNotBlank(SecurityConstants.AUTH_PROVIDER.get())
       && !SecurityConstants.NO_PROVIDER.equalsIgnoreCase(SecurityConstants.AUTH_PROVIDER.get());
 }