且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

为什么我的自定义登录页面没有显示Spring Security 4?

更新时间:2023-09-02 17:59:28

Spring Security 3.x使用 spring_security_login 作为默认登录URL( source 官方文档)。这可以设置为自定义值< security:form-login login-page =/ login> 并映射到控制器以呈现自定义页面。

Spring Security 3.x used spring_security_login as the default login URL (source: official documentation). This could be set to a custom value as <security:form-login login-page="/login"> and mapped to a controller to render a custom page.

Spring Security 4.x已放弃 spring_security_login 并切换到登录作为默认登录URL( source 官方Spring Security 4.x迁移指南)。因此,URL login 现在转到默认的Spring Security基础结构,该基础结构显示默认的自动生成的登录页面。

Spring Security 4.x has abandoned spring_security_login and switched to login as the default login URL (source: official Spring Security 4.x migration guide). Therefore, the URL login now goes to the default Spring Security infrastructure, that displays the default, auto-generated login page.

如果您使用JSP作为视图渲染技术,那么补救措施很简单。只需将登录页面重命名为 login.jsp ,将其放在页面层次结构的根文件夹中,Spring Security将自动将其提取。如果您不使用JSP,则必须使用不同的登录页面值(可能 signin 而不是登录,然后也改变你的控制器映射。

The remedy is simple if you are using JSP as the view rendering technology. Simply rename your login page to login.jsp, drop it in the root folder of the page hierarchy and Spring Security will pick it up automatically. If you are not using JSP, you will have to use a different login-page value (perhaps signin instead of login and then change your controller mapping as well.

请注意,默认的注销URL在4.x中也发生了变化。如果您有为注销URL编写的任何自定义逻辑,请务必同时查看。

Note that the default logout URL has also changed in 4.x. If you have any custom logic written for the logout URL, do make sure to review that as well.

请查看官方迁移指南,因为很多内容已经发生变化在4.x。

Do review the official migration guide as a lot of things have changed in 4.x.