Changed to an implementation more resilient to the absence of the orchestrator and keycloak clients
This commit is contained in:
parent
9ab6a6f22f
commit
44a75b2aff
|
@ -73,11 +73,14 @@ public class OrchestratorEventPublisherProvider extends AbstractEventPublisher
|
|||
OrchestratorEventPublisherProviderFactory.KEYCLOAK_ENDPOINT,
|
||||
OrchestratorEventPublisherProviderFactory.KEYCLOAK_CLIENT_ID);
|
||||
|
||||
return new HTTPWithUMAAuthEventSender(OrchestratorEventPublisherProviderFactory.ORCHESTRATOR_ENDPOINT,
|
||||
OrchestratorEventPublisherProviderFactory.KEYCLOAK_CLIENT_ID,
|
||||
OrchestratorEventPublisherProviderFactory.KEYCLOAK_CLIENT_SECRET,
|
||||
OrchestratorEventPublisherProviderFactory.KEYCLOAK_ENDPOINT,
|
||||
OrchestratorEventPublisherProviderFactory.KEYCLOAK_CLIENT_ID);
|
||||
return OrchestratorEventPublisherProviderFactory.KEYCLOAK_ENDPOINT != null
|
||||
? new HTTPWithUMAAuthEventSender(OrchestratorEventPublisherProviderFactory.ORCHESTRATOR_ENDPOINT,
|
||||
OrchestratorEventPublisherProviderFactory.KEYCLOAK_CLIENT_ID,
|
||||
OrchestratorEventPublisherProviderFactory.KEYCLOAK_CLIENT_SECRET,
|
||||
OrchestratorEventPublisherProviderFactory.KEYCLOAK_ENDPOINT,
|
||||
OrchestratorEventPublisherProviderFactory.KEYCLOAK_CLIENT_ID)
|
||||
: new HTTPWithUMAAuthEventSender(OrchestratorEventPublisherProviderFactory.ORCHESTRATOR_ENDPOINT, null,
|
||||
null, null, null);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -47,36 +47,48 @@ public class OrchestratorEventPublisherProviderFactory implements EventListenerP
|
|||
if (oepp == null || elapsed > CHECK_DELAY) {
|
||||
lastEndpointCheck = now;
|
||||
ClientModel orchestratorClient = getClientInActualOrMasterRealm(keycloakSession, ORCHESTRATOR_CLIENT_ID);
|
||||
ClientModel keycloakClient = getClientInActualOrMasterRealm(keycloakSession, KEYCLOAK_CLIENT_ID);
|
||||
logger.debug("Getting configured orchestrator endpoint address from client's base URL");
|
||||
String orchestratorAddress = orchestratorClient.getBaseUrl();
|
||||
logger.debug("Getting configured keycloak endpoint address from client's base URL");
|
||||
String keycloakAddress = keycloakClient.getBaseUrl();
|
||||
logger.debug("Getting configured keycloak client client-secret from client");
|
||||
String keycloakClientSecret = keycloakClient.getSecret();
|
||||
URL newOrchestratorEndpoint;
|
||||
if (orchestratorClient != null) {
|
||||
logger.trace("Getting configured orchestrator endpoint address from client's base URL");
|
||||
try {
|
||||
newOrchestratorEndpoint = new URL(orchestratorClient.getBaseUrl());
|
||||
} catch (MalformedURLException e) {
|
||||
logger.errorf("Can't create new orchestrator endpoint address: %s", orchestratorClient.getBaseUrl(),
|
||||
e);
|
||||
oepp = null;
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
logger.debugf("Can't go ahead without a configured '%f' client", ORCHESTRATOR_CLIENT_ID);
|
||||
oepp = null;
|
||||
return null;
|
||||
}
|
||||
ClientModel keycloakClient = getClientInActualOrMasterRealm(keycloakSession, KEYCLOAK_CLIENT_ID);
|
||||
URL newKeycloakEndpoint;
|
||||
try {
|
||||
newOrchestratorEndpoint = new URL(orchestratorAddress);
|
||||
} catch (MalformedURLException e) {
|
||||
logger.errorf("Can't create new orchestrator endpoint address: %s",
|
||||
orchestratorAddress, e);
|
||||
oepp = null;
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
newKeycloakEndpoint = new URL(keycloakAddress);
|
||||
} catch (MalformedURLException e) {
|
||||
logger.errorf("Can't create new keycloak token address: %s", keycloakAddress, e);
|
||||
String keycloakClientSecret;
|
||||
if (keycloakClient != null) {
|
||||
try {
|
||||
logger.debug("Getting configured keycloak endpoint address from client's base URL");
|
||||
newKeycloakEndpoint = new URL(keycloakClient.getBaseUrl());
|
||||
// Only do it if URL has been configured properly
|
||||
logger.debug("Getting configured keycloak client client-secret from client");
|
||||
keycloakClientSecret = keycloakClient.getSecret();
|
||||
} catch (MalformedURLException e) {
|
||||
logger.errorf("Can't create new keycloak token address: %s", keycloakClient.getBaseUrl(), e);
|
||||
oepp = null;
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
logger.debugf("Can't go ahead without a configured '%f' client", KEYCLOAK_CLIENT_ID);
|
||||
oepp = null;
|
||||
return null;
|
||||
}
|
||||
|
||||
if (oepp == null || !newOrchestratorEndpoint.equals(ORCHESTRATOR_ENDPOINT)
|
||||
|| !newKeycloakEndpoint.equals(KEYCLOAK_ENDPOINT)
|
||||
|| !keycloakClientSecret.equals(KEYCLOAK_CLIENT_SECRET)) {
|
||||
|
||||
logger.infof("Creating new orchestrator event publisher provider for endpoint: %s",
|
||||
orchestratorAddress);
|
||||
logger.info("Creating new orchestrator event publisher provider");
|
||||
// Address and other fileds will be then read from static fields in this class by
|
||||
// the createEventSender() called by the superclass' constructor, overridden in the impl.
|
||||
ORCHESTRATOR_ENDPOINT = newOrchestratorEndpoint;
|
||||
|
@ -86,7 +98,7 @@ public class OrchestratorEventPublisherProviderFactory implements EventListenerP
|
|||
}
|
||||
|
||||
} else {
|
||||
logger.debugf("Next check is in %d millis", CHECK_DELAY - elapsed);
|
||||
logger.tracef("Next check is in %d millis", CHECK_DELAY - elapsed);
|
||||
}
|
||||
return oepp;
|
||||
}
|
||||
|
@ -107,6 +119,7 @@ public class OrchestratorEventPublisherProviderFactory implements EventListenerP
|
|||
return null;
|
||||
}
|
||||
}
|
||||
logger.debugf("Client '%f' found", clientId);
|
||||
return client;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue