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