Spring Security RunAsManagerImpl不';行不通

Spring Security RunAsManagerImpl不';行不通,spring,spring-security,spring-boot,Spring,Spring Security,Spring Boot,我有Bean_1,它从Bean_2调用方法。Bean_1具有以下安全配置: <protect-pointcut expression="execution(* com.proficiency.cg.core.blc.Bean_1.*.*(..))" access="ROLE_Administrators,RUN_AS_InternalRole"/> Bean_2-具有以下安全配置: <protect-pointcut expression="execution(*

我有Bean_1,它从Bean_2调用方法。Bean_1具有以下安全配置:

    <protect-pointcut expression="execution(* com.proficiency.cg.core.blc.Bean_1.*.*(..))" access="ROLE_Administrators,RUN_AS_InternalRole"/>

Bean_2-具有以下安全配置:

<protect-pointcut expression="execution(* com.proficiency.cg.core.blc.Bean_2.*.*(..))" access="ROLE_InternalRole"/>

另外,我设置了RunAsManager:

<b:bean id="runAsManager"
    class="org.springframework.security.access.intercept.RunAsManagerImpl">
  <b:property name="key" value="prof_key"/>
</b:bean>

<b:bean id="runAsAuthenticationProvider"
    class="org.springframework.security.access.intercept.RunAsImplAuthenticationProvider">
  <b:property name="key" value="prof_key"/>
</b:bean>

<global-method-security secured-annotations="enabled" run-as-manager-ref="runAsManager" authentication-manager-ref="authenticationManager">

当我运行我的测试程序时,我在访问Bean_2时遇到安全异常。
结论:RunAsManager-无法正常工作或出现环礁

好的。看起来RunAsManager有一个bug。调试时-我在原始RunAsManagerImpl的实现中发现以下内容:

public Authentication buildRunAs(Authentication authentication, Object object,
        Collection<ConfigAttribute> attributes) {
    List<GrantedAuthority> newAuthorities = new ArrayList<GrantedAuthority>();

    for (ConfigAttribute attribute : attributes) {
        if (this.supports(attribute)) {
            GrantedAuthority extraAuthority = new SimpleGrantedAuthority(
                    getRolePrefix() + attribute.getAttribute());
            newAuthorities.add(extraAuthority);
        }
    }
public Authentication buildRunAs(身份验证、对象、,
集合属性){
List newAuthorities=new ArrayList();
用于(配置属性:属性){
if(this.supports(属性)){
授权权限extraAuthority=新的SimpleGrantedAuthority(
getRolePrefix()+attribute.getAttribute());
新增权限。添加(临时权限);
}
}
一切看起来都很好,但是。。。 此方法运行所有属性(角色\u管理员、运行\u作为\u内部角色),并检查字符串是否以“运行\u作为\u内部角色”开头。
如果是-(this.supports(…)-创建新的授权机构(getRolePrefix()+attribute.getAttribute())。
一切都很好,但是getRolePrefix()返回“ROLE”。事实上,它创建了新的授权,例如:ROLE\u RUN\u AS\u InternalRole,但它不存在!
作为解决方案,我创建了自己的RunAsManagerImpl,它覆盖了这个方法,并在创建新的授权之前从属性中删除了“RUN_As”
我希望这将在下一版本中修复