Spring regex pattern for security

In my application that uses spring security, I want to define two different areas using their own spring security filter chain. My question is: is it possible to define two regular expression expressions as follows:

  • every path starting with / foobar / *
  • any other path not starting with / foobar

The important part here is that the second path should also match, if somewhere inside it, but not at the beginning, it displays / foobar / string.

thanks

+4
source share
1 answer
^/foobar/.*$ 

will match if the path starts with /foobar/ ;

 ^(?!/foobar/).*$ 

will match any path that does not start with /foobar/ ( (?!...) - this is the so-called negative statement) .

+5
source

Source: https://habr.com/ru/post/1311446/


All Articles