Browse Source

fix issue with unexpected 'lambda' class name info appearing in log output

jrivard@gmail.com 6 years ago
parent
commit
8c22029353

+ 14 - 3
server/src/main/java/password/pwm/PwmAboutProperty.java

@@ -24,8 +24,8 @@ package password.pwm;
 
 import password.pwm.config.PwmSetting;
 import password.pwm.i18n.Display;
-import password.pwm.util.i18n.LocaleHelper;
 import password.pwm.util.db.DatabaseService;
+import password.pwm.util.i18n.LocaleHelper;
 import password.pwm.util.java.FileSystemUtility;
 import password.pwm.util.java.StringUtil;
 import password.pwm.util.logging.PwmLogger;
@@ -35,7 +35,6 @@ import java.nio.charset.Charset;
 import java.time.Instant;
 import java.util.Collections;
 import java.util.Date;
-import java.util.LinkedHashMap;
 import java.util.Map;
 import java.util.TreeMap;
 
@@ -146,7 +145,7 @@ public enum PwmAboutProperty
             }
         }
 
-        final Map<PwmAboutProperty, String> returnMap = new LinkedHashMap<>();
+        final Map<PwmAboutProperty, String> returnMap = new TreeMap<>();
         for ( final Map.Entry<String, String> entry : aboutMap.entrySet() )
         {
             returnMap.put( PwmAboutProperty.valueOf( entry.getKey() ), entry.getValue() );
@@ -178,4 +177,16 @@ public enum PwmAboutProperty
     {
         return label == null ? this.name() : label;
     }
+
+    public static Map<String, String> toStringMap( final Map<PwmAboutProperty, String> infoBeanMap )
+    {
+        final Map<String, String> outputProps = new TreeMap<>( );
+        for ( final Map.Entry<PwmAboutProperty, String> entry : infoBeanMap.entrySet() )
+        {
+            final PwmAboutProperty aboutProperty = entry.getKey();
+            final String value = entry.getValue();
+            outputProps.put( aboutProperty.toString().replace( "_", "." ), value );
+        }
+        return Collections.unmodifiableMap( outputProps );
+    }
 }

+ 5 - 9
server/src/main/java/password/pwm/http/servlet/configmanager/DebugItemGenerator.java

@@ -126,8 +126,7 @@ public class DebugItemGenerator
             {
                 final Instant startTime = Instant.now();
                 LOGGER.trace( pwmRequest, () -> "beginning output of item " + serviceClass.getSimpleName() );
-                final Object newInstance = serviceClass.newInstance();
-                final DebugItemGenerator.Generator newGeneratorItem = ( DebugItemGenerator.Generator ) newInstance;
+                final DebugItemGenerator.Generator newGeneratorItem = serviceClass.getDeclaredConstructor().newInstance();
                 zipOutput.putNextEntry( new ZipEntry( pathPrefix + newGeneratorItem.getFilename() ) );
                 newGeneratorItem.outputItem( pwmApplication, pwmRequest, zipOutput );
                 zipOutput.closeEntry();
@@ -262,15 +261,12 @@ public class DebugItemGenerator
             };
 
             final Map<PwmAboutProperty, String> infoBean = PwmAboutProperty.makeInfoBean( pwmApplication );
-            for ( final Map.Entry<PwmAboutProperty, String> entry : infoBean.entrySet() )
+            outputProps.putAll( PwmAboutProperty.toStringMap( infoBean ) );
+            try ( ByteArrayOutputStream baos = new ByteArrayOutputStream() )
             {
-                final PwmAboutProperty aboutProperty = entry.getKey();
-                final String value = entry.getValue();
-                outputProps.put( aboutProperty.toString().replace( "_", "." ), value );
+                outputProps.store( baos, JavaHelper.toIsoDate( Instant.now() ) );
+                outputStream.write( baos.toByteArray() );
             }
-            final ByteArrayOutputStream baos = new ByteArrayOutputStream();
-            outputProps.store( baos, JavaHelper.toIsoDate( Instant.now() ) );
-            outputStream.write( baos.toByteArray() );
         }
     }
 

+ 3 - 3
server/src/main/java/password/pwm/util/logging/PwmLogger.java

@@ -139,7 +139,7 @@ public class PwmLogger
         {
             try
             {
-                final String cleanedString = PwmLogger.removeUserDataFromString( pwmSession.getLoginInfoBean(), message.toString() );
+                final CharSequence cleanedString = PwmLogger.removeUserDataFromString( pwmSession.getLoginInfoBean(), message.get() );
                 cleanedMessage = () -> cleanedString;
             }
             catch ( PwmUnrecoverableException e1 )
@@ -552,7 +552,7 @@ public class PwmLogger
         }
     }
 
-    public static String removeUserDataFromString( final LoginInfoBean loginInfoBean, final String input )
+    public static CharSequence removeUserDataFromString( final LoginInfoBean loginInfoBean, final CharSequence input )
             throws PwmUnrecoverableException
     {
         if ( input == null || loginInfoBean == null )
@@ -560,7 +560,7 @@ public class PwmLogger
             return input;
         }
 
-        String returnString = input;
+        String returnString = input.toString();
         if ( loginInfoBean.getUserCurrentPassword() != null )
         {
             final String pwdStringValue = loginInfoBean.getUserCurrentPassword().getStringValue();