kusalk commented on code in PR #956:
URL: https://github.com/apache/struts/pull/956#discussion_r1628741666
##########
core/src/main/java/org/apache/struts2/interceptor/csp/CspInterceptor.java:
##########
@@ -57,26 +59,28 @@ 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 {} with action: {}", defaultCspSettingsClassName,
action);
+ LOG.trace("Using {} with action: {}", cspSettingsClassName,
action);
+ CspSettings cspSettings = createCspSettings(invocation);
+ applySettings(invocation, cspSettings);
+ }
+ return invocation.invoke();
+ }
- // 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.");
- }
+ private CspSettings createCspSettings(ActionInvocation invocation) throws
ClassNotFoundException {
+ Class<?> cspSettingsClass;
- // if defaultCspSettingsClassName does not implement CspSettings,
throw an exception
- if
(!CspSettings.class.isAssignableFrom(Class.forName(defaultCspSettingsClassName)))
{
- throw new IllegalArgumentException("The
defaultCspSettingsClassName must implement CspSettings.");
- }
+ try {
+ cspSettingsClass = ClassLoaderUtil.loadClass(cspSettingsClassName,
getClass());
+ } catch (ClassNotFoundException e) {
+ throw new ConfigurationException(String.format("The class %s
doesn't exist!", cspSettingsClassName));
+ }
- CspSettings cspSettings = (CspSettings)
Class.forName(defaultCspSettingsClassName)
- .getDeclaredConstructor().newInstance();
- applySettings(invocation, cspSettings);
+ if
(!CspSettings.class.isAssignableFrom(Class.forName(cspSettingsClassName))) {
Review Comment:
```suggestion
if (!CspSettings.class.isAssignableFrom(cspSettingsClass)) {
```
--
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]