2014-02-12 2 views
0

Я пытаюсь расширить UsernamePasswordAuthenticationFilter как в этом учебнике: http://blog.awnry.com/post/16183749439/two-factor-authentication-and-spring-security-3Расширение безопасности весной 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» реф =«twoFactorAuthenticationFilter»/>' с '<безопасности: заказ фильтра перед тем =«FORM_LOGIN_FILTER» исх = «twoFactorAuthenticationFilter» /> ' – Ilya

+0

Это работает, ошибка исчезла, но она не входит в fillter. – lior

+0

Вы получаете 403 на странице«/demo/player/login »? – Ilya

ответ

1

Вы указали filterProcessesUrl, поэтому ваша форма входа должна быть отправлена ​​на это. В частности, вы должны использовать что-то вроде:.

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

Конечно в идеале вы бы не трудно код корневой контекст Если вы используете JSP, вы можете использовать <c:url> тег, чтобы автоматически включать корневой контекст.

+0

Спасибо! помогли много – lior

Смежные вопросы