无法使用密钥罩构建用于身份验证的基于Spring的项目 [英] Unable to build spring based project for authentication using keycloak

查看:29
本文介绍了无法使用密钥罩构建用于身份验证的基于Spring的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题陈述

我无法通过Spring Boot项目构建,我想通过保护我的应用程序。钥匙斗篷。

预期产量

项目构建成功,当我点击睡觉地址时,它将重定向到密钥斗篷页面进行身份验证。

EmployeeRestController

@RestController
public class EmployeeRestController {

  @GetMapping(path = "/username")
  public String getAuthorizedUserName() {
    return "Username Returned";
  }

  @GetMapping(path = "/roles")
  public String getAuthorizedUserRoles() {
    return "Roles Returned";
  }
}

启动

@SpringBootApplication
public class Startup {

  public static void main(String[] args) {
    SpringApplication.run(Startup.class, args);
  }
}

应用程序属性

server.port=8085

keycloak.realm=wow
keycloak.auth-server-url=http://localhost:8180/auth
keycloak.resource=wow-client
keycloak.public-client=true
keycloak.securityConstraints[0].authRoles[0]=user
keycloak.securityConstraints[0].securityCollections[0].patterns[0]=/*

pom.xml

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.keycloak/keycloak-spring-boot-starter -->
    <dependency>
        <groupId>org.keycloak</groupId>
        <artifactId>keycloak-spring-boot-starter</artifactId>
        <version>7.0.0</version>
    </dependency>
</dependencies>

错误日志

2019-09-16 17:44:24.525  INFO 10396 --- [           main] com.diwakar.Startup                      : Starting Startup on diwakarb with PID 10396 (started by diwakarb in E:DB GodamSample-KeyCloak-Project)
2019-09-16 17:44:24.527  INFO 10396 --- [           main] com.diwakar.Startup                      : No active profile set, falling back to default profiles: default
2019-09-16 17:44:25.419  WARN 10396 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'tomcatServletWebServerFactory' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/ServletWebServerFactoryConfiguration$EmbeddedTomcat.class]: Initialization of bean failed; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.keycloak.adapters.springboot.KeycloakAutoConfiguration': Unsatisfied dependency expressed through method 'setKeycloakSpringBootProperties' parameter 1; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.keycloak.adapters.springboot.KeycloakSpringBootConfigResolver' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
2019-09-16 17:44:25.429  INFO 10396 --- [           main] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-09-16 17:44:25.531 ERROR 10396 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

Parameter 1 of method setKeycloakSpringBootProperties in org.keycloak.adapters.springboot.KeycloakBaseSpringBootConfiguration required a bean of type 'org.keycloak.adapters.springboot.KeycloakSpringBootConfigResolver' that could not be found.


Action:

Consider defining a bean of type 'org.keycloak.adapters.springboot.KeycloakSpringBootConfigResolver' in your configuration.


Process finished with exit code 1

注意:请考虑密钥掩蔽配置正确

推荐答案

我使用Sprringboot-2.2.0/keyloak-7.0.1时遇到了同样的问题。 我将bean KeycloakSpringBootConfigResolver移动到另一个配置文件,它可以工作。

@Configuration
public class BeanKeycloakConfiguration {
    @Bean
    public KeycloakSpringBootConfigResolver KeycloakConfigResolver() {
        return new KeycloakSpringBootConfigResolver();
    }
}`

这篇关于无法使用密钥罩构建用于身份验证的基于Spring的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆