lukaszlenart commented on code in PR #913:
URL: https://github.com/apache/struts/pull/913#discussion_r1582193457
##########
core/src/main/java/org/apache/struts2/interceptor/csp/CspInterceptor.java:
##########
@@ -54,8 +57,24 @@ public String intercept(ActionInvocation invocation) throws
Exception {
LOG.trace("Using CspSettings provided by the action: {}", action);
applySettings(invocation, ((CspSettingsAware)
action).getCspSettings());
} else {
- LOG.trace("Using DefaultCspSettings with action: {}", action);
- applySettings(invocation, new DefaultCspSettings());
+ LOG.trace("Using {} with action: {}", defaultCspSettingsClassName,
action);
+
+ // if the defaultCspSettingsClassName is not a real class, throw
an exception
+ try {
+ Class.forName(defaultCspSettingsClassName, false,
Thread.currentThread().getContextClassLoader());
+ }
+ catch (ClassNotFoundException e) {
+ throw new IllegalArgumentException("The
defaultCspSettingsClassName must be a real class.");
+ }
+
+ // if defaultCspSettingsClassName does not implement CspSettings,
throw an exception
+ if
(!CspSettings.class.isAssignableFrom(Class.forName(defaultCspSettingsClassName)))
{
+ throw new IllegalArgumentException("The
defaultCspSettingsClassName must implement CspSettings.");
+ }
+
+ CspSettings cspSettings = (CspSettings)
Class.forName(defaultCspSettingsClassName)
+ .getDeclaredConstructor().newInstance();
+ applySettings(invocation, cspSettings);
Review Comment:
I wonder if we can move this code into `init()` method of the interceptor as
right now a new instance is created per each invocation
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]