Documentation
¶
Index ¶
- Constants
- Variables
- func DeleteUserToken(key string)
- func GenerateAccessToken(user *User) (map[string]interface{}, error)
- func GetAPIPermissionRouter(typ string) *routetree.Router
- func GetCurrentUserCluster(req *http.Request) (bool, []string)
- func GetPermissions(typ string) interface{}
- func GetRoleCluster(roles []string) (bool, []string)
- func GetRoleClusterMap(roles []string) map[string][]string
- func GetRoleIndex(roles []string, clusterID string) (bool, []string)
- func IsAllowRoleType(roleType string) (err error)
- func NewUserContext(ctx context.Context, clam *UserClaims) context.Context
- func RegisterAPIPermissionRouter(typ string, router *routetree.Router)
- func RegisterAdapter(typ string, handler Adapter)
- func RegisterPermission(typ string, permissions interface{})
- func SearchAPIPermission(typ string, method, path string) (permission string, params map[string]string, matched bool)
- func SetUserToken(key string, token Token)
- func ValidateCluster(req ClusterRequest, userRole RolePermission) (err error)
- func ValidateIndex(req IndexRequest, userRole RolePermission) (err error)
- func ValidatePermission(claims *UserClaims, permissions []string) (err error)
- type Adapter
- type ClusterPrivilege
- type ClusterRequest
- type ElasticsearchAPIPrivilege
- type ElasticsearchPrivilege
- type EsRequest
- type IRole
- type IUser
- type IndexPrivilege
- type IndexRequest
- type InnerCluster
- type Role
- type RolePermission
- type RolePrivilege
- type RoleType
- type SecurityRealm
- type ShortUser
- type Token
- type User
- type UserClaims
- type UserRole
Constants ¶
View Source
const KVUserToken = "user_token"
View Source
const RoleAdminName = "Administrator"
View Source
const Secret = "console"
Variables ¶
View Source
var BuiltinRoles = make(map[string]Role, 0)
View Source
var RoleMap = make(map[string]Role)
Functions ¶
func DeleteUserToken ¶
func DeleteUserToken(key string)
func GenerateAccessToken ¶
func GetAPIPermissionRouter ¶
func GetCurrentUserCluster ¶
GetCurrentUserCluster get cluster id by current login user return true when has all cluster privilege, otherwise return cluster id list
func GetPermissions ¶
func GetPermissions(typ string) interface{}
func GetRoleCluster ¶
GetRoleCluster get cluster id by given role names return true when has all cluster privilege, otherwise return cluster id list
func GetRoleClusterMap ¶
func IsAllowRoleType ¶
func NewUserContext ¶
func NewUserContext(ctx context.Context, clam *UserClaims) context.Context
func RegisterAdapter ¶
func RegisterPermission ¶
func RegisterPermission(typ string, permissions interface{})
func SearchAPIPermission ¶
func SetUserToken ¶
func ValidateCluster ¶
func ValidateCluster(req ClusterRequest, userRole RolePermission) (err error)
func ValidateIndex ¶
func ValidateIndex(req IndexRequest, userRole RolePermission) (err error)
func ValidatePermission ¶
func ValidatePermission(claims *UserClaims, permissions []string) (err error)
Types ¶
type Adapter ¶
func GetAdapter ¶
type ClusterPrivilege ¶
type ClusterPrivilege struct { Resources []InnerCluster `json:"resources,omitempty" elastic_mapping:"resources: { type: object }"` Permissions []string `json:"permissions,omitempty" elastic_mapping:"permissions: { type: keyword }"` }
type ClusterRequest ¶
type ClusterRequest struct { Cluster string `json:"cluster"` Privilege []string `json:"privilege"` }
func NewClusterRequest ¶
func NewClusterRequest(ps httprouter.Params, privilege []string) ClusterRequest
type ElasticsearchAPIPrivilege ¶
func (ElasticsearchAPIPrivilege) Merge ¶
func (ep ElasticsearchAPIPrivilege) Merge(epa ElasticsearchAPIPrivilege)
type ElasticsearchPrivilege ¶
type ElasticsearchPrivilege struct { Cluster ClusterPrivilege `json:"cluster,omitempty" elastic_mapping:"cluster: { type: object }"` Index []IndexPrivilege `json:"index,omitempty" elastic_mapping:"index: { type: object }"` }
type EsRequest ¶
type EsRequest struct { Doc string `json:"doc"` Privilege string `json:"privilege"` ClusterRequest IndexRequest }
type IndexPrivilege ¶
type IndexRequest ¶
type IndexRequest struct { Cluster string `json:"cluster"` Index string `json:"index"` Privilege []string `json:"privilege"` }
func NewIndexRequest ¶
func NewIndexRequest(ps httprouter.Params, privilege []string) IndexRequest
type InnerCluster ¶
type Role ¶
type Role struct { orm.ORMObjectBase Name string `json:"name" elastic_mapping:"name: { type: keyword }"` Type string `json:"type" elastic_mapping:"type: { type: keyword }"` Description string `json:"description" elastic_mapping:"description: { type: text }"` Builtin bool `json:"builtin" elastic_mapping:"builtin: { type: boolean }"` Privilege RolePrivilege `json:"privilege" elastic_mapping:"privilege: { type: object }"` }
type RolePermission ¶
type RolePermission struct { Platform []string `json:"platform,omitempty"` ElasticPrivilege struct { Cluster ElasticsearchAPIPrivilege Index map[string]ElasticsearchAPIPrivilege } }
func CombineUserRoles ¶
func CombineUserRoles(roleNames []string) RolePermission
type RolePrivilege ¶
type RolePrivilege struct { Platform []string `json:"platform,omitempty" elastic_mapping:"platform: { type: keyword }"` Elasticsearch ElasticsearchPrivilege `json:"elasticsearch,omitempty" elastic_mapping:"elasticsearch: { type: object }"` }
type SecurityRealm ¶
type ShortUser ¶
type Token ¶
type Token struct { JwtStr string `json:"jwt_str"` Value string `json:"value"` ExpireIn int64 `json:"expire_in"` }
func GetUserToken ¶
type User ¶
type User struct { orm.ORMObjectBase AuthProvider string `json:"auth_provider" elastic_mapping:"auth_provider: { type: keyword }"` Username string `json:"name" elastic_mapping:"name: { type: keyword }"` Nickname string `json:"nick_name" elastic_mapping:"nick_name: { type: keyword }"` Password string `json:"password" elastic_mapping:"password: { type: keyword }"` Email string `json:"email" elastic_mapping:"email: { type: keyword }"` Phone string `json:"phone" elastic_mapping:"phone: { type: keyword }"` Tags []string `json:"tags" elastic_mapping:"mobile: { type: keyword }"` AvatarUrl string `json:"avatar_url" elastic_mapping:"avatar_url: { type: keyword }"` Roles []UserRole `json:"roles" elastic_mapping:"roles: { type: object }"` Payload interface{} `json:"-"` //used for storing additional data derived from auth provider }
func (*User) GetPermissions ¶
type UserClaims ¶
type UserClaims struct { *jwt.RegisteredClaims *ShortUser }
func ValidateLogin ¶
func ValidateLogin(authorizationHeader string) (clams *UserClaims, err error)
Source Files
¶
Click to show internal directories.
Click to hide internal directories.