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;
}
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;
}
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;
}
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;
}
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;
}
}
Aggregations