3

私は春のセキュリティ3を使用しています。

私は次のことをしたい: ユーザーがログインするときに、ユーザーが電子メールアドレスを確認したかどうか、およびユーザーがアカウントプロファイルを構成したかどうかをシステムに確認させたい.

その方法は正確にはわかりません。

私はこれを試しました:

<http use-expressions="true" auto-config="true">
    <intercept-url ... />
    ...
    <custom-filter after="SECURITY_CONTEXT_FILTER" ref="usrFilter" />
    ...
 </http>

 <b:bean id="usrFilter"
    class="com.zxxztech.zecure.security.MyAuthenticationFilter">
    <b:property name="authenticationManager" ref="authenticationManager" />
    <b:property name="failureHandler">
        <b:bean
            class="org.springframework.security.web.authentication.ExceptionMappingAuthenticationFailureHandler">
            <b:property name="exceptionMappings">
                <b:map>
                    <b:entry key="org.springframework.security.authentication.DisabledException" value="/disabled.htm" />
                </b:map>
            </b:property>
        </b:bean>
    </b:property>
 </b:bean>

そして、これは私のフィルターです:

public class MyAuthenticationFilter extends GenericFilterBean {
  ...
  public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();

        if (authentication != null) {
            Usuario usuario=(Usuario) authentication.getPrincipal();
            if (usuario.getActivationKey()!=null) {
                ((HttpServletResponse) response).sendRedirect("/activacion");
                return;
            } else if (authentication.getAuthorities().contains(AppRole.NUEVO_USUARIO)) {
                ((HttpServletResponse)response).sendRedirect("/configuracion_modelo");
                return;
            }
        }

        chain.doFilter(request, response);
    }

    ...
}

しかし、アプリケーションを段階的にデバッグしてログインすると、ループのようにフィルターが無期限に呼び出されます。

これを行う正しい方法はどうですか?

4

1 に答える 1