微服务监控中心springboot-凯发app官方网站

凯发app官方网站-凯发k8官网下载客户端中心 | | 凯发app官方网站-凯发k8官网下载客户端中心

 |   |  
  • 博客访问: 470973
  • 博文数量: 298
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 3077
  • 用 户 组: 普通用户
  • 注册时间: 2019-06-17 10:57
文章分类

(298)

  • (298)
文章存档

(96)

(201)

(1)

我的朋友
最近访客
相关博文
  • ·
  • ·
  • ·
  • ·
  • ·
  • ·
  • ·
  • ·
  • ·
  • ·

分类: java

2022-06-10 10:30:18


点击(此处)折叠或打开


  1. 1. pom 加入 security

  2.         <!-- 加入密码认证 -->
  3.         <dependency>
  4.             <groupid>org.springframework.boot</groupid>
  5.             <artifactid>spring-boot-starter-security</artifactid>
  6.         </dependency>
  7. 2. 加入配置类 securitysecureconfig

  8. package org.fh.config;
  9.  
  10. import org.springframework.context.annotation.configuration;
  11. import org.springframework.security.config.annotation.web.builders.httpsecurity;
  12. import org.springframework.security.config.annotation.web.configuration.websecurityconfigureradapter;
  13. import org.springframework.security.web.authentication.savedrequestawareauthenticationsuccesshandler;
  14.  
  15. import de.codecentric.boot.admin.server.config.adminserverproperties;
  16.  
  17. /**
  18.  * 说明:securitysecure配置
  19.  * 作者:fh admin
  20.  * from:fhadmin.cn
  21.  */
  22. @configuration
  23. public class securitysecureconfig extends websecurityconfigureradapter {
  24.  
  25.     private final string admincontextpath;
  26.  
  27.     public securitysecureconfig(adminserverproperties adminserverproperties) {
  28.         this.admincontextpath = adminserverproperties.getcontextpath();
  29.     }
  30.  
  31.     @override
  32.     protected void configure(httpsecurity http) throws exception {
  33.  
  34.         savedrequestawareauthenticationsuccesshandler successhandler = new savedrequestawareauthenticationsuccesshandler();
  35.         successhandler.settargeturlparameter("redirectto");
  36.  
  37.         http.headers().frameoptions().disable();
  38.         
  39.         http.authorizerequests().antmatchers(admincontextpath "/assets/**",admincontextpath "/actuator/**").permitall()
  40.                 .antmatchers(admincontextpath "/login").permitall().anyrequest().authenticated().and().formlogin()
  41.                 .loginpage(admincontextpath "/login").successhandler(successhandler).and().logout()
  42.                 .logouturl(admincontextpath "/logout").and().httpbasic().and().csrf().disable();
  43.  
  44.     }
  45.     
  46. }

  47. 3.  配置 application.properties

  48. #开启安全认证 用户名和密码
  49. spring.security.user.name=fhadmin
  50. spring.security.user.password=root
  51. spring.security.basic.enabled=true



阅读(2532) | 评论(0) | 转发(0) |
0

上一篇:

下一篇:

给主人留下些什么吧!~~
")); function link(t){ var href= $(t).attr('href'); href ="?url=" encodeuricomponent(location.href); $(t).attr('href',href); //setcookie("returnouturl", location.href, 60, "/"); }
网站地图