spring-projects / spring-projects/spring-security

UniqueSecurityAnnotationScanner should consider annotation on target class level as fallback

Open
#16,295 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

public abstract class AbstractController {

	@GetMapping("/get")
	public String get() {
		return "OK";
	}

}

@RestController
@Secured("USER")
public class DemoController extends AbstractController {

	/*
	public String get() {
		return super.get();
	}
	*/
}

demoController.get() is not protected by @Secured("USER"), we have to redefine it again.

I tried to fix it by adding

		annotations = findClosestClassAnnotations(targetClass, new HashSet<>());
		if (!annotations.isEmpty()) {
			return annotations;
		}

after
https://github.com/spring-projects/spring-security/blob/b9f3a28678af525e70cd5aa00abc816163cdb4fe/core/src/main/java/org/springframework/security/core/annotation/UniqueSecurityAnnotationScanner.java#L159-L162
but it broken GH-15352.

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 in core/src/main/java/org/springframework/security/core/annotation/UniqueSecurityAnnotationScanner.java around lines 159-162 and trace how annotations are resolved for the target class. Reproduce the AbstractController/DemoController case, then verify that class-level fallback protection works without regressing GH-15352.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
authorization, security
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.