Extracted get-realm to service since statics cannot be overwritten

This commit is contained in:
Timo Bejan 2023-05-30 13:41:08 +03:00
parent 1683f9521c
commit e15769b010
2 changed files with 20 additions and 5 deletions

View File

@ -31,10 +31,5 @@ public class KeycloakSecurity {
}
public Optional<String> getRealm() {
var authentication = (JwtAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
return Optional.of(TokenUtils.toTenant(authentication.getToken().getTokenValue()));
}
}

View File

@ -0,0 +1,20 @@
package com.knecon.fforesight.keycloakcommons.security;
import java.util.Optional;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationToken;
import org.springframework.stereotype.Service;
import com.knecon.fforesight.keycloakcommons.security.TokenUtils;
@Service
public class TokenRealmService {
public Optional<String> getRealm() {
var authentication = (JwtAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
return Optional.of(TokenUtils.toTenant(authentication.getToken().getTokenValue()));
}
}