Spring 安全性无法在 /spring_security_login 处生成/映射默认登录页面



我注意到如果我提到一个模式或输入对HTTP容器的RequestMatcher引用,就不会生成spring_security_login默认页面。我想知道为什么。在这种情况下(驱动到多个 http 配置元素),我们是否需要提供自己的登录页面和身份验证逻辑?

这就是我所指的配置。

<http pattern="/somearea/**" authentication-manager-ref="authMgr"  use-expressions="true" auto-config="true" request-matcher="ant">

这就是我的网络的样子.xml如果感兴趣的话。不是很花哨。:-)

<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

此外,如果我制作自己的登录页面来调用j_spring_security_check,则也找不到j_spring_security_check映射。如果需要更多配置信息,请告诉我。

原因是 http@pattern 和 http@request-matcher-ref 都决定是否使用该块。由于/spring_security_login/j_spring_security_check都不符合提供的模式(/somearea/),该块将不会被使用。

要解决此问题,您需要确保您的表单login@login处理网址配置为查看与您的http@pattern匹配的请求。您还需要指定登录页面并确保呈现自定义登录页面。例如,假设您确保 URL/login 呈现登录页面,则以下配置将起作用:

<http pattern="/somearea/**" authentication-manager-ref="authMgr"  use-expressions="true" auto-config="true" request-matcher="ant">
    <form-login login-processing-url="/somearea/login" loginPage="/login"/>    
</http>

或者,您可以创建一个单独的块来执行身份验证:

<http pattern="/somearea/**" authentication-manager-ref="authMgr"  use-expressions="true" auto-config="true" request-matcher="ant">
</http>
<http authentication-manager-ref="authMgr" use-expressions="true" auto-config="true" request-matcher="ant">    
</http>

请记住,每个配置都是不同的,并且仅在模式或请求匹配器引用匹配时才适用。

最新更新