【问题标题】:Can't Integrate Spring Security and Web Logic 7无法集成 Spring Security 和 Web Logic 7
【发布时间】:2014-11-06 09:05:13
【问题描述】:

请在下面找到我将 Spring Security v3.2.5 与 Web Logic Server v7 集成的配置。

我试图在几个地方找到如何整合但没有运气。

当我使用以下配置运行我的应用程序时,我得到 " No AuthenticationProvider found for org.springframework.security.authentication.UsernamePasswordAuthenticationToken"

如果我们在配置中提到了“preAuthenticatedAuthenticationProvider”作为身份验证管理器的身份验证提供程序,对于 preAuthenticatedAuthenticationProvider 也提到了“preAuthenticatedUserDetailsS​​ervice”。

谁能帮我解决这个问题。

<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/security
       http://www.springframework.org/schema/security/spring-security.xsd">


<!-- web sphere configuration start -->

<http auto-config="false" use-expressions="true">
    <intercept-url pattern="/welcome*" access="permitAll" />
    <form-login login-page="/login" default-target-url="/welcome"
        authentication-failure-url="/loginfailed" />
    <custom-filter before="PRE_AUTH_FILTER" ref="webspherePreAuthFilter" />
    <logout logout-success-url="/logout" delete-cookies="JSESSIONID" />
    <session-management invalid-session-url="/logout">
        <concurrency-control max-sessions="1"
            error-if-maximum-exceeded="true" expired-url="/sessionexpired" />
    </session-management>
</http>

<beans:bean id="filterChainProxy"
    class="org.springframework.security.web.FilterChainProxy">
    <filter-chain-map path-type="ant">
        <!-- <filter-chain pattern="/**"
            filters="sif,webspherePreAuthFilter,logoutFilter,etf,fsi" /> -->
        <filter-chain pattern="/welcome*"
            filters="webspherePreAuthFilter,logoutFilter,etf,fsi" />
    </filter-chain-map>
</beans:bean>

<authentication-manager alias="authenticationManager">
    <authentication-provider ref="preAuthenticatedAuthenticationProvider" />
</authentication-manager>

<beans:bean id="preAuthenticatedAuthenticationProvider"
    class="org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationProvider">
    <beans:property name="preAuthenticatedUserDetailsService"
        ref="preAuthenticatedUserDetailsService" />
</beans:bean>


<beans:bean id="preAuthenticatedUserDetailsService"
    class="org.springframework.security.web.authentication.preauth.PreAuthenticatedGrantedAuthoritiesUserDetailsService" />

<!-- This AbstractPreAuthenticatedProcessingFilter implementation is based 
    on WebSphere authentication. It will use the WebSphere RunAs user principal 
    name as the pre-authenticated principal. -->


<beans:bean id="webspherePreAuthFilter"
    class="org.springframework.security.web.authentication.preauth.websphere.WebSpherePreAuthenticatedProcessingFilter">
    <beans:property name="authenticationManager" ref="authenticationManager" />
    <beans:property name="authenticationDetailsSource" ref="authenticationDetailsSource" />
</beans:bean>


<beans:bean id="authenticationDetailsSource"
    class="org.springframework.security.web.authentication.preauth.websphere.WebSpherePreAuthenticatedWebAuthenticationDetailsSource">
    <beans:property name="webSphereGroups2GrantedAuthoritiesMapper"
        ref="websphereUserGroups2GrantedAuthoritiesMapper" />
</beans:bean>

<beans:bean id="websphereUserGroups2GrantedAuthoritiesMapper"
    class="org.springframework.security.core.authority.mapping.SimpleAttributes2GrantedAuthoritiesMapper">
    <beans:property name="convertAttributeToUpperCase"
        value="true" />
</beans:bean>

<beans:bean id="preAuthenticatedProcessingFilterEntryPoint"
    class="org.springframework.security.web.authentication.Http403ForbiddenEntryPoint" />

<beans:bean id="logoutFilter"
    class="org.springframework.security.web.authentication.logout.LogoutFilter">
    <beans:constructor-arg value="/" />
    <beans:constructor-arg>
        <beans:list>
            <beans:bean
                class="org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler" />
        </beans:list>
    </beans:constructor-arg>
</beans:bean>

<beans:bean id="etf"
    class="org.springframework.security.web.access.ExceptionTranslationFilter">
    <beans:property name="authenticationEntryPoint"
        ref="preAuthenticatedProcessingFilterEntryPoint" />
</beans:bean>

<beans:bean id="fsi"
    class="org.springframework.security.web.access.intercept.FilterSecurityInterceptor">
    <beans:property name="authenticationManager" ref="authenticationManager" />
    <beans:property name="accessDecisionManager" ref="httpRequestAccessDecisionManager" />
    <beans:property name="securityMetadataSource">
        <filter-security-metadata-source>
            <intercept-url pattern="/welcome*" access="ROLE_LDP_ADMINS" />
        </filter-security-metadata-source>
    </beans:property>
</beans:bean>

<beans:bean id="httpRequestAccessDecisionManager"
    class="org.springframework.security.access.vote.AffirmativeBased">
    <beans:property name="allowIfAllAbstainDecisions"
        value="false" />
    <beans:property name="decisionVoters">
        <beans:list>
            <beans:ref bean="roleVoter" />
        </beans:list>
    </beans:property>
</beans:bean>

<beans:bean id="roleVoter"
    class="org.springframework.security.access.vote.RoleVoter" />


<!-- web sphere configuration ends -->

【问题讨论】:

    标签: java spring spring-security weblogic


    【解决方案1】:

    您的配置中包含form-login,这将创建UsernamePasswordAuthenticationToken 并将其提交给身份验证管理器。但是,后者只有一个PreAuthenticatedAuthenticationProvider,无法处理这种类型的身份验证,因此出现错误。

    您需要添加一个AuthenticationProvider,它可以处理用户名/密码验证。

    此外,您似乎混合了命名空间配置和显式 bean 配置。您应该选择其中一个 - 很难弄清楚您发布的示例中实际使用了什么。

    【讨论】:

    • 我在发帖前尝试了你提到的方法,一切似乎都正常,除了我无法解码密码。我们删除了安全部分并使用 WebSphere 进行了基本身份验证,然后重定向到应用程序中的其他页面。我有一些时间对此进行一些研发,我会尽快发布我的结果。感谢您的投入。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-04-07
    • 2015-05-27
    • 1970-01-01
    • 2023-01-30
    • 2014-10-24
    • 2011-09-14
    • 2012-11-14
    相关资源
    最近更新 更多