shiro的注解及标签说明

@RequiresAuthentication

验证用户是否登录,等同于方法subject.isAuthenticated() 结果为true时。

@RequiresUser

验证用户是否被记忆,user有两种含义:

一种是成功登录的(subject.isAuthenticated() 结果为true);

另外一种是被记忆的(subject.isRemembered()结果为true)。

@RequiresGuest

验证是否是一个guest的请求,与@RequiresUser完全相反。

 换言之,RequiresUser  == !RequiresGuest

此时subject.getPrincipal() 结果为null.

@RequiresRoles

扫描二维码关注公众号,回复: 4650448 查看本文章

例如:@RequiresRoles("aRoleName");

  void someMethod();

如果subject中有aRoleName角色才可以访问方法someMethod。如果没有这个权限则会抛出异常AuthorizationException

@RequiresPermissions

例如: @RequiresPermissions({"file:read", "write:aFile.txt"} )
  
void someMethod();

要求subject中必须同时含有file:readwrite:aFile.txt的权限才能执行方法someMethod()。否则抛出异常AuthorizationException


标签说明:
  1. <shiro:authenticated> 登录之后  
    <shiro:notAuthenticated> 不在登录状态时  
    <shiro:guest> 用户在没有RememberMe时  
    <shiro:user> 用户在RememberMe时  
    <shiro:hasAnyRoles name="abc,123" > 在有abc或者123角色时  
    <shiro:hasRole name="abc"> 拥有角色abc  
    <shiro:lacksRole name="abc"> 没有角色abc  
    <shiro:hasPermission name="abc"> 拥有权限abc  
    <shiro:lacksPermission name="abc"> 没有权限abc  
    <shiro:principal> 显示用户登录名
 

猜你喜欢

转载自blog.csdn.net/lyz_112233/article/details/70053355