To get the current security context in a Spring MVC handler method, one needs to use the @CurrentSecurityContext annotation like so:

@GetMapping
public String method(@CurrentSecurityContext SecurityContext context) { ... {

This is particularly useful when using the expression feature like the following:

@GetMapping
public String method(@CurrentSecurityContext(expression="authentication.name") String name) { ... {

But when I just need the SecurityContext, it's unnecessary boilerplate. It would be nice if the argument resolver also matched directly on the SecurityContext type so that one could do:

@GetMapping
public String method(SecurityContext context) { ... {

This change would need to be made in both the servlet and reactive argument resolvers.

Comment From: NerminKarapandzic

Hi, can I pick this up?