34. RunAs Authentication Replacement运行身份验证替换

在安全对象回调阶段,抽象安全接口AbstractSecurityInterceptor 能够临时替换安全上下文SecurityContextHolder 和安全上下文SecurityContext 容器中的身份验证对象Authentication 。只有当身份验证管理器AuthenticationManager 和访问决策管理器AccessDecisionManager成功处理了原始身份验证Authentication 对象时,才会发生这种情况。运行管理器RunAsManager 将指示在安全返回期间SecurityInterceptorCallback应该使用的替换身份验证对象(如果有)。

通过在安全对象回调阶段临时替换身份验证对象,安全调用将能够调用需要不同身份验证和授权凭证的其他对象。它还能够对特定的授权对象执行任何内部安全检查。由于Spring Security提供了许多基于SecurityContextHolder的内容自动配置远程处理协议的帮助器类,因此这些运行时替换在调用远程web服务时特别有用

原文地址:https://www.cnblogs.com/jrkl/p/13508527.html