源码注释
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(接口)
-
Subject save(Subject subject);
保存指定Subject的状态以供以后访问。如果不存在一个持久化的状态,则会在允许的情况下持久化它(即创建操作)。如果指定的{@code Subject}存在状态,则此方法更新现有状态以反映当前状态(即更新操作)。
即Subject不存在持久化状态就添加这个Subject持久化的状态,只会在Subject新建的时候发生;如果存在持久化状态,则会对这些持久化的状态进行更新。
-
void delete(Subject subject);
移除指定{@code Subject