2014-07-26 3 views
3

Cordova 애플리케이션을 개발 중입니다.Cordova POST - 금지 요청 403. Dispatcher 서블릿에 도달하지 않음

물리적 장치 (에뮬레이터가 아닌)에서 실행중인 Cordova 앱에서 $ .ajax POST 요청을 제출하면 금지 된 상태 코드 403이 수신됩니다.

기기에서 GET 요청을 할 수 있습니다. POST (302 발견 응답 수신)를 사용하여 로그인 할 수도 있습니다.

Chrome의 요청은 완벽하게 처리됩니다.

저는 Spring/Tomcat을 사용하고 있습니다. 내 tomcat web.xml에 CORS 필터를 추가했으며 allow-origins *를 Cordova의 config.xml에 추가했습니다.

다음은 Chrome에서 먼저 내 기기에서 POST 요청을 할 때 생성되는 로그 추출물입니다.

크롬 요청 :

org.springframework.security.web.FilterChainProxy/제출 체크 추가 필터 체인 (11)의 위치는 1; firing 필터 : 'WebAsyncManagerIntegrationFilter' org.springframework.security.web.FilterChainProxy : 추가 필터 체인에서 11의 2 위치에서 제출 확인. firing 필터 : 'SecurityContextPersistenceFilter' org.springframework.security.web.context.HttpSessionSecurityContextRepository : 현재 HttpSession이 없습니다. org.springframework.security.web.context.HttpSessionSecurityContextRepository : HttpSession : null에서 SecurityContext를 사용할 수 없습니다. 새로운 것이 생성 될 것입니다. org.springframework.security.web.FilterChainProxy : 추가 필터 체인에서 11의 3 위치에서/submit-check; firing 필터 : 'HeaderWriterFilter' org.springframework.security.web.header.writers.HstsHeaderWriter : requestMatcher와 일치하지 않기 때문에 HSTS 헤더를 삽입하지 않습니다. org.springframework.se[email protected]461e0eb8 org.springframework.security.web.FilterChainProxy : 추가 필터 체인에서 11의 4 위치에서/submit-check; firing 필터 : 'LogoutFilter' org.springframework.security.web.util.matcher.AntPathRequestMatcher : 요청 일치 검사 : '/ submit-check'; '/ j_spring_security_logout'에 대해 org.springframework.security.web.FilterChainProxy : 추가 필터 체인에서 11/5 위치에서 제출 확인; firing 필터 : 'UsernamePasswordAuthenticationFilter' org.springframework.security.web.util.matcher.AntPathRequestMatcher : 요청 일치 확인 : '/ submit-check'; '/ j_spring_security_check'에 대해 org.springframework.security.web.FilterChainProxy : 추가 필터 체인에서 11의 6 위치에서 제출 확인; firing 필터 : 'RequestCacheAwareFilter' org.springframework.security.web.FilterChainProxy : 추가 필터 체인에서 11/7 위치에서 제출 확인. firing 필터 : 'SecurityContextHolderAwareRequestFilter' org.springframework.security.web.FilterChainProxy : 추가 필터 체인에서 11의 위치 8에/submit-check; firing 필터 : 'AnonymousAuthenticationFilter' org.springframework.security.web.authentication.AnonymousAuthenticationFilter : 익명 토큰을 사용하여 채워진 SecurityContextHolder : 'org.sprin[email protected]9055c2bc : Principal : anonymousUser; 자격증 명 : [PROTECTED]; 인증 됨 : true; 세부 사항 : org.sprin[email protected]b364 : RemoteIpAddress : 0 : 0 : 0 : 0 : 0 : 0 : 0 : 1; SessionId : null; 부여 된 권한 : ROLE_ANONYMOUS ' org.springframework.security.web.FilterChainProxy : 추가 필터 체인에서 11/9 위치에서 제출 확인; firing 필터 : 'SessionManagementFilter' org.springframework.security.web.session.SessionManagementFilter : 요청 된 세션 ID 2BB345F22D731DB9A10B0BB65950502D가 잘못되었습니다. org.springframework.security.web.FilterChainProxy : 추가 필터 체인에서 11의 위치 10에/submit-check; firing 필터 : 'ExceptionTranslationFilter' org.springframework.security.web.FilterChainProxy : 추가 필터 체인에서 11의 11 위치에서 제출 확인. firing 필터 : '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 : [ '/ ab/submit-check]에 대한 POST 요청을 처리하는'dispatcher '이름의 DispatcherServlet org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping : 경로/제출 확인을위한 핸들러 메소드 조회하기 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 : 'mobileNavigation'싱글 톤 bean의 캐시 된 인스턴스를 반환합니다. org.springframework.web.servlet.DispatcherServlet : Null ModelAndView는 name을 사용하여 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- 추가 필터 체인에서 11의 1 위치를 확인하십시오. firing 필터 : 'WebAsyncManagerIntegrationFilter' org.springframework.security.web.FilterChainProxy : 추가 필터 체인에서 11의 2 위치에서 제출 확인. firing 필터 : 'SecurityContextPersistenceFilter' org.springframework.security.web.context.HttpSessionSecurityContextRepository : 현재 HttpSession이 없습니다. org.springframework.security.web.context.HttpSessionSecurityContextRepository : HttpSession : null에서 SecurityContext를 사용할 수 없습니다. 새로운 것이 생성 될 것입니다. org.springframework.security.web.FilterChainProxy : 추가 필터 체인에서 11의 3 위치에서/submit-check; firing 필터 : 'HeaderWriterFilter' org.springframework.security.web.header.writers.HstsHeaderWriter : requestMatcher와 일치하지 않기 때문에 HSTS 헤더를 삽입하지 않습니다. org.springframework.se[email protected]461e0eb8 org.springframework.security.web.FilterChainProxy : 추가 필터 체인에서 11의 4 위치에서/submit-check; firing 필터 : 'LogoutFilter' org.springframework.security.web.util.matcher.AntPathRequestMatcher : 요청 일치 검사 : '/ submit-check'; '/ j_spring_security_logout'에 대해 org.springframework.security.web.FilterChainProxy : 추가 필터 체인에서 11/5 위치에서 제출 확인; firing 필터 : 'UsernamePasswordAuthenticationFilter' org.springframework.security.web.util.matcher.AntPathRequestMatcher : 요청 일치 확인 : '/ submit-check'; against '/ j_spring_security_check' org.springframework.security.web.FilterChainProxy : 추가 필터 체인에서 11/6 위치의/submit-check; firing 필터 : 'RequestCacheAwareFilter' org.springframework.security.web.FilterChainProxy : 추가 필터 체인에서 11/7 위치에서 제출 확인. firing 필터 : 'SecurityContextHolderAwareRequestFilter' org.springframework.security.web.FilterChainProxy : 추가 필터 체인에서 11의 위치 8에/submit-check; firing 필터 : 'AnonymousAuthenticationFilter' org.springframework.security.web.authentication.AnonymousAuthenticationFilter : 익명 토큰이있는 SecurityContextHolder가 채워짐 : 'org.sprin[email protected]90550640 : Principal : anonymousUser; 자격증 명 : [PROTECTED]; 인증 됨 : true; 세부 사항 : org.sprin[email protected]7798 : RemoteIpAddress : 192.168.1.5; SessionId : null; 부여 된 권한 : ROLE_ANONYMOUS ' org.springframework.security.web.FilterChainProxy : 추가 필터 체인에서 11/9 위치에서 제출 확인; firing 필터 : 'SessionManagementFilter' org.springframework.security.web.session.SessionManagementFilter : 요청 된 세션 ID F26DAEDA16CA5DAE443ABF8A4ADD836F가 잘못되었습니다. org.springframework.security.web.FilterChainProxy : 추가 필터 체인에서 11의 위치 10에/submit-check; firing 필터 : 'ExceptionTranslationFilter' org.springframework.security.web.FilterChainProxy : 추가 필터 체인에서 11의 11 위치에서 제출 확인. firing 필터 : '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에 지금 삭제

org.springframework.web.servlet.DispatcherServlet : 이름이 'dispatcher'인 DispatcherServlet 처리 중 [/ ab/submit-check]에 대한 POST 요청 org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping : 핸들러 메소드 조회 경로/제출 확인을 위해 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가 'dispatcher'라는 이름으로 DispatcherServlet에 반환되었습니다. HandlerAdapter가 요청 처리를 완료했다고 가정 함 org.springframework.web.servlet.DispatcherServlet : 요청을 성공적으로 완료했습니다.

어떤 이유로 코도바에서 발생한 요청이 Spring의 DispatcherServlet으로 전송되지 않고 왜 그럴까요?

Weinre를 원격 디버그에 설치했으며 Chrome과 Cordova에서 보낸 요청 데이터가 동일하게 보입니다 (Weinre는 대부분의 헤더 정보를 놓치기는하지만).

답변

1

이 문제를 해결하기 위해 관리했습니다.

문제는 내 tomcat web.xml (confcat의 tomcat 글로벌 web.xml)에 CORS 필터가 있습니다. 거기에있을 필요가없는 코르도바 앱을 위해.

코르도바는 "Origin : file : //"헤더를 통해 요청을 보냅니다. Tomcat에 CORS 필터가 설정된 경우 요청이 실패합니다.

web.xml에서 CORS 필터를 제거하면 이제 POST 데이터를 사용할 수 있습니다.

+0

정말 고마워요. 이것은 큰 대답입니다 .. – Keerthivasan

+0

안녕하세요, 비슷한 문제가 있습니다. "file : //"을 허용하도록 web.xml을 어떻게 구성 하였습니까? –

+0

안녕하세요, 오래 전부터 알고 있습니다. 당신은 귀하의 대답에 cors 필터를 제거했다. 이 경우, tomcat이 교차 원점 요청을 허용하는지 확인하는 방법은 무엇입니까? –