Skip to content

Commit f66c306

Browse files
committed
merge domain properties
1 parent a1a4fcd commit f66c306

File tree

7 files changed

+54
-45
lines changed

7 files changed

+54
-45
lines changed

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

Lines changed: 44 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@
2222

2323
import com.google.gson.JsonParseException;
2424
import password.pwm.AppProperty;
25+
import password.pwm.DomainProperty;
2526
import password.pwm.PwmConstants;
2627
import password.pwm.bean.DomainID;
2728
import password.pwm.config.AppConfig;
29+
import password.pwm.config.DomainConfig;
2830
import password.pwm.error.PwmError;
2931
import password.pwm.error.PwmUnrecoverableException;
3032
import password.pwm.util.PasswordData;
@@ -52,14 +54,13 @@
5254
import java.util.Optional;
5355
import java.util.Set;
5456
import java.util.function.Supplier;
55-
import java.util.stream.Collectors;
5657

5758
public class PwmHttpRequestWrapper
5859
{
5960
private static final PwmLogger LOGGER = PwmLogger.forClass( PwmHttpRequestWrapper.class );
6061

6162
private final HttpServletRequest httpServletRequest;
62-
private final AppConfig appConfig;
63+
private final DomainConfig domainConfig;
6364

6465
private static final Set<String> HTTP_PARAM_DEBUG_STRIP_VALUES = Set.of(
6566
"password",
@@ -81,9 +82,11 @@ public enum Flag
8182
}
8283

8384
public PwmHttpRequestWrapper( final HttpServletRequest request, final AppConfig appConfig )
85+
throws PwmUnrecoverableException
8486
{
8587
this.httpServletRequest = request;
86-
this.appConfig = appConfig;
88+
final DomainID domainID = readDomainIdFromRequest( request );
89+
this.domainConfig = appConfig.getDomainConfigs().get( domainID );
8790
}
8891

8992
public HttpServletRequest getHttpServletRequest( )
@@ -107,7 +110,7 @@ public boolean isHtmlRequest( )
107110
public String readRequestBodyAsString( )
108111
throws IOException, PwmUnrecoverableException
109112
{
110-
final int maxChars = Integer.parseInt( appConfig.readAppProperty( AppProperty.HTTP_BODY_MAXREAD_LENGTH ) );
113+
final int maxChars = Integer.parseInt( domainConfig.readAppProperty( AppProperty.HTTP_BODY_MAXREAD_LENGTH ) );
111114
return readRequestBodyAsString( maxChars );
112115
}
113116

@@ -124,9 +127,9 @@ public Map<String, String> readBodyAsJsonStringMap( final Flag... flags )
124127
final String bodyString = readRequestBodyAsString();
125128
final Map<String, String> inputMap = JsonFactory.get().deserializeStringMap( bodyString );
126129

127-
final boolean trim = Boolean.parseBoolean( appConfig.readAppProperty( AppProperty.SECURITY_INPUT_TRIM ) );
128-
final boolean passwordTrim = Boolean.parseBoolean( appConfig.readAppProperty( AppProperty.SECURITY_INPUT_PASSWORD_TRIM ) );
129-
final int maxLength = Integer.parseInt( appConfig.readAppProperty( AppProperty.HTTP_PARAM_MAX_READ_LENGTH ) );
130+
final boolean trim = Boolean.parseBoolean( domainConfig.readAppProperty( AppProperty.SECURITY_INPUT_TRIM ) );
131+
final boolean passwordTrim = Boolean.parseBoolean( domainConfig.readAppProperty( AppProperty.SECURITY_INPUT_PASSWORD_TRIM ) );
132+
final int maxLength = Integer.parseInt( domainConfig.readAppProperty( AppProperty.HTTP_PARAM_MAX_READ_LENGTH ) );
130133

131134
final Map<String, String> outputMap = new LinkedHashMap<>();
132135
if ( inputMap != null )
@@ -140,11 +143,11 @@ public Map<String, String> readBodyAsJsonStringMap( final Flag... flags )
140143
String value;
141144
value = bypassInputValidation
142145
? entry.getValue()
143-
: Validator.sanitizeInputValue( appConfig, entry.getValue(), maxLength );
146+
: Validator.sanitizeInputValue( domainConfig.getAppConfig(), entry.getValue(), maxLength );
144147
value = passwordType && passwordTrim ? value.trim() : value;
145148
value = !passwordType && trim ? value.trim() : value;
146149

147-
final String sanitizedName = Validator.sanitizeInputValue( appConfig, key, maxLength );
150+
final String sanitizedName = Validator.sanitizeInputValue( domainConfig.getAppConfig(), key, maxLength );
148151
outputMap.put( sanitizedName, value );
149152
}
150153
}
@@ -160,9 +163,9 @@ public Map<String, Object> readBodyAsJsonMap( final Flag... flags )
160163
final String bodyString = readRequestBodyAsString();
161164
final Map<String, Object> inputMap = JsonFactory.get().deserializeMap( bodyString, String.class, Object.class );
162165

163-
final boolean trim = Boolean.parseBoolean( appConfig.readAppProperty( AppProperty.SECURITY_INPUT_TRIM ) );
164-
final boolean passwordTrim = Boolean.parseBoolean( appConfig.readAppProperty( AppProperty.SECURITY_INPUT_PASSWORD_TRIM ) );
165-
final int maxLength = Integer.parseInt( appConfig.readAppProperty( AppProperty.HTTP_PARAM_MAX_READ_LENGTH ) );
166+
final boolean trim = Boolean.parseBoolean( domainConfig.readAppProperty( AppProperty.SECURITY_INPUT_TRIM ) );
167+
final boolean passwordTrim = Boolean.parseBoolean( domainConfig.readAppProperty( AppProperty.SECURITY_INPUT_PASSWORD_TRIM ) );
168+
final int maxLength = Integer.parseInt( domainConfig.readAppProperty( AppProperty.HTTP_PARAM_MAX_READ_LENGTH ) );
166169

167170
final Map<String, Object> outputMap = new LinkedHashMap<>();
168171
if ( inputMap != null )
@@ -178,7 +181,7 @@ public Map<String, Object> readBodyAsJsonMap( final Flag... flags )
178181
{
179182
String stringValue = bypassInputValidation
180183
? ( String ) entry.getValue()
181-
: Validator.sanitizeInputValue( appConfig, ( String ) entry.getValue(), maxLength );
184+
: Validator.sanitizeInputValue( domainConfig.getAppConfig(), ( String ) entry.getValue(), maxLength );
182185
stringValue = passwordType && passwordTrim ? stringValue.trim() : stringValue;
183186
stringValue = !passwordType && trim ? stringValue.trim() : stringValue;
184187
value = stringValue;
@@ -188,7 +191,7 @@ public Map<String, Object> readBodyAsJsonMap( final Flag... flags )
188191
value = entry.getValue();
189192
}
190193

191-
final String sanitizedName = Validator.sanitizeInputValue( appConfig, key, maxLength );
194+
final String sanitizedName = Validator.sanitizeInputValue( domainConfig.getAppConfig(), key, maxLength );
192195
outputMap.put( sanitizedName, value );
193196
}
194197
}
@@ -200,14 +203,14 @@ public Map<String, Object> readBodyAsJsonMap( final Flag... flags )
200203
public Optional<PasswordData> readParameterAsPassword( final String name )
201204
throws PwmUnrecoverableException
202205
{
203-
final int maxLength = Integer.parseInt( appConfig.readAppProperty( AppProperty.HTTP_PARAM_MAX_READ_LENGTH ) );
204-
final boolean trim = Boolean.parseBoolean( appConfig.readAppProperty( AppProperty.SECURITY_INPUT_PASSWORD_TRIM ) );
206+
final int maxLength = Integer.parseInt( domainConfig.readAppProperty( AppProperty.HTTP_PARAM_MAX_READ_LENGTH ) );
207+
final boolean trim = Boolean.parseBoolean( domainConfig.readAppProperty( AppProperty.SECURITY_INPUT_PASSWORD_TRIM ) );
205208

206209
final String rawValue = httpServletRequest.getParameter( name );
207210
if ( rawValue != null && !rawValue.isEmpty() )
208211
{
209212
final String decodedValue = decodeStringToDefaultCharSet( rawValue );
210-
final String sanitizedValue = Validator.sanitizeInputValue( appConfig, decodedValue, maxLength );
213+
final String sanitizedValue = Validator.sanitizeInputValue( domainConfig.getAppConfig(), decodedValue, maxLength );
211214
if ( sanitizedValue != null )
212215
{
213216
final String trimmedVale = trim ? sanitizedValue.trim() : sanitizedValue;
@@ -232,7 +235,7 @@ public String readParameterAsString( final String name, final int maxLength, fin
232235
public String readParameterAsString( final String name, final String valueIfNotPresent )
233236
throws PwmUnrecoverableException
234237
{
235-
final int maxLength = Integer.parseInt( appConfig.readAppProperty( AppProperty.HTTP_PARAM_MAX_READ_LENGTH ) );
238+
final int maxLength = Integer.parseInt( domainConfig.readAppProperty( AppProperty.HTTP_PARAM_MAX_READ_LENGTH ) );
236239
final String returnValue = readParameterAsString( name, maxLength );
237240
return returnValue == null || returnValue.isEmpty() ? valueIfNotPresent : returnValue;
238241
}
@@ -246,7 +249,7 @@ public boolean hasParameter( final String name )
246249
public String readParameterAsString( final String name, final Flag... flags )
247250
throws PwmUnrecoverableException
248251
{
249-
final int maxLength = Integer.parseInt( appConfig.readAppProperty( AppProperty.HTTP_PARAM_MAX_READ_LENGTH ) );
252+
final int maxLength = Integer.parseInt( domainConfig.readAppProperty( AppProperty.HTTP_PARAM_MAX_READ_LENGTH ) );
250253
return readParameterAsString( name, maxLength, flags );
251254
}
252255

@@ -287,7 +290,7 @@ public List<String> readParameterAsStrings(
287290
{
288291
final boolean bypassInputValidation = flags != null && Arrays.asList( flags ).contains( Flag.BypassValidation );
289292
final HttpServletRequest req = this.getHttpServletRequest();
290-
final boolean trim = Boolean.parseBoolean( appConfig.readAppProperty( AppProperty.SECURITY_INPUT_TRIM ) );
293+
final boolean trim = Boolean.parseBoolean( domainConfig.readAppProperty( AppProperty.SECURITY_INPUT_TRIM ) );
291294
final String[] rawValues = req.getParameterValues( name );
292295
if ( rawValues == null || rawValues.length == 0 )
293296
{
@@ -300,7 +303,7 @@ public List<String> readParameterAsStrings(
300303
final String decodedValue = decodeStringToDefaultCharSet( rawValue );
301304
final String sanitizedValue = bypassInputValidation
302305
? decodedValue
303-
: Validator.sanitizeInputValue( appConfig, decodedValue, maxLength );
306+
: Validator.sanitizeInputValue( domainConfig.getAppConfig(), decodedValue, maxLength );
304307

305308
if ( sanitizedValue.length() > 0 )
306309
{
@@ -333,22 +336,22 @@ public String readHeaderValueAsString( final HttpHeader headerName )
333336

334337
public String readHeaderValueAsString( final String headerName )
335338
{
336-
final int maxChars = Integer.parseInt( appConfig.readAppProperty( AppProperty.HTTP_PARAM_MAX_READ_LENGTH ) );
339+
final int maxChars = Integer.parseInt( domainConfig.readAppProperty( AppProperty.HTTP_PARAM_MAX_READ_LENGTH ) );
337340
final HttpServletRequest req = this.getHttpServletRequest();
338341
final String rawValue = req.getHeader( headerName );
339-
final String sanitizedInputValue = Validator.sanitizeInputValue( appConfig, rawValue, maxChars );
340-
return Validator.sanitizeHeaderValue( appConfig, sanitizedInputValue );
342+
final String sanitizedInputValue = Validator.sanitizeInputValue( domainConfig.getAppConfig(), rawValue, maxChars );
343+
return Validator.sanitizeHeaderValue( domainConfig.getAppConfig(), sanitizedInputValue );
341344
}
342345

343346
public List<String> readHeaderValuesAsString( final String headerName )
344347
{
345-
final int maxChars = Integer.parseInt( appConfig.readAppProperty( AppProperty.HTTP_PARAM_MAX_READ_LENGTH ) );
348+
final int maxChars = Integer.parseInt( domainConfig.readAppProperty( AppProperty.HTTP_PARAM_MAX_READ_LENGTH ) );
346349
final List<String> valueList = new ArrayList<>();
347350
for ( final Enumeration<String> headerValueEnum = this.getHttpServletRequest().getHeaders( headerName ); headerValueEnum.hasMoreElements(); )
348351
{
349352
final String headerValue = headerValueEnum.nextElement();
350-
final String sanitizedInputValue = Validator.sanitizeInputValue( appConfig, headerValue, maxChars );
351-
final String sanitizedHeaderValue = Validator.sanitizeHeaderValue( appConfig, sanitizedInputValue );
353+
final String sanitizedInputValue = Validator.sanitizeInputValue( domainConfig.getAppConfig(), headerValue, maxChars );
354+
final String sanitizedHeaderValue = Validator.sanitizeHeaderValue( domainConfig.getAppConfig(), sanitizedInputValue );
352355
if ( sanitizedHeaderValue != null && !sanitizedHeaderValue.isEmpty() )
353356
{
354357
valueList.add( sanitizedHeaderValue );
@@ -374,20 +377,20 @@ public Map<String, List<String>> readHeaderValuesMap( )
374377

375378
public List<String> headerNames( )
376379
{
377-
final int maxChars = Integer.parseInt( appConfig.readAppProperty( AppProperty.HTTP_PARAM_MAX_READ_LENGTH ) );
380+
final int maxChars = Integer.parseInt( domainConfig.readAppProperty( AppProperty.HTTP_PARAM_MAX_READ_LENGTH ) );
378381

379382
return CollectionUtil.iteratorToStream( getHttpServletRequest().getHeaderNames().asIterator() )
380-
.map( s -> Validator.sanitizeInputValue( appConfig, s, maxChars ) )
381-
.collect( Collectors.toUnmodifiableList() );
383+
.map( s -> Validator.sanitizeInputValue( domainConfig.getAppConfig(), s, maxChars ) )
384+
.toList();
382385

383386
}
384387

385388
public List<String> parameterNames( )
386389
{
387-
final int maxChars = Integer.parseInt( appConfig.readAppProperty( AppProperty.HTTP_PARAM_MAX_READ_LENGTH ) );
390+
final int maxChars = Integer.parseInt( domainConfig.readAppProperty( AppProperty.HTTP_PARAM_MAX_READ_LENGTH ) );
388391

389392
return CollectionUtil.iteratorToStream( getHttpServletRequest().getParameterNames().asIterator() )
390-
.map( s -> Validator.sanitizeInputValue( appConfig, s, maxChars ) )
393+
.map( s -> Validator.sanitizeInputValue( domainConfig.getAppConfig(), s, maxChars ) )
391394
.toList();
392395

393396
}
@@ -409,7 +412,7 @@ public Map<String, String> readParametersAsMap( )
409412
public Map<String, List<String>> readMultiParametersAsMap( )
410413
throws PwmUnrecoverableException
411414
{
412-
final int maxLength = Integer.parseInt( appConfig.readAppProperty( AppProperty.HTTP_PARAM_MAX_READ_LENGTH ) );
415+
final int maxLength = Integer.parseInt( domainConfig.readAppProperty( AppProperty.HTTP_PARAM_MAX_READ_LENGTH ) );
413416

414417
final List<String> parameterNames = parameterNames();
415418

@@ -425,7 +428,7 @@ public Map<String, List<String>> readMultiParametersAsMap( )
425428

426429
public Optional<String> readCookie( final String cookieName )
427430
{
428-
final int maxChars = Integer.parseInt( appConfig.readAppProperty( AppProperty.HTTP_COOKIE_MAX_READ_LENGTH ) );
431+
final int maxChars = Integer.parseInt( domainConfig.readDomainProperty( DomainProperty.HTTP_COOKIE_MAX_READ_LENGTH ) );
429432
final Cookie[] cookies = this.getHttpServletRequest().getCookies();
430433
if ( cookies != null )
431434
{
@@ -437,7 +440,7 @@ public Optional<String> readCookie( final String cookieName )
437440
try
438441
{
439442
final String decodedCookieValue = StringUtil.urlDecode( rawCookieValue );
440-
return Optional.of( Validator.sanitizeInputValue( appConfig, decodedCookieValue, maxChars ) );
443+
return Optional.of( Validator.sanitizeInputValue( domainConfig.getAppConfig(), decodedCookieValue, maxChars ) );
441444
}
442445
catch ( final IOException e )
443446
{
@@ -464,7 +467,12 @@ public HttpMethod getMethod( )
464467

465468
public AppConfig getAppConfig( )
466469
{
467-
return appConfig;
470+
return domainConfig.getAppConfig();
471+
}
472+
473+
public DomainConfig getDomainConfig( )
474+
{
475+
return domainConfig;
468476
}
469477

470478
public String getUrlWithoutQueryString( )

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ public void writeCookie(
380380
else
381381
{
382382
value = StringUtil.urlEncode(
383-
Validator.sanitizeHeaderValue( domainConfig, cookieValue )
383+
Validator.sanitizeHeaderValue( domainConfig.getAppConfig(), cookieValue )
384384
);
385385
}
386386
}

server/src/main/java/password/pwm/http/filter/AbstractPwmFilter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,12 @@ public void doFilter(
7878
try
7979
{
8080
pwmRequest = PwmRequest.forRequest( req, resp );
81-
final PwmURL pwmURL = PwmURL.create( req );
8281
}
8382
catch ( final PwmException e )
8483
{
8584
LOGGER.error( pwmRequest, () -> "unexpected error processing filter chain: " + e.getMessage(), e );
85+
resp.sendError( 500 );
86+
return;
8687
}
8788

8889
try

server/src/main/java/password/pwm/http/filter/DomainInitFilter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ ProcessStatus initializeDomainIdInRequest(
141141
return ProcessStatus.Continue;
142142
}
143143

144-
private static Optional<DomainID> readDomainFromRequest( final PwmApplication pwmApplication, final HttpServletRequest req )
144+
public static Optional<DomainID> readDomainFromRequest( final PwmApplication pwmApplication, final HttpServletRequest req )
145145
{
146146
final boolean pathMode = pwmApplication.getConfig().readSettingAsBoolean( PwmSetting.DOMAIN_DOMAIN_PATHS );
147147
if ( pathMode )

server/src/main/java/password/pwm/util/Validator.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import password.pwm.PwmConstants;
2626
import password.pwm.bean.FormNonce;
2727
import password.pwm.config.AppConfig;
28-
import password.pwm.config.DomainConfig;
2928
import password.pwm.config.PwmSetting;
3029
import password.pwm.error.ErrorInformation;
3130
import password.pwm.error.PwmError;
@@ -153,14 +152,14 @@ public static String sanitizeInputValue(
153152
}
154153

155154

156-
public static String sanitizeHeaderValue( final DomainConfig domainConfig, final String input )
155+
public static String sanitizeHeaderValue( final AppConfig appConfig, final String input )
157156
{
158157
if ( input == null )
159158
{
160159
return null;
161160
}
162161

163-
final String regexStripPatternStr = domainConfig.readAppProperty( AppProperty.SECURITY_HTTP_STRIP_HEADER_REGEX );
162+
final String regexStripPatternStr = appConfig.readAppProperty( AppProperty.SECURITY_HTTP_STRIP_HEADER_REGEX );
164163
if ( regexStripPatternStr != null && !regexStripPatternStr.isEmpty() )
165164
{
166165
final Pattern pattern = Pattern.compile( regexStripPatternStr );

server/src/main/java/password/pwm/ws/server/RestRequest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ private RestRequest(
6666
final SessionLabel sessionLabel,
6767
final HttpServletRequest httpServletRequest
6868
)
69+
throws PwmUnrecoverableException
6970
{
7071
super( httpServletRequest, pwmDomain.getConfig().getAppConfig() );
7172
this.pwmDomain = pwmDomain;

webapp/src/main/webapp/WEB-INF/web.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,15 +160,15 @@
160160
<filter-class>password.pwm.http.filter.DomainRouterFilter</filter-class>
161161
</filter>
162162
<filter-mapping>
163-
<filter-name>CookieUpdateFilter</filter-name>
163+
<filter-name>DomainInitFilter</filter-name>
164164
<url-pattern>/*</url-pattern>
165165
</filter-mapping>
166166
<filter-mapping>
167-
<filter-name>DomainInitFilter</filter-name>
167+
<filter-name>RequestInitializationFilter</filter-name>
168168
<url-pattern>/*</url-pattern>
169169
</filter-mapping>
170170
<filter-mapping>
171-
<filter-name>RequestInitializationFilter</filter-name>
171+
<filter-name>CookieUpdateFilter</filter-name>
172172
<url-pattern>/*</url-pattern>
173173
</filter-mapping>
174174
<filter-mapping>

0 commit comments

Comments
 (0)