spring-projects / spring-projects/spring-security
SEC-3136: Allow for array Http methods and varargs patterns for Ant matcher
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 9.6k
- Forks
- 6.3k
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 52
Description
Abhijit Sarkar (Migrated from SEC-3136) said:
Often times, the same security requirement applies to multiple Http methods. For example, "any POST, DELETE, PUT or PATCH must only be accessible to the admins, regardless of the URL pattern". The Ant matchers have 2 methods, one that takes a URL pattern and applies to all Http methods and another that takes a Http method and applies to a varargs URL patterns. None of these methods could be used in the above use case requiring redundant code like the following. It'd be nice to have an ant matcher that could take a array Http method and varargs patterns as arguments.
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers(GET, SECURE_PATTERNS).authenticated()
.antMatchers(POST).hasAnyRole("ADMIN")
.antMatchers(DELETE).hasAnyRole("ADMIN")
.antMatchers(PUT).hasAnyRole("ADMIN")
.antMatchers(PATCH).hasAnyRole("ADMIN").and()
.httpBasic()
.and().csrf().disable()
.userDetailsService(userDetailsService); //
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start from the antMatchers methods in the HttpSecurity authorization configuration, comparing the overload that accepts a single HTTP method with the overload that accepts multiple URL patterns. Done means a matcher can accept an array of HTTP methods and varargs URL patterns, supporting the stated POST, DELETE, PUT, and PATCH example without redundant calls.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- authorization, security
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100