spring-cloud Finchley.RELEASE 版本为eureka 增加用户名密码验证

 这个版本的eureka ,配置用户名密码 与其他版本 有所不同

<dependencyManagement>
		<dependencies>
			<dependency>
				<groupId>org.springframework.cloud</groupId>
				<artifactId>spring-cloud-dependencies</artifactId>
				<version>Finchley.RELEASE</version>
				<type>pom</type>
				<scope>import</scope>
			</dependency>
		</dependencies>
	</dependencyManagement>

1.首先是配置文件 修改:

 

原来的配置方式

#security:  
#  basic:  
#    enabled: true  
#  user:  
#   name: user  
#   password: password    


现在的配置方式

spring:
  security:
    user:
      name: user  
      password: password    

2.pom文件

	<!--添加用户名密码  -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-security</artifactId>
		</dependency> 

3.


@EnableWebSecurity
@Configuration
public class WebSecurityConfig  extends  WebSecurityConfigurerAdapter   {
	
	  @Override
	    protected void configure(HttpSecurity http) throws Exception {
	        http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.NEVER);
	        http.csrf().disable(); //关闭csrf
	        //注意:为了可以使用 http://${user}:${password}@${host}:${port}/eureka/ 这种方式登录,所以必须是httpBasic,如果是form方式,不能使用url格式登录
	        http.authorizeRequests().anyRequest().authenticated().and().httpBasic(); //开启认证
	            
		
		  }

}

所以要在程序里 写一个配置类

这样用户名 密码就可以添加上了

 

如果不写那个配置类 ,就会成这个样子

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值