Created
August 29, 2017 10:34
-
-
Save radutoev/7ad5c8bc1fa98188bebf9ab05bfea062 to your computer and use it in GitHub Desktop.
Keycloak access token bean
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 | |
public class KeycloakUtils { | |
@Bean | |
@Scope(scopeName = WebApplicationContext.SCOPE_REQUEST, | |
proxyMode = ScopedProxyMode.TARGET_CLASS) | |
public AccessToken accessToken() { | |
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder | |
.currentRequestAttributes()) | |
.getRequest(); | |
AccessToken accessToken = ((KeycloakPrincipal) ((KeycloakAuthenticationToken) request.getUserPrincipal()).getPrincipal()) | |
.getKeycloakSecurityContext().getToken(); | |
return accessToken; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment