update KeyCloakConfig like in the KeycloakDemo
Co-authored-by: LukasEttel <lukas.ettie@yahoo.de> Co-authored-by: AndiBuls <andreas.buls@uni-duesseldorf.de>
This commit is contained in:
@ -1,8 +1,13 @@
|
||||
package mops.gruppen2.security;
|
||||
|
||||
import org.keycloak.OAuth2Constants;
|
||||
import org.keycloak.adapters.springboot.KeycloakSpringBootConfigResolver;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.security.oauth2.client.OAuth2RestTemplate;
|
||||
import org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsResourceDetails;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
/**
|
||||
* WORKAROUND for https://issues.redhat.com/browse/KEYCLOAK-11282
|
||||
@ -15,4 +20,35 @@ public class KeycloakConfig {
|
||||
public KeycloakSpringBootConfigResolver keycloakConfigResolver() {
|
||||
return new KeycloakSpringBootConfigResolver();
|
||||
}
|
||||
|
||||
@Value("${keycloak.resource}")
|
||||
|
||||
private String clientId;
|
||||
|
||||
@Value("${keycloak.credentials.secret}")
|
||||
|
||||
private String clientSecret;
|
||||
|
||||
@Value("${hhu_keycloak.token-uri}")
|
||||
|
||||
private String tokenUri;
|
||||
|
||||
|
||||
@Bean
|
||||
public RestTemplate serviceAccountRestTemplate() {
|
||||
|
||||
ClientCredentialsResourceDetails resourceDetails = new ClientCredentialsResourceDetails();
|
||||
|
||||
resourceDetails.setGrantType(OAuth2Constants.CLIENT_CREDENTIALS);
|
||||
|
||||
resourceDetails.setAccessTokenUri(tokenUri);
|
||||
|
||||
resourceDetails.setClientId(clientId);
|
||||
|
||||
resourceDetails.setClientSecret(clientSecret);
|
||||
|
||||
|
||||
return new OAuth2RestTemplate(resourceDetails);
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user