Spring Boot中的SpringSecurity基礎教程
一 SpringSecurity簡介
- Web開發(fā)中,雖然安全屬于非共功能性需求,但也是應用非常重要的一部分。
- 如果開發(fā)后期才考慮安全問題,就會有兩方面的弊處:
- 一方面,應用存在嚴重的安全漏洞,無法滿足用戶需求,可能造成用戶隱私數(shù)據(jù)被攻擊者竊取
- 另一方面,應用的基本架構已經(jīng)確定,要修復安全漏洞,可能需要對系統(tǒng)的架構做出比較重大的調整,會需要更多的開發(fā)時間,影響應用的發(fā)布進程
- 結論:從應用開發(fā)的第一天就要把安全相關的因素考慮進來,并持續(xù)在整個應用的開發(fā)過程中
- Spring Security是一個功能強大且高度可定制的身份驗證和訪問控制框架。它實際上是保護基于spring的應用程序的標準Spring Security是一個框架,側重于為Java應用程序提供身份驗證和授權。
- Spring安全性的真正強大之處在于它可以輕松地擴展以滿足定制需求
- Spring 是一個非常流行和成功的 Java 應用開發(fā)框架。Spring Security 基于 Spring 框架,提供了一套Web 應用安全性的完整解決方案。一般來說,Web 應用的安全性包括用戶認證(Authentication)和用戶授權(Authorization)兩個部分。
- 用戶認證指的是驗證某個用戶是否為系統(tǒng)中的合法主體,也就是說用戶能否訪問該系統(tǒng)。用戶認證一般要求用戶提供用戶名和密碼。系統(tǒng)通過校驗用戶名和密碼來完成認證過程。
- 用戶授權指的是驗證某個用戶是否有權限執(zhí)行某個操作。在一個系統(tǒng)中,不同用戶所具有的權限是不同的。比如對一個文件來說,有的用戶只能進行讀取,而有的用戶可以進行修改。一般來說,系統(tǒng)會為不同的用戶分配不同的角色,而每個角色則對應一系列的權限。
- 在用戶認證方面,SpringSecurity 框架支持主流的認證方式,包括==HTTP 基本認證、HTTP 表單驗證、HTTP 摘要認證、OpenID和LDAP ==等。
- 在用戶授權方面,Spring Security 提供了基于角色的訪問控制和訪問控制列表(Access Control List,ACL),可以對應用中的領域對象進行細粒度的控制。
- Spring Security 是針對Spring項目的安全框架,也是Spring Boot底層安全模塊默認的技術選型,可以實現(xiàn)強大的Web安全控制,對于安全控制,僅需要引入 spring-boot-starter-security 模塊,進行少量的配置,即可實現(xiàn)強大的安全管理!
- 幾個重要的類
- WebSecurityConfigurerAdapter: 自定義Security策略
- AuthenticationManagerBuilder:自定義認證策略
- @EnableWebSecurity:開啟WebSecurity模式
- Spring Security的兩個主要目標是 “認證” 和 “授權”(訪問控制)
- “認證”(Authentication)
- 身份驗證是關于驗證您的憑據(jù),如用戶名/用戶ID和密碼,以驗證您的身份。
- 身份驗證通常通過用戶名和密碼完成,有時與身份驗證因素結合使用。
- “授權” (Authorization)
- 授權發(fā)生在系統(tǒng)成功驗證您的身份后,最終會授予您訪問資源(如信息,文件,數(shù)據(jù)庫,資金,位置,幾乎任何內容)的完全權限。
二 實戰(zhàn)演示
0. 環(huán)境 介紹
- jdk 1.8
- Spring Boot 2.0.9.RELEASE
1. 新建一個初始的springboot項目

2. 導入thymeleaf依賴
<!--thymeleaf-->
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf-spring5</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-java8time</artifactId>
</dependency>3. 導入靜態(tài)資源

4. 編寫controller跳轉
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
/**
* @author 緣友一世
* date 2022/9/11-21:56
*/
@Controller
public class RouterController {
@RequestMapping({"/","/index"})
public String index() {
return "index";
}
@RequestMapping("/toLogin")
public String toLogin() {
return "views/login";
}
@RequestMapping("/level1/{id}")
public String level1(@PathVariable("id") int id) {
return "views/level1/"+id;
}
@RequestMapping("/level2/{id}")
public String level2(@PathVariable("id") int id) {
return "views/level2/"+id;
}
@RequestMapping("/level3/{id}")
public String level3(@PathVariable("id") int id) {
return "views/level3/"+id;
}
}
5. 認證和授權
- Spring Security 增加上認證和授權的功能
引入Spring Security模塊
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>2.編寫 Spring Security 配置類
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
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.crypto.bcrypt.BCryptPasswordEncoder;
/**
* @author 緣友一世
* date 2022/9/11-22:13
*/
// 開啟WebSecurity模式
@EnableWebSecurity //AOP 攔截器
public class SecurityConfig extends WebSecurityConfigurerAdapter {
//鏈式編程
@Override
protected void configure(HttpSecurity http) throws Exception {
}
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
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.crypto.bcrypt.BCryptPasswordEncoder;
/**
* @author 緣友一世
* date 2022/9/11-22:13
*/
// 開啟WebSecurity模式
@EnableWebSecurity //AOP 攔截器
public class SecurityConfig extends WebSecurityConfigurerAdapter {
//鏈式編程
@Override
protected void configure(HttpSecurity http) throws Exception {
}
3.定制請求的授權規(guī)則
//鏈式編程
@Override
protected void configure(HttpSecurity http) throws Exception {
//首頁所有人可以訪問,功能頁面只有對應的人可以訪問
//請求授權的規(guī)則
http.authorizeRequests().antMatchers("/").permitAll()
.antMatchers("/level1/**").hasRole("vip1")
.antMatchers("/level2/**").hasRole("vip2")
.antMatchers("/level3/**").hasRole("vip3");
}4.測試一下:發(fā)現(xiàn)除了首頁都進不去了!因為我們目前沒有登錄的角色,因為請求需要登錄的角色擁有對應的權限才可以
5.在 configure() 方法中加入以下配置,開啟自動配置的登錄功能
//沒有權限默認回到登錄頁面,需要開啟登錄的頁面 http.formLogin();
6.定義認證規(guī)則,重寫 configure(AuthenticationManagerBuilder auth) 方法
- 要將前端傳過來的密碼進行某種方式加密,否則就無法登錄

/**
* 要將前端傳過來的密碼進行某種方式加密,否則就無法登錄
* @param auth
* @throws Exception
*/
@Override //認證 密碼編碼 PassWordEncoder
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication().passwordEncoder(new BCryptPasswordEncoder())
.withUser("yang").password(new BCryptPasswordEncoder().encode("123456")).roles("vip2","vip3")
.and()
.withUser("root").password(new BCryptPasswordEncoder().encode("123456")).roles("vip1","vip2","vip3")
.and()
.withUser("guest").password(new BCryptPasswordEncoder().encode("123456")).roles("vip1");
}6. 權限控制和注銷
開啟自動配置的注銷的功能
@EnableWebSecurity //AOP 攔截器
public class SecurityConfig extends WebSecurityConfigurerAdapter {
//鏈式編程
@Override
protected void configure(HttpSecurity http) throws Exception {
//首頁所有人可以訪問,功能頁面只有對應的人可以訪問
//請求授權的規(guī)則
http.authorizeRequests().antMatchers("/").permitAll()
.antMatchers("/level1/**").hasRole("vip1")
.antMatchers("/level2/**").hasRole("vip2")
.antMatchers("/level3/**").hasRole("vip3");
//注銷 跳到首頁
http.logout().logoutSuccessUrl("/");在前端,增加一個注銷的按鈕, index.html 導航欄中
<a class="item" th:href="@{/logout}" rel="external nofollow" rel="external nofollow" rel="external nofollow" >
<i class="address card icon"></i> 注銷
</a>不同身份的用戶,顯示不同內容
- 用戶沒有登錄的時候,導航欄上只顯示登錄按鈕,用戶登錄之后,導航欄可以顯示登錄的用戶信息及注銷按鈕
- sec:authorize=“isAuthenticated()”:是否認證登錄! 來顯示不同的頁面
- 導入依賴
<!--thymeleaf-security整合包-->
<!-- https://mvnrepository.com/artifact/org.thymeleaf.extras/thymeleaf-extras-springsecurity4 -->
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity4</artifactId>
<version>3.0.4.RELEASE</version>
</dependency>在前端頁面導入命名空間
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4">
修改導航欄,增加認證判斷
<!--index.html-->
<!--登錄注銷-->
<div class="right menu">
<!--如果未登錄-->
<div sec:authorize="!isAuthenticated()">
<a class="item" th:href="@{/toLogin}" rel="external nofollow" rel="external nofollow" >
<i class="address card icon"></i> 登錄
</a>
</div>
<!--如果登陸了:用戶名、注銷-->
<!--當?shù)卿?、用戶名、退出同時出現(xiàn),是spring版本太高了,降至2.0.9/7 就能正常了-->
<div sec:authorize="isAuthenticated()">
<a class="item" >
用戶名:<span sec:authentication="name"></span>
</a>
</div>
<div sec:authorize="isAuthenticated()">
<a class="item" th:href="@{/logout}" rel="external nofollow" rel="external nofollow" rel="external nofollow" >
<i class="sign-out icon"></i> 注銷
</a>
</div>
</div>如果注銷404,就是因為它默認防止csrf跨站請求偽造,因為會產(chǎn)生安全問題,我們可以將請求改為post表單提交,或者在spring security中關閉csrf功能;我們試試
//鏈式編程
@Override
protected void configure(HttpSecurity http) throws Exception {
//首頁所有人可以訪問,功能頁面只有對應的人可以訪問
//請求授權的規(guī)則
http.authorizeRequests().antMatchers("/").permitAll()
.antMatchers("/level1/**").hasRole("vip1")
.antMatchers("/level2/**").hasRole("vip2")
.antMatchers("/level3/**").hasRole("vip3");
//沒有權限默認回到登錄頁面,需要開啟登錄的頁面
http.formLogin().loginProcessingUrl("/login");
//防止網(wǎng)站攻擊 csrf--跨站請求偽造
http.csrf().disable();
//注銷 跳到首頁
http.logout().logoutSuccessUrl("/");
}角色功能塊
<div>
<br>
<div class="ui three column stackable grid">
<div class="column" sec:authorize="hasRole('vip1')">
<div class="ui raised segment">
<div class="ui">
<div class="content">
<h5 class="content">Level 1</h5>
<hr>
<div><a th:href="@{/level1/1}" rel="external nofollow" rel="external nofollow" ><i class="bullhorn icon"></i> Level-1-1</a></div>
<div><a th:href="@{/level1/2}" rel="external nofollow" rel="external nofollow" ><i class="bullhorn icon"></i> Level-1-2</a></div>
<div><a th:href="@{/level1/3}" rel="external nofollow" rel="external nofollow" ><i class="bullhorn icon"></i> Level-1-3</a></div>
</div>
</div>
</div>
</div>
<div class="column" sec:authorize="hasRole('vip2')">
<div class="ui raised segment">
<div class="ui">
<div class="content">
<h5 class="content">Level 2</h5>
<hr>
<div><a th:href="@{/level2/1}" rel="external nofollow" rel="external nofollow" ><i class="bullhorn icon"></i> Level-2-1</a></div>
<div><a th:href="@{/level2/2}" rel="external nofollow" rel="external nofollow" ><i class="bullhorn icon"></i> Level-2-2</a></div>
<div><a th:href="@{/level2/3}" rel="external nofollow" rel="external nofollow" ><i class="bullhorn icon"></i> Level-2-3</a></div>
</div>
</div>
</div>
</div>
<div class="column" sec:authorize="hasRole('vip3')">
<div class="ui raised segment">
<div class="ui">
<div class="content">
<h5 class="content">Level 3</h5>
<hr>
<div><a th:href="@{/level3/1}" rel="external nofollow" rel="external nofollow" ><i class="bullhorn icon"></i> Level-3-1</a></div>
<div><a th:href="@{/level3/2}" rel="external nofollow" rel="external nofollow" ><i class="bullhorn icon"></i> Level-3-2</a></div>
<div><a th:href="@{/level3/3}" rel="external nofollow" rel="external nofollow" ><i class="bullhorn icon"></i> Level-3-3</a></div>
</div>
</div>
</div>
</div>
</div>
</div>
7. 記住登錄
開啟記住我功能
//鏈式編程
@Override
protected void configure(HttpSecurity http) throws Exception {
//首頁所有人可以訪問,功能頁面只有對應的人可以訪問
//請求授權的規(guī)則
http.authorizeRequests().antMatchers("/").permitAll()
.antMatchers("/level1/**").hasRole("vip1")
.antMatchers("/level2/**").hasRole("vip2")
.antMatchers("/level3/**").hasRole("vip3");
//沒有權限默認回到登錄頁面,需要開啟登錄的頁面
http.formLogin().loginProcessingUrl("/login");// 登陸表單提交請求
//防止網(wǎng)站攻擊 csrf--跨站請求偽造
http.csrf().disable();
//注銷 跳到首頁
http.logout().logoutSuccessUrl("/");
//開啟記住功能 cookie默認保持兩周 自定義接收前端的參數(shù)
http.rememberMe().rememberMeParameter("remember");
}
原理:登錄成功后,將cookie發(fā)送給瀏覽器保存,以后登錄帶上這個cookie,只要通過檢查就可以免登錄了。如果點擊注銷,則會刪除這個cookie
8. 定制登錄頁面
在登錄頁配置后面指定.loginPage
<form th:action="@{/login}" method="post">
<div class="field">
<label>Username</label>
<div class="ui left icon input">
<input type="text" placeholder="Username" name="username">
<i class="user icon"></i>
</div>
</div>
<div class="field">
<label>Password</label>
<div class="ui left icon input">
<input type="password" name="password">
<i class="lock icon"></i>
</div>
</div>
<div class="field">
<input type="checkbox" name="remember"> 記住我
</div>
<input type="submit" class="ui blue submit button"/>
</form>login.html 配置提交請求及方式,方式必須為post
//鏈式編程
@Override
protected void configure(HttpSecurity http) throws Exception {
//首頁所有人可以訪問,功能頁面只有對應的人可以訪問
//請求授權的規(guī)則
http.authorizeRequests().antMatchers("/").permitAll()
.antMatchers("/level1/**").hasRole("vip1")
.antMatchers("/level2/**").hasRole("vip2")
.antMatchers("/level3/**").hasRole("vip3");
//沒有權限默認回到登錄頁面,需要開啟登錄的頁面
http.formLogin().loginPage("/toLogin");
//防止網(wǎng)站攻擊 csrf--跨站請求偽造
http.csrf().disable();
//注銷 跳到首頁
http.logout().logoutSuccessUrl("/");
//開啟記住功能 cookie默認保持兩周 自定義接收前端的參數(shù)
http.rememberMe().rememberMeParameter("remember");
}配置接收登錄的用戶名和密碼的參數(shù)!
http.formLogin()
.usernameParameter("username")
.passwordParameter("password")
.loginPage("/toLogin")
.loginProcessingUrl("/login"); // 登陸表單提交請求在登錄頁增加記住我的多選框
<input type="checkbox" name="remember"> 記住我
后端驗證處理
//定制記住我的參數(shù)!
http.rememberMe().rememberMeParameter("remember");三 完整代碼
3.1 pom配置文件
<dependencies>
<!--thymeleaf-security整合包-->
<!-- https://mvnrepository.com/artifact/org.thymeleaf.extras/thymeleaf-extras-springsecurity4 -->
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity4</artifactId>
<version>3.0.4.RELEASE</version>
</dependency>
<!--thymeleaf-->
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf-spring5</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-java8time</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
3.2 RouterController.java
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
/**
* @author 緣友一世
* date 2022/9/11-21:56
*/
@Controller
public class RouterController {
@RequestMapping({"/","/index"})
public String index() {
return "index";
}
@RequestMapping("/toLogin")
public String toLogin() {
return "views/login";
}
@RequestMapping("/level1/{id}")
public String level1(@PathVariable("id") int id) {
return "views/level1/"+id;
}
@RequestMapping("/level2/{id}")
public String level2(@PathVariable("id") int id) {
return "views/level2/"+id;
}
@RequestMapping("/level3/{id}")
public String level3(@PathVariable("id") int id) {
return "views/level3/"+id;
}
}
3.3 SecurityConfig.java
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
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.crypto.bcrypt.BCryptPasswordEncoder;
/**
* @author 緣友一世
* date 2022/9/11-22:13
*/
@EnableWebSecurity //AOP 攔截器
public class SecurityConfig extends WebSecurityConfigurerAdapter {
//鏈式編程
@Override
protected void configure(HttpSecurity http) throws Exception {
//首頁所有人可以訪問,功能頁面只有對應的人可以訪問
//請求授權的規(guī)則
http.authorizeRequests().antMatchers("/").permitAll()
.antMatchers("/level1/**").hasRole("vip1")
.antMatchers("/level2/**").hasRole("vip2")
.antMatchers("/level3/**").hasRole("vip3");
//沒有權限默認回到登錄頁面,需要開啟登錄的頁面
http.formLogin().usernameParameter("username")
.passwordParameter("password")
.loginPage("/toLogin")
.loginProcessingUrl("/login");
//防止網(wǎng)站攻擊 csrf--跨站請求偽造
http.csrf().disable();
//注銷 跳到首頁
http.logout().logoutSuccessUrl("/");
//開啟記住功能 cookie默認保持兩周 自定義接收前端的參數(shù)
http.rememberMe().rememberMeParameter("remember");
}
/**
* 要將前端傳過來的密碼進行某種方式加密,否則就無法登錄
* @param auth
* @throws Exception
*/
@Override //認證 密碼編碼 PassWordEncoder
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication().passwordEncoder(new BCryptPasswordEncoder())
.withUser("yang").password(new BCryptPasswordEncoder().encode("123456")).roles("vip2","vip3")
.and()
.withUser("root").password(new BCryptPasswordEncoder().encode("123456")).roles("vip1","vip2","vip3")
.and()
.withUser("guest").password(new BCryptPasswordEncoder().encode("123456")).roles("vip1");
}
}
3.4 login.html
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title>登錄</title>
<!--semantic-ui-->
<link rel="external nofollow" rel="external nofollow" rel="stylesheet">
</head>
<body>
<!--主容器-->
<div class="ui container">
<div class="ui segment">
<div style="text-align: center">
<h1 class="header">登錄</h1>
</div>
<div class="ui placeholder segment">
<div class="ui column very relaxed stackable grid">
<div class="column">
<div class="ui form">
<form th:action="@{/login}" method="post">
<div class="field">
<label>Username</label>
<div class="ui left icon input">
<input type="text" placeholder="Username" name="username">
<i class="user icon"></i>
</div>
</div>
<div class="field">
<label>Password</label>
<div class="ui left icon input">
<input type="password" name="password">
<i class="lock icon"></i>
</div>
</div>
<div class="field">
<input type="checkbox" name="remember"> 記住我
</div>
<input type="submit" class="ui blue submit button"/>
</form>
</div>
</div>
</div>
</div>
<div style="text-align: center">
<div class="ui label">
</i>注冊
</div>
<br><br>
<small>blog.kuangstudy.com</small>
</div>
<div class="ui segment" style="text-align: center">
<h3>Spring Security Study</h3>
</div>
</div>
</div>
<script th:src="@{/qinjiang/js/jquery-3.1.1.min.js}"></script>
<script th:src="@{/qinjiang/js/semantic.min.js}"></script>
</body>
</html>3.5 index.html
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org"
xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title>首頁</title>
<!--semantic-ui-->
<link rel="external nofollow" rel="external nofollow" rel="stylesheet">
<link th:href="@{/qinjiang/css/qinstyle.css}" rel="external nofollow" rel="stylesheet">
</head>
<body>
<!--主容器-->
<div class="ui container">
<div class="ui segment" id="index-header-nav" th:fragment="nav-menu">
<div class="ui secondary menu">
<a class="item" th:href="@{/index}" rel="external nofollow" >首頁</a>
<!--登錄注銷-->
<div class="right menu">
<!--如果未登錄-->
<div sec:authorize="!isAuthenticated()">
<a class="item" th:href="@{/toLogin}" rel="external nofollow" rel="external nofollow" >
<i class="address card icon"></i> 登錄
</a>
</div>
<!--如果登陸了:用戶名、注銷-->
<!--當?shù)卿?、用戶名、退出同時出現(xiàn),是spring版本太高了,降至2.0.9/7 就能正常了-->
<div sec:authorize="isAuthenticated()">
<a class="item" >
用戶名:<span sec:authentication="name"></span>
</a>
</div>
<div sec:authorize="isAuthenticated()">
<a class="item" th:href="@{/logout}" rel="external nofollow" rel="external nofollow" rel="external nofollow" >
<i class="sign-out icon"></i> 注銷
</a>
</div>
<!--已登錄
<a th:href="@{/usr/toUserCenter}" rel="external nofollow" >
<i class="address card icon"></i> admin
</a>
-->
</div>
</div>
</div>
<div class="ui segment" style="text-align: center">
<h3>Spring Security Study</h3>
</div>
<div>
<br>
<div class="ui three column stackable grid">
<div class="column" sec:authorize="hasRole('vip1')">
<div class="ui raised segment">
<div class="ui">
<div class="content">
<h5 class="content">Level 1</h5>
<hr>
<div><a th:href="@{/level1/1}" rel="external nofollow" rel="external nofollow" ><i class="bullhorn icon"></i> Level-1-1</a></div>
<div><a th:href="@{/level1/2}" rel="external nofollow" rel="external nofollow" ><i class="bullhorn icon"></i> Level-1-2</a></div>
<div><a th:href="@{/level1/3}" rel="external nofollow" rel="external nofollow" ><i class="bullhorn icon"></i> Level-1-3</a></div>
</div>
</div>
</div>
</div>
<div class="column" sec:authorize="hasRole('vip2')">
<div class="ui raised segment">
<div class="ui">
<div class="content">
<h5 class="content">Level 2</h5>
<hr>
<div><a th:href="@{/level2/1}" rel="external nofollow" rel="external nofollow" ><i class="bullhorn icon"></i> Level-2-1</a></div>
<div><a th:href="@{/level2/2}" rel="external nofollow" rel="external nofollow" ><i class="bullhorn icon"></i> Level-2-2</a></div>
<div><a th:href="@{/level2/3}" rel="external nofollow" rel="external nofollow" ><i class="bullhorn icon"></i> Level-2-3</a></div>
</div>
</div>
</div>
</div>
<div class="column" sec:authorize="hasRole('vip3')">
<div class="ui raised segment">
<div class="ui">
<div class="content">
<h5 class="content">Level 3</h5>
<hr>
<div><a th:href="@{/level3/1}" rel="external nofollow" rel="external nofollow" ><i class="bullhorn icon"></i> Level-3-1</a></div>
<div><a th:href="@{/level3/2}" rel="external nofollow" rel="external nofollow" ><i class="bullhorn icon"></i> Level-3-2</a></div>
<div><a th:href="@{/level3/3}" rel="external nofollow" rel="external nofollow" ><i class="bullhorn icon"></i> Level-3-3</a></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script th:src="@{/qinjiang/js/jquery-3.1.1.min.js}"></script>
<script th:src="@{/qinjiang/js/semantic.min.js}"></script>
</body>
</html>
3.6 效果展示

到此這篇關于Spring Boot中的SpringSecurity學習的文章就介紹到這了,更多相關Spring Boot之SpringSecurity內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
Spring Boot Hazelcast Caching 使用和配置詳解
這篇文章主要介紹了Spring Boot Hazelcast Caching 使用和配置詳解,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-09-09
@insert mybatis踩坑記錄,實體接收前端傳遞的參數(shù)
這篇文章主要介紹了@insert mybatis踩坑記錄,實體接收前端傳遞的參數(shù)問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-07-07
SpringBoot Shiro授權實現(xiàn)過程解析
這篇文章主要介紹了SpringBoot Shiro授權實現(xiàn)過程解析,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下2019-11-11
idea創(chuàng)建SpringBoot自動創(chuàng)建Lombok無效果的問題解決方案
這篇文章主要介紹了idea創(chuàng)建SpringBoot自動創(chuàng)建Lombok無效果的問題解決方案,感興趣的朋友跟隨小編一起看看吧2024-12-12
Spring?Boot?@Autowired?@Resource屬性賦值時機探究
這篇文章主要為大家介紹了Spring?Boot?@Autowired?@Resource屬性賦值時機,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-07-07
關于springboot加載yml配置文件的no字段自動轉義問題
這篇文章主要介紹了關于springboot加載yml配置文件的no字段自動轉義問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-02-02

