How to create a JSF filter / url template to protect javascripts

I wrote a Java web filter to handle my JSF application security. I have a filter mapping as follows:

<filter-mapping> <filter-name>authFilter</filter-name> <url-pattern>/secure/*</url-pattern> <url-pattern>/login.jsf</url-pattern> <url-pattern>/*.js.jsf</url-pattern> <--- invalid pattern </filter-mapping> 

and now I want to create a url template to filter all javascript files. I use Primefaces, so .js files are extracted at the following URLs:

 http://localhost:8080/MyProject/javax.faces.resource/MyJavascriptFile.js.jsf?ln=MyLibrary 

I can not filter all javax.faces.resouces because it also contains CSS files. Is there a way to create a URL pattern to match only javascripts?

+4
source share
2 answers
 <url-pattern>/*.js.jsf</url-pattern> <--- invalid pattern 

This is really an invalid URL pattern. The wildcard * can only be at the beginning or end of the URL pattern. In your particular case, you do not need the / prefix.

 <url-pattern>*.js.jsf</url-pattern> <--- valid pattern 

Note that this issue has nothing for JSF. Servlet filters are part of the Servlet core API.

See also:

+3
source

Wildcard functionality is limited in JSF because only one * is allowed, and it must be at the end of the form-view-id line. For example, (any xml) It works.

 <from-view-id>/customer/*</from-view-id> 

He will never match ...

 <from-view-id>/cus*mer/</from-view-id> <from-view-id>/c*sto*er/*</from-view-id> <from-view-id>*/customer</from-view-id> 

check this page

+1
source

All Articles