Eureka 用户认证

相关文章

Eureka 服务端配置
Eureka 客户端配置

使用场景

希望给 Eureka 的服务端和客户端的使用加上条件

解决思路

利用 SpringSecurity

服务端

依赖配置

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

application.properties 配置

security.basic.enabled=true
spring.security.user.name=admin
spring.security.user.password=admin

配置类

@EnableWebSecurity
public class WebSecurityConfigurer extends WebSecurityConfigurerAdapter {
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        //关闭csrf
        http.csrf().disable();
        //开启认证:URL格式登录必须是httpBasic
        http.authorizeRequests().anyRequest().authenticated().and().httpBasic();
    }
}

客户端

bootstrap.properties 配置

#加上用户名密码
eureka.client.serviceUrl.defaultZone=http://admin:admin@localhost:8763/eureka/
发布了185 篇原创文章 · 获赞 271 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/weixin_44367006/article/details/105595916
今日推荐