Search in sources :

Example 1 with UserAssetPredicate

use of org.openremote.model.query.filter.UserAssetPredicate 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);
}
Also used : PathPredicate(org.openremote.model.query.filter.PathPredicate) User(org.openremote.model.security.User) UserAssetPredicate(org.openremote.model.query.filter.UserAssetPredicate) ArrayList(java.util.ArrayList) TenantPredicate(org.openremote.model.query.filter.TenantPredicate)

Aggregations

ArrayList (java.util.ArrayList)1 PathPredicate (org.openremote.model.query.filter.PathPredicate)1 TenantPredicate (org.openremote.model.query.filter.TenantPredicate)1 UserAssetPredicate (org.openremote.model.query.filter.UserAssetPredicate)1 User (org.openremote.model.security.User)1