@ -1,12 +1,14 @@
|
||||
package mops.gruppen2.security;
|
||||
|
||||
import java.util.Set;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public class Account {
|
||||
|
||||
private final String name; //user_id
|
||||
private final String email;
|
||||
private final String image;
|
||||
|
||||
@ -16,39 +16,30 @@ import org.springframework.web.client.RestTemplate;
|
||||
|
||||
@Configuration
|
||||
public class KeycloakConfig {
|
||||
|
||||
@Value("${keycloak.resource}")
|
||||
private String clientId;
|
||||
|
||||
@Value("${keycloak.credentials.secret}")
|
||||
private String clientSecret;
|
||||
|
||||
@Value("${hhu_keycloak.token-uri}")
|
||||
private String tokenUri;
|
||||
|
||||
@Bean
|
||||
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);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -48,7 +48,7 @@ class SecurityConfig extends KeycloakWebSecurityConfigurerAdapter {
|
||||
|
||||
@Bean
|
||||
@Scope(scopeName = WebApplicationContext.SCOPE_REQUEST,
|
||||
proxyMode = ScopedProxyMode.TARGET_CLASS)
|
||||
proxyMode = ScopedProxyMode.TARGET_CLASS)
|
||||
public AccessToken getAccessToken() {
|
||||
HttpServletRequest request =
|
||||
((ServletRequestAttributes) RequestContextHolder
|
||||
@ -61,14 +61,14 @@ class SecurityConfig extends KeycloakWebSecurityConfigurerAdapter {
|
||||
protected void configure(HttpSecurity http) throws Exception {
|
||||
super.configure(http);
|
||||
http.authorizeRequests()
|
||||
.antMatchers("/actuator/**")
|
||||
.hasRole("monitoring")
|
||||
.and()
|
||||
.authorizeRequests()
|
||||
.antMatchers("/h2-console/**")
|
||||
.permitAll()
|
||||
.anyRequest()
|
||||
.permitAll();
|
||||
.antMatchers("/actuator/**")
|
||||
.hasRole("monitoring")
|
||||
.and()
|
||||
.authorizeRequests()
|
||||
.antMatchers("/h2-console/**")
|
||||
.permitAll()
|
||||
.anyRequest()
|
||||
.permitAll();
|
||||
|
||||
http.csrf().disable();
|
||||
http.headers().frameOptions().disable();
|
||||
@ -88,5 +88,6 @@ class SecurityConfig extends KeycloakWebSecurityConfigurerAdapter {
|
||||
jsr250Enabled = true)
|
||||
public static class MethodSecurityConfig
|
||||
extends GlobalMethodSecurityConfiguration {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user