spring-security(六)

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,passwordpermissions,用技术的角度上讲熟悉的称为Principal,CredentialsAuthorities:

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

猜你喜欢

转载自blog.csdn.net/u013887008/article/details/80934093