Spring Security登录页面与loginProcessingURL

时间:2018-11-04 12:04:55

标签: spring spring-boot spring-security

loginPage与loginProcessingURL有什么区别?    .formLogin().loginPage("/login").usernameParameter("phone-number").passwordParameter("password")

似乎是loginProcessingURL就像post方法,一旦用户在登录页面中提交了数据,但是当我删除它时也可以正常工作。 loginProcessingURL的意义是什么?它与loginPage有何区别?

2 个答案:

答案 0 :(得分:2)

loginPage("/login")行指示Spring Security

  • 需要身份验证时,将浏览器重定向到/ login
  • 我们负责在请求/ login时呈现登录页面
  • 当身份验证尝试失败时,将浏览器重定向到 / login?error(因为我们没有另外指定)
  • 当/ login?error为错误时,我们负责呈现失败页面 请求
  • 成功注销后,将浏览器重定向到/ login?logout (因为我们没有另外指定)
  • 我们负责在以下情况下呈现注销确认页面 / login?请求注销

AND

.loginProcessingUrl("/login/process")
当发送指定路径时,

告诉Spring Security处理提交的凭据,并且默认情况下,将用户重定向回来自的页面用户。 它不会将请求传递给Spring MVC和您的控制器。

引用documentation

答案 1 :(得分:-1)

Spring安全源代码中的以下代码段可能对您有帮助:

loginPage the login page to redirect to if authentication is required
loginProcessingUrl the URL to validate username and password
 DEFAULT_LOGIN_PAGE_URL = "/login"
/**
     * Updates the default values for authentication.
     *
     * @throws Exception
     */
    protected final void updateAuthenticationDefaults() {
        if (loginProcessingUrl == null) {
            loginProcessingUrl(loginPage);
        }
             //...
        }
相关问题