Shiro 权限注解
4年前
Shiro提供了相应的注解用于权限控制,如果使用这些注解就需要使用AOP的功能来进行判断,如Spring AOP;
Shiro提供了Spring AOP集成用于权限注解的解析和验证。
@RequiresAuthentication
表示当前Subject已经通过login 进行了身份验证;即Subject.isAuthenticated()返回true。
@RequiresUse
表示当前Subject已经身份验证或者通过记住我登录的。
@RequiresGuest
表示当前Subject没有身份验证或通过记住我登录过,即是游客身份。
@RequiresRoles(value = {"admin", "user"}, logical = Logical.AND)
@RequiresRoles(value = {"admin"})
@RequiresRoles({"admin"})
表示当前Subject需要角色admin 和user。
@RequiresPermissions (value={“user:a”, “user:b”}, logical= Logical.OR)
表示当前Subject需要权限user:a或user:b。
Shiro的认证注解处理是有内定的处理顺序的,如果有多个注解的话,前面的通过了会继续检查后面的,若不通过则直接返回,处理顺序依次为(与实际声明顺序无关)
- RequiresRoles
- RequiresPermissions
- RequiresAuthentication
- RequiresUser
- RequiresGuest
以上注解既可以用在controller中,也可以用在service中使用;
建议将shiro注解放在controller中,因为如果service层使用了spring的事物注解,那么shiro注解将无效。
autosalonobman.ru
Get millions of immediate leads for your business to jumpstart your promotion. Utilize the lists an unrestricted amount of times. We have been providing businesses and market research firms with data since 2012. Email Marketing
Thanks for the post
interesting news
interesting news
interesting news
Hello from Sporthappy.
Вижте и страницата ми
=3345re=
Ad fontes — К первоисточникам.
Wedding Invitations, Wedding Video Invitation, Short Video Itvitation, Save the Date, Wedding Backdrop, Wedding Day Slideshow, Wedding Signs - Small
Hello from Happykiddi.