RequiresAuthentication

@RequiresAuthentication

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

@RequiresUser

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

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

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

@RequiresGuest

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

换言之,RequiresUser  == !RequiresGuest。

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

@RequiresRoles

例如:@RequiresRoles("aRoleName");

void someMethod();

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

@RequiresPermissions

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

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

时间: 2024-08-28 05:37:04

RequiresAuthentication的相关文章

NancyFx 2.0的开源框架的使用-Authentication

新建一个空的项目 新建好了空的项目以后,接着通过NuGet安装一下三个包 Nancy Nancy.Hosting.Aspnet Nancy.ViewEnglines.Razor 然后在项目中添加Models,Module,Views三个文件夹,并在Models中添加UserModel类 public string Username { get; set; } public UserModel(string username) { this.Username = username; } 然后往Mo

细说shiro之五:在spring框架中集成shiro

官网:https://shiro.apache.org/ 1. 下载在Maven项目中的依赖配置如下: <!-- shiro配置 --> <dependency> <groupId>org.apache.shiro</groupId> <artifactId>shiro-core</artifactId> <version>${version.shiro}</version> </dependency&g

REST Security with JWT using Java and Spring Security

Security Security is the enemy of convenience, and vice versa. This statement is true for any system, virtual or real, from the physical house entrance to web banking platforms. Engineers are constantly trying to find the right balance for the given

Nancy FormsAuthentication使用

1.新建UserDatabase类,实现IUserMapper接口 using System; using System.Collections.Generic; using System.Linq; using System.Security.Claims; using System.Security.Principal; using Nancy.Authentication.Forms; public class UserDatabase : IUserMapper { private st

ABP 初探 之 权限设计

大.小项目都要设计权限,都想设计一个通用的权限,把权限做的比较复杂,现在了解了ABP的设计思路,觉得设计很简单,但实现方法与思路耐人寻味. 本篇只介绍AbpPermissions的数据库设计,其它表结构参考源代码即可[Name(资源文件唯一Id)].[IsGranted(是否授权)].[RoleId.UserId(授权于角色或用户)] ABP所有常量数据,都是程序启动时通过AbpKernelModule一次性加载完成,用的时候直接从内存中读取即可 public override void Pos

NancyFx 2.0的开源框架的使用-Basic

这是NancyFx开源框架中的Basic认证,学习一下! 首先当然是新建一个空的Web,BasicDemo 继续在项目中添加Nuget包,记得安装的Nuget包是最新的预发行版 Nancy Nancy.Authentication.Basic Nancy.Hosting.Aspnet 之后就往项目中添加Models文件夹和Module文件夹,然后往Models文件夹里面添加UserValidator类 public ClaimsPrincipal Validate(string username

Shiro启用注解方式

shiro验证权限方式一种是基于url配置文件: 例如: <bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean"> <property name="securityManager" ref="securityManager"/> <!-- 登录页面 ,用户 登录不成功自动 返回该页面 --&

Apache Shiro 使用手册(三)Shiro 授权

授权即访问控制,它将判断用户在应用程序中对资源是否拥有相应的访问权限. 如,判断一个用户有查看页面的权限,编辑数据的权限,拥有某一按钮的权限,以及是否拥有打印的权限等等. 一.授权的三要素 授权有着三个核心元素:权限.角色和用户. 权限 权限是Apache Shiro安全机制最核心的元素.它在应用程序中明确声明了被允许的行为和表现.一个格式良好的权限声明可以清晰表达出用户对该资源拥有的权限. 大多数的资源会支持典型的CRUD操作(create.read.update.delete),但是任何操作

abp添加动态菜单

abp中MenuDefinition封装了导航栏上的主菜单的属性,MenuItemDefinition则封装了子菜单的属性,子菜单可以引用其他子菜单构成一个菜单树. MenuDefinitio成员如下: public object CustomData { get; set; }//自定义数据 public ILocalizableString DisplayName { get; set; }//表示本地化字符串 public IList<MenuItemDefinition> Items