Search in sources :

Example 46 with TokenRequest

use of org.xdi.oxauth.client.TokenRequest in project oxTrust by GluuFederation.

the class UmaAuthorizationClient method getAuthorizedRpt.

private String getAuthorizedRpt(String asUri, String ticket) throws OxTrustAuthorizationException {
    try {
        // Get metadata configuration
        UmaMetadata umaMetadata = UmaClientFactory.instance().createMetadataService(asUri).getMetadata();
        if (umaMetadata == null) {
            throw new OxTrustAuthorizationException(String.format("Failed to load valid UMA metadata configuration from: %s", asUri));
        }
        TokenRequest tokenRequest = getAuthorizationTokenRequest(umaMetadata);
        // No need for claims token. See comments on issue https://github.com/GluuFederation/SCIM-Client/issues/22
        UmaTokenService tokenService = UmaClientFactory.instance().createTokenService(umaMetadata);
        // ClaimTokenFormatType.ID_TOKEN.getValue()
        UmaTokenResponse rptResponse = tokenService.requestJwtAuthorizationRpt(ClientAssertionType.JWT_BEARER.toString(), tokenRequest.getClientAssertion(), GrantType.OXAUTH_UMA_TICKET.getValue(), ticket, null, null, null, null, null);
        if (rptResponse == null) {
            throw new OxTrustAuthorizationException("UMA RPT token response is invalid");
        }
        if (StringUtils.isBlank(rptResponse.getAccessToken())) {
            throw new OxTrustAuthorizationException("UMA RPT is invalid");
        }
        this.rpt = rptResponse.getAccessToken();
        return rpt;
    } catch (Exception ex) {
        throw new OxTrustAuthorizationException(ex.getMessage(), ex);
    }
}
Also used : UmaMetadata(org.xdi.oxauth.model.uma.UmaMetadata) UmaTokenResponse(org.xdi.oxauth.model.uma.UmaTokenResponse) UmaTokenService(org.xdi.oxauth.client.uma.UmaTokenService) TokenRequest(org.xdi.oxauth.client.TokenRequest)

Aggregations

TokenRequest (org.xdi.oxauth.client.TokenRequest)46 Test (org.testng.annotations.Test)40 BaseTest (org.xdi.oxauth.BaseTest)40 Builder (javax.ws.rs.client.Invocation.Builder)39 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)39 Response (javax.ws.rs.core.Response)39 JSONException (org.codehaus.jettison.json.JSONException)39 JSONObject (org.codehaus.jettison.json.JSONObject)39 ResteasyClientBuilder (org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder)39 Parameters (org.testng.annotations.Parameters)38 OxAuthCryptoProvider (org.xdi.oxauth.model.crypto.OxAuthCryptoProvider)21 URISyntaxException (java.net.URISyntaxException)7 RegisterResponse (org.xdi.oxauth.client.RegisterResponse)3 IOException (java.io.IOException)2 TokenClient (org.xdi.oxauth.client.TokenClient)2 TokenResponse (org.xdi.oxauth.client.TokenResponse)2 ArrayList (java.util.ArrayList)1 AuthorizationRequest (org.xdi.oxauth.client.AuthorizationRequest)1 AuthorizationResponse (org.xdi.oxauth.client.AuthorizationResponse)1 AuthorizeClient (org.xdi.oxauth.client.AuthorizeClient)1