关于java:shiro源码解析

8次阅读

共计 1085 个字符,预计需要花费 3 分钟才能阅读完成。

AuthenticationToken

Shiro 中的 AuthenticationToken
AuthenticationToken 用于收集用户提交的身份(如用户名)及凭据(如明码)。Shiro 会调用 CredentialsMatcher 对象的 doCredentialsMatch 办法对 AuthenticationInfo 对象和 AuthenticationToken 进行匹配。匹配胜利则示意主体(Subject)认证胜利,否则示意认证失败。

public interface AuthenticationToken extends Serializable {Object getPrincipal(); // 身份
    Object getCredentials(); // 凭据}

public interface HostAuthenticationToken extends AuthenticationToken {String getHost();// 获取用户“主机”}

public interface RememberMeAuthenticationToken extends AuthenticationToken {boolean isRememberMe();// 记住我
}

Shiro 仅提供了一个能够间接应用的 UsernamePasswordToken,用于实现基于用户名 / 明码主体(Subject)身份认证。UsernamePasswordToken实现了 RememberMeAuthenticationTokenHostAuthenticationToken,能够实现“记住我”及“主机验证”的反对。
个别状况下 UsernamePasswordToken 曾经能够满足咱们的大我数需要。当咱们遇到须要申明本人的 Token 类时,能够依据需要来实现 AuthenticationTokenHostAuthenticationTokenRememberMeAuthenticationToken

  1. 如果不须要“记住我”,也不须要“主机验证”,则能够实现AuthenticationToken
  2. 如果须要“记住我”,则能够实现RememberMeAuthenticationToken
  3. 如果须要“主机验证”性能,则能够实现HostAuthenticationToken
  4. 如果须要“记住我”,且须要“主机验证”,则能够像 UsernamePasswordToken 一样,同时实现 RememberMeAuthenticationTokenHostAuthenticationToken
  5. 如果须要其余自定义性能,则须要本人实现。
正文完
 0