简体   繁体   中英

Spring Security login page url parameters

I am trying to localize my application which is fairly easy to implement through Spring localization and url params which works fine on every page except for the login page where Spring Security strips the mandatory "lang" parameter and the page defaults to English. I have tried implementing a custom login filter through LoginUrlAuthenticationEntryPoint, overriding determineUrlToUseForThisRequest like so:

 @Override
protected String determineUrlToUseForThisRequest(HttpServletRequest request, HttpServletResponse response,
    AuthenticationException exception) {
String url = super.determineUrlToUseForThisRequest(request, response, exception);
return url + "?" + request.getQueryString();
}

However this ends in a permanent redirect loop. Note my spring security config class does in theory allow request params on login page:

http
.and().formLogin().loginPage("/user").permitAll()

but I want to achieve "/user?lang=en" which in current state redirects to "/user" thus "lang" param is ignored.

Thanks in advance for any tips.

I have managed to find a solution by simply removing all restrictions on the login page like so:

.authorizeRequests().antMatchers("/user").permitAll()

This way no custom LoginUrlAuthenticationEntryPoint is required and the url params are all retained!

Thanks for all the input.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM