37f2f2df by Adam Heath

Don't use a singleton instance of keycloak, but create one each time

getInstance() is called.
1 parent 89286c2a
......@@ -32,7 +32,7 @@ class KeycloakToolFactory implements ToolFactory<Keycloak> {
protected final static Logger logger = LoggerFactory.getLogger(KeycloakToolFactory.class)
final static String TOOL_NAME = "Keycloak"
protected Keycloak keycloak = null
protected KeycloakBuilder keycloakBuilder = null
KeycloakToolFactory() { }
......@@ -44,34 +44,33 @@ class KeycloakToolFactory implements ToolFactory<Keycloak> {
@Override
void init(ExecutionContextFactory ecf) {
logger.info("Starting Keycloak")
Keycloak keycloak = getInstance()
try {
ServerInfoRepresentation serverInfo = keycloak.serverInfo().getInfo()
} catch (Exception e) {
logger.error("Could not connect to keycloak server")
throw e
} finally {
keycloak.close()
}
}
@Override
void preFacadeInit(ExecutionContextFactory ecf) {
this.keycloak = KeycloakBuilder.builder()
this.keycloakBuilder = KeycloakBuilder.builder()
.serverUrl((String) System.getProperty("moqui_keycloak_server_url"))
.realm((String) System.getProperty("moqui_keycloak_realm"))
.grantType((String) OAuth2Constants.CLIENT_CREDENTIALS)
.clientId((String) System.getProperty("moqui_keycloak_client_id"))
.clientSecret((String) System.getProperty("moqui_keycloak_client_secret"))
.build()
}
@Override
Keycloak getInstance(Object... parameters) {
return keycloak
return keycloakBuilder.build()
}
@Override
void destroy() {
if (keycloak != null) {
keycloak.close()
}
}
}
......