auth

package
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 10, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const SecurityPrincipalCtxKey ctxKey = 1

SecurityPrincipalCtxKey is used to pass the SecurityPrincipal to the request context.Context

Variables

View Source
var ScopeSeparator = '/'

Functions

This section is empty.

Types

type Access

type Access uint32
const (
	AccessRead Access = 1 << iota
	AccessCreate
	AccessUpdate
	AccessDelete
	AccessAdd
	AccessRemove
	AccessDisable
	AccessEnable
	AccessApprove
)

func AccessAll

func AccessAll() Access

type Group

type Group struct {
	Name  string
	Roles []Role
}

A Group is a collection of roles

func (Group) HasPermission

func (g Group) HasPermission(permission Permission) bool

HasPermission returns true if the current Group has the Permission

func (Group) HasRole

func (g Group) HasRole(roleName string) bool

HasRole returns true if the current Group has the Role

type Permission

type Permission struct {
	Scope  string
	Access Access
}

A Permission has a Scope and Access. A Scope describes where an action can be performed For simplicity, the scope might have maximum 3 levels, (domain, subdomain and resource) separated by ScopeSeparator Scopes should be structured in a parent-child relationship. Each level of hierarchy makes the scope more specific

Examples:

  1. admin/timesheet/team1 -> Allow access only to the resource team1 from admin/timesheet
  2. admin/timesheet/* -> Allow access to all resources from admin/timesheet
  3. admin/*/team1 -> Allow access to all subdomains from the admin domain related to the resource team1
  4. admin/* -> Allow access to all subdomains and all resources from the admin domain
  5. * -> Allow access to all domains

func AllPermissions

func AllPermissions() Permission

func NewPermission

func NewPermission(scope string, access Access) (Permission, error)

func ParsePermission

func ParsePermission(permissionAsString string) (Permission, error)

ParsePermission parse a string into a Permission

func (Permission) Implies

func (p Permission) Implies(anotherPermission Permission) bool

Implies returns true if the current Permission implies anotherPermission This function assumes that the scope of the Permission from the argument, does not contain the wildcard (*)

func (Permission) String

func (p Permission) String() string

type Role

type Role struct {
	Name               string
	Description        string
	AllowedPermissions []Permission
	DeniedPermissions  []Permission
}

A Role is a collection of allowed and denied permissions The denied permissions check has higher priority than allowed one

func (Role) HasPermission

func (r Role) HasPermission(permission Permission) bool

HasPermission returns true if the current Role has the Permission

type SecurityPrincipal

type SecurityPrincipal interface {
	// Identity returns the principal identity
	Identity() string
	// HasRole returns true if the current SecurityPrincipal has assigned the role
	HasRole(roleName string) bool
	// HasPermission returns true if the current SecurityPrincipal has the Permission
	HasPermission(permission Permission) bool
	// String returns a string representation of the SecurityPrincipal
	String() string
}

A SecurityPrincipal represents any managed identity that is requesting access to a resource (a user, a service principal, etc)

func GetSecurityPrincipalFromContext

func GetSecurityPrincipalFromContext(ctx context.Context) SecurityPrincipal

GetSecurityPrincipalFromContext returns the SecurityPrincipal from the request context.Context

type User

type User struct {
	// the user internal id
	Id string
	// the name of user
	Name string
	// the id/name of the platform were the user was authenticated (for example Google, Linkedin, Internal, etc)
	IdentityPlatform string
	// the security groups where this user belongs
	Groups []Group
	// a field where any additional data to this user can be attached
	Attachment any
}

A User implements SecurityPrincipal and represents an authenticated person

func (User) HasPermission

func (u User) HasPermission(permission Permission) bool

func (User) HasRole

func (u User) HasRole(roleName string) bool

func (User) Identity

func (u User) Identity() string

func (User) String added in v1.0.0

func (u User) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL