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

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

SpringBoot與SpringSecurity整合方法附源碼

瀏覽:19日期: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://www.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://www.b3g6.com/bcjs/@{/index}' rel='external nofollow' >首頁</a> <!--登錄注銷--> <div class='right menu'> <!--如果未登錄--> <div sec:authorize='!isAuthenticated()'> <a th:href='http://www.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://www.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://www.b3g6.com/bcjs/@{/level1/1}' rel='external nofollow' ><i class='bullhorn icon'></i> Level-1-1</a></div> <div><a th:href='http://www.b3g6.com/bcjs/@{/level1/2}' rel='external nofollow' ><i class='bullhorn icon'></i> Level-1-2</a></div> <div><a th:href='http://www.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://www.b3g6.com/bcjs/@{/level2/1}' rel='external nofollow' ><i class='bullhorn icon'></i> Level-2-1</a></div> <div><a th:href='http://www.b3g6.com/bcjs/@{/level2/2}' rel='external nofollow' ><i class='bullhorn icon'></i> Level-2-2</a></div> <div><a th:href='http://www.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://www.b3g6.com/bcjs/@{/level3/1}' rel='external nofollow' ><i class='bullhorn icon'></i> Level-3-1</a></div> <div><a th:href='http://www.b3g6.com/bcjs/@{/level3/2}' rel='external nofollow' ><i class='bullhorn icon'></i> Level-3-2</a></div> <div><a th:href='http://www.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://www.b3g6.com/bcjs/@{/qinjiang/js/jquery-3.1.1.min.js}'></script><script th:src='http://www.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://www.b3g6.com/bcjs/@{/qinjiang/js/jquery-3.1.1.min.js}'></script><script th:src='http://www.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://www.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://www.b3g6.com/bcjs/@{/qinjiang/js/jquery-3.1.1.min.js}'></script><script th:src='http://www.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久久,三上悠亚国产精品一区二区三区
国产精品一区二区三区美女| 国产理论在线| 91精品久久久久久久久久不卡| 国产精品二区不卡| 理论片午夜视频在线观看| 日本欧美不卡| 久久免费精品| 日韩在线观看| 好吊日精品视频| 亚洲精品中文字幕99999| 欧美午夜三级| 国产aⅴ精品一区二区四区| 久久九九国产| 亚洲色图国产| 精品一区二区三区中文字幕视频 | 国产乱人伦丫前精品视频 | 黄色不卡一区| 午夜亚洲福利| 精品免费av一区二区三区| 视频二区不卡| 在线精品观看| 久久精品一本| 日韩视频中文| 国产精品色婷婷在线观看| 日韩av一级| 日韩精品欧美精品| 免费观看亚洲| 国产亚洲毛片| 国产精品sss在线观看av| 日韩三区在线| 日韩欧美中文字幕电影| 国产一区2区在线观看| 国产免费成人| 欧美欧美黄在线二区| 欧美日韩一区二区三区视频播放| 四虎精品一区二区免费| 欧美成a人免费观看久久| 日韩av中文字幕一区二区 | 欧美视频精品全部免费观看| 青草综合视频| 久久久一本精品| 亚洲精品高潮| 亚洲播播91| 日本va欧美va瓶| 久久久天天操| 国产乱人伦精品一区| 99xxxx成人网| 精品网站999| 午夜亚洲福利| 99久久九九| 麻豆中文一区二区| 亚洲一区欧美| 亚洲国产一区二区三区在线播放 | 日韩中文字幕91| 国产伦久视频在线观看| 日韩久久99| 狠狠干综合网| 精品中文在线| 日韩av一区二区三区四区| 久久在线电影| 国产高清不卡| 精品亚洲成人| 青青草精品视频| 久久亚洲一区| 欧美精品羞羞答答| 亚洲精品在线影院| 荡女精品导航| 国产精品久久久久久av公交车| 日韩免费小视频| 国产精品亚洲二区| 在线观看亚洲精品福利片| 91精品国产乱码久久久久久久| 久久精品午夜| 国产剧情一区| 日本在线不卡视频一二三区| 国产手机视频一区二区| 欧美精品一区二区久久| 亚洲一级少妇| xxxxx性欧美特大| 91亚洲人成网污www| 久久av国产紧身裤| 日韩超碰人人爽人人做人人添| 久久午夜精品| 久久视频国产| 国产在线|日韩| 午夜精品成人av| 色爱av综合网| 久久要要av| 婷婷亚洲五月色综合| 欧美在线影院| 性一交一乱一区二区洋洋av| 欧美美女一区| 一区在线免费| 久久成人国产| 最新日韩av| 欧美精品自拍| 亚洲欧美日韩国产| 在线日韩成人| 视频国产精品| 国产日韩欧美中文在线| 国产高清精品二区| 精品久久影院| 综合日韩av| 激情婷婷久久| 麻豆久久精品| 日本aⅴ免费视频一区二区三区| 日本免费在线视频不卡一不卡二| 日本不卡一二三区黄网| 青青伊人久久| 久久av资源| 免费福利视频一区二区三区| 伊人久久大香线蕉av不卡| 亚洲v在线看| 欧美日韩免费看片| 尤物精品在线| 日韩精品国产欧美| 精品国产精品国产偷麻豆| 日本韩国欧美超级黄在线观看| 国内精品福利| 日韩一区免费| 精品一区二区三区免费看 | 蜜桃视频一区二区三区在线观看| 日韩精品导航| 国产一区调教| 久久在线免费| 国产高潮在线| 午夜精品一区二区三区国产| 蜜臀va亚洲va欧美va天堂| 国产区精品区| 亚洲播播91| 少妇精品久久久一区二区三区| 国产伦精品一区二区三区视频 | 亚洲日本三级| 精品高清久久| 国产亚洲毛片在线| 国产精品99久久久久久董美香| 久久久精品日韩| 亚洲精品看片| 国产精品99一区二区三区| 99国产精品| 久久伊人国产| 久久国产精品亚洲77777| 麻豆视频一区二区| 亚洲激情另类| 美女视频黄久久| 亚洲一区二区毛片| 国产日韩在线观看视频| 99视频精品全国免费| 欧美亚洲综合视频| 欧美.日韩.国产.一区.二区 | 日韩黄色免费网站| 精品女同一区二区三区在线观看| 欧美日韩国产高清电影| 国产精品大片| 狠狠久久婷婷| 精品免费av| 亚洲综合中文| 精精国产xxxx视频在线野外| 日韩激情啪啪| 欧美在线网站| 精品国产第一福利网站| 日韩精品免费一区二区夜夜嗨 | 国产欧美日韩视频在线| 久久视频精品| 久久精品资源| 日韩毛片网站| 久久都是精品| 欧美中文一区二区| 97在线精品| 国产精品毛片aⅴ一区二区三区| 99香蕉国产精品偷在线观看 | 91亚洲一区| 91欧美日韩在线| 欧美日韩视频一区二区三区| 精品国产精品久久一区免费式 | 日本在线视频一区二区| 最新亚洲一区| 日韩一区电影| 福利在线一区| 国产欧美日韩精品一区二区免费| 美女黄网久久| 一区视频在线| 欧美日韩国产免费观看视频| 丝袜av一区| 91欧美日韩| 丰满少妇一区| 国产极品久久久久久久久波多结野| 亚洲免费观看高清完整版在线观| 夜夜精品视频| 午夜精品影院| 欧美aa国产视频| 伊人精品一区| 亚洲夜间福利| 热三久草你在线| 日韩av二区| 国产拍在线视频| 日韩国产一区| 天堂日韩电影| 亚洲h色精品| 成人一区而且|