Spring Cloud 配置服务器/客户端安全问题

时间:2021-02-04 06:44:37

标签: spring-boot client-server spring-cloud spring-cloud-config

我有以下安全配置

服务器应用程序.yml

management:
    security:
        enabled: false
server:
    port: 8888
spring:
    cloud:
        config:
            server:
                jdbc:
                    order: 1
                    sql: SELECT prop_key,value FROM xlabs.properties where application=?
                        and profile=? and label=?
    datasource:
        password: XXXXX
        url: jdbc:postgresql://localhost:8000/finos?currentSchema=xlabs
        username: XXXXX
    profiles:
        active: jdbc
    security:
        user:
            name: mufg
            password: mufg

在客户端。

客户端应用程序.properties

server:
    port: 8082
spring:
    application:
        name: config-server
    cloud:
        config:
            label: latest
            profile: development
            uri: http://localhost:8888
            username: mufg
            password: mufg

使用此设置 配置服务器安全性工作正常我可以在输入用户名和密码后通过 http://localhost:8888/config-server/development/latest 访问属性。但是当我尝试启动客户端时,它说属性未解决。这里有什么问题吗?

谢谢。

1 个答案:

答案 0 :(得分:0)

一段时间后,我能够找到答案。在只有该配置的配置服务器中,客户端将被阻止。所以必须禁用 csrf 并允许任何如下所示的请求。

只需添加服务器端。

@Configuration
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {

    @Override
    public void configure(HttpSecurity http) throws Exception {
        http
                .csrf()
                .disable()
                .httpBasic()
                .and()
                .authorizeRequests()
                .antMatchers("/encrypt/**").authenticated()
                .antMatchers("/decrypt/**").authenticated();
        
    }
}

但是这里默认的安全性将被禁用。这里的问题是如果用户名或密码从客户端身份验证发生更改。