Java Code Examples for org.jboss.resteasy.client.ClientRequest#get()

The following examples show how to use org.jboss.resteasy.client.ClientRequest#get() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JwtUtil.java    From oxAuth with MIT License 6 votes vote down vote up
public static JSONObject getJSONWebKeys(String jwksUri, ClientExecutor executor) {
    log.debug("Retrieving jwks " + jwksUri + "...");

    JSONObject jwks = null;
    try {
        if (!StringHelper.isEmpty(jwksUri)) {
            ClientRequest clientRequest = executor != null ? new ClientRequest(jwksUri, executor) : new ClientRequest(jwksUri);
            clientRequest.setHttpMethod(HttpMethod.GET);
            ClientResponse<String> clientResponse = clientRequest.get(String.class);

            int status = clientResponse.getStatus();
            log.debug(String.format("Status: %n%d", status));

            if (status == 200) {
                jwks = fromJson(clientResponse.getEntity(String.class));
                log.debug(String.format("JWK: %s", jwks));
            }
        }
    } catch (Exception ex) {
        log.error(ex.getMessage(), ex);
    }

    return jwks;
}
 
Example 2
Source File: HttpUtils.java    From pnc with Apache License 2.0 5 votes vote down vote up
/**
 * Process HTTP requests and tests if server responds with expected HTTP code. Request is implicitly set to accept
 * MIME type application/json.
 *
 * @param ecode Expected HTTP error code
 * @param url Request URL
 * @throws Exception Thrown if some error occurs in communication with server
 */
public static void testResponseHttpCode(int ecode, String url) throws Exception {
    ClientRequest request = new ClientRequest(url);
    request.accept(MediaType.APPLICATION_JSON);

    ClientResponse<String> response = request.get(String.class);
    if (response.getStatus() != ecode)
        throw new Exception("Server returned unexpected HTTP code! Returned code:" + response.getStatus());
}
 
Example 3
Source File: HttpUtils.java    From pnc with Apache License 2.0 4 votes vote down vote up
public static String processGetRequest(String url) throws Exception {
    ClientRequest request = new ClientRequest(url);
    request.accept(MediaType.APPLICATION_JSON);
    ClientResponse<String> response = request.get(String.class);
    return response.getEntity();
}
 
Example 4
Source File: CIBARegisterParamsValidatorService.java    From oxAuth with MIT License 4 votes vote down vote up
public boolean validateParams(
        BackchannelTokenDeliveryMode backchannelTokenDeliveryMode, String backchannelClientNotificationEndpoint,
        AsymmetricSignatureAlgorithm backchannelAuthenticationRequestSigningAlg, Boolean backchannelUserCodeParameter,
        List<GrantType> grantTypes, SubjectType subjectType, String sectorIdentifierUri, String jwks, String jwksUri) {
    try {
        // Not CIBA Registration
        if (backchannelTokenDeliveryMode == null && Strings.isBlank(backchannelClientNotificationEndpoint) && backchannelAuthenticationRequestSigningAlg == null) {
            return true;
        }

        // Required parameter.
        if (backchannelTokenDeliveryMode == null
                || !appConfiguration.getBackchannelTokenDeliveryModesSupported().contains(backchannelTokenDeliveryMode.getValue())) {
            return false;
        }

        // Required if the token delivery mode is set to ping or push.
        if ((backchannelTokenDeliveryMode == PING || backchannelTokenDeliveryMode == PUSH)
                && Strings.isBlank(backchannelClientNotificationEndpoint)) {
            return false;
        }

        // Grant type urn:openid:params:grant-type:ciba is required if the token delivery mode is set to ping or poll.
        if (backchannelTokenDeliveryMode == PING || backchannelTokenDeliveryMode == POLL) {
            if (!appConfiguration.getGrantTypesSupported().contains(CIBA) || !grantTypes.contains(CIBA)) {
                return false;
            }
        }

        // If the server does not support backchannel_user_code_parameter_supported, the default value is false.
        if (appConfiguration.getBackchannelUserCodeParameterSupported() == null || appConfiguration.getBackchannelUserCodeParameterSupported() == false) {
            backchannelUserCodeParameter = false;
        }

        if (subjectType != null && subjectType == SubjectType.PAIRWISE) {

            if (backchannelTokenDeliveryMode == PING || backchannelTokenDeliveryMode == POLL) {
                if (Strings.isBlank(jwks) && Strings.isBlank(jwksUri)) {
                    return false;
                }
            }

            if (Strings.isNotBlank(sectorIdentifierUri)) {
                ClientRequest clientRequest = new ClientRequest(sectorIdentifierUri);
                clientRequest.setHttpMethod(HttpMethod.GET);

                ClientResponse<String> clientResponse = clientRequest.get(String.class);
                int status = clientResponse.getStatus();

                if (status != 200) {
                    return false;
                }

                String entity = clientResponse.getEntity(String.class);
                JSONArray sectorIdentifierJsonArray = new JSONArray(entity);

                if (backchannelTokenDeliveryMode == PING || backchannelTokenDeliveryMode == POLL) {
                    // If a sector_identifier_uri is explicitly provided, then the jwks_uri must be included in the list of
                    // URIs pointed to by the sector_identifier_uri.
                    if (!Strings.isBlank(jwksUri) && !Util.asList(sectorIdentifierJsonArray).contains(jwksUri)) {
                        return false;
                    }
                } else if (backchannelTokenDeliveryMode == PUSH) {
                    // In case a sector_identifier_uri is explicitly provided, then the backchannel_client_notification_endpoint
                    // must be included in the list of URIs pointed to by the sector_identifier_uri.
                    if (!Util.asList(sectorIdentifierJsonArray).contains(backchannelClientNotificationEndpoint)) {
                        return false;
                    }
                }
            }
        }
    } catch (Exception e) {
        log.trace(e.getMessage(), e);
        return false;
    }

    return true;
}
 
Example 5
Source File: RedirectionUriService.java    From oxAuth with MIT License 4 votes vote down vote up
public String validateRedirectionUri(@NotNull Client client, String redirectionUri) {
    try {
        String sectorIdentifierUri = client.getSectorIdentifierUri();
        String[] redirectUris = client.getRedirectUris();

        if (StringUtils.isNotBlank(sectorIdentifierUri)) {
            ClientRequest clientRequest = new ClientRequest(sectorIdentifierUri);
            clientRequest.setHttpMethod(HttpMethod.GET);

            ClientResponse<String> clientResponse = clientRequest.get(String.class);
            int status = clientResponse.getStatus();

            if (status == 200) {
                String entity = clientResponse.getEntity(String.class);
                JSONArray sectorIdentifierJsonArray = new JSONArray(entity);
                redirectUris = new String[sectorIdentifierJsonArray.length()];
                for (int i = 0; i < sectorIdentifierJsonArray.length(); i++) {
                    redirectUris[i] = sectorIdentifierJsonArray.getString(i);
                }
            } else {
                return null;
            }
        }

        if (StringUtils.isNotBlank(redirectionUri) && redirectUris != null) {
            log.debug("Validating redirection URI: clientIdentifier = {}, redirectionUri = {}, found = {}",
                    client.getClientId(), redirectionUri, redirectUris.length);

            if (isUriEqual(redirectionUri, redirectUris)) {
                return redirectionUri;
            }
        } else {
            // Accept Request Without redirect_uri when One Registered
            if (redirectUris != null && redirectUris.length == 1) {
                return redirectUris[0];
            }
        }
    } catch (Exception e) {
        return null;
    }
    return null;
}
 
Example 6
Source File: JwtUtil.java    From oxAuth with MIT License 4 votes vote down vote up
public static JSONObject getJsonKey(String jwksUri, String jwks, String keyId) {
    log.debug("Retrieving JWK Key...");

    JSONObject jsonKey = null;
    try {
        if (StringHelper.isEmpty(jwks)) {
            ClientRequest clientRequest = new ClientRequest(jwksUri);
            clientRequest.setHttpMethod(HttpMethod.GET);
            ClientResponse<String> clientResponse = clientRequest.get(String.class);

            int status = clientResponse.getStatus();
            log.debug(String.format("Status: %n%d", status));

            if (status == 200) {
                jwks = clientResponse.getEntity(String.class);
                log.debug(String.format("JWK: %s", jwks));
            }
        }
        if (StringHelper.isNotEmpty(jwks)) {
            JSONObject jsonObject = new JSONObject(jwks);
            JSONArray keys = jsonObject.getJSONArray(JSON_WEB_KEY_SET);
            if (keys.length() > 0) {
                if (StringHelper.isEmpty(keyId)) {
                    jsonKey = keys.getJSONObject(0);
                } else {
                    for (int i = 0; i < keys.length(); i++) {
                        JSONObject kv = keys.getJSONObject(i);
                        if (kv.getString(KEY_ID).equals(keyId)) {
                            jsonKey = kv;
                            break;
                        }
                    }
                }
            }
        }
    } catch (Exception ex) {
        log.error(ex.getMessage(), ex);
    }

    return jsonKey;
}
 
Example 7
Source File: HttpUtils.java    From pnc with Apache License 2.0 3 votes vote down vote up
/**
 * Process HTTP GET request and get the data as type specified as parameter. Client accepts application/json MIME
 * type.
 *
 * @param clazz Class to which the data are unmarshalled
 * @param <T> module config
 * @param url Request URL
 * @throws Exception Thrown if some error occurs in communication with server
 * @return Unmarshalled entity data
 */
public static <T> T processGetRequest(Class<T> clazz, String url) throws Exception {
    ClientRequest request = new ClientRequest(url);
    request.accept(MediaType.APPLICATION_JSON);

    ClientResponse<T> response = request.get(clazz);
    return response.getEntity();
}