spring-projects / spring-projects/spring-security

SEC-3136: Allow for array Http methods and varargs patterns for Ant matcher

Open
#3,335 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

in: config type: enhancement type: jira
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.