| | |
| | | String headerName = (String) reqHeaderEnum.nextElement(); |
| | | headers.put(headerName.toLowerCase(), request.getHeader(headerName)); |
| | | } |
| | | pd = PageData.newInstance().builder(userId, userName, this.getToken(request), reqData, componentCode, componentMethod, url, sessionId, appId, headers); |
| | | //pd = PageData.newInstance().builder(userId, userName, this.getToken(request), reqData, componentCode, componentMethod, url, sessionId, appId, headers); |
| | | headers.put(CommonConstant.COOKIE_AUTH_TOKEN,this.getToken(request)); |
| | | pd = PageData.newInstance().builder(userId, userName, "", reqData, componentCode, componentMethod, url, sessionId, appId, headers); |
| | | pd.setMethod(request.getMethod().equals("GET") ? HttpMethod.GET : HttpMethod.POST); |
| | | |
| | | logger.debug("切面 获取到的pd=" + JSONObject.toJSONString(pd)); |
| | |
| | | return o; |
| | | } catch (Throwable e) { |
| | | logger.error("执行方法异常", e); |
| | | return new ResponseEntity("内部异常" + e.getLocalizedMessage(), HttpStatus.BAD_REQUEST); |
| | | return new ResponseEntity(e.getLocalizedMessage(), HttpStatus.BAD_REQUEST); |
| | | } |
| | | } |
| | | |
| | |
| | | */ |
| | | private String getToken(HttpServletRequest request) throws FilterException { |
| | | String token = ""; |
| | | if (request.getCookies() == null || request.getCookies().length == 0) { |
| | | return token; |
| | | } |
| | | for (Cookie cookie : request.getCookies()) { |
| | | if (CommonConstant.COOKIE_AUTH_TOKEN.equals(cookie.getName())) { |
| | | token = cookie.getValue(); |
| | | } |
| | | // if (request.getCookies() != null && request.getCookies().length > 0) { |
| | | // for (Cookie cookie : request.getCookies()) { |
| | | // if (CommonConstant.COOKIE_AUTH_TOKEN.equals(cookie.getName())) { |
| | | // token = cookie.getValue(); |
| | | // } |
| | | // } |
| | | // } |
| | | String authorization = request.getHeader("Authorization"); |
| | | |
| | | if(StringUtil.isEmpty(token) && !StringUtil.isEmpty(authorization)){ |
| | | token = authorization.substring("Bearer ".length()); |
| | | } |
| | | return token; |
| | | } |
| | |
| | | * @throws IOException |
| | | */ |
| | | private void writeCookieInfo(IPageData pd, ServletRequestAttributes attributes) throws IOException { |
| | | // 这里目前只写到组件级别,如果需要 写成方法级别 |
| | | if (!StringUtil.isNullOrNone(pd.getToken()) && "login".equals(pd.getComponentCode())) { |
| | | HttpServletResponse response = attributes.getResponse(); |
| | | Cookie cookie = new Cookie(CommonConstant.COOKIE_AUTH_TOKEN, pd.getToken()); |
| | | cookie.setHttpOnly(true); |
| | | cookie.setPath("/"); |
| | | response.addCookie(cookie); |
| | | response.flushBuffer(); |
| | | // 这里目前只写到组件级别,如果需要 写成方法级别 && "login".equals(pd.getComponentCode()) |
| | | //todo 未包含token 不做处理 |
| | | if (StringUtil.isNullOrNone(pd.getToken())) { |
| | | return; |
| | | } |
| | | HttpServletResponse response = attributes.getResponse(); |
| | | |
| | | //讲token写入到cookies 中 |
| | | Cookie cookie = new Cookie(CommonConstant.COOKIE_AUTH_TOKEN, pd.getToken()); |
| | | cookie.setHttpOnly(true); |
| | | cookie.setPath("/"); |
| | | |
| | | response.addCookie(cookie); |
| | | //response.addHeader("Set-Cookie","SameSite=None"); |
| | | |
| | | response.flushBuffer(); |
| | | |
| | | |
| | | } |
| | | } |