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

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

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

import java.io.Serializable
import kotlin.reflect.KClass

data class Authorisations(
        private val projectFunctions: Set> = emptySet(),
        private val globalRole: GlobalRole? = null,
        private val projectRoleAssociations: Set = emptySet()
) : AuthorisationsCheck, Serializable {

    companion object {
        @JvmStatic
        fun none() = Authorisations(emptySet(), null, emptySet())
    }

    override fun isGranted(fn: Class) = globalRole != null && globalRole.isGlobalFunctionGranted(fn)

    override fun isGranted(projectId: Int, fn: Class) =
            (globalRole != null && globalRole.isProjectFunctionGranted(fn))
                    || projectFunctions.map { it.java }.any { fn.isAssignableFrom(it) }
                    || projectRoleAssociations.any { pa -> pa.projectId == projectId && pa.isGranted(fn) }

    fun withProjectFunctions(projectFunctions: Set>) =
            Authorisations(projectFunctions, globalRole, projectRoleAssociations)

    fun withGlobalRole(globalRole: GlobalRole?) = Authorisations(projectFunctions, globalRole, projectRoleAssociations)

    fun withProjectRoles(projectRoleAssociations: Collection) =
            Authorisations(projectFunctions, globalRole, this.projectRoleAssociations + projectRoleAssociations)

    fun withProjectRole(projectRoleAssociation: ProjectRoleAssociation) =
            Authorisations(projectFunctions, globalRole, this.projectRoleAssociations + projectRoleAssociation)
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy