Skip to content

Commit aff15fd

Browse files
committed
pw form field js/css refactoring and de-dojo in changepassword and newuser modules
1 parent 16c7b70 commit aff15fd

31 files changed

+611
-471
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public static <V> List<V> stripNulls( final List<V> input )
6464

6565
return input.stream()
6666
.filter( Objects::nonNull )
67-
.collect( Collectors.toUnmodifiableList() );
67+
.toList();
6868
}
6969

7070
public static <V> Set<V> stripNulls( final Set<V> input )

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import java.util.Arrays;
4444
import java.util.Collection;
4545
import java.util.Collections;
46+
import java.util.HexFormat;
4647
import java.util.LinkedHashMap;
4748
import java.util.LinkedHashSet;
4849
import java.util.Map;
@@ -56,21 +57,15 @@
5657

5758
public final class JavaHelper
5859
{
59-
private static final char[] HEX_CHAR_ARRAY = "0123456789ABCDEF".toCharArray();
60+
private static final HexFormat HEX_FORMAT = HexFormat.of().withUpperCase();
6061

6162
private JavaHelper()
6263
{
6364
}
6465

6566
public static String binaryArrayToHex( final byte[] buf )
6667
{
67-
final char[] chars = new char[2 * buf.length];
68-
for ( int i = 0; i < buf.length; ++i )
69-
{
70-
chars[2 * i] = HEX_CHAR_ARRAY[( buf[i] & 0xF0 ) >>> 4];
71-
chars[2 * i + 1] = HEX_CHAR_ARRAY[buf[i] & 0x0F];
72-
}
73-
return new String( chars );
68+
return HEX_FORMAT.formatHex( buf );
7469
}
7570

7671
public static String throwableToString( final Throwable throwable )

lib-util/src/test/java/password/pwm/util/java/JavaHelperTest.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,36 @@
2323
import org.junit.jupiter.api.Assertions;
2424
import org.junit.jupiter.api.Test;
2525

26+
import java.util.stream.IntStream;
27+
2628
public class JavaHelperTest
2729
{
30+
@Test
31+
public void binaryArrayToHexTest()
32+
{
33+
{
34+
final byte[] bytes = {
35+
3,
36+
127,
37+
41,
38+
16,
39+
};
40+
Assertions.assertEquals( "037F2910", JavaHelper.binaryArrayToHex( bytes ) );
41+
}
42+
43+
{
44+
45+
final byte[] bytes = new byte[128];
46+
IntStream.range( 0, 127 ).forEach( value -> bytes[value] = (byte) value );
47+
Assertions.assertEquals(
48+
"""
49+
000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2\
50+
C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F505152535455565758\
51+
595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E00\
52+
""",
53+
JavaHelper.binaryArrayToHex( bytes ) );
54+
}
55+
}
2856

2957
@Test
3058
public void concatByteArraysTwo()

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

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ public class PwmApplication
9090
{
9191
private static final PwmLogger LOGGER = PwmLogger.forClass( PwmApplication.class );
9292

93-
static final int DOMAIN_STARTUP_THREADS = 10;
93+
static final int DOMAIN_STARTUP_THREAD_COUNT = 10;
9494

95-
private volatile Map<DomainID, PwmDomain> domains = new HashMap<>();
95+
private volatile Map<DomainID, PwmDomain> domains = Map.of();
9696
private String runtimeNonce = PwmApplicationUtil.makeRuntimeNonce();
9797

9898
private final SessionLabel sessionLabel;
@@ -240,22 +240,39 @@ public void reInit( final PwmEnvironment pwmEnvironment )
240240
this.pwmEnvironment = pwmEnvironment;
241241
final AppConfig newConfig = this.pwmEnvironment.getConfig();
242242

243+
warnOnOlderNewConfig( oldConfig, newConfig );
244+
243245
if ( !Objects.equals( oldConfig.getValueHash(), newConfig.getValueHash() ) )
244246
{
245247
processPwmAppRestart( );
246248
}
247249
else
248250
{
249-
LOGGER.debug( sessionLabel, () -> "no system-level settings have been changed, restart of system services is not required" );
251+
LOGGER.debug( sessionLabel, () -> "no system-level settings have been changed"
252+
+ ", restart of system services is not required" );
250253
}
251254

252255
PwmDomainUtil.reInitDomains( this, newConfig, oldConfig );
253256

254257
runtimeNonce = PwmApplicationUtil.makeRuntimeNonce();
255258

256-
LOGGER.debug( sessionLabel, () -> "completed application restart with " + domains().size() + " domains", TimeDuration.fromCurrent( startTime ) );
259+
LOGGER.debug( sessionLabel, () -> "completed application restart with " + domains().size()
260+
+ " domains", TimeDuration.fromCurrent( startTime ) );
257261
}
258262

263+
private void warnOnOlderNewConfig( final AppConfig oldConfig, final AppConfig newConfig )
264+
{
265+
final Instant newInstant = newConfig.getStoredConfiguration().modifyTime();
266+
final Instant oldInstant = oldConfig.getStoredConfiguration().modifyTime();
267+
if ( newInstant != null && oldInstant != null && newInstant.isBefore( oldInstant ) )
268+
{
269+
LOGGER.warn( sessionLabel, () -> " oldConfig (" + oldInstant + ") "
270+
+ "is newer than new config (" + newInstant + ") by "
271+
+ TimeDuration.between( oldInstant, newInstant ).asCompactString() );
272+
}
273+
}
274+
275+
259276
private void postInitTasks()
260277
{
261278
final Instant startTime = Instant.now();
@@ -382,7 +399,7 @@ public void shutdown( )
382399

383400
final Instant startDomainShutdown = Instant.now();
384401
LOGGER.trace( sessionLabel, () -> "beginning shutdown of " + callables.size() + " running domains" );
385-
pwmScheduler.executeImmediateThreadPerJobAndAwaitCompletion( DOMAIN_STARTUP_THREADS, callables, sessionLabel, PwmApplication.class );
402+
pwmScheduler.executeImmediateThreadPerJobAndAwaitCompletion( DOMAIN_STARTUP_THREAD_COUNT, callables, sessionLabel, PwmApplication.class );
386403
LOGGER.trace( sessionLabel, () -> "shutdown of " + callables.size() + " running domains completed", TimeDuration.fromCurrent( startDomainShutdown ) );
387404
}
388405
catch ( final PwmUnrecoverableException e )

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

Lines changed: 34 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import password.pwm.config.stored.StoredConfigurationUtil;
2727
import password.pwm.error.PwmUnrecoverableException;
2828
import password.pwm.util.java.CollectionUtil;
29+
import password.pwm.util.java.EnumUtil;
2930
import password.pwm.util.java.TimeDuration;
3031
import password.pwm.util.logging.PwmLogger;
3132

@@ -39,6 +40,7 @@
3940
import java.util.Set;
4041
import java.util.TreeMap;
4142
import java.util.concurrent.Callable;
43+
import java.util.function.Function;
4244
import java.util.stream.Collectors;
4345

4446
class PwmDomainUtil
@@ -79,11 +81,15 @@ static void initDomains(
7981
LOGGER.trace( pwmApplication.getSessionLabel(), () -> "beginning domain initializations" );
8082

8183
final List<Callable<Optional<PwmUnrecoverableException>>> callables = domains.stream()
82-
.map( DomainInitializingCallable::new )
83-
.collect( Collectors.toUnmodifiableList() );
84+
.map( PwmDomainUtil::makeCallableDomainInit )
85+
.toList();
8486

85-
final List<Optional<PwmUnrecoverableException>> domainStartException = pwmApplication.getPwmScheduler()
86-
.executeImmediateThreadPerJobAndAwaitCompletion( PwmApplication.DOMAIN_STARTUP_THREADS, callables, pwmApplication.getSessionLabel(), PwmDomainUtil.class );
87+
final List<Optional<PwmUnrecoverableException>> domainStartException = pwmApplication.getPwmScheduler()
88+
.executeImmediateThreadPerJobAndAwaitCompletion(
89+
PwmApplication.DOMAIN_STARTUP_THREAD_COUNT,
90+
callables,
91+
pwmApplication.getSessionLabel(),
92+
PwmDomainUtil.class );
8793

8894
final Optional<PwmUnrecoverableException> domainStartupException = domainStartException.stream()
8995
.filter( Optional::isPresent )
@@ -99,17 +105,9 @@ static void initDomains(
99105
TimeDuration.fromCurrent( domainInitStartTime ) );
100106
}
101107

102-
private static class DomainInitializingCallable implements Callable<Optional<PwmUnrecoverableException>>
108+
private static Callable<Optional<PwmUnrecoverableException>> makeCallableDomainInit( final PwmDomain pwmDomain )
103109
{
104-
private final PwmDomain pwmDomain;
105-
106-
DomainInitializingCallable( final PwmDomain pwmDomain )
107-
{
108-
this.pwmDomain = pwmDomain;
109-
}
110-
111-
@Override
112-
public Optional<PwmUnrecoverableException> call()
110+
return () ->
113111
{
114112
try
115113
{
@@ -120,7 +118,7 @@ public Optional<PwmUnrecoverableException> call()
120118
{
121119
return Optional.of( e );
122120
}
123-
}
121+
};
124122
}
125123

126124
static void reInitDomains(
@@ -164,7 +162,8 @@ static void reInitDomains(
164162

165163
if ( newDomains.isEmpty() && deletedDomains.isEmpty() )
166164
{
167-
LOGGER.debug( pwmApplication.getSessionLabel(), () -> "no domain-level settings have been changed, restart of domain services is not required" );
165+
LOGGER.debug( pwmApplication.getSessionLabel(),
166+
() -> "no domain-level settings have been changed, restart of domain services is not required" );
168167
}
169168

170169
if ( !newDomains.isEmpty() )
@@ -197,35 +196,37 @@ private static void processDeletedDomains(
197196

198197
enum DomainModifyCategory
199198
{
200-
removed,
201-
unchanged,
202-
modified,
203-
created,
199+
removed( new RemovalClassifier() ),
200+
unchanged( new UnchangedClassifier() ),
201+
modified( new ModifiedClassifier() ),
202+
created( new CreationClassifier() ),;
203+
204+
private final DomainModificationClassifier classifier;
205+
206+
DomainModifyCategory( final DomainModificationClassifier classifier )
207+
{
208+
this.classifier = classifier;
209+
}
210+
211+
public DomainModificationClassifier classifier()
212+
{
213+
return classifier;
214+
}
204215
}
205216

206217
public static Map<DomainModifyCategory, Set<DomainID>> categorizeDomainModifications(
207218
final AppConfig newConfig,
208219
final AppConfig oldConfig
209220
)
210221
{
211-
{
212-
final Instant newInstant = newConfig.getStoredConfiguration().modifyTime();
213-
final Instant oldInstant = oldConfig.getStoredConfiguration().modifyTime();
214-
if ( newInstant != null && oldInstant != null && newInstant.isBefore( oldInstant ) )
215-
{
216-
throw new IllegalStateException( "refusing request to categorize changes due to oldConfig "
217-
+ "being newer than new config" );
218-
}
219-
}
220-
221222
final Set<StoredConfigKey> modifiedValues = StoredConfigurationUtil.changedValues(
222223
newConfig.getStoredConfiguration(),
223224
oldConfig.getStoredConfiguration() );
224225

225-
return CLASSIFIERS.entrySet().stream()
226+
return EnumUtil.enumStream( DomainModifyCategory.class )
226227
.collect( Collectors.toUnmodifiableMap(
227-
Map.Entry::getKey,
228-
entry -> entry.getValue().categorize( newConfig, oldConfig, modifiedValues )
228+
Function.identity(),
229+
entry -> entry.classifier().categorize( newConfig, oldConfig, modifiedValues )
229230
) );
230231
}
231232

@@ -234,12 +235,6 @@ interface DomainModificationClassifier
234235
Set<DomainID> categorize( AppConfig newConfig, AppConfig oldConfig, Set<StoredConfigKey> modifiedValues );
235236
}
236237

237-
private static final Map<DomainModifyCategory, DomainModificationClassifier> CLASSIFIERS = Map.of(
238-
DomainModifyCategory.removed, new RemovalClassifier(),
239-
DomainModifyCategory.created, new CreationClassifier(),
240-
DomainModifyCategory.unchanged, new UnchangedClassifier(),
241-
DomainModifyCategory.modified, new ModifiedClassifier() );
242-
243238
private static class RemovalClassifier implements DomainModificationClassifier
244239
{
245240
@Override

server/src/main/java/password/pwm/http/PwmRequestAttribute.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ public enum PwmRequestAttribute
7979

8080
ChangePassword_MaxWaitSeconds,
8181
ChangePassword_CheckIntervalSeconds,
82-
ChangePassword_PasswordPolicyChangeMessage,
8382

8483
ForgottenPasswordChallengeSet,
8584
ForgottenPasswordOptionalPageView,
@@ -107,5 +106,7 @@ public enum PwmRequestAttribute
107106
ExternalResponsePrompts,
108107
ExternalResponseInstructions,
109108

109+
JspIndexTabCounter,
110+
110111
GoBackAction,;
111112
}

server/src/main/java/password/pwm/http/PwmRequestUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public static Optional<String> readUserNetworkAddress(
143143
{
144144
final String xForwardedForValue = request.getHeader( HttpHeader.XForwardedFor.getHttpName() );
145145
if ( StringUtil.notEmpty( xForwardedForValue ) )
146-
{
146+
{
147147
Collections.addAll( candidateAddresses, xForwardedForValue.split( "," ) );
148148
}
149149
}

server/src/main/java/password/pwm/http/servlet/changepw/ChangePasswordServlet.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -589,14 +589,6 @@ public ProcessStatus preProcessCheck( final PwmRequest pwmRequest )
589589

590590
private void forwardToChangePage( final PwmRequest pwmRequest ) throws ServletException, PwmUnrecoverableException, IOException
591591
{
592-
final Optional<String> passwordPolicyChangeMessage = pwmRequest.getPwmSession().getUserInfo().getPasswordPolicy().getChangeMessage( pwmRequest.getLocale() );
593-
if ( passwordPolicyChangeMessage.isPresent() )
594-
{
595-
final MacroRequest macroRequest = pwmRequest.getMacroMachine( );
596-
final String expandedMessage = macroRequest.expandMacros( passwordPolicyChangeMessage.get() );
597-
pwmRequest.setAttribute( PwmRequestAttribute.ChangePassword_PasswordPolicyChangeMessage, expandedMessage );
598-
}
599-
600592
pwmRequest.forwardToJsp( JspUrl.PASSWORD_CHANGE );
601593
}
602594
}

server/src/main/java/password/pwm/http/tag/CurrentUrlTag.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public int doEndTag( )
5252
{
5353
/* ignore */
5454
}
55-
LOGGER.error( () -> "error during CurrentUrl output: " + e.getMessage() );
55+
LOGGER.error( () -> "error during CurrentUrl output: " + e.getMessage(), e );
5656
}
5757
return EVAL_PAGE;
5858
}

0 commit comments

Comments
 (0)