我在我的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