打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
微服务监控中心springboot-admin 配置登录密码
userphoto

2022.06.10 山东

关注

1. pom 加入 security

		<!-- 加入密码认证 -->
		<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>

2. 加入配置类 SecuritySecureConfig

package org.fh.config;
 
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler;
 
import de.codecentric.boot.admin.server.config.AdminServerProperties;
 
/**
 * 说明:SecuritySecure配置
 * 作者:FH Admin
 * from:fhadmin.cn
 */
@Configuration
public class SecuritySecureConfig extends WebSecurityConfigurerAdapter {
 
	private final String adminContextPath;
 
	public SecuritySecureConfig(AdminServerProperties adminServerProperties) {
		this.adminContextPath = adminServerProperties.getContextPath();
	}
 
	@Override
	protected void configure(HttpSecurity http) throws Exception {
 
		SavedRequestAwareAuthenticationSuccessHandler successHandler = new SavedRequestAwareAuthenticationSuccessHandler();
		successHandler.setTargetUrlParameter("redirectTo");
 
		http.headers().frameOptions().disable();
		
		http.authorizeRequests().antMatchers(adminContextPath + "/assets/**",adminContextPath + "/actuator/**").permitAll()
				.antMatchers(adminContextPath + "/login").permitAll().anyRequest().authenticated().and().formLogin()
				.loginPage(adminContextPath + "/login").successHandler(successHandler).and().logout()
				.logoutUrl(adminContextPath + "/logout").and().httpBasic().and().csrf().disable();
 
	}
	
}

3.  配置 application.properties

#开启安全认证 用户名和密码
spring.security.user.name=fhadmin
spring.security.user.password=root
spring.security.basic.enabled=true
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
spring security 11种过滤器介绍 - Eryk - JavaEye技术网站
Centos6.5 搭建openstack
ActiveMQ 5.2的安全性配置
Websphere5.1.x JAAS LDAP配置全攻略(1)
使用membership(System.Web.Security)来进行角色与权_2009...
CuteEditor5.0实现分用户上传
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服