Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable @WebFilter (embedded in dependency jar)

Is there a way to disable a embedded Servlet Filter?

My project has a dependency jar that contains (inside the jar) a @WebFilter mapped to "/*".
I need the jar (it has a lot of commons class of my company), but this new project does not need this WebFilter, actually this new project will not work because this Filter checks user authentication and the new project has no "loggedUser". It's like a website

Thanks

like image 221
ethanxyz_0 Avatar asked Jan 13 '23 10:01

ethanxyz_0


1 Answers

web.xml takes precedence over annotations for precisely this reason. Simply declare the offending filter in web.xml the good old way and set its <filter-mapping> to something bogus, eg:

<filter>
    <filter-name>BadBadFilter</filter-name>
    <filter-class>com.example.BadBadFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>BadBadFilter</filter-name>
    <url-pattern>/this-path-does-not-exist/*</url-pattern>
</filter-mapping>

This will effectively disable it.

like image 148
rdcrng Avatar answered Feb 08 '23 12:02

rdcrng