All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.netgrif.application.engine.workflow.service.AbstractAuthorizationService Maven / Gradle / Ivy

Go to download

System provides workflow management functions including user, role and data management.

There is a newer version: 6.3.3
Show newest version
package com.netgrif.application.engine.workflow.service;

import com.netgrif.application.engine.auth.domain.IUser;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

public abstract class AbstractAuthorizationService {

    protected boolean hasPermission(Boolean hasPermission) {
        return hasPermission != null && hasPermission;
    }

    protected boolean hasRestrictedPermission(Boolean hasPermission) {
        return hasPermission != null && !hasPermission;
    }

    protected Map getAggregatePermissions(IUser user, Map> permissions) {
        Map aggregatePermissions = new HashMap<>();

        Set userProcessRoleIDs = user.getSelfOrImpersonated().getProcessRoles().stream().map(role -> role.get_id().toString()).collect(Collectors.toSet());

        for (Map.Entry> role : permissions.entrySet()) {
            aggregatePermission(userProcessRoleIDs, role, aggregatePermissions);
        }

        return aggregatePermissions;
    }

    private void aggregatePermission(Set userProcessRoleIDs, Map.Entry> role, Map aggregatePermissions) {
        if (userProcessRoleIDs.contains(role.getKey())) {
            for (Map.Entry permission : role.getValue().entrySet()) {
                if (aggregatePermissions.containsKey(permission.getKey())) {
                    aggregatePermissions.put(permission.getKey(), aggregatePermissions.get(permission.getKey()) && permission.getValue());
                } else {
                    aggregatePermissions.put(permission.getKey(), permission.getValue());
                }
            }
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy