我正在研究使用库进行身份验证的应用程序。 我想在用户身份验证期间捕获/拦截一些HTTP请求的标头信息。在该库中,我创建了一个restController,但从未捕获到该请求。
邮递员请求:http://localhost:8080/myApp/user/login/authenticate
响应状态:HTTP状态404
14:16:11.959 [http-8080-4]调试org.springframework.security.web.context.SecurityContextPersistenceFilter -随着请求处理完成,SecurityContextHolder现在已清除
14:16:27.074 [http-8080-4]调试org.springframework.security.web.util.matcher.AntPathRequestMatcher- 检查请求是否匹配:'/ user / login / authenticate';反对 '/ rest / olta / **'
14:16:27.074 [http-8080-4]调试org.springframework.security.web.util.matcher.AntPathRequestMatcher- 检查请求是否匹配:'/ user / login / authenticate';反对 '/ rest / errors / / '
14:16:27.074 [http-8080-4]调试org.springframework.security.web.util.matcher.AntPathRequestMatcher- 检查请求是否匹配:'/ user / login / authenticate';反对 '/ rest / parameter / / '
14:16:27.074 [http-8080-4]调试org.springframework.security.web.util.matcher.AntPathRequestMatcher- 检查请求是否匹配:'/ user / login / authenticate';反对 '/ rest / user / authenticate'
14:16:27.074 [http-8080-4]调试org.springframework.security.web.util.matcher.AntPathRequestMatcher- 检查请求是否匹配:'/ user / login / authenticate';反对 '/ rest / isUp'
14:16:27.074 [http-8080-4]调试org.springframework.security.web.FilterChainProxy- / user / login / authenticate没有匹配的过滤器
14:16:27.074 [http-8080-4]调试org.springframework.web.servlet.DispatcherServlet-DispatcherServlet 名称为“ dispatcher”的POST处理请求 [/ myApp / user / login / authenticate]
14:16:27.074 [http-8080-4]调试org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping -查找路径/ user / login / authenticate
的处理程序方法14:16:27.075 [http-8080-4]调试org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping -找不到[/ user / login / authenticate]
的处理程序方法14:16:27.075 [http-8080-4] WARN org.springframework.web.servlet.PageNotFound-未找到对应的映射 带有URI [/ myApp / user / login / authenticate]的HTTP请求 名称为“ dispatcher”的DispatcherServlet
14:16:27.075 [http-8080-4]调试org.springframework.web.servlet.DispatcherServlet-成功 完成的请求
父应用程序的web.xml:
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<display-name>myApp WebApp</display-name>
<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>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:/META-INF/spring/applicationContext.xml
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextClass</param-name>
<param-value>
org.springframework.web.context.support.AnnotationConfigWebApplicationContext
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
依赖项库中的我的控制器:
@RestController
@RequestMapping("/user/login")
public class LoginController {
@RequestMapping(value = "authenticate", method = RequestMethod.POST, produces = "application/json")
@ResponseBody
public ResponseEntity<User> authenticate(@RequestParam("username") String username,
@RequestParam("password") String password) {
...
}