liveBook · Manning

ANT syntax

As explained in Spring Security in Action, Second Edition

ANT syntax is a path-pattern notation that uses wildcard expressions to match hierarchies of path segments.

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

How Spring Security in Action, Second Edition covers it

How deep it goes
Defines exact, wildcard, variable, and regex patterns with authorization examples, but does not explain matcher internals.
Examples
Uses /a, /a/b/**, product path variables, and a digits-only regular-expression constraint.
What it assumes
Assumes basic Spring endpoint mappings and introduces request matching through incremental authorization examples.
What you can do after
Configure endpoint authorization by matching exact paths, path hierarchies, HTTP methods, and constrained variables.
How it connects
Connects requestMatchers() with Spring MVC mappings, HTTP methods, authorization rules, path variables, and regular expressions.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Spring Security in Action, Second Edition. The section links point to the parts of the book it draws on.