Skip to content

Commit

Permalink
Added missing data synchronization after LDAP auth
Browse files Browse the repository at this point in the history
Gitea should synchronize same data from LDAP on user
authentication that is synchronized in cron task.

Fixes: a5c21f1
Related: #18452
Author-Change-Id: IB#1104925
  • Loading branch information
pboguslawski committed Feb 4, 2022
1 parent a5c21f1 commit ca00ec6
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions services/auth/source/ldap/source_authenticate.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ func (source *Source) Authenticate(user *user_model.User, userName, password str
}
if user != nil && !user.ProhibitLogin {
cols := make([]string, 0)
fullName := composeFullName(sr.Name, sr.Surname, sr.Username)
if user.FullName != fullName {
// Update user fullname if changed.
user.FullName = fullName
cols = append(cols, "full_name")
}
if !strings.EqualFold(user.Email, sr.Mail) {
// Update user e-mail if changed.
user.Email = sr.Mail
cols = append(cols, "email")
}
if len(source.AdminFilter) > 0 && user.IsAdmin != sr.IsAdmin {
// Change existing admin flag only if AdminFilter option is set
user.IsAdmin = sr.IsAdmin
Expand All @@ -49,6 +60,11 @@ func (source *Source) Authenticate(user *user_model.User, userName, password str
user.IsRestricted = sr.IsRestricted
cols = append(cols, "is_restricted")
}
if !user.IsActive {
// User existing in LDAP should be active in application.
user.IsActive = true
cols = append(cols, "is_active")
}
if len(cols) > 0 {
err = user_model.UpdateUserCols(db.DefaultContext, user, cols...)
if err != nil {
Expand Down

0 comments on commit ca00ec6

Please sign in to comment.