shiro學習摘錄(二)

2021-07-10 20:56:18 字數 2166 閱讀 6824

shiro內建***。預設***可參考org.apache.shiro.web.filter.mgt.defaultfilter中的列舉***。

預設***名

***類

說明(括號裡的表示預設值)

身份驗證相關的

使用者***,使用者已經身份驗證/記住我登入的都可;示例「/**=user」

anon

org.apache.shiro.web.filter.authc.anonymousfilter

匿名***,即不需要登入即可訪問;一般用於靜態資源過濾;例「/static/**=anon」

授權相關的

roles

org.apache.shiro.web.filter.authz.rolesauthorizationfilter

角色授權***,驗證使用者是否擁有所有角色;主要屬性: loginurl:登入頁面位址(/login.jsp);unauthorizedurl:未授權後重定向的位址;例「/admin/**=roles[admin]」

perms

org.apache.shiro.web.filter.authz.permissionsauthorizationfilter

許可權授權***,驗證使用者是否擁有所有許可權;屬性和roles 一樣;例「/user/**=perms[「user:create」]」

port

org.apache.shiro.web.filter.authz.portfilter

埠***,主要屬性:port(80):可以通過的埠;示例「/test= port[80]」,如果使用者訪問該頁面是非80,將自動將請求埠改為80 並重定向到該80 埠,其他路徑/引數等都一樣

rest 風格***,自動根據請求方法構建許可權字串( get=read,post=create,put=update,delete=delete,head=read,trace=read,options=read, mkcol=create)構建許可權字串;示例「/users=rest[user]」,會自動拼出「user:read,user:create,user:update,user:delete」許可權字串進行許可權匹配(所有都得匹配,ispermittedall);

sslorg.apache.shiro.web.filter.authz.sslfilter

ssl ***,只有請求協議是https 才能通過;否則自動跳轉會https埠(443);其他和port***一樣;

其他

nosessioncreation

org.apache.shiro.web.filter.session.nosessioncreationfilter

不建立會話***,呼叫subject.getsession(false)不會有什麼問題,但是如果subject.getsession(true)將丟擲disabledsessionexception異常;

另外還提供了乙個org.apache.shiro.web.filter.authz.hostfilter,即主機***,

比如其提供了屬性:authorizedips:已授權的ip 位址,deniedips:表示拒絕的ip 位址;不過目前還沒有完全實現,不可用。

這些預設的***會自動註冊,可以直接在ini 配置檔案中通過「***名.屬性」設定其屬性:

perms.unauthorizedurl=/unauthorized

另外如果某個***不想使用了可以直接通過如下配置直接禁用:

perms.enabled=false

shiro入門學習二

shiro是 apache 的乙個開源框架,是乙個許可權管理的框架,實現 使用者認證 使用者授權。spring中有 spring security 原名acegi 是乙個許可權框架,它和 spring 依賴過於緊密,沒有 shiro 使用簡單。shiro不依賴於 spring shiro 不僅可以實...

Shiro學習筆記(二)

基於shiro 使用ssm框架 進行使用者,角色,許可權維護和管理一套 在ssm框架中,需要許可權,寫註解 requirepermission就行。但是,真正專案開發的時候,這種方式就很有侷限性了,當許可權配置關係發生變化,每次都要修改 編譯打包重啟系統,這肯定是不能夠被接受的。所以,最好的方式,還...

shiro學習 二 入門認證

使用 test 完成最基本簡單的認證流程。1 建立 securitymanager 2 主體 subject 提交請求 3 securitymanager 認證 4 authenticator 認證 5 realm 驗證 org.apache.shiro shiro core 1.6.0 junit...