# Keycloak for Desktop Application with method-level Authenication in Spring Security

**URL:** <https://forum.keycloak.org/t/keycloak-for-desktop-application-with-method-level-authenication-in-spring-security/4008>\
**Category:** Getting advice\
**Created:** [July 28, 2020, 3:12pm UTC](https://forum.keycloak.org/t/keycloak-for-desktop-application-with-method-level-authenication-in-spring-security/4008 "2020-07-28T15:12:42Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![KarlDerKaefer](https://avatars.discourse-cdn.com/v4/letter/k/f6c823/32.png) [@KarlDerKaefer](https://forum.keycloak.org/u/KarlDerKaefer)\
**Post date:** [July 28, 2020, 3:12pm UTC](https://forum.keycloak.org/t/keycloak-for-desktop-application-with-method-level-authenication-in-spring-security/4008/1 "2020-07-28T15:12:42Z")

</div>

Hey all,

I use Keycloak to secure my desktop app with the help of KeycloakInstalled. The app uses spring security to secure the methods with the help of annotations like @PreAuthorize(“hasRole(‘ADMIN’)”). As KeycloakInstalled only returns the token, I was wondering how I could make this combination work? Do you have any hint for me?

I was trying to implement my own UserDetailsService and my own UserPrincipal but figured out that probably the Authentication and SecurityContext will also be important for SpringSecurity to authenticate on a method-level. Sorry if this question is more SpringSecurity related, I just want to make sure that I am not missing something obvious from KeyCloakInstalled

Any idea is greatly appreciated! Thanks!
