We configure the relationship of protected resources and permissions in ApplicationContext
< property name =" filterchaindefinitions " < value > /login.jsp= anon/shiro/login= Anon /shiro/logout = logout/user.jsp = Roles[user]/admin.jsp = roles [Admin] # Everything else requires authentication:/** = Aut HC </ value > </ property >
This configuration is sometimes especially true for our protected resources and permissions, and we want to put these configuration resources and permissions information in the database, and then we take them out in a SQL way, which should be the most appropriate.
We can view the source code of filterchaindefinitions in the configuration
Public voidsetfilterchaindefinitions (String definitions) {ini ini=NewIni (); Ini.load (Definitions); //did they explicitly state a ' URLs ' section? Not necessary, but just in case:Ini.section section =ini.getsection (Inifilterchainresolverfactory.urls); if(Collectionutils.isempty (section)) {//no URLs section. Since This _is_ a URLs chain definition property, just assume the//default section contains only the definitions:Section =ini.getsection (ini.default_section_name); } setfilterchaindefinitionmap (section); }
1 Public void Setfilterchaindefinitionmap (map<string, string> filterchaindefinitionmap) {2 This . filterchaindefinitionmap = Filterchaindefinitionmap; 3 }
By means of debug, you can see that at initialization, Filterchaindefinitionmap is a linkedhashmap, and the content is what we configure in the configuration file.
So we can configure a separate bean Filterchaindefinitionmap as the Shirofilterfactorybean property.
Modify Applicationcontext.xml
Create a Bean
Packagecom.java.shiro.factory;ImportJava.util.LinkedHashMap; Public classFilterchaindefinitionmapbuilder { PublicLinkedhashmap<string, string>Buildfilterchaindefinitionmap () {Linkedhashmap<string, string> map =NewLinkedhashmap<>(); //accessing data tables in real -world development
//Here must be a linkedhashmap hold order Map.put ("/login.jsp", "anon"); Map.put ("/**", "AUTHC"); returnmap; }}
Break again point to view
shiro-initializing resources and permissions from a data table