2222
2323import com .google .gson .JsonParseException ;
2424import password .pwm .AppProperty ;
25+ import password .pwm .DomainProperty ;
2526import password .pwm .PwmConstants ;
2627import password .pwm .bean .DomainID ;
2728import password .pwm .config .AppConfig ;
29+ import password .pwm .config .DomainConfig ;
2830import password .pwm .error .PwmError ;
2931import password .pwm .error .PwmUnrecoverableException ;
3032import password .pwm .util .PasswordData ;
5254import java .util .Optional ;
5355import java .util .Set ;
5456import java .util .function .Supplier ;
55- import java .util .stream .Collectors ;
5657
5758public 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 ( )
0 commit comments