Skip to content

Commit ca00ec6

Browse files
committed
Added missing data synchronization after LDAP auth
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
1 parent a5c21f1 commit ca00ec6

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

services/auth/source/ldap/source_authenticate.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,17 @@ func (source *Source) Authenticate(user *user_model.User, userName, password str
3939
}
4040
if user != nil && !user.ProhibitLogin {
4141
cols := make([]string, 0)
42+
fullName := composeFullName(sr.Name, sr.Surname, sr.Username)
43+
if user.FullName != fullName {
44+
// Update user fullname if changed.
45+
user.FullName = fullName
46+
cols = append(cols, "full_name")
47+
}
48+
if !strings.EqualFold(user.Email, sr.Mail) {
49+
// Update user e-mail if changed.
50+
user.Email = sr.Mail
51+
cols = append(cols, "email")
52+
}
4253
if len(source.AdminFilter) > 0 && user.IsAdmin != sr.IsAdmin {
4354
// Change existing admin flag only if AdminFilter option is set
4455
user.IsAdmin = sr.IsAdmin
@@ -49,6 +60,11 @@ func (source *Source) Authenticate(user *user_model.User, userName, password str
4960
user.IsRestricted = sr.IsRestricted
5061
cols = append(cols, "is_restricted")
5162
}
63+
if !user.IsActive {
64+
// User existing in LDAP should be active in application.
65+
user.IsActive = true
66+
cols = append(cols, "is_active")
67+
}
5268
if len(cols) > 0 {
5369
err = user_model.UpdateUserCols(db.DefaultContext, user, cols...)
5470
if err != nil {

0 commit comments

Comments
 (0)