Search in sources :

Example 1 with ClientRequest

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

the class JwtUtil method getJSONWebKeys.

public static JSONObject getJSONWebKeys(String jwksUri) {
    log.debug("Retrieving jwks...");
    JSONObject jwks = null;
    try {
        if (!StringHelper.isEmpty(jwksUri)) {
            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 = new JSONObject(clientResponse.getEntity(String.class));
                log.debug(String.format("JWK: %s", jwks));
            }
        }
    } catch (Exception ex) {
        log.error(ex.getMessage(), ex);
    }
    return jwks;
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) ClientRequest(org.jboss.resteasy.client.ClientRequest) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 2 with ClientRequest

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

the class JwtUtil method getJsonKey.

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;
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) JSONArray(org.codehaus.jettison.json.JSONArray) ClientRequest(org.jboss.resteasy.client.ClientRequest) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 3 with ClientRequest

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

the class AuthorizeClient method exec.

@Deprecated
public AuthorizationResponse exec(ClientExecutor clientExecutor) {
    AuthorizationResponse response = null;
    try {
        clientRequest = new ClientRequest(getUrl(), clientExecutor);
        response = exec_();
    } catch (Exception e) {
        LOG.error(e.getMessage(), e);
    }
    return response;
}
Also used : ClientRequest(org.jboss.resteasy.client.ClientRequest)

Example 4 with ClientRequest

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

the class SignOutHandler method getOAuthLogoutUrl.

public String getOAuthLogoutUrl(final HttpServletRequest servletRequest) {
    final HttpServletRequest request = (HttpServletRequest) servletRequest;
    final HttpSession session = request.getSession(false);
    if (session == null) {
        log.trace("There is no exising session");
        return null;
    }
    OAuthData oAuthData = (OAuthData) session.getAttribute(Configuration.SESSION_OAUTH_DATA);
    if (oAuthData == null) {
        log.trace("There is no OAuthData in the session");
        return null;
    }
    // TODO: Validate access token
    ClientRequest clientRequest = new ClientRequest(Configuration.instance().getPropertyValue(Configuration.OAUTH_PROPERTY_LOGOUT_URL));
    clientRequest.queryParameter(Configuration.OAUTH_ID_TOKEN_HINT, oAuthData.getIdToken());
    clientRequest.queryParameter(Configuration.OAUTH_POST_LOGOUT_REDIRECT_URI, constructRedirectUrl(request));
    // Remove OAuth data from session
    session.removeAttribute(Configuration.SESSION_OAUTH_DATA);
    try {
        return clientRequest.getUri();
    } catch (Exception ex) {
        log.error("Failed to prepare OAuth log out URL", ex);
    }
    return null;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpSession(javax.servlet.http.HttpSession) ClientRequest(org.jboss.resteasy.client.ClientRequest)

Example 5 with ClientRequest

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

the class RecaptchaUtil method verifyGoogleRecaptcha.

public boolean verifyGoogleRecaptcha(String gRecaptchaResponse, String secretKey) {
    boolean result = false;
    try {
        ClientRequest request = new ClientRequest("https://www.google.com/recaptcha/api/siteverify");
        request.formParameter("secret", secretKey);
        request.formParameter("response", gRecaptchaResponse);
        request.accept("application/json");
        ClientResponse<String> response = request.post(String.class);
        ObjectMapper mapper = new ObjectMapper();
        Map<String, String> map = mapper.readValue(new ByteArrayInputStream(response.getEntity().getBytes()), new TypeReference<Map<String, String>>() {
        });
        return Boolean.parseBoolean(map.get("success"));
    } catch (Exception e) {
        log.error("Exception happened while verifying recaptcha ", e);
        return result;
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Map(java.util.Map) ClientRequest(org.jboss.resteasy.client.ClientRequest) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Aggregations

ClientRequest (org.jboss.resteasy.client.ClientRequest)13 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 Cookie (javax.servlet.http.Cookie)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