如何在springcloud中配置用户名和密码?

1. pom.xml 加入依赖

成都创新互联公司是一家专注于成都做网站、成都网站建设与策划设计,洛龙网站建设哪家好?成都创新互联公司做网站,专注于网站建设十年,网设计领域的专业建站公司;建站业务涵盖:洛龙等地区。洛龙做网站价格咨询:18980820575

	
		
		
            org.springframework.boot
            spring-boot-starter-security
        

2. application.properties 配置如下 用户名和密码

#开启安全认证 用户名和密码spring.security.basic.enabled=truespring.security.user.name=adminspring.security.user.password=root

3. 加入配置类 WebSecurityConfig.java

package org.fh.config;import org.springframework.security.config.annotation.web.builders.HttpSecurity;import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler;/**
 * 说明:CSRF保护禁用
 * 作者:www.1b23.com
 */@EnableWebSecuritypublic class WebSecurityConfig extends WebSecurityConfigurerAdapter {	
    @Override
    protected void configure(HttpSecurity http) throws Exception {
    	
    	SavedRequestAwareAuthenticationSuccessHandler successHandler = new SavedRequestAwareAuthenticationSuccessHandler();
		successHandler.setTargetUrlParameter("redirectTo");

		http.headers().frameOptions().disable();
    	
    	http.csrf().disable().authorizeRequests().antMatchers("/actuator/**").permitAll().anyRequest().authenticated().and().httpBasic();
    }
}

 


网站名称:如何在springcloud中配置用户名和密码?
文章转载:http://hxwzsj.com/article/jiphci.html

其他资讯

Copyright © 2025 青羊区翔捷宏鑫字牌设计制作工作室(个体工商户) All Rights Reserved 蜀ICP备2025123194号-14
友情链接: 成都企业网站制作 企业手机网站建设 手机网站制作 重庆电商网站建设 成都网站建设流程 成都营销网站制作 网站建设方案 网站建设费用 企业网站制作 企业网站设计 企业网站建设 高端网站设计 成都网站建设推广 高端网站建设 成都做网站建设公司 网站设计制作 高端定制网站设计 企业网站设计 重庆企业网站建设 专业网站建设 高端品牌网站建设 手机网站建设套餐