Skip to content

class Athena::Security::Role::Hierarchy
inherits Reference #

A hierarchy of roles, where a role is granted the roles below it, and in turn the roles below those.

hierarchy = ASEC::Role::Hierarchy.new({
  "ROLE_ADMIN"       => ["ROLE_USER"],
  "ROLE_SUPER_ADMIN" => ["ROLE_ADMIN", "ROLE_BILLING"],
})

hierarchy.reachable_role_names ["ROLE_SUPER_ADMIN"] # => ["ROLE_SUPER_ADMIN", "ROLE_ADMIN", "ROLE_USER", "ROLE_BILLING"]

A role may contain wildcards, a * preceded by _ and followed by _ or the end of the role. It then grants its roles to each role it matches, without being granted itself.

hierarchy = ASEC::Role::Hierarchy.new({"ROLE_ADMIN_*" => ["ROLE_ADMIN"]})

hierarchy.reachable_role_names ["ROLE_ADMIN_BLOG"] # => ["ROLE_ADMIN_BLOG", "ROLE_ADMIN"]

Included modules

Athena::Security::Role::HierarchyInterface

Constructors#

.new(hierarchy : Hash(String, Array(String)))#

View source

Methods#

#reachable_role_names(roles : Array(String)) : Array(String)#

Returns the provided roles, along with the roles reachable from them.

View source