【问题标题】:Unauthorized in spring boot admin在 Spring Boot 管理员中未经授权
【发布时间】:2017-07-27 15:31:54
【问题描述】:

我想控制在 Eureka 服务器中运行的微服务。我为此使用了 spring-boot-admin,但在访问有关 Trace、Log 等信息时出现错误...

我得到的错误是

错误:{"timestamp":1489052472862,"status":401,"error":"Unauthorized","message":"访问此资源需要完全身份验证。","path":"/metrics" }

我的依赖是

<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-eureka</artifactId>
    </dependency>
    <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>
    <dependency>
        <groupId>de.codecentric</groupId>
        <artifactId>spring-boot-admin-server</artifactId>
        <version>1.4.3</version>
    </dependency>
    <dependency>
        <groupId>de.codecentric</groupId>
        <artifactId>spring-boot-admin-server-ui</artifactId>
        <version>1.4.3</version>
    </dependency>

以下属性均无效

endpoints.info.id=information
endpoints.info.sensitive=false
endpoints.info.enabled=true
information.app.name=Actuator Example
information.app.description=Actuator Example
information.app.version=1.0.0

所有端点(如映射、环境和所有接受健康)都发生了同样的事情

【问题讨论】:

    标签: spring spring-boot microservices netflix-eureka spring-boot-admin


    【解决方案1】:

    我认为禁用所有敏感端点的安全性不是可行的方法。

    我在访问/metricsapparently 时遇到了这个问题,我缺少spring-boot-starter-security 依赖项:

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

    将依赖项添加到我的pom.xml 后,并假设我的application.yml 上有以下内容

    ...
    security:
        user:
            name: myActuatorUser
            password: myActuatorPwd
    ...
    

    我能够访问我的/metrics 端点。

    【讨论】:

      【解决方案2】:

      我也遇到过类似的问题。 在我的 Spring Boot 应用程序中,我们有一个 cors 过滤器来阻止 Http Head 请求。因此无法接受头部请求。

      • 检查 Javascript 控制台日志和应用程序日志。

      • 在 application.properties 中设置 management.security.enabled=false 也是必要的。

      【讨论】:

        【解决方案3】:

        对于此处列出的大多数端点,最好通过凭据 usernamepassword 设置安全性: https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-endpoints.html

        规则中的例外是 healthinfo 端点,它们不受凭据保护。

        您可以像这样在application.properties 中设置usernamepassword

        security.user.name=admin
        security.user.password=secret
        

        【讨论】:

          【解决方案4】:

          application.properties 中设置management.security.enabled=false 将禁用端点上的安全性。

          【讨论】:

          • 此应用程序属性在最新的 spring-security 版本 (2.1+) 上不再可用。作为当前读者的信息
          猜你喜欢
          • 1970-01-01
          • 2019-11-09
          • 2021-01-24
          • 2016-10-28
          • 2018-07-04
          • 1970-01-01
          • 2021-04-07
          • 2022-01-21
          • 2020-09-27
          相关资源
          最近更新 更多