0

I am trying to use a custom login form with spring security.

So I have a website and there is a Sign in button on the top, so when the user click the button it will take them to the login form. What I want is to go back to the page where the user was when he clicked the button.

My button is in the navigation bar, so it can be clicked anywhere in the application.

So far I have this config (XML):

  <http auto-config="true" use-expressions="true">

        <intercept-url pattern="/**/*.css" access="permitAll" />
        <intercept-url pattern="/**/*.js" access="permitAll" />
        <intercept-url pattern="/**/*.png" access="permitAll" />
        <intercept-url pattern="/**/*.jpg" access="permitAll" />
        <intercept-url pattern="/**/*.gif" access="permitAll" />
        <intercept-url pattern="/**/*.ttf" access="permitAll" />
        <intercept-url pattern="/**/*.otf" access="permitAll" />
        <intercept-url pattern="/**/*.woff" access="permitAll" />
        <intercept-url pattern="/**/*.woff2" access="permitAll" />
        <intercept-url pattern="/**/*.eot" access="permitAll" />
        <intercept-url pattern="/**/*.svg" access="permitAll" />
        <intercept-url pattern="/**/*.ico" access="permitAll" />
        <intercept-url pattern="/**/*.map" access="permitAll" />
        <intercept-url pattern="/login" access="permitAll"/>
        <intercept-url pattern="/resources" access="permitAll"/>
        <intercept-url pattern="/foo/{fooName}" access="hasRole('ROLE_USERREGISTERED')"/>
        <intercept-url pattern="/rest/foo/**" access="permitAll"/>




        <!-- access denied page -->
        <!--<access-denied-handler error-page="/page404"/>-->
       <form-login
                 login-page="/login"
                 authentication-failure-url="/login?error"
                 username-parameter="username"
                 password-parameter="password"
        />
         <logout logout-success-url="/login?logout"/>
        <!-- enable csrf protection -->
        <csrf disabled="true"/>
    </http>
 <authentication-manager>
        <authentication-provider>
            <jdbc-user-service data-source-ref="dataSource"
                               users-by-username-query=
                                       "foo Select"
                               authorities-by-username-query=
                                       "foo SELECT"/>
        </authentication-provider>
    </authentication-manager>

And my custom login form:

<c:url var="loginUrl" value='login' />
<div class="wrapper">
    <form class="form-signin" action="${loginUrl}" method="post">
        <img id="image-logo-foo" class="img-responsive" src="<c:url value="/resources/images/foo_logo.png"/>">
        <h2 class="form-signin-heading text-center"><spring:message code="log.in"/></h2>
        <input type="text" id="username"  class="form-control" name="username" placeholder="Email" required="" autofocus="" />
        <input type="password" class="form-control"  id="password" name="password" placeholder="Password" required=""/>
        <h6 class="text-center"><a><spring:message code="forgot.password"/></a></h6>

        <button class="btn btn-lg btn-primary btn-block btn-orange" type="submit"><spring:message code="log.in"/></button>
    </form>
    <form class="form-signin form-signin-middle">
        <button class="btn btn-lg btn-primary btn-block btn-blue"><span class="icon-facebook"></span><spring:message code="log.in.facebook"/></button>
    </form>
    <form class="form-signin">
        <h6 class="text-center margin-first"><spring:message code="first.time"/></h6>
        <button class="btn btn-lg btn-primary btn-block btn-green"><spring:message code="create.account"/></button>
    </form>
</div>
ZetaPR
  • 964
  • 7
  • 32

0 Answers0