Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get an EAR to read a properties file from a WAR?

I'm using Wildfly 11 and Java 8. I'm trying to deploy an EAR file that contains multiple WAR files. One of my WAR files contains this in its web.xml ...

<context-param>
    <param-name>Owasp.CsrfGuard.Config</param-name>
    <param-value>csrfguard.properties</param-value>
</context-param>

The file in question is within one of my WARs at

myapp.war/WEB-INF/classes/csrfguard.properties

When I deploy the WAR by itself, everything deploys fine. However when I deploy the EAR containing the WAR I get an error complaining about not being able to locate the properties file ...

Caused by: java.io.IOException: unable to locate resource - csrfguard.properties
    at org.owasp.csrfguard.CsrfGuardServletContextListener.getResourceStream(CsrfGuardServletContextListener.java:85)
    at org.owasp.csrfguard.CsrfGuardServletContextListener.contextInitialized(CsrfGuardServletContextListener.java:36)
    ... 10 more

I sense that there is a class loader issue happening that I'm not figuring out how to work-around. How do I tell my EAR file where to find the properties file in question?

like image 616
Dave Avatar asked Nov 07 '22 10:11

Dave


1 Answers

I suspect that the wrong class loader is being used to search the classpath for csrfguard.properties, which would cause getResourceAsStream to fail. In the .ear file, where does the CSRFGuard library get packaged?

You can try using the context.getRealPath fallback by switching to a path relative to the .war file:

<context-param>
    <param-name>Owasp.CsrfGuard.Config</param-name>
    <param-value>WEB-INF/classes/csrfguard.properties</param-value>
</context-param>
like image 198
earldouglas Avatar answered Nov 14 '22 03:11

earldouglas