Skip to content

Instantly share code, notes, and snippets.

@radutoev
Created August 29, 2017 10:34
Show Gist options
  • Select an option

  • Save radutoev/7ad5c8bc1fa98188bebf9ab05bfea062 to your computer and use it in GitHub Desktop.

Select an option

Save radutoev/7ad5c8bc1fa98188bebf9ab05bfea062 to your computer and use it in GitHub Desktop.

Revisions

  1. Radu Toev created this gist Aug 29, 2017.
    14 changes: 14 additions & 0 deletions KeycloakUtils.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    @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;
    }
    }