Documentation
¶
Overview ¶
Package accessadmin decides plugin/admin's permissions with plugin/access roles, given as an access control and named roles. It is the adapter that lets the admin plugin, which lives in the core module and imports no permission engine, use fine-grained roles from the access module:
authz := accessadmin.MustNew(accessadmin.DefaultAccessControl, map[string]access.Role{"support": support})
auth.New(db, auth.WithPlugins(admin.New(admin.WithAuthorizer(authz), …)))
Without it the admin plugin keeps its two built-in roles (admin, user).
Index ¶
Constants ¶
This section is empty.
Variables ¶
var DefaultAccessControl = access.MustNew(access.Statements(admin.DefaultStatements.Clone()))
DefaultAccessControl is the access control of admin.DefaultStatements, the vocabulary every admin operation asks from. An app adding resources of its own builds one from a copy of admin.DefaultStatements.
var ErrNoAccessControl = errors.New("accessadmin: needs an access control")
ErrNoAccessControl is New with a nil access control.
Functions ¶
func DefaultRoles ¶
DefaultRoles returns admin.DefaultRoles as access roles of DefaultAccessControl; a new map each call.
Types ¶
type Authorizer ¶
type Authorizer struct {
// contains filtered or unexported fields
}
Authorizer is an admin.Authorizer and admin.RoleCatalog over access roles. Build it with New; it is immutable afterwards and safe for concurrent use.
func MustNew ¶
func MustNew(ac *access.AccessControl, roles map[string]access.Role) *Authorizer
MustNew is New for roles known at compile time; it panics on an error, which then shows at start-up.
func New ¶
func New(ac *access.AccessControl, roles map[string]access.Role) (*Authorizer, error)
New builds the authorizer from ac and roles, which are added to DefaultRoles or replace one of them under its name. Every role must name only statements ac declares, and every name must be one name without commas, as admin_role stores several comma-joined.
func (*Authorizer) Authorize ¶
func (a *Authorizer) Authorize(_ context.Context, req admin.AccessRequest) (bool, error)
Authorize allows req when one of its roles passes the whole request under its connector, so a user with several roles needs only one to pass. It never fails.
func (*Authorizer) DefinesRole ¶
func (a *Authorizer) DefinesRole(name string) bool
DefinesRole reports whether name is one of the authorizer's roles, which set-role then accepts.