spring-projects / spring-projects/spring-security

SEC-2914: Support @AuthenticationPrincipal on @SubscribeMapping endpoints

Open
#3,129 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

in: messaging type: enhancement type: jira
Dominant language
Java
Stars
9.6k
Forks
6.3k
Avg merge
2d 11h
Merged PRs (30d)
52

Description

Igor Kolomiets (Migrated from SEC-2914) said:

I'm using latest websocket/messaging related features of Spring Security 4 to secure my application's websocket messaging endpoints. We have many @SubscribeMapping annotated methods to provide request-response style of communication that need access to current authenticated user. Currently we do this to get authenticated user:

@SubscribeMapping("/foo")
public MyResponse foo(MyAuthenticationToken authenticationToken) {
MyUser user = authenticationToken.getPrincipal();
}

Naturally I'd like to use @AuthenticationPrincipal so we can do this:

@SubscribeMapping("/foo")
public MyResponse foo(@AuthenticationPrincipal MyUser user) {

}

But it looks like @AuthenticationPrincipal is only supported by @MessageMapping annotated methods. Can we have it work for those annotated with @SubscribeMapping?

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 comparing how @AuthenticationPrincipal is supported for @MessageMapping methods with the @SubscribeMapping endpoints described in the issue. Trace the existing Spring Security messaging argument-resolution path, then verify that a principal can be injected for @SubscribeMapping methods using the requested example shape.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
backend, security
Issue type
Feature
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.