springMVC中快速配置shiro

2021-07-27 18:32:04 字數 1388 閱讀 1066

1.在web.xml檔案中配置shiro的過濾器,以攔截專案內的訪問

shirofilter

org.springframework.web.filter.delegatingfilterproxy

targetfilterlifecycle

true

shirofilter

/*

2.在spring 的配置檔案中配置shiro的相關項

/** = authc

3.在對應包下定義reaml(我在spring中配置的是com.bf.planner.realm.myrealm,所以我在com.bf.planner.realm包下新建了乙個myrealm類)

public class myrealm extends authorizingrealm

/*** 使用者登入

*/@override

protected authenticationinfo dogetauthenticationinfo(authenticationtoken token) throws authenticationexception else

}}

4.登入時使用shiro來驗證

@responsebody

public resultinfo login(user user)catch(exception e)

}5.使用shiro來控制方法的訪問許可權(例子):

@requiresroles(value=, logical = logical.or)

@requirespermissions(value = , logical = logical.and)

public void shiro_test()

上面的**中對shiro_test方法新增了訪問限制:

@requiresroles控制擁有admin或base角色的使用者可以訪問此方法

@requirespermissions控制擁有add和update許可權的使用者可以訪問此方法

6.頁面中使用shiro來控制頁面內容的顯示:

首先,需要在頁面頭部引入shiro支援:

<%@ taglib prefix="shiro" uri="" %>
然後,我們可以在頁面中使用shiro的標籤了:(當前登入使用者的使用者名稱【即登入賬號】)

歡迎有admin角色的使用者!

歡迎有student:create許可權的使用者!

注意:從資料庫中獲取的角色集合和許可權集合中不允許有空值

快速配置ZendFramwork

apache環境是ampserv5.2.6的整合環境 目前使用的是zendframwork1.10 1 建乙個test.com的虛擬目錄 2 開啟 apmserv5.2.6 apache conf apmserv vhost.conf,把test.com的 allowoverride 設為all 3...

快速配置BIND DNS

新裝的centos虛擬機器,先設定下機器名和ip vim etc sysconfig network vim etc sysconfig network scripts ifcfg eth0 yum安裝bind 其他關聯資料的東西就不用裝了,我們直接使用文字檔案 yum install bind b...

快速配置vim ctags cscope

配置vim是linux環境下開發的日常,這裡記錄如何快捷地配置好vim ctags cscope開發環境。外掛程式管理器 git clone vim bundle vundle.vimctags cscope 要使用這兩個功能,除了要配置vim外,還有安裝相應的軟體。sudo apt get ins...