Search in sources :

Example 6 with ClientRequest

use of org.jboss.resteasy.client.ClientRequest in project oxTrust by GluuFederation.

the class Authenticator method oAuthlLogout.

public void oAuthlLogout() throws Exception {
    OauthData oauthData = identity.getOauthData();
    if (StringHelper.isEmpty(oauthData.getUserUid())) {
        return;
    }
    ClientRequest clientRequest = new ClientRequest(openIdService.getOpenIdConfiguration().getEndSessionEndpoint());
    clientRequest.queryParameter(OxTrustConstants.OXAUTH_SESSION_STATE, oauthData.getSessionState());
    clientRequest.queryParameter(OxTrustConstants.OXAUTH_ID_TOKEN_HINT, oauthData.getIdToken());
    clientRequest.queryParameter(OxTrustConstants.OXAUTH_POST_LOGOUT_REDIRECT_URI, appConfiguration.getLogoutRedirectUrl());
    // Clean up OAuth token
    oauthData.setUserUid(null);
    oauthData.setIdToken(null);
    oauthData.setSessionState(null);
    oauthData = null;
    FacesContext.getCurrentInstance().getExternalContext().redirect(clientRequest.getUri());
}
Also used : OauthData(org.gluu.oxtrust.security.OauthData) ClientRequest(org.jboss.resteasy.client.ClientRequest)

Example 7 with ClientRequest

use of org.jboss.resteasy.client.ClientRequest in project quickstarts by jboss-switchyard.

the class MyClientExecutionInterceptor method execute.

public ClientResponse execute(ClientExecutionContext ctx) throws Exception {
    ClientRequest request = ctx.getRequest();
    ClientResponse response = null;
    response = ctx.proceed();
    if ((response.getResponseStatus() != null) && (response.getResponseStatus().getStatusCode() == 404)) {
        BaseClientResponse r = (BaseClientResponse) response;
        MultivaluedMap<String, String> headers = r.getHeaders();
        headers.add("full-path", request.getUri());
        r.setHeaders(headers);
    }
    return response;
}
Also used : BaseClientResponse(org.jboss.resteasy.client.core.BaseClientResponse) ClientResponse(org.jboss.resteasy.client.ClientResponse) BaseClientResponse(org.jboss.resteasy.client.core.BaseClientResponse) ClientRequest(org.jboss.resteasy.client.ClientRequest)

Example 8 with ClientRequest

use of org.jboss.resteasy.client.ClientRequest in project openstack4j by ContainX.

the class HttpCommand method initialize.

private void initialize() {
    client = new ClientRequest(UriBuilder.fromUri(new EndpointURIFromRequestFunction().apply(request)), ApacheHttpClientExecutor.create(request.getConfig()), ResteasyClientFactory.getInstance());
    client.followRedirects(true);
    populateQueryParams(request);
    populateHeaders(request);
}
Also used : EndpointURIFromRequestFunction(org.openstack4j.core.transport.functions.EndpointURIFromRequestFunction) ClientRequest(org.jboss.resteasy.client.ClientRequest)

Example 9 with ClientRequest

use of org.jboss.resteasy.client.ClientRequest in project oxAuth by GluuFederation.

the class RedirectionUriService method validateRedirectionUri.

public String validateRedirectionUri(String clientIdentifier, String redirectionUri) {
    try {
        Client client = clientService.getClient(clientIdentifier);
        if (client != null) {
            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)) {
                log.debug("Validating redirection URI: clientIdentifier = {}, redirectionUri = {}, found = {}", clientIdentifier, redirectionUri, redirectUris.length);
                final String redirectUriWithoutParams = uriWithoutParams(redirectionUri);
                for (String uri : redirectUris) {
                    log.debug("Comparing {} == {}", uri, redirectionUri);
                    if (uri.equals(redirectionUri)) {
                        // compare complete uri
                        return redirectionUri;
                    }
                    String uriWithoutParams = uriWithoutParams(uri);
                    final Map<String, String> params = getParams(uri);
                    if ((uriWithoutParams.equals(redirectUriWithoutParams) && params.size() == 0 && getParams(redirectionUri).size() == 0) || uriWithoutParams.equals(redirectUriWithoutParams) && params.size() > 0 && compareParams(redirectionUri, uri)) {
                        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;
}
Also used : JSONArray(org.codehaus.jettison.json.JSONArray) Client(org.xdi.oxauth.model.registration.Client) ClientRequest(org.jboss.resteasy.client.ClientRequest)

Example 10 with ClientRequest

use of org.jboss.resteasy.client.ClientRequest in project oxAuth by GluuFederation.

the class RegisterParamsValidator method validateRedirectUris.

/**
     * @param applicationType     The Application Type: native or web.
     * @param subjectType         Subject Type requested for responses to this Client.
     * @param redirectUris        Redirection URI values used by the Client.
     * @param sectorIdentifierUrl A HTTPS scheme URL to be used in calculating Pseudonymous Identifiers by the OP.
     *                            The URL contains a file with a single JSON array of redirect_uri values.
     * @return Whether the Redirect URI parameters are valid or not.
     */
public boolean validateRedirectUris(ApplicationType applicationType, SubjectType subjectType, List<String> redirectUris, String sectorIdentifierUrl) {
    boolean valid = true;
    Set<String> redirectUriHosts = new HashSet<String>();
    try {
        if (redirectUris != null && !redirectUris.isEmpty()) {
            for (String redirectUri : redirectUris) {
                if (redirectUri == null || redirectUri.contains("#")) {
                    valid = false;
                } else {
                    URI uri = new URI(redirectUri);
                    redirectUriHosts.add(uri.getHost());
                    switch(applicationType) {
                        case WEB:
                            if (HTTP.equalsIgnoreCase(uri.getScheme())) {
                                if (!LOCALHOST.equalsIgnoreCase(uri.getHost()) && !LOOPBACK.equalsIgnoreCase(uri.getHost())) {
                                    log.error("Invalid protocol for redirect_uri: " + redirectUri + " (only https protocol is allowed for application_type=web or localhost/127.0.0.1 for http)");
                                    valid = false;
                                }
                            }
                            break;
                        case NATIVE:
                            //                                }
                            break;
                    }
                }
            }
        } else {
            valid = false;
        }
    } catch (URISyntaxException e) {
        valid = false;
    }
    /*
         * Providers that use pairwise sub (subject) values SHOULD utilize the sector_identifier_uri value
         * provided in the Subject Identifier calculation for pairwise identifiers.
         *
         * If the Client has not provided a value for sector_identifier_uri in Dynamic Client Registration,
         * the Sector Identifier used for pairwise identifier calculation is the host component of the
         * registered redirect_uri.
         *
         * If there are multiple hostnames in the registered redirect_uris, the Client MUST register a
         * sector_identifier_uri.
         */
    if (subjectType != null && subjectType.equals(SubjectType.PAIRWISE) && StringUtils.isBlank(sectorIdentifierUrl)) {
        if (redirectUriHosts.size() > 1) {
            valid = false;
        }
    }
    // Validate Sector Identifier URL
    if (valid && StringUtils.isNotBlank(sectorIdentifierUrl)) {
        try {
            URI uri = new URI(sectorIdentifierUrl);
            if (!HTTPS.equalsIgnoreCase(uri.getScheme())) {
                valid = false;
            }
            ClientRequest clientRequest = new ClientRequest(sectorIdentifierUrl);
            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);
                valid = Util.asList(sectorIdentifierJsonArray).containsAll(redirectUris);
            }
        } catch (URISyntaxException e) {
            log.trace(e.getMessage(), e);
            valid = false;
        } catch (UnknownHostException e) {
            log.trace(e.getMessage(), e);
            valid = false;
        } catch (ConnectException e) {
            log.trace(e.getMessage(), e);
            valid = false;
        } catch (JSONException e) {
            log.trace(e.getMessage(), e);
            valid = false;
        } catch (Exception e) {
            log.trace(e.getMessage(), e);
            valid = false;
        }
    }
    // Validate Redirect Uris checking the white list and black list
    if (valid) {
        valid = checkWhiteListRedirectUris(redirectUris) && checkBlackListRedirectUris(redirectUris);
    }
    return valid;
}
Also used : UnknownHostException(java.net.UnknownHostException) JSONArray(org.codehaus.jettison.json.JSONArray) JSONException(org.codehaus.jettison.json.JSONException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) URISyntaxException(java.net.URISyntaxException) ConnectException(java.net.ConnectException) UnknownHostException(java.net.UnknownHostException) JSONException(org.codehaus.jettison.json.JSONException) WebApplicationException(javax.ws.rs.WebApplicationException) ClientRequest(org.jboss.resteasy.client.ClientRequest) HashSet(java.util.HashSet) ConnectException(java.net.ConnectException)

Aggregations

ClientRequest (org.jboss.resteasy.client.ClientRequest)12 JSONArray (org.codehaus.jettison.json.JSONArray)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 ConnectException (java.net.ConnectException)2 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)2 UnknownHostException (java.net.UnknownHostException)2 JSONObject (org.codehaus.jettison.json.JSONObject)2 Client (org.xdi.oxauth.model.registration.Client)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 SignatureException (java.security.SignatureException)1 ArrayList (java.util.ArrayList)1 GregorianCalendar (java.util.GregorianCalendar)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpSession (javax.servlet.http.HttpSession)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)1 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)1