Ejemplo n.º 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;
 }
Ejemplo n.º 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;
  }
Ejemplo n.º 3
0
 @Override
 public boolean isConfigured() {
   return StringUtils.isNotBlank(SecurityConstants.AUTH_PROVIDER.get())
       && !SecurityConstants.NO_PROVIDER.equalsIgnoreCase(SecurityConstants.AUTH_PROVIDER.get());
 }