-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #345 from tallyto/23.17
Obtendo usuário autenticado no Resource Server
- Loading branch information
Showing
2 changed files
with
24 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/main/java/com/tallyto/algafood/core/security/AlgaSecurity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.tallyto.algafood.core.security; | ||
|
||
import org.springframework.security.core.Authentication; | ||
import org.springframework.security.core.context.SecurityContextHolder; | ||
import org.springframework.security.oauth2.jwt.Jwt; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class AlgaSecurity { | ||
|
||
public Authentication getAuthentication() { | ||
return SecurityContextHolder.getContext().getAuthentication(); | ||
} | ||
public Long getUsuarioId() { | ||
Jwt jwt = (Jwt) getAuthentication().getPrincipal(); | ||
|
||
return jwt.getClaim("usuario_id"); | ||
} | ||
} |