Documentation
¶
Index ¶
- Constants
- func GetAuthenticatedUser(ctx context.Context) string
- func SetAuthenticatedUser(ctx context.Context, user string) context.Context
- type AuthModule
- func (auth *AuthModule) AddPolicy(userGroup, resourceGroup, method string) error
- func (auth *AuthModule) AddResourceToGroup(resourceName string, groupName ...string) error
- func (auth *AuthModule) AddUserToGroup(userName string, groupName ...string) error
- func (auth *AuthModule) CreateResourceGroup(groupName string) error
- func (auth *AuthModule) CreateUserGroup(groupName string) error
- func (auth *AuthModule) GetGroupsForResource(resourceName string) ([]string, error)
- func (auth *AuthModule) GetGroupsForUser(userName string) ([]string, error)
- func (auth *AuthModule) GetResourceGroup(groupName string) ([]string, error)
- func (auth *AuthModule) GetResourceGroups() ([]ResourceGroup, error)
- func (auth *AuthModule) GetUserGroup(groupName string) ([]string, error)
- func (auth *AuthModule) GetUserGroups() ([]UserGroup, error)
- func (auth *AuthModule) ListPolicies() ([]Policy, error)
- func (auth *AuthModule) Middleware() gin.HandlerFunc
- func (auth *AuthModule) RemovePolicy(userGroup, resourceGroup, method string) error
- func (auth *AuthModule) RemoveResource(resourceName string) error
- func (auth *AuthModule) RemoveResourceFromGroup(resourceName string, groupName ...string) error
- func (auth *AuthModule) RemoveResourceGroup(groupName string) error
- func (auth *AuthModule) RemoveUser(userName string) error
- func (auth *AuthModule) RemoveUserFromGroup(userName string, groupName ...string) error
- func (auth *AuthModule) RemoveUserGroup(groupName string) error
- func (auth *AuthModule) ResourceGroupExists(groupName string) (bool, error)
- func (auth *AuthModule) UserGroupExists(groupName string) (bool, error)
- type CasbinError
- type ConflictError
- type GroupType
- type NotFoundError
- type Policy
- type ResourceGroup
- type UserGroup
Constants ¶
const (
UnauthenticatedUser = "__unauthenticated__"
)
Variables ¶
This section is empty.
Functions ¶
func GetAuthenticatedUser ¶ added in v0.9.0
Types ¶
type AuthModule ¶ added in v0.9.0
type AuthModule struct {
// contains filtered or unexported fields
}
func NewModule ¶ added in v0.9.0
func NewModule(adapter persist.Adapter) AuthModule
NewModule initializes the casbin enforcer with the provided adapter and sets up default policies. It creates the casbin model, loads policies, and ensures the enclaveAdmin group and policy exist.
func (*AuthModule) AddPolicy ¶ added in v0.9.0
func (auth *AuthModule) AddPolicy( userGroup, resourceGroup, method string, ) error
AddPolicy adds a policy to the enforcer if it does not already exist.
It checks if the user group and resource group exist before adding the policy and throws if they do not.
func (*AuthModule) AddResourceToGroup ¶ added in v0.9.0
func (auth *AuthModule) AddResourceToGroup( resourceName string, groupName ...string, ) error
AddResourceToGroup adds a resource to one or more groups. It validates that all specified groups exist before adding the resource.
func (*AuthModule) AddUserToGroup ¶ added in v0.9.0
func (auth *AuthModule) AddUserToGroup( userName string, groupName ...string, ) error
AddUserToGroup adds a user to one or more groups. It validates that all specified groups exist before adding the user.
func (*AuthModule) CreateResourceGroup ¶ added in v0.9.0
func (auth *AuthModule) CreateResourceGroup(groupName string) error
CreateResourceGroup creates a new resource group with the specified name. If the group already exists, the function returns without error.
func (*AuthModule) CreateUserGroup ¶ added in v0.9.0
func (auth *AuthModule) CreateUserGroup(groupName string) error
CreateUserGroup creates a new user group with the specified name. If the group already exists, the function returns without error.
func (*AuthModule) GetGroupsForResource ¶ added in v0.9.0
func (auth *AuthModule) GetGroupsForResource( resourceName string, ) ([]string, error)
GetGroupsForResource returns all groups that a specific resource belongs to.
func (*AuthModule) GetGroupsForUser ¶ added in v0.9.0
func (auth *AuthModule) GetGroupsForUser(userName string) ([]string, error)
GetGroupsForUser returns all groups that a specific user belongs to.
func (*AuthModule) GetResourceGroup ¶ added in v0.9.0
func (auth *AuthModule) GetResourceGroup(groupName string) ([]string, error)
GetResourceGroup returns all resources that belong to a specific group.
func (*AuthModule) GetResourceGroups ¶ added in v0.9.0
func (auth *AuthModule) GetResourceGroups() ([]ResourceGroup, error)
GetResourceGroups returns all resource groups as a slice of ResourceGroup structs.
func (*AuthModule) GetUserGroup ¶ added in v0.9.0
func (auth *AuthModule) GetUserGroup(groupName string) ([]string, error)
GetUserGroup returns all users that belong to a specific group.
func (*AuthModule) GetUserGroups ¶ added in v0.9.0
func (auth *AuthModule) GetUserGroups() ([]UserGroup, error)
GetUserGroups returns all user groups as a slice of UserGroup structs.
func (*AuthModule) ListPolicies ¶ added in v0.9.0
func (auth *AuthModule) ListPolicies() ([]Policy, error)
func (*AuthModule) Middleware ¶ added in v0.9.0
func (auth *AuthModule) Middleware() gin.HandlerFunc
func (*AuthModule) RemovePolicy ¶ added in v0.9.0
func (auth *AuthModule) RemovePolicy( userGroup, resourceGroup, method string, ) error
RemovePolicy removes a policy from the enforcer.
It prevents the removal of the enclaveAdmin policy to ensure that enclaveAdmins always have full access.
func (*AuthModule) RemoveResource ¶ added in v0.9.0
func (auth *AuthModule) RemoveResource(resourceName string) error
RemoveResource removes a resource from all groups it belongs to.
func (*AuthModule) RemoveResourceFromGroup ¶ added in v0.9.0
func (auth *AuthModule) RemoveResourceFromGroup( resourceName string, groupName ...string, ) error
RemoveResourceFromGroup removes a resource from one or more groups. It validates that all specified groups exist before removing the resource.
func (*AuthModule) RemoveResourceGroup ¶ added in v0.9.0
func (auth *AuthModule) RemoveResourceGroup(groupName string) error
RemoveResourceGroup removes a resource group and all associated policies. It prevents removal of the enclaveAdmin group to maintain system security.
func (*AuthModule) RemoveUser ¶ added in v0.9.0
func (auth *AuthModule) RemoveUser(userName string) error
RemoveUser removes a user from all groups they belong to.
func (*AuthModule) RemoveUserFromGroup ¶ added in v0.9.0
func (auth *AuthModule) RemoveUserFromGroup( userName string, groupName ...string, ) error
RemoveUserFromGroup removes a user from one or more groups. It validates that all specified groups exist before removing the user.
func (*AuthModule) RemoveUserGroup ¶ added in v0.9.0
func (auth *AuthModule) RemoveUserGroup(groupName string) error
RemoveUserGroup removes a user group and all associated policies. It prevents removal of the enclaveAdmin group to maintain system security.
func (*AuthModule) ResourceGroupExists ¶ added in v0.9.0
func (auth *AuthModule) ResourceGroupExists(groupName string) (bool, error)
ResourceGroupExists checks if a resource group with the specified name exists.
func (*AuthModule) UserGroupExists ¶ added in v0.9.0
func (auth *AuthModule) UserGroupExists(groupName string) (bool, error)
UserGroupExists checks if a user group with the specified name exists.
type CasbinError ¶ added in v0.4.1
func (*CasbinError) Error ¶ added in v0.4.1
func (e *CasbinError) Error() string
func (*CasbinError) Unwrap ¶ added in v0.4.1
func (e *CasbinError) Unwrap() error
type ConflictError ¶ added in v0.4.1
type ConflictError struct {
Reason string
}
func (*ConflictError) Error ¶ added in v0.4.1
func (e *ConflictError) Error() string
type GroupType ¶
type GroupType string
GroupType represents the policy type for different group kinds
type NotFoundError ¶ added in v0.4.1
func (*NotFoundError) Error ¶ added in v0.4.1
func (e *NotFoundError) Error() string
type ResourceGroup ¶
func (ResourceGroup) GetGroupName ¶
func (rg ResourceGroup) GetGroupName() string
func (ResourceGroup) GetName ¶
func (rg ResourceGroup) GetName() string
Implement group interface for ResourceGroup