lior
lior

Reputation: 1187

Extending spring security UsernamePasswordAuthenticationFilter

I'm trying to extend UsernamePasswordAuthenticationFilter as in this tutorial: http://blog.awnry.com/post/16183749439/two-factor-authentication-and-spring-security-3

this is my 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>

when i get to a page that need registration my custom login appears but on submit nothing appends.

My login:

<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>

Ideas?

Upvotes: 0

Views: 2960

Answers (1)

Rob Winch
Rob Winch

Reputation: 21720

You have specified the filterProcessesUrl, so your login form needs to submit to that. Specifically you should use something like:

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

Of course ideally you would not hard code the context root in. If you are using JSPs you can use the <c:url> tag to automatically include the context root.

Upvotes: 1

Related Questions