net.nemerosa.ontrack.model.security.Authorisations.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ontrack-model Show documentation
Show all versions of ontrack-model Show documentation
Ontrack module: ontrack-model
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