日本不卡不码高清免费观看,久久国产精品久久w女人spa,黄色aa久久,三上悠亚国产精品一区二区三区

您的位置:首頁技術文章
文章詳情頁

SpringBoot與SpringSecurity整合方法附源碼

瀏覽:23日期:2023-03-28 13:11:25

依賴

<dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><!-- Thymeleaf --><dependency><groupId>org.thymeleaf</groupId><artifactId>thymeleaf-spring5</artifactId></dependency><dependency><groupId>org.thymeleaf.extras</groupId><artifactId>thymeleaf-extras-java8time</artifactId></dependency><!-- SpringSecurity --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-security</artifactId></dependency><!-- Thymeleaf 與 SpringSecurity 整合包 --><dependency> <groupId>org.thymeleaf.extras</groupId> <artifactId>thymeleaf-extras-springsecurity5</artifactId> <version>3.0.4.RELEASE</version></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope><exclusions><exclusion><groupId>org.junit.vintage</groupId><artifactId>junit-vintage-engine</artifactId></exclusion></exclusions></dependency></dependencies>

Controller:

package com.blu.controller;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.PathVariable;import org.springframework.web.bind.annotation.RequestMapping;@Controllerpublic 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;}}

SecurityConfig:

package com.blu.config;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;@EnableWebSecuritypublic class SecurityConfig extends WebSecurityConfigurerAdapter{/** * 授權 */@Overrideprotected void configure(HttpSecurity http) throws Exception {//所有人可以訪問首頁,功能頁需要指定權限才可以訪問http.authorizeRequests().antMatchers('/').permitAll().antMatchers('/level1/**').hasRole('vip1').antMatchers('/level2/**').hasRole('vip2').antMatchers('/level3/**').hasRole('vip3');//沒有權限將默認跳轉至登錄頁,需要開啟登錄的頁面//loginPage設置跳轉至登錄頁的請求(默認為/login)//usernameParameter和passwordParameter配置登錄的用戶名和密碼參數名稱,默認就是username和password//loginProcessingUrl配置登錄請求的url,需要和表單提交的url一致http.formLogin().loginPage('/tologin').usernameParameter('username').passwordParameter('password').loginProcessingUrl('/login');//禁用CSRF保護http.csrf().disable();//開啟注銷功能和注銷成功后的跳轉頁面(默認為登錄頁面)http.logout().logoutSuccessUrl('/');//開啟記住我功能,Cookie默認保存兩周http.rememberMe().rememberMeParameter('remember');}/** * 認證 */@Overrideprotected void configure(AuthenticationManagerBuilder auth) throws Exception {auth.inMemoryAuthentication().passwordEncoder(new BCryptPasswordEncoder()).withUser('BLU').password(new BCryptPasswordEncoder().encode('123456')).roles('vip2','vip3').and().withUser('root').password(new BCryptPasswordEncoder().encode('111111')).roles('vip1','vip2','vip3').and().withUser('guest').password(new BCryptPasswordEncoder().encode('111222')).roles('vip1');}}

注:以上方式認證的用戶和角色信息是存儲在內存中的,在實際開發中應該從數據庫中獲取,詳見:SpringSecurity從數據庫中獲取用戶信息進行驗證

index.html

<!DOCTYPE html><html lang='en' xmlns:th='http://www.thymeleaf.org' xmlns:sec='http://www.thymeleaf.org/thymeleaf-extras-springsecurity5'><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='external nofollow' rel='stylesheet'> <link th:href='http://m.b3g6.com/bcjs/@{/qinjiang/css/qinstyle.css}' rel='external nofollow' rel='external nofollow' rel='stylesheet'></head><body><!--主容器--><div class='ui container'> <div th:fragment='nav-menu'> <div class='ui secondary menu'> <a th:href='http://m.b3g6.com/bcjs/@{/index}' rel='external nofollow' >首頁</a> <!--登錄注銷--> <div class='right menu'> <!--如果未登錄--> <div sec:authorize='!isAuthenticated()'> <a th:href='http://m.b3g6.com/bcjs/@{/tologin}' rel='external nofollow' > <i class='address card icon'></i> 登錄 </a> </div> <!--如果已登錄--> <div sec:authorize='isAuthenticated()'> <a class='item'> <i class='address card icon'></i> 用戶名:<span sec:authentication='principal.username'></span> 角色:<span sec:authentication='principal.authorities'></span> </a> </div> <div sec:authorize='isAuthenticated()'> <a th:href='http://m.b3g6.com/bcjs/@{/logout}' rel='external nofollow' > <i class='address card icon'></i> 注銷 </a> </div> </div> </div> </div> <div style='text-align: center'> <h3>Spring Security Study by BLU</h3> </div> <div> <br> <div class='ui three column stackable grid'> <div 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='http://m.b3g6.com/bcjs/@{/level1/1}' rel='external nofollow' ><i class='bullhorn icon'></i> Level-1-1</a></div> <div><a th:href='http://m.b3g6.com/bcjs/@{/level1/2}' rel='external nofollow' ><i class='bullhorn icon'></i> Level-1-2</a></div> <div><a th:href='http://m.b3g6.com/bcjs/@{/level1/3}' rel='external nofollow' ><i class='bullhorn icon'></i> Level-1-3</a></div> </div> </div> </div> </div> <div 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='http://m.b3g6.com/bcjs/@{/level2/1}' rel='external nofollow' ><i class='bullhorn icon'></i> Level-2-1</a></div> <div><a th:href='http://m.b3g6.com/bcjs/@{/level2/2}' rel='external nofollow' ><i class='bullhorn icon'></i> Level-2-2</a></div> <div><a th:href='http://m.b3g6.com/bcjs/@{/level2/3}' rel='external nofollow' ><i class='bullhorn icon'></i> Level-2-3</a></div> </div> </div> </div> </div> <div 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='http://m.b3g6.com/bcjs/@{/level3/1}' rel='external nofollow' ><i class='bullhorn icon'></i> Level-3-1</a></div> <div><a th:href='http://m.b3g6.com/bcjs/@{/level3/2}' rel='external nofollow' ><i class='bullhorn icon'></i> Level-3-2</a></div> <div><a th:href='http://m.b3g6.com/bcjs/@{/level3/3}' rel='external nofollow' ><i class='bullhorn icon'></i> Level-3-3</a></div> </div> </div> </div> </div> </div> </div> </div><script th:src='http://m.b3g6.com/bcjs/@{/qinjiang/js/jquery-3.1.1.min.js}'></script><script th:src='http://m.b3g6.com/bcjs/@{/qinjiang/js/semantic.min.js}'></script></body></html>

views/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='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' /> </form> </div> </div> </div> </div> <div style='text-align: center'> <div class='ui label'> </i>注冊 </div> <br><br> <small>736917155@qq.com</small> </div> <div style='text-align: center'> <h3>Spring Security Study by BLU</h3> </div> </div></div><script th:src='http://m.b3g6.com/bcjs/@{/qinjiang/js/jquery-3.1.1.min.js}'></script><script th:src='http://m.b3g6.com/bcjs/@{/qinjiang/js/semantic.min.js}'></script></body></html>

views/level1/1.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='external nofollow' rel='stylesheet'> <link th:href='http://m.b3g6.com/bcjs/@{/qinjiang/css/qinstyle.css}' rel='external nofollow' rel='external nofollow' rel='stylesheet'></head><body><!--主容器--><div class='ui container'> <div th:replace='~{index::nav-menu}'></div> <div style='text-align: center'> <h3>Level-1-1</h3> </div></div><script th:src='http://m.b3g6.com/bcjs/@{/qinjiang/js/jquery-3.1.1.min.js}'></script><script th:src='http://m.b3g6.com/bcjs/@{/qinjiang/js/semantic.min.js}'></script></body></html>

views/level2/1.html 等其他頁面:略

運行效果:

SpringBoot與SpringSecurity整合方法附源碼SpringBoot與SpringSecurity整合方法附源碼SpringBoot與SpringSecurity整合方法附源碼SpringBoot與SpringSecurity整合方法附源碼SpringBoot與SpringSecurity整合方法附源碼

項目源碼:

鏈接: https://pan.baidu.com/s/1AtbcCht84NT-69-sSUAQRw

提取碼: nh92

到此這篇關于SpringBoot與SpringSecurity整合的文章就介紹到這了,更多相關SpringBoot與SpringSecurity整合內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!

標簽: Spring
相關文章:
日本不卡不码高清免费观看,久久国产精品久久w女人spa,黄色aa久久,三上悠亚国产精品一区二区三区
国产精品99视频| 精品国产亚洲一区二区在线观看| 欧美精品91| 日韩精品免费观看视频| 国产精品av久久久久久麻豆网| 欧美二三四区| 成人污污视频| 国产精品久久久久久久久久齐齐| 99国产精品久久久久久久成人热| 久久精品毛片| 麻豆久久久久久久| 国产精品伊人| 国产精品极品| 国产伦理久久久久久妇女| 视频一区二区国产| 亚洲少妇在线| 亚洲午夜黄色| 久久影视一区| 99视频一区| 玖玖玖国产精品| 亚洲欧洲一区| 西西人体一区二区| 亚久久调教视频| 麻豆国产精品视频| 国产白浆在线免费观看| 色网在线免费观看| 中文字幕人成乱码在线观看| 成人一区而且| 精品欧美激情在线观看| 免费不卡在线视频| 欧美视频精品全部免费观看| 日韩免费久久| 日本在线成人| 欧美成a人国产精品高清乱码在线观看片在线观看久 | 免费视频久久| 欧美日韩亚洲一区在线观看| 蜜臀久久精品| 亚洲三级精品| 国产精品探花在线观看| 中文字幕在线视频网站| 欧美在线综合| 国产精品极品国产中出| 婷婷成人在线| 久久亚洲美女| 在线亚洲人成| 美女精品久久| 免费的成人av| www.com.cn成人| 在线视频免费在线观看一区二区| 亚洲乱码一区| 黄色网一区二区| 国产美女一区| 国产成人免费视频网站视频社区| 亚洲激情社区| 欧美aa一级| 日韩精品视频中文字幕| 精品国产亚洲日本| 中文字幕日韩亚洲| 亚洲二区三区不卡| 久久午夜影院| 欧美欧美黄在线二区| 亚洲一区国产| 美女亚洲一区| 久久电影tv| 美日韩一区二区三区| 蜜桃久久久久久| 久久精品一区二区不卡| 国产资源在线观看入口av| 里番精品3d一二三区| 欧美韩一区二区| 精品一区视频| 国产精品伦一区二区| 国产调教精品| 香蕉久久夜色精品国产| 久久精品影视| 激情91久久| 亚洲一区欧美激情| 亚洲+小说+欧美+激情+另类| 欧美亚洲专区| 久久精品一区| 97欧美在线视频| 国内亚洲精品| 午夜一级在线看亚洲| 四虎精品永久免费| 国产精品激情电影| 麻豆国产欧美一区二区三区 | 狠狠久久伊人| 久久久久久黄| 五月激情久久| 成人av二区| 丝袜国产日韩另类美女| 久久国产精品久久w女人spa| 亚洲精品免费观看| 精品午夜视频| 欧美日韩激情| 国产欧美精品久久| 日韩啪啪电影网| 亚洲三级在线| 日韩精品永久网址| 日韩精品社区| 国内精品福利| 国产探花在线精品| 91看片一区| 欧美偷窥清纯综合图区| 亚洲高清不卡| 久久精品午夜| 国产日韩欧美中文在线| 91高清一区| 日韩影院二区| 欧美成人精品午夜一区二区| 亚洲区第一页| 国产视频一区三区| 日韩三区免费| 久久亚洲国产精品尤物| 久久激五月天综合精品| 亚洲在线免费| 99久久婷婷这里只有精品| 国产精品日韩精品在线播放| 蜜桃av一区二区三区电影| 亚洲第一精品影视| 欧美性感美女一区二区| 久久婷婷一区| 99久久夜色精品国产亚洲1000部 | 成人亚洲一区二区| 成人在线观看免费视频| 日韩欧美2区| 午夜视频一区二区在线观看| 欧美专区18| 免费黄网站欧美| 视频在线在亚洲| 亚洲欧美日本国产专区一区| 999精品色在线播放| 日本国产精品| 精精国产xxxx视频在线播放| 欧美一区三区| 一区在线免费观看| 国产精品毛片一区二区三区| 国产亚洲精品久久久久婷婷瑜伽| 欧美日本不卡高清| 成人免费电影网址| 99视频精品全部免费在线视频| 亚洲精品在线观看91| 99在线精品免费视频九九视| 久久福利精品| 日韩精品免费视频一区二区三区 | 免费国产自久久久久三四区久久 | 久久亚洲图片| 综合一区二区三区| 久草精品视频| 日本高清不卡一区二区三区视频| 久久久一二三| 日韩影院在线观看| 国产精品videossex久久发布 | 欧美成人基地 | 久久精品资源| 日本国产精品| 少妇精品在线| 精品视频高潮| 亚洲色图综合| 国产成人久久精品一区二区三区| 91精品一区二区三区综合| 日av在线不卡| 国产成人精品免费视| 亚洲男女av一区二区| 国产精品红桃| 99国产精品视频免费观看一公开 | 国产成人精品一区二区免费看京 | 午夜欧美精品| 精品日本视频| 日韩精品视频一区二区三区| 日韩不卡视频在线观看| 日韩欧美中文字幕电影| 久久精选视频| 美女视频黄久久| 日本中文字幕视频一区| 国产99久久| 国产美女高潮在线| 国产亚洲欧美日韩精品一区二区三区| 日韩一区电影| 国产精品三上| 精品丝袜在线| 久久精品天堂| 久久一区国产| 91久久精品无嫩草影院| 伊人精品一区| 国产成人77亚洲精品www| 精品国产免费人成网站| 日本aⅴ精品一区二区三区 | 国产亚洲久久| 99在线|亚洲一区二区| 国产一区二区中文| 久久亚洲欧美| 国产精品一区二区三区美女 | 亚洲三级精品| 欧美在线91| 国产一区二区三区不卡视频网站 | 婷婷五月色综合香五月| 久久99精品久久久野外观看| av免费不卡国产观看| 欧美精品激情|