怎么做区块链媒体网站,wordpress和阿里云,在国内做敏感网站,宝安商城网站建设哪家便宜Eureka 自带了一个 Web 的管理页面#xff0c;方便我们查询注册到上面的实例信息#xff0c;但是有一个问题#xff1a;如果在实际使用中#xff0c;注册中心地址有公网 IP 的话#xff0c;必然能直接访问到#xff0c;这样是不安全的。所以我们需要对 Eureka 进行改造方便我们查询注册到上面的实例信息但是有一个问题如果在实际使用中注册中心地址有公网 IP 的话必然能直接访问到这样是不安全的。所以我们需要对 Eureka 进行改造加上权限认证来保证安全性。 改造我们的 eureka-server通过集成 Spring-Security 来进行安全认证。 在 pom.xml 中添加 Spring-Security 的依赖包代码如下所示。
dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-security/artifactId
/dependency
然后在 application.properties 中加上认证的配置信息
spring.security.user.nameyinjihuan #用户名
spring.security.user.password123456 #密码
增加 Security 配置类 Configuration
EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
Override
protected void configure(HttpSecurity http) throws Exception {
// 关闭csrf
http.csrf().disable();
// 支持httpBasic
http.authorizeRequests().anyRequest().authenticated().and().httpBasic();
}
}
重新启动注册中心访问 http://localhost:8761/此时浏览器会提示你输入用户名和密码输入正确后才能继续访问 Eureka 提供的管理页面。 在 Eureka 开启认证后客户端注册的配置也要加上认证的用户名和密码信息
eureka.client.serviceUrl.defaultZonehttp://zhangsan:123456localhost:8761/eureka/
上一篇 使用Eureka编写服务消费者
下一篇介绍 Eureka集群搭建