apache shiro spring簡單整合

2021-06-08 01:57:51 字數 1148 閱讀 9440

1、apache shiro與spring整合

(1)、   需要匯入shiro-all.jar包;在web.xml中新增shiro過濾器:

shirofilter

org.springframework.web.filter.delegatingfilterproxy

targetfilterlifecycle

true

shirofilter/*

/index.jsp = anon

/login.jsp = authc

/course/** = authc, roles[admin]

(3)、登入系統時將頁面傳入的使用者名稱和密碼封裝到token中:

subject currentuser= securityutil.getsubject();獲取當前活動使用者資訊;

if(!currentuser.isauthenticated())

(4)、自定義realm類,該類需要繼承authorizingrealm,並重寫認證、授權方法:

@service

public class myrealm extends authorizingrealm

//授權

protected authorizationinfo dogetauthorizationinfo(principalcollection principalcollection) else

}/** * 更新使用者授權資訊快取. */

public void clearcachedauthorizationinfo(string principal)

//認證

protected authenticationinfo dogetauthenticationinfo(authenticationtoken token) throws authenticationexception

return null;}}

(5)、自定義加密類需要繼承******credentialsmather,並重寫docredentialsmatch方法;

@override

public boolean docredentialsmatch(authenticationtoken token,

authenticationinfo info)

簡單遞推錦集

1 走樓梯問題,乙個人剛開始站在第一級樓梯,每次可以走1級或者兩級,請問走到第n級樓梯有幾種走法?不容易系列之 3 lele 的rpg 難題有排成一行的 個方格,用紅 red 粉 pink 綠 green 三色塗每個格仔,每格塗一色,要求任何相鄰的方格不能同色,且首尾兩格也不同色 求全部的滿足要求的...

簡單並查集

哈爾濱理工大學oj 1160 吸血鬼 description remilia是 東方紅魔館 中首次亮相的吸血鬼角色,是有著500歲年齡的吸血鬼領主。作為紅魔館的主人,有著高貴和威嚴的氣質,不過也經常任性和孩子氣。關於吸血鬼有很多傳說。吸血鬼是乙個血族,有著嚴格的等級。吸血鬼會嚴格聽從血之主人的命令。...

LeetCode 簡單題目集

leetcode的問題有趣的地方在於人家直接給了乙個介面,相當於只需要寫了乙個函式就可以了,我是不知道多個呼叫函式會怎麼做。對於leetcode的刷題的方法,其實可以看看知乎就可以啦。這幾條意見也貼出來,對於未來的愉快的刷題有著很大的作用。一定在理清楚思路之後再去程式設計。我喜歡的乙個比喻就是,對於...