0

「ログインに失敗しました」や「内部システム エラー」など、さまざまなログイン エラー メッセージを表示しようとしています。または、別のページにリダイレクトする機能さえあるかもしれません。ここで行われたことに従おうとしましたhttp://www.codemarvels.com/2010/12/spring-security-3-how-to-display-login-errors/フォームログインタグがないことを除いて、そのため、authentication-failure-handler-ref をページに表示されるように設定できませんでした。ただし、UsernamePasswordAuthenticationFilter を拡張するだけのカスタム クラスである FORM_LOGIN_FILTER に authenticationFailureHandler (ExceptionMappingAuthenticationFailureHandler を使用するため) を設定しました。

ここで何が欠けていますか?

EDIT-09/19/2013: デバッグを少し行いましたが、間違った質問をしています。うまく機能しているようです。ただし、複数の認証プロバイダーがあり、最初のプロバイダーの例外が 2 番目の例外で上書きされます。基本的に、スローされるDBダウン例外をシミュレートしようとしていますが、アクティブディレクトリに対する認証が試行され、ユーザーが見つかりません。したがって、AuthenticationServiceException を取得できません。

この時点での私の質問は、プロバイダーの順序を変更せずに最初のスティックから例外を作成する方法だと思います (DB プロバイダーは大多数のユーザーに使用されます)。

<http pattern="/**"  authentication-manager-ref='testAuthenticationManager' entry-point-ref="loginUrlAuthenticationEntryPoint" >
    <intercept-url pattern="/**" access="ROLE_USER" />
    <custom-filter position="CONCURRENT_SESSION_FILTER" ref="concurrencyFilter" />
    <custom-filter position="FORM_LOGIN_FILTER" ref="customFormLoginFilter" />
     <session-management session-authentication-strategy-ref="sas"/>
 </http>

<!-- This just extends UsernamePasswordAuthenticationFilter -->
<beans:bean id="customFormLoginFilter" class="com.acme.security.CustomAuthenticationFilter" >
    <beans:property name="sessionAuthenticationStrategy" ref="sas" />
    <beans:property name="filterProcessesUrl" value="/j_spring_security_check" />
    <beans:property name="authenticationManager" ref="testAuthenticationManager"/>    
    <beans:property name="authenticationSuccessHandler" ref="successHandler"/>        
    <beans:property name="authenticationFailureHandler" ref="failureHandler" />        
</beans:bean>

<beans:bean id="concurrencyFilter" class="org.springframework.security.web.session.ConcurrentSessionFilter">
    <beans:property name="sessionRegistry" ref="sessionRegistry" />
    <beans:property name="expiredUrl" value="/login.jsp?errorCode=maxSessionsExceeded" />
</beans:bean>

<beans:bean id="sas" class="org.springframework.security.web.authentication.session.ConcurrentSessionControlStrategy">
    <beans:constructor-arg name="sessionRegistry" ref="sessionRegistry" />
    <beans:property name="maximumSessions" value="1" />
</beans:bean>

<beans:bean id="sessionRegistry" class="org.springframework.security.core.session.SessionRegistryImpl" />

<beans:bean id="loginUrlAuthenticationEntryPoint" class="org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint">
     <beans:property name="loginFormUrl" value="/login.jsp"/>
</beans:bean>

<beans:bean id="successHandler"
            class="org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler">
    <beans:property name="defaultTargetUrl" value="/login/setup.htm"/>
    <beans:property  name="alwaysUseDefaultTargetUrl" value="true"/>        
</beans:bean>

<beans:bean id="failureHandler"
    class="org.springframework.security.web.authentication.ExceptionMappingAuthenticationFailureHandler">
    <beans:property name="defaultFailureUrl" value="/login.jsp" />
    <beans:property name="exceptionMappings">
        <beans:props>
            <beans:prop key="org.springframework.security.authentication.AuthenticationServiceException">/login.jsp?errorCode=666</beans:prop>
        </beans:props>
    </beans:property>
</beans:bean>
4

0 に答える 0