2014-02-12 66 views
0

我想UsernamePasswordAuthenticationFilter延伸本教程:http://blog.awnry.com/post/16183749439/two-factor-authentication-and-spring-security-3扩展Spring安全UsernamePasswordAuthenticationFilter

这是我的security.xml:

<security:http use-expressions="true" auto-config="false" 
    entry-point-ref="loginUrlAuthenticationEntryPoint"> 

    <security:custom-filter position="FORM_LOGIN_FILTER" 
     ref="twoFactorAuthenticationFilter" /> 

    <security:intercept-url pattern="/**" 
     access="isAuthenticated()" /> 


    <security:logout logout-url="/player/logout" 
     success-handler-ref="playerLogoutSuccessHandler" /> 

</security:http> 

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

<bean id="twoFactorAuthenticationFilter" 
    class="com.XXX.filter.TwoFactorAuthenticationFilter"> 
    <property name="authenticationManager" ref="authenticationManager" /> 
    <property name="authenticationFailureHandler" ref="failureHandler" /> 
    <property name="authenticationSuccessHandler" ref="playerAuthenticationSuccessHandler" /> 
    <property name="filterProcessesUrl" value="/processLogin" /> 
    <property name="postOnly" value="true" /> 
    <property name="extraParameter" value="domain" /> 
</bean> 


<bean id="failureHandler" 
    class="org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler"> 
    <property name="defaultFailureUrl" value="/login?login_error=true" /> 
</bean> 

    <bean id="bCryptPasswordEncoder" 
     class="org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder" /> 



    <security:authentication-manager 
     alias="authenticationManager"> 
     <security:authentication-provider 
      ref="authenticationProvider"> 
     </security:authentication-provider> 
    </security:authentication-manager> 
</beans> 

当我到了需要注册我的自定义登录页面出现,但没有提交任何附加内容。

我登录:

<body> 
<form method="post" action="http://localhost:8080/XXX/j_spring_security_check"> 
     <div id="passwordLoginOption" class="form"> 
      <div class="row"> 
       <div class="label left"> 
        <label for="j_username">login:</label> 
       </div> 
       <div class="right"> 
        <div class="textWrapper"> 
         <input type="text" name="j_username"/> 
        </div> 
       </div> 
       <div class="cl"></div> 
      </div> 
      <div class="row"> 
       <div class="label left"> 
        <label for="j_password">password:</label> 
       </div> 
       <div class="right"> 
        <div class="textWrapper"> 
         <input type="password" name="j_password"/> 
        </div> 
       </div> 
       <div class="cl"></div> 
      </div> 
      <div class="row"> 
       <div class="label left"> 
        <label for="brand">brand:</label> 
       </div> 
       <div class="right"> 
        <div class="textWrapper"> 
         <input type="text" name="brand"/> 
        </div> 
       </div> 
       <div class="cl"></div> 
      </div> 
       <div class="buttons"> 
       <input type="submit" value="Login"/> 
      </div> 
     </div> 
    </form> 
</body> 

想法?

+0

我不知道,但尝试更换'<安全:自定义过滤器位置= “FORM_LOGIN_FILTER” REF = “twoFactorAuthenticationFilter”/>'和'<安全:之前= “FORM_LOGIN_FILTER” 裁判定制过滤器= “twoFactorAuthenticationFilter”/>' – Ilya

+0

它的工作原理,错误消失了,但它没有进入填充者 – lior

+0

你在页面“/ demo/player/login”上获得了403吗? – Ilya

回答

1

你已经指定了filterProcessesUrl,所以你的登录表单需要提交。具体来说,你应该使用类似:

<form method="post" action="/XXX/filterProcessesUrl"> 

当然最好你不会硬编码在上下文根如果您在使用JSP可以使用<c:url>标签来自动包括上下文根。

+0

谢谢!帮了很多忙 – lior