| | |
| | | package com.doumee.config.cloudfilter; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.doumee.config.annotation.CloudRequiredPermission; |
| | | import com.doumee.config.annotation.LoginNoRequired; |
| | | import com.doumee.core.constants.ResponseStatus; |
| | | import com.doumee.core.exception.BusinessException; |
| | | import com.doumee.core.model.ApiResponse; |
| | | import com.doumee.core.model.LoginUserInfo; |
| | | import com.doumee.core.utils.Constants; |
| | | import org.apache.commons.lang3.StringUtils; |
| | |
| | | //获取token |
| | | Cookie[] cookies = request.getCookies(); |
| | | String token = request.getHeader(Constants.HEADER_USER_TOKEN); // 从 http 请求头中取出 token |
| | | if(StringUtils.isBlank(token)){ |
| | | if(StringUtils.isBlank(token) && cookies != null){ |
| | | for(Cookie c :cookies){ |
| | | if(StringUtils.equals(c.getName(),Constants.HEADER_USER_TOKEN)){ |
| | | token = c.getValue(); |
| | |
| | | } |
| | | } |
| | | if (!hasPermission) { |
| | | throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "没有该操作权限"); |
| | | return writeBusinessError(response, ResponseStatus.NOT_ALLOWED.getCode(), "没有该操作权限"); |
| | | } |
| | | } |
| | | } |
| | |
| | | }catch (Exception e){ |
| | | }*/ |
| | | } else { |
| | | throw new BusinessException(ResponseStatus.NO_LOGIN.getCode(),"未登录"); |
| | | return writeBusinessError(response, ResponseStatus.NO_LOGIN.getCode(), "未登录"); |
| | | } |
| | | } |
| | | }else{ |
| | | throw new BusinessException(ResponseStatus.NO_LOGIN.getCode(),"未登录"); |
| | | } else { |
| | | return writeBusinessError(response, ResponseStatus.NO_LOGIN.getCode(), "未登录"); |
| | | } |
| | | |
| | | return true; |
| | | } |
| | | |
| | | private boolean writeBusinessError(HttpServletResponse response, Integer code, String message) throws IOException { |
| | | response.setStatus(HttpServletResponse.SC_OK); |
| | | response.setHeader("content-type", "application/json;charset=UTF-8"); |
| | | response.getWriter().write(JSON.toJSONString(ApiResponse.failed(code, message))); |
| | | return false; |
| | | } |
| | | |
| | | private String getRequestBody(HttpServletRequest request) { |
| | | // 实现从request获取请求体的逻辑 |
| | | String body = null; |