|
52 | 52 | import java.lang.reflect.Field; |
53 | 53 | import java.lang.reflect.Method; |
54 | 54 | import java.lang.reflect.Modifier; |
| 55 | +import java.lang.reflect.ParameterizedType; |
| 56 | +import java.lang.reflect.Type; |
55 | 57 | import java.util.Arrays; |
56 | 58 | import java.util.Collection; |
57 | 59 | import java.util.Comparator; |
@@ -373,61 +375,62 @@ protected boolean hasValidAnnotatedMember(String rootProperty, Object action, lo |
373 | 375 | } |
374 | 376 |
|
375 | 377 | protected boolean hasValidAnnotatedPropertyDescriptor(PropertyDescriptor propDesc, long paramDepth) { |
376 | | - Class<?> rootType = getValidAnnotatedPropertyDescriptorType(propDesc, paramDepth); |
377 | | - if (rootType != null) { |
378 | | - if (paramDepth > 0) { |
379 | | - threadAllowlist.allowClass(rootType); |
380 | | - } |
381 | | - return true; |
382 | | - } |
383 | | - return false; |
384 | | - } |
385 | | - |
386 | | - /** |
387 | | - * @return getter return type or setter parameter type, if one corresponding to the <code>paramDepth</code> exists |
388 | | - * with a valid annotation |
389 | | - */ |
390 | | - protected Class<?> getValidAnnotatedPropertyDescriptorType(PropertyDescriptor propDesc, long paramDepth) { |
391 | 378 | Method relevantMethod = paramDepth == 0 ? propDesc.getWriteMethod() : propDesc.getReadMethod(); |
392 | 379 | if (relevantMethod == null) { |
393 | | - return null; |
| 380 | + return false; |
394 | 381 | } |
395 | 382 | StrutsParameter annotation = getParameterAnnotation(relevantMethod); |
396 | | - if (annotation != null && annotation.depth() >= paramDepth) { |
397 | | - return paramDepth == 0 ? relevantMethod.getParameterTypes()[0] : relevantMethod.getReturnType(); |
| 383 | + if (annotation == null || annotation.depth() < paramDepth) { |
| 384 | + return false; |
| 385 | + } |
| 386 | + if (paramDepth >= 1) { |
| 387 | + threadAllowlist.allowClass(relevantMethod.getReturnType()); |
398 | 388 | } |
399 | | - return null; |
| 389 | + if (paramDepth >= 2) { |
| 390 | + allowlistReturnTypeIfParameterized(relevantMethod); |
| 391 | + } |
| 392 | + return true; |
400 | 393 | } |
401 | 394 |
|
402 | | - protected boolean hasValidAnnotatedField(Object action, String fieldName, long paramDepth) { |
403 | | - Class<?> rootType = getValidAnnotatedFieldType(action, fieldName, paramDepth); |
404 | | - if (rootType != null) { |
405 | | - if (paramDepth > 0) { |
406 | | - threadAllowlist.allowClass(rootType); |
407 | | - } |
408 | | - return true; |
| 395 | + protected void allowlistReturnTypeIfParameterized(Method method) { |
| 396 | + allowlistParameterizedTypeArg(method.getGenericReturnType()); |
| 397 | + } |
| 398 | + |
| 399 | + protected void allowlistParameterizedTypeArg(Type genericType) { |
| 400 | + if (!(genericType instanceof ParameterizedType)) { |
| 401 | + return; |
| 402 | + } |
| 403 | + Type paramType = ((ParameterizedType) genericType).getActualTypeArguments()[0]; |
| 404 | + if (paramType instanceof Class) { |
| 405 | + threadAllowlist.allowClass((Class<?>) paramType); |
409 | 406 | } |
410 | | - return false; |
411 | 407 | } |
412 | 408 |
|
413 | | - /** |
414 | | - * @return field type if a public field exists on the action with a valid annotation |
415 | | - */ |
416 | | - protected Class<?> getValidAnnotatedFieldType(Object action, String fieldName, long paramDepth) { |
| 409 | + protected boolean hasValidAnnotatedField(Object action, String fieldName, long paramDepth) { |
417 | 410 | Field field; |
418 | 411 | try { |
419 | 412 | field = action.getClass().getDeclaredField(fieldName); |
420 | 413 | } catch (NoSuchFieldException e) { |
421 | | - return null; |
| 414 | + return false; |
422 | 415 | } |
423 | 416 | if (!Modifier.isPublic(field.getModifiers())) { |
424 | | - return null; |
| 417 | + return false; |
425 | 418 | } |
426 | 419 | StrutsParameter annotation = getParameterAnnotation(field); |
427 | | - if (annotation != null && annotation.depth() >= paramDepth) { |
428 | | - return field.getType(); |
| 420 | + if (annotation == null || annotation.depth() < paramDepth) { |
| 421 | + return false; |
| 422 | + } |
| 423 | + if (paramDepth >= 1) { |
| 424 | + threadAllowlist.allowClass(field.getType()); |
429 | 425 | } |
430 | | - return null; |
| 426 | + if (paramDepth >= 2) { |
| 427 | + allowlistFieldIfParameterized(field); |
| 428 | + } |
| 429 | + return true; |
| 430 | + } |
| 431 | + |
| 432 | + protected void allowlistFieldIfParameterized(Field field) { |
| 433 | + allowlistParameterizedTypeArg(field.getGenericType()); |
431 | 434 | } |
432 | 435 |
|
433 | 436 | /** |
|
0 commit comments