spring-security(六)
摘自《pro spring security》基于spring security 4.2.2.RELEASE
认证对象(The Authentication Object)
Authentication object
就是登陆到系统的对象的一种抽象。大体来讲,像用户(user),通常只有用户需要认证。Authentication object
在spring security框架中有一些默认的实现类。
一般的,在创建认证请求的时候就会使用到Authentication object
,携带了不同层次和类的在这框架中的请求数据,当校验通过,这个Authentication object
又包含了已经认证过实体的信息,并且将它存储在SecurityContext
上下文中。通常情况下,当你登陆到一个应用的时候,这个Authentication object
会被创建,并且存储了你的username
,password
和permissions
,用技术的角度上讲熟悉的称为Principal
,Credentials
和Authorities
:
public interface Authentication extends Principal, Serializable {
Collection<? extends GrantedAuthority> getAuthorities();
Object getCredentials();
Object getDetails();
Object getPrincipal();
boolean isAuthenticated();
void setAuthenticated(boolean isAuthenticated) throws IllegalArgumentException;
}
- UsernamePasswordAuthenticationToken.:: 一种简单的实现,顾名思义,这个类包含了用户名和密码,也是系统中最普遍的
Authentication
接口的实现,像AuthenticationProvider
大多是直接依赖这个类 - PreAuthenticatedAuthenticationToken: 这个是为了预认证
Authentication objects
而存在的。预认证的过程实际上是外部系统认证的过程,spring security
仅仅是给外部系统提供解析用户身份(Principal)信息 - RunAsUserToken: 通常是在
Security Interceptor
中的RunAsManager
才会使用到,是因为访问资源所包含的ConfigAttribute
中是RUN_AS_
为前缀的,如果确实包含了这个值,RunAsManager
会根据RUN_AS
的值给认证的用户创建GrantedAuthorities