Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change Principal to @AuthenticationPrincipal #21

Open
tarcidio opened this issue Mar 12, 2024 · 0 comments
Open

Change Principal to @AuthenticationPrincipal #21

tarcidio opened this issue Mar 12, 2024 · 0 comments

Comments

@tarcidio
Copy link
Owner

tarcidio commented Mar 12, 2024

@AuthenticationPrincipal in Spring Security is a best practice for accessing the authenticated user's details in a clean, type-safe, and readable manner. It simplifies the code by eliminating the need for manual retrieval and casting of the principal, making the controller methods more concise and easier to understand.

Example:

@GetMapping("/user")
public String getUser(@AuthenticationPrincipal UserDetails userDetails) {
    return "Hello, " + userDetails.getUsername();
}
@tarcidio tarcidio reopened this May 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant