【发布时间】:2017-06-21 17:06:12
【问题描述】:
我有一个@RestController,其中每个方法都需要将(WebSSO)cookie 传递给服务。该服务反过来使用 cookie 进行身份验证。我在控制器中自动装配服务 bean。该服务有一个设置器setCredentials(String webSSOCookie)。一种简单的方法是在每个方法中调用此设置器。我想做得更好;例如使用HandlerInterceptor。但是,HandlerInterceptor 无权访问控制器(因此也无法访问其成员) - 对吗?
在jersey 中,我可以使用filter。我如何在 SPRING 中实现它?
@RestController
@RequestMapping("/documents")
public class ECMRestController {
@Autowired
public ECMService ecmService;
@RequestMapping(value="/{documentId}", method=RequestMethod.DELETE)
public void deleteDocument(@RequestParam("documentId") String documentId) throws IllegalArgumentException, HttpClientErrorException {
// I could get and pass the cookie to ecmService in every method.
// ecmService.setCredentials(webSSOCookieObtainedfromRequest);
// However I don't want to do it that way.
ecmService.deleteDocument(documentId);
}
// Other REST Methods that need to pass the cookie in the same way.
}
【问题讨论】:
标签: java spring spring-mvc cookies