shiro-initializing resources and permissions from a data table

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.