参考
自己的一个demo源码
https://github.com/huangzhenshi/eureka2.x_auth_demo
eureka整合账号密码的功能
- 添加配置 而且defaultZone的配置不同
server.port=8761
spring.profiles.active=master
spring.application.name=spring-cloud-eureka
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
security.basic.enabled=true
security.user.name=yinjihuan
security.user.password=123456
eureka.client.serviceUrl.defaultZone=http://yinjihuan:123456@localhost:8761/eureka/
- 添加jar包依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
2.x 版本权限配置
- application配置不同,需要添加前缀spring
- eureka的server端需要关闭CSRD保护
2.0 版配置 server端
spring.security.basic.enabled=true
spring.security.user.name=huangzs
spring.security.user.password=123456
eureka.client.serviceUrl.defaultZone=http://huangzs:123456@localhost:8762/eureka/
2.X CSRF保护默认是开启的,可以禁用掉即可
https://blog.csdn.net/u010889990/article/details/80431487
通过配置server端的代码
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable();
}
}
网友评论