Skip to content

Commit 4626393

Browse files
committed
refactoring and logging improvements
1 parent 00e51c9 commit 4626393

File tree

67 files changed

+1104
-1221
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+1104
-1221
lines changed

lib-util/src/main/java/password/pwm/util/java/JavaHelper.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,26 @@
3636
import java.lang.management.LockInfo;
3737
import java.lang.management.MonitorInfo;
3838
import java.lang.management.ThreadInfo;
39+
import java.lang.reflect.Constructor;
40+
import java.lang.reflect.InvocationTargetException;
3941
import java.lang.reflect.Method;
4042
import java.nio.ByteBuffer;
4143
import java.nio.charset.Charset;
4244
import java.time.Instant;
45+
import java.util.ArrayList;
4346
import java.util.Arrays;
4447
import java.util.Collection;
4548
import java.util.Collections;
4649
import java.util.HexFormat;
4750
import java.util.LinkedHashMap;
4851
import java.util.LinkedHashSet;
52+
import java.util.List;
4953
import java.util.Map;
5054
import java.util.Objects;
5155
import java.util.Optional;
5256
import java.util.Properties;
5357
import java.util.concurrent.atomic.LongAccumulator;
58+
import java.util.function.Function;
5459
import java.util.function.Predicate;
5560
import java.util.zip.GZIPInputStream;
5661
import java.util.zip.GZIPOutputStream;
@@ -496,4 +501,33 @@ public static long nextPositiveLong( final long input )
496501
final long next = input + 1;
497502
return next > 0 ? next : 0;
498503
}
504+
505+
public static <T> List<T> instancesOfSealedInterface( final Class<T> sealedInterface )
506+
{
507+
if ( !Objects.requireNonNull( sealedInterface ).isSealed() )
508+
{
509+
throw new IllegalArgumentException( "sealedInterface argument is required to be marked as sealed" );
510+
}
511+
512+
final Function<Class<T>, T> f = theClass ->
513+
{
514+
try
515+
{
516+
final Constructor<T> constructor = theClass.getDeclaredConstructor();
517+
constructor.setAccessible( true );
518+
return ( T ) constructor.newInstance();
519+
}
520+
catch ( final InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e )
521+
{
522+
throw new RuntimeException( e );
523+
}
524+
};
525+
526+
final List<T> list = new ArrayList<>();
527+
for ( final Class<?> loopClass : sealedInterface.getPermittedSubclasses() )
528+
{
529+
list.add( f.apply( (Class<T> ) loopClass ) );
530+
}
531+
return List.copyOf( list );
532+
}
499533
}

server/src/main/java/password/pwm/PwmAboutProperty.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,8 @@ private static String format( final Instant date )
160160
{
161161
return date.toString();
162162
}
163-
else
164-
{
165-
return LocaleHelper.getLocalizedMessage( PwmConstants.DEFAULT_LOCALE, Display.Value_NotApplicable, null );
166-
}
167163

164+
return LocaleHelper.getLocalizedMessage( PwmConstants.DEFAULT_LOCALE, Display.Value_NotApplicable, null );
168165
}
169166

170167
public String getLabel( )

server/src/main/java/password/pwm/PwmApplication.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ private void postInitTasks()
301301

302302
MBeanUtility.registerMBean( this );
303303

304-
UserAgentUtils.initializeCache();
304+
UserAgentUtils.initializeCache( sessionLabel );
305305

306306
LOGGER.trace( sessionLabel, () -> "completed post init tasks", TimeDuration.fromCurrent( startTime ) );
307307
}

server/src/main/java/password/pwm/PwmConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ public abstract class PwmConstants
151151

152152
public static final String VALUE_REPLACEMENT_USERNAME = "%USERNAME%";
153153

154+
public static final String LOGBACK_APP_PATH_FILENAME = "logback.xml";
154155
public static final String RESOURCE_FILE_EULA_TXT = "eula.txt";
155156
public static final String RESOURCE_FILE_PRIVACY_TXT = "privacy.txt";
156157
public static final String RESOURCE_FILE_WELCOME_TXT = "welcome.txt";

server/src/main/java/password/pwm/bean/SessionLabel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ public static SessionLabel forPwmRequest( final PwmRequest pwmRequest )
168168
}
169169
catch ( final PwmUnrecoverableException e )
170170
{
171-
LOGGER.error( () -> "unexpected error reading username: " + e.getMessage(), e );
171+
LOGGER.error( () -> "unexpected error reading username while building SessionLabel: " + e.getMessage(), e );
172172
}
173173
}
174174
}

server/src/main/java/password/pwm/config/profile/LdapProfile.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,13 +205,15 @@ public String readCanonicalDN(
205205

206206
{
207207
final String finalCanonical = canonicalValue;
208-
LOGGER.trace( () -> "read and cached canonical ldap DN value for input '" + dnValue + "' as '" + finalCanonical + "'",
208+
LOGGER.trace( sessionLabel, () -> "read and cached canonical ldap DN value for input '"
209+
+ dnValue + "' as '" + finalCanonical + "'",
209210
TimeDuration.fromCurrent( startTime ) );
210211
}
211212
}
212213
catch ( final ChaiUnavailableException | ChaiOperationException e )
213214
{
214-
LOGGER.error( () -> "error while reading canonicalDN for dn value '" + dnValue + "', error: " + e.getMessage() );
215+
LOGGER.error( sessionLabel, () -> "error while reading canonicalDN for dn value '"
216+
+ dnValue + "', error: " + e.getMessage() );
215217
return dnValue;
216218
}
217219
}

server/src/main/java/password/pwm/config/profile/PwmPasswordPolicy.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ public ChaiPasswordPolicy getChaiPasswordPolicy( )
239239
return chaiPasswordPolicy;
240240
}
241241

242-
public PasswordRuleReaderHelper getRuleHelper( )
242+
public PasswordRuleReaderHelper ruleHelper( )
243243
{
244244
return new PasswordRuleReaderHelper( this );
245245
}
@@ -341,7 +341,7 @@ private static List<HealthRecord> doHealthChecks( final PwmPasswordPolicy pwmPas
341341
final Locale locale = PwmConstants.DEFAULT_LOCALE;
342342
final PolicyMetaData policyMetaData = pwmPasswordPolicy.getPolicyMetaData();
343343

344-
final PasswordRuleReaderHelper ruleHelper = pwmPasswordPolicy.getRuleHelper();
344+
final PasswordRuleReaderHelper ruleHelper = pwmPasswordPolicy.ruleHelper();
345345
final List<HealthRecord> returnList = new ArrayList<>();
346346
final Map<PwmPasswordRule, PwmPasswordRule> rulePairs = new LinkedHashMap<>();
347347
rulePairs.put( PwmPasswordRule.MinimumLength, PwmPasswordRule.MaximumLength );

server/src/main/java/password/pwm/config/stored/ConfigurationCleaner.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ private static void doConversion(
101101

102102
final Optional<ProfileID> profileID = key.getProfileID();
103103

104-
LOGGER.info( () -> "converting deprecated non-default setting "
104+
LOGGER.info( SESSION_LABEL, () -> "converting deprecated non-default setting "
105105
+ PwmSetting.PASSWORD_POLICY_AD_COMPLEXITY.getKey() + "/" + profileID
106106
+ " to replacement setting "
107107
+ PwmSetting.PASSWORD_POLICY_AD_COMPLEXITY_LEVEL + ", value="
@@ -215,7 +215,8 @@ private void convertSetting(
215215

216216
for ( final ProfileID destProfile : targetProfiles )
217217
{
218-
LOGGER.info( () -> "moving setting " + key + " without profile attribute to profile \"" + destProfile + "\"." );
218+
LOGGER.info( SESSION_LABEL, () -> "moving setting " + key
219+
+ " without profile attribute to profile \"" + destProfile + "\"." );
219220
{
220221
try
221222
{

server/src/main/java/password/pwm/config/stored/StoredConfigXmlSerializer.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,7 @@ public void accept( final XmlDocument xmlDocument )
752752
newValueElement.setText( textValue.get().trim() );
753753
settingElement.attachElement( newValueElement );
754754
final String key = settingElement.getAttribute( StoredConfigXmlConstants.XML_ATTRIBUTE_KEY ).orElse( "" );
755-
LOGGER.info( () -> "migrating pre-xml 'value' tag format to use value element for key: " + key );
755+
LOGGER.info( SESSION_LABEL, () -> "migrating pre-xml 'value' tag format to use value element for key: " + key );
756756
}
757757
}
758758
}
@@ -882,7 +882,8 @@ public void accept( final XmlDocument xmlDocument ) throws PwmUnrecoverableExcep
882882
final Optional<String> value = property.getText();
883883
if ( key.isPresent() && value.isPresent() )
884884
{
885-
LOGGER.info( () -> "migrating app-property config element '" + key.get() + "' to setting " + PwmSetting.APP_PROPERTY_OVERRIDES.getKey() );
885+
LOGGER.info( SESSION_LABEL, () -> "migrating app-property config element '" + key.get()
886+
+ "' to setting " + PwmSetting.APP_PROPERTY_OVERRIDES.getKey() );
886887
final String newValue = key.get() + "=" + value.get();
887888

888889
final List<String> existingValues = new ArrayList<>();

server/src/main/java/password/pwm/health/LDAPHealthChecker.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ public List<HealthRecord> doLdapTestUserCheck(
318318
pwmDomain, sessionLabel, userIdentity, theUser );
319319

320320
boolean doPasswordChange = true;
321-
final int minLifetimeSeconds = passwordPolicy.getRuleHelper().readIntValue( PwmPasswordRule.MinimumLifetime );
321+
final int minLifetimeSeconds = passwordPolicy.ruleHelper().readIntValue( PwmPasswordRule.MinimumLifetime );
322322
if ( minLifetimeSeconds > 0 )
323323
{
324324
final Instant pwdLastModified = PasswordUtility.determinePwdLastModified(

0 commit comments

Comments
 (0)