Skip to content

armgit / core

Public Imported from GitHub
0

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

Keycloak bug fixes and rolled back UniqueIdentifierGenerator MAC based changes

Rich Turner9c63b00cc3c5
diff --git a/client/build.gradle b/client/build.gradle
index 845c35eb6..459b76c73 100644
--- a/client/build.gradle
+++ b/client/build.gradle
@@ -113,7 +113,7 @@ task gwtSuperDev(dependsOn: classes, type: JavaExec) {
sourceSets.main.output.classesDirs,
sourceSets.main.compileClasspath]
}
- maxHeapSize = "1024M"
+ maxHeapSize = "1536M"
/*
-[no]allowMissingSrc Allows -src flags to reference missing directories. (defaults to OFF)
-bindAddress The ip address of the code server. Defaults to 127.0.0.1.
@@ -178,4 +178,4 @@ distributions {
}
}
}
-}
\ No newline at end of file
+}
diff --git a/container/src/main/java/org/openremote/container/security/keycloak/KeycloakIdentityProvider.java b/container/src/main/java/org/openremote/container/security/keycloak/KeycloakIdentityProvider.java
index 1d902dda6..c4c9742db 100644
--- a/container/src/main/java/org/openremote/container/security/keycloak/KeycloakIdentityProvider.java
+++ b/container/src/main/java/org/openremote/container/security/keycloak/KeycloakIdentityProvider.java
@@ -376,12 +376,14 @@ public abstract class KeycloakIdentityProvider implements IdentityProvider {
public KeycloakDeployment load(KeycloakRealmClient keycloakRealmClient) {
LOG.fine("Loading adapter config for client '" + keycloakRealmClient.clientId + "' in realm '" + keycloakRealmClient.realm + "'");
- AdapterConfig adapterConfig = getKeycloak().getAdapterConfig(
+ KeycloakResource keycloak = getTarget(httpClient, keycloakServiceUri.build(), null, null, null).proxy(KeycloakResource.class);
+
+ AdapterConfig adapterConfig = keycloak.getAdapterConfig(
keycloakRealmClient.realm, keycloakRealmClient.clientId
);
// Get the public key for token verification
- PublishedRealmRepresentation realmRepresentation = getKeycloak().getPublishedRealm(keycloakRealmClient.realm);
+ PublishedRealmRepresentation realmRepresentation = keycloak.getPublishedRealm(keycloakRealmClient.realm);
adapterConfig.setRealmKey(realmRepresentation.getPublicKeyPem());
// Must rewrite the auth-server URL to our external host and port, which
diff --git a/container/src/main/java/org/openremote/container/util/UniqueIdentifierGenerator.java b/container/src/main/java/org/openremote/container/util/UniqueIdentifierGenerator.java
index 6ca72bb3e..2164ba643 100644
--- a/container/src/main/java/org/openremote/container/util/UniqueIdentifierGenerator.java
+++ b/container/src/main/java/org/openremote/container/util/UniqueIdentifierGenerator.java
@@ -23,17 +23,12 @@ import com.devskiller.friendly_id.Url62;
import com.fasterxml.uuid.Generators;
import com.fasterxml.uuid.impl.NameBasedGenerator;
import com.fasterxml.uuid.impl.RandomBasedGenerator;
-import org.apache.james.mime4j.util.CharsetUtil;
import org.hibernate.HibernateException;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.id.IdentifierGenerator;
import org.openremote.model.IdentifiableEntity;
import java.io.Serializable;
-import java.net.InetAddress;
-import java.net.NetworkInterface;
-import java.nio.charset.Charset;
-import java.util.UUID;
/**
* Generate a globally unique identifier value.
@@ -43,9 +38,8 @@ import java.util.UUID;
*/
public class UniqueIdentifierGenerator implements IdentifierGenerator {
- static final protected String macAddress = generateMacAddressString();
static final protected RandomBasedGenerator randomGenerator = Generators.randomBasedGenerator();
- static final protected NameBasedGenerator nameGenerator = Generators.nameBasedGenerator(UUID.nameUUIDFromBytes(macAddress.getBytes(CharsetUtil.UTF_8)));
+ static final protected NameBasedGenerator nameGenerator = Generators.nameBasedGenerator();
@Override
public Serializable generate(SharedSessionContractImplementor session, Object object) throws HibernateException {
@@ -65,8 +59,7 @@ public class UniqueIdentifierGenerator implements IdentifierGenerator {
}
/**
- * Generates the same UUID for the current system value encoded as Base62, 22 characters long, if the name is the same.
- * The UUID is namespaced with the MAC address of the host to provide a level of variability for multiple deployments.
+ * Generates the same UUID value encoded as Base62, 22 characters long, if the name is the same.
*/
public static String generateId(String name) {
return Url62.encode(nameGenerator.generate(name));
@@ -78,24 +71,4 @@ public class UniqueIdentifierGenerator implements IdentifierGenerator {
public static String generateId(byte[] bytes) {
return Url62.encode(nameGenerator.generate(bytes));
}
-
- public static String getMacAddress() {
- return macAddress;
- }
-
- protected static String generateMacAddressString() {
- try {
- final InetAddress ip = InetAddress.getLocalHost();
- final NetworkInterface network = NetworkInterface.getByInetAddress(ip);
-
- byte[] macAddress = network.getHardwareAddress();
- StringBuilder sb = new StringBuilder();
- for (byte address : macAddress) {
- sb.append(String.format("%02X", (address & 0xFF)));
- }
- return sb.toString();
- } catch (Exception e) {
- return "000000000000";
- }
- }
}
diff --git a/manager/src/main/java/org/openremote/manager/security/ManagerKeycloakIdentityProvider.java b/manager/src/main/java/org/openremote/manager/security/ManagerKeycloakIdentityProvider.java
index 27b215f1c..7ee8673e3 100644
--- a/manager/src/main/java/org/openremote/manager/security/ManagerKeycloakIdentityProvider.java
+++ b/manager/src/main/java/org/openremote/manager/security/ManagerKeycloakIdentityProvider.java
@@ -334,8 +334,12 @@ public class ManagerKeycloakIdentityProvider extends KeycloakIdentityProvider im
RealmsResource realmsResource = getRealms();
RealmRepresentation realmRepresentation = convert(Container.JSON, RealmRepresentation.class, tenant);
realmsResource.create(realmRepresentation);
- realmRepresentation = realmsResource.realm(tenant.getRealm()).toRepresentation();
+ RealmResource realmResource = realmsResource.realm(tenant.getRealm());
+
+ realmRepresentation = realmResource.toRepresentation();
+ // Need a committed realmRepresentation to update the security
configureRealm(realmRepresentation);
+ realmResource.update(realmRepresentation);
createOpenRemoteClientApplication(realmRepresentation.getRealm());
publishModification(PersistenceEvent.Cause.CREATE, tenant);
return convert(Container.JSON, Tenant.class, realmRepresentation);
diff --git a/manager/src/main/java/org/openremote/manager/setup/AbstractKeycloakSetup.java b/manager/src/main/java/org/openremote/manager/setup/AbstractKeycloakSetup.java
index 6e9251a40..89c665aa6 100644
--- a/manager/src/main/java/org/openremote/manager/setup/AbstractKeycloakSetup.java
+++ b/manager/src/main/java/org/openremote/manager/setup/AbstractKeycloakSetup.java
@@ -69,6 +69,10 @@ public abstract class AbstractKeycloakSetup implements Setup {
return tenant;
}
+ protected Tenant createTenant(Tenant tenant) {
+ return keycloakProvider.createTenant(tenant);
+ }
+
protected User createUser(String realm, String username, String password, String firstName, String lastName, String email, boolean enabled, ClientRole[] roles) {
User user = new User();
user.setUsername(username);
diff --git a/manager/src/main/java/org/openremote/manager/setup/builtin/KeycloakDemoSetup.java b/manager/src/main/java/org/openremote/manager/setup/builtin/KeycloakDemoSetup.java
index 37cb44dd7..bcceb70ca 100644
--- a/manager/src/main/java/org/openremote/manager/setup/builtin/KeycloakDemoSetup.java
+++ b/manager/src/main/java/org/openremote/manager/setup/builtin/KeycloakDemoSetup.java
@@ -69,7 +69,7 @@ public class KeycloakDemoSetup extends AbstractKeycloakSetup {
// Tenants
masterTenant = identityService.getIdentityProvider().getTenant(Constants.MASTER_REALM);
tenantBuilding = createTenant("building", "Building");
- tenantCity = createTenant("smaercity", "Smart City");
+ tenantCity = createTenant("smartcity", "Smart City");
// Users
User testuser1 = createUser(MASTER_REALM, "testuser1", "testuser1", "DemoMaster", "DemoLast", null, true, REGULAR_USER_ROLES);