- 此问题在此处已有答案**:
Use Keycloak Spring Adapter with Spring Boot 3(2个答案)
昨天关门了。
我在设置@KeycloakConfiguration时遇到问题,我看了keycloak的文档,它说我必须创建一个类并设置文档中设置的所有方法
文档密钥罩:
@KeycloakConfiguration
public class SecurityConfig extends KeycloakWebSecurityConfigurerAdapter
{
/**
* Registers the KeycloakAuthenticationProvider with the authentication manager.
*/
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.authenticationProvider(keycloakAuthenticationProvider());
}
/**
* Defines the session authentication strategy.
*/
@Bean
@Override
protected SessionAuthenticationStrategy sessionAuthenticationStrategy() {
return new RegisterSessionAuthenticationStrategy(buildSessionRegistry());
}
@Bean
protected SessionRegistry buildSessionRegistry() {
return new SessionRegistryImpl();
}
@Override
protected void configure(HttpSecurity http) throws Exception
{
super.configure(http);
http
.authorizeRequests()
.antMatchers("/customers*").hasRole("USER")
.antMatchers("/admin*").hasRole("ADMIN")
.anyRequest().permitAll();
}
}
我照做了,但是当我将其复制并粘贴到我类中时,它说我必须实现另外两个安全配置器方法,即init(Builder:B)void和configure(Builder:B)void,除此之外,我已经有一个configure方法。
我在文档中看到了,但没有说明我必须如何使用这两种方法,我想知道我是否遗漏了什么,或者是否是上一个版本的keycloak的功能,我使用的keycloak版本是20.0.2
我的依赖是:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-spring-boot-starter</artifactId>[enter image description here](https://i.stack.imgur.com/v2En6.png)
</dependency>
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-spring-security-adapter</artifactId>
<version>20.0.2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.keycloak.bom</groupId>
<artifactId>keycloak-adapter-bom</artifactId>
<version>20.0.2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>```
As i say i would like to know what i have to do with these two methods
1条答案
按热度按时间nwlqm0z11#
选中Use Keycloak Spring Adapter with Spring Boot 3或https://www.baeldung.com/spring-boot-keycloak均解决了我的同一问题