【发布时间】:2014-09-18 08:16:27
【问题描述】:
我正在开发一个 Cordova 应用程序。
当我从在我的物理设备(不是模拟器)上运行的 Cordova 应用程序提交 $.ajax POST 请求时,我收到状态代码 403 禁止。
我可以从设备发出 GET 请求,这没有问题。我也可以使用 POST 登录(收到 302 Found Response)。
来自 Chrome 的请求得到完美处理。
我正在使用 Spring / Tomcat。我已将 CORS 过滤器添加到我的 tomcat web.xml 中,并已将 allow-origins * 添加到我在 Cordova 中的 config.xml 中。
以下是我发出 POST 请求时产生的日志提取,首先来自 Chrome,其次来自我的设备。
Chrome 请求:
org.springframework.security.web.FilterChainProxy: /submit-check 在附加过滤器链中的第 11 个位置;触发过滤器:'WebAsyncManagerIntegrationFilter' org.springframework.security.web.FilterChainProxy: /submit-check 在附加过滤器链中的 11 的第 2 位;触发过滤器:'SecurityContextPersistenceFilter' org.springframework.security.web.context.HttpSessionSecurityContextRepository:当前不存在 HttpSession org.springframework.security.web.context.HttpSessionSecurityContextRepository:HttpSession 中没有可用的 SecurityContext:null。将创建一个新的。 org.springframework.security.web.FilterChainProxy: /submit-check 在附加过滤器链中的 11 的第 3 位;触发过滤器:'HeaderWriterFilter' org.springframework.security.web.header.writers.HstsHeaderWriter:不注入 HSTS 标头,因为它与 requestMatcher org.springframework.security.web.header.writers.HstsHeaderWriter$SecureRequestMatcher@461e0eb8 不匹配 org.springframework.security.web.FilterChainProxy: /submit-check 在附加过滤器链中的 11 的第 4 位;触发过滤器:'LogoutFilter' org.springframework.security.web.util.matcher.AntPathRequestMatcher:检查请求的匹配:'/submit-check';反对“/j_spring_security_logout” org.springframework.security.web.FilterChainProxy: /submit-check 在附加过滤器链中 11 的第 5 位;触发过滤器:'UsernamePasswordAuthenticationFilter' org.springframework.security.web.util.matcher.AntPathRequestMatcher:检查请求的匹配:'/submit-check';反对'/j_spring_security_check' org.springframework.security.web.FilterChainProxy: /submit-check 在附加过滤器链中 11 的位置 6;触发过滤器:'RequestCacheAwareFilter' org.springframework.security.web.FilterChainProxy: /submit-check 在附加过滤器链中的 11 的第 7 位;触发过滤器:'SecurityContextHolderAwareRequestFilter' org.springframework.security.web.FilterChainProxy: /submit-check 在附加过滤器链中的第 11 位的第 8 位;触发过滤器:'AnonymousAuthenticationFilter' org.springframework.security.web.authentication.AnonymousAuthenticationFilter:使用匿名令牌填充 SecurityContextHolder:'org.springframework.security.authentication.AnonymousAuthenticationToken@9055c2bc:主体:anonymousUser;凭证:[受保护];已认证:真实;详细信息:org.springframework.security.web.authentication.WebAuthenticationDetails@b364:RemoteIpAddress:0:0:0:0:0:0:0:1;会话ID:空;授予权限:ROLE_ANONYMOUS' org.springframework.security.web.FilterChainProxy: /submit-check 在附加过滤器链中的 11 的第 9 位;触发过滤器:'SessionManagementFilter' org.springframework.security.web.session.SessionManagementFilter:请求的会话 ID 2BB345F22D731DB9A10B0BB65950502D 无效。 org.springframework.security.web.FilterChainProxy: /submit-check 在附加过滤器链中 11 的第 10 位;触发过滤器:'ExceptionTranslationFilter' org.springframework.security.web.FilterChainProxy: /submit-check 在附加过滤器链中 11 的第 11 位;触发过滤器:'FilterSecurityInterceptor' org.springframework.security.web.util.matcher.AntPathRequestMatcher:检查请求的匹配:'/submit-check';反对'/**.html' org.springframework.security.web.access.intercept.FilterSecurityInterceptor:公共对象-未尝试身份验证 org.springframework.security.web.FilterChainProxy: /submit-check 到达附加过滤器链的末尾;继续原链 org.springframework.web.servlet.DispatcherServlet:名为“dispatcher”的 DispatcherServlet 处理 [/ab/submit-check] 的 POST 请求 org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping:查找路径/submit-check的处理程序方法 org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping:返回处理程序方法 [public org.springframework.web.servlet.ModelAndView com.gm.ab.controller.MobileNavigation.save(java.lang.String)] org.springframework.beans.factory.support.DefaultListableBeanFactory:返回单例 bean 'mobileNavigation' 的缓存实例 org.springframework.web.servlet.DispatcherServlet:Null ModelAndView 返回到 DispatcherServlet,名称为“dispatcher”:假设 HandlerAdapter 完成了请求处理 org.springframework.web.servlet.DispatcherServlet:成功完成请求 org.springframework.security.web.access.ExceptionTranslationFilter:链处理正常 org.springframework.security.web.context.HttpSessionSecurityContextRepository:SecurityContext 为空或内容是匿名的 - 上下文不会存储在 HttpSession 中。 org.springframework.security.web.context.SecurityContextPersistenceFilter:SecurityContextHolder 现在清除,请求处理完成
科尔多瓦请求
org.springframework.security.web.FilterChainProxy: /submit-check 在附加过滤器链中的第 11 个位置;触发过滤器:'WebAsyncManagerIntegrationFilter' org.springframework.security.web.FilterChainProxy: /submit-check 在附加过滤器链中的 11 的第 2 位;触发过滤器:'SecurityContextPersistenceFilter' org.springframework.security.web.context.HttpSessionSecurityContextRepository:当前不存在 HttpSession org.springframework.security.web.context.HttpSessionSecurityContextRepository:HttpSession 中没有可用的 SecurityContext:null。将创建一个新的。 org.springframework.security.web.FilterChainProxy: /submit-check 在附加过滤器链中的 11 的第 3 位;触发过滤器:'HeaderWriterFilter' org.springframework.security.web.header.writers.HstsHeaderWriter:不注入 HSTS 标头,因为它与 requestMatcher org.springframework.security.web.header.writers.HstsHeaderWriter$SecureRequestMatcher@461e0eb8 不匹配 org.springframework.security.web.FilterChainProxy: /submit-check 在附加过滤器链中的 11 的第 4 位;触发过滤器:'LogoutFilter' org.springframework.security.web.util.matcher.AntPathRequestMatcher:检查请求的匹配:'/submit-check';反对“/j_spring_security_logout” org.springframework.security.web.FilterChainProxy: /submit-check 在附加过滤器链中 11 的第 5 位;触发过滤器:'UsernamePasswordAuthenticationFilter' org.springframework.security.web.util.matcher.AntPathRequestMatcher:检查请求的匹配:'/submit-check';反对'/j_spring_security_check' org.springframework.security.web.FilterChainProxy: /submit-check 在附加过滤器链中 11 的位置 6;触发过滤器:'RequestCacheAwareFilter' org.springframework.security.web.FilterChainProxy: /submit-check 在附加过滤器链中的 11 的第 7 位;触发过滤器:'SecurityContextHolderAwareRequestFilter' org.springframework.security.web.FilterChainProxy: /submit-check 在附加过滤器链中的第 11 位的第 8 位;触发过滤器:'AnonymousAuthenticationFilter' org.springframework.security.web.authentication.AnonymousAuthenticationFilter:使用匿名令牌填充 SecurityContextHolder:'org.springframework.security.authentication.AnonymousAuthenticationToken@90550640:主体:anonymousUser;凭证:[受保护];已认证:真实;详细信息:org.springframework.security.web.authentication.WebAuthenticationDetails@7798:RemoteIpAddress:192.168.1.5;会话ID:空;授予权限:ROLE_ANONYMOUS' org.springframework.security.web.FilterChainProxy: /submit-check 在附加过滤器链中的 11 的第 9 位;触发过滤器:'SessionManagementFilter' org.springframework.security.web.session.SessionManagementFilter:请求的会话 ID F26DAEDA16CA5DAE443ABF8A4ADD836F 无效。 org.springframework.security.web.FilterChainProxy: /submit-check 在附加过滤器链中 11 的第 10 位;触发过滤器:'ExceptionTranslationFilter' org.springframework.security.web.FilterChainProxy: /submit-check 在附加过滤器链中 11 的第 11 位;触发过滤器:'FilterSecurityInterceptor' org.springframework.security.web.util.matcher.AntPathRequestMatcher:检查请求的匹配:'/submit-check';反对'/**.html' org.springframework.security.web.access.intercept.FilterSecurityInterceptor:公共对象-未尝试身份验证 org.springframework.security.web.FilterChainProxy: /submit-check 到达附加过滤器链的末尾;继续原链 org.springframework.security.web.access.ExceptionTranslationFilter:链处理正常 org.springframework.security.web.context.HttpSessionSecurityContextRepository:SecurityContext 为空或内容是匿名的 - 上下文不会存储在 HttpSession 中。 org.springframework.security.web.context.SecurityContextPersistenceFilter:SecurityContextHolder 现在清除,请求处理完成
日志是相同的,除了来自 Chrome 的请求中的这些行:
org.springframework.web.servlet.DispatcherServlet:名为“dispatcher”的 DispatcherServlet 处理 [/ab/submit-check] 的 POST 请求 org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping:查找路径/submit-check的处理程序方法 org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping:返回处理程序方法 [public org.springframework.web.servlet.ModelAndView com.gm.ab.controller.MobileNavigation.save(java.lang.String)] org.springframework.beans.factory.support.DefaultListableBeanFactory:返回单例 bean 'mobileNavigation' 的缓存实例 org.springframework.web.servlet.DispatcherServlet:Null ModelAndView 返回到 DispatcherServlet,名称为“dispatcher”:假设 HandlerAdapter 完成了请求处理 org.springframework.web.servlet.DispatcherServlet:成功完成请求
由于某种原因,来自 Cordova 的请求没有被发送到 Spring 的 DispatcherServlet,我不知道为什么不发送。
我已经安装了 Weinre 进行远程调试,Chrome 和 Cordova 发送的请求数据似乎是相同的(尽管 Weinre 遗漏了大部分标头信息)。
【问题讨论】:
标签: spring tomcat cordova cors servlet-3.0