shiro控制登入訪問許可權

2021-09-29 15:09:41 字數 1932 閱讀 5940

步驟:

1.在web.xml中配置

2.在spring-mvc中配置

3.建立兩個實體類 :(在web層建立)

實體類一:  authrealm   繼承shrio包中的類   authorizingrealm , authorizingrealm是realm的實現類之一

實體類二: customcredentialsmatcher  繼承   ******credentialsmatcher

4.在登入方法編寫登入**  --> 在authrealm編寫**   -->   在customcredentialsmatcher 編寫**

1.在web.xml中配置 , 官網copy ,不做修改

shirofilter

org.springframework.web.filter.delegatingfilterproxy

targetfilterlifecycle

true

/*

2.在spring-mvc中配置如下**

注:實體類路徑需要根據實體類位置稍作修改

/system/module/list.do = perms["模組管理"]

/index.jsp* = anon

/login.jsp* = anon

/login* = anon

/logout* = anon

/css/** = anon

/img/** = anon

/plugins/** = anon

/make/** = anon

/** = authc,user

/*.* = authc

3.建立兩個實體類 :

實體類一:  authrealm   繼承shrio包中的類   authorizingrealm , authorizingrealm是realm的實現類之一

public class authrealm extends authorizingrealm 

//構建shiro需要的許可權資料

******authorizationinfo ******authorizationinfo = new ******authorizationinfo();

******authorizationinfo.setstringpermissions(set);

return ******authorizationinfo;

}@override

protected authenticationinfo dogetauthenticationinfo(authenticationtoken token) throws authenticationexception else

}}

實體類二: customcredentialsmatcher  繼承   ******credentialsmatcher

注:**中我使用md5的加密方式 , 加密方式可以更換

public class customcredentialsmatcher  extends ******credentialsmatcher 

}

4.登入方法

public string login(string email,string password)

try catch (exception e)

注:第三步中使用到的md5的加密工具類 , 參考

public class encrypt 

}

shiro許可權控制簡介

最近專案中用到了shrio許可權控制,因此抽出一定的時間了解了一下他的使用方式和原理,同springsecurity的方式一樣,使用shiro許可權控制,主要包括了三個重要的組成部分 user,permission,role即使用者,許可權,和角色,其中,使用者和許可權,角色之間是一對多的,許可權和...

Shiro的許可權控制

requirespermissions 許可權的攔截,對應使用者的許可權列表。logical是各 個許可權的關係,or是滿足乙個就行,and是都得滿足 requiresroles 角色的攔截,對應使用者的角色 role requirespermissions value logical logica...

Shiro登入及許可權管理

github位址 使用shiro springboot mybatis實現簡單的登入和許可權管理,使用自定義許可權註解實現許可權管理。資料庫表user 欄位名示例id1 username 1password 1資料庫表auth 欄位名示例id1 username 1role user permiss...