[keycloak-user] Spring Security Adapter working but no Principal

Marc Logemann marc.logemann at gmail.com
Wed Apr 4 05:14:52 EDT 2018


Hi,

i have a weird thing going on. My keycloak Spring Security adapter
works as expected. But i am unable to retrieve the principal. I am
requesting a REST service with a valid Bearer Token. In the REST
controller i want to see the principal via:

Principal userPrincipal = request.getUserPrincipal();

or

Authentication authentication =
SecurityContextHolder.getContext().getAuthentication();
String currentPrincipalName = authentication.getName();

But everything is null. Funny thing is, the Keycloak Filter set the
Authentication correctly but at the end, in my controller, its not
there anymore.

here is my filter list:

Security filter chain: [
  WebAsyncManagerIntegrationFilter
  SecurityContextPersistenceFilter
  HeaderWriterFilter
  KeycloakPreAuthActionsFilter
  LogoutFilter
  KeycloakAuthenticationProcessingFilter
  RequestCacheAwareFilter
  SecurityContextHolderAwareRequestFilter
  AnonymousAuthenticationFilter
  SessionManagementFilter
  ExceptionTranslationFilter
  FilterSecurityInterceptor
]

Has anyone experienced something like this or has an idea?

Thanks
Marc


More information about the keycloak-user mailing list