Created
February 17, 2022 13:26
-
-
Save h-hub/274b1b8a0a413ee1c21cbac5d41ce4c3 to your computer and use it in GitHub Desktop.
Revisions
-
h-hub created this gist
Feb 17, 2022 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,30 @@ @Component @Scope(value = "request", proxyMode = ScopedProxyMode.TARGET_CLASS) public class MyRequestContext { private Jwt jwt; public MyRequestContext(){ this.jwt = (Jwt) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); } public String getUsername() { String username = jwt.getClaim("sub"); return username; } public boolean isAdmin() { List<String> claims = jwt.getClaim("cognito:groups"); if(claims.contains("ROLE_ADMIN")) { return true; } return false; } }