大佬教程收集整理的这篇文章主要介绍了spring boot-admin 监控中心 配置登录密码,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
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@H_874_73@(AdminServerProperties adminServerProperties) {
this.adminContextPath = adminServerProperties.getContextPath();
}
@Override
protected void configure@H_874_73@(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
以上是大佬教程为你收集整理的spring boot-admin 监控中心 配置登录密码全部内容,希望文章能够帮你解决spring boot-admin 监控中心 配置登录密码所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。