Created
February 17, 2022 13:26
-
-
Save h-hub/274b1b8a0a413ee1c21cbac5d41ce4c3 to your computer and use it in GitHub Desktop.
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
@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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment