{"modulePath":"github.com/infinitbyte/framework","version":"v1.1.5","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package security\n\n## Constants\n\n```go\nconst RoleAdmin = \"admin\"\n```\n\n```go\nconst RoleReadOnly = \"readonly\"\n```\n\n## Functions\n\n```go\nfunc AddUserToContext(ctx context.Context, clam *UserClaims) context.Context\n```\n\n```go\nfunc AssignPermissionsToRoles(permission string, roles ...string)\n```\n\n```go\nfunc GetOrInitRole(role string)\n```\nGetOrInitRole ensures a role exists; if not, it initializes it\n\n```go\nfunc GetPermissionVersion() int32\n```\n\n```go\nfunc GetPermissionsForRole(role string) ([]string, bool)\n```\nGetPermissionsForRole retrieves permissions assigned to a role\n\n```go\nfunc GetSimplePermission(category, resource, action interface{}) string\n```\n\n```go\nfunc GetSimplePermissions(category, resource interface{}, action ...interface{}) []string\n```\n\n```go\nfunc IncreasePermissionVersion()\n```\n\n```go\nfunc MustGetRole(role string)\n```\nMustGetRole ensures a role exists, panics if not registered\n\n```go\nfunc NeedRefreshPermission(ver int32) bool\n```\n\n```go\nfunc RegisterPermissionsToRole(role string, permissions ...string)\n```\nRegisterPermissionsToRole assigns permissions to a role\n\n```go\nfunc UpdatePermissionVersion(i int32)\n```\n\n## Types\n\n```go\ntype AccessToken struct {\n\torm.ORMObjectBase\n\tName        string `json:\"name\"`\n\tUserID      string `json:\"userid\"`\n\tAccessToken string `json:\"access_token\"`\n\n\tProvider string `json:\"provider\"`\n\tLogin    string `json:\"login\"`\n\n\tType        string   `json:\"type\"`\n\tRoles       []string `json:\"roles\"`\n\tPermissions []string `json:\"permissions\"`\n\n\tExpireIn int64 `json:\"expire_in\"`\n}\n```\n\n```go\ntype Action string\n```\nAction is permission action\n\n```go\nconst (\n\t// None is for empty action\n\tNone Action = \"none\"\n\t// Create is for create action\n\tCreate Action = \"create\"\n\t// Read is for read action\n\tRead Action = \"read\"\n\t// Update is for  update action\n\tUpdate Action = \"update\"\n\t// Delete is for delete action\n\tDelete Action = \"delete\"\n\t// Search is for search action\n\tSearch Action = \"search\"\n\t// CRUD is an alias for, create+read+update+delete permissions\n\tCRUD Action = \"crud\"\n\n\tAdmin Action = \"admin\"\n)\n```\n\n```go\ntype PermissionID uint32\n```\n\n```go\nfunc GetOrInitPermission(category, resource string, action string) PermissionID\n```\n\n```go\nfunc GetOrInitPermissionKey(key string) PermissionID\n```\n\n```go\nfunc GetOrInitPermissionKeys(keys ...string) []PermissionID\n```\n\n```go\nfunc MustRegisterPermissionByKey(key string) PermissionID\n```\n\n```go\nfunc MustRegisterPermissionByKeys(key []string) []PermissionID\n```\n\n```go\ntype PermissionRegistry struct {\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc NewPermissionRegistry() *PermissionRegistry\n```\n\n```go\nfunc (pr *PermissionRegistry) GetOrInitPermissionIDByKey(key string) PermissionID\n```\n\n```go\nfunc (pr *PermissionRegistry) MustGetPermissionID(category, resource string, action string) PermissionID\n```\n\n```go\nfunc (pr *PermissionRegistry) MustGetPermissionIDByKey(key string) PermissionID\n```\n\n```go\ntype Preferences struct {\n\tTheme    string `json:\"theme\"`\n\tLanguage string `json:\"language\"`\n}\n```\n\n```go\ntype RoleRegistry struct {\n\t// contains filtered or unexported fields\n}\n```\nRoleRegistry manages roles and their associated permissions\n\n```go\nfunc NewRoleRegistry() *RoleRegistry\n```\nNewRoleRegistry creates a new role registry\n\n```go\nfunc (rr *RoleRegistry) GetOrInitRole(role string)\n```\nGetOrInitRole ensures a role exists, initializing it if necessary\n\n```go\nfunc (rr *RoleRegistry) GetPermissionsForRole(role string) ([]string, bool)\n```\nGetPermissionsForRole retrieves permissions assigned to a role\n\n```go\nfunc (rr *RoleRegistry) MustGetRole(role string)\n```\nMustGetRole ensures a role exists; panics if not found\n\n```go\nfunc (rr *RoleRegistry) RegisterPermissionsForRole(role string, permissions []string)\n```\nRegisterPermissionsToRole associates permissions with a role\n\n```go\ntype SessionUser struct {\n\tProvider string   `json:\"provider\"`\n\tUsername string   `json:\"username\"`\n\tUserId   string   `json:\"user_id\"`\n\tRoles    []string `json:\"roles\"`\n\n\tLabels util.MapStr `json:\"labels\"`\n\n\t*UserAssignedPermission\n}\n```\n\n```go\nfunc UserFromContext(ctx context.Context) (*SessionUser, error)\n```\n\n```go\ntype UserAssignedPermission struct {\n\tPermissionVersion  int32\n\tAllowedPermissions *roaring.Bitmap // Allowed merged bitmap from roles + direct permits\n\tDeniedPermissions  *roaring.Bitmap // Explicit deny bitmap for the user\n}\n```\nUserAssignedPermission represents role and direct permissions for a user in a tenant\n\n```go\nfunc NewUserAssignedPermission(allowed []string, denied []string) *UserAssignedPermission\n```\n\n```go\nfunc (p *UserAssignedPermission) Dump()\n```\nHasPermission checks if the user has a specific permission for a tenant\n\n```go\nfunc (p *UserAssignedPermission) NeedRefresh() bool\n```\n\n```go\nfunc (p *UserAssignedPermission) Validate(permIDs []PermissionID) bool\n```\n\n```go\nfunc (p *UserAssignedPermission) ValidateFor(permID PermissionID) bool\n```\n\n```go\ntype UserClaims struct {\n\t*jwt.RegisteredClaims\n\t*SessionUser\n}\n```\n\n```go\ntype UserExternalProfile struct {\n\torm.ORMObjectBase\n\tUserID       string      `json:\"user_id\"  elastic_mapping:\"user_id: { type: keyword }\"`\n\tAuthProvider string      `json:\"provider\"  elastic_mapping:\"provider: { type: keyword }\"`\n\tLogin        string      `json:\"login\"  elastic_mapping:\"login: { type: keyword }\"`\n\tPayload      interface{} `json:\"payload\" elastic_mapping:\"payload: { type: object }\"`\n}\n```\n\n```go\ntype UserRole struct {\n\tID   string `json:\"id\" elastic_mapping:\"id: { type: keyword }\"`\n\tName string `json:\"name\" elastic_mapping:\"name: { type: keyword }\"`\n}\n```\n\n```go\ntype UserUniversalProfile struct {\n\torm.ORMObjectBase\n\tName        string      `json:\"name\"  elastic_mapping:\"name: { type: keyword }\"`\n\tEmail       string      `json:\"email\" elastic_mapping:\"email: { type: keyword }\"`\n\tPhone       string      `json:\"phone\" elastic_mapping:\"phone: { type: keyword }\"`\n\tAvatarUrl   string      `json:\"avatar\" elastic_mapping:\"avatar: { type: keyword }\"`\n\tRoles       []UserRole  `json:\"roles\" elastic_mapping:\"roles: { type: object }\"`\n\tPreferences Preferences `json:\"preferences\" elastic_mapping:\"preferences: { type: object }\"`\n\tPayload     interface{} `json:\"payload\" elastic_mapping:\"payload: { enabled: false }\"`\n}\n```\n\n","path":"github.com/infinitbyte/framework/core/security","name":"security","synopsis":"","isRedistributable":true}
