| | |
| | | */ |
| | | 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())) { |
| | | // 这里目前只写到组件级别,如果需要 写成方法级别 && "login".equals(pd.getComponentCode()) |
| | | if (!StringUtil.isNullOrNone(pd.getToken()) ) { |
| | | HttpServletResponse response = attributes.getResponse(); |
| | | 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(); |
| | | } |
| | | |