spring-projects / spring-projects/spring-security

Annotation for Automatic Detection of Authenticated Routes

Open
#16,563 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status: waiting-for-triage type: enhancement
Dominant language
Java
Stars
9.6k
Forks
6.3k
Avg merge
2d 11h
Merged PRs (30d)
52

Description

Expected Behavior

The functionality should work based on an annotation applied to Controllers. Let's assume we'll call it @Authenticated. Once this annotation is present on a method, we can use the application context to retrieve all routes and check if they have this annotation.

If the annotation is present, we can use an AntPathMatcher to match the path and method, and subsequently add it to the SecurityConfig.

Current Behavior

Currently, the developer must manually create a list of routes they want to authenticate. With the annotation, we propose a different approach to automate this process.

Context

This issue has added complexity to the development process, as developers need to manually manage and update the list of authenticated routes. The goal is to simplify and automate this process by introducing an annotation-based approach.

Alternatives considered include:

Manually maintaining the list of authenticated routes (current approach).

Using reflection to scan for specific method signatures or patterns.

Implementing a custom route registration mechanism.

A potential workaround is to use reflection to dynamically detect methods that require authentication, but this can be error-prone and less maintainable compared to an annotation-based solution.

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 by tracing how Controllers, the application context, AntPathMatcher, and SecurityConfig currently represent and authenticate routes. Define how an @Authenticated method is discovered and mapped to its path and HTTP method. Done means annotated routes are added to authentication requirements without a manually maintained route list.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
authentication, security
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.