rbac

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2019 License: Apache-2.0 Imports: 10 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	// user for role relation
	UserForRoleRelation = "U"
	// role for role relation
	RoleForRoleRelation = "R"
)

Variables

This section is empty.

Functions

func ArrayEquals

func ArrayEquals(a []string, b []string) bool

ArrayEquals determines whether two string arrays are identical.

func ArrayRemoveDuplicates

func ArrayRemoveDuplicates(s *[]string)

ArrayRemoveDuplicates removes any duplicated elements in a string array.

func EscapeAssertion

func EscapeAssertion(s string) string

EscapeAssertion escapes the dots in the assertion, because the expression evaluation doesn't support such variable names.

func LogPrint

func LogPrint(v ...interface{})

LogPrint prints the log.

func RemoveComments

func RemoveComments(s string) string

RemoveComments removes the comments starting with # in the text.

Types

type Assertion

type Assertion struct {
	Key    string
	Value  string
	Tokens []string
	Rule   [][]string
	RL     *roleLinks
}

Assertion represents an expression in a section of the model. For example: r = sub, obj, act

type Role

type Role struct {
	ID          int64
	Name        string
	Description string
}

Role the role statement in system, a group of user with the same permissions

type RoleManager

type RoleManager struct {
	// contains filtered or unexported fields
}

RoleManager manage the user's role and role hierarchy.

func NewRoleManager

func NewRoleManager(params ...interface{}) (*RoleManager, error)

NewRoleManager returns a new role manager

func (*RoleManager) AddRole

func (m *RoleManager) AddRole(role *Role) (bool, error)

AddRole adds a role inside a rule. Returns false if the user already has the role (aka not affected).

func (*RoleManager) AddRoleForUser

func (m *RoleManager) AddRoleForUser(role string, user string) error

AddRoleForUser adds a role to a user.

func (*RoleManager) AddRoleForUsers

func (m *RoleManager) AddRoleForUsers(role string, users []string) error

AddRoleForUsers adds the same role to multiple users

func (*RoleManager) AddRoles

func (m *RoleManager) AddRoles(roles []*Role) (bool, error)

AddRoles adds multiple roles inside the rule. Returns false if the user already has the role (aka not affected).

func (*RoleManager) AddRolesForUser

func (m *RoleManager) AddRolesForUser(user string, roles []string) error

AddRolesForUser adds the multiple roles to a user

func (*RoleManager) AssignRole

func (m *RoleManager) AssignRole(roleGroup string, role string) error

AssignRole assign a role to role group, the role includes all permissions for role group.

func (*RoleManager) AssignRoles

func (m *RoleManager) AssignRoles(roleGroup string, roles []string) error

AssignRoles assign multiple roles to role group, the role includes all permissions for role group.

func (*RoleManager) CancelAssignRole

func (m *RoleManager) CancelAssignRole(roleGroup string, role string) error

CancelAssignRole cancel assign a role to role group.

func (*RoleManager) CancelAssignRoles

func (m *RoleManager) CancelAssignRoles(roleGroup string, roles []string) error

CancelAssignRoles cancel assign multiple role to role group.

func (*RoleManager) Close

func (m *RoleManager) Close()

Close close database connection

func (*RoleManager) CountRoles

func (m *RoleManager) CountRoles(likeRole ...string) (int64, error)

CountRoles gets the count of roles that show up in the current role.

func (*RoleManager) GetRole

func (m *RoleManager) GetRole(roleName string) (*Role, error)

GetRole gets a role inside the rule.

func (*RoleManager) GetRoles

func (m *RoleManager) GetRoles(limit, offset int64, likeRole ...string) ([]*Role, int64, error)

GetRoles gets the list of roles that show up in the current role.

func (*RoleManager) GetRolesForUser

func (m *RoleManager) GetRolesForUser(name string, likeRoles ...string) ([]*Role, error)

GetRolesForUser gets the roles that a user has.

func (*RoleManager) GetRolesHierarchyForUser

func (m *RoleManager) GetRolesHierarchyForUser(name string, likeRoles ...string) ([]*Role, error)

GetRolesHierarchyForUser gets all roles of hierarchy that a user has.

func (*RoleManager) GetUsersForRole

func (m *RoleManager) GetUsersForRole(role string) ([]string, error)

GetUsersForRole gets the users that has a role inside the rule.

func (*RoleManager) GetUsersForRoleHierarchy

func (m *RoleManager) GetUsersForRoleHierarchy(role string) ([]*User, error)

GetUsersForRoleHierarchy gets the users that has all role hierarchy inside the rule.

func (*RoleManager) HasRole

func (m *RoleManager) HasRole(roleName string) (bool, error)

HasRole determines whether a role inside the rule.

func (*RoleManager) HasRoleForUser

func (m *RoleManager) HasRoleForUser(role, user string) (bool, error)

HasRoleForUser determines whether a user has a role.

func (*RoleManager) Load

func (m *RoleManager) Load() error

Load reloads the role from database.

func (*RoleManager) RemoveRole

func (m *RoleManager) RemoveRole(name string) error

RemoveRole deletes the role and all its users.

func (*RoleManager) RemoveRoleForUser

func (m *RoleManager) RemoveRoleForUser(role, user string) error

RemoveRoleForUser deletes a role for the user.

type Rule

type Rule struct {
	ID    int64
	PType string
	V0    string
	V1    string
	V2    string
	V3    string
	V4    string
	V5    string
}

Rule the storage structure of the rule

type User

type User struct {
	Name string
	Type UserType
}

User the user have two user type includes subject or role

type UserType

type UserType string
const (
	SubjectUserType UserType = "S"
	RoleUserType    UserType = "R"
)

type XODB

type XODB interface {
	Exec(string, ...interface{}) (sql.Result, error)
	Query(string, ...interface{}) (*sql.Rows, error)
	QueryRow(string, ...interface{}) *sql.Row
	ExecContext(context.Context, string, ...interface{}) (sql.Result, error)
	QueryContext(context.Context, string, ...interface{}) (*sql.Rows, error)
	QueryRowContext(context.Context, string, ...interface{}) *sql.Row
	DriverName() string
	Rebind(query string) string
}

XODB This should work with database/sql.DB and database/sql.Tx.

Jump to

Keyboard shortcuts

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