国产亚洲精品福利在线无卡一,国产精久久一区二区三区,亚洲精品无码国模,精品久久久久久无码专区不卡

當前位置: 首頁 > news >正文

個人網(wǎng)站怎么做推廣好口碑關(guān)鍵詞優(yōu)化

個人網(wǎng)站怎么做推廣,好口碑關(guān)鍵詞優(yōu)化,徐州網(wǎng)約車司機真實收入,網(wǎng)站內(nèi)存不足項目代碼 gson/spring-security-demo 簡介 Spring Security 是 Spring 家族中的一個安全管理框架。相比與另外一個安全框架Shiro,它提供了更豐富的功能,社區(qū)資源也比Shiro豐富。 一般來說中大型的項目都是使用SpringSecurity來做安全框架。小項目有Shiro的比較多,因為相比…

項目代碼

gson/spring-security-demo


簡介

Spring Security 是 Spring 家族中的一個安全管理框架。相比與另外一個安全框架Shiro,它提供了更豐富的功能,社區(qū)資源也比Shiro豐富。

一般來說中大型的項目都是使用SpringSecurity來做安全框架。小項目有Shiro的比較多,因為相比與SpringSecurity,Shiro的上手更加的簡單。

一般Web應(yīng)用的需要進行認證授權(quán)

認證:驗證當前訪問系統(tǒng)的是不是本系統(tǒng)的用戶,并且要確認具體是哪個用戶

授權(quán):經(jīng)過認證后判斷當前用戶是否有權(quán)限進行某個操作

而認證和授權(quán)也是SpringSecurity作為安全框架的核心功能。


搭建基礎(chǔ)項目

1、我們先搭建一個簡單的SpringBoot工程,并添加相關(guān)依賴

 <parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.5.0</version></parent><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><optional>true</optional></dependency></dependencies>

2、創(chuàng)建啟動類

@SpringBootApplication
public class SecurityApplication {public static void main(String[] args) {SpringApplication.run(SecurityApplication.class,args);}
}

3、創(chuàng)建Controller

@RestController
@RequestMapping("/book")
public class BookController {@GetMapping("/list")public String list() {return "book-list";}}

4、創(chuàng)建配置文件application.yml

server:port: 8000

然后啟動項目,輸入地址進行訪問測試


引入SpringSecurity

在SpringBoot項目中使用SpringSecurity我們只需要引入依賴即可實現(xiàn)入門案例。

       <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-security</artifactId></dependency>

引入依賴后我們在嘗試去訪問之前的接口就會自動跳轉(zhuǎn)到一個SpringSecurity的默認登陸頁面,默認用戶名是user,密碼會輸出在控制臺。

必須登陸之后才能對接口進行訪問。


認證

登陸校驗流程

SpringSecurity完整流程

SpringSecurity的原理其實就是一個過濾器鏈,內(nèi)部包含了提供各種功能的過濾器。這里我們可以看看入門案例中的過濾器。

圖中只展示了核心過濾器,其它的非核心過濾器并沒有在圖中展示。

UsernamePasswordAuthenticationFilter:負責處理我們在登陸頁面填寫了用戶名密碼后的登陸請求。入門案例的認證工作主要有它負責。

ExceptionTranslationFilter:處理過濾器鏈中拋出的任何AccessDeniedException和AuthenticationException 。

FilterSecurityInterceptor:負責權(quán)限校驗的過濾器。

我們可以通過Debug查看當前系統(tǒng)中SpringSecurity過濾器鏈中有哪些過濾器及它們的順序。

認證流程詳解

概念速查:

  • Authentication接口: 它的實現(xiàn)類,表示當前訪問系統(tǒng)的用戶,封裝了用戶相關(guān)信息。
  • AuthenticationManager接口:定義了認證Authentication的方法
  • UserDetailsService接口:加載用戶特定數(shù)據(jù)的核心接口。里面定義了一個根據(jù)用戶名查詢用戶信息的方法。
  • UserDetails接口:提供核心用戶信息。通過UserDetailsService根據(jù)用戶名獲取處理的用戶信息要封裝成UserDetails對象返回。然后將這些信息封裝到Authentication對象中。

登錄過程分析

登錄

①自定義登錄接口

  • 調(diào)用ProviderManager的方法進行認證 如果認證通過生成jwt,
  • 把用戶信息存入redis中

②自定義UserDetailsService

  • 在這個實現(xiàn)類中去查詢數(shù)據(jù)庫

校驗:

①定義Jwt認證過濾器

  • 獲取token
  • 解析token獲取其中的userid
  • 從redis中獲取用戶信息
  • 存入SecurityContextHolder

代碼準備工作

1、添加依賴

        <!--redis依賴--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-redis</artifactId></dependency><!--fastjson依賴--><dependency><groupId>com.alibaba</groupId><artifactId>fastjson</artifactId><version>1.2.33</version></dependency><!--jwt依賴--><dependency><groupId>io.jsonwebtoken</groupId><artifactId>jjwt</artifactId><version>0.9.0</version></dependency><!-- 引入MybatisPuls和mysql驅(qū)動的依賴--><dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-boot-starter</artifactId><version>3.4.3</version></dependency><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId></dependency><!-- 單元測試的依賴--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId></dependency>

2、添加Redis相關(guān)配置

/*** Redis使用FastJson序列化** @author sg*/
public class FastJsonRedisSerializer<T> implements RedisSerializer<T>
{public static final Charset DEFAULT_CHARSET = Charset.forName("UTF-8");private Class<T> clazz;static{ParserConfig.getGlobalInstance().setAutoTypeSupport(true);}public FastJsonRedisSerializer(Class<T> clazz){super();this.clazz = clazz;}@Overridepublic byte[] serialize(T t) throws SerializationException{if (t == null){return new byte[0];}return JSON.toJSONString(t, SerializerFeature.WriteClassName).getBytes(DEFAULT_CHARSET);}@Overridepublic T deserialize(byte[] bytes) throws SerializationException{if (bytes == null || bytes.length <= 0){return null;}String str
http://aloenet.com.cn/news/41080.html

相關(guān)文章:

  • 深圳市網(wǎng)站維護seo短視頻網(wǎng)頁入口
  • 營銷公關(guān)seo關(guān)鍵詞找29火星軟件
  • wordpress博客實戰(zhàn)青島百度整站優(yōu)化服務(wù)
  • 網(wǎng)站圖文列表seo優(yōu)化快排
  • 寧波網(wǎng)站建設(shè) 聯(lián)系哪家百度seo推廣免費
  • 網(wǎng)站開發(fā)的客戶群體淘寶新店怎么快速做起來
  • 查網(wǎng)站空間商seo是什么意思啊
  • 網(wǎng)站建設(shè)期任務(wù)及總結(jié)今日頭條號官網(wǎng)
  • 深圳市建筑工程佛山seo外包平臺
  • 網(wǎng)站開發(fā) 參考文獻seo網(wǎng)絡(luò)優(yōu)化招聘信息
  • wordpress 屏蔽白云百度seo公司
  • 微信怎么制作微電影網(wǎng)站深圳seo優(yōu)化seo優(yōu)化
  • 2018年網(wǎng)站建設(shè)免費拓客軟件
  • 滄州網(wǎng)站域名注冊服務(wù)公司seo網(wǎng)絡(luò)排名優(yōu)化技巧
  • 邢臺手機網(wǎng)站建設(shè)公司seo排名點擊軟件推薦
  • 視頻網(wǎng)站開發(fā)背景手機網(wǎng)站排名優(yōu)化
  • 基礎(chǔ)微網(wǎng)站開發(fā)口碑好seo基礎(chǔ)入門
  • 信譽好的武漢網(wǎng)站建設(shè)seo課培訓(xùn)
  • 怎么使用vs2017做網(wǎng)站關(guān)鍵詞排名怎么快速上去
  • 百度做的網(wǎng)站字體侵權(quán)百度一下百度主頁官網(wǎng)
  • 爐石做任務(wù)抽獎網(wǎng)站windows優(yōu)化大師下載安裝
  • WordPress潮流媒體主題sem推廣和seo的區(qū)別
  • 溫州市手機網(wǎng)站制作班級優(yōu)化大師官方免費下載
  • wordpress欄目圖片seo上排名
  • wordpress獨立博客免費seo視頻教程
  • 哲學專業(yè)特色建設(shè)網(wǎng)站谷歌搜索廣告優(yōu)化
  • 畢業(yè)論文做cad圖的網(wǎng)站江蘇網(wǎng)頁設(shè)計
  • 網(wǎng)站投訴平臺寧波seo快速排名
  • WordPress可以做社交網(wǎng)站嘛網(wǎng)絡(luò)平臺怎么創(chuàng)建
  • 溫州做網(wǎng)站設(shè)計網(wǎng)絡(luò)營銷類型有哪些