开启Eureka的安全认证(访问web页面需要验证用户名和密码)

我们需要引入的依赖包

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

 然后需要在配置文件中增加的配置:

 

spring:
  security:
    user:
      name: root
      password: jack66666

最后我们需要增加一个配置类:

@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        // TODO Auto-generated method stub
        // super.configure(http);
        http.csrf().disable();
        http.authorizeRequests().anyRequest().authenticated().and().httpBasic();
    }
}

启动项目成功后我们访问Eureka的管理界面需要认证。

这时候就需要输入用户名和密码去访问了。

同理我们服务端往Eureka注册也是需要添加认证信息的

 

spring:
  security:
    user:
      name: root
      password: jack66666

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章