diff --git a/multiuser/keycloak/che-multiuser-keycloak-server/pom.xml b/multiuser/keycloak/che-multiuser-keycloak-server/pom.xml
index 3ea5c7870aa..419930a301e 100644
--- a/multiuser/keycloak/che-multiuser-keycloak-server/pom.xml
+++ b/multiuser/keycloak/che-multiuser-keycloak-server/pom.xml
@@ -147,6 +147,11 @@
javax.servlet-api
provided
+
+ com.github.tomakehurst
+ wiremock-jre8-standalone
+ test
+
com.jayway.restassured
rest-assured
diff --git a/multiuser/keycloak/che-multiuser-keycloak-server/src/main/java/org/eclipse/che/multiuser/keycloak/server/KeycloakJwkProvider.java b/multiuser/keycloak/che-multiuser-keycloak-server/src/main/java/org/eclipse/che/multiuser/keycloak/server/KeycloakJwkProvider.java
index 22f2135179c..688906d589f 100644
--- a/multiuser/keycloak/che-multiuser-keycloak-server/src/main/java/org/eclipse/che/multiuser/keycloak/server/KeycloakJwkProvider.java
+++ b/multiuser/keycloak/che-multiuser-keycloak-server/src/main/java/org/eclipse/che/multiuser/keycloak/server/KeycloakJwkProvider.java
@@ -19,7 +19,6 @@
import javax.inject.Inject;
import javax.inject.Provider;
import org.eclipse.che.inject.ConfigurationException;
-import org.eclipse.che.multiuser.keycloak.shared.KeycloakConstants;
/** Constructs {@link UrlJwkProvider} based on Jwk endpoint from keycloak settings */
public class KeycloakJwkProvider implements Provider {
@@ -27,10 +26,8 @@ public class KeycloakJwkProvider implements Provider {
private final JwkProvider jwkProvider;
@Inject
- public KeycloakJwkProvider(KeycloakSettings keycloakSettings) throws MalformedURLException {
-
- final String jwksUrl =
- keycloakSettings.getInternalSettings().get(KeycloakConstants.JWKS_ENDPOINT_SETTING);
+ public KeycloakJwkProvider(OIDCInfo oidcInfo) throws MalformedURLException {
+ final String jwksUrl = oidcInfo.getJwksUri();
if (jwksUrl == null) {
throw new ConfigurationException("Jwks endpoint url not found in keycloak settings");
diff --git a/multiuser/keycloak/che-multiuser-keycloak-server/src/main/java/org/eclipse/che/multiuser/keycloak/server/KeycloakProfileRetriever.java b/multiuser/keycloak/che-multiuser-keycloak-server/src/main/java/org/eclipse/che/multiuser/keycloak/server/KeycloakProfileRetriever.java
index f09e16a9fad..61ff00ffa6f 100644
--- a/multiuser/keycloak/che-multiuser-keycloak-server/src/main/java/org/eclipse/che/multiuser/keycloak/server/KeycloakProfileRetriever.java
+++ b/multiuser/keycloak/che-multiuser-keycloak-server/src/main/java/org/eclipse/che/multiuser/keycloak/server/KeycloakProfileRetriever.java
@@ -19,7 +19,6 @@
import org.eclipse.che.api.core.ApiException;
import org.eclipse.che.api.core.ServerException;
import org.eclipse.che.api.core.rest.HttpJsonRequestFactory;
-import org.eclipse.che.multiuser.keycloak.shared.KeycloakConstants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -36,11 +35,9 @@ public class KeycloakProfileRetriever {
private final HttpJsonRequestFactory requestFactory;
@Inject
- public KeycloakProfileRetriever(
- KeycloakSettings keycloakSettings, HttpJsonRequestFactory requestFactory) {
+ public KeycloakProfileRetriever(OIDCInfo oidcInfo, HttpJsonRequestFactory requestFactory) {
this.requestFactory = requestFactory;
- this.keyclockCurrentUserInfoUrl =
- keycloakSettings.getInternalSettings().get(KeycloakConstants.USERINFO_ENDPOINT_SETTING);
+ this.keyclockCurrentUserInfoUrl = oidcInfo.getUserInfoEndpoint();
}
/**
diff --git a/multiuser/keycloak/che-multiuser-keycloak-server/src/main/java/org/eclipse/che/multiuser/keycloak/server/KeycloakServiceClient.java b/multiuser/keycloak/che-multiuser-keycloak-server/src/main/java/org/eclipse/che/multiuser/keycloak/server/KeycloakServiceClient.java
index 34bc4626968..ffc5d59cbaf 100644
--- a/multiuser/keycloak/che-multiuser-keycloak-server/src/main/java/org/eclipse/che/multiuser/keycloak/server/KeycloakServiceClient.java
+++ b/multiuser/keycloak/che-multiuser-keycloak-server/src/main/java/org/eclipse/che/multiuser/keycloak/server/KeycloakServiceClient.java
@@ -11,7 +11,6 @@
*/
package org.eclipse.che.multiuser.keycloak.server;
-import static org.eclipse.che.multiuser.keycloak.shared.KeycloakConstants.AUTH_SERVER_URL_INTERNAL_SETTING;
import static org.eclipse.che.multiuser.keycloak.shared.KeycloakConstants.REALM_SETTING;
import com.google.common.io.CharStreams;
@@ -62,6 +61,7 @@
public class KeycloakServiceClient {
private KeycloakSettings keycloakSettings;
+ private final OIDCInfo oidcInfo;
private static final Pattern assotiateUserPattern =
Pattern.compile("User (.+) is not associated with identity provider (.+)");
@@ -70,8 +70,10 @@ public class KeycloakServiceClient {
private JwtParser jwtParser;
@Inject
- public KeycloakServiceClient(KeycloakSettings keycloakSettings, JwtParser jwtParser) {
+ public KeycloakServiceClient(
+ KeycloakSettings keycloakSettings, OIDCInfo oidcInfo, JwtParser jwtParser) {
this.keycloakSettings = keycloakSettings;
+ this.oidcInfo = oidcInfo;
this.jwtParser = jwtParser;
}
@@ -101,8 +103,7 @@ public String getAccountLinkingURL(
byte[] check = md.digest(input.getBytes(StandardCharsets.UTF_8));
final String hash = Base64.getUrlEncoder().encodeToString(check);
- return UriBuilder.fromUri(
- keycloakSettings.getInternalSettings().get(AUTH_SERVER_URL_INTERNAL_SETTING))
+ return UriBuilder.fromUri(oidcInfo.getAuthServerURL())
.path("/realms/{realm}/broker/{provider}/link")
.queryParam("nonce", nonce)
.queryParam("hash", hash)
@@ -128,8 +129,7 @@ public KeycloakTokenResponse getIdentityProviderToken(String oauthProvider)
throws ForbiddenException, BadRequestException, IOException, NotFoundException,
ServerException, UnauthorizedException {
String url =
- UriBuilder.fromUri(
- keycloakSettings.getInternalSettings().get(AUTH_SERVER_URL_INTERNAL_SETTING))
+ UriBuilder.fromUri(oidcInfo.getAuthServerURL())
.path("/realms/{realm}/broker/{provider}/token")
.build(keycloakSettings.get().get(REALM_SETTING), oauthProvider)
.toString();
diff --git a/multiuser/keycloak/che-multiuser-keycloak-server/src/main/java/org/eclipse/che/multiuser/keycloak/server/KeycloakSettings.java b/multiuser/keycloak/che-multiuser-keycloak-server/src/main/java/org/eclipse/che/multiuser/keycloak/server/KeycloakSettings.java
index 1b3a7b6c8d6..f7a64d4fa6b 100644
--- a/multiuser/keycloak/che-multiuser-keycloak-server/src/main/java/org/eclipse/che/multiuser/keycloak/server/KeycloakSettings.java
+++ b/multiuser/keycloak/che-multiuser-keycloak-server/src/main/java/org/eclipse/che/multiuser/keycloak/server/KeycloakSettings.java
@@ -11,8 +11,6 @@
*/
package org.eclipse.che.multiuser.keycloak.server;
-import static com.google.common.base.MoreObjects.firstNonNull;
-import static org.eclipse.che.multiuser.keycloak.shared.KeycloakConstants.AUTH_SERVER_URL_INTERNAL_SETTING;
import static org.eclipse.che.multiuser.keycloak.shared.KeycloakConstants.AUTH_SERVER_URL_SETTING;
import static org.eclipse.che.multiuser.keycloak.shared.KeycloakConstants.CLIENT_ID_SETTING;
import static org.eclipse.che.multiuser.keycloak.shared.KeycloakConstants.FIXED_REDIRECT_URL_FOR_DASHBOARD;
@@ -32,112 +30,44 @@
import static org.eclipse.che.multiuser.keycloak.shared.KeycloakConstants.USE_FIXED_REDIRECT_URLS_SETTING;
import static org.eclipse.che.multiuser.keycloak.shared.KeycloakConstants.USE_NONCE_SETTING;
-import com.fasterxml.jackson.core.JsonFactory;
-import com.fasterxml.jackson.core.JsonParser;
-import com.fasterxml.jackson.core.type.TypeReference;
-import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.Maps;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
import java.util.Collections;
import java.util.Map;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import org.eclipse.che.commons.annotation.Nullable;
-import org.eclipse.che.commons.proxy.ProxyAuthenticator;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/** @author Max Shaposhnik (mshaposh@redhat.com) */
@Singleton
public class KeycloakSettings {
- private static final Logger LOG = LoggerFactory.getLogger(KeycloakSettings.class);
- private static final String DEFAULT_USERNAME_CLAIM = "preferred_username";
+ protected static final String DEFAULT_USERNAME_CLAIM = "preferred_username";
- /**
- * Public Keycloak connection settings. It contains information about keycloak api urls and
- * information required to make Keycloak connection using public domain hostname. This info will
- * be shared with frontend.
- */
private final Map settings;
- /**
- * Internal network Keycloak connection settings. It contains information about keycloak api urls
- * and information required to make connection using k8s/openshift internal services hostname.
- * This info will be used only on the Che server side. If using internal network is disabled, then
- * will be included settings with public domain hostname.
- */
- private final Map internalSettings;
+ private final String oidcProviderUrl;
@Inject
public KeycloakSettings(
@Named("che.api") String cheServerEndpoint,
@Nullable @Named(JS_ADAPTER_URL_SETTING) String jsAdapterUrl,
@Nullable @Named(AUTH_SERVER_URL_SETTING) String serverURL,
- @Nullable @Named(AUTH_SERVER_URL_INTERNAL_SETTING) String serverInternalURL,
@Nullable @Named(REALM_SETTING) String realm,
@Named(CLIENT_ID_SETTING) String clientId,
- @Nullable @Named(OIDC_PROVIDER_SETTING) String oidcProvider,
+ @Nullable @Named(OIDC_PROVIDER_SETTING) String oidcProviderUrl,
@Nullable @Named(USERNAME_CLAIM_SETTING) String usernameClaim,
@Named(USE_NONCE_SETTING) boolean useNonce,
@Nullable @Named(OSO_ENDPOINT_SETTING) String osoEndpoint,
@Nullable @Named(GITHUB_ENDPOINT_SETTING) String gitHubEndpoint,
- @Named(USE_FIXED_REDIRECT_URLS_SETTING) boolean useFixedRedirectUrls) {
-
- serverInternalURL = (serverInternalURL != null) ? serverInternalURL : serverURL;
-
- if (serverURL == null && serverInternalURL == null && oidcProvider == null) {
- throw new RuntimeException(
- "Either the '"
- + AUTH_SERVER_URL_SETTING
- + "'or'"
- + AUTH_SERVER_URL_INTERNAL_SETTING
- + "' or '"
- + OIDC_PROVIDER_SETTING
- + "' property should be set");
- }
-
- if (oidcProvider == null && realm == null) {
- throw new RuntimeException("The '" + REALM_SETTING + "' property should be set");
- }
-
- String wellKnownEndpoint = firstNonNull(oidcProvider, serverInternalURL + "/realms/" + realm);
- if (!wellKnownEndpoint.endsWith("/")) {
- wellKnownEndpoint = wellKnownEndpoint + "/";
- }
- wellKnownEndpoint += ".well-known/openid-configuration";
-
- LOG.info("Retrieving OpenId configuration from endpoint: {}", wellKnownEndpoint);
-
- Map openIdConfiguration;
- ProxyAuthenticator.initAuthenticator(wellKnownEndpoint);
- try (InputStream inputStream = new URL(wellKnownEndpoint).openStream()) {
- final JsonFactory factory = new JsonFactory();
- final JsonParser parser = factory.createParser(inputStream);
- final TypeReference
+
+ com.github.tomakehurst
+ wiremock-jre8-standalone
+ ${com.github.tomakehurst.wiremock-jre8-standalone.version}
+
com.google.code.findbugs
jsr305