From f3fe030951831eef43a1004d700b9ca362cfc793 Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Thu, 25 Sep 2014 11:27:42 -0700 Subject: [PATCH] [ZD-21561] Do not make idempotent updates addProperty() results in a costly save operation, so don't do that unless we think the value has changed. This is significant because this code gets called every time the user logs in, including every time the HTTP basic auth happens. --- src/main/java/hudson/security/LDAPSecurityRealm.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/hudson/security/LDAPSecurityRealm.java b/src/main/java/hudson/security/LDAPSecurityRealm.java index 98b364b..f9d3679 100644 --- a/src/main/java/hudson/security/LDAPSecurityRealm.java +++ b/src/main/java/hudson/security/LDAPSecurityRealm.java @@ -37,6 +37,7 @@ import hudson.model.Descriptor; import hudson.model.User; import hudson.tasks.MailAddressResolver; import hudson.tasks.Mailer; +import hudson.tasks.Mailer.UserProperty; import hudson.util.FormValidation; import hudson.util.ListBoxModel; import hudson.util.Scrambler; @@ -688,7 +689,7 @@ public class LDAPSecurityRealm extends AbstractPasswordBasedSecurityRealm { try { Attribute attribute = d.getAttributes().get(getDisplayNameAttributeName()); String displayName = attribute == null ? null : (String) attribute.get(); - if (StringUtils.isNotBlank(displayName) && u.getId().equals(u.getFullName())) { + if (StringUtils.isNotBlank(displayName) && u.getId().equals(u.getFullName()) && !u.getFullName().equals(displayName)) { u.setFullName(displayName); } } catch (NamingException e) { @@ -699,7 +700,9 @@ public class LDAPSecurityRealm extends AbstractPasswordBasedSecurityRealm { Attribute attribute = d.getAttributes().get(getMailAddressAttributeName()); String mailAddress = attribute == null ? null : (String) attribute.get(); if (StringUtils.isNotBlank(mailAddress)) { - u.addProperty(new Mailer.UserProperty(mailAddress)); + UserProperty existing = u.getProperty(UserProperty.class); + if (existing==null || !existing.hasExplicitlyConfiguredAddress()) + u.addProperty(new Mailer.UserProperty(mailAddress)); } } catch (NamingException e) { LOGGER.log(Level.FINEST, "Could not retrieve email address attribute", e);