shiro安全框架

2021-10-07 18:02:21 字數 2129 閱讀 3370

依賴

org.apache.shiro

shiro-spring

1.5.3

攔截配置

建立config類

package com.cy.pj.common.config;

/**@configuration 註解描述的類為乙個配置物件,

* 此物件也會交給spring管理

*/@configuration

public

class

springshiroconfig

新增securitymanager配置類

@bean

public securitymanager securitymanager()

新增shirofilte***ctorybean物件的配置

@bean

public shirofilte***ctorybean shirofilte***ctory (

securitymanager securitymanager)

認證配置

認證流程

系統呼叫subject的login方法將使用者資訊提交給securitymanager

securitymanager將認證操作委託給認證器物件authenticator

authenticator將使用者輸入的身份資訊傳遞給realm。

realm訪問資料庫獲取使用者資訊然後對資訊進行封裝並返回。

authenticator 對realm返回的資訊進行身份認證。

dao層根據情況(簡略)

homeworkentity finduserbyusername

(string username)。

realm繼承authorizingrealm–完成認證(授權暫時沒寫)

@component

public

class

userrealm

extends

authorizingrealm

@override

protected authenticationinfo dogetauthenticationinfo

(authenticationtoken token)

throws authenticationexception

******authenticationinfo info =

new******authenticationinfo(""

, entity.

getpassword()

,"");

return info;

}}

controlle層(

"/")

@responsebody

public jsonresult dologin

(homeworkentity entity)

catch

(unknownaccountexception e)

catch

(incorrectcredential***ception e)

//分析:

//1)token會傳給shiro的securitymanager

//2)securitymanager將token傳遞給認證管理器

//3)認證管理器會將token傳遞給realm

//return new jsonresult("login ok");

}securitymanager配置類修改

@bean

public securitymanager securitymanager

(userrealm realm)

以上是對shiro的安全框架–攔截與認證的主要實現、授權暫時沒有(前端很簡單根據情況而定)

shiro安全框架

shiro安全框架是目前為止作為登入註冊最常用的框架,因為它十分的強大簡單,提供了認證 授權 加密和會話管理等功能 shiro能做什麼?認證 驗證使用者的身份 授權 對使用者執行訪問控制 判斷使用者是否被允許做某事 會話管理 在任何環境下使用 session api,即使沒有 web 或ejb 容器...

Shiro安全框架

subject sub securityutils.getsubject usernamepasswordtoken token newusernamepasswordtoken username,password sub.login token requiresguest 驗證是否是乙個guest...

Shiro安全框架

shiro是apache旗下乙個開源安全框架,它將軟體系統的安全認證相關的功能抽取出來,實現使用者身份認證,許可權授權 加密 會話管理等功能,組成了乙個通用的安全認證框架。使用shiro就可以非常快速的完成認證 授權等功能的開發,降低系統成本。shiro安全框架 在概念層面,shiro 架構包含三個...