Apache Shiro源码(SubjectDAO)

源码注释

A {@code SubjectDAO} is responsible for persisting a Subject instance's internal state such that the Subject instance can be recreated at a later time if necessary.
Shiro's default {@code SecurityManager} implementations typically use a {@code SubjectDAO} in conjunction with a {@link SubjectFactory}: after the {@code SubjectFactory} creates a {@code Subject} instance, the {@code SubjectDAO} is used to persist that subject's state such that it can be accessed later if necessary.
It should be noted that this component is used by {@code SecurityManager} implementations to manage Subject state persistence.  It does not make Subject instances accessible to the application (e.g. via {@link org.apache.shiro.SecurityUtils#getSubject() SecurityUtils.getSubject()}).

{@code SubjectDAO}负责持久化Subject实例的内部状态,以便在以后需要时可以重新创建Subject实例。

Shiro的默认{@code SecurityManager}实现通常使用{@code SubjectDAO}联同一个{@link SubjectFactory}在{@code SubjectFactory}创建一个{@code Subject}实例,在{@code SubjectDAO}用于持久化对象的状态。

需要注意的是,{@code SecurityManager}实现类使用SubjectDAO来管理Subject状态的持久性。它不能使Subject实例可被应用程序访问(例如通过{@link org.apache. shiros.securityutils #getSubject() SecurityUtils.getSubject()})。

其默认实现类为DefaultSubjectDAO。详细见Api

SubjectDAO API(接口)

  1. Subject save(Subject subject);

保存指定Subject的状态以供以后访问。如果不存在一个持久化的状态,则会在允许的情况下持久化它(即创建操作)。如果指定的{@code Subject}存在状态,则此方法更新现有状态以反映当前状态(即更新操作)。

即Subject不存在持久化状态就添加这个Subject持久化的状态,只会在Subject新建的时候发生;如果存在持久化状态,则会对这些持久化的状态进行更新。

  1. void delete(Subject subject);

移除指定{@code Subject

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值