我注意到,如果我提到某种模式或输入对 HTTP 容器的 RequestMatcher 引用,则不会生成 spring_security_login 默认页面。我想知道为什么。在这种情况下(驱动到多个http配置元素)我们是否需要提供自己的登录页面和身份验证逻辑?
这是我指的配置。
<http pattern="/somearea/**" authentication-manager-ref="authMgr" use-expressions="true" auto-config="true" request-matcher="ant">
这就是我的 web.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两者都决定是否使用该 block 。由于 /spring_security_login
或 /j_spring_security_check
都不匹配提供的模式 (/somearea/
),因此不会使用该 block 。
要解决此问题,您需要确保将 form-login@login-processing-url 配置为查看与您的 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>
或者,您可以创建一个仅执行身份验证的单独 block :
<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>
请记住,每个配置都是不同的,并且仅在模式或 request-matcher-ref 匹配时才适用。
关于java - Spring Security 无法在/spring_security_login 生成/映射默认登录页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19690075/