eureka集群搭建中安全配置-1

1、在server的pom中引入如下配置:

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

2、修改properties:

spring.security.user.name=admin
spring.security.user.password=admin
eureka.client.serviceUrl.defaultZone=http://admin:admin@host-server80:7901/eureka/

3、重启服务在登录eureka页面就会要求输入用户名密码,输入上面配置的用户名密码就可以了:

 

 

需要注意的是:

1、每个需要注册的客户端都需要在defaultZone中配置用户名密码,否则会注册失败;

2、在eureka-server中需要关闭跨域攻击配置,方法是在server中添加配置类:

@EnableWebSecurity
@Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

@Override
public void configure(HttpSecurity http) throws Exception {
http.csrf().disable(); //关闭csrf认证,否则会报错Root name 'timestamp' does not match expected ('instance')
super.configure(http);
}
}

 




posted @ 2021-10-22 14:46  奋斗吧&#128663;少年  阅读(124)  评论(0)    收藏  举报