From ee167f8f819896ea32f29734012a77424957185e Mon Sep 17 00:00:00 2001 From: stianst Date: Thu, 26 Mar 2020 08:17:45 +0100 Subject: [PATCH] Fix links --- .../topics/oidc/java/installed-adapter.adoc | 3 - .../identity-broker/social/openshift.adoc | 4 +- tests/pom.xml | 6 + .../documentation/test/utils/HttpUtils.java | 126 +++++++++++------- .../documentation/test/utils/LinkUtils.java | 4 +- tests/src/test/resources/ignored-links | 3 + 6 files changed, 94 insertions(+), 52 deletions(-) diff --git a/securing_apps/topics/oidc/java/installed-adapter.adoc b/securing_apps/topics/oidc/java/installed-adapter.adoc index a8507b70f2..5bd99e6d75 100644 --- a/securing_apps/topics/oidc/java/installed-adapter.adoc +++ b/securing_apps/topics/oidc/java/installed-adapter.adoc @@ -10,9 +10,6 @@ variant. The desktop variant uses the system browser to gather the user credentials. The manual variant reads the user credentials from `STDIN`. -Tip: Google provides some more information about this approach on at -https://developers.google.com/identity/protocols/OAuth2InstalledApp[OAuth2InstalledApp]. - ===== How it works To authenticate a user with the `desktop` variant the `KeycloakInstalled` diff --git a/server_admin/topics/identity-broker/social/openshift.adoc b/server_admin/topics/identity-broker/social/openshift.adoc index 5d37b20221..ffbe3ac849 100644 --- a/server_admin/topics/identity-broker/social/openshift.adoc +++ b/server_admin/topics/identity-broker/social/openshift.adoc @@ -36,7 +36,7 @@ grantMethod: prompt <4> Use client ID and secret defined by `oc create` command to enter them back on the {project_name} `Add identity provider` page. Go back to {project_name} and specify those items. -Please refer to https://docs.okd.io/latest/architecture/additional_concepts/authentication.html#oauth[official OpenShift documentation] for more detailed guides. +Please refer to https://docs.okd.io/latest/authentication/configuring-internal-oauth.html#oauth-register-additional-client_configuring-internal-oauth[official OpenShift documentation] for more detailed guides. ==== OpenShift 4 @@ -81,4 +81,4 @@ Go back to {project_name} and specify those items. TIP: The OpenShift API server returns `The client is not authorized to request a token using this method` whenever `OAuthClient` `name`, `secret` or `redirectURIs` is incorrect. Make sure you copy-pasted them into {project_name} OpenShift 4 Identity Provider page correctly. -Please refer to https://docs.okd.io/latest/architecture/additional_concepts/authentication.html#oauth[official OpenShift documentation] for more detailed guides. \ No newline at end of file +Please refer to https://docs.okd.io/latest/authentication/configuring-internal-oauth.html#oauth-register-additional-client_configuring-internal-oauth[official OpenShift documentation] for more detailed guides. \ No newline at end of file diff --git a/tests/pom.xml b/tests/pom.xml index 1c9d465d65..cc6146e4af 100644 --- a/tests/pom.xml +++ b/tests/pom.xml @@ -118,6 +118,12 @@ 2.1.0 test + + org.apache.httpcomponents + httpclient + 4.5.12 + test + diff --git a/tests/src/test/java/org/keycloak/documentation/test/utils/HttpUtils.java b/tests/src/test/java/org/keycloak/documentation/test/utils/HttpUtils.java index 80dd7bd82a..878fd20cf7 100644 --- a/tests/src/test/java/org/keycloak/documentation/test/utils/HttpUtils.java +++ b/tests/src/test/java/org/keycloak/documentation/test/utils/HttpUtils.java @@ -1,68 +1,104 @@ package org.keycloak.documentation.test.utils; import org.apache.commons.io.IOUtils; +import org.apache.http.HttpEntity; +import org.apache.http.client.config.CookieSpecs; +import org.apache.http.client.config.RequestConfig; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpHead; +import org.apache.http.cookie.CookieSpec; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.DefaultHttpRequestRetryHandler; +import org.apache.http.impl.client.HttpClientBuilder; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import java.io.IOException; import java.io.StringWriter; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLDecoder; +import java.nio.charset.StandardCharsets; public class HttpUtils { - private static final Logger logger = LogManager.getLogger(HttpUtils.class); + public Response load(String url) { + CloseableHttpClient client = createClient(); + Response response = new Response(); - public boolean isValid(String url) { - Response response = load(url, false, false); - return response.isSuccess(); - } + try { + HttpGet h = new HttpGet(url); + CloseableHttpResponse r = client.execute(h); + int status = r.getStatusLine().getStatusCode(); - public Response load(String url, boolean readContent, boolean followRedirects) { - int retryCount = Constants.HTTP_RETRY; + if (status == 200) { + response.setSuccess(true); - while (true) { - HttpURLConnection.setFollowRedirects(followRedirects); - HttpURLConnection connection = null; - Response response = new Response(); - try { - connection = (HttpURLConnection) new URL(url).openConnection(); - connection.setConnectTimeout(Constants.HTTP_CONNECTION_TIMEOUT); - connection.setReadTimeout(Constants.HTTP_READ_TIMEOUT); - int status = connection.getResponseCode(); - if (status == 200) { - if (readContent) { - StringWriter w = new StringWriter(); - IOUtils.copy(connection.getInputStream(), w, "utf-8"); - response.setContent(w.toString()); - } - response.setSuccess(true); - } else if (status == 301 || status == 302) { - String location = URLDecoder.decode(connection.getHeaderField("Location"), "utf-8"); - response.setRedirectLocation(location); - response.setSuccess(false); - } else { - response.setError("invalid status code " + status); - response.setSuccess(false); - } + HttpEntity entity = r.getEntity(); + String c = IOUtils.toString(entity.getContent(), StandardCharsets.UTF_8); - return response; - } catch (Exception e) { - response.setError("exception " + e.getMessage()); + response.setContent(c); + } else if (status == 301 || status == 302) { + String location = r.getFirstHeader("Location").getValue(); + response.setRedirectLocation(location); response.setSuccess(false); - - retryCount--; - if (retryCount == 0) { - return response; - } - - logger.info("Retrying " + url); - } finally { - if (connection != null) { - connection.disconnect(); - } + } else { + response.setError("invalid status code " + status); + response.setSuccess(false); + } + } catch (Exception e) { + response.setError("exception " + e.getMessage()); + response.setSuccess(false); + } finally { + try { + client.close(); + } catch (IOException e) { } } + + return response; + } + + private CloseableHttpClient createClient() { + return HttpClientBuilder.create() + .setRetryHandler(new DefaultHttpRequestRetryHandler(Constants.HTTP_RETRY, true)) + .setDefaultRequestConfig( + RequestConfig.custom().setCookieSpec(CookieSpecs.IGNORE_COOKIES).build() + ) + .build(); + } + + public Response isValid(String url) { + CloseableHttpClient client = createClient(); + Response response = new Response(); + + try { + HttpHead h = new HttpHead(url); + CloseableHttpResponse r = client.execute(h); + int status = r.getStatusLine().getStatusCode(); + + if (status == 200) { + response.setSuccess(true); + } else if (status == 301 || status == 302) { + String location = r.getFirstHeader("Location").getValue(); + response.setRedirectLocation(location); + response.setSuccess(false); + } else { + response.setError("invalid status code " + status); + response.setSuccess(false); + } + } catch (Exception e) { + response.setError("exception " + e.getMessage()); + response.setSuccess(false); + } finally { + try { + client.close(); + } catch (IOException e) { + } + } + + return response; } public static class Response { diff --git a/tests/src/test/java/org/keycloak/documentation/test/utils/LinkUtils.java b/tests/src/test/java/org/keycloak/documentation/test/utils/LinkUtils.java index bc259f26d4..d74b4c9fbd 100644 --- a/tests/src/test/java/org/keycloak/documentation/test/utils/LinkUtils.java +++ b/tests/src/test/java/org/keycloak/documentation/test/utils/LinkUtils.java @@ -63,7 +63,7 @@ public class LinkUtils { String anchor = link.contains("#") ? link.split("#")[1] : null; String error = null; - HttpUtils.Response response = http.load(link, anchor != null, false); + HttpUtils.Response response = anchor != null ? http.load(link) : http.isValid(link); if (response.getRedirectLocation() != null) { if (!validRedirect(response.getRedirectLocation(), ignoredLinkRedirects)) { @@ -127,7 +127,7 @@ public class LinkUtils { } if (!verifiedLinks.containsKey(image)) { - boolean valid = http.isValid(image); + boolean valid = http.isValid(image).isSuccess(); if (valid) { verifiedLinks.put(image, System.currentTimeMillis()); diff --git a/tests/src/test/resources/ignored-links b/tests/src/test/resources/ignored-links index 145919915e..8291eb7dc6 100644 --- a/tests/src/test/resources/ignored-links +++ b/tests/src/test/resources/ignored-links @@ -31,3 +31,6 @@ https://api.linkedin.com/v2/me https://raw.githubusercontent.com/jboss-container-images/redhat-sso-7-openshift-image/sso-cd-dev/templates/${resource} https://raw.githubusercontent.com/jboss-container-images/redhat-sso-7-openshift-image/sso73-dev/templates/${resource} https://issues.redhat.com/secure/CreateIssueDetails* +https://developer.paypal.com/developer/applications +https://account.live.com/developers/applications/create +https://developer.twitter.com/apps/ \ No newline at end of file