Spring+shiro Configure JSP permissions tag + role Tag + cache

Source: Internet
Author: User

Spring+shiro, let Shiro manage all rights, especially implement the permission point label in JSP page, each time open the page needs to read the database to see permissions, such a way to the database pressure is too large, using the cache can greatly reduce the amount of database access.

The following document Shiro the process of configuring the JSP permissions tag + role tag + cache:

1 First Configure SecurityManager in the configuration file XML.

<BeanID= "SecurityManager"class= "Org.apache.shiro.web.mgt.DefaultWebSecurityManager">        <!--Authentication Manager -        < Propertyname= "Realm"ref= "Permissionsrealm" />        <!--Cache Manager -        < Propertyname= "CacheManager"ref= "Shirocachemanager" />    </Bean>    <!--Authentication Manager Implementation Class -    <BeanID= "Permissionsrealm"class= "Com.soft.security.Realm.PermissionsRealm" />     <!--Cache Manager Implementation class, here is the system comes with the -    <BeanID= "Shirocachemanager"class= "Org.apache.shiro.cache.MemoryConstrainedCacheManager"   />    

2 Then, in the Permissionsrealm class, overriding the Dogetauthorizationinfo method, you need to do two things in the method: (1) Set the role (2) to set the permission point. The code is as follows:

New simpleauthorizationinfo (); Info.addrole ("role name"), Info.addstringpermission ("Privilege call");

3. At this point, the tag validation permission and role can be called in the JSP page.

At the top of the page, reference <% @taglib prefix= "Shiro" uri= "http://shiro.apache.org/tags"%> Tag Library,

Then write to the place where you want to trigger the permission point:

<name= "1111">       user has permission </Shiro: Haspermission>  

If the user has 1111 permissions, the user has permission is displayed, and if the test user has a role, the following tags are available:

<name= "admin">     User has role </shiro:hasrole  >

4. Because in 1, the configuration file has been configured in the cache manager, so every time the page opens, the background will only read the user role + permissions, followed by the cache, re-login after the cache automatically emptied.

Spring+shiro Configure JSP permissions tag + role Tag + cache

Related Article

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.