Search in sources :

Example 1 with UmaException

use of org.gluu.oxauth.client.uma.exception.UmaException in project oxAuth by GluuFederation.

the class UmaClient method request.

private static Token request(final String tokenUrl, final String clientKeyStoreFile, final String clientKeyStorePassword, final String clientId, final String keyId, TokenRequest tokenRequest) throws UmaException {
    OxAuthCryptoProvider cryptoProvider;
    try {
        cryptoProvider = new OxAuthCryptoProvider(clientKeyStoreFile, clientKeyStorePassword, null);
    } catch (Exception ex) {
        throw new UmaException("Failed to initialize crypto provider");
    }
    try {
        String tmpKeyId = keyId;
        if (StringHelper.isEmpty(tmpKeyId)) {
            // Get first key
            List<String> aliases = cryptoProvider.getKeys();
            if (aliases.size() > 0) {
                tmpKeyId = aliases.get(0);
            }
        }
        if (StringHelper.isEmpty(tmpKeyId)) {
            throw new UmaException("UMA keyId is empty");
        }
        SignatureAlgorithm algorithm = cryptoProvider.getSignatureAlgorithm(tmpKeyId);
        tokenRequest.setAuthenticationMethod(AuthenticationMethod.PRIVATE_KEY_JWT);
        tokenRequest.setAuthUsername(clientId);
        tokenRequest.setCryptoProvider(cryptoProvider);
        tokenRequest.setAlgorithm(algorithm);
        tokenRequest.setKeyId(tmpKeyId);
        tokenRequest.setAudience(tokenUrl);
        Token umaPat = UmaClient.request(tokenUrl, tokenRequest);
        return umaPat;
    } catch (Exception ex) {
        throw new UmaException("Failed to obtain valid UMA PAT token", ex);
    }
}
Also used : OxAuthCryptoProvider(org.gluu.oxauth.model.crypto.OxAuthCryptoProvider) UmaException(org.gluu.oxauth.client.uma.exception.UmaException) SignatureAlgorithm(org.gluu.oxauth.model.crypto.signature.SignatureAlgorithm) Token(org.gluu.oxauth.model.uma.wrapper.Token) UmaException(org.gluu.oxauth.client.uma.exception.UmaException)

Aggregations

UmaException (org.gluu.oxauth.client.uma.exception.UmaException)1 OxAuthCryptoProvider (org.gluu.oxauth.model.crypto.OxAuthCryptoProvider)1 SignatureAlgorithm (org.gluu.oxauth.model.crypto.signature.SignatureAlgorithm)1 Token (org.gluu.oxauth.model.uma.wrapper.Token)1