Announcement Announcement Module
Collapse
No announcement yet.
SaveContextOnUpdateOrErrorResponseWrapper java.lang.ClassCastException Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • SaveContextOnUpdateOrErrorResponseWrapper java.lang.ClassCastException

    hi,All:

    I meet a very strange error today, I try to login with ajax, so I write those code:
    Code:
            @Autowired
    	private AuthenticationManager authenticationManager;
    
    	@Autowired
    	SecurityContextRepository repository;
    	
    	
    	@ResponseStatus(value = HttpStatus.OK)
    	@RequestMapping(value = "loginfromjson", produces = MediaType.APPLICATION_JSON_VALUE)
    	public ModelAndView loginjson(
    			@RequestParam String username, @RequestParam String password,
    			HttpServletRequest request, HttpServletResponse response) {
    		ModelAndView mav = new ModelAndView();
    		Authentication auth = new UsernamePasswordAuthenticationToken(username,
    				password);
    		auth = authenticationManager.authenticate(auth);
    		SecurityContextHolder.getContext().setAuthentication(auth);
    		
    		repository.saveContext(SecurityContextHolder.getContext(), request,
    				response);
    		mav.addObject("sessionid", request.getSession().getId());
    		return mav;
    	}
    but, spring throw this ClassCastException:
    Code:
    java.lang.ClassCastException: org.eclipse.jetty.server.Response cannot be cast t
    o org.springframework.security.web.context.SaveContextOnUpdateOrErrorResponseWra
    pper
            at org.springframework.security.web.context.HttpSessionSecurityContextRe
    pository.saveContext(HttpSessionSecurityContextRepository.java:99)
            at com.nanhua.trading.manager.account.web.LoginController.loginjson(Logi
    nController.java:47)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
    java:39)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
    sorImpl.java:25)
            at java.lang.reflect.Method.invoke(Method.java:597)
            at org.springframework.web.method.support.InvocableHandlerMethod.invoke(
    InvocableHandlerMethod.java:212)
            at org.springframework.web.method.support.InvocableHandlerMethod.invokeF
    orRequest(InvocableHandlerMethod.java:126)
            at org.springframework.web.servlet.mvc.method.annotation.ServletInvocabl
    eHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96)
            at org.springframework.web.servlet.mvc.method.annotation.RequestMappingH
    andlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617)
            at org.springframework.web.servlet.mvc.method.annotation.RequestMappingH
    andlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578)
            at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapt
    er.handle(AbstractHandlerMethodAdapter.java:80)
    I dont know where cause this error, please help me!

    thank you!

  • #2
    resloved, forget

    <filter-mapping>
    <filter-name>springSecurityFilterChain</filter-name>
    <url-pattern>/*</url-pattern>
    </filter-mapping>

    in web.xml

    Comment

    Working...
    X