2021-11-28 16:25:58 +01:00
|
|
|
package keycloakclaims
|
|
|
|
|
2022-11-03 15:52:11 +01:00
|
|
|
// RoleInRoles returns true if role is present in the claims.
|
|
|
|
//
|
|
|
|
// Deprecated: RoleInRoles will be replaced by HasRole
|
2021-11-28 16:25:58 +01:00
|
|
|
func RoleInRoles(role string, claims *Claims) bool {
|
|
|
|
for _, v := range claims.RealmAccess.Roles {
|
|
|
|
if role == v {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
2022-11-03 15:52:11 +01:00
|
|
|
|
|
|
|
// HasRole returns true if role is present in the claims.
|
|
|
|
func HasRole(query string, claims *Claims) bool {
|
|
|
|
for _, role := range claims.RealmAccess.Roles {
|
|
|
|
if query == role {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// HasAnyRole returns true if any of the given roles is present in the claims.
|
|
|
|
func HasAnyRole(query []string, claims *Claims) bool {
|
|
|
|
for _, q := range query {
|
|
|
|
for _, role := range claims.RealmAccess.Roles {
|
|
|
|
if q == role {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|