mirror of
https://github.com/goharbor/harbor.git
synced 2024-12-29 03:57:56 +01:00
Address review comment by Yan
Resolve review comment in PR #13312 Signed-off-by: Daniel Jiang <jiangd@vmware.com>
This commit is contained in:
parent
f4ff369ed0
commit
649c9814e4
@ -126,7 +126,7 @@ type UserInfo struct {
|
|||||||
Username string `json:"name"`
|
Username string `json:"name"`
|
||||||
Email string `json:"email"`
|
Email string `json:"email"`
|
||||||
Groups []string `json:"groups"`
|
Groups []string `json:"groups"`
|
||||||
AdminGroupMember bool `json:"AdminGroupMember"`
|
AdminGroupMember bool `json:"admin_group_member"`
|
||||||
hasGroupClaim bool
|
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.
|
// 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) {
|
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
|
var populateGroups populate
|
||||||
if len(f) == 0 {
|
if len(f) == 0 {
|
||||||
populateGroups = populateGroupsDB
|
populateGroups = populateGroupsDB
|
||||||
|
@ -62,6 +62,7 @@ func (i *idToken) Generate(req *http.Request) security.Context {
|
|||||||
info, err := oidc.UserInfoFromIDToken(ctx, &oidc.Token{RawIDToken: token}, *setting)
|
info, err := oidc.UserInfoFromIDToken(ctx, &oidc.Token{RawIDToken: token}, *setting)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("Failed to get user info from ID token: %v", err)
|
log.Errorf("Failed to get user info from ID token: %v", err)
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
oidc.InjectGroupsToUser(info, u)
|
oidc.InjectGroupsToUser(info, u)
|
||||||
log.Debugf("an ID token security context generated for request %s %s", req.Method, req.URL.Path)
|
log.Debugf("an ID token security context generated for request %s %s", req.Method, req.URL.Path)
|
||||||
|
Loading…
Reference in New Issue
Block a user