Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Filters not working in Struts2

for some unknown reason I'm not being able to use filter on struts2. I'm using apache tomcat and using filter to restrict user access ( I preffer rather than Interceptors). Is there any reason why my requests with /tela-paciente is not being filtering??

   <filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <filter>
        <filter-name>Paciente</filter-name>
        <filter-class>br.ufg.inf.sas.filtros.FiltroPaciente</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>Paciente</filter-name>
        <url-pattern>/tela-paciente</url-pattern>
    </filter-mapping>
like image 639
Marcos Roriz Junior Avatar asked Nov 20 '25 20:11

Marcos Roriz Junior


1 Answers

Another thing to keep in mind is that in your example the mapping for /tela-paciente occurs after the mapping for /* (for the Struts2 filter), so all requests will be mapped to Struts2 and none will go to your security filter.

Remember that the order of your filters matters. :)

@totaam: The StrutsPrepareAndExecuteFilter does not chain on to other filters unless:

  • The request URL is excluded from processing by the struts.action.excludePattern property
  • The request does not map to an action or a static resource

Therefore, assuming his request does map to an action, his security filter will not be invoked if it is mapped after the Struts2 filter.

like image 197
Steven Benitez Avatar answered Nov 23 '25 11:11

Steven Benitez



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!