spring-cloud-config 使用安全认证后 刷新配置端点 /actuator/bus-refresh 返回403

spring-cloud-config 开启了spring-security后,导致自动刷新配置接口异常:
开始报

POST http://localhost:8888/actuator/bus-refresh
{
    "timestamp": "2018-07-01T11:48:52.417+0000",
    "status": 401,
    "error": "Unauthorized",
    "message": "Unauthorized",
    "path": "/actuator/bus-refresh"
}

然后我就加了Basic Auth,使用的是POSTMAN
加上正确的帐号密码后,报以下错误:

{
    "timestamp": "2018-07-01T11:48:52.417+0000",
    "status": 403,
    "error": "Forbidden",
    "message": "Forbidden",
    "path": "/actuator/bus-refresh"
}

下面说下解决方案:
首先我采用的是spring-cloud 2.0.3版本,
这里写图片描述
看了官网的描述,才知道,spring5.0以后,以及把spring.security.basic.enabled给去掉了,
所以我们推荐我们去创建一个自己的WebSecurityConfig类去实现WebSecurityConfigAdapter。
上代码:

@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

    /**
     * 高版本的丢弃了 
     * 
     * security: 
     *   basic: 
     *    enabled: true 
     * 
     * 配置,应该使用以下方式开启
     *
     * @param http
     * @throws Exception
     */
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        // Configure HttpSecurity as needed (e.g. enable http basic).
        http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.NEVER);
        http.csrf().disable();
        //注意:为了可以使用 http://${user}:${password}@${host}:${port}/eureka/ 这种方式登录,所以必须是httpBasic,
        // 如果是form方式,不能使用url格式登录
        http.authorizeRequests().anyRequest().authenticated().and().httpBasic();
    }
}

然后再试刷新POST /actuator/bus-refresh ,刷新成功!
开始借鉴了其他同行的错误问题,得以解决思路,附上问题链接:

spring cloud config 使用用户认证后 刷新配置端点bus-refresh 403
https://www.oschina.net/question/3877992_2281549

  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值