Address review comment by Yan

Resolve review comment in PR #13312

Signed-off-by: Daniel Jiang <jiangd@vmware.com>
This commit is contained in:
Daniel Jiang 2020-10-22 16:53:37 +08:00
parent f4ff369ed0
commit 649c9814e4
2 changed files with 7 additions and 2 deletions

View File

@ -126,7 +126,7 @@ type UserInfo struct {
Username string `json:"name"`
Email string `json:"email"`
Groups []string `json:"groups"`
AdminGroupMember bool `json:"AdminGroupMember"`
AdminGroupMember bool `json:"admin_group_member"`
hasGroupClaim bool
}
@ -382,8 +382,12 @@ func populateGroupsDB(groupNames []string) ([]int, error) {
}
// InjectGroupsToUser populates the group to DB and inject the group IDs to user model.
// The third optional parm is for UT only, when using the func, the third
// The third optional parm is for UT only.
func InjectGroupsToUser(info *UserInfo, user *models.User, f ...populate) {
if info == nil || user == nil {
log.Warningf("user info or user model is nil, skip the func")
return
}
var populateGroups populate
if len(f) == 0 {
populateGroups = populateGroupsDB

View File

@ -62,6 +62,7 @@ func (i *idToken) Generate(req *http.Request) security.Context {
info, err := oidc.UserInfoFromIDToken(ctx, &oidc.Token{RawIDToken: token}, *setting)
if err != nil {
log.Errorf("Failed to get user info from ID token: %v", err)
return nil
}
oidc.InjectGroupsToUser(info, u)
log.Debugf("an ID token security context generated for request %s %s", req.Method, req.URL.Path)