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