ANT syntax is a path-pattern notation used with Spring Security requestMatchers() to select endpoints for authorization. It follows the same path style as common Spring MVC mapping annotations. section 8.2
Use these patterns to control which paths match:
- Use /a for only the exact /a path. section 8.2
- Use /a/* to match one additional path segment, such as /a/b, but not /a/b/c. section 8.2
- Use /a/** to match multiple path segments, including /a, /a/b, and /a/b/c. section 8.2
- Use /a/{param} for a path variable, or /a/{param:regex} to constrain its value with a regular expression. section 8.2
Protecting a path hierarchy
requestMatchers("/a/b/**").authenticated() protects /a/b and deeper paths, while anyRequest().permitAll() leaves other paths accessible. section 8.2
Table 8.1 Common expressions used for path matching with MVC matchers (view table figure)
| Expression |
Description |
|---|---|
| /a |
Only path /a. |
| /a/* |
The * operator replaces one pathname. In this case, it matches /a/b or /a/c, but not /a/b/c. |
| /a/** |
The ** operator replaces multiple pathnames. In this case, /a, /a/b, and /a/b/c are a match for this expression. |
| /a/{param} |
This expression applies to the path /a with a given path parameter. |
| /a/{param:regex} |
This expression applies to the path /a with a given path parameter only when the value of the parameter matches the given regular expression. |
Browse the common ANT expressions and their matching behavior. section 8.2
