fix: (rbac)
This commit is contained in:
parent
38f5c64153
commit
a1efff50f2
|
@ -98,13 +98,16 @@ func authorize(user Account) (m map[string]interface{}, err error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
var roles []string
|
||||||
|
for _, v := range user.Roles {
|
||||||
|
roles = append(roles, v.Name)
|
||||||
|
}
|
||||||
m = util.MapStr{
|
m = util.MapStr{
|
||||||
"access_token": tokenString,
|
"access_token": tokenString,
|
||||||
"username": user.Username,
|
"username": user.Username,
|
||||||
"id": user.ID,
|
"id": user.ID,
|
||||||
"expire_in": 86400,
|
"expire_in": 86400,
|
||||||
"roles": user.Roles,
|
"roles": roles,
|
||||||
"privilege": []string{
|
"privilege": []string{
|
||||||
"system.user:all", "system.role:all", "system.cluster:all", "system.command:all",
|
"system.user:all", "system.role:all", "system.cluster:all", "system.command:all",
|
||||||
},
|
},
|
||||||
|
|
|
@ -21,6 +21,7 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
type IRole interface {
|
type IRole interface {
|
||||||
|
ListPermission() interface{}
|
||||||
Create(localUser *User) (id string, err error)
|
Create(localUser *User) (id string, err error)
|
||||||
//Delete(localUser *User, id string) (err error)
|
//Delete(localUser *User, id string) (err error)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package rbac
|
package rbac
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
log "github.com/cihub/seelog"
|
||||||
|
"infini.sh/console/internal/biz"
|
||||||
httprouter "infini.sh/framework/core/api/router"
|
httprouter "infini.sh/framework/core/api/router"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
@ -8,19 +10,19 @@ import (
|
||||||
func (h Rbac) ListPermission(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
func (h Rbac) ListPermission(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||||
typ := ps.MustGetParameter("type")
|
typ := ps.MustGetParameter("type")
|
||||||
|
|
||||||
//err := biz.IsAllowRoleType(typ)
|
err := biz.IsAllowRoleType(typ)
|
||||||
//if err != nil {
|
if err != nil {
|
||||||
// h.Error400(w, err.Error())
|
h.Error400(w, err.Error())
|
||||||
// return
|
return
|
||||||
//}
|
}
|
||||||
//role, err := biz.NewRole(typ)
|
role, err := biz.NewRole(typ)
|
||||||
//
|
|
||||||
//if err != nil {
|
if err != nil {
|
||||||
// _ = log.Error(err.Error())
|
_ = log.Error(err.Error())
|
||||||
// h.Error(w, err)
|
h.Error(w, err)
|
||||||
// return
|
return
|
||||||
//}
|
}
|
||||||
|
permissions := role.ListPermission()
|
||||||
h.WriteOKJSON(w, typ)
|
h.WriteOKJSON(w, permissions)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue