Introduction to shiro tags

Here are the tags:
 

1.guest

 
 
  1. <@shiro.guest>
  2. You are currently a visitor, <a href="javascript:void(0);" class="dropdown-toggle qqlogin" >login</a>
  3. </@shiro.guest>
 

2.user (already logged in, or remember me logged in)

 
 
  1. <@shiro.user>
  2. Welcome [<@shiro.principal/>] to log in, <a href="/logout.shtml">logout</a>
  3. </@shiro.user>
 

3.authenticated (authenticated, excluding remember me logged in)

 
 
  1. <@shiro.authenticated>
  2.     User [<@shiro.principal/>] authenticated
  3. </@shiro.authenticated>
 

4.notAuthenticated (the opposite of authenticated)

 
 
  1. <@shiro.notAuthenticated>
  2. The current identity is not authenticated (including remember me logged in)
  3. </@shiro.notAuthenticated>
The main purpose of this function is to identify whether you have logged in this operation. For example, in the payment system, you can use remember my login information to enter the system, but when you want to perform key operations, you need to perform authentication and identification.
 

5.principal label, this should be a little more focused. A lot of blogs are taken at once.

 
The principal tag, the value is when you log in. The following code in the Realm implementation class:
 
  1. ....
  2. return new SimpleAuthenticationInfo(user,user.getPswd(), getName());
If the first parameter of new SimpleAuthenticationInfo (the first parameter, ....) is a username, it can be used directly.
 
  1. <!--Get username-->
  2. <@shiro. principal/>
If the first parameter is an object, for example, I like to put the User object. Then if you want to take the username field.
 
  1. <!-- need to specify property-->
  2. <@shiro.principal property="username"/>
Consistent with the following Java code in Java
 
  1. User user = (User)SecurityUtils.getSubject().getPrincipals();
  2. String username = user.getUsername();
 

6.hasRole label (to determine whether to have this role)

 
 
  1. <@shiro.hasRole name="admin">
  2.     User [<@shiro.principal/>] has role admin<br/>
  3. </@shiro.hasRole>
 

7.hasAnyRoles tag (to determine whether you have one of these roles)

 
 
  1. <@shiro.hasAnyRoles name="admin,user,member">
  2. User [<@shiro.principal/>] has role admin or user or member<br/>
  3. </@shiro.hasAnyRoles>
 

8.lacksRole label (judging whether you do not own this role)

 
 
  1. <@shiro.lacksRole name="admin">
  2. User [<@shiro.principal/>] does not have the admin role
  3. </@shiro.lacksRole>
 

9.hasPermission label (judging whether you have this permission)

 
 
  1. <@shiro.hasPermission name="user:add">
  2.     User [<@shiro.principal/>] has user:add permission
  3. </@shiro.hasPermission>
 

10.lacksPermission label (judging whether there is no such permission)

  1. <@shiro.lacksPermission name="user:add">
  2.     User [<@shiro.principal/>] does not have user:add permission
  3. </@shiro.lacksPermission>
 

 

11. Custom tabs.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326570425&siteId=291194637