在尝试关注文章https://sandor-nemeth.github.io/java/spring/2017/06/15/spring-boot-with-keycloak.html
时除了我使用maven pom.xml而不是gradle之外,我在春季启动应用程序中完全相同地设置了我的keycloak oauth。
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-spring-boot-2-starter</artifactId>
<version>4.0.0.Final</version>
</dependency>
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-spring-boot-adapter</artifactId>
<version>9.0.0</version>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.keycloak.bom</groupId>
<artifactId>keycloak-adapter-bom</artifactId>
<version>9.0.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
Java部分与文章中的内容相同:
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(securedEnabled = true)
public class KeycloakSecurityConfigurer extends KeycloakWebSecurityConfigurerAdapter {
@Autowired
public void configureGlobal(final AuthenticationManagerBuilder auth) {
final SimpleAuthorityMapper mapper = new SimpleAuthorityMapper();
mapper.setConvertToUpperCase(true);
final KeycloakAuthenticationProvider provider = keycloakAuthenticationProvider();
provider.setGrantedAuthoritiesMapper(mapper);
auth.authenticationProvider(provider);
}
@Bean
public KeycloakSpringBootConfigResolver keycloakConfigResolver() {
return new KeycloakSpringBootConfigResolver();
}
@Override
protected SessionAuthenticationStrategy sessionAuthenticationStrategy() {
return new NullAuthenticatedSessionStrategy();
}
@Override
protected void configure(final HttpSecurity http) throws Exception {
super.configure(http);
http.authorizeRequests();
}
尝试启动Spring Boot应用程序时
java ${JAVA_OPTS} -Djava.security.egd=file:/dev/./urandom -jar "${HOME}/app.war" "$@"
我正在获取BeanInCreationException:
rg.springframework.context.ApplicationContextException:无法启动Web服务器。嵌套异常是org.springframework.beans.factory.BeanCreationException:在类路径资源[org / springframework / boot / autoconfigure / web / servlet / ServletWebServerFactoryConfiguration $ EmbeddedUndertow.class]中创建名称为“ undertowServletWebServerFactory”的bean时出错。 ;嵌套的异常是org.springframework.beans.factory.UnsatisfiedDependencyException:创建名称为“ org.keycloak.adapters.springboot.KeycloakAutoConfiguration”的bean时出错:通过方法“ setKeycloakSpringBootProperties”参数1表示的依赖关系未满足;嵌套的异常是org.springframework.beans.factory.UnsatisfiedDependencyException:创建名称为'keycloakSecurityConfigurer'的bean时出错:通过字段'keycloakConfigResolver'表示的不满足的依赖关系;嵌套的异常是org.springframework.beans.factory.BeanCurrentlyInCreationException:创建名称为'keycloakConfigResolver'的bean时出错:当前正在创建请求的bean:是否存在无法解析的循环引用?”,“ logger”:“ org.springframework.boot.web .servlet.context.AnnotationConfigServletWebServerApplicationContext“,”线程“:”主“,”级别“:” WARN“} {“ time”:“ 2020-03-10T12:53:22.667 + 00:00”,“ msg”:“应用程序运行失败”,“ logger”:“ org.springframework.boot.SpringApplication”,“ thread”:“ main“,” level“:” ERROR“,” stack_trace“:” org.springframework.context.ApplicationContextException:无法启动Web服务器;嵌套异常是org.springframework.beans.factory.BeanCreationException:创建名称为'undertowServletWebServerFactory的bean时出错'在类路径资源[org / springframework / boot / autoconfigure / web / servlet / ServletWebServerFactoryConfiguration $ EmbeddedUndertow.class]中定义:Bean初始化失败;嵌套异常为org.springframework.beans.factory.UnsatisfiedDependencyException:创建名称为Bean时出错org.keycloak.adapters.springboot.KeycloakAutoConfiguration':通过方法'setKeycloakSpringBootProperties'参数1表达的不满意依赖项