我在我的UI服务中正确设置了正确的身份验证和授权问题。春季安全云:通过ZUUL网关安全设置的UI服务
目前,我有以下设置(所有利用春*春季云。*):
- Config Service;
- Registry Service;
- Gateway Service (Zuul);
- Authentication Service (Spring Cloud Security, JWT);
- Company backend service (db <-> rest);
- Ui service;
在后端安全的一切方面的工作,因为它应该:您请求JWT令牌通过凭据一个来自认证服务的网关,如果全部匹配,则通过REST返回。
公司服务意识到新令牌并在提交时验证它。
问题出在UI服务上。我现在做的是使用Spring Boot和Thymeleaf,并在前端部分中手动构建HttpHeaders,HttpEntity和Cookie对象,而无需使用Spring Cloud Security,以便访问Web应用程序的某些部分。这是很多愚蠢的不必要的代码。我知道我无法理解如何将Spring云安全整合到我的UI服务中。
这是控制器的方法(很丑陋)中的一个例子:
@RequestMapping("/firms")
public String firm (Model model,
HttpServletRequest servletRequest,
HttpServletResponse servletResponse,
HttpSession httpSession) throws IOException {
final String returnPage;
Cookie cookie = authService.findCookie(servletRequest, servletResponse);
HttpHeaders httpHeaders = authService.createJwtAuthHeader(cookie);
HttpEntity requestEntity = new HttpEntity(httpHeaders);
ResponseEntity <UserObject> userObjectResponse = authService.createUserResponseEntity(requestEntity, servletResponse);
authService.setUserSessionDetails(userObjectResponse, httpSession);
if (userObjectResponse != null && userObjectResponse.getBody() != null) {
log.info(CommonMessages.GOT_COOKIE_FROM_AUTH_SERVICE.toString(), cookie.getName());
returnPage = "firm";
} else {
log.error(CommonMessages.NO_COOKIES_FOUND_NO_ACCESS_REDIRECTING.toString());
httpSession.setAttribute("authorized", false);
returnPage = "error";
}
return returnPage;
}
也许有人遇到了类似的问题,发现一个资源或一个例子,我可以为了整合春季云安全使用正确地进入我的UI服务?
谢谢!
您是否发现http://docs.spring.io/spring-security/site/docs/4.2.3.RELEASE/reference/htmlsingle/#access-control-using-preauthorize-and-postauthorize? – Jeff
@Jeff为了这个工作,我需要在UI服务中将我当前的设置与Spring Cloud Security集成。我不知道该怎么做。 –
当前端向后端发送请求时,它必须传递令牌,这是在授权标头中完成的。我试图找到一个例子 – Jeff