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. 如果须要其余自定义性能,则须要本人实现。