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