带有密钥斗篷的Spring Cloud微服务

问题描述 投票:0回答:1

我有一个Spring Cloud微服务项目,该项目使用Spring Cloud Config Server管理配置,并使用Eureka Server进行服务发现。

我的应用程序做得很好,直到我想用keycloak添加新的微服务。这项新的微服务只是我的Vue前端应用程序的其余API,并且预期由Keycloak处理用户管理。

新服务运行正常,并将其注册到Eureka 直到我向项目添加了keycloak依赖项。应用程序不会崩溃或引发任何错误,不会启动,也可以自行注册到Eureka,但是在Spring Boot Admin服务器面板上,我看到该应用程序已关闭。

这是我的新服务的.properties文件。

eureka.instance.preferIpAddress=true
eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka
eureka.instance.leaseRenewalIntervalInSeconds=3
eureka.client.eureka-connection-idle-timeout-seconds=3
eureka.client.fetchRegistry=true

spring.boot.admin.client.url=http://localhost:6060
management.endpoints.web.exposure.include=*
management.endpoint.health.show-details=always

server.port=8082

keycloak.auth-server-url=http://localhost:8080/auth
keycloak.realm=microservices
keycloak.resource=microservices-app
keycloak.public-client=true

keycloak.security-constraints[0].authRoles[0]=user
keycloak.security-constraints[0].securityCollections[0].patterns[0]=/*
keycloak.cors=true

这是我对新服务的依赖关系。

...
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.thymeleaf</groupId>
                <artifactId>thymeleaf</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-config</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
    </dependency>
    <dependency>
        <groupId>org.keycloak</groupId>
        <artifactId>keycloak-spring-boot-starter</artifactId>
        <version>4.8.3.Final</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-openfeign</artifactId>
    </dependency>
</dependencies>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.keycloak.bom</groupId>
            <artifactId>keycloak-adapter-bom</artifactId>
            <version>4.8.3.Final</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

春季云版本为Hoxton.SR1

春季启动版本为2.2.2.RELEASE

我曾尝试添加Spring Security并使用KeycloakAuthenticationProvider进行Java配置,但没有帮助。

在整个项目中,我遇到了许多由Spring Cloud版本或Spring Cloud-Spring Boot Admin交互引起的怪异错误,因此更改版本或在配置文件中添加一个小参数通常可以解决问题,我怀疑此Keycloak问题将得到解决同样的方式。

spring-boot microservices spring-cloud keycloak spring-cloud-netflix
1个回答
0
投票

Spring Boot Admin使用执行器端点,请尝试使其不受保护:

    keycloak.security-constraints[0].authRoles[0]=user
    keycloak.security-constraints[0].securityCollections[0].patterns[0]=/*
    keycloak.security-constraints[0].securityCollections[1].patterns[0]=/actuator
    keycloak.security-constraints[0].securityCollections[1].patterns[1]=/actuator/*
© www.soinside.com 2019 - 2024. All rights reserved.