Skip to content

armgit / core

Public Imported from GitHub
0

100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps

Minor cleanup

Christian Bauera5cd6bbd54e4
diff --git a/container/src/main/java/org/openremote/container/ConfigurationException.java b/container/src/main/java/org/openremote/container/ConfigurationException.java
deleted file mode 100644
index 72f9d6ebd..000000000
--- a/container/src/main/java/org/openremote/container/ConfigurationException.java
+++ /dev/null
@@ -1,23 +0,0 @@
-package org.openremote.container;
-
-public class ConfigurationException extends RuntimeException {
-
- public ConfigurationException() {
- }
-
- public ConfigurationException(String message) {
- super(message);
- }
-
- public ConfigurationException(String message, Throwable cause) {
- super(message, cause);
- }
-
- public ConfigurationException(Throwable cause) {
- super(cause);
- }
-
- public ConfigurationException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
- super(message, cause, enableSuppression, writableStackTrace);
- }
-}
diff --git a/container/src/main/java/org/openremote/container/Container.java b/container/src/main/java/org/openremote/container/Container.java
index 3c89fede0..a62b66288 100644
--- a/container/src/main/java/org/openremote/container/Container.java
+++ b/container/src/main/java/org/openremote/container/Container.java
@@ -104,10 +104,6 @@ public class Container {
Runtime.getRuntime().addShutdownHook(new Thread(this::stop));
}
- public ObjectNode getConfig() {
- return config;
- }
-
public String getConfig(String variable, String defaultValue) {
return config.has(variable) ? config.get(variable).asText() : defaultValue;
}
@@ -126,6 +122,7 @@ public class Container {
synchronized public CompletableFuture start() {
return CompletableFuture.runAsync(() -> {
+ LOG.info(">>> Starting runtime container...");
for (ContainerService service : getServices()) {
LOG.fine("Preparing service: " + service);
service.prepare(Container.this);
@@ -134,15 +131,24 @@ public class Container {
LOG.fine("Starting service: " + service);
service.start(Container.this);
}
+ LOG.info(">>> Runtime container startup complete");
});
}
+ synchronized public void stop() {
+ LOG.info("<<< Stopping runtime container...");
+ for (ContainerService service : getServices()) {
+ LOG.fine("Stopping service: " + service);
+ service.stop(this);
+ }
+ LOG.info("<<< Runtime container stopped");
+ }
+
/**
* Starts the container and a non-daemon thread that waits forever.
*/
public void startBackground() throws Exception{
// We block here so we die fast if startup fails
- LOG.info(">>> Starting runtime container...");
start().get();
Thread containerThread = new Thread("container") {
@Override
@@ -156,16 +162,6 @@ public class Container {
};
containerThread.setDaemon(false);
containerThread.start();
- LOG.info(">>> Runtime container startup complete");
- }
-
- synchronized public void stop() {
- LOG.info("<<< Stopping runtime container...");
- for (ContainerService service : getServices()) {
- LOG.fine("Stopping service: " + service);
- service.stop(this);
- }
- LOG.info("<<< Runtime container stopped");
}
synchronized public void addService(ContainerService service) {
diff --git a/container/src/main/java/org/openremote/container/security/SecuredClientApplication.java b/container/src/main/java/org/openremote/container/security/ClientRealm.java
similarity index 87%
rename from container/src/main/java/org/openremote/container/security/SecuredClientApplication.java
rename to container/src/main/java/org/openremote/container/security/ClientRealm.java
index 9114ced9e..d1b47b15b 100644
--- a/container/src/main/java/org/openremote/container/security/SecuredClientApplication.java
+++ b/container/src/main/java/org/openremote/container/security/ClientRealm.java
@@ -2,7 +2,7 @@ package org.openremote.container.security;
import org.keycloak.adapters.KeycloakDeployment;
-public class SecuredClientApplication {
+public class ClientRealm {
public static class Key {
public final String realm;
@@ -36,7 +36,7 @@ public class SecuredClientApplication {
final public ClientInstall clientInstall;
final public KeycloakDeployment keycloakDeployment;
- public SecuredClientApplication(ClientInstall clientInstall, KeycloakDeployment keycloakDeployment) {
+ public ClientRealm(ClientInstall clientInstall, KeycloakDeployment keycloakDeployment) {
this.clientInstall = clientInstall;
this.keycloakDeployment = keycloakDeployment;
}
diff --git a/container/src/main/java/org/openremote/container/security/IdentityResource.java b/container/src/main/java/org/openremote/container/security/IdentityResource.java
index b17c37456..8161b3a91 100644
--- a/container/src/main/java/org/openremote/container/security/IdentityResource.java
+++ b/container/src/main/java/org/openremote/container/security/IdentityResource.java
@@ -19,8 +19,8 @@ public class IdentityResource extends WebResource {
@Path("install/{clientId}")
@Produces(MediaType.APPLICATION_JSON)
public ClientInstall getClientInstall(@PathParam("clientId") String clientId) {
- SecuredClientApplication clientApplication =
- identityService.getSecuredClientApplication(getRealm(), clientId);
+ ClientRealm clientApplication =
+ identityService.getClientRealm(getRealm(), clientId);
if (clientApplication == null)
throw new WebApplicationException(Response.Status.NOT_FOUND);
return clientApplication.clientInstall;
diff --git a/container/src/main/java/org/openremote/container/security/IdentityService.java b/container/src/main/java/org/openremote/container/security/IdentityService.java
index 75f550e00..e19778e88 100644
--- a/container/src/main/java/org/openremote/container/security/IdentityService.java
+++ b/container/src/main/java/org/openremote/container/security/IdentityService.java
@@ -63,7 +63,7 @@ public abstract class IdentityService implements ContainerService {
protected UriBuilder keycloakHostUri;
protected UriBuilder keycloakServiceUri;
protected Client client;
- protected LoadingCache<SecuredClientApplication.Key, SecuredClientApplication> clientApplicationCache;
+ protected LoadingCache<ClientRealm.Key, ClientRealm> clientApplicationCache;
@Override
public void prepare(Container container) {
@@ -132,7 +132,7 @@ public abstract class IdentityService implements ContainerService {
String realm = request.getQueryParamValue("realm");
if (realm == null || realm.length() == 0)
return passthroughKeycloakDeployment;
- SecuredClientApplication clientApplication = getSecuredClientApplication(realm, getClientId());
+ ClientRealm clientApplication = getClientRealm(realm, getClientId());
if (clientApplication == null)
return passthroughKeycloakDeployment;
return clientApplication.keycloakDeployment;
@@ -204,16 +204,16 @@ public abstract class IdentityService implements ContainerService {
).toBlocking().singleOrDefault(false);
}
- public SecuredClientApplication getSecuredClientApplication(String realm, String clientId) {
+ public ClientRealm getClientRealm(String realm, String clientId) {
try {
- return clientApplicationCache.get(new SecuredClientApplication.Key(realm, clientId));
+ return clientApplicationCache.get(new ClientRealm.Key(realm, clientId));
} catch (Exception ex) {
if (ex.getCause() != null && ex.getCause() instanceof NotFoundException) {
- LOG.fine("Client application '" + clientId + "' for realm '" + realm + "' not found on identity provider");
+ LOG.fine("Client '" + clientId + "' for realm '" + realm + "' not found on identity provider");
} else {
LOG.log(
Level.INFO,
- "Error loading client application '" + clientId + "' for realm '" + realm + "' from identity provider",
+ "Error loading client '" + clientId + "' for realm '" + realm + "' from identity provider",
ex
);
}
@@ -221,15 +221,16 @@ public abstract class IdentityService implements ContainerService {
}
}
- protected LoadingCache<SecuredClientApplication.Key, SecuredClientApplication> createClientApplicationCache() {
- CacheLoader<SecuredClientApplication.Key, SecuredClientApplication> loader =
- new CacheLoader<SecuredClientApplication.Key, SecuredClientApplication>() {
- public SecuredClientApplication load(SecuredClientApplication.Key key) {
- LOG.fine("Loading client '" + key.clientId + "' install details for realm '" + key.realm + "'");
+ protected LoadingCache<ClientRealm.Key, ClientRealm> createClientApplicationCache() {
+ CacheLoader<ClientRealm.Key, ClientRealm> loader =
+ new CacheLoader<ClientRealm.Key, ClientRealm>() {
+ public ClientRealm load(ClientRealm.Key key) {
+ LOG.fine("Loading client '" + key.clientId + "' for realm '" + key.realm + "'");
+ // The client install contains the details we need to verify access tokens
ClientInstall clientInstall = getKeycloak().getClientInstall(key.realm, key.clientId);
- // Make the public key usable
+ // Make the public key usable for token verification
try {
clientInstall.setPublicKey(PemUtils.decodePublicKey(clientInstall.getPublicKeyPEM()));
} catch (Exception ex) {
@@ -247,7 +248,9 @@ public abstract class IdentityService implements ContainerService {
.build().toString()
);
- // Some more bloated infrastructure needed to configure stuff
+ // Some more bloated infrastructure needed, this is for the Keycloak container adapter which
+ // does the automatic token verification. As you can see, it's duplicating ClientInstall.
+ // TODO: Some of the options should be configurable, e.g. CORS and NotBefore
KeycloakDeployment keycloakDeployment = new KeycloakDeployment();
keycloakDeployment.setRealm(clientInstall.getRealm());
@@ -262,7 +265,7 @@ public abstract class IdentityService implements ContainerService {
adapterConfig.setAuthServerUrlForBackendRequests(clientInstall.getAuthServerUrlForBackendRequests());
keycloakDeployment.setAuthServerBaseUrl(adapterConfig);
- return new SecuredClientApplication(
+ return new ClientRealm(
clientInstall, keycloakDeployment
);
}