0

I am trying to create an API with JWT authentication with Spring security.

Because it's an API I don't need all login/logout functionality from Spring security. I just need the part where Spring Security determines the current user.

So my question is, where can I set the current user for each request?

1 Answer 1

0

You can add Principal to your methods in your REST controllers. The Principal contains the all the details of the API client identified by the token. It includes client name, token details such as roles, scopes, and etc...

    import java.security.Principal;

   @GetMapping(value = "/hello")
   public String whoAmI(Principal principal)  {
      return principal.getName();
   }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.