TestingAuthenticationToken(位于org.springframework.security.authentication),第一次看到这类名感觉就是用于测试认证使用的类,看了看源码确实没有多少东西:
public class TestingAuthenticationToken extends AbstractAuthenticationToken {
// 序列号id
private static final long serialVersionUID = 1L;
// 一般指密码
private final Object credentials;
// 一般指用户名
private final Object principal;
// 构造器
// principal
// credentials
public TestingAuthenticationToken(Object principal, Object credentials) {
// 初始化父类构造器
super((Collection)null);
this.principal = principal;
this.credentials = credentials;
}
// 构造器
public TestingAuthenticationToken(Object principal, Object credentials, String... authorities) {
this(principal, credentials, AuthorityUtils.createAuthorityList(authorities));
}
// 构造器
// principal
// credentials
// authorities
public TestingAuthenticationToken(Object principal, Object credentials, List<GrantedAuthority> authorities) {
// 初始化父类权限构造器
super(authorities);
this.principal = principal;
this.credentials = credentials;
// 将父类已认证状态改为true
this.setAuthenticated(true);
}
public Object getCredentials() {
return this.credentials;
}
public Object getPrincipal() {
return this.principal;
}
}
看了几个认证方式的实现类都会有基本的两个构造器,一个初始化已认证状态为false,默认父类就是false,一个初始化已认证状态为true,感觉一个就是认证前调用存储待认证用户信息,另一个是认证成功后跟新当前用户信息。