Quellcode durchsuchen

improve handling of missing ldap guid values

Jason Rivard vor 7 Jahren
Ursprung
Commit
28f9666505

+ 10 - 5
server/src/main/java/password/pwm/ldap/LdapOperationsHelper.java

@@ -39,9 +39,9 @@ import password.pwm.PwmApplication;
 import password.pwm.bean.SessionLabel;
 import password.pwm.bean.UserIdentity;
 import password.pwm.config.Configuration;
-import password.pwm.config.value.data.FormConfiguration;
 import password.pwm.config.PwmSetting;
 import password.pwm.config.profile.LdapProfile;
+import password.pwm.config.value.data.FormConfiguration;
 import password.pwm.error.ErrorInformation;
 import password.pwm.error.PwmError;
 import password.pwm.error.PwmOperationalException;
@@ -159,6 +159,7 @@ public class LdapOperationsHelper {
     }
 
 
+    private static final String NULL_CACHE_GUID = "NULL_CACHE_GUID";
     public static String readLdapGuidValue(
             final PwmApplication pwmApplication,
             final SessionLabel sessionLabel,
@@ -167,14 +168,15 @@ public class LdapOperationsHelper {
     )
             throws ChaiUnavailableException, PwmUnrecoverableException
     {
-
         final boolean enableCache = Boolean.parseBoolean(pwmApplication.getConfig().readAppProperty(AppProperty.LDAP_CACHE_USER_GUID_ENABLE));
         final CacheKey cacheKey = CacheKey.makeCacheKey(LdapOperationsHelper.class, null, "guidValue-" + userIdentity.toDelimitedKey());
 
         if (enableCache) {
             final String cachedValue = pwmApplication.getCacheService().get(cacheKey);
             if (cachedValue != null) {
-                return cachedValue;
+                return NULL_CACHE_GUID.equals(cachedValue)
+                        ? null
+                        : cachedValue;
             }
         }
 
@@ -187,7 +189,7 @@ public class LdapOperationsHelper {
 
         final LdapProfile ldapProfile = pwmApplication.getConfig().getLdapProfiles().get(userIdentity.getLdapProfileID());
         final String guidAttributeName = ldapProfile.readSettingAsString(PwmSetting.LDAP_GUID_ATTRIBUTE);
-        if (existingValue == null || existingValue.length() < 1) {
+        if (StringUtil.isEmpty(existingValue)) {
             if (!"DN".equalsIgnoreCase(guidAttributeName) && !"VENDORGUID".equalsIgnoreCase(guidAttributeName)) {
                 if (ldapProfile.readSettingAsBoolean(PwmSetting.LDAP_GUID_AUTO_ADD)) {
                     LOGGER.trace("assigning new GUID to user " + userIdentity);
@@ -201,7 +203,10 @@ public class LdapOperationsHelper {
         if (enableCache) {
             final long cacheSeconds = Long.parseLong(pwmApplication.getConfig().readAppProperty(AppProperty.LDAP_CACHE_USER_GUID_SECONDS));
             final CachePolicy cachePolicy = CachePolicy.makePolicyWithExpiration(new TimeDuration(cacheSeconds, TimeUnit.SECONDS));
-            pwmApplication.getCacheService().put(cacheKey, cachePolicy, existingValue);
+            final String cacheValue = existingValue == null
+                    ? NULL_CACHE_GUID
+                    : existingValue;
+            pwmApplication.getCacheService().put(cacheKey, cachePolicy, cacheValue);
         }
 
         return existingValue;

+ 1 - 1
server/src/main/java/password/pwm/ldap/search/UserSearchEngine.java

@@ -605,7 +605,7 @@ public class UserSearchEngine implements PwmService {
                     final Throwable t = e.getCause();
                     final ErrorInformation errorInformation;
                     final String errorMsg = "unexpected error during ldap search ("
-                            + "profile=" + jobInfo.getUserSearchJob().getLdapProfile() + ")"
+                            + "profile=" + jobInfo.getUserSearchJob().getLdapProfile().getIdentifier() + ")"
                             + ", error: " + (t instanceof PwmException ? t.getMessage() : JavaHelper.readHostileExceptionMessage(t));
                     if (t instanceof PwmException) {
                         errorInformation = new ErrorInformation(((PwmException) t).getError(), errorMsg);

+ 5 - 5
server/src/main/java/password/pwm/util/logging/PwmLogEvent.java

@@ -37,7 +37,7 @@ import java.time.Instant;
 @Getter
 public class PwmLogEvent implements Serializable, Comparable {
 
-    private static final int MAX_MESSAGE_LENGTH = 1_000_000;
+    private static final int MAX_MESSAGE_LENGTH = 100_000;
 
 
     // ------------------------------ FIELDS ------------------------------
@@ -94,13 +94,13 @@ public class PwmLogEvent implements Serializable, Comparable {
             throw new IllegalArgumentException("level may not be null");
         }
 
-        if (message != null && message.length() > MAX_MESSAGE_LENGTH) {
-            throw new IllegalStateException("log message length is too long (" + message.length() + " chars)");
-        }
+        final String retainedMessage = message != null && message.length() > MAX_MESSAGE_LENGTH
+                ? message.substring(0, MAX_MESSAGE_LENGTH) + " [truncated message]"
+                : message;
 
         this.date = date;
         this.topic = topic;
-        this.message = message;
+        this.message = retainedMessage;
         this.source = source;
         this.actor = actor;
         this.label = label;