相关疑难解决方法(0)

Struts2 + Spring Security 2.06:尝试在Action方法上使用@Secured时,Valuestack为null

在我开始之前,我要说的是我找到的最接近的答案就在这里,但说实话,我并不真正理解那里发生了什么.

我正在使用Struts2 + Spring Security 2.06与自定义身份验证提供程序和访问决策管理器来消除对"ROLE_"前缀的需求.

我的applicationContext-security.xml看起来像这样:

    <beans:bean id="customAuthenticationProvider"
                class="com.test.testconsole.security.CustomAuthenticationProvider">
        <beans:property name="userManagementService" ref="userManagementService"/>
        <custom-authentication-provider/>
    </beans:bean>

    <!--Customize Spring Security's access decision manager to remove need for "ROLE_" prefix-->
    <beans:bean
            id="accessDecisionManager"
            class="org.springframework.security.vote.AffirmativeBased">
        <beans:property name="decisionVoters">
            <beans:list>
                <beans:ref bean="roleVoter"/>
                <beans:ref bean="authenticatedVoter"/>
            </beans:list>
        </beans:property>
    </beans:bean>

    <beans:bean
            id="roleVoter"
            class="org.springframework.security.vote.RoleVoter">
        <beans:property name="rolePrefix" value=""/>
    </beans:bean>

    <beans:bean
            id="authenticatedVoter"
            class="org.springframework.security.vote.AuthenticatedVoter">
    </beans:bean>

<global-method-security secured-annotations="enabled" access-decision-manager-ref="accessDecisionManager"/>
Run Code Online (Sandbox Code Playgroud)

我的web.xml的相关部分:

    <!--Spring Security-->
<filter>
    <filter-name>springSecurityFilterChain</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>

<filter>
    <filter-name>struts2</filter-name>
    <filter-class>
        org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
    </filter-class>
</filter>

<!--Has to be placed _Before_ the struts2 filter-mapping-->
<filter-mapping>
    <filter-name>springSecurityFilterChain</filter-name>
    <url-pattern>/*</url-pattern> …
Run Code Online (Sandbox Code Playgroud)

java spring struts2 spring-security spring-annotations

39
推荐指数
1
解决办法
2454
查看次数

如何处理Spring Security更新中的defaultRolePrefix ="ROLE_"从3.2.7到4.0.2.RELEASE

我的Spring Boot应用程序可以运行Spring Security 3.2.7.RELEASE.现在,我想将其更新为4.0.2.RELEASE.

经过几个小时的调试后,我发现Spring Security 4.0.2.RELEASE使用了 defaultRolePrefix="ROLE_"

在

org.springframework.security.access.expression.SecurityExpressionRoot.hasAnyAuthorityName(String prefix, String... roles) 方法

在我的应用程序中,我使用没有此前缀的角色,因此我得到了AccessDeniedException.

如何配置Spring Boot才能使用SecurityExpressionRoot.defaultRolePrefix=""?

spring spring-security spring-boot

13
推荐指数
1
解决办法
3328
查看次数