前言

在搭建成功并集成nacos后,未登录用户也可访问首页,然后敏感信息太多,肯定得需要进程登录认证,此处只是一个演示,实际需要整合自己项目得权限认证

步骤

  1. amdin服务端项目添加pom
        <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-security</artifactId></dependency>
  1. amdin项目添加security配置类
package org.pearl.devops.admin.config;import de.codecentric.boot.admin.server.config.AdminServerProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
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;
import org.springframework.security.web.csrf.CookieCsrfTokenRepository;/*** Created by TD on 2020/10/26*/
@EnableWebSecurity
@Configuration(proxyBeanMethods = false)
public class AdminSecurityConfig extends WebSecurityConfigurerAdapter {private final String adminContextPath;public AdminSecurityConfig(AdminServerProperties adminServerProperties) {this.adminContextPath = adminServerProperties.getContextPath();}@Overrideprotected void configure(HttpSecurity http) throws Exception {// @formatter:offSavedRequestAwareAuthenticationSuccessHandler successHandler = new SavedRequestAwareAuthenticationSuccessHandler();successHandler.setTargetUrlParameter("redirectTo");successHandler.setDefaultTargetUrl(adminContextPath + "/");http.authorizeRequests().antMatchers(adminContextPath + "/assets/**").permitAll().antMatchers(adminContextPath + "/login").permitAll().antMatchers(adminContextPath + "/instances/**").permitAll().anyRequest().authenticated().and().formLogin().loginPage(adminContextPath + "/login").successHandler(successHandler).and().logout().logoutUrl(adminContextPath + "/logout").and().httpBasic().and().csrf().csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse()).ignoringAntMatchers(adminContextPath + "/instances",adminContextPath + "/actuator/**");// @formatter:on}@Overridepublic void configure(WebSecurity web) {web.ignoring().antMatchers("/actuator/**");}
}
  1. yml配置登录用户
spring:application:name: pearl-admincloud:nacos:discovery:server-addr: 127.0.0.1:8848     # nacos注册地址security:user:name: adminpassword: admin
  1. 跳转首页,使用admin/admin登录

Spring Boot Admin系列(3)-Spring Boot Admin添加登录认证相关推荐

  1. Spring Cloud入门系列(1)- Spring生态体系发展史+全系框架介绍

    Spring发展史 2000年,Java EE和EJB迅速发展,很多知名公司都是采用此技术方案进行项目开发,但是EJB 属于重量级框架,开发繁琐.于是一个叫Rod Johnson的大佬写了一本叫做&l ...

  2. 安全系列 —— 在 Laravel 中实现用户注册登录认证

    简介 注:想要快速上手?只需要在新安装的 Laravel 应用下运行 php artisan make:auth 和 php artisan migrate,这两个命令会生成用户登录注册所需要的所有东 ...

  3. Spring Boot 应用系列 1 -- Spring Boot 2 整合Spring Data JPA和Druid,双数据源

    最近Team开始尝试使用Spring Boot + Spring Data JPA作为数据层的解决方案,在网上逛了几圈之后发现大家并不待见JPA,理由是(1)MyBatis简单直观够用,(2)以Hib ...

  4. Spring Boot 应用系列 5 -- Spring Boot 2 整合logback

    上一篇我们梳理了Spring Boot 2 整合log4j2的配置过程,其中讲到了Spring Boot 2原装适配logback,并且在非异步环境下logback和log4j2的性能差别不大,所以对 ...

  5. 【Spring BootSpring Cloud系列】Spring Boot初识

    项目代码地址:https://github.com/AndyFlower/Spring-Boot-Learn/tree/master/Spring-boot-helloworld 一.Spring B ...

  6. service获取selinux权限_Spring Boot 整合 Spring Security 示例实现前后分离权限注解 + JWT 登录认证...

    点击上方蓝色字体,选择"标星公众号" 优质文章,第一时间送达 99套Java企业级实战项目 4000G架构师资料 作者:Sans_ juejin.im/post/5da82f066 ...

  7. 【Spring全家桶系列】Spring中bean标签的配置与使用

    ⭐️前面的话⭐️ 本文已经收录到<Spring框架全家桶系列>专栏(该专栏计划在全部文章更新完毕后付费,反正订阅不要钱,要不来一个?),本文将介绍Spring中XML配置Bean,有关be ...

  8. 【Spring源码系列】Spring注解扫描-@ComponentScan底层原理解读

    这里写目录标题 前言 一.Spring扫描-@ComponentScan注解介绍 @ComponentScan作用 @ComponentScan重要参数 二.Spring扫描-源码分析 声明关键点 源 ...

  9. 闷棍暴打面试官 Spring源码系列: (一) Spring 如何解决循环依赖

    前言 初夏时节, 时间: AM 7.30分左右, 空无一人的健身房里,一个硕大的身体在跑步机上扭动着, 不一会头上便挥汗如雨, 他嘴上还不时嘀咕着 "循环依赖,单例模式,Bean的定位加载注 ...

最新文章

  1. Linux上用户执行命令记录
  2. xml web service
  3. leetcode 18 -- 4Sum
  4. Linux iptables 防火墙相关命令介绍及使用
  5. 从零开始学python项目_从零开始可以这样学python
  6. opencv在python环境下的安装_python环境下安装opencv库的方法
  7. python 打开excel并在屏幕上呈现_excel-检查文件是否在Python中打开
  8. 【华为云技术分享】一统江湖大前端DOClever—你的Postman有点Low
  9. AcWing1069.凸多边形的划分(区间DP)题解
  10. MySQL性能优化的最佳20+套经验
  11. SQL中的Having与Where的区别(面试常问)
  12. 擎标带你了解CMMI3与CMMI5的区别
  13. visio安装报错 1:1935 2:{XXXXXXXX...
  14. 《数论概论》读书笔记 第三章勾股数组与单位圆
  15. 007数据分析能力:业务题
  16. 一款多核架构GPU IP有多达33种配置!Imagination要守住移动市场攻向云端
  17. Model-Agnostic Meta-Learning (MAML) 理解
  18. Access denied for user ‘xxx‘@‘localhost‘ 错误
  19. dos2unix和unix2dos命令
  20. 用Python写一个UI界面

热门文章

  1. Python自动化办公:PDF批量处理(打水印、加密码、分类放置)
  2. 备考英语六级刷题记录 1
  3. A 10-bit 2.6-GS/s Time-Interleaved SAR ADC With a Digital-Mixing Timing-Skew Calibration Technique
  4. EL1041E: After parsing a valid expression, there is still more data in the expression: ‘colon(:)‘
  5. 解决webstorm总是卡得自动退出
  6. 基于规则引擎实现规则可配置的机场地勤人员排班系统
  7. 企业财务制度二--会计科目名称和编号(一)1261 委托代销商品(转载)
  8. 圈子决定人生,靠近什么样的人
  9. JAVA电子产品专卖电商系统计算机毕业设计Mybatis+系统+数据库+调试部署
  10. 男士面试服饰讲究必看十一条