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
实现了 RememberMeAuthenticationToken
和 HostAuthenticationToken
,能够实现“记住我”及“主机验证”的反对。
个别状况下UsernamePasswordToken
曾经能够满足咱们的大我数需要。当咱们遇到须要申明本人的Token类时,能够依据需要来实现AuthenticationToken
,HostAuthenticationToken
或RememberMeAuthenticationToken
。
- 如果不须要“记住我”,也不须要“主机验证”,则能够实现
AuthenticationToken
; - 如果须要“记住我”,则能够实现
RememberMeAuthenticationToken
; - 如果须要“主机验证”性能,则能够实现
HostAuthenticationToken
; - 如果须要“记住我”,且须要“主机验证”,则能够像
UsernamePasswordToken
一样,同时实现RememberMeAuthenticationToken
和HostAuthenticationToken
。 - 如果须要其余自定义性能,则须要本人实现。