認証を管理するために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>