KEYCLOAK-16798 Add guarding condition for multi-thread usage in KeycloakDeployment.java

This commit is contained in:
Katsiaryna Mikhalchanka 2021-01-13 13:29:54 +03:00 committed by Hynek Mlnařík
parent ba8e2fef6b
commit 1c445cc4cc

View file

@ -170,9 +170,12 @@ public class KeycloakDeployment {
protected void resolveUrls() { protected void resolveUrls() {
if (realmInfoUrl == null) { if (realmInfoUrl == null) {
synchronized (this) { synchronized (this) {
KeycloakUriBuilder authUrlBuilder = KeycloakUriBuilder.fromUri(authServerBaseUrl); if (realmInfoUrl == null) {
KeycloakUriBuilder authUrlBuilder = KeycloakUriBuilder
.fromUri(authServerBaseUrl);
String discoveryUrl = authUrlBuilder.clone().path(ServiceUrlConstants.DISCOVERY_URL).build(getRealm()).toString(); String discoveryUrl = authUrlBuilder.clone()
.path(ServiceUrlConstants.DISCOVERY_URL).build(getRealm()).toString();
try { try {
log.debugv("Resolving URLs from {0}", discoveryUrl); log.debugv("Resolving URLs from {0}", discoveryUrl);
@ -183,9 +186,14 @@ public class KeycloakDeployment {
tokenUrl = config.getTokenEndpoint(); tokenUrl = config.getTokenEndpoint();
logoutUrl = KeycloakUriBuilder.fromUri(config.getLogoutEndpoint()); logoutUrl = KeycloakUriBuilder.fromUri(config.getLogoutEndpoint());
accountUrl = KeycloakUriBuilder.fromUri(config.getIssuer()).path("/account").build().toString(); accountUrl = KeycloakUriBuilder.fromUri(config.getIssuer()).path("/account")
registerNodeUrl = authUrlBuilder.clone().path(ServiceUrlConstants.CLIENTS_MANAGEMENT_REGISTER_NODE_PATH).build(getRealm()).toString(); .build().toString();
unregisterNodeUrl = authUrlBuilder.clone().path(ServiceUrlConstants.CLIENTS_MANAGEMENT_UNREGISTER_NODE_PATH).build(getRealm()).toString(); registerNodeUrl = authUrlBuilder.clone()
.path(ServiceUrlConstants.CLIENTS_MANAGEMENT_REGISTER_NODE_PATH)
.build(getRealm()).toString();
unregisterNodeUrl = authUrlBuilder.clone()
.path(ServiceUrlConstants.CLIENTS_MANAGEMENT_UNREGISTER_NODE_PATH)
.build(getRealm()).toString();
jwksUrl = config.getJwksUri(); jwksUrl = config.getJwksUri();
log.infov("Loaded URLs from {0}", discoveryUrl); log.infov("Loaded URLs from {0}", discoveryUrl);
@ -195,6 +203,7 @@ public class KeycloakDeployment {
} }
} }
} }
}
protected void resolveUrls(KeycloakUriBuilder authUrlBuilder) { protected void resolveUrls(KeycloakUriBuilder authUrlBuilder) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {