Documentation ¶
Overview ¶
casbin 权限管理
@Author: haifengat hubert28@qq.com
@Date: 2023-05-22 13:57:25
@LastEditors: haifengat hubert28@qq.com
@LastEditTime: 2023-05-22 14:11:41
@FilePath: /cas/check_role.go
@Description:
@Author: haifengat hubert28@qq.com
@Date: 2023-04-30 10:13:52
@LastEditors: haifengat hubert28@qq.com
@LastEditTime: 2023-05-31 10:34:18
@FilePath: /cas/init.go
@Description: 初始化 casdoor
Index ¶
- func AddPolicy(roleName, path, method string) (bool, error)
- func AddUserToRole(userName, roleName string) (bool, error)
- func CheckRole(roleName, urlPath, methord string) (bool, error)
- func GetEnforcer() (*casbin.Enforcer, error)
- func GetRolesForUser(userName string) (roles []string)
- func GetUsersForRole(roleName string) (users []string)
- func HdlChangePassword(c *gin.Context)
- func HdlCheckAuth(ctx *gin.Context)
- func HdlCheckRole(c *gin.Context)
- func HdlGetClaims(c *gin.Context) *casdoorsdk.Claims
- func HdlSignin(c *gin.Context)
- func HdlSignout(c *gin.Context)
- func InitCas(endpoint, clientID, clientSecret, certificate, organizationName, ... string) error
- func InitCasAdapter(dmDSN, modelFilePath string) error
- func InitRouter(g *gin.RouterGroup)
- func RemovePolicy(roleName, path, method string) (bool, error)
- func RemoveUserFromRole(userName, roleName string) (bool, error)
- func UpdatePolicy(roleName, oldPath, oldMethod string, newPath, newMethod string) (bool, error)
- type CasbinModel
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddPolicy ¶ added in v0.0.5
AddPolicy 添加授权规则
@param roleName string 角色 @param path string urlPath @param method string method GET/POST/PUT @return bool 如果规则已经存在,函数返回false,并且不会添加规则。 否则,函数通过添加新规则并返回true。 @return error 错误
func AddUserToRole ¶ added in v0.0.5
AddUserToRole 添加用户到角色
@param userName string 用户 @param roleName string 角色 @return bool 如果规则已经存在,函数返回false,并且不会添加规则。 否则,函数通过添加新规则并返回true。 @return error 错误
func CheckRole ¶ added in v0.0.5
CheckRole 检查用户是否有权限
@param roleName string 角色 @param urlPath string urlPath @param methord string method GET/POST/PUT @return bool 通过 @return error 错误
func GetEnforcer ¶ added in v0.0.5
func GetEnforcer() (*casbin.Enforcer, error)
GetEnforcer 取得 casbin 的 enforcer
须先执行 InitCasAdapter, 否则返回 nil
@return *casbin.Enforcer @return error
func GetRolesForUser ¶ added in v0.0.5
GetRolesForUser 获取用户角色
@receiver e @param userName string 用户 @return []string 角色列表, 如果没有对应的角色,则返回空列表
func GetUsersForRole ¶ added in v0.0.5
GetUsersForRole 获取角色的用户列表
@receiver e @param roleName string 角色 @return users 用户列表, 如果没有对应的用户,则返回空列表
func HdlChangePassword ¶ added in v0.0.5
HdlChangePassword 修改密码
@param oldPassword PostString @param newPassword PostString @router /changePassword [POST]
func HdlGetClaims ¶ added in v0.0.5
func HdlGetClaims(c *gin.Context) *casdoorsdk.Claims
HdlGetClaims
@param c @return *casdoorsdk.Claims
func HdlSignin ¶ added in v0.0.5
HdlSignin 登录
@Description sign in as a member @Param code QueryString "The code to sign in" @Param state QueryString "The state" @Success 200 {Status: "success", Msg: "登录成功", Data: claims, Data2: affected} @router /signin [GET]
func HdlSignout ¶ added in v0.0.5
HdlSignout 登出
@Description sign out the current member @Success 200 {Status: "success"} @router /signout [post]
func InitCas ¶ added in v0.0.2
func InitCas(endpoint, clientID, clientSecret, certificate, organizationName, applicationName string) error
InitCas 初始化 cas 配置
@param endpoint casdoor 网址 @param clientID 应用对应的 id @param clientSecret 应用对应的 secret @param certificate 证书内容 @param organizationName 组织 @param applicationName 应用名 @return error
func InitCasAdapter ¶ added in v0.0.5
InitCasAdapter 初始化适配器
@param dmDSN string 达梦DSN @param rbacModelFile string path/to/basic_model.conf @return error 错误
func InitRouter ¶
func InitRouter(g *gin.RouterGroup)
InitRouter 初始化cas路由 /code /signin /signout /hello
@param g
func RemovePolicy ¶ added in v0.0.5
RemovePolicy 删除授权规则
@param roleName string 角色名称 @param path string urlPath @param method string method GET/POST/PUT @return bool 如消规则不存圮,函数返回false,如添加成功,函数返回true。 @return error
func RemoveUserFromRole ¶ added in v0.0.5
RemoveUserFromRole 删除用户
@receiver e @param userName string 用户 @param roleName string 角色 @return bool @return error
func UpdatePolicy ¶ added in v0.0.5
UpdatePolicy 更新授权规则
@param oldRoleName string 角色 @param oldPath string urlPath @param oldMethod string method GET/POST/PUT @param newPath string urlPath @param newMethod string method GET/POST/PUT @return bool @return error
Types ¶
type CasbinModel ¶ added in v0.0.5
type CasbinModel struct { Ptype string `json:"ptype" bson:"ptype"` RoleName string `json:"rolename" bson:"v0"` Path string `json:"path" bson:"v1"` Method string `json:"method" bson:"v2"` }
func GetCasbin ¶ added in v0.0.5
func GetCasbin() []CasbinModel
GetCasbin 获取所有授权规则
@return []CasbinModel 规则
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
* @Author: haifengat hubert28@qq.com * @Date: 2023-05-01 11:36:29 * @LastEditors: haifengat hubert28@qq.com * @LastEditTime: 2023-05-01 11:37:38 * @FilePath: /cas/demo/main.go * @Description: cas 示例
|
* @Author: haifengat hubert28@qq.com * @Date: 2023-05-01 11:36:29 * @LastEditors: haifengat hubert28@qq.com * @LastEditTime: 2023-05-01 11:37:38 * @FilePath: /cas/demo/main.go * @Description: cas 示例 |