fix: (rbac) login roles
This commit is contained in:
parent
a6f3c2203f
commit
95aeeac377
|
@ -28,15 +28,16 @@ type User struct {
|
||||||
Privilege []string `json:"privilege"`
|
Privilege []string `json:"privilege"`
|
||||||
}
|
}
|
||||||
type Account struct {
|
type Account struct {
|
||||||
ID string `json:"id,omitempty" `
|
ID string `json:"id,omitempty" `
|
||||||
Created string `json:"created,omitempty" `
|
Created string `json:"created,omitempty" `
|
||||||
Updated string `json:"updated,omitempty" `
|
Updated string `json:"updated,omitempty" `
|
||||||
Username string `json:"username" elastic_mapping:"username:{type:keyword}"`
|
Username string `json:"username" elastic_mapping:"username:{type:keyword}"`
|
||||||
Password string `json:"password" elastic_mapping:"password:{type:text}"`
|
Password string `json:"password" elastic_mapping:"password:{type:text}"`
|
||||||
Name string `json:"name" elastic_mapping:"name:{type:keyword}"`
|
Name string `json:"name" elastic_mapping:"name:{type:keyword}"`
|
||||||
Phone string `json:"phone" elastic_mapping:"phone:{type:keyword}"`
|
Phone string `json:"phone" elastic_mapping:"phone:{type:keyword}"`
|
||||||
Email string `json:"email" elastic_mapping:"email:{type:keyword}"`
|
Email string `json:"email" elastic_mapping:"email:{type:keyword}"`
|
||||||
Tags []string `json:"tags" elastic_mapping:"tags:{type:text}"`
|
Tags []string `json:"tags" elastic_mapping:"tags:{type:text}"`
|
||||||
|
Roles []rbac.UserRole `json:"roles"`
|
||||||
}
|
}
|
||||||
|
|
||||||
const Secret = "console"
|
const Secret = "console"
|
||||||
|
@ -76,6 +77,9 @@ func authenticateAdmin(username string, password string) (user Account, err erro
|
||||||
}
|
}
|
||||||
user.ID = username
|
user.ID = username
|
||||||
user.Username = username
|
user.Username = username
|
||||||
|
user.Roles = []rbac.UserRole{{
|
||||||
|
Id: "admin", Name: "admin",
|
||||||
|
}}
|
||||||
return user, nil
|
return user, nil
|
||||||
}
|
}
|
||||||
func authorize(user Account) (m map[string]interface{}, err error) {
|
func authorize(user Account) (m map[string]interface{}, err error) {
|
||||||
|
@ -94,12 +98,13 @@ func authorize(user Account) (m map[string]interface{}, err error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
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": []string{"admin"},
|
"roles": user.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",
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue