Skip to content

armgit / core

Public Imported from GitHub
0

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

BIG CHANGE: Completely removed use of realm ID (replaced with realm name) includes auto migration script

Rich Turner74b6858f9edf
diff --git a/agent/src/main/java/org/openremote/agent/protocol/http/AbstractHttpServerProtocol.java b/agent/src/main/java/org/openremote/agent/protocol/http/AbstractHttpServerProtocol.java
index cbe32bed2..7c7855153 100644
--- a/agent/src/main/java/org/openremote/agent/protocol/http/AbstractHttpServerProtocol.java
+++ b/agent/src/main/java/org/openremote/agent/protocol/http/AbstractHttpServerProtocol.java
@@ -344,7 +344,7 @@ public abstract class AbstractHttpServerProtocol extends AbstractProtocol {
// Get realm from owning agent asset
Asset agent = assetService.getAgent(protocolConfiguration);
- String agentRealm = agent.getTenantRealm();
+ String agentRealm = agent.getRealm();
if (TextUtil.isNullOrEmpty(agentRealm)) {
throw new IllegalStateException("Cannot determine the realm that this protocol configuration belongs to");
diff --git a/client/src/main/java/org/openremote/app/client/admin/tenant/AdminTenantPlace.java b/client/src/main/java/org/openremote/app/client/admin/tenant/AdminTenantPlace.java
index 538b3987a..f79d477f0 100644
--- a/client/src/main/java/org/openremote/app/client/admin/tenant/AdminTenantPlace.java
+++ b/client/src/main/java/org/openremote/app/client/admin/tenant/AdminTenantPlace.java
@@ -56,7 +56,7 @@ public class AdminTenantPlace extends AdminPlace {
@Override
public String toString() {
return getClass().getSimpleName() + "{" +
- "realmId='" + realm + '\'' +
+ "realm='" + realm + '\'' +
"}";
}
}
diff --git a/client/src/main/java/org/openremote/app/client/admin/users/AbstractAdminUsersPlace.java b/client/src/main/java/org/openremote/app/client/admin/users/AbstractAdminUsersPlace.java
index 31f0f796c..4ef9036bb 100644
--- a/client/src/main/java/org/openremote/app/client/admin/users/AbstractAdminUsersPlace.java
+++ b/client/src/main/java/org/openremote/app/client/admin/users/AbstractAdminUsersPlace.java
@@ -51,7 +51,7 @@ public abstract class AbstractAdminUsersPlace extends AdminPlace {
@Override
public String toString() {
return getClass().getSimpleName() + "{" +
- "realmId='" + realm + '\'' +
+ "realm='" + realm + '\'' +
", userId='" + userId + '\'' +
"}";
}
diff --git a/client/src/main/java/org/openremote/app/client/app/HeaderPresenter.java b/client/src/main/java/org/openremote/app/client/app/HeaderPresenter.java
index 966cd689c..fcb59a800 100644
--- a/client/src/main/java/org/openremote/app/client/app/HeaderPresenter.java
+++ b/client/src/main/java/org/openremote/app/client/app/HeaderPresenter.java
@@ -138,10 +138,10 @@ public class HeaderPresenter implements HeaderView.Presenter {
return;
}
if (assetBrowserSelection.getSelectedNode() instanceof TenantTreeNode) {
- placeController.goTo(new NotificationsPlace(((TenantTreeNode) assetBrowserSelection.getSelectedNode()).getTenant().getRealm(), null));
+ placeController.goTo(new NotificationsPlace(assetBrowserSelection.getSelectedNode().getId(), null));
} else if (assetBrowserSelection.getSelectedNode() instanceof AssetTreeNode) {
placeController.goTo(
- new NotificationsPlace(((AssetTreeNode) assetBrowserSelection.getSelectedNode()).getAsset().getTenantRealm(),
+ new NotificationsPlace(((AssetTreeNode) assetBrowserSelection.getSelectedNode()).getAsset().getRealm(),
assetBrowserSelection.getSelectedNode().getId()));
} else {
placeController.goTo(new NotificationsPlace());
diff --git a/client/src/main/java/org/openremote/app/client/apps/ConsoleAppsPlace.java b/client/src/main/java/org/openremote/app/client/apps/ConsoleAppsPlace.java
index c5747f160..cf3886a40 100644
--- a/client/src/main/java/org/openremote/app/client/apps/ConsoleAppsPlace.java
+++ b/client/src/main/java/org/openremote/app/client/apps/ConsoleAppsPlace.java
@@ -56,7 +56,7 @@ public class ConsoleAppsPlace extends Place {
@Override
public String toString() {
return getClass().getSimpleName() + "{" +
- "realmId='" + realm + '\'' +
+ "realm='" + realm + '\'' +
'}';
}
}
diff --git a/client/src/main/java/org/openremote/app/client/assets/asset/AbstractAssetActivity.java b/client/src/main/java/org/openremote/app/client/assets/asset/AbstractAssetActivity.java
index e00060362..7ee8120a3 100644
--- a/client/src/main/java/org/openremote/app/client/assets/asset/AbstractAssetActivity.java
+++ b/client/src/main/java/org/openremote/app/client/assets/asset/AbstractAssetActivity.java
@@ -194,7 +194,7 @@ public abstract class AbstractAssetActivity<V
} else {
view.setParentNode(
new TenantTreeNode(
- new Tenant(asset.getRealmId(), asset.getTenantRealm(), asset.getTenantDisplayName(), true)
+ new Tenant(asset.getRealm(), asset.getRealm(), asset.getRealm(), true)
)
);
}
diff --git a/client/src/main/java/org/openremote/app/client/assets/asset/AssetEditActivity.java b/client/src/main/java/org/openremote/app/client/assets/asset/AssetEditActivity.java
index 9865710fc..dcd3f0ac6 100644
--- a/client/src/main/java/org/openremote/app/client/assets/asset/AssetEditActivity.java
+++ b/client/src/main/java/org/openremote/app/client/assets/asset/AssetEditActivity.java
@@ -151,8 +151,7 @@ public class AssetEditActivity
assetBrowserPresenter.clearSelection();
asset = new Asset();
asset.setName("My New Asset");
- asset.setRealmId(environment.getApp().getTenant().getId());
- asset.setTenantDisplayName(environment.getApp().getTenant().getDisplayName());
+ asset.setRealm(environment.getApp().getTenant().getId());
asset.setType(AssetType.THING);
}
@@ -169,8 +168,7 @@ public class AssetEditActivity
@Override
public void onParentSelection(BrowserTreeNode treeNode) {
if (treeNode instanceof TenantTreeNode) {
- asset.setRealmId(treeNode.getId());
- asset.setTenantDisplayName(treeNode.getLabel());
+ asset.setRealm(treeNode.getId());
parentAsset = null;
} else if (treeNode instanceof AssetTreeNode) {
assetBrowserPresenter.loadAsset(treeNode.getId(), loadedAsset -> {
@@ -359,8 +357,8 @@ public class AssetEditActivity
// Retrieve agents in the same realm as the asset (if it has been assigned a realm otherwise
// the query will be automatically restricted to the logged in users realm)
- if (!isNullOrEmpty(asset.getRealmId())) {
- query.tenant(new TenantPredicate(asset.getRealmId()));
+ if (!isNullOrEmpty(asset.getRealm())) {
+ query.tenant(new TenantPredicate(asset.getRealm()));
}
// Agents must have protocol configurations
@@ -374,8 +372,8 @@ public class AssetEditActivity
// Limit to assets that have the same realm as the asset being edited (if it has been assigned a realm
// otherwise the query will be automatically restricted to the logged in users realm)
- if (!isNullOrEmpty(asset.getRealmId())) {
- query.tenant(new TenantPredicate(asset.getRealmId()));
+ if (!isNullOrEmpty(asset.getRealm())) {
+ query.tenant(new TenantPredicate(asset.getRealm()));
}
}
@@ -652,8 +650,7 @@ public class AssetEditActivity
protected void readFromView() {
asset.setName(view.getName());
if (parentAsset != null) {
- asset.setRealmId(parentAsset.getRealmId());
- asset.setTenantDisplayName(parentAsset.getTenantDisplayName());
+ asset.setRealm(parentAsset.getRealm());
asset.setParentId(parentAsset.getId());
} else {
asset.setParentId(null);
@@ -688,7 +685,7 @@ public class AssetEditActivity
requestParams, assetId,
request.getProtocolConfigurationName(),
request.getParentId(),
- request.getRealmId(),
+ request.getRealm(),
request.getFileInfo()
);
} else {
@@ -696,7 +693,7 @@ public class AssetEditActivity
requestParams, assetId,
request.getProtocolConfigurationName(),
request.getParentId(),
- request.getRealmId()
+ request.getRealm()
);
}
},
diff --git a/client/src/main/java/org/openremote/app/client/assets/asset/AssetViewActivity.java b/client/src/main/java/org/openremote/app/client/assets/asset/AssetViewActivity.java
index b90e4c0b8..ced40cd36 100644
--- a/client/src/main/java/org/openremote/app/client/assets/asset/AssetViewActivity.java
+++ b/client/src/main/java/org/openremote/app/client/assets/asset/AssetViewActivity.java
@@ -20,7 +20,6 @@
package org.openremote.app.client.assets.asset;
import com.google.gwt.http.client.URL;
-import org.openremote.app.client.AppSecurity;
import org.openremote.app.client.Environment;
import org.openremote.app.client.assets.AgentStatusEventMapper;
import org.openremote.app.client.assets.AssetMapper;
@@ -202,7 +201,7 @@ public class AssetViewActivity
protected void subscribeAgentStatus(boolean subscribe) {
if (subscribe) {
- environment.getEventService().subscribe(AgentStatusEvent.class, new TenantFilter<>(asset.getRealmId()));
+ environment.getEventService().subscribe(AgentStatusEvent.class, new TenantFilter<>(asset.getRealm()));
} else {
environment.getEventService().unsubscribe(AgentStatusEvent.class);
}
@@ -278,7 +277,7 @@ public class AssetViewActivity
.put("id", Values.create(asset.getId()))
.toJson();
view.setAccessPublicReadAnchor(
- "/" + asset.getTenantRealm() + "/asset/public/query?q=" + URL.encodeQueryString(query)
+ "/" + asset.getRealm() + "/asset/public/query?q=" + URL.encodeQueryString(query)
);
}
diff --git a/client/src/main/java/org/openremote/app/client/assets/attributes/ProtocolDiscoveryView.java b/client/src/main/java/org/openremote/app/client/assets/attributes/ProtocolDiscoveryView.java
index 92f5d640d..7aa149084 100644
--- a/client/src/main/java/org/openremote/app/client/assets/attributes/ProtocolDiscoveryView.java
+++ b/client/src/main/java/org/openremote/app/client/assets/attributes/ProtocolDiscoveryView.java
@@ -42,13 +42,13 @@ public class ProtocolDiscoveryView extends AbstractAttributeViewExtension {
public static class DiscoveryRequest {
protected final String protocolConfigurationName;
protected final String parentId;
- protected final String realmId;
+ protected final String realm;
protected final FileInfo fileInfo;
- public DiscoveryRequest(String protocolConfigurationName, String parentId, String realmId, FileInfo fileInfo) {
+ public DiscoveryRequest(String protocolConfigurationName, String parentId, String realm, FileInfo fileInfo) {
this.protocolConfigurationName = protocolConfigurationName;
this.parentId = parentId;
- this.realmId = realmId;
+ this.realm = realm;
this.fileInfo = fileInfo;
}
@@ -60,8 +60,8 @@ public class ProtocolDiscoveryView extends AbstractAttributeViewExtension {
return parentId;
}
- public String getRealmId() {
- return realmId;
+ public String getRealm() {
+ return realm;
}
public FileInfo getFileInfo() {
@@ -72,7 +72,7 @@ public class ProtocolDiscoveryView extends AbstractAttributeViewExtension {
protected final ProtocolDescriptor protocolDescriptor;
protected final AssetSelector assetSelector;
protected final BiConsumer<DiscoveryRequest, Runnable> discoveryRequestConsumer;
- protected String importRealmId;
+ protected String importRealm;
protected String importParentId;
protected FileUploadLabelled fileUpload;
@@ -97,11 +97,11 @@ public class ProtocolDiscoveryView extends AbstractAttributeViewExtension {
true,
treeNode -> {
importParentId = null;
- importRealmId = null;
+ importRealm = null;
if (treeNode instanceof TenantTreeNode) {
TenantTreeNode tenantTreeNode = (TenantTreeNode)treeNode;
- importRealmId = tenantTreeNode.getId();
+ importRealm = tenantTreeNode.getId();
} else if (treeNode instanceof AssetTreeNode) {
AssetTreeNode assetTreeNode = (AssetTreeNode)treeNode;
importParentId = assetTreeNode.getId();
@@ -176,7 +176,7 @@ public class ProtocolDiscoveryView extends AbstractAttributeViewExtension {
fileUpload.setText(environment.getMessages().importInProgress());
FileInfo fileInfo = new FileInfo(name, data, binary);
- DiscoveryRequest discoveryRequest = new DiscoveryRequest(attribute.getName().orElse(""), importParentId, importRealmId, fileInfo);
+ DiscoveryRequest discoveryRequest = new DiscoveryRequest(attribute.getName().orElse(""), importParentId, importRealm, fileInfo);
if (discoveryRequestConsumer != null) {
discoveryRequestConsumer.accept(discoveryRequest, () -> {
fileUpload.setText(environment.getMessages().uploadProtocolFile());
diff --git a/client/src/main/java/org/openremote/app/client/assets/browser/AssetBrowser.java b/client/src/main/java/org/openremote/app/client/assets/browser/AssetBrowser.java
index 75b0e525c..57ba7f197 100644
--- a/client/src/main/java/org/openremote/app/client/assets/browser/AssetBrowser.java
+++ b/client/src/main/java/org/openremote/app/client/assets/browser/AssetBrowser.java
@@ -28,8 +28,8 @@ import org.openremote.model.interop.Consumer;
* Browse tenants and assets in a tree view.
*
* Listen to {@link AssetBrowserSelection} events to be notified of user selections. Call
- * the methods {@link Presenter#selectAsset(Asset)}, {@link Presenter#selectTenant)}
- * and {@link Presenter#clearSelection} to modify the browser's current selected node.
+ * the methods {@link Presenter#selectAsset(Asset)} and {@link Presenter#clearSelection}
+ * to modify the browser's current selected node.
*/
public interface AssetBrowser extends IsWidget {
@@ -51,8 +51,6 @@ public interface AssetBrowser extends IsWidget {
void selectAssetById(String assetId);
- void selectTenant(String realmId);
-
void selectRealm(String realm);
void clearSelection();
diff --git a/client/src/main/java/org/openremote/app/client/assets/browser/AssetBrowserPresenter.java b/client/src/main/java/org/openremote/app/client/assets/browser/AssetBrowserPresenter.java
index 57e725c9b..8da45aa13 100644
--- a/client/src/main/java/org/openremote/app/client/assets/browser/AssetBrowserPresenter.java
+++ b/client/src/main/java/org/openremote/app/client/assets/browser/AssetBrowserPresenter.java
@@ -87,7 +87,7 @@ public class AssetBrowserPresenter implements AssetBrowser.Presenter {
environment.getEventBus().register(
AssetTreeModifiedEvent.class,
event -> {
- String modifiedNodeId = event.isTenantModified() ? event.getRealmId() : event.getAssetId();
+ String modifiedNodeId = event.isTenantModified() ? event.getRealm() : event.getAssetId();
if (event.isNewAssetChildren()) {
LOG.fine("Asset tree modified on server, forcing open due to new child asset: " + modifiedNodeId);
view.refresh(event.getAssetId(), modifiedNodeId);
@@ -106,7 +106,7 @@ public class AssetBrowserPresenter implements AssetBrowser.Presenter {
AssetTreeModifiedEvent.class,
environment.getApp().getSecurity().isSuperUser()
? null
- : new TenantFilter(currentTenant.getId())
+ : new TenantFilter(currentTenant.getRealm())
);
}
@@ -186,24 +186,18 @@ public class AssetBrowserPresenter implements AssetBrowser.Presenter {
@Override
public void selectRealm(String realm) {
- selectTenant(realm, false);
- }
-
- @Override
- public void selectTenant(String realmId) {
- selectTenant(realmId, true);
- }
-
- protected void selectTenant(String value, boolean compareId) {
TenantTreeNode selectedTenantNode = null;
- if (!TextUtil.isNullOrEmpty(value)) {
+
+ if (!TextUtil.isNullOrEmpty(realm)) {
for (TenantTreeNode tenantNode : tenantNodes) {
- String matchValue = compareId ? tenantNode.getId() : tenantNode.getTenant().getRealm();
- if (matchValue.equals(value))
+ if (tenantNode.getId().equals(realm)) {
selectedTenantNode = tenantNode;
+ break;
+ }
}
}
+
if (selectedTenantNode != null) {
onNodeSelected(selectedTenantNode);
selectedNodePath = new String[]{selectedTenantNode.getId()};
@@ -313,7 +307,7 @@ public class AssetBrowserPresenter implements AssetBrowser.Presenter {
List<String> path = new ArrayList<>();
if (environment.getApp().getSecurity().isSuperUser()) {
for (TenantTreeNode tenantNode : tenantNodes) {
- if (tenantNode.getId().equals(asset.getRealmId())) {
+ if (tenantNode.getId().equals(asset.getRealm())) {
path.add(tenantNode.getId());
break;
}
diff --git a/client/src/main/java/org/openremote/app/client/assets/browser/AssetSelector.java b/client/src/main/java/org/openremote/app/client/assets/browser/AssetSelector.java
index f4ecc1096..d586b9c80 100644
--- a/client/src/main/java/org/openremote/app/client/assets/browser/AssetSelector.java
+++ b/client/src/main/java/org/openremote/app/client/assets/browser/AssetSelector.java
@@ -137,7 +137,7 @@ public class AssetSelector extends FormGroup {
assetBrowserPresenter.useSelector(null);
if (originalNode != null) {
if (originalNode instanceof TenantTreeNode) {
- assetBrowserPresenter.selectTenant(originalNode.getId());
+ assetBrowserPresenter.selectRealm(originalNode.getId());
} else if (originalNode instanceof AssetTreeNode) {
assetBrowserPresenter.selectAssetById(originalNode.getId());
}
@@ -170,7 +170,7 @@ public class AssetSelector extends FormGroup {
} else if (treeNode instanceof AssetTreeNode) {
AssetTreeNode assetTreeNode = (AssetTreeNode) treeNode;
outputTenantDisplayName.setVisible(true);
- outputTenantDisplayName.setText(assetTreeNode.getAsset().getTenantDisplayName());
+ outputTenantDisplayName.setText(assetTreeNode.getAsset().getRealm());
outputAssetName.setVisible(true);
outputAssetName.setText(treeNode.getLabel());
}
diff --git a/client/src/main/java/org/openremote/app/client/assets/browser/TenantTreeNode.java b/client/src/main/java/org/openremote/app/client/assets/browser/TenantTreeNode.java
index 17c825b12..4989db708 100644
--- a/client/src/main/java/org/openremote/app/client/assets/browser/TenantTreeNode.java
+++ b/client/src/main/java/org/openremote/app/client/assets/browser/TenantTreeNode.java
@@ -36,7 +36,7 @@ public class TenantTreeNode extends BrowserTreeNode {
@Override
public String getId() {
- return tenant.getId();
+ return tenant.getRealm();
}
@Override
diff --git a/client/src/main/java/org/openremote/app/client/assets/tenant/AssetsTenantActivity.java b/client/src/main/java/org/openremote/app/client/assets/tenant/AssetsTenantActivity.java
index 17f6fc3a1..3fda3497c 100644
--- a/client/src/main/java/org/openremote/app/client/assets/tenant/AssetsTenantActivity.java
+++ b/client/src/main/java/org/openremote/app/client/assets/tenant/AssetsTenantActivity.java
@@ -54,7 +54,7 @@ public class AssetsTenantActivity extends AssetBrowsingActivity<AssetsTenantPlac
UserResource userResource;
final protected UserArrayMapper userArrayMapper;
- protected String realmId;
+ protected String realm;
protected Tenant tenant;
protected User[] users;
@@ -85,7 +85,7 @@ public class AssetsTenantActivity extends AssetBrowsingActivity<AssetsTenantPlac
@Override
protected AppActivity<AssetsTenantPlace> init(AssetsTenantPlace place) {
- this.realmId = place.getRealmId();
+ this.realm = place.getRealm();
return this;
}
@@ -96,7 +96,7 @@ public class AssetsTenantActivity extends AssetBrowsingActivity<AssetsTenantPlac
registrations.add(eventBus.register(AssetBrowserSelection.class, event -> {
if (event.getSelectedNode() instanceof TenantTreeNode) {
- if (this.realmId == null || !this.realmId.equals(event.getSelectedNode().getId())) {
+ if (this.realm == null || !this.realm.equals(event.getSelectedNode().getId())) {
environment.getPlaceController().goTo(
new AssetsTenantPlace(event.getSelectedNode().getId())
);
@@ -136,7 +136,7 @@ public class AssetsTenantActivity extends AssetBrowsingActivity<AssetsTenantPlac
view.setCreateAssetLinkEnabled(false);
} else {
AssetTreeNode assetTreeNode = (AssetTreeNode) treeNode;
- if (!assetTreeNode.getAsset().getRealmId().equals(this.realmId)) {
+ if (!assetTreeNode.getAsset().getRealm().equals(this.realm)) {
environment.getEventBus().dispatch(new ShowFailureEvent(
environment.getMessages().assetNotInTenant(this.tenant.getDisplayName()), 2000
));
@@ -155,7 +155,7 @@ public class AssetsTenantActivity extends AssetBrowsingActivity<AssetsTenantPlac
public void onCreateAssetLink() {
if (selectedUserId == null || selectedAssetId == null)
return;
- UserAsset userAsset = new UserAsset(realmId, selectedUserId, selectedAssetId);
+ UserAsset userAsset = new UserAsset(realm, selectedUserId, selectedAssetId);
view.setFormBusy(true);
environment.getApp().getRequests().sendWith(
userAssetMapper,
@@ -176,7 +176,7 @@ public class AssetsTenantActivity extends AssetBrowsingActivity<AssetsTenantPlac
view.setFormBusy(true);
environment.getApp().getRequests().sendWith(
userAssetMapper,
- requestParams -> assetResource.deleteUserAsset(requestParams, id.getRealmId(), id.getUserId(), id.getAssetId()),
+ requestParams -> assetResource.deleteUserAsset(requestParams, id.getRealm(), id.getUserId(), id.getAssetId()),
204,
() -> {
environment.getEventBus().dispatch(new ShowSuccessEvent(
@@ -197,16 +197,16 @@ public class AssetsTenantActivity extends AssetBrowsingActivity<AssetsTenantPlac
protected void loadTenant() {
view.setFormBusy(true);
- if (this.realmId == null)
+ if (this.realm == null)
return;
environment.getApp().getRequests().sendAndReturn(
tenantMapper,
- requestParams -> tenantResource.getForRealmId(requestParams, this.realmId),
+ requestParams -> tenantResource.get(requestParams, this.realm),
200,
tenant -> {
this.tenant = tenant;
loadUsers(() -> {
- assetBrowserPresenter.selectTenant(tenant.getId());
+ assetBrowserPresenter.selectRealm(tenant.getRealm());
writeTenantToView();
loadUserAssets();
view.setFormBusy(false);
@@ -233,13 +233,13 @@ public class AssetsTenantActivity extends AssetBrowsingActivity<AssetsTenantPlac
protected void loadUserAssets() {
environment.getApp().getRequests().sendAndReturn(
userAssetArrayMapper,
- requestParams -> assetResource.getUserAssetLinks(requestParams, realmId, selectedUserId, selectedAssetId),
+ requestParams -> assetResource.getUserAssetLinks(requestParams, realm, selectedUserId, selectedAssetId),
200,
userAssets -> {
// Do not allow creating a duplicate of a link we already have
if ((userAssets.length == 1
- && userAssets[0].getId().equals(new UserAsset.Id(realmId, selectedUserId, selectedAssetId))))
+ && userAssets[0].getId().equals(new UserAsset.Id(realm, selectedUserId, selectedAssetId))))
view.setCreateAssetLinkEnabled(false);
view.setUserAssets(userAssets);
diff --git a/client/src/main/java/org/openremote/app/client/assets/tenant/AssetsTenantPlace.java b/client/src/main/java/org/openremote/app/client/assets/tenant/AssetsTenantPlace.java
index 06fa0c888..c1eea1dcf 100644
--- a/client/src/main/java/org/openremote/app/client/assets/tenant/AssetsTenantPlace.java
+++ b/client/src/main/java/org/openremote/app/client/assets/tenant/AssetsTenantPlace.java
@@ -25,14 +25,14 @@ import org.openremote.app.client.assets.AssetsPlace;
public class AssetsTenantPlace extends AssetsPlace {
- final String realmId;
+ final String realm;
- public AssetsTenantPlace(String realmId) {
- this.realmId = realmId;
+ public AssetsTenantPlace(String realm) {
+ this.realm = realm;
}
- public String getRealmId() {
- return realmId;
+ public String getRealm() {
+ return realm;
}
@Prefix("assetsTenant")
@@ -45,14 +45,14 @@ public class AssetsTenantPlace extends AssetsPlace {
@Override
public String getToken(AssetsTenantPlace place) {
- return place.getRealmId() != null ? place.getRealmId() : "";
+ return place.getRealm() != null ? place.getRealm() : "";
}
}
@Override
public String toString() {
return getClass().getSimpleName() + "{" +
- "realmId='" + realmId + '\'' +
+ "realm='" + realm + '\'' +
'}';
}
}
diff --git a/client/src/main/java/org/openremote/app/client/map/MapActivity.java b/client/src/main/java/org/openremote/app/client/map/MapActivity.java
index 7d6fdbe95..92f5cacef 100644
--- a/client/src/main/java/org/openremote/app/client/map/MapActivity.java
+++ b/client/src/main/java/org/openremote/app/client/map/MapActivity.java
@@ -62,7 +62,7 @@ public class MapActivity extends AssetBrowsingActivity<MapPlace> implements MapV
final ObjectValueMapper objectValueMapper;
String assetId;
- String realmId;
+ String realm;
Asset asset;
List<AssetAttribute> dashboardAttributes = new ArrayList<>();
@@ -89,7 +89,7 @@ public class MapActivity extends AssetBrowsingActivity<MapPlace> implements MapV
assetId = mapAssetPlace.getAssetId();
} else if (place instanceof MapTenantPlace) {
MapTenantPlace mapTenantPlace = (MapTenantPlace) place;
- realmId = mapTenantPlace.getRealmId();
+ realm = mapTenantPlace.getRealm();
}
return this;
}
@@ -101,8 +101,8 @@ public class MapActivity extends AssetBrowsingActivity<MapPlace> implements MapV
registrations.add(eventBus.register(AssetBrowserSelection.class, event -> {
if (event.getSelectedNode() instanceof TenantTreeNode) {
- String selectedRealmId = event.getSelectedNode().getId();
- if (this.realmId == null || !this.realmId.equals(selectedRealmId)) {
+ String selectedRealm = event.getSelectedNode().getId();
+ if (this.realm == null || !this.realm.equals(selectedRealm)) {
environment.getPlaceController().goTo(
new MapTenantPlace(event.getSelectedNode().getId())
);
@@ -183,7 +183,7 @@ public class MapActivity extends AssetBrowsingActivity<MapPlace> implements MapV
);
}
});
- } else if (realmId != null) {
+ } else if (realm != null) {
// TODO: Tenant map not implemented
}
}
diff --git a/client/src/main/java/org/openremote/app/client/map/MapTenantPlace.java b/client/src/main/java/org/openremote/app/client/map/MapTenantPlace.java
index e794bc47f..d099e3c47 100644
--- a/client/src/main/java/org/openremote/app/client/map/MapTenantPlace.java
+++ b/client/src/main/java/org/openremote/app/client/map/MapTenantPlace.java
@@ -24,18 +24,18 @@ import com.google.gwt.place.shared.Prefix;
public class MapTenantPlace extends MapPlace {
- final String realmId;
+ final String realm;
- public MapTenantPlace(String realmId) {
- this.realmId = realmId;
+ public MapTenantPlace(String realm) {
+ this.realm = realm;
}
public MapTenantPlace() {
- this.realmId = null;
+ this.realm = null;
}
- public String getRealmId() {
- return realmId;
+ public String getRealm() {
+ return realm;
}
@Prefix("mapTenant")
@@ -48,14 +48,14 @@ public class MapTenantPlace extends MapPlace {
@Override
public String getToken(MapTenantPlace place) {
- return place.getRealmId() != null ? place.getRealmId() : "";
+ return place.getRealm() != null ? place.getRealm() : "";
}
}
@Override
public String toString() {
return getClass().getSimpleName() + "{" +
- "realmId='" + realmId + '\'' +
+ "realm='" + realm + '\'' +
'}';
}
}
diff --git a/client/src/main/java/org/openremote/app/client/notifications/FilterOptions.java b/client/src/main/java/org/openremote/app/client/notifications/FilterOptions.java
index 5910ab8e4..d4ed69e7e 100644
--- a/client/src/main/java/org/openremote/app/client/notifications/FilterOptions.java
+++ b/client/src/main/java/org/openremote/app/client/notifications/FilterOptions.java
@@ -48,7 +48,6 @@ public class FilterOptions {
}
final protected Map<String, String> realms;
- final protected Map<String, String> realmIds;
final protected BiConsumer<FilterOptions, Consumer<Map<String, String>>> targetsSupplier;
protected Map<String, String> targets = new HashMap<>();
protected String selectedNotificationType = NOTIFICATION_TYPES[0]; // Only one type at the moment so select it
@@ -59,9 +58,8 @@ public class FilterOptions {
protected Runnable targetsChangedCallback;
protected Runnable changedCallback;
- public FilterOptions(Map<String, String> realms, Map<String, String> realmIds, BiConsumer<FilterOptions, Consumer<Map<String, String>>> targetsSupplier) {
+ public FilterOptions(Map<String, String> realms, BiConsumer<FilterOptions, Consumer<Map<String, String>>> targetsSupplier) {
this.realms = realms;
- this.realmIds = realmIds;
this.targetsSupplier = targetsSupplier;
}
@@ -77,10 +75,6 @@ public class FilterOptions {
return realms;
}
- public Map<String, String> getRealmIds() {
- return realmIds;
- }
-
public Map<String, String> getTargets() {
return targets;
}
@@ -113,10 +107,6 @@ public class FilterOptions {
return selectedRealm;
}
- public String getSelectedRealmId() {
- return selectedRealm == null ? null : realmIds.get(selectedRealm);
- }
-
public void setSelectedRealm(String selectedRealm) {
this.selectedRealm = selectedRealm;
this.selectedTarget = null;
@@ -193,8 +183,8 @@ public class FilterOptions {
return fromTimestamp;
}
- public String getTenantId() {
- return getSelectedTargetType() == Notification.TargetType.TENANT ? getSelectedRealmId() : null;
+ public String getRealm() {
+ return getSelectedTargetType() == Notification.TargetType.TENANT ? getSelectedRealm() : null;
}
public String getUserId() {
diff --git a/client/src/main/java/org/openremote/app/client/notifications/NotificationEditorImpl.java b/client/src/main/java/org/openremote/app/client/notifications/NotificationEditorImpl.java
index 8895cccc8..4ebabdced 100644
--- a/client/src/main/java/org/openremote/app/client/notifications/NotificationEditorImpl.java
+++ b/client/src/main/java/org/openremote/app/client/notifications/NotificationEditorImpl.java
@@ -168,7 +168,7 @@ public class NotificationEditorImpl implements NotificationEditor {
sendOptions.setSelectedRealm(realmsList.getSelectedValue());
if (sendOptions.getSelectedTargetType() == Notification.TargetType.TENANT) {
- sendOptions.setSelectedTarget(sendOptions.getSelectedRealmId());
+ sendOptions.setSelectedTarget(sendOptions.getSelectedRealm());
}
}
});
@@ -177,7 +177,7 @@ public class NotificationEditorImpl implements NotificationEditor {
if (sendOptions != null) {
sendOptions.setSelectedTargetType(targetTypesList.getSelectedValue());
if (sendOptions.getSelectedTargetType() == Notification.TargetType.TENANT) {
- sendOptions.setSelectedTarget(sendOptions.getSelectedRealmId());
+ sendOptions.setSelectedTarget(sendOptions.getSelectedRealm());
targetsGroup.setVisible(false);
} else {
targetsList.selectItem("");
diff --git a/client/src/main/java/org/openremote/app/client/notifications/NotificationsActivity.java b/client/src/main/java/org/openremote/app/client/notifications/NotificationsActivity.java
index f4c8aa6f2..a3b2b507b 100644
--- a/client/src/main/java/org/openremote/app/client/notifications/NotificationsActivity.java
+++ b/client/src/main/java/org/openremote/app/client/notifications/NotificationsActivity.java
@@ -124,7 +124,7 @@ public class NotificationsActivity extends AssetBrowsingActivity<NotificationsPl
if (event.getSelectedNode() instanceof TenantTreeNode) {
realm = ((TenantTreeNode) event.getSelectedNode()).getTenant().getRealm();
} else if (event.getSelectedNode() instanceof AssetTreeNode) {
- realm = ((AssetTreeNode) event.getSelectedNode()).getAsset().getTenantRealm();
+ realm = ((AssetTreeNode) event.getSelectedNode()).getAsset().getRealm();
assetId = event.getSelectedNode().getId();
}
@@ -146,10 +146,7 @@ public class NotificationsActivity extends AssetBrowsingActivity<NotificationsPl
Map<String, String> realms = Arrays.stream(tenants)
.collect(Collectors.toMap(Tenant::getRealm, Tenant::getDisplayName));
- Map<String, String> realmIds = Arrays.stream(tenants)
- .collect(Collectors.toMap(Tenant::getRealm, Tenant::getId));
-
- filterOptions = new FilterOptions(realms, realmIds, this::loadTargets);
+ filterOptions = new FilterOptions(realms, this::loadTargets);
String selectedRealm = !TextUtil.isNullOrEmpty(place.getRealm()) && realms.containsKey(place.getRealm())
? place.getRealm() : null;
@@ -194,11 +191,8 @@ public class NotificationsActivity extends AssetBrowsingActivity<NotificationsPl
Map<String, String> realms = Arrays.stream(tenants)
.collect(Collectors.toMap(Tenant::getRealm, Tenant::getDisplayName));
- Map<String, String> realmIds = Arrays.stream(tenants)
- .collect(Collectors.toMap(Tenant::getRealm, Tenant::getId));
-
if (sendOptions == null) {
- sendOptions = new SendOptions(realms, realmIds, this::loadTargets, this::createMessage);
+ sendOptions = new SendOptions(realms, this::loadTargets, this::createMessage);
}
String selectedRealm = !TextUtil.isNullOrEmpty(place.getRealm()) && realms.containsKey(place.getRealm())
@@ -234,7 +228,7 @@ public class NotificationsActivity extends AssetBrowsingActivity<NotificationsPl
@Override
public void deleteNotifications() {
- String tenantId = filterOptions.getTenantId();
+ String tenantId = filterOptions.getRealm();
String userId = filterOptions.getUserId();
String assetId = filterOptions.getAssetId();
Long fromTimestamp = filterOptions.getFromTimestamp();
@@ -407,7 +401,7 @@ public class NotificationsActivity extends AssetBrowsingActivity<NotificationsPl
new AssetQuery()
.select(new BaseAssetQuery
.Select(BaseAssetQuery.Include.ONLY_ID_AND_NAME))
- .tenant(new TenantPredicate().realm(realm))),
+ .tenant(new TenantPredicate(realm))),
200,
assetConsumer::accept);
}
@@ -419,7 +413,7 @@ public class NotificationsActivity extends AssetBrowsingActivity<NotificationsPl
return;
}
- String tenantId = filterOptions.getTenantId();
+ String tenantId = filterOptions.getRealm();
String userId = filterOptions.getUserId();
String assetId = filterOptions.getAssetId();
Long fromTimestamp = filterOptions.getFromTimestamp();
diff --git a/client/src/main/java/org/openremote/app/client/notifications/SendOptions.java b/client/src/main/java/org/openremote/app/client/notifications/SendOptions.java
index 3e010492a..01ec31ca2 100644
--- a/client/src/main/java/org/openremote/app/client/notifications/SendOptions.java
+++ b/client/src/main/java/org/openremote/app/client/notifications/SendOptions.java
@@ -36,8 +36,8 @@ public class SendOptions extends FilterOptions {
protected Supplier<AbstractNotificationMessage> messageSupplier;
protected AbstractNotificationMessage message;
- public SendOptions(Map<String, String> realms, Map<String, String> realmIds, BiConsumer<FilterOptions, Consumer<Map<String, String>>> targetsSupplier, Supplier<AbstractNotificationMessage> messageSupplier) {
- super(realms, realmIds, targetsSupplier);
+ public SendOptions(Map<String, String> realms, BiConsumer<FilterOptions, Consumer<Map<String, String>>> targetsSupplier, Supplier<AbstractNotificationMessage> messageSupplier) {
+ super(realms, targetsSupplier);
this.messageSupplier = messageSupplier;
}
diff --git a/client/src/main/java/org/openremote/app/client/rules/RulesModule.java b/client/src/main/java/org/openremote/app/client/rules/RulesModule.java
index 1a0536c9c..a3d0d2c28 100644
--- a/client/src/main/java/org/openremote/app/client/rules/RulesModule.java
+++ b/client/src/main/java/org/openremote/app/client/rules/RulesModule.java
@@ -41,7 +41,7 @@ public class RulesModule extends AbstractGinModule {
return event -> {
if (event.getSelectedNode() instanceof TenantTreeNode) {
environment.getPlaceController().goTo(
- new TenantRulesListPlace(event.getSelectedNode().getId())
+ new TenantRulesListPlace(((TenantTreeNode) event.getSelectedNode()).getTenant().getRealm())
);
} else if (event.getSelectedNode() instanceof AssetTreeNode) {
environment.getPlaceController().goTo(
diff --git a/client/src/main/java/org/openremote/app/client/rules/tenant/TenantRulesEditorActivity.java b/client/src/main/java/org/openremote/app/client/rules/tenant/TenantRulesEditorActivity.java
index d6722be6f..33dddae63 100644
--- a/client/src/main/java/org/openremote/app/client/rules/tenant/TenantRulesEditorActivity.java
+++ b/client/src/main/java/org/openremote/app/client/rules/tenant/TenantRulesEditorActivity.java
@@ -46,7 +46,7 @@ public class TenantRulesEditorActivity
final TenantResource tenantResource;
final TenantRulesetMapper tenantRulesetMapper;
- String realmId;
+ String realm;
@Inject
public TenantRulesEditorActivity(Environment environment,
@@ -64,7 +64,7 @@ public class TenantRulesEditorActivity
@Override
protected AppActivity<TenantRulesEditorPlace> init(TenantRulesEditorPlace place) {
- realmId = place.getRealmId();
+ realm = place.getRealm();
return super.init(place);
}
@@ -74,7 +74,7 @@ public class TenantRulesEditorActivity
environment.getApp().getRequests().sendAndReturn(
tenantMapper,
- params -> tenantResource.getForRealmId(params, realmId),
+ params -> tenantResource.get(params, realm),
200,
tenant -> {
view.setHeadline(tenant.getDisplayName(), environment.getMessages().editTenantRuleset());
@@ -84,7 +84,7 @@ public class TenantRulesEditorActivity
@Override
protected TenantRuleset newRuleset() {
- return new TenantRuleset(realmId);
+ return new TenantRuleset(realm);
}
@Override
@@ -109,7 +109,7 @@ public class TenantRulesEditorActivity
@Override
protected void afterCreate() {
- environment.getPlaceController().goTo(new TenantRulesListPlace(realmId));
+ environment.getPlaceController().goTo(new TenantRulesListPlace(realm));
}
@Override
@@ -119,7 +119,7 @@ public class TenantRulesEditorActivity
@Override
protected void afterUpdate() {
- environment.getPlaceController().goTo(new TenantRulesEditorPlace(realmId, rulesetId));
+ environment.getPlaceController().goTo(new TenantRulesEditorPlace(realm, rulesetId));
}
@Override
@@ -129,11 +129,11 @@ public class TenantRulesEditorActivity
@Override
protected void afterDelete() {
- environment.getPlaceController().goTo(new TenantRulesListPlace(realmId));
+ environment.getPlaceController().goTo(new TenantRulesListPlace(realm));
}
@Override
public void cancel() {
- environment.getPlaceController().goTo(new TenantRulesListPlace(realmId));
+ environment.getPlaceController().goTo(new TenantRulesListPlace(realm));
}
}
diff --git a/client/src/main/java/org/openremote/app/client/rules/tenant/TenantRulesEditorPlace.java b/client/src/main/java/org/openremote/app/client/rules/tenant/TenantRulesEditorPlace.java
index d24a18d98..e63534242 100644
--- a/client/src/main/java/org/openremote/app/client/rules/tenant/TenantRulesEditorPlace.java
+++ b/client/src/main/java/org/openremote/app/client/rules/tenant/TenantRulesEditorPlace.java
@@ -25,25 +25,25 @@ import org.openremote.app.client.rules.RulesEditorPlace;
public class TenantRulesEditorPlace extends RulesEditorPlace {
- final protected String realmId;
+ final protected String realm;
- public TenantRulesEditorPlace(String realmId) {
+ public TenantRulesEditorPlace(String realm) {
super();
- this.realmId = realmId;
+ this.realm = realm;
}
- public TenantRulesEditorPlace(String realmId, String rulesetId) {
+ public TenantRulesEditorPlace(String realm, String rulesetId) {
super(rulesetId);
- this.realmId = realmId;
+ this.realm = realm;
}
- public TenantRulesEditorPlace(String realmId, Long rulesetId) {
+ public TenantRulesEditorPlace(String realm, Long rulesetId) {
super(rulesetId);
- this.realmId = realmId;
+ this.realm = realm;
}
- public String getRealmId() {
- return realmId;
+ public String getRealm() {
+ return realm;
}
@Prefix("tenantRulesEditor")
@@ -66,10 +66,10 @@ public class TenantRulesEditorPlace extends RulesEditorPlace {
@Override
public String getToken(TenantRulesEditorPlace place) {
- if (place.getRealmId() == null) {
+ if (place.getRealm() == null) {
return "";
}
- return place.getRealmId() + ":" + (place.getRulesetId() != null ? place.getRulesetId() : "");
+ return place.getRealm() + ":" + (place.getRulesetId() != null ? place.getRulesetId() : "");
}
}
}
diff --git a/client/src/main/java/org/openremote/app/client/rules/tenant/TenantRulesListActivity.java b/client/src/main/java/org/openremote/app/client/rules/tenant/TenantRulesListActivity.java
index f1af4b117..14274fdf5 100644
--- a/client/src/main/java/org/openremote/app/client/rules/tenant/TenantRulesListActivity.java
+++ b/client/src/main/java/org/openremote/app/client/rules/tenant/TenantRulesListActivity.java
@@ -52,7 +52,7 @@ public class TenantRulesListActivity
final TenantRulesetArrayMapper tenantRulesetArrayMapper;
final RulesResource rulesResource;
- String realmId;
+ String realm;
@Inject
public TenantRulesListActivity(Environment environment,
@@ -74,7 +74,7 @@ public class TenantRulesListActivity
@Override
protected AppActivity<TenantRulesListPlace> init(TenantRulesListPlace place) {
- this.realmId = place.getRealmId();
+ this.realm = place.getRealm();
return this;
}
@@ -88,34 +88,34 @@ public class TenantRulesListActivity
RulesModule.createDefaultNavigationListener(environment)
));
- if (realmId != null) {
+ if (realm != null) {
subscribeStatusEvents(true, registrations);
- assetBrowserPresenter.selectTenant(realmId);
+ assetBrowserPresenter.selectRealm(realm);
environment.getApp().getRequests().sendAndReturn(
tenantMapper,
- params -> tenantResource.getForRealmId(params, realmId),
+ params -> tenantResource.get(params, realm),
200,
tenant -> {
view.setRealmLabel(tenant.getDisplayName());
view.setCreateRulesetHistoryToken(
- environment.getPlaceHistoryMapper().getToken(new TenantRulesEditorPlace(realmId))
+ environment.getPlaceHistoryMapper().getToken(new TenantRulesEditorPlace(realm))
);
}
);
environment.getApp().getRequests().sendAndReturn(
rulesEngineInfoMapper,
- params -> rulesResource.getTenantEngineInfo(params, realmId),
+ params -> rulesResource.getTenantEngineInfo(params, realm),
new double[] {200, 204},
view::onEngineStatusChanged
);
environment.getApp().getRequests().sendAndReturn(
tenantRulesetArrayMapper,
- params -> rulesResource.getTenantRulesets(params, realmId),
+ params -> rulesResource.getTenantRulesets(params, realm),
200,
results -> view.setRulesets(new ArrayList<>(Arrays.asList(results)))
);
@@ -131,7 +131,7 @@ public class TenantRulesListActivity
@Override
public void onRulesetSelected(TenantRuleset ruleset) {
- environment.getPlaceController().goTo(new TenantRulesEditorPlace(realmId, ruleset.getId()));
+ environment.getPlaceController().goTo(new TenantRulesEditorPlace(realm, ruleset.getId()));
}
protected void subscribeStatusEvents(boolean subscribe, Collection<EventRegistration> registrations) {
@@ -142,7 +142,7 @@ public class TenantRulesListActivity
registrations.add(environment.getEventBus().register(
RulesEngineStatusEvent.class,
e -> {
- if (realmId.equals(e.getEngineId())) {
+ if (realm.equals(e.getEngineId())) {
view.onEngineStatusChanged(e.getEngineInfo());
}
}
@@ -151,7 +151,7 @@ public class TenantRulesListActivity
registrations.add(environment.getEventBus().register(
RulesetChangedEvent.class,
e -> {
- if (realmId.equals(e.getEngineId())) {
+ if (realm.equals(e.getEngineId())) {
view.onRulesetStatusChanged((TenantRuleset) e.getRuleset());
}
}
diff --git a/client/src/main/java/org/openremote/app/client/rules/tenant/TenantRulesListPlace.java b/client/src/main/java/org/openremote/app/client/rules/tenant/TenantRulesListPlace.java
index d3c533db0..cfb20c90c 100644
--- a/client/src/main/java/org/openremote/app/client/rules/tenant/TenantRulesListPlace.java
+++ b/client/src/main/java/org/openremote/app/client/rules/tenant/TenantRulesListPlace.java
@@ -25,14 +25,14 @@ import org.openremote.app.client.rules.RulesPlace;
public class TenantRulesListPlace extends RulesPlace {
- final String realmId;
+ final String realm;
- public TenantRulesListPlace(String realmId) {
- this.realmId = realmId;
+ public TenantRulesListPlace(String realm) {
+ this.realm = realm;
}
- public String getRealmId() {
- return realmId;
+ public String getRealm() {
+ return realm;
}
@Prefix("tenantRules")
@@ -45,14 +45,14 @@ public class TenantRulesListPlace extends RulesPlace {
@Override
public String getToken(TenantRulesListPlace place) {
- return place.getRealmId() != null ? place.getRealmId() : "";
+ return place.getRealm() != null ? place.getRealm() : "";
}
}
@Override
public String toString() {
return getClass().getSimpleName() + "{" +
- "realmId='" + realmId + '\'' +
+ "realm='" + realm + '\'' +
'}';
}
}
diff --git a/manager/src/main/java/org/openremote/manager/agent/AgentResourceImpl.java b/manager/src/main/java/org/openremote/manager/agent/AgentResourceImpl.java
index 00380eba0..6d1333b03 100644
--- a/manager/src/main/java/org/openremote/manager/agent/AgentResourceImpl.java
+++ b/manager/src/main/java/org/openremote/manager/agent/AgentResourceImpl.java
@@ -23,11 +23,10 @@ import org.openremote.container.timer.TimerService;
import org.openremote.manager.asset.AssetStorageService;
import org.openremote.manager.security.ManagerIdentityService;
import org.openremote.manager.web.ManagerWebResource;
-import org.openremote.model.asset.agent.AgentResource;
-import org.openremote.model.security.Tenant;
import org.openremote.model.asset.Asset;
import org.openremote.model.asset.AssetAttribute;
import org.openremote.model.asset.AssetType;
+import org.openremote.model.asset.agent.AgentResource;
import org.openremote.model.asset.agent.AgentStatusEvent;
import org.openremote.model.asset.agent.ProtocolDescriptor;
import org.openremote.model.attribute.AttributeRef;
@@ -36,6 +35,7 @@ import org.openremote.model.event.shared.TenantFilter;
import org.openremote.model.file.FileInfo;
import org.openremote.model.http.RequestParams;
import org.openremote.model.util.Pair;
+import org.openremote.model.util.TextUtil;
import javax.ws.rs.*;
import javax.ws.rs.core.HttpHeaders;
@@ -48,8 +48,6 @@ import java.util.function.Function;
import java.util.logging.Level;
import java.util.logging.Logger;
-import static org.openremote.model.util.TextUtil.isNullOrEmpty;
-
public class AgentResourceImpl extends ManagerWebResource implements AgentResource {
private static final Logger LOG = Logger.getLogger(AgentResourceImpl.class.getName());
@@ -81,7 +79,7 @@ public class AgentResourceImpl extends ManagerWebResource implements AgentResour
new TenantFilter<AgentStatusEvent>() {
@Override
public boolean apply(AgentStatusEvent event) {
- return event.getRealmId().equals(getAuthenticatedTenant().getId());
+ return event.getRealm().equals(getAuthenticatedTenant().getId());
}
}
)) {
@@ -131,10 +129,14 @@ public class AgentResourceImpl extends ManagerWebResource implements AgentResour
}
@Override
- public Asset[] searchForLinkedAttributes(RequestParams requestParams, String agentId, String protocolConfigurationName, String parentId, String realmId) {
+ public Asset[] searchForLinkedAttributes(RequestParams requestParams, String agentId, String protocolConfigurationName, String parentId, String realm) {
AttributeRef protocolConfigRef = new AttributeRef(agentId, protocolConfigurationName);
- Pair<Asset, String> parentAndRealmId = getParentAssetAndRealmId(parentId, realmId);
+ if (!isSuperUser() && TextUtil.isNullOrEmpty(realm)) {
+ realm = getAuthenticatedRealm();
+ }
+
+ Asset parentAsset = getParent(parentId, realm);
// TODO: Allow user to select which assets/attributes are actually added to the DB
Asset[] assets = withAgentConnector(
@@ -148,7 +150,7 @@ public class AgentResourceImpl extends ManagerWebResource implements AgentResour
);
try {
- persistAssets(assets, parentAndRealmId.key, parentAndRealmId.value);
+ persistAssets(assets, parentAsset, realm);
return assets;
} catch (IllegalArgumentException e) {
LOG.log(Level.WARNING, e.getMessage(), e);
@@ -160,15 +162,19 @@ public class AgentResourceImpl extends ManagerWebResource implements AgentResour
}
@Override
- public Asset[] importLinkedAttributes(RequestParams requestParams, String agentId, String protocolConfigurationName, String parentId, String realmId, FileInfo fileInfo) {
+ public Asset[] importLinkedAttributes(RequestParams requestParams, String agentId, String protocolConfigurationName, String parentId, String realm, FileInfo fileInfo) {
AttributeRef protocolConfigRef = new AttributeRef(agentId, protocolConfigurationName);
+ if (TextUtil.isNullOrEmpty(parentId) && TextUtil.isNullOrEmpty(realm)) {
+ realm = getAuthenticatedRealm();
+ }
+
+ Asset parentAsset = getParent(parentId, realm);
+
if (fileInfo == null || fileInfo.getContents() == null) {
throw new BadRequestException("A file must be provided for import");
}
- Pair<Asset, String> parentAndRealmId = getParentAssetAndRealmId(parentId, realmId);
-
Asset[] assets = withAgentConnector(
agentId,
agentConnector -> {
@@ -182,7 +188,7 @@ public class AgentResourceImpl extends ManagerWebResource implements AgentResour
try {
// TODO: Allow user to select which assets/attributes are actually added to the DB
- persistAssets(assets, parentAndRealmId.key, parentAndRealmId.value);
+ persistAssets(assets, parentAsset, realm);
return assets;
} catch (IllegalArgumentException e) {
LOG.log(Level.WARNING, e.getMessage(), e);
@@ -210,39 +216,7 @@ public class AgentResourceImpl extends ManagerWebResource implements AgentResour
});
}
- /**
- * Parent takes priority over realm ID (only super user can add to other realms)
- */
- protected Pair<Asset, String> getParentAssetAndRealmId(String parentId, String realmId) {
- if (isRestrictedUser()) {
- throw new ForbiddenException("User is restricted");
- }
-
- // Assets must be added in the same realm as the user (unless super user)
- Asset parentAsset = isNullOrEmpty(parentId) ? null : assetStorageService.find(parentId);
-
- if (parentAsset == null && !isNullOrEmpty(parentId)) {
- // Either invalid asset or user doesn't have access to it
- LOG.info("User is trying to import with an invalid or inaccessible parent");
- throw new BadRequestException("Parent either doesn't exist or is not accessible");
- }
-
- Tenant tenant = parentAsset != null ?
- identityService.getIdentityProvider().getTenantForRealmId(parentAsset.getRealmId()) :
- !isNullOrEmpty(realmId) ?
- identityService.getIdentityProvider().getTenantForRealmId(realmId) :
- getAuthenticatedTenant();
-
- if (!isTenantActiveAndAccessible(tenant)) {
- String msg = "The requested parent asset or realm is inaccessible";
- LOG.fine(msg);
- throw new ForbiddenException(msg);
- }
-
- return new Pair<>(parentAsset, tenant.getId());
- }
-
- protected void persistAssets(Asset[] assets, Asset parentAsset, String realmId) {
+ protected void persistAssets(Asset[] assets, Asset parentAsset, String realm) {
if (assets == null || assets.length == 0) {
LOG.info("No assets to import");
return;
@@ -251,10 +225,29 @@ public class AgentResourceImpl extends ManagerWebResource implements AgentResour
for (int i = 0; i < assets.length; i++) {
Asset asset = assets[i];
asset.setId(null);
+ asset.setRealm(realm);
asset.setParent(parentAsset);
- asset.setRealmId(realmId);
Asset newAsset = Asset.map(asset, new Asset());
assets[i] = assetStorageService.merge(newAsset);
}
}
+
+ protected Asset getParent(String parentId, String realm) throws WebApplicationException {
+ if (!isSuperUser() && !realm.equals(getAuthenticatedRealm())) {
+ throw new ForbiddenException();
+ }
+
+ if (TextUtil.isNullOrEmpty(parentId)) {
+ return null;
+ }
+
+ // Assets must be added in the same realm as the user (unless super user)
+ Asset parentAsset = assetStorageService.find(parentId);
+
+ if (parentAsset == null || (!TextUtil.isNullOrEmpty(realm) && parentAsset.getRealm().equals(realm))) {
+ throw new NotFoundException("Parent asset doesn't exist in the requested realm '" + realm + "'");
+ }
+
+ return parentAsset;
+ }
}
diff --git a/manager/src/main/java/org/openremote/manager/agent/AgentService.java b/manager/src/main/java/org/openremote/manager/agent/AgentService.java
index 691f5153e..2e919220a 100644
--- a/manager/src/main/java/org/openremote/manager/agent/AgentService.java
+++ b/manager/src/main/java/org/openremote/manager/agent/AgentService.java
@@ -554,7 +554,7 @@ public class AgentService extends RouteBuilder implements ContainerService, Asse
clientEventService.publishEvent(
new AgentStatusEvent(
timerService.getCurrentTimeMillis(),
- agentMap.get(protocolRef.getEntityId()).getRealmId(),
+ agentMap.get(protocolRef.getEntityId()).getRealm(),
protocolRef,
connectionStatus
)
diff --git a/manager/src/main/java/org/openremote/manager/agent/LocalAgentConnector.java b/manager/src/main/java/org/openremote/manager/agent/LocalAgentConnector.java
index 413a514ac..52898085b 100644
--- a/manager/src/main/java/org/openremote/manager/agent/LocalAgentConnector.java
+++ b/manager/src/main/java/org/openremote/manager/agent/LocalAgentConnector.java
@@ -55,7 +55,7 @@ public class LocalAgentConnector implements AgentConnector {
.map(protocolConfigurationRef -> new Pair<>(protocolConfigurationRef, agentService.getProtocolConnectionStatus(protocolConfigurationRef)))
.map(pair -> new AgentStatusEvent(
agentService.timerService.getCurrentTimeMillis(),
- asset.getRealmId(),
+ asset.getRealm(),
pair.key,
pair.value)
)
diff --git a/manager/src/main/java/org/openremote/manager/asset/AssetProcessingService.java b/manager/src/main/java/org/openremote/manager/asset/AssetProcessingService.java
index b1cd0229a..c93d72956 100644
--- a/manager/src/main/java/org/openremote/manager/asset/AssetProcessingService.java
+++ b/manager/src/main/java/org/openremote/manager/asset/AssetProcessingService.java
@@ -190,7 +190,7 @@ public class AssetProcessingService extends RouteBuilder implements ContainerSer
// TODO Restricted clients should only receive events for RESTRICTED_READ attributes!
} else {
// Regular users can only get attribute events for assets in their realm
- if (!asset.getTenantRealm().equals(auth.getAuthenticatedRealm()))
+ if (!asset.getRealm().equals(auth.getAuthenticatedRealm()))
return false;
}
}
diff --git a/manager/src/main/java/org/openremote/manager/asset/AssetResourceImpl.java b/manager/src/main/java/org/openremote/manager/asset/AssetResourceImpl.java
index 71763f1c5..1de0f430e 100644
--- a/manager/src/main/java/org/openremote/manager/asset/AssetResourceImpl.java
+++ b/manager/src/main/java/org/openremote/manager/asset/AssetResourceImpl.java
@@ -79,7 +79,7 @@ public class AssetResourceImpl extends ManagerWebResource implements AssetResour
List<Asset> result = assetStorageService.findAll(
new AssetQuery()
.parent(new ParentPredicate(true))
- .tenant(new TenantPredicate().realm(getAuthenticatedRealm()))
+ .tenant(new TenantPredicate(getAuthenticatedRealm()))
);
return result.toArray(new Asset[result.size()]);
}
@@ -92,11 +92,10 @@ public class AssetResourceImpl extends ManagerWebResource implements AssetResour
// Filter assets that might have been moved into a different realm and can no longer be accessed by user
// TODO: Should we forbid moving assets between realms?
- Tenant authenticatedTenant = getAuthenticatedTenant();
Iterator<Asset> it = assets.iterator();
while (it.hasNext()) {
Asset asset = it.next();
- if (!asset.getRealmId().equals(authenticatedTenant.getId())) {
+ if (!asset.getRealm().equals(getAuthenticatedRealm())) {
LOG.warning("User '" + getUsername() + "' linked to asset in other realm, skipping: " + asset);
it.remove();
}
@@ -112,22 +111,21 @@ public class AssetResourceImpl extends ManagerWebResource implements AssetResour
}
@Override
- public UserAsset[] getUserAssetLinks(RequestParams requestParams, String realmId, String userId, String assetId) {
+ public UserAsset[] getUserAssetLinks(RequestParams requestParams, String realm, String userId, String assetId) {
try {
- if (realmId == null)
+ if (realm == null)
throw new WebApplicationException(BAD_REQUEST);
- Tenant tenant = identityService.getIdentityProvider().getTenantForRealmId(realmId);
- if (tenant == null)
+ if (!identityService.getIdentityProvider().tenantExists(realm))
throw new WebApplicationException(NOT_FOUND);
- if (!isSuperUser() && (isRestrictedUser() && !getAuthenticatedTenant().getId().equals(tenant.getId())))
+ if (!(isSuperUser() || getAuthenticatedRealm().equals(realm)))
throw new WebApplicationException(FORBIDDEN);
- if (userId != null && !identityService.getIdentityProvider().isUserInTenant(userId, realmId))
+ if (userId != null && !identityService.getIdentityProvider().isUserInTenant(userId, realm))
throw new WebApplicationException(BAD_REQUEST);
- UserAsset[] result = assetStorageService.findUserAssets(realmId, userId, assetId).toArray(new UserAsset[0]);
+ UserAsset[] result = assetStorageService.findUserAssets(realm, userId, assetId).toArray(new UserAsset[0]);
// Compress response (the request attribute enables the interceptor)
request.setAttribute(HttpHeaders.CONTENT_ENCODING, "gzip");
@@ -142,15 +140,15 @@ public class AssetResourceImpl extends ManagerWebResource implements AssetResour
@Override
public void createUserAsset(RequestParams requestParams, UserAsset userAsset) {
- String realmId = userAsset.getId().getRealmId();
+ String realm = userAsset.getId().getRealm();
String userId = userAsset.getId().getUserId();
String assetId = userAsset.getId().getAssetId();
- if (!identityService.getIdentityProvider().isUserInTenant(userId, realmId))
+ if (!identityService.getIdentityProvider().isUserInTenant(userId, realm))
throw new WebApplicationException(BAD_REQUEST);
Asset asset;
- if ((asset = assetStorageService.find(assetId)) == null || !asset.getRealmId().equals(realmId)) {
+ if ((asset = assetStorageService.find(assetId)) == null || !asset.getRealm().equals(realm)) {
throw new WebApplicationException(BAD_REQUEST);
}
@@ -161,28 +159,28 @@ public class AssetResourceImpl extends ManagerWebResource implements AssetResour
// Restricted users or regular users in a different realm can not create links
if (isRestrictedUser()
- || !getAuthenticatedTenant().getId().equals(realmId))
+ || !getAuthenticatedTenant().getId().equals(realm))
throw new WebApplicationException(FORBIDDEN);
assetStorageService.storeUserAsset(userAsset);
}
@Override
- public void deleteUserAsset(RequestParams requestParams, String realmId, String userId, String assetId) {
- if (!identityService.getIdentityProvider().isUserInTenant(userId, realmId))
+ public void deleteUserAsset(RequestParams requestParams, String realm, String userId, String assetId) {
+ if (!identityService.getIdentityProvider().isUserInTenant(userId, realm))
throw new WebApplicationException(BAD_REQUEST);
if (isSuperUser()) {
- assetStorageService.deleteUserAsset(realmId, userId, assetId);
+ assetStorageService.deleteUserAsset(realm, userId, assetId);
return;
}
// Restricted users or regular users in a different realm can not delete links
if (isRestrictedUser()
- || !getAuthenticatedTenant().getId().equals(realmId))
+ || !getAuthenticatedTenant().getId().equals(realm))
throw new WebApplicationException(FORBIDDEN);
- assetStorageService.deleteUserAsset(realmId, userId, assetId);
+ assetStorageService.deleteUserAsset(realm, userId, assetId);
}
@Override
@@ -247,7 +245,7 @@ public class AssetResourceImpl extends ManagerWebResource implements AssetResour
asset,
storageAsset,
isRestrictedUser ? storageAsset.getName() : null, // TODO We could allow restricted users to update names?
- isRestrictedUser ? storageAsset.getRealmId() : null, // Restricted users can not change realm
+ isRestrictedUser ? storageAsset.getRealm() : null, // Restricted users can not change realm
isRestrictedUser ? storageAsset.getParentId() : null, // Restricted users can not change realm
storageAsset.getType(), // The type can never change
isRestrictedUser ? storageAsset.isAccessPublicRead() : null, // Restricted user can not change access public flag
@@ -439,8 +437,8 @@ public class AssetResourceImpl extends ManagerWebResource implements AssetResour
}
// If there was no realm provided (create was called by regular user in manager UI), use the auth realm
- if (asset.getRealmId() == null || asset.getRealmId().length() == 0) {
- asset.setRealmId(getAuthenticatedTenant().getId());
+ if (asset.getRealm() == null || asset.getRealm().length() == 0) {
+ asset.setRealm(getAuthenticatedTenant().getId());
}
if (!isTenantActiveAndAccessible(asset)) {
@@ -538,10 +536,8 @@ public class AssetResourceImpl extends ManagerWebResource implements AssetResour
}
Tenant tenant = query.tenant != null
- ? !isNullOrEmpty(query.tenant.realmId)
- ? identityService.getIdentityProvider().getTenantForRealmId(query.tenant.realmId)
- : !isNullOrEmpty(query.tenant.realm)
- ? identityService.getIdentityProvider().getTenantForRealm(query.tenant.realm)
+ ? !isNullOrEmpty(query.tenant.realm)
+ ? identityService.getIdentityProvider().getTenant(query.tenant.realm)
: getAuthenticatedTenant()
: getAuthenticatedTenant();
@@ -555,7 +551,7 @@ public class AssetResourceImpl extends ManagerWebResource implements AssetResour
// This replicates behaviour of old getRoot and getChildren methods
if (!isSuperUser() || query.parent == null || query.parent.noParent) {
- query.tenant(new TenantPredicate(tenant.getId()));
+ query.tenant(new TenantPredicate(tenant.getRealm()));
}
List<Asset> result = assetStorageService.findAll(query);
@@ -581,7 +577,7 @@ public class AssetResourceImpl extends ManagerWebResource implements AssetResour
// Force realm to be request realm
if (query.tenant == null) {
- query.tenant(new TenantPredicate().realm(requestRealm));
+ query.tenant(new TenantPredicate(requestRealm));
} else {
query.tenant.realm = requestRealm;
}
diff --git a/manager/src/main/java/org/openremote/manager/asset/AssetStorageService.java b/manager/src/main/java/org/openremote/manager/asset/AssetStorageService.java
index fc282bac0..9ab4da10a 100644
--- a/manager/src/main/java/org/openremote/manager/asset/AssetStorageService.java
+++ b/manager/src/main/java/org/openremote/manager/asset/AssetStorageService.java
@@ -342,17 +342,17 @@ public class AssetStorageService extends RouteBuilder implements ContainerServic
throw new IllegalStateException("Invalid parent");
// .. the parent should be in the same realm
- if (asset.getRealmId() != null && !parent.getRealmId().equals(asset.getRealmId())) {
- throw new IllegalStateException("Parent not in same realm as asset: " + asset.getRealmId());
- } else if (asset.getRealmId() == null) {
+ if (asset.getRealm() != null && !parent.getRealm().equals(asset.getRealm())) {
+ throw new IllegalStateException("Parent not in same realm as asset: " + asset.getRealm());
+ } else if (asset.getRealm() == null) {
// ... and if we don't have a realm identifier, use the parent's
- asset.setRealmId(parent.getRealmId());
+ asset.setRealm(parent.getRealm());
}
}
// Validate realm
- if (!identityService.getIdentityProvider().isActiveTenant(asset.getRealmId())) {
- throw new IllegalStateException("Realm not found/active: " + asset.getRealmId());
+ if (!identityService.getIdentityProvider().tenantExists(asset.getRealm())) {
+ throw new IllegalStateException("Realm not found/active: " + asset.getRealm());
}
// Validate attributes
@@ -381,7 +381,7 @@ public class AssetStorageService extends RouteBuilder implements ContainerServic
// If username present
User user = null;
if (!TextUtil.isNullOrEmpty(userName)) {
- user = identityService.getIdentityProvider().getUser(asset.getRealmId(), userName);
+ user = identityService.getIdentityProvider().getUser(asset.getRealm(), userName);
if (user == null) {
throw new IllegalStateException("User not found: " + userName);
}
@@ -392,7 +392,7 @@ public class AssetStorageService extends RouteBuilder implements ContainerServic
Asset updatedAsset = em.merge(asset);
if (user != null) {
- storeUserAsset(em, new UserAsset(user.getRealmId(), user.getId(), updatedAsset.getId()));
+ storeUserAsset(em, new UserAsset(user.getRealm(), user.getId(), updatedAsset.getId()));
}
return updatedAsset;
@@ -477,20 +477,20 @@ public class AssetStorageService extends RouteBuilder implements ContainerServic
/**
* Indicates if the specified asset belongs to the specified realm
*/
- public boolean isRealmAsset(String realmId, String assetId) {
- return isRealmAssets(realmId, Collections.singletonList(assetId));
+ public boolean isRealmAsset(String realm, String assetId) {
+ return isRealmAssets(realm, Collections.singletonList(assetId));
}
/**
* Indicates if the specified assets belong to the specified realm
*/
- public boolean isRealmAssets(String realmId, List<String> assetIds) {
+ public boolean isRealmAssets(String realm, List<String> assetIds) {
return persistenceService.doReturningTransaction(entityManager -> {
try {
return entityManager.createQuery(
- "select count(a) from Asset a where a.realmId = :realmId and a.id in :assetIds",
+ "select count(a) from Asset a where a.realm = :realm and a.id in :assetIds",
Long.class)
- .setParameter("realmId", realmId)
+ .setParameter("realm", realm)
.setParameter("assetIds", assetIds)
.getSingleResult() == assetIds.size();
} catch (NoResultException ex) {
@@ -520,15 +520,15 @@ public class AssetStorageService extends RouteBuilder implements ContainerServic
}));
}
- public List<UserAsset> findUserAssets(String realmId, String userId, String assetId) {
+ public List<UserAsset> findUserAssets(String realm, String userId, String assetId) {
return persistenceService.doReturningTransaction(entityManager -> {
StringBuilder sb = new StringBuilder();
Map<String, Object> parameters = new HashMap<>(3);
sb.append("select ua from UserAsset ua where 1=1");
- if (!isNullOrEmpty(realmId)) {
- sb.append(" and ua.id.realmId = :realmId");
- parameters.put("realmId", realmId);
+ if (!isNullOrEmpty(realm)) {
+ sb.append(" and ua.id.realm = :realm");
+ parameters.put("realm", realm);
}
if (!isNullOrEmpty(userId)) {
sb.append(" and ua.id.userId = :userId");
@@ -559,9 +559,9 @@ public class AssetStorageService extends RouteBuilder implements ContainerServic
* This used to automatically unrestrict a user if no assets are linked to the them anymore but this has been
* disabled as it no longer fitted with use cases.
*/
- public void deleteUserAsset(String realmId, String userId, String assetId) {
+ public void deleteUserAsset(String realm, String userId, String assetId) {
persistenceService.doTransaction(entityManager -> {
- UserAsset userAsset = entityManager.find(UserAsset.class, new UserAsset.Id(realmId, userId, assetId));
+ UserAsset userAsset = entityManager.find(UserAsset.class, new UserAsset.Id(realm, userId, assetId));
if (userAsset != null)
entityManager.remove(userAsset);
});
@@ -679,7 +679,7 @@ public class AssetStorageService extends RouteBuilder implements ContainerServic
sb.append("select A.ID as ID, A.NAME as NAME, A.ACCESS_PUBLIC_READ as ACCESS_PUBLIC_READ");
sb.append(
- ", A.CREATED_ON AS CREATED_ON, A.ASSET_TYPE AS ASSET_TYPE, A.PARENT_ID AS PARENT_ID, A.REALM_ID AS REALM_ID");
+ ", A.CREATED_ON AS CREATED_ON, A.ASSET_TYPE AS ASSET_TYPE, A.PARENT_ID AS PARENT_ID, A.REALM AS REALM");
if (include == AssetQuery.Include.ONLY_ID_AND_NAME) {
return sb.toString();
@@ -691,7 +691,7 @@ public class AssetStorageService extends RouteBuilder implements ContainerServic
sb.append(", A.OBJ_VERSION as OBJ_VERSION");
sb.append(", P.NAME as PARENT_NAME, P.ASSET_TYPE as PARENT_TYPE");
if (!recursive || level == 3) {
- sb.append(", R.NAME as TENANT_NAME, RA.VALUE as TENANT_DISPLAY_NAME");
+ sb.append(", R.NAME as TENANT_NAME");
}
break;
}
@@ -802,8 +802,7 @@ public class AssetStorageService extends RouteBuilder implements ContainerServic
query.select.include != AssetQuery.Include.ONLY_ID_AND_NAME_AND_ATTRIBUTES;
if ((!recursive || level == 3) && (includeRealmInfo || query.tenant != null)) {
- sb.append("join PUBLIC.REALM R on R.ID = A.REALM_ID ");
- sb.append("join PUBLIC.REALM_ATTRIBUTE RA on RA.REALM_ID = R.ID and RA.NAME = 'displayName' ");
+ sb.append("join PUBLIC.REALM R on R.NAME = A.REALM ");
}
if ((!recursive || level == 3) && query.ids == null && query.userId != null) {
@@ -844,8 +843,8 @@ public class AssetStorageService extends RouteBuilder implements ContainerServic
case PARENT_ID:
sb.append(" A.PARENT_ID ");
break;
- case REALM_ID:
- sb.append(" A.REALM_ID ");
+ case REALM:
+ sb.append(" A.REALM ");
break;
}
sb.append(query.orderBy.descending ? "desc " : "asc ");
@@ -926,11 +925,7 @@ public class AssetStorageService extends RouteBuilder implements ContainerServic
}
if (!recursive || level == 3) {
- if (query.tenant != null && query.tenant.realmId != null) {
- sb.append(" and R.ID = ?");
- final int pos = binders.size() + 1;
- binders.add(st -> st.setString(pos, query.tenant.realmId));
- } else if (query.tenant != null && query.tenant.realm != null) {
+ if (query.tenant != null && !TextUtil.isNullOrEmpty(query.tenant.realm)) {
sb.append(" and R.NAME = ?");
final int pos = binders.size() + 1;
binders.add(st -> st.setString(pos, query.tenant.realm));
@@ -1248,7 +1243,7 @@ public class AssetStorageService extends RouteBuilder implements ContainerServic
rs.getString("ID"), rs.getLong("OBJ_VERSION"), rs.getTimestamp("CREATED_ON"), rs.getString("NAME"),
rs.getString("ASSET_TYPE"), rs.getBoolean("ACCESS_PUBLIC_READ"),
rs.getString("PARENT_ID"), rs.getString("PARENT_NAME"), rs.getString("PARENT_TYPE"),
- rs.getString("REALM_ID"), rs.getString("TENANT_NAME"), rs.getString("TENANT_DISPLAY_NAME"),
+ rs.getString("REALM"),
path != null ? (String[]) path.getArray() : null,
attributes != null && attributes.length() > 0 ? Values.instance().<ObjectValue>parse(attributes).orElse(
null)
@@ -1316,20 +1311,20 @@ public class AssetStorageService extends RouteBuilder implements ContainerServic
switch (persistenceEvent.getCause()) {
case INSERT:
clientEventService.publishEvent(
- new AssetTreeModifiedEvent(timerService.getCurrentTimeMillis(), asset.getRealmId(), asset.getId())
+ new AssetTreeModifiedEvent(timerService.getCurrentTimeMillis(), asset.getRealm(), asset.getId())
);
if (asset.getParentId() != null) {
// Child asset created
clientEventService.publishEvent(
new AssetTreeModifiedEvent(timerService.getCurrentTimeMillis(),
- asset.getRealmId(),
+ asset.getRealm(),
asset.getParentId(),
true)
);
} else {
// Child asset created (root asset)
clientEventService.publishEvent(
- new AssetTreeModifiedEvent(timerService.getCurrentTimeMillis(), asset.getRealmId(), true)
+ new AssetTreeModifiedEvent(timerService.getCurrentTimeMillis(), asset.getRealm(), true)
);
}
break;
@@ -1341,7 +1336,7 @@ public class AssetStorageService extends RouteBuilder implements ContainerServic
if (!Objects.equals(previousName, currentName)) {
clientEventService.publishEvent(
new AssetTreeModifiedEvent(timerService.getCurrentTimeMillis(),
- asset.getRealmId(),
+ asset.getRealm(),
asset.getId())
);
break;
@@ -1353,19 +1348,19 @@ public class AssetStorageService extends RouteBuilder implements ContainerServic
if (!Objects.equals(previousParentId, currentParentId)) {
clientEventService.publishEvent(
new AssetTreeModifiedEvent(timerService.getCurrentTimeMillis(),
- asset.getRealmId(),
+ asset.getRealm(),
asset.getId())
);
break;
}
// Did the realm change?
- String previousRealmId = persistenceEvent.getPreviousState("realmId");
- String currentRealmId = persistenceEvent.getCurrentState("realmId");
- if (!Objects.equals(previousRealmId, currentRealmId)) {
+ String previousRealm = persistenceEvent.getPreviousState("realm");
+ String currentRealm = persistenceEvent.getCurrentState("realm");
+ if (!Objects.equals(previousRealm, currentRealm)) {
clientEventService.publishEvent(
new AssetTreeModifiedEvent(timerService.getCurrentTimeMillis(),
- asset.getRealmId(),
+ asset.getRealm(),
asset.getId())
);
break;
@@ -1395,7 +1390,7 @@ public class AssetStorageService extends RouteBuilder implements ContainerServic
break;
case DELETE:
clientEventService.publishEvent(
- new AssetTreeModifiedEvent(timerService.getCurrentTimeMillis(), asset.getRealmId(), asset.getId())
+ new AssetTreeModifiedEvent(timerService.getCurrentTimeMillis(), asset.getRealm(), asset.getId())
);
break;
}
diff --git a/manager/src/main/java/org/openremote/manager/asset/console/ConsoleResourceImpl.java b/manager/src/main/java/org/openremote/manager/asset/console/ConsoleResourceImpl.java
index aa47d1028..8c1df038c 100644
--- a/manager/src/main/java/org/openremote/manager/asset/console/ConsoleResourceImpl.java
+++ b/manager/src/main/java/org/openremote/manager/asset/console/ConsoleResourceImpl.java
@@ -36,15 +36,12 @@ import org.openremote.model.security.Tenant;
import org.openremote.model.util.TextUtil;
import javax.ws.rs.BadRequestException;
-import javax.ws.rs.ForbiddenException;
-import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Response;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import static javax.ws.rs.core.Response.Status.FORBIDDEN;
import static org.openremote.container.concurrent.GlobalLock.withLockReturning;
public class ConsoleResourceImpl extends ManagerWebResource implements ConsoleResource {
@@ -60,6 +57,11 @@ public class ConsoleResourceImpl extends ManagerWebResource implements ConsoleRe
@Override
public ConsoleRegistration register(RequestParams requestParams, ConsoleRegistration consoleRegistration) {
+
+ if (getRequestTenant() == null) {
+ throw new BadRequestException("Invalid realm");
+ }
+
// Validate the console registration
List<ValidationFailure> failures = new ArrayList<>();
if (!ConsoleConfiguration.validateConsoleRegistration(consoleRegistration, failures)) {
@@ -83,7 +85,7 @@ public class ConsoleResourceImpl extends ManagerWebResource implements ConsoleRe
true,
true);
- consoleAsset.setRealmId(getRequestTenant().getId());
+ consoleAsset.setRealm(getRequestRealm());
consoleAsset.setParentId(getConsoleParentAssetId(getRequestRealm()));
consoleAsset.setId(consoleRegistration.getId());
} else {
@@ -103,7 +105,7 @@ public class ConsoleResourceImpl extends ManagerWebResource implements ConsoleRe
// If authenticated link the console to this user
if (isAuthenticated()) {
- assetStorageService.storeUserAsset(new UserAsset(getAuthenticatedTenant().getId(), getUserId(), consoleAsset.getId()));
+ assetStorageService.storeUserAsset(new UserAsset(getAuthenticatedRealm(), getUserId(), consoleAsset.getId()));
}
return consoleRegistration;
@@ -129,7 +131,7 @@ public class ConsoleResourceImpl extends ManagerWebResource implements ConsoleRe
if (consoleParent == null) {
consoleParent = new Asset(CONSOLE_PARENT_ASSET_NAME, AssetType.THING);
consoleParent.setId(id);
- consoleParent.setRealmId(tenant.getId());
+ consoleParent.setRealm(tenant.getRealm());
assetStorageService.merge(consoleParent);
}
return consoleParent;
diff --git a/manager/src/main/java/org/openremote/manager/notification/NotificationResourceImpl.java b/manager/src/main/java/org/openremote/manager/notification/NotificationResourceImpl.java
index 3087df016..29fea0c50 100644
--- a/manager/src/main/java/org/openremote/manager/notification/NotificationResourceImpl.java
+++ b/manager/src/main/java/org/openremote/manager/notification/NotificationResourceImpl.java
@@ -214,7 +214,7 @@ public class NotificationResourceImpl extends WebResource implements Notificatio
LOG.fine("DENIED: User request to update a notification sent to an asset that doesn't exist");
throw new WebApplicationException("Asset not found", NOT_FOUND);
}
- if (!asset.getRealmId().equals(managerIdentityService.getIdentityProvider().getTenantForRealm(getAuthenticatedRealm()).getId())) {
+ if (!asset.getRealm().equals(getAuthenticatedRealm())) {
LOG.fine("DENIED: User request to update a notification sent to an asset that is in another realm");
throw new WebApplicationException("Asset not in users realm", FORBIDDEN);
}
diff --git a/manager/src/main/java/org/openremote/manager/notification/NotificationService.java b/manager/src/main/java/org/openremote/manager/notification/NotificationService.java
index c3cea06aa..3781fa084 100644
--- a/manager/src/main/java/org/openremote/manager/notification/NotificationService.java
+++ b/manager/src/main/java/org/openremote/manager/notification/NotificationService.java
@@ -30,7 +30,6 @@ import org.openremote.container.message.MessageBrokerSetupService;
import org.openremote.container.persistence.PersistenceService;
import org.openremote.container.security.AuthContext;
import org.openremote.container.timer.TimerService;
-import org.openremote.container.web.WebService;
import org.openremote.manager.asset.AssetStorageService;
import org.openremote.manager.security.ManagerIdentityService;
import org.openremote.manager.web.ManagerWebService;
@@ -47,8 +46,6 @@ import javax.persistence.Query;
import javax.persistence.TypedQuery;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
-import java.time.temporal.TemporalField;
-import java.time.temporal.WeekFields;
import java.util.*;
import java.util.concurrent.atomic.AtomicReference;
import java.util.logging.Level;
@@ -180,7 +177,7 @@ public class NotificationService extends RouteBuilder implements ContainerServic
}
// Validate access and map targets to handler compatible targets
- String realmId = null;
+ String realm = null;
String userId = null;
String assetId = null;
AtomicReference<String> sourceId = new AtomicReference<>();
@@ -200,7 +197,7 @@ public class NotificationService extends RouteBuilder implements ContainerServic
throw new NotificationProcessingException(INSUFFICIENT_ACCESS);
}
- realmId = identityService.getIdentityProvider().getTenantForRealm(authContext.getAuthenticatedRealm()).getId();
+ realm = authContext.getAuthenticatedRealm();
userId = authContext.getUserId();
sourceId.set(userId);
isSuperUser = authContext.isSuperUser();
@@ -212,22 +209,22 @@ public class NotificationService extends RouteBuilder implements ContainerServic
break;
case TENANT_RULESET:
- realmId = exchange.getIn().getHeader(Notification.HEADER_SOURCE_ID, String.class);
- sourceId.set(realmId);
+ realm = exchange.getIn().getHeader(Notification.HEADER_SOURCE_ID, String.class);
+ sourceId.set(realm);
break;
case ASSET_RULESET:
assetId = exchange.getIn().getHeader(Notification.HEADER_SOURCE_ID, String.class);
sourceId.set(assetId);
Asset asset = assetStorageService.find(assetId, false);
- realmId = asset.getRealmId();
+ realm = asset.getRealm();
break;
}
LOG.info("Sending " + notification.getMessage().getType() + " notification '" + notification.getName() + "': '" + source + ":" + sourceId.get() + "' -> " + notification.getTargets());
// Check access permissions
- checkAccess(source, sourceId.get(), notification.getTargets(), realmId, userId, isSuperUser, isRestrictedUser, assetId);
+ checkAccess(source, sourceId.get(), notification.getTargets(), realm, userId, isSuperUser, isRestrictedUser, assetId);
// Map targets to handler compatible targets
List<Notification.Targets> mappedTargetsList = Arrays.stream(notification.getTargets().getIds())
@@ -522,7 +519,7 @@ public class NotificationService extends RouteBuilder implements ContainerServic
}
@SuppressWarnings("unchecked")
- protected void checkAccess(Notification.Source source, String sourceId, Notification.Targets targets, String realmId, String userId, boolean isSuperUser, boolean isRestrictedUser, String assetId) throws NotificationProcessingException {
+ protected void checkAccess(Notification.Source source, String sourceId, Notification.Targets targets, String realm, String userId, boolean isSuperUser, boolean isRestrictedUser, String assetId) throws NotificationProcessingException {
if (isSuperUser) {
return;
@@ -535,7 +532,7 @@ public class NotificationService extends RouteBuilder implements ContainerServic
throw new NotificationProcessingException(INSUFFICIENT_ACCESS);
}
case USER:
- if (TextUtil.isNullOrEmpty(realmId) || isRestrictedUser) {
+ if (TextUtil.isNullOrEmpty(realm) || isRestrictedUser) {
throw new NotificationProcessingException(INSUFFICIENT_ACCESS);
}
@@ -544,10 +541,10 @@ public class NotificationService extends RouteBuilder implements ContainerServic
if (targets.getType() == Notification.TargetType.USER) {
realmMatch = Arrays.stream(identityService.getIdentityProvider().getUsers(Arrays.asList(targets.getIds())))
- .allMatch(user -> realmId.equals(user.getRealmId()));
+ .allMatch(user -> realm.equals(user.getRealm()));
} else {
// Can only send to the same realm as the requestor realm
- realmMatch = targets.getIds().length == 1 && realmId.equals(targets.getIds()[0]);
+ realmMatch = targets.getIds().length == 1 && realm.equals(targets.getIds()[0]);
}
if (!realmMatch) {
@@ -556,7 +553,7 @@ public class NotificationService extends RouteBuilder implements ContainerServic
break;
case ASSET:
- if (TextUtil.isNullOrEmpty(realmId)) {
+ if (TextUtil.isNullOrEmpty(realm)) {
throw new NotificationProcessingException(INSUFFICIENT_ACCESS);
}
@@ -566,7 +563,7 @@ public class NotificationService extends RouteBuilder implements ContainerServic
}
// Target assets must be in the same realm as requestor
- if (!assetStorageService.isRealmAssets(realmId, Arrays.asList(targets.getIds()))) {
+ if (!assetStorageService.isRealmAssets(realm, Arrays.asList(targets.getIds()))) {
throw new NotificationProcessingException(INSUFFICIENT_ACCESS, "Targets must all be in the same realm as the requestor");
}
diff --git a/manager/src/main/java/org/openremote/manager/rules/AssetQueryPredicate.java b/manager/src/main/java/org/openremote/manager/rules/AssetQueryPredicate.java
index 3b303e51d..bcccc893d 100644
--- a/manager/src/main/java/org/openremote/manager/rules/AssetQueryPredicate.java
+++ b/manager/src/main/java/org/openremote/manager/rules/AssetQueryPredicate.java
@@ -279,8 +279,7 @@ public class AssetQueryPredicate implements Predicate<AssetState> {
public static Predicate<AssetState> asPredicate(TenantPredicate predicate) {
return assetState ->
- (predicate.realm == null || predicate.realm.equals(assetState.getTenantRealm()))
- && (predicate.realmId == null || predicate.realmId.equals(assetState.getRealmId()));
+ predicate == null || (predicate.realm != null && predicate.realm.equals(assetState.getRealm()));
}
public static Predicate<Coordinate> asPredicate(GeofencePredicate predicate) {
diff --git a/manager/src/main/java/org/openremote/manager/rules/RulesEngine.java b/manager/src/main/java/org/openremote/manager/rules/RulesEngine.java
index b674fba71..a3bf8dec0 100644
--- a/manager/src/main/java/org/openremote/manager/rules/RulesEngine.java
+++ b/manager/src/main/java/org/openremote/manager/rules/RulesEngine.java
@@ -530,7 +530,7 @@ public class RulesEngine<T extends Ruleset> {
protected void publishRulesEngineStatus() {
withLock(getClass().getSimpleName() + "::publishRulesEngineStatus", () -> {
- String engineId = id == null ? null : id.getRealmId().orElse(id.getAssetId().orElse(null));
+ String engineId = id == null ? null : id.getRealm().orElse(id.getAssetId().orElse(null));
int compilationErrors = getCompilationErrorDeploymentCount();
int executionErrors = getExecutionErrorDeploymentCount();
RulesEngineInfo engineInfo = new RulesEngineInfo(
@@ -554,7 +554,7 @@ public class RulesEngine<T extends Ruleset> {
protected void publishRulesetStatus(Ruleset ruleset, RulesetStatus status, String error) {
withLock(getClass().getSimpleName() + "::publishRulesetStatus", () -> {
- String engineId = id == null ? null : id.getRealmId().orElse(id.getAssetId().orElse(null));
+ String engineId = id == null ? null : id.getRealm().orElse(id.getAssetId().orElse(null));
ruleset.setStatus(status);
ruleset.setError(error);
diff --git a/manager/src/main/java/org/openremote/manager/rules/RulesEngineId.java b/manager/src/main/java/org/openremote/manager/rules/RulesEngineId.java
index a5f9a969c..d47374d6c 100644
--- a/manager/src/main/java/org/openremote/manager/rules/RulesEngineId.java
+++ b/manager/src/main/java/org/openremote/manager/rules/RulesEngineId.java
@@ -30,14 +30,14 @@ import java.util.Optional;
/**
* The scope of a {@link RulesEngine} and, optional, the tenant or asset it belongs to.
*
- * An engine in {@link org.openremote.model.rules.GlobalRuleset} scope has no {@link #realmId}
+ * An engine in {@link org.openremote.model.rules.GlobalRuleset} scope has no {@link #realm}
* or {@link #assetId}. An engine {@link org.openremote.model.rules.TenantRuleset} scope has only
- * {@link #realmId}. An engine in {@link org.openremote.model.rules.AssetRuleset} scope has both.
+ * {@link #realm}. An engine in {@link org.openremote.model.rules.AssetRuleset} scope has both.
*/
public class RulesEngineId<T extends Ruleset> {
final protected Class<T> scope;
- final protected String realmId;
+ final protected String realm;
final protected String assetId;
@SuppressWarnings("unchecked")
@@ -46,18 +46,18 @@ public class RulesEngineId<T extends Ruleset> {
}
@SuppressWarnings("unchecked")
- public RulesEngineId(String realmId) {
- this((Class<T>) TenantRuleset.class, realmId, null);
+ public RulesEngineId(String realm) {
+ this((Class<T>) TenantRuleset.class, realm, null);
}
@SuppressWarnings("unchecked")
- public RulesEngineId(String realmId, String assetId) {
- this((Class<T>) AssetRuleset.class, realmId, assetId);
+ public RulesEngineId(String realm, String assetId) {
+ this((Class<T>) AssetRuleset.class, realm, assetId);
}
- protected RulesEngineId(Class<T> scope, String realmId, String assetId) {
+ protected RulesEngineId(Class<T> scope, String realm, String assetId) {
this.scope = scope;
- this.realmId = realmId;
+ this.realm = realm;
this.assetId = assetId;
}
@@ -65,8 +65,8 @@ public class RulesEngineId<T extends Ruleset> {
return scope;
}
- public Optional<String> getRealmId() {
- return Optional.ofNullable(realmId);
+ public Optional<String> getRealm() {
+ return Optional.ofNullable(realm);
}
public Optional<String> getAssetId() {
@@ -79,21 +79,21 @@ public class RulesEngineId<T extends Ruleset> {
if (o == null || getClass() != o.getClass()) return false;
RulesEngineId that = (RulesEngineId) o;
return scope == that.scope &&
- Objects.equals(realmId, that.realmId) &&
+ Objects.equals(realm, that.realm) &&
Objects.equals(assetId, that.assetId);
}
@Override
public int hashCode() {
- return Objects.hash(scope, realmId, assetId);
+ return Objects.hash(scope, realm, assetId);
}
@Override
public String toString() {
return getClass().getSimpleName() + "{" +
"scope=" + scope.getSimpleName() +
- ", realmId='" + realmId + '\'' +
+ ", realm='" + realm + '\'' +
", assetId='" + assetId + '\'' +
'}';
}
diff --git a/manager/src/main/java/org/openremote/manager/rules/RulesFacts.java b/manager/src/main/java/org/openremote/manager/rules/RulesFacts.java
index bbeb8553e..174dc1cf4 100644
--- a/manager/src/main/java/org/openremote/manager/rules/RulesFacts.java
+++ b/manager/src/main/java/org/openremote/manager/rules/RulesFacts.java
@@ -31,7 +31,6 @@ import org.openremote.model.query.BaseAssetQuery;
import org.openremote.model.query.NewAssetQuery;
import org.openremote.model.query.filter.AttributePredicate;
import org.openremote.model.query.filter.GeofencePredicate;
-import org.openremote.model.query.filter.NewAttributePredicate;
import org.openremote.model.rules.AssetState;
import org.openremote.model.rules.Assets;
import org.openremote.model.rules.TemporaryFact;
@@ -614,8 +613,8 @@ public class RulesFacts extends Facts implements RuleListener {
case PARENT_ID:
keyExtractor = AssetState::getParentId;
break;
- case REALM_ID:
- keyExtractor = AssetState::getRealmId;
+ case REALM:
+ keyExtractor = AssetState::getRealm;
break;
}
diff --git a/manager/src/main/java/org/openremote/manager/rules/RulesHealthStatusProvider.java b/manager/src/main/java/org/openremote/manager/rules/RulesHealthStatusProvider.java
index 2fcf62872..391f382b0 100644
--- a/manager/src/main/java/org/openremote/manager/rules/RulesHealthStatusProvider.java
+++ b/manager/src/main/java/org/openremote/manager/rules/RulesHealthStatusProvider.java
@@ -91,7 +91,7 @@ public class RulesHealthStatusProvider implements ContainerHealthStatusProvider
errorEngines++;
}
- tenantEngines.put(tenantEngine.getId().getRealmId().orElse(""), getEngineHealthStatus(tenantEngine));
+ tenantEngines.put(tenantEngine.getId().getRealm().orElse(""), getEngineHealthStatus(tenantEngine));
}
ObjectValue assetEngines = Values.createObject();
diff --git a/manager/src/main/java/org/openremote/manager/rules/RulesResourceImpl.java b/manager/src/main/java/org/openremote/manager/rules/RulesResourceImpl.java
index 4fd378f1a..d78f2f9ab 100644
--- a/manager/src/main/java/org/openremote/manager/rules/RulesResourceImpl.java
+++ b/manager/src/main/java/org/openremote/manager/rules/RulesResourceImpl.java
@@ -72,12 +72,12 @@ public class RulesResourceImpl extends ManagerWebResource implements RulesResour
}
@Override
- public RulesEngineInfo getTenantEngineInfo(RequestParams requestParams, String realmId) {
- if (!isRealmAccessibleByUser(realmId) || isRestrictedUser()) {
+ public RulesEngineInfo getTenantEngineInfo(RequestParams requestParams, String realm) {
+ if (!isRealmAccessibleByUser(realm) || isRestrictedUser()) {
throw new WebApplicationException(Response.Status.FORBIDDEN);
}
- RulesEngine<TenantRuleset> engine = rulesService.tenantEngines.get(realmId);
+ RulesEngine<TenantRuleset> engine = rulesService.tenantEngines.get(realm);
return getEngineInfo(engine);
}
@@ -88,7 +88,7 @@ public class RulesResourceImpl extends ManagerWebResource implements RulesResour
if (asset == null)
return null;
- if (!isRealmAccessibleByUser(asset.getTenantRealm())) {
+ if (!isRealmAccessibleByUser(asset.getRealm())) {
throw new WebApplicationException(Response.Status.FORBIDDEN);
}
@@ -161,13 +161,13 @@ public class RulesResourceImpl extends ManagerWebResource implements RulesResour
if (asset == null)
return new AssetRuleset[0];
- if (!isRealmAccessibleByUser(asset.getTenantRealm())) {
+ if (!isRealmAccessibleByUser(asset.getRealm())) {
throw new WebApplicationException(Response.Status.FORBIDDEN);
}
if (isRestrictedUser() && !assetStorageService.isUserAsset(getUserId(), assetId)) {
throw new WebApplicationException(Response.Status.FORBIDDEN);
}
- List<AssetRuleset> result = rulesetStorageService.findAssetRulesets(asset.getRealmId(), assetId);
+ List<AssetRuleset> result = rulesetStorageService.findAssetRulesets(asset.getRealm(), assetId);
// Try and retrieve transient status and error data
result.forEach(ruleset ->
@@ -226,7 +226,7 @@ public class RulesResourceImpl extends ManagerWebResource implements RulesResour
@Override
public void createTenantRuleset(@BeanParam RequestParams requestParams, TenantRuleset ruleset) {
- Tenant tenant = identityService.getIdentityProvider().getTenantForRealmId(ruleset.getRealmId());
+ Tenant tenant = identityService.getIdentityProvider().getTenant(ruleset.getRealm());
if (tenant == null) {
throw new WebApplicationException(BAD_REQUEST);
}
@@ -243,7 +243,7 @@ public class RulesResourceImpl extends ManagerWebResource implements RulesResour
if (ruleset == null) {
throw new WebApplicationException(NOT_FOUND);
}
- Tenant tenant = identityService.getIdentityProvider().getTenantForRealmId(ruleset.getRealmId());
+ Tenant tenant = identityService.getIdentityProvider().getTenant(ruleset.getRealm());
if (tenant == null) {
throw new WebApplicationException(BAD_REQUEST);
}
@@ -260,7 +260,7 @@ public class RulesResourceImpl extends ManagerWebResource implements RulesResour
if (existingRuleset == null) {
throw new WebApplicationException(NOT_FOUND);
}
- Tenant tenant = identityService.getIdentityProvider().getTenantForRealmId(existingRuleset.getRealmId());
+ Tenant tenant = identityService.getIdentityProvider().getTenant(existingRuleset.getRealm());
if (tenant == null) {
throw new WebApplicationException(BAD_REQUEST);
}
@@ -271,7 +271,7 @@ public class RulesResourceImpl extends ManagerWebResource implements RulesResour
if (!id.equals(ruleset.getId())) {
throw new WebApplicationException("Requested ID and ruleset ID don't match", BAD_REQUEST);
}
- if (!existingRuleset.getRealmId().equals(ruleset.getRealmId())) {
+ if (!existingRuleset.getRealm().equals(ruleset.getRealm())) {
throw new WebApplicationException("Requested realm and existing ruleset realm must match", BAD_REQUEST);
}
rulesetStorageService.merge(ruleset);
@@ -283,7 +283,7 @@ public class RulesResourceImpl extends ManagerWebResource implements RulesResour
if (ruleset == null) {
return;
}
- Tenant tenant = identityService.getIdentityProvider().getTenantForRealmId(ruleset.getRealmId());
+ Tenant tenant = identityService.getIdentityProvider().getTenant(ruleset.getRealm());
if (tenant == null) {
throw new WebApplicationException(BAD_REQUEST);
}
@@ -305,7 +305,7 @@ public class RulesResourceImpl extends ManagerWebResource implements RulesResour
if (asset == null) {
throw new WebApplicationException(NOT_FOUND);
}
- if (!isRealmAccessibleByUser(asset.getTenantRealm())) {
+ if (!isRealmAccessibleByUser(asset.getRealm())) {
throw new WebApplicationException(Response.Status.FORBIDDEN);
}
if (isRestrictedUser() && !assetStorageService.isUserAsset(getUserId(), asset.getId())) {
@@ -324,7 +324,7 @@ public class RulesResourceImpl extends ManagerWebResource implements RulesResour
if (asset == null) {
throw new WebApplicationException(NOT_FOUND);
}
- if (!isRealmAccessibleByUser(asset.getTenantRealm())) {
+ if (!isRealmAccessibleByUser(asset.getRealm())) {
throw new WebApplicationException(Response.Status.FORBIDDEN);
}
if (isRestrictedUser() && !assetStorageService.isUserAsset(getUserId(), asset.getId())) {
@@ -343,7 +343,7 @@ public class RulesResourceImpl extends ManagerWebResource implements RulesResour
if (asset == null) {
throw new WebApplicationException(NOT_FOUND);
}
- if (!isRealmAccessibleByUser(asset.getTenantRealm())) {
+ if (!isRealmAccessibleByUser(asset.getRealm())) {
throw new WebApplicationException(Response.Status.FORBIDDEN);
}
if (isRestrictedUser() && !assetStorageService.isUserAsset(getUserId(), asset.getId())) {
@@ -369,7 +369,7 @@ public class RulesResourceImpl extends ManagerWebResource implements RulesResour
if (asset == null) {
throw new WebApplicationException(NOT_FOUND);
}
- if (!isRealmAccessibleByUser(asset.getTenantRealm())) {
+ if (!isRealmAccessibleByUser(asset.getRealm())) {
throw new WebApplicationException(Response.Status.FORBIDDEN);
}
if (isRestrictedUser() && !assetStorageService.isUserAsset(getUserId(), asset.getId())) {
@@ -394,7 +394,7 @@ public class RulesResourceImpl extends ManagerWebResource implements RulesResour
if (!asset.isAccessPublicRead()) {
// If asset is linked to users then only those users can get the geofences for it
- List<UserAsset> userAssetLinks = assetStorageService.findUserAssets(asset.getRealmId(), null, assetId);
+ List<UserAsset> userAssetLinks = assetStorageService.findUserAssets(asset.getRealm(), null, assetId);
if (!userAssetLinks.isEmpty()) {
if (!isAuthenticated() || userAssetLinks.stream().noneMatch(userAssetLink -> userAssetLink.getId().getUserId().equals(getUserId()))) {
diff --git a/manager/src/main/java/org/openremote/manager/rules/RulesService.java b/manager/src/main/java/org/openremote/manager/rules/RulesService.java
index c552e9283..edef1705f 100644
--- a/manager/src/main/java/org/openremote/manager/rules/RulesService.java
+++ b/manager/src/main/java/org/openremote/manager/rules/RulesService.java
@@ -53,7 +53,6 @@ import org.openremote.model.value.ObjectValue;
import javax.persistence.EntityManager;
import java.util.*;
-import java.util.function.BiConsumer;
import java.util.function.BiFunction;
import java.util.logging.Logger;
import java.util.stream.Collectors;
@@ -110,7 +109,7 @@ public class RulesService extends RouteBuilder implements ContainerService, Asse
protected AssetProcessingService assetProcessingService;
protected ClientEventService clientEventService;
protected RulesEngine<GlobalRuleset> globalEngine;
- protected String[] activeTenantIds;
+ protected Tenant[] tenants;
protected AssetLocationPredicateProcessor locationPredicateRulesConsumer;
protected Map<RulesEngine, List<RulesEngine.AssetStateLocationPredicates>> engineAssetLocationPredicateMap = new HashMap<>();
protected Set<String> assetsWithModifiedLocationPredicates = new HashSet<>();
@@ -210,9 +209,7 @@ public class RulesService extends RouteBuilder implements ContainerService, Asse
locationPredicateRulesConsumer = this::onEngineLocationRulesChanged;
for (GeofenceAssetAdapter geofenceAssetAdapter : geofenceAssetAdapters) {
- if (geofenceAssetAdapter instanceof ContainerService) {
- ((ContainerService) geofenceAssetAdapter).start(container);
- }
+ geofenceAssetAdapter.start(container);
}
}
@@ -220,12 +217,12 @@ public class RulesService extends RouteBuilder implements ContainerService, Asse
rulesetStorageService.findEnabledGlobalRulesets().forEach(this::deployGlobalRuleset);
LOG.info("Deploying tenant rulesets");
- activeTenantIds = identityService.getIdentityProvider().getActiveTenantIds();
+ tenants = identityService.getIdentityProvider().getTenants();
rulesetStorageService.findEnabledTenantRulesets()
.stream()
.filter(rd ->
- Arrays.stream(activeTenantIds)
- .anyMatch(tenantId -> rd.getRealmId().equals(tenantId))
+ Arrays.stream(tenants)
+ .anyMatch(tenant -> rd.getRealm().equals(tenant.getRealm()))
).forEach(this::deployTenantRuleset);
LOG.info("Deploying asset rulesets");
@@ -251,12 +248,10 @@ public class RulesService extends RouteBuilder implements ContainerService, Asse
public void stop(Container container) throws Exception {
withLock(getClass().getSimpleName() + "::stop", () -> {
for (GeofenceAssetAdapter geofenceAssetAdapter : geofenceAssetAdapters) {
- if (geofenceAssetAdapter instanceof ContainerService) {
- try {
- ((ContainerService) geofenceAssetAdapter).stop(container);
- } catch (Exception e) {
- LOG.log(SEVERE, "Exception thrown whilst stopping geofence adapter", e);
- }
+ try {
+ geofenceAssetAdapter.stop(container);
+ } catch (Exception e) {
+ LOG.log(SEVERE, "Exception thrown whilst stopping geofence adapter", e);
}
}
@@ -320,9 +315,9 @@ public class RulesService extends RouteBuilder implements ContainerService, Asse
protected void processTenantChange(Tenant tenant, PersistenceEvent.Cause cause) {
withLock(getClass().getSimpleName() + "::processTenantChange", () -> {
// Check if enabled status has changed
- boolean wasEnabled = Arrays.asList(activeTenantIds).contains(tenant.getId());
+ boolean wasEnabled = Arrays.stream(tenants).anyMatch(t -> tenant.getRealm().equals(t.getRealm()));
boolean isEnabled = tenant.getEnabled() && cause != PersistenceEvent.Cause.DELETE;
- activeTenantIds = identityService.getIdentityProvider().getActiveTenantIds();
+ tenants = identityService.getIdentityProvider().getTenants();
if (wasEnabled == isEnabled) {
// Nothing to do here
@@ -331,29 +326,29 @@ public class RulesService extends RouteBuilder implements ContainerService, Asse
if (wasEnabled) {
// Remove tenant rules engine for this tenant if it exists
- RulesEngine<TenantRuleset> tenantRulesEngine = tenantEngines.get(tenant.getId());
+ RulesEngine<TenantRuleset> tenantRulesEngine = tenantEngines.get(tenant.getRealm());
if (tenantRulesEngine != null) {
tenantRulesEngine.stop();
- tenantEngines.remove(tenant.getId());
+ tenantEngines.remove(tenant.getRealm());
}
// Remove any asset rules engines for assets in this realm
assetEngines.values().stream()
- .filter(re -> re.getId().getRealmId().map(id -> id.equals(tenant.getId())).orElse(false))
+ .filter(re -> re.getId().getRealm().map(id -> id.equals(tenant.getRealm())).orElse(false))
.forEach(RulesEngine::stop);
assetEngines.entrySet().removeIf(entry ->
- entry.getValue().getId().getRealmId().map(id -> id.equals(tenant.getId())).orElse(
+ entry.getValue().getId().getRealm().map(id -> id.equals(tenant.getRealm())).orElse(
false)
);
} else {
// Create tenant rules engines for this tenant if it has any rulesets
rulesetStorageService
- .findEnabledTenantRulesets(tenant.getId())
+ .findEnabledTenantRulesets(tenant.getRealm())
.forEach(this::deployTenantRuleset);
// Create any asset rules engines for assets in this realm that have rulesets
- deployAssetRulesets(rulesetStorageService.findEnabledAssetRulesets(tenant.getId()));
+ deployAssetRulesets(rulesetStorageService.findEnabledAssetRulesets(tenant.getRealm()));
}
});
}
@@ -479,7 +474,7 @@ public class RulesService extends RouteBuilder implements ContainerService, Asse
if (newEngine != null) {
// Push all existing facts into the engine, this is an initial import of state so fire delayed
assetStates.forEach(assetState -> {
- if (assetState.getRealmId().equals(((TenantRuleset) ruleset).getRealmId())) {
+ if (assetState.getRealm().equals(((TenantRuleset) ruleset).getRealm())) {
newEngine.updateFact(assetState, false);
}
});
@@ -549,7 +544,7 @@ public class RulesService extends RouteBuilder implements ContainerService, Asse
// Look for existing rules engines for this tenant
RulesEngine<TenantRuleset> tenentRulesEngine = tenantEngines
- .computeIfAbsent(ruleset.getRealmId(), (realmId) -> {
+ .computeIfAbsent(ruleset.getRealm(), (realm) -> {
created[0] = true;
return new RulesEngine<>(
timerService,
@@ -559,7 +554,7 @@ public class RulesService extends RouteBuilder implements ContainerService, Asse
assetProcessingService,
notificationService,
clientEventService,
- new RulesEngineId<>(realmId),
+ new RulesEngineId<>(realm),
locationPredicateRulesConsumer
);
});
@@ -572,13 +567,13 @@ public class RulesService extends RouteBuilder implements ContainerService, Asse
protected void undeployTenantRuleset(TenantRuleset ruleset) {
withLock(getClass().getSimpleName() + "::undeployTenantRuleset", () -> {
- RulesEngine<TenantRuleset> rulesEngine = tenantEngines.get(ruleset.getRealmId());
+ RulesEngine<TenantRuleset> rulesEngine = tenantEngines.get(ruleset.getRealm());
if (rulesEngine == null) {
return;
}
if (rulesEngine.removeRuleset(ruleset)) {
- tenantEngines.remove(ruleset.getRealmId());
+ tenantEngines.remove(ruleset.getRealm());
}
});
}
@@ -593,12 +588,12 @@ public class RulesService extends RouteBuilder implements ContainerService, Asse
new Pair<>(assetStorageService.find(es.getKey(), true), es.getValue())
)
.filter(assetAndRules -> assetAndRules.key != null)
- .collect(Collectors.groupingBy(assetAndRules -> assetAndRules.key.getRealmId()))
+ .collect(Collectors.groupingBy(assetAndRules -> assetAndRules.key.getRealm()))
.entrySet()
.stream()
.filter(es -> Arrays
- .stream(activeTenantIds)
- .anyMatch(at -> es.getKey().equals(at)))
+ .stream(tenants)
+ .anyMatch(at -> es.getKey().equals(at.getRealm())))
.forEach(es -> {
List<Pair<Asset, List<AssetRuleset>>> tenantAssetAndRules = es.getValue();
@@ -627,7 +622,7 @@ public class RulesService extends RouteBuilder implements ContainerService, Asse
assetProcessingService,
notificationService,
clientEventService,
- new RulesEngineId<>(ruleset.getRealmId(), assetId),
+ new RulesEngineId<>(ruleset.getRealm(), assetId),
locationPredicateRulesConsumer
);
});
@@ -653,7 +648,7 @@ public class RulesService extends RouteBuilder implements ContainerService, Asse
protected void insertAssetEvent(AssetState assetState, String expires) {
withLock(getClass().getSimpleName() + "::insertAssetEvent", () -> {
// Get the chain of rule engines that we need to pass through
- List<RulesEngine> rulesEngines = getEnginesInScope(assetState.getRealmId(), assetState.getPath());
+ List<RulesEngine> rulesEngines = getEnginesInScope(assetState.getRealm(), assetState.getPath());
// Check that all engines in the scope are available
if (rulesEngines.stream().anyMatch(RulesEngine::isError)) {
@@ -682,7 +677,7 @@ public class RulesService extends RouteBuilder implements ContainerService, Asse
LOG.fine("Updating asset state: " + assetState);
// Get the chain of rule engines that we need to pass through
- List<RulesEngine> rulesEngines = getEnginesInScope(assetState.getRealmId(), assetState.getPath());
+ List<RulesEngine> rulesEngines = getEnginesInScope(assetState.getRealm(), assetState.getPath());
if (!skipStatusCheck) {
// Check that all engines in the scope are available
@@ -707,7 +702,7 @@ public class RulesService extends RouteBuilder implements ContainerService, Asse
protected void retractAssetState(AssetState assetState) {
// Get the chain of rule engines that we need to pass through
- List<RulesEngine> rulesEngines = getEnginesInScope(assetState.getRealmId(), assetState.getPath());
+ List<RulesEngine> rulesEngines = getEnginesInScope(assetState.getRealm(), assetState.getPath());
// Remove asset state with same attribute ref
assetStates.remove(assetState);
@@ -729,7 +724,7 @@ public class RulesService extends RouteBuilder implements ContainerService, Asse
.collect(Collectors.toList());
}
- protected List<RulesEngine> getEnginesInScope(String realmId, String[] assetPath) {
+ protected List<RulesEngine> getEnginesInScope(String realm, String[] assetPath) {
List<RulesEngine> rulesEngines = new ArrayList<>();
// Add global engine (if it exists)
@@ -738,7 +733,7 @@ public class RulesService extends RouteBuilder implements ContainerService, Asse
}
// Add tenant engine (if it exists)
- RulesEngine tenantRulesEngine = tenantEngines.get(realmId);
+ RulesEngine tenantRulesEngine = tenantEngines.get(realm);
if (tenantRulesEngine != null) {
rulesEngines.add(tenantRulesEngine);
@@ -909,15 +904,15 @@ public class RulesService extends RouteBuilder implements ContainerService, Asse
}
}
- for (Map.Entry<String, RulesEngine<TenantRuleset>> realmIdAndEngine : tenantEngines.entrySet()) {
- if (realmIdAndEngine.getValue().deployments.containsKey(rulesetId)) {
- return Optional.of(realmIdAndEngine.getValue().deployments.get(rulesetId));
+ for (Map.Entry<String, RulesEngine<TenantRuleset>> realmAndEngine : tenantEngines.entrySet()) {
+ if (realmAndEngine.getValue().deployments.containsKey(rulesetId)) {
+ return Optional.of(realmAndEngine.getValue().deployments.get(rulesetId));
}
}
- for (Map.Entry<String, RulesEngine<AssetRuleset>> realmIdAndEngine : assetEngines.entrySet()) {
- if (realmIdAndEngine.getValue().deployments.containsKey(rulesetId)) {
- return Optional.of(realmIdAndEngine.getValue().deployments.get(rulesetId));
+ for (Map.Entry<String, RulesEngine<AssetRuleset>> realmAndEngine : assetEngines.entrySet()) {
+ if (realmAndEngine.getValue().deployments.containsKey(rulesetId)) {
+ return Optional.of(realmAndEngine.getValue().deployments.get(rulesetId));
}
}
diff --git a/manager/src/main/java/org/openremote/manager/rules/RulesetStorageService.java b/manager/src/main/java/org/openremote/manager/rules/RulesetStorageService.java
index f1f64fdbe..5526a9507 100644
--- a/manager/src/main/java/org/openremote/manager/rules/RulesetStorageService.java
+++ b/manager/src/main/java/org/openremote/manager/rules/RulesetStorageService.java
@@ -88,34 +88,34 @@ public class RulesetStorageService implements ContainerService {
/**
* The {@link Ruleset#rules} property is not populated for this query to avoid loading multiple large strings.
*/
- public List<TenantRuleset> findTenantRulesets(String realmId) {
+ public List<TenantRuleset> findTenantRulesets(String realm) {
return persistenceService.doReturningTransaction(entityManager ->
entityManager.createQuery(
"select new org.openremote.model.rules.TenantRuleset(" +
- "rs.id, rs.version, rs.createdOn, rs.lastModified, rs.name, rs.enabled, rs.realmId, rs.lang" +
+ "rs.id, rs.version, rs.createdOn, rs.lastModified, rs.name, rs.enabled, rs.realm, rs.lang" +
") " +
"from TenantRuleset rs " +
- "where rs.realmId = :realmId " +
+ "where rs.realm = :realm " +
"order by rs.createdOn asc",
TenantRuleset.class
- ).setParameter("realmId", realmId).getResultList()
+ ).setParameter("realm", realm).getResultList()
);
}
/**
* The {@link Ruleset#rules} property is not populated for this query to avoid loading multiple large strings.
*/
- public List<AssetRuleset> findAssetRulesets(String realmId, String assetId) {
+ public List<AssetRuleset> findAssetRulesets(String realm, String assetId) {
return persistenceService.doReturningTransaction(entityManager ->
entityManager.createQuery(
"select new org.openremote.model.rules.AssetRuleset(" +
"rs.id, rs.version, rs.createdOn, rs.lastModified, rs.name, rs.enabled, rs.assetId, rs.lang" +
") " +
"from AssetRuleset rs, Asset a " +
- "where rs.assetId = :assetId and rs.assetId = a.id and a.realmId = :realmId " +
+ "where rs.assetId = :assetId and rs.assetId = a.id and a.realm = :realm " +
"order by rs.createdOn asc",
AssetRuleset.class
- ).setParameter("realmId", realmId).setParameter("assetId",
+ ).setParameter("realm", realm).setParameter("assetId",
assetId).getResultList()
);
}
@@ -143,7 +143,7 @@ public class RulesetStorageService implements ContainerService {
return persistenceService.doReturningTransaction(entityManager ->
entityManager.createQuery(
"select new org.openremote.model.rules.TenantRuleset(" +
- "rs.id, rs.version, rs.createdOn, rs.lastModified, rs.name, rs.enabled, rs.rules, rs.lang, rs.realmId" +
+ "rs.id, rs.version, rs.createdOn, rs.lastModified, rs.name, rs.enabled, rs.rules, rs.lang, rs.realm" +
") " +
"from TenantRuleset rs " +
"where rs.enabled = true",
@@ -155,16 +155,16 @@ public class RulesetStorageService implements ContainerService {
/**
* @return Fully populated rulesets including {@link Ruleset#rules} property.
*/
- public List<TenantRuleset> findEnabledTenantRulesets(String realmId) {
+ public List<TenantRuleset> findEnabledTenantRulesets(String realm) {
return persistenceService.doReturningTransaction(entityManager ->
entityManager.createQuery(
"select new org.openremote.model.rules.TenantRuleset(" +
- "rs.id, rs.version, rs.createdOn, rs.lastModified, rs.name, rs.enabled, rs.rules, rs.lang, rs.realmId" +
+ "rs.id, rs.version, rs.createdOn, rs.lastModified, rs.name, rs.enabled, rs.rules, rs.lang, rs.realm" +
") " +
"from TenantRuleset rs " +
- "where rs.enabled = true and rs.realmId = :realmId",
+ "where rs.enabled = true and rs.realm = :realm",
TenantRuleset.class
- ).setParameter("realmId", realmId).getResultList()
+ ).setParameter("realm", realm).getResultList()
);
}
@@ -175,7 +175,7 @@ public class RulesetStorageService implements ContainerService {
return persistenceService.doReturningTransaction(entityManager ->
entityManager.createQuery(
"select new org.openremote.model.rules.AssetRuleset(" +
- "rs.id, rs.version, rs.createdOn, rs.lastModified, rs.name, rs.enabled, rs.rules, rs.lang, rs.assetId, a.realmId" +
+ "rs.id, rs.version, rs.createdOn, rs.lastModified, rs.name, rs.enabled, rs.rules, rs.lang, rs.assetId, a.realm" +
") " +
"from AssetRuleset rs, Asset a " +
"where rs.assetId = a.id " +
@@ -192,7 +192,7 @@ public class RulesetStorageService implements ContainerService {
return persistenceService.doReturningTransaction(entityManager -> {
List<AssetRuleset> result = entityManager.createQuery(
"select new org.openremote.model.rules.AssetRuleset(" +
- "rs.id, rs.version, rs.createdOn, rs.lastModified, rs.name, rs.enabled, rs.rules, rs.lang, rs.assetId, a.realmId" +
+ "rs.id, rs.version, rs.createdOn, rs.lastModified, rs.name, rs.enabled, rs.rules, rs.lang, rs.assetId, a.realm" +
") " +
"from AssetRuleset rs, Asset a " +
"where rs.assetId = a.id " +
@@ -208,17 +208,17 @@ public class RulesetStorageService implements ContainerService {
/**
* @return Fully populated rulesets including {@link Ruleset#rules} property.
*/
- public List<AssetRuleset> findEnabledAssetRulesets(String realmId) {
+ public List<AssetRuleset> findEnabledAssetRulesets(String realm) {
return persistenceService.doReturningTransaction(entityManager ->
entityManager.createQuery(
"select new org.openremote.model.rules.AssetRuleset(" +
- "rs.id, rs.version, rs.createdOn, rs.lastModified, rs.name, rs.enabled, rs.rules, rs.lang, rs.assetId, a.realmId" +
+ "rs.id, rs.version, rs.createdOn, rs.lastModified, rs.name, rs.enabled, rs.rules, rs.lang, rs.assetId, a.realm" +
") " +
"from AssetRuleset rs, Asset a " +
- "where rs.assetId = a.id and a.realmId = :realmId " +
+ "where rs.assetId = a.id and a.realm = :realm " +
"and rs.enabled = true",
AssetRuleset.class
- ).setParameter("realmId", realmId).getResultList()
+ ).setParameter("realm", realm).getResultList()
);
}
diff --git a/manager/src/main/java/org/openremote/manager/rules/facade/AssetsFacade.java b/manager/src/main/java/org/openremote/manager/rules/facade/AssetsFacade.java
index ce7a1caa6..c58f00331 100644
--- a/manager/src/main/java/org/openremote/manager/rules/facade/AssetsFacade.java
+++ b/manager/src/main/java/org/openremote/manager/rules/facade/AssetsFacade.java
@@ -49,7 +49,7 @@ public class AssetsFacade<T extends Ruleset> extends Assets {
public AssetsRestrictedQueryFacade() {
if (TenantRuleset.class.isAssignableFrom(rulesEngineId.getScope())) {
tenant = new TenantPredicate(
- rulesEngineId.getRealmId().orElseThrow(() -> new IllegalArgumentException("Realm ID missing: " + rulesEngineId))
+ rulesEngineId.getRealm().orElseThrow(() -> new IllegalArgumentException("Realm ID missing: " + rulesEngineId))
);
}
if (AssetRuleset.class.isAssignableFrom(rulesEngineId.getScope())) {
diff --git a/manager/src/main/java/org/openremote/manager/rules/facade/NotificationsFacade.java b/manager/src/main/java/org/openremote/manager/rules/facade/NotificationsFacade.java
index b7846484e..38d4c813d 100644
--- a/manager/src/main/java/org/openremote/manager/rules/facade/NotificationsFacade.java
+++ b/manager/src/main/java/org/openremote/manager/rules/facade/NotificationsFacade.java
@@ -27,8 +27,6 @@ import org.openremote.model.rules.Notifications;
import org.openremote.model.rules.Ruleset;
import org.openremote.model.rules.TenantRuleset;
-import java.util.function.Consumer;
-
import static org.openremote.model.notification.Notification.Source.ASSET_RULESET;
import static org.openremote.model.notification.Notification.Source.GLOBAL_RULESET;
import static org.openremote.model.notification.Notification.Source.TENANT_RULESET;
@@ -51,7 +49,7 @@ public class NotificationsFacade<T extends Ruleset> extends Notifications {
source = GLOBAL_RULESET;
} else if (rulesEngineId.getScope() == TenantRuleset.class) {
source = TENANT_RULESET;
- sourceId = rulesEngineId.getRealmId().orElseThrow(() -> new IllegalStateException("Tenant ruleset must have a realm ID"));
+ sourceId = rulesEngineId.getRealm().orElseThrow(() -> new IllegalStateException("Tenant ruleset must have a realm ID"));
} else {
source = ASSET_RULESET;
sourceId = rulesEngineId.getAssetId().orElseThrow(() -> new IllegalStateException("Asset ruleset must have an asset ID"));
diff --git a/manager/src/main/java/org/openremote/manager/rules/facade/UsersFacade.java b/manager/src/main/java/org/openremote/manager/rules/facade/UsersFacade.java
index f79bfdc6a..31f774446 100644
--- a/manager/src/main/java/org/openremote/manager/rules/facade/UsersFacade.java
+++ b/manager/src/main/java/org/openremote/manager/rules/facade/UsersFacade.java
@@ -60,7 +60,7 @@ public class UsersFacade<T extends Ruleset> extends Users {
if (TenantRuleset.class.isAssignableFrom(rulesEngineId.getScope())) {
// Restrict tenant
tenantPredicate = new TenantPredicate(
- rulesEngineId.getRealmId().orElseThrow(() -> new IllegalArgumentException("Realm ID missing: " + rulesEngineId))
+ rulesEngineId.getRealm().orElseThrow(() -> new IllegalArgumentException("Realm ID missing: " + rulesEngineId))
);
} else if (AssetRuleset.class.isAssignableFrom(rulesEngineId.getScope())) {
tenantPredicate = null;
@@ -71,8 +71,7 @@ public class UsersFacade<T extends Ruleset> extends Users {
if (assetId.equals(assetPredicate.id)) {
pathPredicate = null;
} else {
- pathPredicate = new PathPredicate(new String[]{rulesEngineId.getAssetId().orElseThrow(
- IllegalArgumentException::new)});
+ pathPredicate = new PathPredicate(rulesEngineId.getAssetId().orElseThrow(IllegalArgumentException::new));
}
} else if (pathPredicate != null) {
// Path must contain this engines asset ID
diff --git a/manager/src/main/java/org/openremote/manager/rules/geofence/ORConsoleGeofenceAssetAdapter.java b/manager/src/main/java/org/openremote/manager/rules/geofence/ORConsoleGeofenceAssetAdapter.java
index 634794f8d..6c6a4fe5d 100644
--- a/manager/src/main/java/org/openremote/manager/rules/geofence/ORConsoleGeofenceAssetAdapter.java
+++ b/manager/src/main/java/org/openremote/manager/rules/geofence/ORConsoleGeofenceAssetAdapter.java
@@ -21,8 +21,6 @@ package org.openremote.manager.rules.geofence;
import org.apache.camel.builder.RouteBuilder;
import org.openremote.container.Container;
-import org.openremote.container.ContainerService;
-import org.openremote.container.message.MessageBrokerService;
import org.openremote.container.message.MessageBrokerSetupService;
import org.openremote.container.persistence.PersistenceEvent;
import org.openremote.manager.asset.AssetStorageService;
@@ -114,7 +112,7 @@ public class ORConsoleGeofenceAssetAdapter extends RouteBuilder implements Geofe
new ObjectValueKeyPredicate("geofence")))
.stream()
.filter(ORConsoleGeofenceAssetAdapter::isLinkedToORConsoleGeofenceAdapter)
- .forEach(asset -> consoleIdRealmMap.put(asset.getId(), asset.getTenantRealm()));
+ .forEach(asset -> consoleIdRealmMap.put(asset.getId(), asset.getRealm()));
}
@Override
@@ -290,8 +288,7 @@ public class ORConsoleGeofenceAssetAdapter extends RouteBuilder implements Geofe
case UPDATE:
if (isLinkedToORConsoleGeofenceAdapter(asset)) {
- String realm = TextUtil.isNullOrEmpty(asset.getTenantRealm()) ? identityService.getIdentityProvider().getTenantForRealmId(asset.getRealmId()).getRealm() : asset.getTenantRealm();
- consoleIdRealmMap.put(asset.getId(), realm);
+ consoleIdRealmMap.put(asset.getId(), asset.getRealm());
} else {
consoleIdRealmMap.remove(asset.getId());
}
diff --git a/manager/src/main/java/org/openremote/manager/security/ManagerBasicIdentityProvider.java b/manager/src/main/java/org/openremote/manager/security/ManagerBasicIdentityProvider.java
index b739f9fef..38421c30a 100644
--- a/manager/src/main/java/org/openremote/manager/security/ManagerBasicIdentityProvider.java
+++ b/manager/src/main/java/org/openremote/manager/security/ManagerBasicIdentityProvider.java
@@ -113,25 +113,20 @@ public class ManagerBasicIdentityProvider extends BasicIdentityProvider implemen
}
@Override
- public boolean isUserInTenant(String userId, String realmId) {
+ public boolean isUserInTenant(String userId, String realm) {
return true;
}
@Override
- public Tenant[] getTenants(ClientRequestInfo clientRequestInfo) {
+ public Tenant[] getTenants() {
return new Tenant[]{masterTenant};
}
@Override
- public Tenant getTenantForRealm(String realm) {
+ public Tenant getTenant(String realm) {
return Objects.equals(realm, Constants.MASTER_REALM) ? masterTenant : null;
}
- @Override
- public Tenant getTenantForRealmId(String realmId) {
- return Objects.equals(realmId, Constants.MASTER_REALM) ? masterTenant : null;
- }
-
@Override
public void updateTenant(ClientRequestInfo clientRequestInfo, String realm, Tenant tenant) {
throw new UnsupportedOperationException("This provider does not support multiple tenants");
@@ -160,17 +155,12 @@ public class ManagerBasicIdentityProvider extends BasicIdentityProvider implemen
@Override
public boolean isTenantActiveAndAccessible(AuthContext authContext, Asset asset) {
- return Objects.equals(asset.getRealmId(), Constants.MASTER_REALM);
- }
-
- @Override
- public String[] getActiveTenantIds() {
- return new String[]{Constants.MASTER_REALM};
+ return Objects.equals(asset.getRealm(), Constants.MASTER_REALM);
}
@Override
- public boolean isActiveTenant(String realmId) {
- return Objects.equals(realmId, Constants.MASTER_REALM);
+ public boolean tenantExists(String realm) {
+ return Objects.equals(realm, Constants.MASTER_REALM);
}
@Override
diff --git a/manager/src/main/java/org/openremote/manager/security/ManagerIdentityProvider.java b/manager/src/main/java/org/openremote/manager/security/ManagerIdentityProvider.java
index 3532a3f71..f29373db2 100644
--- a/manager/src/main/java/org/openremote/manager/security/ManagerIdentityProvider.java
+++ b/manager/src/main/java/org/openremote/manager/security/ManagerIdentityProvider.java
@@ -61,13 +61,11 @@ public interface ManagerIdentityProvider extends IdentityProvider {
boolean isRestrictedUser(String userId);
- boolean isUserInTenant(String userId, String realmId);
+ boolean isUserInTenant(String userId, String realm);
- Tenant[] getTenants(ClientRequestInfo clientRequestInfo);
+ Tenant[] getTenants();
- Tenant getTenantForRealm(String realm);
-
- Tenant getTenantForRealmId(String realmId);
+ Tenant getTenant(String realm);
void updateTenant(ClientRequestInfo clientRequestInfo, String realm, Tenant tenant);
@@ -81,9 +79,7 @@ public interface ManagerIdentityProvider extends IdentityProvider {
boolean isTenantActiveAndAccessible(AuthContext authContext, Asset asset);
- String[] getActiveTenantIds();
-
- boolean isActiveTenant(String realmId);
+ boolean tenantExists(String realm);
/**
* Superusers can subscribe to all events, regular users must be in the same realm as the filter and any
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 537fa700a..7ffa9aede 100644
--- a/manager/src/main/java/org/openremote/manager/security/ManagerKeycloakIdentityProvider.java
+++ b/manager/src/main/java/org/openremote/manager/security/ManagerKeycloakIdentityProvider.java
@@ -159,15 +159,9 @@ public class ManagerKeycloakIdentityProvider extends KeycloakIdentityProvider im
sb.append(" WHERE 1=1");
- if (query.tenantPredicate != null) {
- if (!TextUtil.isNullOrEmpty(query.tenantPredicate.realmId)) {
- sb.append(" AND u.realmId = ?").append(parameters.size() + 1);
- parameters.add(query.tenantPredicate.realmId);
- } else if (!TextUtil.isNullOrEmpty(query.tenantPredicate.realm)) {
- sb.append(" AND u.realm = ?").append(parameters.size() + 1);
- parameters.add(query.tenantPredicate.realm);
- }
-
+ if (query.tenantPredicate != null && !TextUtil.isNullOrEmpty(query.tenantPredicate.realm)) {
+ sb.append(" AND u.realm = ?").append(parameters.size() + 1);
+ parameters.add(query.tenantPredicate.realm);
}
if (query.assetPredicate != null) {
sb.append(" AND ua.id.assetId = ?").append(parameters.size() + 1);
@@ -198,11 +192,11 @@ public class ManagerKeycloakIdentityProvider extends KeycloakIdentityProvider im
}
@Override
- public User getUser(String realmId, String userName) {
+ public User getUser(String realm, String userName) {
return persistenceService.doReturningTransaction(em -> {
List<User> result =
- em.createQuery("select u from User u where u.realmId = :realmId and u.username = :username", User.class)
- .setParameter("realmId", realmId)
+ em.createQuery("select u from User u where u.realm = :realm and u.username = :username", User.class)
+ .setParameter("realm", realm)
.setParameter("username", userName)
.getResultList();
return result.size() > 0 ? result.get(0) : null;
@@ -324,38 +318,34 @@ public class ManagerKeycloakIdentityProvider extends KeycloakIdentityProvider im
}
@Override
- public Tenant[] getTenants(ClientRequestInfo clientRequestInfo) {
- List<RealmRepresentation> realms = getRealms(clientRequestInfo).findAll();
-
- // Make sure the master tenant is always on top
- realms.sort((o1, o2) -> {
- if (o1.getRealm().equals(MASTER_REALM))
- return -1;
- if (o2.getRealm().equals(MASTER_REALM))
- return 1;
- return o1.getRealm().compareTo(o2.getRealm());
- });
-
- List<Tenant> tenants = new ArrayList<>();
- for (RealmRepresentation realm : realms) {
- tenants.add(convert(Container.JSON, Tenant.class, realm));
- }
- return tenants.toArray(new Tenant[tenants.size()]);
- }
+ public Tenant[] getTenants() {
- @Override
- public Tenant getTenantForRealm(String realm) {
- return persistenceService.doReturningTransaction(em -> {
- List<Tenant> result =
- em.createQuery("select t from Tenant t where t.realm = :realm", Tenant.class)
- .setParameter("realm", realm).getResultList();
- return result.size() > 0 ? result.get(0) : null;
+ return persistenceService.doReturningTransaction(entityManager -> {
+ List<Tenant> realms = entityManager.createQuery(
+ "select t from Tenant t where t.enabled = true and (t.notBefore is null or t.notBefore = 0 or to_timestamp(t.notBefore) <= now())"
+ , Tenant.class).getResultList();
+
+ // Make sure the master tenant is always on top
+ realms.sort((o1, o2) -> {
+ if (o1.getRealm().equals(MASTER_REALM))
+ return -1;
+ if (o2.getRealm().equals(MASTER_REALM))
+ return 1;
+ return o1.getRealm().compareTo(o2.getRealm());
+ });
+
+ return realms.toArray(new Tenant[realms.size()]);
});
}
@Override
- public Tenant getTenantForRealmId(String realmId) {
- return persistenceService.doReturningTransaction(em -> em.find(Tenant.class, realmId));
+ public Tenant getTenant(String realm) {
+ return persistenceService.doReturningTransaction(em -> {
+ List<Tenant> tenants = em.createQuery("select t from Tenant t where t.realm = :realm and t.enabled = true and (t.notBefore is null or t.notBefore = 0 or to_timestamp(t.notBefore) <= now())", Tenant.class)
+ .setParameter("realm", realm).getResultList();
+ return tenants.size() == 1 ? tenants.get(0) : null;
+ }
+ );
}
@Override
@@ -387,7 +377,7 @@ public class ManagerKeycloakIdentityProvider extends KeycloakIdentityProvider im
@Override
public void deleteTenant(ClientRequestInfo clientRequestInfo, String realm) {
- Tenant tenant = getTenantForRealm(realm);
+ Tenant tenant = getTenant(realm);
if (tenant != null) {
LOG.fine("Delete tenant: " + realm);
getRealms(clientRequestInfo).realm(realm).remove();
@@ -411,26 +401,18 @@ public class ManagerKeycloakIdentityProvider extends KeycloakIdentityProvider im
*/
@Override
public boolean isTenantActiveAndAccessible(AuthContext authContext, Asset asset) {
- return isTenantActiveAndAccessible(authContext, getTenantForRealmId(asset.getRealmId()));
- }
-
- @Override
- public String[] getActiveTenantIds() {
- return persistenceService.doReturningTransaction(entityManager -> {
- @SuppressWarnings("unchecked")
- List<String> results = entityManager.createQuery(
- "select t.id from Tenant t where " +
- "t.enabled = true and (t.notBefore is null or t.notBefore = 0 or to_timestamp(t.notBefore) <= now())"
- ).getResultList();
- return results.toArray(new String[results.size()]);
- });
+ return isTenantActiveAndAccessible(authContext, getTenant(asset.getRealm()));
}
@Override
- public boolean isActiveTenant(String realmId) {
+ public boolean tenantExists(String realm) {
return persistenceService.doReturningTransaction(em -> {
- Tenant tenant = em.find(Tenant.class, realmId);
- return tenant != null && tenant.isActive(timerService.getCurrentTimeMillis());
+
+ long count = em.createQuery(
+ "select count(t) from Tenant t where t.realm = :realm and t.enabled = true and (t.notBefore is null or t.notBefore = 0 or to_timestamp(t.notBefore) <= now())",
+ Long.class).setParameter("realm", realm).getSingleResult();
+
+ return count > 0;
});
}
@@ -441,10 +423,10 @@ public class ManagerKeycloakIdentityProvider extends KeycloakIdentityProvider im
}
@Override
- public boolean isUserInTenant(String userId, String realmId) {
+ public boolean isUserInTenant(String userId, String realm) {
return persistenceService.doReturningTransaction(em -> {
User user = em.find(User.class, userId);
- return (user != null && realmId.equals(user.getRealmId()));
+ return (user != null && realm.equals(user.getRealm()));
});
}
@@ -469,10 +451,11 @@ public class ManagerKeycloakIdentityProvider extends KeycloakIdentityProvider im
// Ensure filter matches authenticated realm
if (filter != null) {
- Tenant authenticatedTenant = getTenantForRealm(auth.getAuthenticatedRealm());
- if (authenticatedTenant == null)
+ String authenticatedRealm = auth.getAuthenticatedRealm();
+
+ if (TextUtil.isNullOrEmpty(authenticatedRealm))
return false;
- if (filter.getRealmId().equals(authenticatedTenant.getId()))
+ if (authenticatedRealm.equals(filter.getRealm()))
return true;
}
@@ -564,7 +547,7 @@ public class ManagerKeycloakIdentityProvider extends KeycloakIdentityProvider im
);
clientEventService.publishEvent(
- new AssetTreeModifiedEvent(timerService.getCurrentTimeMillis(), tenant.getId(), null)
+ new AssetTreeModifiedEvent(timerService.getCurrentTimeMillis(), tenant.getRealm(), null)
);
}
diff --git a/manager/src/main/java/org/openremote/manager/security/TenantResourceImpl.java b/manager/src/main/java/org/openremote/manager/security/TenantResourceImpl.java
index 58ca0da56..626d7828c 100644
--- a/manager/src/main/java/org/openremote/manager/security/TenantResourceImpl.java
+++ b/manager/src/main/java/org/openremote/manager/security/TenantResourceImpl.java
@@ -56,9 +56,7 @@ public class TenantResourceImpl extends ManagerWebResource implements TenantReso
throw new WebApplicationException(Response.Status.FORBIDDEN);
}
try {
- return identityService.getIdentityProvider().getTenants(
- new ClientRequestInfo(getClientRemoteAddress(), requestParams.getBearerAuth())
- );
+ return identityService.getIdentityProvider().getTenants();
} catch (ClientErrorException ex) {
throw new WebApplicationException(ex.getCause(), ex.getResponse().getStatus());
} catch (Exception ex) {
@@ -68,19 +66,7 @@ public class TenantResourceImpl extends ManagerWebResource implements TenantReso
@Override
public Tenant get(RequestParams requestParams, String realm) {
- Tenant tenant = identityService.getIdentityProvider().getTenantForRealm(realm);
- if (tenant == null)
- throw new WebApplicationException(NOT_FOUND);
- if (!isTenantActiveAndAccessible(tenant)) {
- LOG.fine("Forbidden access for user '" + getUsername() + "': " + tenant);
- throw new WebApplicationException(Response.Status.FORBIDDEN);
- }
- return tenant;
- }
-
- @Override
- public Tenant getForRealmId(RequestParams requestParams, String realmId) {
- Tenant tenant = identityService.getIdentityProvider().getTenantForRealmId(realmId);
+ Tenant tenant = identityService.getIdentityProvider().getTenant(realm);
if (tenant == null)
throw new WebApplicationException(NOT_FOUND);
if (!isTenantActiveAndAccessible(tenant)) {
diff --git a/manager/src/main/java/org/openremote/manager/setup/builtin/BasicIdentityDemoSetup.java b/manager/src/main/java/org/openremote/manager/setup/builtin/BasicIdentityDemoSetup.java
index 9ffa1fe3f..e69db5615 100644
--- a/manager/src/main/java/org/openremote/manager/setup/builtin/BasicIdentityDemoSetup.java
+++ b/manager/src/main/java/org/openremote/manager/setup/builtin/BasicIdentityDemoSetup.java
@@ -59,7 +59,7 @@ public class BasicIdentityDemoSetup implements Setup {
public void onStart() throws Exception {
// Tenants
- masterTenant = identityService.getIdentityProvider().getTenantForRealm(Constants.MASTER_REALM);
+ masterTenant = identityService.getIdentityProvider().getTenant(Constants.MASTER_REALM);
// Users
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 b89a23ab2..3c0ef500f 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
@@ -66,21 +66,21 @@ public class KeycloakDemoSetup extends AbstractKeycloakSetup {
super.onStart();
// Tenants
- masterTenant = identityService.getIdentityProvider().getTenantForRealm(Constants.MASTER_REALM);
+ masterTenant = identityService.getIdentityProvider().getTenant(Constants.MASTER_REALM);
tenantA = new Tenant();
tenantA.setRealm("tenantA");
tenantA.setDisplayName("Tenant A");
tenantA.setEnabled(true);
keycloakProvider.createTenant(new ClientRequestInfo(null, accessToken), tenantA, emailConfig);
- tenantA = keycloakProvider.getTenantForRealm(tenantA.getRealm());
+ tenantA = keycloakProvider.getTenant(tenantA.getRealm());
tenantB = new Tenant();
tenantB.setRealm("tenantB");
tenantB.setDisplayName("Tenant B");
tenantB.setEnabled(true);
keycloakProvider.createTenant(new ClientRequestInfo(null, accessToken), tenantB, emailConfig);
- tenantB = keycloakProvider.getTenantForRealm(tenantB.getRealm());
+ tenantB = keycloakProvider.getTenant(tenantB.getRealm());
// Users
diff --git a/manager/src/main/java/org/openremote/manager/setup/builtin/ManagerDemoAgentSetup.java b/manager/src/main/java/org/openremote/manager/setup/builtin/ManagerDemoAgentSetup.java
index 6fe9ed3cc..4467a7c4c 100644
--- a/manager/src/main/java/org/openremote/manager/setup/builtin/ManagerDemoAgentSetup.java
+++ b/manager/src/main/java/org/openremote/manager/setup/builtin/ManagerDemoAgentSetup.java
@@ -48,7 +48,7 @@ public class ManagerDemoAgentSetup extends AbstractManagerSetup {
public static final String SETUP_IMPORT_DEMO_AGENT_VELBUS = "SETUP_IMPORT_DEMO_AGENT_VELBUS";
public static final String SETUP_IMPORT_DEMO_AGENT_VELBUS_COM_PORT = "SETUP_IMPORT_DEMO_AGENT_VELBUS_COM_PORT";
- public String masterRealmId;
+ public String masterRealm;
final protected boolean knx;
final protected String knxGatewayIp;
@@ -73,10 +73,10 @@ public class ManagerDemoAgentSetup extends AbstractManagerSetup {
KeycloakDemoSetup keycloakDemoSetup = setupService.getTaskOfType(KeycloakDemoSetup.class);
Tenant masterTenant = keycloakDemoSetup.masterTenant;
- masterRealmId = masterTenant.getId();
+ masterRealm = masterTenant.getRealm();
Asset agent = new Asset("Demo Agent", AGENT);
- agent.setRealmId(masterRealmId);
+ agent.setRealm(masterRealm);
agent = assetStorageService.merge(agent);
if (knx) {
@@ -88,7 +88,7 @@ public class ManagerDemoAgentSetup extends AbstractManagerSetup {
new MetaItem(KNXProtocol.META_KNX_LOCAL_IP, Values.create(knxLocalIp))
)
);
- Asset knxDevices = new Asset("KNX Devices", THING, agent, masterRealmId);
+ Asset knxDevices = new Asset("KNX Devices", THING, agent, masterRealm);
knxDevices = assetStorageService.merge(knxDevices);
}
@@ -100,7 +100,7 @@ public class ManagerDemoAgentSetup extends AbstractManagerSetup {
new MetaItem(VelbusSerialProtocol.META_VELBUS_SERIAL_PORT, Values.create(velbusComPort))
)
);
- Asset velbusDevices = new Asset("VELBUS Devices", THING, agent, masterRealmId);
+ Asset velbusDevices = new Asset("VELBUS Devices", THING, agent, masterRealm);
velbusDevices = assetStorageService.merge(velbusDevices);
}
diff --git a/manager/src/main/java/org/openremote/manager/setup/builtin/ManagerDemoSetup.java b/manager/src/main/java/org/openremote/manager/setup/builtin/ManagerDemoSetup.java
index 9fbe4cb8d..196b1c5f2 100644
--- a/manager/src/main/java/org/openremote/manager/setup/builtin/ManagerDemoSetup.java
+++ b/manager/src/main/java/org/openremote/manager/setup/builtin/ManagerDemoSetup.java
@@ -86,9 +86,9 @@ public class ManagerDemoSetup extends AbstractManagerSetup {
public String apartment2LivingroomId;
public String apartment2BathroomId;
public String apartment3LivingroomId;
- public String masterRealmId;
- public String realmATenantId;
- public String realmBTenantId;
+ public String masterRealm;
+ public String realmATenant;
+ public String realmBTenant;
public String smartCityServiceAgentId;
@@ -105,16 +105,16 @@ public class ManagerDemoSetup extends AbstractManagerSetup {
Tenant masterTenant = keycloakDemoSetup.masterTenant;
Tenant realmATenant = keycloakDemoSetup.tenantA;
Tenant realmBTenant = keycloakDemoSetup.tenantB;
- masterRealmId = masterTenant.getId();
- realmATenantId = realmATenant.getId();
- realmBTenantId = realmBTenant.getId();
+ masterRealm = masterTenant.getRealm();
+ this.realmATenant = realmATenant.getRealm();
+ this.realmBTenant = realmBTenant.getRealm();
// ################################ Demo assets for 'master' realm ###################################
ObjectValue locationValue = SMART_OFFICE_LOCATION.toValue();
Asset smartOffice = new Asset();
- smartOffice.setRealmId(masterRealmId);
+ smartOffice.setRealm(masterRealm);
smartOffice.setName("Smart Office");
smartOffice.setType(BUILDING);
List<AssetAttribute> smartOfficeAttributes = Arrays.asList(
@@ -380,7 +380,7 @@ public class ManagerDemoSetup extends AbstractManagerSetup {
ObjectValue locationValueA = SMART_BUILDING_LOCATION.toValue();
Asset smartBuilding = new Asset();
- smartBuilding.setRealmId(realmATenantId);
+ smartBuilding.setRealm(this.realmATenant);
smartBuilding.setName("Smart Building");
smartBuilding.setType(BUILDING);
smartBuilding.addAttributes(
@@ -721,25 +721,25 @@ public class ManagerDemoSetup extends AbstractManagerSetup {
// ################################ Link demo users and assets ###################################
- assetStorageService.storeUserAsset(new UserAsset(keycloakDemoSetup.tenantA.getId(),
+ assetStorageService.storeUserAsset(new UserAsset(keycloakDemoSetup.tenantA.getRealm(),
keycloakDemoSetup.testuser3Id,
apartment1Id));
- assetStorageService.storeUserAsset(new UserAsset(keycloakDemoSetup.tenantA.getId(),
+ assetStorageService.storeUserAsset(new UserAsset(keycloakDemoSetup.tenantA.getRealm(),
keycloakDemoSetup.testuser3Id,
apartment1LivingroomId));
- assetStorageService.storeUserAsset(new UserAsset(keycloakDemoSetup.tenantA.getId(),
+ assetStorageService.storeUserAsset(new UserAsset(keycloakDemoSetup.tenantA.getRealm(),
keycloakDemoSetup.testuser3Id,
apartment1KitchenId));
- assetStorageService.storeUserAsset(new UserAsset(keycloakDemoSetup.tenantA.getId(),
+ assetStorageService.storeUserAsset(new UserAsset(keycloakDemoSetup.tenantA.getRealm(),
keycloakDemoSetup.testuser3Id,
apartment1Bedroom1Id));
- assetStorageService.storeUserAsset(new UserAsset(keycloakDemoSetup.tenantA.getId(),
+ assetStorageService.storeUserAsset(new UserAsset(keycloakDemoSetup.tenantA.getRealm(),
keycloakDemoSetup.testuser3Id,
apartment1BathroomId));
- assetStorageService.storeUserAsset(new UserAsset(keycloakDemoSetup.tenantA.getId(),
+ assetStorageService.storeUserAsset(new UserAsset(keycloakDemoSetup.tenantA.getRealm(),
keycloakDemoSetup.testuser3Id,
apartment1HallwayId));
-// assetStorageService.storeUserAsset(new UserAsset(keycloakDemoSetup.tenantA.getId(),
+// assetStorageService.storeUserAsset(new UserAsset(keycloakDemoSetup.tenantA.getRealm(),
// keycloakDemoSetup.testuser2Id,
// apartment2Id));
@@ -755,7 +755,7 @@ public class ManagerDemoSetup extends AbstractManagerSetup {
Asset smartCity = new Asset();
- smartCity.setRealmId(realmBTenantId);
+ smartCity.setRealm(this.realmBTenant);
smartCity.setName("Smart City");
smartCity.setType(BUILDING);
smartCity.addAttributes(
diff --git a/manager/src/main/java/org/openremote/manager/setup/builtin/RulesDemoSetup.java b/manager/src/main/java/org/openremote/manager/setup/builtin/RulesDemoSetup.java
index ff4bd4016..09f39c961 100644
--- a/manager/src/main/java/org/openremote/manager/setup/builtin/RulesDemoSetup.java
+++ b/manager/src/main/java/org/openremote/manager/setup/builtin/RulesDemoSetup.java
@@ -100,7 +100,7 @@ public class RulesDemoSetup extends AbstractManagerSetup {
try (InputStream inputStream = RulesDemoSetup.class.getResourceAsStream("/demo/rules/DemoConsoleLocation.groovy")) {
String rules = IOUtils.toString(inputStream, Charset.forName("utf-8"));
Ruleset ruleset = new TenantRuleset(
- "Demo Console Location", keycloakDemoSetup.tenantA.getId(), rules, Ruleset.Lang.GROOVY
+ "Demo Console Location", keycloakDemoSetup.tenantA.getRealm(), rules, Ruleset.Lang.GROOVY
);
tenantARulesetId = rulesetStorageService.merge(ruleset).getId();
}
diff --git a/manager/src/main/java/org/openremote/manager/web/ManagerWebResource.java b/manager/src/main/java/org/openremote/manager/web/ManagerWebResource.java
index 5fc675369..fbe521167 100644
--- a/manager/src/main/java/org/openremote/manager/web/ManagerWebResource.java
+++ b/manager/src/main/java/org/openremote/manager/web/ManagerWebResource.java
@@ -40,11 +40,11 @@ public class ManagerWebResource extends WebResource {
}
public Tenant getAuthenticatedTenant() {
- return identityService.getIdentityProvider().getTenantForRealm(getAuthenticatedRealm());
+ return identityService.getIdentityProvider().getTenant(getAuthenticatedRealm());
}
public Tenant getRequestTenant() {
- return identityService.getIdentityProvider().getTenantForRealm(getRequestRealm());
+ return identityService.getIdentityProvider().getTenant(getRequestRealm());
}
public boolean isTenantActiveAndAccessible(Asset asset) {
diff --git a/manager/src/main/resources/org/openremote/manager/setup/database/V20190228_03__RemovedRealmId.sql b/manager/src/main/resources/org/openremote/manager/setup/database/V20190228_03__RemovedRealmId.sql
new file mode 100644
index 000000000..0005a2bed
--- /dev/null
+++ b/manager/src/main/resources/org/openremote/manager/setup/database/V20190228_03__RemovedRealmId.sql
@@ -0,0 +1,67 @@
+
+/*
+ Removed use of REALM_ID and now just using REALM
+ */
+
+-- UPDATE ASSET TABLE
+
+ALTER TABLE ASSET
+ DROP CONSTRAINT asset_realm_id_fkey,
+ ADD COLUMN REALM VARCHAR(255);
+
+DO $$
+ begin
+ IF EXISTS(SELECT to_regclass('public.realm')) THEN
+ UPDATE openremote.ASSET A SET REALM = R.NAME FROM public.REALM R WHERE A.REALM_ID = R.id;
+ END IF;
+ end
+ $$;
+
+ALTER TABLE ASSET
+ ALTER COLUMN REALM SET NOT NULL,
+ add foreign key (REALM) references PUBLIC.REALM (NAME),
+ DROP COLUMN REALM_ID;
+
+
+-- UPDATE TENANT RULSET TABLE
+
+ALTER TABLE TENANT_RULESET
+ DROP CONSTRAINT tenant_ruleset_realm_id_fkey,
+ ADD COLUMN REALM VARCHAR(255);
+
+DO $$
+ begin
+ IF EXISTS(SELECT to_regclass('public.realm')) THEN
+ UPDATE openremote.TENANT_RULESET TR SET REALM = R.NAME FROM public.REALM R WHERE TR.REALM_ID = R.id;
+ END IF;
+ end
+ $$;
+
+ALTER TABLE TENANT_RULESET
+ ALTER COLUMN REALM SET NOT NULL,
+ add foreign key (REALM) references PUBLIC.REALM (NAME),
+ DROP COLUMN REALM_ID;
+
+
+-- UPDATE USER ASSET TABLE
+
+ALTER TABLE USER_ASSET
+ DROP CONSTRAINT user_asset_realm_id_fkey,
+ ADD COLUMN REALM VARCHAR(255);
+
+DO $$
+ begin
+ IF EXISTS(SELECT to_regclass('public.realm')) THEN
+ UPDATE openremote.USER_ASSET A SET REALM = R.NAME FROM public.REALM R WHERE A.REALM_ID = R.id;
+ END IF;
+ end
+ $$;
+
+ALTER TABLE USER_ASSET
+ ALTER COLUMN REALM SET NOT NULL,
+ add foreign key (REALM) references PUBLIC.REALM (NAME) on delete cascade,
+ DROP COLUMN REALM_ID;
+
+
+-- UPDATE NOTIFICATION TABLE
+UPDATE openremote.notification N SET target_id = R.NAME FROM public.REALM R WHERE target = 'TENANT' and N.target_id = R.id;
\ No newline at end of file
diff --git a/model/src/main/java/org/openremote/model/asset/Asset.java b/model/src/main/java/org/openremote/model/asset/Asset.java
index 4524e6f2f..2b63fd2b5 100644
--- a/model/src/main/java/org/openremote/model/asset/Asset.java
+++ b/model/src/main/java/org/openremote/model/asset/Asset.java
@@ -64,10 +64,7 @@ import static org.openremote.model.attribute.AttributeType.LOCATION;
* The properties {@link #parentName} and {@link #parentType} are transient, not required
* for storing assets, and only resolved and usable when the asset is loaded from storage.
* <p>
- * An asset is stored in and therefore access-controlled through a {@link #realmId}. The
- * transient properties {@link #tenantRealm} (the unique realm name of the realm
- * ID) and {@link #tenantDisplayName} are only resolved and usable when the asset is loaded
- * from storage and not relevant for storing assets.
+ * An asset is stored in and therefore access-controlled through a {@link #realm}.
* <p>
* The {@link #createdOn} value is milliseconds since the Unix epoch.
* <p>
@@ -97,9 +94,8 @@ import static org.openremote.model.attribute.AttributeType.LOCATION;
* "name": "Smart Building",
* "type": "urn:openremote:asset:building",
* "accessPublicRead": false,
- * "realmId": "c38a3fdf-9d74-4dac-940c-50d3dce1d248",
- * "tenantRealm": "tenantA",
- * "tenantDisplayName": "Tenant A",
+ * "realm": "tenantA",
+ * "realmDisplayName": "Tenant A",
* "path": [
* "0oI7Gf_kTh6WyRJFUTr8Lg"
* ],
@@ -120,7 +116,7 @@ import static org.openremote.model.attribute.AttributeType.LOCATION;
* "parentId": "0oI7Gf_kTh6WyRJFUTr8Lg",
* "parentName": "Smart Building",
* "parentType": "urn:openremote:asset:building",
- * "realmId": "c38a3fdf-9d74-4dac-940c-50d3dce1d248",
+ * "realm": "c38a3fdf-9d74-4dac-940c-50d3dce1d248",
* "tenantRealm": "tenantA",
* "tenantDisplayName": "Tenant A",
* "path": [
@@ -144,7 +140,7 @@ import static org.openremote.model.attribute.AttributeType.LOCATION;
* "parentId": "B0x8ZOqZQHGjq_l0RxAJBA",
* "parentName": "Apartment 1",
* "parentType": "urn:openremote:asset:residence",
- * "realmId": "c38a3fdf-9d74-4dac-940c-50d3dce1d248",
+ * "realm": "c38a3fdf-9d74-4dac-940c-50d3dce1d248",
* "tenantRealm": "tenantA",
* "tenantDisplayName": "Tenant A",
* "path": [
@@ -169,7 +165,7 @@ import static org.openremote.model.attribute.AttributeType.LOCATION;
* "parentId": "bzlRiJmSSMCl8HIUt9-lMg",
* "parentName": "Living Room",
* "parentType": "urn:openremote:asset:room",
- * "realmId": "c38a3fdf-9d74-4dac-940c-50d3dce1d248",
+ * "realm": "c38a3fdf-9d74-4dac-940c-50d3dce1d248",
* "tenantRealm": "tenantA",
* "tenantDisplayName": "Tenant A",
* "path": [
@@ -266,14 +262,8 @@ public class Asset implements IdentifiableEntity {
@Transient
protected String parentType;
- @Column(name = "REALM_ID", nullable = false)
- protected String realmId;
-
- @Transient
- protected String tenantRealm;
-
- @Transient
- protected String tenantDisplayName;
+ @Column(name = "REALM", nullable = false)
+ protected String realm;
@Transient
@JsonIgnore
@@ -308,12 +298,12 @@ public class Asset implements IdentifiableEntity {
this(name, type, false, parent, null);
}
- public Asset(@NotNull String name, @NotNull AssetType type, Asset parent, @NotNull String realmId) {
- this(name, type.getValue(), false, parent, realmId);
+ public Asset(@NotNull String name, @NotNull AssetType type, Asset parent, @NotNull String realm) {
+ this(name, type.getValue(), false, parent, realm);
}
- public Asset(@NotNull String name, @NotNull String type, boolean accessPublicRead, Asset parent, @NotNull String realmId) {
- setRealmId(realmId);
+ public Asset(@NotNull String name, @NotNull String type, boolean accessPublicRead, Asset parent, @NotNull String realm) {
+ setRealm(realm);
setName(name);
setType(type);
setParent(parent);
@@ -322,25 +312,20 @@ public class Asset implements IdentifiableEntity {
// Initialise realm from parent
// TODO: Need to look at this - can child have a different realm to the parent?
if (parent != null) {
- this.realmId = parent.getRealmId();
- this.tenantRealm = parent.getTenantRealm();
- this.tenantDisplayName = parent.getTenantDisplayName();
+ this.realm = parent.getRealm();
}
}
public Asset(String id, long version, Date createdOn, String name, String type, boolean accessPublicRead,
String parentId, String parentName, String parentType,
- String realmId, String tenantRealm, String tenantDisplayName,
- String[] path, ObjectValue attributes) {
- this(name, type, accessPublicRead, null, realmId);
+ String realm, String[] path, ObjectValue attributes) {
+ this(name, type, accessPublicRead, null, realm);
this.id = id;
this.version = version;
this.createdOn = createdOn;
this.parentId = parentId;
this.parentName = parentName;
this.parentType = parentType;
- this.tenantRealm = tenantRealm;
- this.tenantDisplayName = tenantDisplayName;
this.path = path;
this.attributes = attributes;
}
@@ -490,34 +475,12 @@ public class Asset implements IdentifiableEntity {
return AssetType.getByValue(getParentType()).orElse(AssetType.CUSTOM);
}
- public String getRealmId() {
- return realmId;
- }
-
- public void setRealmId(String realmId) {
- this.realmId = realmId;
- }
-
- /**
- * NOTE: This is a transient and optional property, set only in database query results.
- */
- public String getTenantRealm() {
- return tenantRealm;
- }
-
- public void setTenantRealm(String tenantRealm) {
- this.tenantRealm = tenantRealm;
- }
-
- /**
- * NOTE: This is a transient and optional property, set only in database query results.
- */
- public String getTenantDisplayName() {
- return tenantDisplayName;
+ public String getRealm() {
+ return realm;
}
- public void setTenantDisplayName(String tenantDisplayName) {
- this.tenantDisplayName = tenantDisplayName;
+ public void setRealm(String realm) {
+ this.realm = realm;
}
/**
@@ -619,9 +582,7 @@ public class Asset implements IdentifiableEntity {
", parentId='" + parentId + '\'' +
", parentName='" + parentName + '\'' +
", parentType='" + parentType + '\'' +
- ", realmId='" + realmId + '\'' +
- ", tenantRealm='" + tenantRealm + '\'' +
- ", tenantDisplayName='" + tenantDisplayName + '\'' +
+ ", realm='" + realm + '\'' +
", path=" + Arrays.toString(path) +
", attributes=" + attributes +
'}';
@@ -697,7 +658,7 @@ public class Asset implements IdentifiableEntity {
public static Asset map(Asset assetToMap, Asset asset,
String overrideName,
- String overrideRealmId,
+ String overrideRealm,
String overrideParentId,
String overrideType,
Boolean overrideAccessPublicRead,
@@ -716,9 +677,7 @@ public class Asset implements IdentifiableEntity {
asset.setParentName(null);
asset.setParentType(null);
- asset.setRealmId(overrideRealmId != null ? overrideRealmId : assetToMap.getRealmId());
- asset.setTenantRealm(null);
- asset.setTenantDisplayName(null);
+ asset.setRealm(overrideRealm != null ? overrideRealm : assetToMap.getRealm());
asset.setAttributes(overrideAttributes != null ? overrideAttributes : assetToMap.getAttributes());
diff --git a/model/src/main/java/org/openremote/model/asset/AssetResource.java b/model/src/main/java/org/openremote/model/asset/AssetResource.java
index ac2ccff38..f1a588220 100644
--- a/model/src/main/java/org/openremote/model/asset/AssetResource.java
+++ b/model/src/main/java/org/openremote/model/asset/AssetResource.java
@@ -89,7 +89,7 @@ public interface AssetResource {
/**
* Retrieve links between assets and users.
* <p>
- * The <code>realmId</code> parameter is required, <code>userId</code> and <code>assetId</code> can be null.
+ * The <code>realm</code> parameter is required, <code>userId</code> and <code>assetId</code> can be null.
* <p>
* If the authenticated user is the superuser, assigned assets from any realm can be retrieved. Otherwise the
* authenticated realm must be the same as the given realm. A 403 status is returned if a regular user tries to
@@ -106,7 +106,7 @@ public interface AssetResource {
@RolesAllowed({"read:assets"})
@SuppressWarnings("unusable-by-js")
UserAsset[] getUserAssetLinks(@BeanParam RequestParams requestParams,
- @QueryParam("realmId") String realmId,
+ @QueryParam("realm") String realm,
@QueryParam("userId") String userId,
@QueryParam("assetId") String assetId);
@@ -129,7 +129,7 @@ public interface AssetResource {
/**
* Delete a link between asset and user.
* <p>
- * The <code>realmId</code> is required.
+ * The <code>realm</code> is required.
* <p>
* If the authenticated user is the superuser, asset/user links from any realm can be deleted. Otherwise assets
* must be in the same realm as the authenticated user. A 403 status is returned if a regular user tries to delete
@@ -137,12 +137,12 @@ public interface AssetResource {
* 400 status is returned if the user or asset or realm doesn't exist.
*/
@DELETE
- @Path("link/{realmId}/{userId}/{assetId}")
+ @Path("link/{realm}/{userId}/{assetId}")
@SuccessStatusCode(204)
@RolesAllowed({"write:assets"})
@SuppressWarnings("unusable-by-js")
void deleteUserAsset(@BeanParam RequestParams requestParams,
- @PathParam("realmId") String realmId,
+ @PathParam("realm") String realm,
@PathParam("userId") String userId,
@PathParam("assetId") String assetId);
diff --git a/model/src/main/java/org/openremote/model/asset/AssetTreeModifiedEvent.java b/model/src/main/java/org/openremote/model/asset/AssetTreeModifiedEvent.java
index 468f4b7a8..47d2341bd 100644
--- a/model/src/main/java/org/openremote/model/asset/AssetTreeModifiedEvent.java
+++ b/model/src/main/java/org/openremote/model/asset/AssetTreeModifiedEvent.java
@@ -42,19 +42,19 @@ public class AssetTreeModifiedEvent extends TenantScopedEvent {
protected AssetTreeModifiedEvent() {
}
- public AssetTreeModifiedEvent(long timestamp, String realmId, String assetId) {
- super(timestamp, realmId);
- this.realmId = realmId;
+ public AssetTreeModifiedEvent(long timestamp, String realm, String assetId) {
+ super(timestamp, realm);
+ this.realm = realm;
this.assetId = assetId;
}
- public AssetTreeModifiedEvent(long timestamp, String realmId, String parentId, boolean newAssetChildren) {
- this(timestamp, realmId, parentId);
+ public AssetTreeModifiedEvent(long timestamp, String realm, String parentId, boolean newAssetChildren) {
+ this(timestamp, realm, parentId);
this.newAssetChildren = newAssetChildren;
}
- public AssetTreeModifiedEvent(long timestamp, String realmId, boolean newAssetChildren) {
- this(timestamp, realmId, null);
+ public AssetTreeModifiedEvent(long timestamp, String realm, boolean newAssetChildren) {
+ this(timestamp, realm, null);
this.newAssetChildren = newAssetChildren;
}
@@ -64,8 +64,8 @@ public class AssetTreeModifiedEvent extends TenantScopedEvent {
* of the realm of a newly created root asset.
*/
@Override
- public String getRealmId() {
- return super.getRealmId();
+ public String getRealm() {
+ return super.getRealm();
}
/**
@@ -78,11 +78,11 @@ public class AssetTreeModifiedEvent extends TenantScopedEvent {
}
public boolean isTenantModified() {
- return getRealmId() != null && getAssetId() == null;
+ return getRealm() != null && getAssetId() == null;
}
/**
- * @return <code>true</code> if child assets were added to parent {@link #assetId} or {@link #realmId}.
+ * @return <code>true</code> if child assets were added to parent {@link #assetId} or {@link #realm}.
*/
public boolean isNewAssetChildren() {
return newAssetChildren;
@@ -95,7 +95,7 @@ public class AssetTreeModifiedEvent extends TenantScopedEvent {
@Override
public String toString() {
return getClass().getSimpleName() + "{" +
- "realmId='" + realmId + '\'' +
+ "realm='" + realm + '\'' +
", assetId='" + assetId + '\'' +
", newAssetChildren=" + newAssetChildren +
'}';
diff --git a/model/src/main/java/org/openremote/model/asset/UserAsset.java b/model/src/main/java/org/openremote/model/asset/UserAsset.java
index 281e17714..73dcabee1 100644
--- a/model/src/main/java/org/openremote/model/asset/UserAsset.java
+++ b/model/src/main/java/org/openremote/model/asset/UserAsset.java
@@ -61,8 +61,8 @@ import java.util.Date;
public class UserAsset {
public static class Id implements Serializable {
- @Column(name = "REALM_ID", length = 36)
- protected String realmId;
+ @Column(name = "REALM", length = 36)
+ protected String realm;
@Column(name = "USER_ID", length = 36)
protected String userId;
@@ -73,14 +73,14 @@ public class UserAsset {
protected Id() {
}
- public Id(String realmId, String userId, String assetId) {
- this.realmId = realmId;
+ public Id(String realm, String userId, String assetId) {
+ this.realm = realm;
this.userId = userId;
this.assetId = assetId;
}
- public String getRealmId() {
- return realmId;
+ public String getRealm() {
+ return realm;
}
public String getUserId() {
@@ -98,14 +98,14 @@ public class UserAsset {
Id id = (Id) o;
- if (!realmId.equals(id.realmId)) return false;
+ if (!realm.equals(id.realm)) return false;
if (!userId.equals(id.userId)) return false;
return assetId.equals(id.assetId);
}
@Override
public int hashCode() {
- int result = realmId.hashCode();
+ int result = realm.hashCode();
result = 31 * result + userId.hashCode();
result = 31 * result + assetId.hashCode();
return result;
@@ -114,7 +114,7 @@ public class UserAsset {
@Override
public String toString() {
return getClass().getSimpleName() + "{" +
- "realmId='" + realmId + '\'' +
+ "realm='" + realm + '\'' +
", userId='" + userId + '\'' +
", assetId='" + assetId + '\'' +
'}';
@@ -144,8 +144,8 @@ public class UserAsset {
this.id = id;
}
- public UserAsset(String realmId, String userId, String assetId) {
- this(new UserAsset.Id(realmId, userId, assetId));
+ public UserAsset(String realm, String userId, String assetId) {
+ this(new UserAsset.Id(realm, userId, assetId));
}
public Id getId() {
diff --git a/model/src/main/java/org/openremote/model/asset/agent/AgentResource.java b/model/src/main/java/org/openremote/model/asset/agent/AgentResource.java
index 01c5911a0..c740d8541 100644
--- a/model/src/main/java/org/openremote/model/asset/agent/AgentResource.java
+++ b/model/src/main/java/org/openremote/model/asset/agent/AgentResource.java
@@ -138,7 +138,7 @@ public interface AgentResource {
@PathParam("agentId") String agentId,
@PathParam("protocolConfigurationName") String protocolConfigurationName,
@QueryParam("parentId") String parentId,
- @QueryParam("realmId") String realmId
+ @QueryParam("realm") String realm
);
/**
@@ -162,7 +162,7 @@ public interface AgentResource {
@PathParam("agentId") String agentId,
@PathParam("protocolConfigurationName") String protocolConfigurationName,
@QueryParam("parentId") String parentId,
- @QueryParam("realmId") String realmId,
+ @QueryParam("realm") String realm,
FileInfo fileInfo
);
}
diff --git a/model/src/main/java/org/openremote/model/asset/agent/AgentStatusEvent.java b/model/src/main/java/org/openremote/model/asset/agent/AgentStatusEvent.java
index c593605f9..ffc6e782e 100644
--- a/model/src/main/java/org/openremote/model/asset/agent/AgentStatusEvent.java
+++ b/model/src/main/java/org/openremote/model/asset/agent/AgentStatusEvent.java
@@ -35,8 +35,8 @@ public class AgentStatusEvent extends TenantScopedEvent {
protected AgentStatusEvent() {
}
- public AgentStatusEvent(long timestamp, String realmId, AttributeRef protocolConfiguration, ConnectionStatus connectionStatus) {
- super(timestamp, realmId);
+ public AgentStatusEvent(long timestamp, String realm, AttributeRef protocolConfiguration, ConnectionStatus connectionStatus) {
+ super(timestamp, realm);
this.protocolConfiguration = protocolConfiguration;
this.connectionStatus = connectionStatus;
}
@@ -52,7 +52,7 @@ public class AgentStatusEvent extends TenantScopedEvent {
@Override
public String toString() {
return getClass().getSimpleName() + "{" +
- "realmId=" + realmId +
+ "realm=" + realm +
", protocolConfiguration=" + protocolConfiguration +
", connectionStatus=" + connectionStatus +
'}';
diff --git a/model/src/main/java/org/openremote/model/event/shared/TenantFilter.java b/model/src/main/java/org/openremote/model/event/shared/TenantFilter.java
index 7466e8615..19dfda8fc 100644
--- a/model/src/main/java/org/openremote/model/event/shared/TenantFilter.java
+++ b/model/src/main/java/org/openremote/model/event/shared/TenantFilter.java
@@ -23,17 +23,17 @@ public class TenantFilter<T extends TenantScopedEvent> extends EventFilter<T> {
public static final String FILTER_TYPE = "tenant";
- protected String realmId;
+ protected String realm;
protected TenantFilter() {
}
- public TenantFilter(String realmId) {
- this.realmId = realmId;
+ public TenantFilter(String realm) {
+ this.realm = realm;
}
- public String getRealmId() {
- return realmId;
+ public String getRealm() {
+ return realm;
}
@Override
@@ -43,13 +43,13 @@ public class TenantFilter<T extends TenantScopedEvent> extends EventFilter<T> {
@Override
public boolean apply(TenantScopedEvent event) {
- return getRealmId().equals(event.getRealmId());
+ return getRealm().equals(event.getRealm());
}
@Override
public String toString() {
return getClass().getSimpleName() + "{" +
- "realmId='" + realmId + '\'' +
+ "realm='" + realm + '\'' +
'}';
}
}
diff --git a/model/src/main/java/org/openremote/model/event/shared/TenantScopedEvent.java b/model/src/main/java/org/openremote/model/event/shared/TenantScopedEvent.java
index 454006400..1b7aeb531 100644
--- a/model/src/main/java/org/openremote/model/event/shared/TenantScopedEvent.java
+++ b/model/src/main/java/org/openremote/model/event/shared/TenantScopedEvent.java
@@ -24,21 +24,21 @@ package org.openremote.model.event.shared;
*/
public abstract class TenantScopedEvent extends SharedEvent {
- public String realmId;
+ public String realm;
- public TenantScopedEvent(long timestamp, String realmId) {
+ public TenantScopedEvent(long timestamp, String realm) {
super(timestamp);
- this.realmId = realmId;
+ this.realm = realm;
}
- public TenantScopedEvent(String realmId) {
- this.realmId = realmId;
+ public TenantScopedEvent(String realm) {
+ this.realm = realm;
}
protected TenantScopedEvent() {
}
- public String getRealmId() {
- return realmId;
+ public String getRealm() {
+ return realm;
}
}
diff --git a/model/src/main/java/org/openremote/model/query/BaseAssetQuery.java b/model/src/main/java/org/openremote/model/query/BaseAssetQuery.java
index 9c64b6e9c..df0d14f76 100644
--- a/model/src/main/java/org/openremote/model/query/BaseAssetQuery.java
+++ b/model/src/main/java/org/openremote/model/query/BaseAssetQuery.java
@@ -196,7 +196,7 @@ public class BaseAssetQuery<CHILD extends BaseAssetQuery<CHILD>> {
NAME,
ASSET_TYPE,
PARENT_ID,
- REALM_ID
+ REALM
}
public Property property;
diff --git a/model/src/main/java/org/openremote/model/query/filter/TenantPredicate.java b/model/src/main/java/org/openremote/model/query/filter/TenantPredicate.java
index 6e1deebcc..8b2dea63a 100644
--- a/model/src/main/java/org/openremote/model/query/filter/TenantPredicate.java
+++ b/model/src/main/java/org/openremote/model/query/filter/TenantPredicate.java
@@ -19,34 +19,21 @@
*/
package org.openremote.model.query.filter;
-import org.openremote.model.query.BaseAssetQuery;
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
public class TenantPredicate {
- public String realmId;
public String realm;
- public TenantPredicate() {
- }
-
- public TenantPredicate(String realmId) {
- this.realmId = realmId;
- }
-
- public TenantPredicate realmId(String id) {
- this.realmId = id;
- return this;
- }
-
- public TenantPredicate realm(String name) {
- this.realm = name;
- return this;
+ @JsonCreator
+ public TenantPredicate(@JsonProperty("realm") String realm) {
+ this.realm = realm;
}
@Override
public String toString() {
return getClass().getSimpleName() + "{" +
- "realmId='" + realmId + '\'' +
", realm='" + realm + '\'' +
'}';
}
diff --git a/model/src/main/java/org/openremote/model/rules/AssetRuleset.java b/model/src/main/java/org/openremote/model/rules/AssetRuleset.java
index ce62b94e9..828c09c30 100644
--- a/model/src/main/java/org/openremote/model/rules/AssetRuleset.java
+++ b/model/src/main/java/org/openremote/model/rules/AssetRuleset.java
@@ -39,7 +39,7 @@ public class AssetRuleset extends Ruleset {
protected String assetId;
@Transient
- protected String realmId;
+ protected String realm;
public AssetRuleset() {
}
@@ -49,7 +49,7 @@ public class AssetRuleset extends Ruleset {
}
public AssetRuleset(long id, long version, Date createdOn, Date lastModified, String name, boolean enabled, String assetId, Lang lang) {
- this(id, version, createdOn, lastModified, name, enabled, null, lang, null, assetId);
+ this(id, version, createdOn, lastModified, name, enabled, null, lang, assetId, null);
}
public AssetRuleset(String name, String assetId, String rules, Lang lang) {
@@ -57,10 +57,10 @@ public class AssetRuleset extends Ruleset {
this.assetId = assetId;
}
- public AssetRuleset(long id, long version, Date createdOn, Date lastModified, String name, boolean enabled, String rules, Lang lang, String assetId, String realmId) {
+ public AssetRuleset(long id, long version, Date createdOn, Date lastModified, String name, boolean enabled, String rules, Lang lang, String assetId, String realm) {
super(id, version, createdOn, lastModified, name, enabled, rules, lang);
this.assetId = assetId;
- this.realmId = realmId;
+ this.realm = realm;
}
public String getAssetId() {
@@ -71,12 +71,12 @@ public class AssetRuleset extends Ruleset {
this.assetId = assetId;
}
- public String getRealmId() {
- return realmId;
+ public String getRealm() {
+ return realm;
}
- public void setRealmId(String realmId) {
- this.realmId = realmId;
+ public void setRealm(String realm) {
+ this.realm = realm;
}
@Override
@@ -89,6 +89,7 @@ public class AssetRuleset extends Ruleset {
", createdOn='" + createdOn + '\'' +
", lastModified='" + lastModified + '\'' +
", enabled='" + enabled + '\'' +
+ ", realm='" + realm + '\'' +
", assetId='" + assetId + '\'' +
'}';
}
diff --git a/model/src/main/java/org/openremote/model/rules/AssetState.java b/model/src/main/java/org/openremote/model/rules/AssetState.java
index b3bf57d9e..dc799d0a4 100644
--- a/model/src/main/java/org/openremote/model/rules/AssetState.java
+++ b/model/src/main/java/org/openremote/model/rules/AssetState.java
@@ -33,9 +33,6 @@ import org.openremote.model.value.ObjectValue;
import org.openremote.model.value.Value;
import org.openremote.model.value.Values;
-import java.time.Instant;
-import java.time.LocalDateTime;
-import java.time.ZoneId;
import java.util.Date;
import java.util.Objects;
import java.util.Optional;
@@ -58,8 +55,6 @@ public class AssetState implements Comparable<AssetState> {
final protected long timestamp;
- final protected LocalDateTime time;
-
final protected AttributeEvent.Source source;
final protected Value oldValue;
@@ -86,9 +81,7 @@ public class AssetState implements Comparable<AssetState> {
final protected AssetType parentType;
- final protected String realmId;
-
- final protected String tenantRealm;
+ final protected String realm;
final protected Meta meta;
@@ -97,7 +90,6 @@ public class AssetState implements Comparable<AssetState> {
this.attributeValueType = that.attributeValueType;
this.value = that.value;
this.timestamp = that.timestamp;
- this.time = that.time;
this.source = that.source;
this.oldValue = that.oldValue;
this.oldValueTimestamp = that.oldValueTimestamp;
@@ -111,8 +103,7 @@ public class AssetState implements Comparable<AssetState> {
this.parentName = that.parentName;
this.parentTypeString = that.parentTypeString;
this.parentType = that.parentType;
- this.realmId = that.realmId;
- this.tenantRealm = that.tenantRealm;
+ this.realm = that.realm;
this.meta = that.meta;
}
@@ -121,7 +112,6 @@ public class AssetState implements Comparable<AssetState> {
this.attributeValueType = attribute.getTypeOrThrow();
this.value = attribute.getValue().orElse(null);
this.timestamp = attribute.getValueTimestamp().orElse(-1L);
- this.time = timestamp > 0 ? LocalDateTime.ofInstant(Instant.ofEpochMilli(timestamp), ZoneId.systemDefault()) : null;
this.source = source;
this.oldValue = asset.getAttribute(attributeName).flatMap(AbstractValueHolder::getValue).orElse(null);
this.oldValueTimestamp = asset.getAttribute(attributeName).flatMap(AbstractValueTimestampHolder::getValueTimestamp).orElse(-1L);
@@ -135,8 +125,7 @@ public class AssetState implements Comparable<AssetState> {
this.parentName = asset.getParentName();
this.parentTypeString = asset.getParentType();
this.parentType = asset.getParentWellKnownType();
- this.realmId = asset.getRealmId();
- this.tenantRealm = asset.getTenantRealm();
+ this.realm = asset.getRealm();
this.meta = attribute.getMeta();
}
@@ -156,10 +145,6 @@ public class AssetState implements Comparable<AssetState> {
return timestamp;
}
- public LocalDateTime getTime() {
- return time;
- }
-
public AttributeEvent.Source getSource() {
return source;
}
@@ -212,12 +197,8 @@ public class AssetState implements Comparable<AssetState> {
return parentType;
}
- public String getRealmId() {
- return realmId;
- }
-
- public String getTenantRealm() {
- return tenantRealm;
+ public String getRealm() {
+ return realm;
}
public Meta getMeta() {
@@ -345,7 +326,6 @@ public class AssetState implements Comparable<AssetState> {
", attributeValueType=" + getAttributeValueType() +
", value=" + (getValue().isPresent() ? getValue().get().toJson() : "null") + // TODO Performance?
", timestamp=" + getTimestamp() +
- ", time=" + getTime() +
", oldValue=" + (getOldValue().isPresent() ? getOldValue().get().toJson() : "null") +
", oldValueTimestamp=" + getOldValueTimestamp() +
", source=" + getSource() +
diff --git a/model/src/main/java/org/openremote/model/rules/RulesResource.java b/model/src/main/java/org/openremote/model/rules/RulesResource.java
index 9722c4e14..06ab2482b 100644
--- a/model/src/main/java/org/openremote/model/rules/RulesResource.java
+++ b/model/src/main/java/org/openremote/model/rules/RulesResource.java
@@ -48,11 +48,11 @@ public interface RulesResource {
* Retrieve information about the specified tenant rules engine (if engine doesn't exist then will return null).
*/
@GET
- @Path("info/tenant/{realmId}")
+ @Path("info/tenant/{realm}")
@SuccessStatusCode(200)
@RolesAllowed({"read:rules"})
@SuppressWarnings("unusable-by-js")
- RulesEngineInfo getTenantEngineInfo(@BeanParam RequestParams requestParams, @PathParam("realmId") String realmId);
+ RulesEngineInfo getTenantEngineInfo(@BeanParam RequestParams requestParams, @PathParam("realm") String realm);
/**
* Retrieve information about the specified asset rules engine (if engine doesn't exist then will return null).
@@ -81,12 +81,12 @@ public interface RulesResource {
* can not be found.
*/
@GET
- @Path("tenant/for/{realmId}")
+ @Path("tenant/for/{realm}")
@Produces(APPLICATION_JSON)
@SuccessStatusCode(200)
@RolesAllowed({"read:rules"})
@SuppressWarnings("unusable-by-js")
- TenantRuleset[] getTenantRulesets(@BeanParam RequestParams requestParams, @PathParam("realmId") String realmId);
+ TenantRuleset[] getTenantRulesets(@BeanParam RequestParams requestParams, @PathParam("realm") String realm);
/**
* Retrieve rules of an asset. The superuser can retrieve rules of all realms and assets, a 403 status is returned
diff --git a/model/src/main/java/org/openremote/model/rules/TenantRuleset.java b/model/src/main/java/org/openremote/model/rules/TenantRuleset.java
index 653addf4d..b7e758dfa 100644
--- a/model/src/main/java/org/openremote/model/rules/TenantRuleset.java
+++ b/model/src/main/java/org/openremote/model/rules/TenantRuleset.java
@@ -34,38 +34,38 @@ public class TenantRuleset extends Ruleset {
public static final String TYPE = "tenant";
- @Column(name = "REALM_ID", nullable = false)
- protected String realmId;
+ @Column(name = "REALM", nullable = false)
+ protected String realm;
public TenantRuleset() {
}
- public TenantRuleset(long id, long version, Date createdOn, Date lastModified, String name, boolean enabled, String realmId, Lang lang) {
+ public TenantRuleset(long id, long version, Date createdOn, Date lastModified, String name, boolean enabled, String realm, Lang lang) {
super(id, version, createdOn, lastModified, name, enabled, lang);
- this.realmId = realmId;
+ this.realm = realm;
}
- public TenantRuleset(long id, long version, Date createdOn, Date lastModified, String name, boolean enabled, String rules, Lang lang, String realmId) {
+ public TenantRuleset(long id, long version, Date createdOn, Date lastModified, String name, boolean enabled, String rules, Lang lang, String realm) {
super(id, version, createdOn, lastModified, name, enabled, rules, lang);
- this.realmId = realmId;
+ this.realm = realm;
}
- public TenantRuleset(String realmId) {
- this(null, realmId, null, Lang.GROOVY);
+ public TenantRuleset(String realm) {
+ this(null, realm, null, Lang.GROOVY);
}
- public TenantRuleset(String name, String realmId, String rules, Lang lang) {
+ public TenantRuleset(String name, String realm, String rules, Lang lang) {
super(name, rules, lang);
- this.realmId = realmId;
+ this.realm = realm;
}
- public String getRealmId() {
- return realmId;
+ public String getRealm() {
+ return realm;
}
- public void setRealmId(String realmId) {
- this.realmId = realmId;
+ public void setRealm(String realm) {
+ this.realm = realm;
}
@Override
@@ -78,7 +78,7 @@ public class TenantRuleset extends Ruleset {
", createdOn='" + createdOn + '\'' +
", lastModified='" + lastModified + '\'' +
", enabled='" + enabled + '\'' +
- ", realmId='" + realmId + '\'' +
+ ", realm='" + realm + '\'' +
'}';
}
}
diff --git a/model/src/main/java/org/openremote/model/security/TenantResource.java b/model/src/main/java/org/openremote/model/security/TenantResource.java
index 3e3cd2cd4..a46d62dc7 100644
--- a/model/src/main/java/org/openremote/model/security/TenantResource.java
+++ b/model/src/main/java/org/openremote/model/security/TenantResource.java
@@ -58,16 +58,6 @@ public interface TenantResource {
@SuppressWarnings("unusable-by-js")
Tenant get(@BeanParam RequestParams requestParams, @PathParam("realm") String realm);
- /**
- * Regular users can call this, but only to obtain details about their currently authenticated and active realm.
- */
- @GET
- @Path("for/{realmId}")
- @Produces(APPLICATION_JSON)
- @SuccessStatusCode(200)
- @SuppressWarnings("unusable-by-js")
- Tenant getForRealmId(@BeanParam RequestParams requestParams, @PathParam("realmId") String realmId);
-
@PUT
@Path("{realm}")
@Consumes(APPLICATION_JSON)
diff --git a/test/src/test/groovy/org/openremote/test/admin/AdminTenantsActivityTest.groovy b/test/src/test/groovy/org/openremote/test/admin/AdminTenantsActivityTest.groovy
index 6351f69ef..3efee5fb7 100644
--- a/test/src/test/groovy/org/openremote/test/admin/AdminTenantsActivityTest.groovy
+++ b/test/src/test/groovy/org/openremote/test/admin/AdminTenantsActivityTest.groovy
@@ -69,7 +69,7 @@ class AdminTenantsActivityTest extends Specification implements ManagerContainer
and: "a test client app"
def testApp = new TestOpenRemoteApp(
keycloakProvider.getKeycloakDeployment(realm, KEYCLOAK_CLIENT_ID),
- identityService.getIdentityProvider().getTenantForRealm(realm),
+ identityService.getIdentityProvider().getTenant(realm),
accessToken
)
diff --git a/test/src/test/groovy/org/openremote/test/admin/AdminUsersActivityTest.groovy b/test/src/test/groovy/org/openremote/test/admin/AdminUsersActivityTest.groovy
index b579bf6d9..ca53cf308 100644
--- a/test/src/test/groovy/org/openremote/test/admin/AdminUsersActivityTest.groovy
+++ b/test/src/test/groovy/org/openremote/test/admin/AdminUsersActivityTest.groovy
@@ -76,7 +76,7 @@ class AdminUsersActivityTest extends Specification implements ManagerContainerTr
and: "a test client app"
def testApp = new TestOpenRemoteApp(
keycloakProvider.getKeycloakDeployment(realm, KEYCLOAK_CLIENT_ID),
- identityService.getIdentityProvider().getTenantForRealm(realm),
+ identityService.getIdentityProvider().getTenant(realm),
accessToken
)
diff --git a/test/src/test/groovy/org/openremote/test/assets/AssetBrowserPresenterTest.groovy b/test/src/test/groovy/org/openremote/test/assets/AssetBrowserPresenterTest.groovy
index 91b6d3e1e..732cec5a5 100644
--- a/test/src/test/groovy/org/openremote/test/assets/AssetBrowserPresenterTest.groovy
+++ b/test/src/test/groovy/org/openremote/test/assets/AssetBrowserPresenterTest.groovy
@@ -65,7 +65,7 @@ class AssetBrowserPresenterTest extends Specification implements ManagerContaine
and: "a test client app"
def testApp = new TestOpenRemoteApp(
keycloakProvider.getKeycloakDeployment(realm, KEYCLOAK_CLIENT_ID),
- identityService.getIdentityProvider().getTenantForRealm(realm),
+ identityService.getIdentityProvider().getTenant(realm),
accessToken
)
@@ -162,13 +162,13 @@ class AssetBrowserPresenterTest extends Specification implements ManagerContaine
assert rowData[0] instanceof TenantTreeNode
assert rowData[0].label == "Master"
assert rowData[0].icon == "group"
- assert rowData[0].tenant.id == keycloakDemoSetup.masterTenant.id
+ assert rowData[0].id == keycloakDemoSetup.masterTenant.realm
assert rowData[1] instanceof TenantTreeNode
assert rowData[1].label == "Tenant A"
- assert rowData[1].tenant.id == keycloakDemoSetup.tenantA.id
+ assert rowData[1].id == keycloakDemoSetup.tenantA.realm
assert rowData[2] instanceof TenantTreeNode
assert rowData[2].label == "Tenant B"
- assert rowData[2].tenant.id == keycloakDemoSetup.tenantB.id
+ assert rowData[2].id == keycloakDemoSetup.tenantB.realm
}
1 * treeDisplay.setRowCount(3, true)
@@ -196,7 +196,7 @@ class AssetBrowserPresenterTest extends Specification implements ManagerContaine
conditions.eventually {
assert collectedSharedEvents.size() == 1
assert collectedSharedEvents[0] instanceof AssetTreeModifiedEvent
- assert collectedSharedEvents[0].realmId == keycloakDemoSetup.masterTenant.id
+ assert collectedSharedEvents[0].realm == keycloakDemoSetup.masterTenant.realm
assert collectedSharedEvents[0].assetId == managerDemoSetup.smartOfficeId
}
@@ -214,14 +214,14 @@ class AssetBrowserPresenterTest extends Specification implements ManagerContaine
// The inserted new asset
assert collectedSharedEvents.any {
(it instanceof AssetTreeModifiedEvent
- && it.realmId == keycloakDemoSetup.masterTenant.id
+ && it.realm == keycloakDemoSetup.masterTenant.realm
&& it.assetId == asset.id
&& !it.newAssetChildren)
}
// The parent which has a new child asset
assert collectedSharedEvents.any {
(it instanceof AssetTreeModifiedEvent
- && it.realmId == keycloakDemoSetup.masterTenant.id
+ && it.realm == keycloakDemoSetup.masterTenant.realm
&& it.assetId == managerDemoSetup.smartOfficeId
&& it.newAssetChildren)
}
@@ -263,7 +263,7 @@ class AssetBrowserPresenterTest extends Specification implements ManagerContaine
and: "a test client app"
def testApp = new TestOpenRemoteApp(
keycloakProvider.getKeycloakDeployment(realm, KEYCLOAK_CLIENT_ID),
- identityService.getIdentityProvider().getTenantForRealm(realm),
+ identityService.getIdentityProvider().getTenant(realm),
accessToken
)
@@ -389,7 +389,7 @@ class AssetBrowserPresenterTest extends Specification implements ManagerContaine
conditions.eventually {
assert collectedSharedEvents.size() == 1
assert collectedSharedEvents[0] instanceof AssetTreeModifiedEvent
- assert collectedSharedEvents[0].realmId == keycloakDemoSetup.masterTenant.id
+ assert collectedSharedEvents[0].realm == keycloakDemoSetup.masterTenant.realm
assert collectedSharedEvents[0].assetId == managerDemoSetup.groundFloorId
}
@@ -400,7 +400,7 @@ class AssetBrowserPresenterTest extends Specification implements ManagerContaine
collectedSharedEvents.clear()
clientEventService.subscribe(
AssetTreeModifiedEvent.class,
- new TenantFilter(keycloakDemoSetup.tenantA.id)
+ new TenantFilter(keycloakDemoSetup.tenantA.realm)
)
then: "the server should return a failure"
@@ -441,7 +441,7 @@ class AssetBrowserPresenterTest extends Specification implements ManagerContaine
and: "a test client app"
def testApp = new TestOpenRemoteApp(
keycloakProvider.getKeycloakDeployment(realm, KEYCLOAK_CLIENT_ID),
- identityService.getIdentityProvider().getTenantForRealm(realm),
+ identityService.getIdentityProvider().getTenant(realm),
accessToken
)
diff --git a/test/src/test/groovy/org/openremote/test/assets/AssetIntegrityTest.groovy b/test/src/test/groovy/org/openremote/test/assets/AssetIntegrityTest.groovy
index acb62dc8f..90368a107 100644
--- a/test/src/test/groovy/org/openremote/test/assets/AssetIntegrityTest.groovy
+++ b/test/src/test/groovy/org/openremote/test/assets/AssetIntegrityTest.groovy
@@ -43,13 +43,13 @@ class AssetIntegrityTest extends Specification implements ManagerContainerTrait
def assetResource = getClientApiTarget(serverUri, MASTER_REALM, accessToken).proxy(AssetResource.class)
when: "an asset is created in the authenticated realm"
- def testAsset = new Asset("Test Room", AssetType.ROOM, null, keycloakDemoSetup.masterTenant.id)
+ def testAsset = new Asset("Test Room", AssetType.ROOM, null, keycloakDemoSetup.masterTenant.realm)
testAsset = assetResource.create(null, testAsset)
then: "the asset should exist"
testAsset.name == "Test Room"
testAsset.wellKnownType == AssetType.ROOM
- testAsset.realmId == keycloakDemoSetup.masterTenant.id
+ testAsset.realm == keycloakDemoSetup.masterTenant.realm
testAsset.parentId == null
when: "an asset is stored with an illegal attribute name"
@@ -104,7 +104,7 @@ class AssetIntegrityTest extends Specification implements ManagerContainerTrait
testAsset.wellKnownType == AssetType.ROOM
when: "an asset is updated with a non-existent realm"
- testAsset.setRealmId("thisdoesnotexistitreallydoesnt")
+ testAsset.setRealm("thisdoesnotexistitreallydoesnt")
assetResource.update(null, testAsset.id, testAsset)
then: "the request should be forbidden"
diff --git a/test/src/test/groovy/org/openremote/test/assets/AssetPermissionsTest.groovy b/test/src/test/groovy/org/openremote/test/assets/AssetPermissionsTest.groovy
index 90ca35503..6701f04f3 100644
--- a/test/src/test/groovy/org/openremote/test/assets/AssetPermissionsTest.groovy
+++ b/test/src/test/groovy/org/openremote/test/assets/AssetPermissionsTest.groovy
@@ -62,7 +62,7 @@ class AssetPermissionsTest extends Specification implements ManagerContainerTrai
when: "the root assets of the authenticated realm are retrieved"
assets = assetResource.queryAssets(null,
new AssetQuery()
- .tenant(new TenantPredicate(keycloakDemoSetup.masterTenant.id))
+ .tenant(new TenantPredicate(keycloakDemoSetup.masterTenant.realm))
.parent(new ParentPredicate(true))
)
@@ -83,7 +83,7 @@ class AssetPermissionsTest extends Specification implements ManagerContainerTrai
when: "the root assets of the authenticated realm are retrieved"
assets = assetResource.queryAssets(null,
new AssetQuery()
- .tenant(new TenantPredicate(keycloakDemoSetup.masterTenant.id))
+ .tenant(new TenantPredicate(keycloakDemoSetup.masterTenant.realm))
.parent(new ParentPredicate(true))
)
@@ -94,7 +94,7 @@ class AssetPermissionsTest extends Specification implements ManagerContainerTrai
when: "the root assets of the given realm are retrieved"
assets = assetResource.queryAssets(null,
new AssetQuery()
- .tenant(new TenantPredicate(keycloakDemoSetup.tenantA.id))
+ .tenant(new TenantPredicate(keycloakDemoSetup.tenantA.realm))
.parent(new ParentPredicate(true))
)
@@ -130,14 +130,14 @@ class AssetPermissionsTest extends Specification implements ManagerContainerTrai
/* ############################################## WRITE ####################################### */
when: "an asset is created in the authenticated realm"
- def testAsset = new Asset("Test Room", AssetType.ROOM, null, keycloakDemoSetup.masterTenant.id)
+ def testAsset = new Asset("Test Room", AssetType.ROOM, null, keycloakDemoSetup.masterTenant.realm)
testAsset = assetResource.create(null, testAsset)
testAsset = assetResource.get(null, testAsset.getId())
then: "the asset should exist"
testAsset.name == "Test Room"
testAsset.wellKnownType == AssetType.ROOM
- testAsset.realmId == keycloakDemoSetup.masterTenant.id
+ testAsset.realm == keycloakDemoSetup.masterTenant.realm
testAsset.parentId == null
when: "an asset is made public"
@@ -157,13 +157,13 @@ class AssetPermissionsTest extends Specification implements ManagerContainerTrai
testAsset.parentId == managerDemoSetup.groundFloorId
when: "an asset is moved to a foreign realm and made a root asset"
- testAsset.setRealmId(keycloakDemoSetup.tenantA.id)
+ testAsset.setRealm(keycloakDemoSetup.tenantA.realm)
testAsset.setParentId(null)
assetResource.update(null, testAsset.id, testAsset)
testAsset = assetResource.get(null, testAsset.getId())
then: "the asset should be updated"
- testAsset.realmId == keycloakDemoSetup.tenantA.id
+ testAsset.realm == keycloakDemoSetup.tenantA.realm
testAsset.parentId == null
when: "an asset is updated with a new parent in a foreign realm"
@@ -172,7 +172,7 @@ class AssetPermissionsTest extends Specification implements ManagerContainerTrai
testAsset = assetResource.get(null, testAsset.getId())
then: "the asset should be updated"
- testAsset.realmId == keycloakDemoSetup.tenantA.id
+ testAsset.realm == keycloakDemoSetup.tenantA.realm
testAsset.parentId == managerDemoSetup.smartBuildingId
when: "an asset is deleted in the authenticated realm"
@@ -266,7 +266,7 @@ class AssetPermissionsTest extends Specification implements ManagerContainerTrai
when: "the root assets of the authenticated realm are retrieved"
assets = assetResource.queryAssets(null,
new AssetQuery()
- .tenant(new TenantPredicate(keycloakDemoSetup.masterTenant.id))
+ .tenant(new TenantPredicate(keycloakDemoSetup.masterTenant.realm))
.parent(new ParentPredicate(true))
)
@@ -293,12 +293,12 @@ class AssetPermissionsTest extends Specification implements ManagerContainerTrai
then: "result should match"
assets.length == 1
assets[0].id == managerDemoSetup.smartOfficeId
- assets[0].realmId == keycloakDemoSetup.masterTenant.id
+ assets[0].realm == keycloakDemoSetup.masterTenant.realm
when: "the root assets of the given realm are retrieved"
assets = assetResource.queryAssets(null,
new AssetQuery()
- .tenant(new TenantPredicate(keycloakDemoSetup.tenantA.id))
+ .tenant(new TenantPredicate(keycloakDemoSetup.tenantA.realm))
.parent(new ParentPredicate(true))
)
@@ -337,7 +337,7 @@ class AssetPermissionsTest extends Specification implements ManagerContainerTrai
then: "the asset should exist"
testAsset.name == "Test Room"
testAsset.wellKnownType == AssetType.ROOM
- testAsset.realmId == keycloakDemoSetup.masterTenant.id
+ testAsset.realm == keycloakDemoSetup.masterTenant.realm
testAsset.parentId == null
when: "an asset is updated with a new parent in the authenticated realm"
@@ -349,7 +349,7 @@ class AssetPermissionsTest extends Specification implements ManagerContainerTrai
testAsset.parentId == managerDemoSetup.groundFloorId
when: "an asset is moved to a foreign realm and made a root asset"
- testAsset.setRealmId(keycloakDemoSetup.tenantA.id)
+ testAsset.setRealm(keycloakDemoSetup.tenantA.realm)
testAsset.setParentId(null)
assetResource.update(null, testAsset.id, testAsset)
@@ -435,7 +435,7 @@ class AssetPermissionsTest extends Specification implements ManagerContainerTrai
when: "the root assets of a foreign realm are retrieved"
assets = assetResource.queryAssets(null,
new AssetQuery()
- .tenant(new TenantPredicate(keycloakDemoSetup.masterTenant.id))
+ .tenant(new TenantPredicate(keycloakDemoSetup.masterTenant.realm))
.parent(new ParentPredicate(true))
)
@@ -451,12 +451,12 @@ class AssetPermissionsTest extends Specification implements ManagerContainerTrai
then: "result should match"
assets.length == 1
assets[0].id == managerDemoSetup.smartBuildingId
- assets[0].realmId == keycloakDemoSetup.tenantA.id
+ assets[0].realm == keycloakDemoSetup.tenantA.realm
when: "the root assets of the given realm are retrieved"
assets = assetResource.queryAssets(null,
new AssetQuery()
- .tenant(new TenantPredicate(keycloakDemoSetup.tenantB.id))
+ .tenant(new TenantPredicate(keycloakDemoSetup.tenantB.realm))
.parent(new ParentPredicate(true))
)
@@ -488,7 +488,7 @@ class AssetPermissionsTest extends Specification implements ManagerContainerTrai
/* ############################################## WRITE ####################################### */
when: "an asset is created in a foreign realm"
- def testAsset = new Asset("Test Room", AssetType.ROOM, null, keycloakDemoSetup.masterTenant.id)
+ def testAsset = new Asset("Test Room", AssetType.ROOM, null, keycloakDemoSetup.masterTenant.realm)
assetResource.create(null, testAsset)
then: "access should be forbidden"
@@ -505,7 +505,7 @@ class AssetPermissionsTest extends Specification implements ManagerContainerTrai
ex.response.status == 403
when: "an asset is created in the authenticated realm"
- testAsset = new Asset("Test Room", AssetType.ROOM, null, keycloakDemoSetup.tenantA.id)
+ testAsset = new Asset("Test Room", AssetType.ROOM, null, keycloakDemoSetup.tenantA.realm)
assetResource.create(null, testAsset)
then: "access should be forbidden"
@@ -575,7 +575,7 @@ class AssetPermissionsTest extends Specification implements ManagerContainerTrai
apartment1.id == managerDemoSetup.apartment1Id
apartment1.name == "Apartment 1"
apartment1.createdOn.getTime() < System.currentTimeMillis()
- apartment1.realmId == keycloakDemoSetup.tenantA.id
+ apartment1.realm == keycloakDemoSetup.tenantA.realm
apartment1.type == AssetType.RESIDENCE.value
apartment1.parentId == managerDemoSetup.smartBuildingId
apartment1.path == null
@@ -604,7 +604,7 @@ class AssetPermissionsTest extends Specification implements ManagerContainerTrai
when: "the root assets of a foreign realm are retrieved"
assets = assetResource.queryAssets(null,
new AssetQuery()
- .tenant(new TenantPredicate(keycloakDemoSetup.masterTenant.id))
+ .tenant(new TenantPredicate(keycloakDemoSetup.masterTenant.realm))
.parent(new ParentPredicate(true))
)
@@ -623,7 +623,7 @@ class AssetPermissionsTest extends Specification implements ManagerContainerTrai
when: "the root assets of the given realm are retrieved"
assets = assetResource.queryAssets(null,
new AssetQuery()
- .tenant(new TenantPredicate(keycloakDemoSetup.tenantB.id))
+ .tenant(new TenantPredicate(keycloakDemoSetup.tenantB.realm))
.parent(new ParentPredicate(true))
)
@@ -694,7 +694,7 @@ class AssetPermissionsTest extends Specification implements ManagerContainerTrai
/* ############################################## WRITE ####################################### */
when: "an asset is created in a foreign realm"
- def testAsset = new Asset("Test Room", AssetType.ROOM, null, keycloakDemoSetup.masterTenant.id)
+ def testAsset = new Asset("Test Room", AssetType.ROOM, null, keycloakDemoSetup.masterTenant.realm)
assetResource.create(null, testAsset)
then: "access should be forbidden"
@@ -738,7 +738,7 @@ class AssetPermissionsTest extends Specification implements ManagerContainerTrai
assert testAsset.getName() == "Living Room"
when: "an asset is created in the authenticated realm"
- testAsset = new Asset("Test Room", AssetType.ROOM, null, keycloakDemoSetup.tenantA.id)
+ testAsset = new Asset("Test Room", AssetType.ROOM, null, keycloakDemoSetup.tenantA.realm)
assetResource.create(null, testAsset)
then: "access should be forbidden"
diff --git a/test/src/test/groovy/org/openremote/test/assets/AssetProcessingTest.groovy b/test/src/test/groovy/org/openremote/test/assets/AssetProcessingTest.groovy
index 8e2245cde..b675bcd91 100644
--- a/test/src/test/groovy/org/openremote/test/assets/AssetProcessingTest.groovy
+++ b/test/src/test/groovy/org/openremote/test/assets/AssetProcessingTest.groovy
@@ -167,7 +167,7 @@ class AssetProcessingTest extends Specification implements ManagerContainerTrait
mockAgent.setAttributes(
ProtocolConfiguration.initProtocolConfiguration(new AssetAttribute("mock123"), mockProtocolName)
)
- mockAgent.setRealmId(keycloakDemoSetup.masterTenant.id)
+ mockAgent.setRealm(keycloakDemoSetup.masterTenant.realm)
mockAgent = assetStorageService.merge(mockAgent)
and: "a mock thing asset is created with a valid protocol attribute, an invalid protocol attribute and a plain attribute"
diff --git a/test/src/test/groovy/org/openremote/test/assets/AssetPublicQueryTest.groovy b/test/src/test/groovy/org/openremote/test/assets/AssetPublicQueryTest.groovy
index b151194a8..dfbdbaa16 100644
--- a/test/src/test/groovy/org/openremote/test/assets/AssetPublicQueryTest.groovy
+++ b/test/src/test/groovy/org/openremote/test/assets/AssetPublicQueryTest.groovy
@@ -94,9 +94,7 @@ class AssetPublicQueryTest extends Specification implements ManagerContainerTrai
assets[0].name == "Some Public Asset"
assets[0].wellKnownType == THING
assets[0].parentId == managerDemoSetup.smartOfficeId
- assets[0].realmId == keycloakDemoSetup.masterTenant.id
- assets[0].tenantRealm == keycloakDemoSetup.masterTenant.realm
- assets[0].tenantDisplayName == keycloakDemoSetup.masterTenant.displayName
+ assets[0].realm == keycloakDemoSetup.masterTenant.realm
!assets[0].getAttribute("somePrivateAttribute").isPresent()
assets[0].getAttribute("somePublicAttribute").get().getValue().get() == Values.create(456)
assets[0].getAttribute("somePublicAttribute").get().getMeta().size() == 1
@@ -113,9 +111,7 @@ class AssetPublicQueryTest extends Specification implements ManagerContainerTrai
assets[0].name == "Some Public Asset"
assets[0].wellKnownType == THING
assets[0].parentId == managerDemoSetup.smartOfficeId
- assets[0].realmId == keycloakDemoSetup.masterTenant.id
- assets[0].tenantRealm == keycloakDemoSetup.masterTenant.realm
- assets[0].tenantDisplayName == keycloakDemoSetup.masterTenant.displayName
+ assets[0].realm == keycloakDemoSetup.masterTenant.realm
!assets[0].getAttribute("somePrivateAttribute").isPresent()
assets[0].getAttribute("somePublicAttribute").get().getValue().get() == Values.create(456)
assets[0].getAttribute("somePublicAttribute").get().getMeta().size() == 1
diff --git a/test/src/test/groovy/org/openremote/test/assets/AssetQueryTest.groovy b/test/src/test/groovy/org/openremote/test/assets/AssetQueryTest.groovy
index d14f2a7f5..c38835713 100644
--- a/test/src/test/groovy/org/openremote/test/assets/AssetQueryTest.groovy
+++ b/test/src/test/groovy/org/openremote/test/assets/AssetQueryTest.groovy
@@ -72,7 +72,7 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
new AssetQuery()
.select(new Select(Include.ONLY_ID_AND_NAME_AND_ATTRIBUTES))
.type(AssetType.AGENT)
- .tenant(new TenantPredicate(keycloakDemoSetup.masterTenant.id))
+ .tenant(new TenantPredicate(keycloakDemoSetup.masterTenant.realm))
)
then: "agent assets should be retrieved"
@@ -83,9 +83,7 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
assets[0].parentId == null
assets[0].parentName == null
assets[0].parentType == null
- assets[0].realmId == null
- assets[0].tenantRealm == null
- assets[0].tenantDisplayName == null
+ assets[0].realm == null
assets[0].path == null
when: "a user filtering query is executed that returns only IDs, names and attribute names"
@@ -166,9 +164,7 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
assets[1].parentId == null
assets[1].parentName == null
assets[1].parentType == null
- assets[1].realmId == null
- assets[1].tenantRealm == null
- assets[1].tenantDisplayName == null
+ assets[1].realm == null
assets[1].path == null
assets[1].getAttributesList().size() == 6
assets[1].getAttribute("ventilationAuto").isPresent()
@@ -209,9 +205,7 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
asset.parentId == managerDemoSetup.smartBuildingId
asset.parentName == null
asset.parentType == null
- asset.realmId == keycloakDemoSetup.tenantA.id
- asset.tenantRealm == null
- asset.tenantDisplayName == null
+ asset.realm == keycloakDemoSetup.tenantA.realm
asset.path.length == 2
asset.path[0] == managerDemoSetup.apartment1Id
asset.path[1] == managerDemoSetup.smartBuildingId
@@ -232,9 +226,7 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
asset.parentId == null
asset.parentName == null
asset.parentType == null
- asset.realmId == keycloakDemoSetup.masterTenant.id
- asset.tenantRealm == keycloakDemoSetup.masterTenant.realm
- asset.tenantDisplayName == keycloakDemoSetup.masterTenant.displayName
+ asset.realm == keycloakDemoSetup.masterTenant.realm
asset.path == null
asset.attributesList.size() == 0
@@ -254,9 +246,7 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
asset.parentId == null
asset.parentName == null
asset.parentType == null
- asset.realmId == keycloakDemoSetup.masterTenant.id
- asset.tenantRealm == keycloakDemoSetup.masterTenant.realm
- asset.tenantDisplayName == keycloakDemoSetup.masterTenant.displayName
+ asset.realm == keycloakDemoSetup.masterTenant.realm
asset.path.length == 1
asset.path[0] == managerDemoSetup.smartOfficeId
asset.getAttribute("geoStreet").get().getValueAsString().get() == "Torenallee 20"
@@ -265,7 +255,7 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
assets = assetStorageService.findAll(
new AssetQuery()
.parent(new ParentPredicate(true))
- .tenant(new TenantPredicate(keycloakDemoSetup.masterTenant.id))
+ .tenant(new TenantPredicate(keycloakDemoSetup.masterTenant.realm))
)
then: "result should match"
@@ -278,9 +268,7 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
assets.get(0).parentId == null
assets.get(0).parentName == null
assets.get(0).parentType == null
- assets.get(0).realmId == keycloakDemoSetup.masterTenant.id
- assets.get(0).tenantRealm == keycloakDemoSetup.masterTenant.realm
- assets.get(0).tenantDisplayName == keycloakDemoSetup.masterTenant.displayName
+ assets.get(0).realm == keycloakDemoSetup.masterTenant.realm
assets.get(0).path == null
assets.get(0).attributesList.size() == 0
@@ -289,7 +277,7 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
new AssetQuery()
.select(new Select(Include.ALL))
.parent(new ParentPredicate(true))
- .tenant(new TenantPredicate(keycloakDemoSetup.masterTenant.id))
+ .tenant(new TenantPredicate(keycloakDemoSetup.masterTenant.realm))
)
then: "result should match"
@@ -302,9 +290,7 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
assets.get(0).parentId == null
assets.get(0).parentName == null
assets.get(0).parentType == null
- assets.get(0).realmId == keycloakDemoSetup.masterTenant.id
- assets.get(0).tenantRealm == keycloakDemoSetup.masterTenant.realm
- assets.get(0).tenantDisplayName == keycloakDemoSetup.masterTenant.displayName
+ assets.get(0).realm == keycloakDemoSetup.masterTenant.realm
assets.get(0).path.length == 1
assets.get(0).path[0] == managerDemoSetup.smartOfficeId
assets.get(0).getAttribute("geoStreet").get().getValueAsString().get() == "Torenallee 20"
@@ -324,9 +310,7 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
assets.get(0).parentId == managerDemoSetup.smartBuildingId
assets.get(0).parentName == "Smart Building"
assets.get(0).parentType == AssetType.BUILDING.value
- assets.get(0).realmId == keycloakDemoSetup.tenantA.id
- assets.get(0).tenantRealm == keycloakDemoSetup.tenantA.realm
- assets.get(0).tenantDisplayName == keycloakDemoSetup.tenantA.displayName
+ assets.get(0).realm == keycloakDemoSetup.tenantA.realm
assets.get(0).path == null
assets.get(0).attributesList.size() == 0
assets.get(1).id == managerDemoSetup.apartment2Id
@@ -336,7 +320,7 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
assets = assetStorageService.findAll(
new AssetQuery()
.parent(new ParentPredicate(managerDemoSetup.smartBuildingId))
- .tenant(new TenantPredicate(keycloakDemoSetup.tenantA.id))
+ .tenant(new TenantPredicate(keycloakDemoSetup.tenantA.realm))
)
then: "result should match"
@@ -349,7 +333,7 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
assets = assetStorageService.findAll(
new AssetQuery()
.parent(new ParentPredicate(managerDemoSetup.smartBuildingId))
- .tenant(new TenantPredicate(keycloakDemoSetup.tenantA.id))
+ .tenant(new TenantPredicate(keycloakDemoSetup.tenantA.realm))
.orderBy(new OrderBy(NAME, true))
)
@@ -363,7 +347,7 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
assets = assetStorageService.findAll(
new AssetQuery()
.parent(new ParentPredicate(managerDemoSetup.smartBuildingId))
- .tenant(new TenantPredicate(keycloakDemoSetup.masterTenant.id))
+ .tenant(new TenantPredicate(keycloakDemoSetup.masterTenant.realm))
)
then: "result should match"
@@ -477,7 +461,7 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
when: "a query is executed"
assets = assetStorageService.findAll(
new AssetQuery()
- .tenant(new TenantPredicate(keycloakDemoSetup.masterTenant.id))
+ .tenant(new TenantPredicate(keycloakDemoSetup.masterTenant.realm))
.attributeMeta(new AttributeMetaPredicate(AssetMeta.STORE_DATA_POINTS, new BooleanPredicate(true)))
)
@@ -575,7 +559,7 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
managerDemoSetup.agentId,
managerDemoSetup.agentProtocolConfigName
)
- ).tenant(new TenantPredicate().realm(keycloakDemoSetup.masterTenant.realm))
+ ).tenant(new TenantPredicate(keycloakDemoSetup.masterTenant.realm))
)
then: "result should match"
@@ -598,9 +582,7 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
asset.parentId != null
asset.parentName == "Apartment 1"
asset.parentType == AssetType.RESIDENCE.getValue()
- asset.realmId == keycloakDemoSetup.tenantA.id
- asset.tenantRealm == keycloakDemoSetup.tenantA.realm
- asset.tenantDisplayName == keycloakDemoSetup.tenantA.displayName
+ asset.realm == keycloakDemoSetup.tenantA.realm
asset.path != null
asset.getAttributesList().size() == 3
asset.getAttribute("co2Level").isPresent()
@@ -626,9 +608,7 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
asset.parentId != null
asset.parentName == "Apartment 1"
asset.parentType == AssetType.RESIDENCE.getValue()
- asset.realmId == keycloakDemoSetup.tenantA.id
- asset.tenantRealm == keycloakDemoSetup.tenantA.realm
- asset.tenantDisplayName == keycloakDemoSetup.tenantA.displayName
+ asset.realm == keycloakDemoSetup.tenantA.realm
asset.path != null
asset.getAttributesList().size() == 1
asset.getAttribute("co2Level").isPresent()
@@ -667,7 +647,7 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
new AssetQuery()
.select(new Select(Include.ONLY_ID_AND_NAME))
.attributes(new LocationAttributePredicate(new RadialGeofencePredicate(10, 51.44541688237109d, 5.460315214821094d)))
- .tenant(new TenantPredicate(keycloakDemoSetup.masterTenant.id))
+ .tenant(new TenantPredicate(keycloakDemoSetup.masterTenant.realm))
.orderBy(new OrderBy(NAME))
)
@@ -699,7 +679,7 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
new AssetQuery()
.select(new Select(Include.ONLY_ID_AND_NAME))
.attributes(new LocationAttributePredicate(new RadialGeofencePredicate(10, 51.44541688237109d, 5.460315214821094d)))
- .tenant(new TenantPredicate(keycloakDemoSetup.masterTenant.id))
+ .tenant(new TenantPredicate(keycloakDemoSetup.masterTenant.realm))
.orderBy(new OrderBy(NAME))
)
@@ -712,7 +692,7 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
new AssetQuery()
.select(new Select(Include.ONLY_ID_AND_NAME))
.attributes(new LocationAttributePredicate(new RectangularGeofencePredicate(51.44540d, 5.46031d, 51.44594d, 5.46110d)))
- .tenant(new TenantPredicate(keycloakDemoSetup.masterTenant.id))
+ .tenant(new TenantPredicate(keycloakDemoSetup.masterTenant.realm))
.orderBy(new OrderBy(NAME))
)
@@ -734,7 +714,7 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
new AssetQuery()
.select(new Select(Include.ONLY_ID_AND_NAME))
.attributes(new LocationAttributePredicate(new RectangularGeofencePredicate(51.44542d, 5.46032d, 51.44590d, 5.46100d)))
- .tenant(new TenantPredicate(keycloakDemoSetup.masterTenant.id))
+ .tenant(new TenantPredicate(keycloakDemoSetup.masterTenant.realm))
.orderBy(new OrderBy(NAME))
)
@@ -746,7 +726,7 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
new AssetQuery()
.select(new Select(Include.ONLY_ID_AND_NAME))
.attributes(new LocationAttributePredicate(new RectangularGeofencePredicate(51.44542d, 5.46032d, 51.44590d, 5.46100d).negate()))
- .tenant(new TenantPredicate(keycloakDemoSetup.masterTenant.id))
+ .tenant(new TenantPredicate(keycloakDemoSetup.masterTenant.realm))
.orderBy(new OrderBy(NAME))
)
@@ -791,7 +771,7 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
def assets = assetStorageService.findAll(
new AssetQuery()
.select(new Select(Include.ALL_EXCEPT_PATH)) // Need attributes to do calendar filtering
- .tenant(new TenantPredicate(keycloakDemoSetup.masterTenant.id))
+ .tenant(new TenantPredicate(keycloakDemoSetup.masterTenant.realm))
.calendarEventActive(1517155200) // 28/01/2018 @ 4:00pm (UTC)
.orderBy(new OrderBy(NAME))
)
@@ -813,7 +793,7 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
assets = assetStorageService.findAll(
new AssetQuery()
.select(new Select(Include.ALL_EXCEPT_PATH))
- .tenant(new TenantPredicate(keycloakDemoSetup.masterTenant.id))
+ .tenant(new TenantPredicate(keycloakDemoSetup.masterTenant.realm))
.calendarEventActive(1517335200) // 30/01/2018 @ 6:00pm (UTC)
.orderBy(new OrderBy(NAME))
)
@@ -826,7 +806,7 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
assets = assetStorageService.findAll(
new AssetQuery()
.select(new Select(Include.ALL_EXCEPT_PATH))
- .tenant(new TenantPredicate(keycloakDemoSetup.masterTenant.id))
+ .tenant(new TenantPredicate(keycloakDemoSetup.masterTenant.realm))
.calendarEventActive(1517238600) // 29/01/2018 @ 3:10pm (UTC)
.orderBy(new OrderBy(NAME))
)
@@ -839,7 +819,7 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
assets = assetStorageService.findAll(
new AssetQuery()
.select(new Select(Include.ALL_EXCEPT_PATH)) // Need attributes to do calendar filtering
- .tenant(new TenantPredicate(keycloakDemoSetup.masterTenant.id))
+ .tenant(new TenantPredicate(keycloakDemoSetup.masterTenant.realm))
.calendarEventActive(1517849400) // 05/02/2018 @ 4:50pm (UTC))
.orderBy(new OrderBy(NAME))
)
@@ -861,7 +841,7 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
assets = assetStorageService.findAll(
new AssetQuery()
.select(new Select(Include.ALL_EXCEPT_PATH))
- .tenant(new TenantPredicate(keycloakDemoSetup.masterTenant.id))
+ .tenant(new TenantPredicate(keycloakDemoSetup.masterTenant.realm))
.calendarEventActive(1518017520) // 02/07/2018 @ 3:32pm (UTC)
.orderBy(new OrderBy(NAME))
)
@@ -885,7 +865,7 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
def assets = assetStorageService.findAll(
new AssetQuery()
- .tenant(new TenantPredicate(keycloakDemoSetup.masterTenant.id))
+ .tenant(new TenantPredicate(keycloakDemoSetup.masterTenant.realm))
.attributeValue(
"openingDate",
new DateTimePredicate(rangeStart.format(ISO_LOCAL_DATE_TIME), rangeEnd.format(ISO_LOCAL_DATE_TIME))
@@ -901,7 +881,7 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
when: "the lobby has an opening date and the date is after the filtering date"
assets = assetStorageService.findAll(
new AssetQuery()
- .tenant(new TenantPredicate(keycloakDemoSetup.masterTenant.id))
+ .tenant(new TenantPredicate(keycloakDemoSetup.masterTenant.realm))
.attributeValue(
"openingDate",
new DateTimePredicate(Operator.GREATER_THAN, rangeStart.format(ISO_LOCAL_DATE_TIME))
@@ -916,7 +896,7 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
when: "the lobby has an opening date and the date is before the filtering date"
assets = assetStorageService.findAll(
new AssetQuery()
- .tenant(new TenantPredicate(keycloakDemoSetup.masterTenant.id))
+ .tenant(new TenantPredicate(keycloakDemoSetup.masterTenant.realm))
.attributeValue(
"openingDate",
new DateTimePredicate(Operator.LESS_THAN, rangeEnd.format(ISO_LOCAL_DATE_TIME))
@@ -933,7 +913,7 @@ class AssetQueryTest extends Specification implements ManagerContainerTrait {
assets = assetStorageService.findAll(
new AssetQuery()
- .tenant(new TenantPredicate(keycloakDemoSetup.masterTenant.id))
+ .tenant(new TenantPredicate(keycloakDemoSetup.masterTenant.realm))
.attributeValue(
"openingDate",
new DateTimePredicate(Operator.EQUALS, rangeStart.format(ISO_LOCAL_DATE_TIME))
diff --git a/test/src/test/groovy/org/openremote/test/assets/AssetUserLinkingTest.groovy b/test/src/test/groovy/org/openremote/test/assets/AssetUserLinkingTest.groovy
index cf4eb367f..cc1515dd0 100644
--- a/test/src/test/groovy/org/openremote/test/assets/AssetUserLinkingTest.groovy
+++ b/test/src/test/groovy/org/openremote/test/assets/AssetUserLinkingTest.groovy
@@ -48,12 +48,12 @@ class AssetUserLinkingTest extends Specification implements ManagerContainerTrai
identityService.getIdentityProvider().isRestrictedUser(keycloakDemoSetup.testuser3Id)
when: "all user assets are retrieved of a realm"
- def userAssets = assetResource.getUserAssetLinks(null, keycloakDemoSetup.tenantA.id, null, null)
+ def userAssets = assetResource.getUserAssetLinks(null, keycloakDemoSetup.tenantA.realm, null, null)
then: "result should match"
userAssets.length == 6
userAssets.any {
- it.id.realmId == keycloakDemoSetup.tenantA.id &&
+ it.id.realm == keycloakDemoSetup.tenantA.realm &&
it.id.userId == keycloakDemoSetup.testuser3Id &&
it.id.assetId == managerDemoSetup.apartment1Id &&
it.assetName == "Apartment 1" &&
@@ -61,7 +61,7 @@ class AssetUserLinkingTest extends Specification implements ManagerContainerTrai
it.userFullName == "testuser3 (DemoA3 DemoLast)"
}
userAssets.any {
- it.id.realmId == keycloakDemoSetup.tenantA.id &&
+ it.id.realm == keycloakDemoSetup.tenantA.realm &&
it.id.userId == keycloakDemoSetup.testuser3Id &&
it.id.assetId == managerDemoSetup.apartment1LivingroomId &&
it.assetName == "Living Room" &&
@@ -69,7 +69,7 @@ class AssetUserLinkingTest extends Specification implements ManagerContainerTrai
it.userFullName == "testuser3 (DemoA3 DemoLast)"
}
userAssets.any {
- it.id.realmId == keycloakDemoSetup.tenantA.id &&
+ it.id.realm == keycloakDemoSetup.tenantA.realm &&
it.id.userId == keycloakDemoSetup.testuser3Id &&
it.id.assetId == managerDemoSetup.apartment1KitchenId &&
it.assetName == "Kitchen" &&
@@ -77,7 +77,7 @@ class AssetUserLinkingTest extends Specification implements ManagerContainerTrai
it.userFullName == "testuser3 (DemoA3 DemoLast)"
}
userAssets.any {
- it.id.realmId == keycloakDemoSetup.tenantA.id &&
+ it.id.realm == keycloakDemoSetup.tenantA.realm &&
it.id.userId == keycloakDemoSetup.testuser3Id &&
it.id.assetId == managerDemoSetup.apartment1HallwayId &&
it.assetName == "Hallway" &&
@@ -85,7 +85,7 @@ class AssetUserLinkingTest extends Specification implements ManagerContainerTrai
it.userFullName == "testuser3 (DemoA3 DemoLast)"
}
userAssets.any {
- it.id.realmId == keycloakDemoSetup.tenantA.id &&
+ it.id.realm == keycloakDemoSetup.tenantA.realm &&
it.id.userId == keycloakDemoSetup.testuser3Id &&
it.id.assetId == managerDemoSetup.apartment1Bedroom1Id &&
it.assetName == "Bedroom" &&
@@ -93,7 +93,7 @@ class AssetUserLinkingTest extends Specification implements ManagerContainerTrai
it.userFullName == "testuser3 (DemoA3 DemoLast)"
}
userAssets.any {
- it.id.realmId == keycloakDemoSetup.tenantA.id &&
+ it.id.realm == keycloakDemoSetup.tenantA.realm &&
it.id.userId == keycloakDemoSetup.testuser3Id &&
it.id.assetId == managerDemoSetup.apartment1BathroomId &&
it.assetName == "Bathroom" &&
@@ -102,13 +102,13 @@ class AssetUserLinkingTest extends Specification implements ManagerContainerTrai
}
when: "all user assets are retrieved of a realm and user"
- userAssets = assetResource.getUserAssetLinks(null, keycloakDemoSetup.tenantA.id, keycloakDemoSetup.testuser3Id, null)
+ userAssets = assetResource.getUserAssetLinks(null, keycloakDemoSetup.tenantA.realm, keycloakDemoSetup.testuser3Id, null)
then: "result should match"
userAssets.length == 6
when: "the realm and user don't match"
- assetResource.getUserAssetLinks(null, keycloakDemoSetup.tenantB.id, keycloakDemoSetup.testuser3Id, null)
+ assetResource.getUserAssetLinks(null, keycloakDemoSetup.tenantB.realm, keycloakDemoSetup.testuser3Id, null)
then: "an error response should be returned"
WebApplicationException ex = thrown()
@@ -122,12 +122,12 @@ class AssetUserLinkingTest extends Specification implements ManagerContainerTrai
ex.response.status == 404
when: "all user assets are retrieved of a realm and user"
- userAssets = assetResource.getUserAssetLinks(null, keycloakDemoSetup.tenantA.id, null, managerDemoSetup.apartment1Id)
+ userAssets = assetResource.getUserAssetLinks(null, keycloakDemoSetup.tenantA.realm, null, managerDemoSetup.apartment1Id)
then: "result should match"
userAssets.length == 1
userAssets.any {
- it.id.realmId == keycloakDemoSetup.tenantA.id &&
+ it.id.realm == keycloakDemoSetup.tenantA.realm &&
it.id.userId == keycloakDemoSetup.testuser3Id &&
it.id.assetId == managerDemoSetup.apartment1Id &&
it.assetName == "Apartment 1" &&
@@ -136,12 +136,12 @@ class AssetUserLinkingTest extends Specification implements ManagerContainerTrai
}
when: "all user assets are retrieved of a realm and user and asset"
- userAssets = assetResource.getUserAssetLinks(null, keycloakDemoSetup.tenantA.id, keycloakDemoSetup.testuser3Id, managerDemoSetup.apartment1Id)
+ userAssets = assetResource.getUserAssetLinks(null, keycloakDemoSetup.tenantA.realm, keycloakDemoSetup.testuser3Id, managerDemoSetup.apartment1Id)
then: "result should match"
userAssets.length == 1
userAssets.any {
- it.id.realmId == keycloakDemoSetup.tenantA.id &&
+ it.id.realm == keycloakDemoSetup.tenantA.realm &&
it.id.userId == keycloakDemoSetup.testuser3Id &&
it.id.assetId == managerDemoSetup.apartment1Id &&
it.assetName == "Apartment 1" &&
@@ -150,7 +150,7 @@ class AssetUserLinkingTest extends Specification implements ManagerContainerTrai
}
when: "all user assets are retrieved of a realm and user and asset"
- userAssets = assetResource.getUserAssetLinks(null, keycloakDemoSetup.tenantA.id, keycloakDemoSetup.testuser2Id, managerDemoSetup.apartment1Id)
+ userAssets = assetResource.getUserAssetLinks(null, keycloakDemoSetup.tenantA.realm, keycloakDemoSetup.testuser2Id, managerDemoSetup.apartment1Id)
then: "result should match"
userAssets.length == 0
@@ -158,14 +158,14 @@ class AssetUserLinkingTest extends Specification implements ManagerContainerTrai
/* ############################################## WRITE ####################################### */
when: "an asset is linked to a user"
- UserAsset userAsset = new UserAsset(keycloakDemoSetup.tenantA.id, keycloakDemoSetup.testuser2Id, managerDemoSetup.apartment2Id)
+ UserAsset userAsset = new UserAsset(keycloakDemoSetup.tenantA.realm, keycloakDemoSetup.testuser2Id, managerDemoSetup.apartment2Id)
assetResource.createUserAsset(null, userAsset)
- userAssets = assetResource.getUserAssetLinks(null, keycloakDemoSetup.tenantA.id, keycloakDemoSetup.testuser2Id, null)
+ userAssets = assetResource.getUserAssetLinks(null, keycloakDemoSetup.tenantA.realm, keycloakDemoSetup.testuser2Id, null)
then: "result should match"
userAssets.length == 1
userAssets.any {
- it.id.realmId == keycloakDemoSetup.tenantA.id &&
+ it.id.realm == keycloakDemoSetup.tenantA.realm &&
it.id.userId == keycloakDemoSetup.testuser2Id &&
it.id.assetId == managerDemoSetup.apartment2Id &&
it.assetName == "Apartment 2" &&
@@ -175,8 +175,8 @@ class AssetUserLinkingTest extends Specification implements ManagerContainerTrai
}
when: "an asset link is deleted"
- assetResource.deleteUserAsset(null, keycloakDemoSetup.tenantA.id, keycloakDemoSetup.testuser2Id, managerDemoSetup.apartment2Id)
- userAssets = assetResource.getUserAssetLinks(null, keycloakDemoSetup.tenantA.id, keycloakDemoSetup.testuser2Id, null)
+ assetResource.deleteUserAsset(null, keycloakDemoSetup.tenantA.realm, keycloakDemoSetup.testuser2Id, managerDemoSetup.apartment2Id)
+ userAssets = assetResource.getUserAssetLinks(null, keycloakDemoSetup.tenantA.realm, keycloakDemoSetup.testuser2Id, null)
then: "result should match"
userAssets.length == 0
diff --git a/test/src/test/groovy/org/openremote/test/console/ConsoleTest.groovy b/test/src/test/groovy/org/openremote/test/console/ConsoleTest.groovy
index 0c13ae48e..0dd807d39 100644
--- a/test/src/test/groovy/org/openremote/test/console/ConsoleTest.groovy
+++ b/test/src/test/groovy/org/openremote/test/console/ConsoleTest.groovy
@@ -98,7 +98,7 @@ class ConsoleTest extends Specification implements ManagerContainerTrait {
and: "the demo location predicate console rules are loaded"
Ruleset ruleset = new TenantRuleset(
"Demo Tenant A - Console Location",
- keycloakDemoSetup.tenantA.id,
+ keycloakDemoSetup.tenantA.realm,
getClass().getResource("/demo/rules/DemoConsoleLocation.groovy").text,
Ruleset.Lang.GROOVY
)
@@ -106,7 +106,7 @@ class ConsoleTest extends Specification implements ManagerContainerTrait {
expect: "the rule engine to become available and be running"
conditions.eventually {
- def tenantAEngine = rulesService.tenantEngines.get(keycloakDemoSetup.tenantA.id)
+ def tenantAEngine = rulesService.tenantEngines.get(keycloakDemoSetup.tenantA.realm)
assert tenantAEngine != null
assert tenantAEngine.isRunning()
assert tenantAEngine.assetStates.size() == DEMO_RULE_STATES_CUSTOMER_A
@@ -185,7 +185,7 @@ class ConsoleTest extends Specification implements ManagerContainerTrait {
}.orElse(null) == "23123213ad2313b0897efd"
and: "the console should have been linked to the authenticated user"
- def userAssets = assetStorageService.findUserAssets(keycloakDemoSetup.tenantA.id, keycloakDemoSetup.testuser3Id, consoleId)
+ def userAssets = assetStorageService.findUserAssets(keycloakDemoSetup.tenantA.realm, keycloakDemoSetup.testuser3Id, consoleId)
assert userAssets.size() == 1
assert userAssets.get(0).assetName == "Test Console"
@@ -412,7 +412,7 @@ class ConsoleTest extends Specification implements ManagerContainerTrait {
assert asset != null
assert asset.getAttribute(LOCATION.name).flatMap { it.valueTimestamp }.orElse(Long.MIN_VALUE) > timestamp
assert notificationIds.size() == 1
- def tenantAEngine = rulesService.tenantEngines.get(keycloakDemoSetup.tenantA.id)
+ def tenantAEngine = rulesService.tenantEngines.get(keycloakDemoSetup.tenantA.realm)
assert tenantAEngine != null
assert tenantAEngine.isRunning()
assert !tenantAEngine.facts.getOptional("welcomeHome_${testUser3Console2.id}").isPresent()
diff --git a/test/src/test/groovy/org/openremote/test/notification/NotificationTest.groovy b/test/src/test/groovy/org/openremote/test/notification/NotificationTest.groovy
index e9e80724b..6beb0d89f 100644
--- a/test/src/test/groovy/org/openremote/test/notification/NotificationTest.groovy
+++ b/test/src/test/groovy/org/openremote/test/notification/NotificationTest.groovy
@@ -175,7 +175,7 @@ class NotificationTest extends Specification implements ManagerContainerTrait {
anonymousConsole.id != null
when: "the admin user sends a push notification to an entire realm"
- notification.targets = new Notification.Targets(Notification.TargetType.TENANT, keycloakDemoSetup.tenantA.id)
+ notification.targets = new Notification.Targets(Notification.TargetType.TENANT, keycloakDemoSetup.tenantA.realm)
adminNotificationResource.sendNotification(null, notification)
then: "all consoles in that realm should have been sent a notification"
@@ -577,8 +577,8 @@ class NotificationTest extends Specification implements ManagerContainerTrait {
def notification = new Notification(
"Test",
new EmailNotificationMessage().setSubject("Test").setText("Hello world!"),
- new Notification.Targets(Notification.TargetType.TENANT, managerDemoSetup.realmATenantId), null, null)
- notificationService.sendNotification(notification, Notification.Source.TENANT_RULESET, managerDemoSetup.realmATenantId)
+ new Notification.Targets(Notification.TargetType.TENANT, managerDemoSetup.realmATenant), null, null)
+ notificationService.sendNotification(notification, Notification.Source.TENANT_RULESET, managerDemoSetup.realmATenant)
then: "the email should have been sent to all tenant users"
conditions.eventually {
diff --git a/test/src/test/groovy/org/openremote/test/protocol/BasicProtocolTest.groovy b/test/src/test/groovy/org/openremote/test/protocol/BasicProtocolTest.groovy
index b174da378..ce1410cc1 100644
--- a/test/src/test/groovy/org/openremote/test/protocol/BasicProtocolTest.groovy
+++ b/test/src/test/groovy/org/openremote/test/protocol/BasicProtocolTest.groovy
@@ -194,7 +194,7 @@ class BasicProtocolTest extends Specification implements ManagerContainerTrait,
new MetaItem(AssetMeta.DISABLED, Values.create(true))
)
)
- mockAgent.setRealmId(MASTER_REALM)
+ mockAgent.setRealm(MASTER_REALM)
mockAgent = assetStorageService.merge(mockAgent)
then: "the protocol configurations should be linked and their deployment status should be available in the agent service"
diff --git a/test/src/test/groovy/org/openremote/test/protocol/KNXImportTest.groovy b/test/src/test/groovy/org/openremote/test/protocol/KNXImportTest.groovy
index f4b748598..dc5c76d1e 100644
--- a/test/src/test/groovy/org/openremote/test/protocol/KNXImportTest.groovy
+++ b/test/src/test/groovy/org/openremote/test/protocol/KNXImportTest.groovy
@@ -69,7 +69,7 @@ class KNXImportTest extends Specification implements ManagerContainerTrait {
knxAgent.setAttributes(
ProtocolConfiguration.initProtocolConfiguration(new AssetAttribute("knxConfigError1"), KNXProtocol.PROTOCOL_NAME)
)
- knxAgent.setRealmId(Constants.MASTER_REALM)
+ knxAgent.setRealm(Constants.MASTER_REALM)
knxAgent = assetStorageService.merge(knxAgent)
then: "the protocol configurations should be linked and their deployment status should be available in the agent service"
diff --git a/test/src/test/groovy/org/openremote/test/protocol/KNXProtocolTest.groovy b/test/src/test/groovy/org/openremote/test/protocol/KNXProtocolTest.groovy
index b3a361fee..9955aed49 100644
--- a/test/src/test/groovy/org/openremote/test/protocol/KNXProtocolTest.groovy
+++ b/test/src/test/groovy/org/openremote/test/protocol/KNXProtocolTest.groovy
@@ -104,7 +104,7 @@ class KNXProtocolTest extends Specification implements ManagerContainerTrait {
new MetaItem(KNXProtocol.META_KNX_IP_CONNECTION_TYPE, Values.create("dummy"))
)
)
- knxAgent.setRealmId(Constants.MASTER_REALM)
+ knxAgent.setRealm(Constants.MASTER_REALM)
knxAgent = assetStorageService.merge(knxAgent)
then: "the protocol configurations should be linked and their deployment status should be available in the agent service"
diff --git a/test/src/test/groovy/org/openremote/test/protocol/controller/ControllerProtocolTest.groovy b/test/src/test/groovy/org/openremote/test/protocol/controller/ControllerProtocolTest.groovy
index ee51949d5..0d744fbde 100644
--- a/test/src/test/groovy/org/openremote/test/protocol/controller/ControllerProtocolTest.groovy
+++ b/test/src/test/groovy/org/openremote/test/protocol/controller/ControllerProtocolTest.groovy
@@ -198,7 +198,7 @@ class ControllerProtocolTest extends Specification implements ManagerContainerTr
and: "an agent with a Controller protocol configuration is created"
def agent = new Asset()
- agent.setRealmId(Constants.MASTER_REALM)
+ agent.setRealm(Constants.MASTER_REALM)
agent.setName("Test Agent")
agent.setType(AssetType.AGENT)
agent.setAttributes(
diff --git a/test/src/test/groovy/org/openremote/test/protocol/http/HttpClientProtocolTest.groovy b/test/src/test/groovy/org/openremote/test/protocol/http/HttpClientProtocolTest.groovy
index a095cc2d2..e1b836016 100644
--- a/test/src/test/groovy/org/openremote/test/protocol/http/HttpClientProtocolTest.groovy
+++ b/test/src/test/groovy/org/openremote/test/protocol/http/HttpClientProtocolTest.groovy
@@ -299,7 +299,7 @@ class HttpClientProtocolTest extends Specification implements ManagerContainerTr
and: "an agent with a HTTP client protocol configuration is created"
def agent = new Asset()
- agent.setRealmId(Constants.MASTER_REALM)
+ agent.setRealm(Constants.MASTER_REALM)
agent.setName("Test Agent")
agent.setType(AssetType.AGENT)
agent.setAttributes(
diff --git a/test/src/test/groovy/org/openremote/test/protocol/http/HttpServerProtocolTest.groovy b/test/src/test/groovy/org/openremote/test/protocol/http/HttpServerProtocolTest.groovy
index 67a119cf6..3c6845191 100644
--- a/test/src/test/groovy/org/openremote/test/protocol/http/HttpServerProtocolTest.groovy
+++ b/test/src/test/groovy/org/openremote/test/protocol/http/HttpServerProtocolTest.groovy
@@ -39,7 +39,6 @@ import spock.lang.Specification
import spock.util.concurrent.PollingConditions
import javax.ws.rs.ForbiddenException
-import javax.ws.rs.ProcessingException
import javax.ws.rs.HttpMethod
import javax.ws.rs.client.ClientRequestContext
import javax.ws.rs.client.ClientRequestFilter
@@ -303,7 +302,7 @@ class HttpServerProtocolTest extends Specification implements ManagerContainerTr
when: "an agent with a test HTTP server protocol configuration is created"
def agent = new Asset()
- agent.setRealmId(MASTER_REALM)
+ agent.setRealm(MASTER_REALM)
agent.setName("Test Agent")
agent.setType(AssetType.AGENT)
agent.setAttributes(
diff --git a/test/src/test/groovy/org/openremote/test/protocol/velbus/VelbusProtocolTest.groovy b/test/src/test/groovy/org/openremote/test/protocol/velbus/VelbusProtocolTest.groovy
index fb0aa88e0..a47a7133d 100644
--- a/test/src/test/groovy/org/openremote/test/protocol/velbus/VelbusProtocolTest.groovy
+++ b/test/src/test/groovy/org/openremote/test/protocol/velbus/VelbusProtocolTest.groovy
@@ -99,7 +99,7 @@ class VelbusProtocolTest extends Specification implements ManagerContainerTrait
and: "a VELBUS agent is created"
def agent = new Asset("VELBUS", AssetType.AGENT)
- agent.setRealmId(MASTER_REALM)
+ agent.setRealm(MASTER_REALM)
agent.setType(AssetType.AGENT)
agent.setAttributes(
initProtocolConfiguration(new AssetAttribute("protocolConfig"), velbusProtocol.getProtocolName())
@@ -160,7 +160,7 @@ class VelbusProtocolTest extends Specification implements ManagerContainerTrait
and: "a VELBUS agent is created"
def agent = new Asset("VELBUS", AssetType.AGENT)
- agent.setRealmId(MASTER_REALM)
+ agent.setRealm(MASTER_REALM)
agent.setType(AssetType.AGENT)
agent.setAttributes(
initProtocolConfiguration(new AssetAttribute("protocolConfig"), VelbusSerialProtocol.PROTOCOL_NAME)
diff --git a/test/src/test/groovy/org/openremote/test/rules/BasicRulesDeploymentTest.groovy b/test/src/test/groovy/org/openremote/test/rules/BasicRulesDeploymentTest.groovy
index 8212d18da..5a3c21ce1 100644
--- a/test/src/test/groovy/org/openremote/test/rules/BasicRulesDeploymentTest.groovy
+++ b/test/src/test/groovy/org/openremote/test/rules/BasicRulesDeploymentTest.groovy
@@ -74,7 +74,7 @@ class BasicRulesDeploymentTest extends Specification implements ManagerContainer
when: "a new tenant rule definition is added to Tenant A"
ruleset = new TenantRuleset(
"Some more tenantA tenant rules",
- keycloakDemoSetup.tenantA.id,
+ keycloakDemoSetup.tenantA.realm,
getClass().getResource("/org/openremote/test/rules/BasicMatchAllAssetStates2.groovy").text,
GROOVY
)
@@ -82,7 +82,7 @@ class BasicRulesDeploymentTest extends Specification implements ManagerContainer
then: "Tenant A rules engine should load this definition and restart successfully"
conditions.eventually {
- def tenantAEngine = rulesService.tenantEngines.get(keycloakDemoSetup.tenantA.id)
+ def tenantAEngine = rulesService.tenantEngines.get(keycloakDemoSetup.tenantA.realm)
assert tenantAEngine != null
assert tenantAEngine.isRunning()
assert tenantAEngine.deployments.size() == 2
@@ -93,7 +93,7 @@ class BasicRulesDeploymentTest extends Specification implements ManagerContainer
when: "a new tenant rule definition is added to Tenant B"
ruleset = new TenantRuleset(
"Some more tenantB tenant rules",
- keycloakDemoSetup.tenantB.id,
+ keycloakDemoSetup.tenantB.realm,
getClass().getResource("/org/openremote/test/rules/BasicMatchAllAssetStates2.groovy").text,
GROOVY
)
@@ -101,7 +101,7 @@ class BasicRulesDeploymentTest extends Specification implements ManagerContainer
then: "a tenant rules engine should be created for Tenant B and load this definition and start successfully"
conditions.eventually {
- def tenantBEngine = rulesService.tenantEngines.get(keycloakDemoSetup.tenantB.id)
+ def tenantBEngine = rulesService.tenantEngines.get(keycloakDemoSetup.tenantB.realm)
assert rulesService.tenantEngines.size() == 3
assert tenantBEngine != null
assert tenantBEngine.isRunning()
@@ -116,7 +116,7 @@ class BasicRulesDeploymentTest extends Specification implements ManagerContainer
then: "Tenant B rule engine should load this definition and restart successfully"
conditions.eventually {
- def tenantBEngine = rulesService.tenantEngines.get(keycloakDemoSetup.tenantB.id)
+ def tenantBEngine = rulesService.tenantEngines.get(keycloakDemoSetup.tenantB.realm)
assert rulesService.tenantEngines.size() == 3
assert tenantBEngine != null
assert tenantBEngine.isRunning()
@@ -133,7 +133,7 @@ class BasicRulesDeploymentTest extends Specification implements ManagerContainer
then: "Tenant B rule engine should remove it again"
conditions.eventually {
- def tenantBEngine = rulesService.tenantEngines.get(keycloakDemoSetup.tenantB.id)
+ def tenantBEngine = rulesService.tenantEngines.get(keycloakDemoSetup.tenantB.realm)
assert tenantBEngine != null
assert tenantBEngine.isRunning()
assert tenantBEngine.deployments.size() == 1
@@ -185,7 +185,7 @@ class BasicRulesDeploymentTest extends Specification implements ManagerContainer
}
when: "a tenant is disabled"
- def tenantAEngine = rulesService.tenantEngines.get(keycloakDemoSetup.tenantA.id)
+ def tenantAEngine = rulesService.tenantEngines.get(keycloakDemoSetup.tenantA.realm)
def apartment3Engine = rulesService.assetEngines.get(managerDemoSetup.apartment3Id)
def tenantATenant = keycloakDemoSetup.tenantA
tenantATenant.setEnabled(false)
@@ -195,7 +195,7 @@ class BasicRulesDeploymentTest extends Specification implements ManagerContainer
conditions.eventually {
assert tenantAEngine.isRunning() == false
assert tenantAEngine.deployments.size() == 2
- assert rulesService.tenantEngines.get(keycloakDemoSetup.tenantA.id) == null
+ assert rulesService.tenantEngines.get(keycloakDemoSetup.tenantA.realm) == null
assert apartment3Engine.isRunning() == false
assert apartment3Engine.deployments.size() == 1
assert rulesService.assetEngines.get(managerDemoSetup.apartment3Id) == null
@@ -205,8 +205,8 @@ class BasicRulesDeploymentTest extends Specification implements ManagerContainer
conditions.eventually {
assert rulesService.tenantEngines.size() == 2
assert rulesService.assetEngines.size() == 1
- def masterEngine = rulesService.tenantEngines.get(keycloakDemoSetup.masterTenant.id)
- def tenantBEngine = rulesService.tenantEngines.get(keycloakDemoSetup.tenantB.id)
+ def masterEngine = rulesService.tenantEngines.get(keycloakDemoSetup.masterTenant.realm)
+ def tenantBEngine = rulesService.tenantEngines.get(keycloakDemoSetup.tenantB.realm)
assert masterEngine != null
assert masterEngine.isRunning()
assert tenantBEngine != null
@@ -219,7 +219,7 @@ class BasicRulesDeploymentTest extends Specification implements ManagerContainer
then: "the tenants rule engine should start and all asset rule engines from this realm should also start"
conditions.eventually {
- tenantAEngine = rulesService.tenantEngines.get(keycloakDemoSetup.tenantA.id)
+ tenantAEngine = rulesService.tenantEngines.get(keycloakDemoSetup.tenantA.realm)
apartment3Engine = rulesService.assetEngines.get(managerDemoSetup.apartment3Id)
assert rulesService.tenantEngines.size() == 3
assert rulesService.assetEngines.size() == 2
diff --git a/test/src/test/groovy/org/openremote/test/rules/BasicRulesImport.groovy b/test/src/test/groovy/org/openremote/test/rules/BasicRulesImport.groovy
index 91eacd234..82cfabd46 100644
--- a/test/src/test/groovy/org/openremote/test/rules/BasicRulesImport.groovy
+++ b/test/src/test/groovy/org/openremote/test/rules/BasicRulesImport.groovy
@@ -52,7 +52,7 @@ class BasicRulesImport {
ruleset = new TenantRuleset(
"Some master tenant demo rules",
- keycloakDemoSetup.masterTenant.id,
+ keycloakDemoSetup.masterTenant.realm,
getClass().getResource("/org/openremote/test/rules/BasicMatchAllAssetStates.groovy").text,
GROOVY
)
@@ -60,7 +60,7 @@ class BasicRulesImport {
ruleset = new TenantRuleset(
"Some tenantA tenant demo rules",
- keycloakDemoSetup.tenantA.id,
+ keycloakDemoSetup.tenantA.realm,
getClass().getResource("/org/openremote/test/rules/BasicMatchAllAssetStates.groovy").text,
GROOVY
)
@@ -68,7 +68,7 @@ class BasicRulesImport {
ruleset = new TenantRuleset(
"Some tenantB tenant demo rules",
- keycloakDemoSetup.tenantB.id,
+ keycloakDemoSetup.tenantB.realm,
getClass().getResource("/org/openremote/test/rules/BasicMatchAllAssetStates.groovy").text,
GROOVY
)
@@ -113,21 +113,21 @@ class BasicRulesImport {
assert globalEngine.deployments.values().any { it -> it.name == "Some global demo rules" && it.status == DEPLOYED }
assert rulesService.tenantEngines.size() == 2
- masterEngine = rulesService.tenantEngines.get(keycloakDemoSetup.masterTenant.id)
+ masterEngine = rulesService.tenantEngines.get(keycloakDemoSetup.masterTenant.realm)
masterEngine.disableTemporaryFactExpiration = true
assert masterEngine != null
assert masterEngine.isRunning()
assert masterEngine.deployments.size() == 1
assert masterEngine.deployments.values().iterator().next().name == "Some master tenant demo rules"
assert masterEngine.deployments.values().iterator().next().status == DEPLOYED
- tenantAEngine = rulesService.tenantEngines.get(keycloakDemoSetup.tenantA.id)
+ tenantAEngine = rulesService.tenantEngines.get(keycloakDemoSetup.tenantA.realm)
assert tenantAEngine != null
tenantAEngine.disableTemporaryFactExpiration = true
assert tenantAEngine.isRunning()
assert tenantAEngine.deployments.size() == 1
assert tenantAEngine.deployments.values().iterator().next().name == "Some tenantA tenant demo rules"
assert tenantAEngine.deployments.values().iterator().next().status == DEPLOYED
- def tenantBEngine = rulesService.tenantEngines.get(keycloakDemoSetup.tenantB.id)
+ def tenantBEngine = rulesService.tenantEngines.get(keycloakDemoSetup.tenantB.realm)
assert tenantBEngine == null
assert rulesService.assetEngines.size() == 3
diff --git a/test/src/test/groovy/org/openremote/test/rules/BasicRulesProcessingTest.groovy b/test/src/test/groovy/org/openremote/test/rules/BasicRulesProcessingTest.groovy
index dc147156d..450c75c8e 100644
--- a/test/src/test/groovy/org/openremote/test/rules/BasicRulesProcessingTest.groovy
+++ b/test/src/test/groovy/org/openremote/test/rules/BasicRulesProcessingTest.groovy
@@ -211,7 +211,7 @@ class BasicRulesProcessingTest extends Specification implements ManagerContainer
rulesImport.resetRulesFired()
def apartment2 = assetStorageService.find(managerDemoSetup.apartment2Id)
def asset = new Asset("Kitchen", AssetType.ROOM, apartment2)
- asset.setRealmId(keycloakDemoSetup.tenantA.getId())
+ asset.setRealm(keycloakDemoSetup.tenantA.getRealm())
def attributes = [
new AssetAttribute("testString", AttributeValueType.STRING, Values.create("test"))
.setMeta(
@@ -378,7 +378,7 @@ class BasicRulesProcessingTest extends Specification implements ManagerContainer
when: "a broken RHS rule is loaded into the tenantA engine"
def ruleset = new TenantRuleset(
"Some broken test rules",
- keycloakDemoSetup.tenantA.id,
+ keycloakDemoSetup.tenantA.realm,
getClass().getResource("/org/openremote/test/rules/BasicBrokenRules.groovy").text,
Ruleset.Lang.GROOVY
)
diff --git a/test/src/test/groovy/org/openremote/test/rules/BasicRulesetResourceTest.groovy b/test/src/test/groovy/org/openremote/test/rules/BasicRulesetResourceTest.groovy
index 2e5356ae6..4b9faf7d3 100644
--- a/test/src/test/groovy/org/openremote/test/rules/BasicRulesetResourceTest.groovy
+++ b/test/src/test/groovy/org/openremote/test/rules/BasicRulesetResourceTest.groovy
@@ -64,7 +64,7 @@ class BasicRulesetResourceTest extends Specification implements ManagerContainer
ruleDefinitions[0].rules == null // Don't retrieve the (large) rules data when getting a list of rule definitions
when: "some tenant rules are retrieved"
- ruleDefinitions = rulesetResource.getTenantRulesets(null, keycloakDemoSetup.masterTenant.id)
+ ruleDefinitions = rulesetResource.getTenantRulesets(null, keycloakDemoSetup.masterTenant.realm)
then: "result should match"
ruleDefinitions.length == 1
@@ -72,7 +72,7 @@ class BasicRulesetResourceTest extends Specification implements ManagerContainer
ruleDefinitions[0].lang == GROOVY
when: "some tenant rules in a non-authenticated realm are retrieved"
- ruleDefinitions = rulesetResource.getTenantRulesets(null, keycloakDemoSetup.tenantA.id)
+ ruleDefinitions = rulesetResource.getTenantRulesets(null, keycloakDemoSetup.tenantA.realm)
then: "result should match"
ruleDefinitions.length == 1
@@ -135,9 +135,9 @@ class BasicRulesetResourceTest extends Specification implements ManagerContainer
ex.response.status == 404
when: "a tenant ruleset is created in the authenticated realm"
- def tenantRuleset = new TenantRuleset("Test tenant definition", keycloakDemoSetup.masterTenant.id, "SomeRulesCode", GROOVY)
+ def tenantRuleset = new TenantRuleset("Test tenant definition", keycloakDemoSetup.masterTenant.realm, "SomeRulesCode", GROOVY)
rulesetResource.createTenantRuleset(null, tenantRuleset)
- rulesetId = rulesetResource.getTenantRulesets(null, keycloakDemoSetup.masterTenant.id)[1].id
+ rulesetId = rulesetResource.getTenantRulesets(null, keycloakDemoSetup.masterTenant.realm)[1].id
tenantRuleset = rulesetResource.getTenantRuleset(null, rulesetId)
lastModified = tenantRuleset.lastModified
@@ -148,7 +148,7 @@ class BasicRulesetResourceTest extends Specification implements ManagerContainer
lastModified.time < System.currentTimeMillis()
tenantRuleset.name == "Test tenant definition"
tenantRuleset.rules == "SomeRulesCode"
- tenantRuleset.realmId == keycloakDemoSetup.masterTenant.id
+ tenantRuleset.realm == keycloakDemoSetup.masterTenant.realm
when: "a tenant ruleset is updated"
tenantRuleset.name = "Renamed test tenant definition"
@@ -163,10 +163,10 @@ class BasicRulesetResourceTest extends Specification implements ManagerContainer
lastModified.time < System.currentTimeMillis()
tenantRuleset.name == "Renamed test tenant definition"
tenantRuleset.rules == "SomeRulesCodeModified"
- tenantRuleset.realmId == keycloakDemoSetup.masterTenant.id
+ tenantRuleset.realm == keycloakDemoSetup.masterTenant.realm
when: "a tenant ruleset is updated with an invalid realm"
- tenantRuleset.realmId = "thisdoesnotexist"
+ tenantRuleset.realm = "thisdoesnotexist"
rulesetResource.updateTenantRuleset(null, rulesetId, tenantRuleset)
then: "the request should be bad"
@@ -174,7 +174,7 @@ class BasicRulesetResourceTest extends Specification implements ManagerContainer
ex.response.status == 400
when: "a tenant ruleset is updated with an invalid id"
- tenantRuleset.realmId = keycloakDemoSetup.masterTenant.id
+ tenantRuleset.realm = keycloakDemoSetup.masterTenant.realm
tenantRuleset.id = 1234567890l
rulesetResource.updateTenantRuleset(null, rulesetId, tenantRuleset)
@@ -198,9 +198,9 @@ class BasicRulesetResourceTest extends Specification implements ManagerContainer
ex.response.status == 404
when: "a tenant ruleset is created in a non-authenticated realm"
- tenantRuleset = new TenantRuleset("Test tenant definition", keycloakDemoSetup.tenantA.id, "SomeRulesCode", GROOVY)
+ tenantRuleset = new TenantRuleset("Test tenant definition", keycloakDemoSetup.tenantA.realm, "SomeRulesCode", GROOVY)
rulesetResource.createTenantRuleset(null, tenantRuleset)
- rulesetId = rulesetResource.getTenantRulesets(null, keycloakDemoSetup.tenantA.id)[1].id
+ rulesetId = rulesetResource.getTenantRulesets(null, keycloakDemoSetup.tenantA.realm)[1].id
tenantRuleset = rulesetResource.getTenantRuleset(null, rulesetId)
lastModified = tenantRuleset.lastModified
@@ -211,7 +211,7 @@ class BasicRulesetResourceTest extends Specification implements ManagerContainer
lastModified.time < System.currentTimeMillis()
tenantRuleset.name == "Test tenant definition"
tenantRuleset.rules == "SomeRulesCode"
- tenantRuleset.realmId == keycloakDemoSetup.tenantA.id
+ tenantRuleset.realm == keycloakDemoSetup.tenantA.realm
when: "an asset ruleset is created in the authenticated realm"
def assetRuleset = new AssetRuleset("Test asset definition", managerDemoSetup.smartOfficeId, "SomeRulesCode", GROOVY)
@@ -336,14 +336,14 @@ class BasicRulesetResourceTest extends Specification implements ManagerContainer
ex.response.status == 403
when: "some tenant rules are retrieved"
- def ruleDefinitions = rulesetResource.getTenantRulesets(null, keycloakDemoSetup.masterTenant.id)
+ def ruleDefinitions = rulesetResource.getTenantRulesets(null, keycloakDemoSetup.masterTenant.realm)
then: "result should match"
ruleDefinitions.length == 1
ruleDefinitions[0].name == "Some master tenant demo rules"
when: "some tenant rules in a non-authenticated realm are retrieved"
- rulesetResource.getTenantRulesets(null, keycloakDemoSetup.tenantA.id)
+ rulesetResource.getTenantRulesets(null, keycloakDemoSetup.tenantA.realm)
then: "access should be forbidden"
ex = thrown()
@@ -381,9 +381,9 @@ class BasicRulesetResourceTest extends Specification implements ManagerContainer
ex.response.status == 403
when: "a tenant ruleset is created in the authenticated realm"
- def tenantRuleset = new TenantRuleset("Test tenant definition", keycloakDemoSetup.masterTenant.id, "SomeRulesCode", GROOVY)
+ def tenantRuleset = new TenantRuleset("Test tenant definition", keycloakDemoSetup.masterTenant.realm, "SomeRulesCode", GROOVY)
rulesetResource.createTenantRuleset(null, tenantRuleset)
- def rulesetId = rulesetResource.getTenantRulesets(null, keycloakDemoSetup.masterTenant.id)[1].id
+ def rulesetId = rulesetResource.getTenantRulesets(null, keycloakDemoSetup.masterTenant.realm)[1].id
tenantRuleset = rulesetResource.getTenantRuleset(null, rulesetId)
def lastModified = tenantRuleset.lastModified
@@ -394,7 +394,7 @@ class BasicRulesetResourceTest extends Specification implements ManagerContainer
lastModified.time < System.currentTimeMillis()
tenantRuleset.name == "Test tenant definition"
tenantRuleset.rules == "SomeRulesCode"
- tenantRuleset.realmId == keycloakDemoSetup.masterTenant.id
+ tenantRuleset.realm == keycloakDemoSetup.masterTenant.realm
when: "a tenant ruleset is updated"
tenantRuleset.name = "Renamed test tenant definition"
@@ -409,10 +409,10 @@ class BasicRulesetResourceTest extends Specification implements ManagerContainer
lastModified.time < System.currentTimeMillis()
tenantRuleset.name == "Renamed test tenant definition"
tenantRuleset.rules == "SomeRulesCodeModified"
- tenantRuleset.realmId == keycloakDemoSetup.masterTenant.id
+ tenantRuleset.realm == keycloakDemoSetup.masterTenant.realm
when: "a tenant ruleset is updated with an invalid realm"
- tenantRuleset.realmId = "thisdoesnotexist"
+ tenantRuleset.realm = "thisdoesnotexist"
rulesetResource.updateTenantRuleset(null, rulesetId, tenantRuleset)
then: "the request should be bad"
@@ -420,7 +420,7 @@ class BasicRulesetResourceTest extends Specification implements ManagerContainer
ex.response.status == 400
when: "a tenant ruleset is updated with an invalid id"
- tenantRuleset.realmId = keycloakDemoSetup.masterTenant.id
+ tenantRuleset.realm = keycloakDemoSetup.masterTenant.realm
tenantRuleset.id = 1234567890l
rulesetResource.updateTenantRuleset(null, rulesetId, tenantRuleset)
@@ -444,7 +444,7 @@ class BasicRulesetResourceTest extends Specification implements ManagerContainer
ex.response.status == 404
when: "a tenant ruleset is created in a non-authenticated realm"
- tenantRuleset = new TenantRuleset("Test tenant definition", keycloakDemoSetup.tenantA.id, "SomeRulesCode", GROOVY)
+ tenantRuleset = new TenantRuleset("Test tenant definition", keycloakDemoSetup.tenantA.realm, "SomeRulesCode", GROOVY)
rulesetResource.createTenantRuleset(null, tenantRuleset)
then: "access should be forbidden"
@@ -566,14 +566,14 @@ class BasicRulesetResourceTest extends Specification implements ManagerContainer
ex.response.status == 403
when: "some tenant rules in a non-authenticated realm are retrieved"
- rulesetResource.getTenantRulesets(null, keycloakDemoSetup.masterTenant.id)
+ rulesetResource.getTenantRulesets(null, keycloakDemoSetup.masterTenant.realm)
then: "access should be forbidden"
ex = thrown()
ex.response.status == 403
when: "some tenant rules in the authenticated realm are retrieved"
- rulesetResource.getTenantRulesets(null, keycloakDemoSetup.tenantA.id)
+ rulesetResource.getTenantRulesets(null, keycloakDemoSetup.tenantA.realm)
then: "access should be forbidden"
ex = thrown()
@@ -611,7 +611,7 @@ class BasicRulesetResourceTest extends Specification implements ManagerContainer
ex.response.status == 403
when: "a tenant ruleset is created in the authenticated realm"
- def tenantRuleset = new TenantRuleset("Test tenant definition", keycloakDemoSetup.tenantA.id, "SomeRulesCode", GROOVY)
+ def tenantRuleset = new TenantRuleset("Test tenant definition", keycloakDemoSetup.tenantA.realm, "SomeRulesCode", GROOVY)
rulesetResource.createTenantRuleset(null, tenantRuleset)
then: "access should be forbidden"
@@ -633,7 +633,7 @@ class BasicRulesetResourceTest extends Specification implements ManagerContainer
ex.response.status == 403
when: "a tenant ruleset is created in a non-authenticated realm"
- tenantRuleset = new TenantRuleset("Test tenant definition", keycloakDemoSetup.tenantB.id, "SomeRulesCode", GROOVY)
+ tenantRuleset = new TenantRuleset("Test tenant definition", keycloakDemoSetup.tenantB.realm, "SomeRulesCode", GROOVY)
rulesetResource.createTenantRuleset(null, tenantRuleset)
then: "access should be forbidden"
@@ -641,7 +641,7 @@ class BasicRulesetResourceTest extends Specification implements ManagerContainer
ex.response.status == 403
when: "a tenant ruleset is created in the authenticated realm"
- def assetRuleset = new AssetRuleset("Test asset definition", keycloakDemoSetup.tenantA.id, "SomeRulesCode", GROOVY)
+ def assetRuleset = new AssetRuleset("Test asset definition", keycloakDemoSetup.tenantA.realm, "SomeRulesCode", GROOVY)
rulesetResource.createAssetRuleset(null, assetRuleset)
then: "access should be forbidden"
@@ -663,7 +663,7 @@ class BasicRulesetResourceTest extends Specification implements ManagerContainer
ex.response.status == 403
when: "a tenant ruleset is created in a non-authenticated realm"
- assetRuleset = new AssetRuleset("Test asset definition", keycloakDemoSetup.tenantB.id, "SomeRulesCode", GROOVY)
+ assetRuleset = new AssetRuleset("Test asset definition", keycloakDemoSetup.tenantB.realm, "SomeRulesCode", GROOVY)
rulesetResource.createAssetRuleset(null, assetRuleset)
then: "access should be forbidden"
@@ -714,14 +714,14 @@ class BasicRulesetResourceTest extends Specification implements ManagerContainer
ex.response.status == 403
when: "some tenant rules in a non-authenticated realm are retrieved"
- rulesetResource.getTenantRulesets(null, keycloakDemoSetup.masterTenant.id)
+ rulesetResource.getTenantRulesets(null, keycloakDemoSetup.masterTenant.realm)
then: "access should be forbidden"
ex = thrown()
ex.response.status == 403
when: "some tenant rules in the authenticated realm are retrieved"
- rulesetResource.getTenantRulesets(null, keycloakDemoSetup.tenantA.id)
+ rulesetResource.getTenantRulesets(null, keycloakDemoSetup.tenantA.realm)
then: "access should be forbidden"
ex = thrown()
@@ -766,7 +766,7 @@ class BasicRulesetResourceTest extends Specification implements ManagerContainer
ex.response.status == 403
when: "a tenant ruleset is created in the authenticated realm"
- def tenantRuleset = new TenantRuleset("Test tenant definition", keycloakDemoSetup.tenantA.id, "SomeRulesCode", GROOVY)
+ def tenantRuleset = new TenantRuleset("Test tenant definition", keycloakDemoSetup.tenantA.realm, "SomeRulesCode", GROOVY)
rulesetResource.createTenantRuleset(null, tenantRuleset)
then: "access should be forbidden"
@@ -789,7 +789,7 @@ class BasicRulesetResourceTest extends Specification implements ManagerContainer
ex.response.status == 404
when: "a tenant ruleset is created in a non-authenticated realm"
- tenantRuleset = new TenantRuleset("Test tenant definition", keycloakDemoSetup.tenantB.id, "SomeRulesCode", GROOVY)
+ tenantRuleset = new TenantRuleset("Test tenant definition", keycloakDemoSetup.tenantB.realm, "SomeRulesCode", GROOVY)
rulesetResource.createTenantRuleset(null, tenantRuleset)
then: "access should be forbidden"
diff --git a/test/src/test/groovy/org/openremote/test/rules/residence/JsonRulesTest.groovy b/test/src/test/groovy/org/openremote/test/rules/residence/JsonRulesTest.groovy
index 4ab92191a..3c477473a 100644
--- a/test/src/test/groovy/org/openremote/test/rules/residence/JsonRulesTest.groovy
+++ b/test/src/test/groovy/org/openremote/test/rules/residence/JsonRulesTest.groovy
@@ -75,7 +75,7 @@ class JsonRulesTest extends Specification implements ManagerContainerTrait {
and: "some rules"
Ruleset ruleset = new TenantRuleset(
"Demo Apartment - All Lights Off",
- keycloakDemoSetup.tenantA.id,
+ keycloakDemoSetup.tenantA.realm,
getClass().getResource("/org/openremote/test/rules/BasicJsonRules.json").text,
Ruleset.Lang.JSON
)
@@ -83,7 +83,7 @@ class JsonRulesTest extends Specification implements ManagerContainerTrait {
expect: "the rule engines to become available and be running with asset states inserted"
conditions.eventually {
- tenantAEngine = rulesService.tenantEngines.get(keycloakDemoSetup.tenantA.id)
+ tenantAEngine = rulesService.tenantEngines.get(keycloakDemoSetup.tenantA.realm)
assert tenantAEngine != null
assert tenantAEngine.isRunning()
assert tenantAEngine.assetStates.size() == DEMO_RULE_STATES_CUSTOMER_A