Spring security remember me giving the error: ERR_TOO_MANY_REDIRECTS

Spring security remember me giving the error: ERR_TOO_MANY_REDIRECTS



I have recently implemented the Spring Security Token based remember me functionality in my Java Spring MVC web application. My spring-security.xml fie is as follows:


Spring Security Token based remember me


Java Spring MVC web application


<http auto-config="true" use-expressions="true">
<intercept-url pattern="/login**" access="permitAll" />
<intercept-url pattern="/layout/**" access="permitAll" />
<intercept-url pattern="/min/**" access="permitAll" />
<intercept-url pattern="/rest/v3/**" access="permitAll" />
<intercept-url pattern="/password/**" access="permitAll" />
<intercept-url pattern="/register/**" access="permitAll" />
<intercept-url pattern="/unsubscribe/**" access="permitAll" />
<intercept-url pattern="/**" access="isFullyAuthenticated()"/>

<form-login login-page="/login" default-target-url="/"
authentication-failure-url="/login?error" username-parameter="username"
password-parameter="password" />
<logout logout-success-url="/login?logout" invalidate-session="false" />

<!-- enable csrf protection
<csrf />
-->
<!-- access denied page -->
<access-denied-handler error-page="/403" />

<logout delete-cookies="JSESSIONID"/>
<remember-me key="myAppKey" />

</http>



After implementing this feature, the remember me function is working. But I am getting an error as follows:
Error Screen



I have tried to add the permitAll() option to the login `URL' as understood from some docs. But nothing seems to be working for me. The same configuration is working for me in all my other web applications.


permitAll()






Use your browser's web developer features to figure out what URLs are redirecting to what. (I suspect that something is redirecting to the wrong place ...)

– Stephen C
Sep 14 '18 at 3:27






Hmmm ... is "/login**" the correct syntax? If it isn't matching the login page, then the permitAll() would not apply and you would drop through to the "/**" rule for the login page (!)

– Stephen C
Sep 14 '18 at 3:29



permitAll()






@Stephen C, I find that / is the URL to which there are too many redirects

– Geo Thomas
Sep 18 '18 at 10:40




2 Answers
2



Try changing


<intercept-url pattern="/login**" access="permitAll" />



TO


<intercept-url pattern="/login" access="permitAll" />






I have tried this, but the issue remains same

– Geo Thomas
Sep 14 '18 at 12:18



You actually don't need permission to a login page:



Outside your http tag, add this


http tag


<http security="none" pattern="/login" />



and remove


<intercept-url pattern="/login**" access="permitAll" />



This applies for those cases you wanna load css/js files too



Your file will look like this, for example:


<http security="none" pattern="/login" />
<http security="none" pattern="/layout/**" />
<http security="none" pattern="/min/**" />

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

<intercept-url pattern="/rest/v3/**" access="permitAll" />
<intercept-url pattern="/password/**" access="permitAll" />
<intercept-url pattern="/register/**" access="permitAll" />
<intercept-url pattern="/unsubscribe/**" access="permitAll" />
<intercept-url pattern="/**" access="isFullyAuthenticated()"/>

<form-login login-page="/login" default-target-url="/"
authentication-failure-url="/login?error" username-parameter="username"
password-parameter="password" />
<logout logout-success-url="/login?logout" invalidate-session="false" />

<!-- enable csrf protection
<csrf />
-->
<!-- access denied page -->
<access-denied-handler error-page="/403" />

<logout delete-cookies="JSESSIONID"/>
<remember-me key="myAppKey" />

</http>



Reference Spring Security documentation: https://docs.spring.io/spring-security/site/docs/3.1.x/reference/springsecurity-single.html#ns-minimal



3.2.3 Form and Basic Login Options



Note that you can still use auto-config. The form-login element just overrides the default settings. Also note that we've added an extra intercept-url element to say that any requests for the login page should be available to anonymous users [5]. Otherwise the request would be matched by the pattern /** and it wouldn't be possible to access the login page itself! This is a common configuration error and will result in an infinite loop in the application. Spring Security will emit a warning in the log if your login page appears to be secured. It is also possible to have all requests matching a particular pattern bypass the security filter chain completely, by defining a separate http element for the pattern like this:



Thanks for contributing an answer to Stack Overflow!



But avoid



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown




By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)