1

認証を管理するためにSpringSecurityを使用するWebアプリケーションがあります。私のクライアントには2つのログインフォームがあります。私の春のセキュリティ設定は次のとおりです。

<http auto-config="true" use-expressions="true" create-session="always">
        <intercept-url pattern="/**"  access="permitAll" />

        <form-login login-processing-url="/user/login" login-page="/user/login/unauthorized" 
            default-target-url="/user/firstLogin" authentication-failure-url="/user/login/failure" />

        <form-login login-processing-url="/user/relogin" login-page="/user/login/unauthorized" 
            default-target-url="/user/reLoginFromClient" authentication-failure-url="/user/login/failure" />

        <logout logout-url="/user/logout/spring" logout-success-url="/user/logout/success" />
        <access-denied-handler ref="accessDeniedHandler"/>
    </http>

/user/login最初のform-login要素は正常に機能します。つまり、 URLからログインできます。ただし、2番目のURLからログインしようとすると/user/relogin、サーバーから415:unsupportedmediatype応答が返されます。

2つの要素を切り替えると、上にあるものは正常に機能し、下にあるものは415応答になることに注意してください。

選択した回答で提案されているように実行しましたが、構成は次のようになります。

<http auto-config="true" use-expressions="true" create-session="always" authentication-manager-ref="authenticationManager">
        <intercept-url pattern="/**"  access="permitAll" />
        <custom-filter after="SECURITY_CONTEXT_FILTER" ref="reLoginFilter"/>
        <form-login login-processing-url="/user/login" login-page="/user/login/unauthorized" 
            default-target-url="/user/firstLogin" authentication-failure-url="/user/login/failure" />
        <logout logout-url="/user/logout/spring" logout-success-url="/user/logout/success" />
        <access-denied-handler ref="accessDeniedHandler"/>  
    </http>

    <beans:bean id="reLoginFilter" class="org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter">
        <beans:property name="authenticationManager" ref="authenticationManager"/>
        <beans:property name="filterProcessesUrl" value="/user/relogin"/>
        <beans:property name="authenticationSuccessHandler" ref="authenticationSuccessHandler" />
        <beans:property name="authenticationFailureHandler" ref="authenticationFailHandler" />
    </beans:bean> 

    <beans:bean id="authenticationSuccessHandler" class="org.springframework.security.web.authentication.SimpleUrlAuthenticationSuccessHandler">
        <beans:property name="defaultTargetUrl" value="/user/relogin/success"/>
    </beans:bean>

    <beans:bean id="authenticationFailHandler" class="org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler">
        <beans:property name="defaultFailureUrl" value="/user/login/failure"/>
    </beans:bean>
4

1 に答える 1

1

<form-login>1つの要素内で複数の要素を使用することはできません<http>

UsernamePasswordAuthenticationFilter代わりに、 Beanを定義し、custom-filter要素を使用してそれを挿入することにより、1つを使用して2つ目を追加することができます。

また、おそらくを削除する必要がありauto-configます。リクエストごとにセッションを作成する必要があることもめったにないので、create-session必要であることが確実でない限り、属性も削除します。

于 2013-02-25T16:56:40.463 に答える