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

net.nemerosa.ontrack.model.security.Authorisations Maven / Gradle / Ivy

There is a newer version: 4.4.5
Show newest version
package net.nemerosa.ontrack.model.security;

import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;

import java.io.Serializable;
import java.util.*;

@Data
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public class Authorisations implements Serializable {

    public static Authorisations none() {
        return new Authorisations(
                null,
                new LinkedHashSet<>()
        );
    }

    @Getter(AccessLevel.PRIVATE)
    private GlobalRole globalRole;
    @Getter(AccessLevel.PRIVATE)
    private Set projectRoleAssociations = new LinkedHashSet<>();

    public boolean isGranted(Class fn) {
        return (globalRole != null && globalRole.isGlobalFunctionGranted(fn));
    }

    public boolean isGranted(int projectId, Class fn) {
        return (globalRole != null && globalRole.isProjectFunctionGranted(fn))
                || projectRoleAssociations.stream().anyMatch(pa -> pa.getProjectId() == projectId && pa.isGranted(fn));
    }

    public Authorisations withGlobalRole(Optional globalRole) {
        this.globalRole = globalRole.orElse(null);
        return this;
    }

    public Authorisations withProjectRoles(Collection projectRoleAssociations) {
        this.projectRoleAssociations.addAll(projectRoleAssociations);
        return this;
    }

    public Authorisations withProjectRole(ProjectRoleAssociation projectRoleAssociation) {
        this.projectRoleAssociations.add(projectRoleAssociation);
        return this;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy