use of org.openremote.model.query.filter.TenantPredicate in project openremote by openremote.
the class UsersFacade method getResults.
@Override
public Stream<String> getResults(UserQuery userQuery) {
// No restriction for global rulesets
if (TenantRuleset.class.isAssignableFrom(rulesEngineId.getScope())) {
// Restrict tenant
userQuery.tenantPredicate = new TenantPredicate(rulesEngineId.getRealm().orElseThrow(() -> new IllegalArgumentException("Realm ID missing: " + rulesEngineId)));
} else if (AssetRuleset.class.isAssignableFrom(rulesEngineId.getScope())) {
userQuery.tenantPredicate = null;
String assetId = rulesEngineId.getAssetId().orElseThrow(() -> new IllegalArgumentException("Asset ID missing: " + rulesEngineId));
// Asset<?> must be this engines asset or a child
if (userQuery.assetPredicate != null) {
if (assetId.equals(userQuery.assetPredicate.id)) {
userQuery.pathPredicate = null;
} else {
userQuery.pathPredicate = new PathPredicate(rulesEngineId.getAssetId().orElseThrow(IllegalArgumentException::new));
}
} else if (userQuery.pathPredicate != null) {
// Path must contain this engines asset ID
List<String> path = new ArrayList<>(Arrays.asList(userQuery.pathPredicate.path));
if (!path.contains(assetId)) {
path.add(assetId);
userQuery.pathPredicate.path = path.toArray(new String[userQuery.pathPredicate.path.length + 1]);
}
} else {
// Force scope to this asset
userQuery.assetPredicate = new UserAssetPredicate(assetId);
}
}
// Prevent system users being retrieved
userQuery.select(new UserQuery.Select().excludeSystemUsers(true));
return Arrays.stream(identityService.getIdentityProvider().queryUsers(userQuery)).map(User::getId);
}
use of org.openremote.model.query.filter.TenantPredicate in project openremote by openremote.
the class ConsoleResourceImpl method getConsoleParentAsset.
public static Asset<?> getConsoleParentAsset(AssetStorageService assetStorageService, Tenant tenant) {
// Look for a group asset with a child type of console in the realm root
GroupAsset consoleParent = (GroupAsset) assetStorageService.find(new AssetQuery().select(new AssetQuery.Select().excludeAttributes()).names(CONSOLE_PARENT_ASSET_NAME).parents(new ParentPredicate(null)).types(GroupAsset.class).tenant(new TenantPredicate(tenant.getRealm())).attributes(new AttributePredicate("childAssetType", new StringPredicate(ConsoleAsset.DESCRIPTOR.getName()))));
if (consoleParent == null) {
consoleParent = new GroupAsset(CONSOLE_PARENT_ASSET_NAME, ConsoleAsset.class);
consoleParent.setChildAssetType(ConsoleAsset.DESCRIPTOR.getName());
consoleParent.setRealm(tenant.getRealm());
consoleParent = assetStorageService.merge(consoleParent);
}
return consoleParent;
}
Aggregations