TOKEN过期返回错误编码处理

master
shijie 4 years ago
parent 153e2fde75
commit 76b053e21f
  1. 13
      dq-financial-guarantee/src/main/java/com/daqing/financial/guarantee/service/impl/DgApplyAmountInfoServiceImpl.java
  2. 30
      dq-financial-hrms-auth/src/main/java/com/daqing/financial/hrauth/filter/MyAuthenticationFilter.java

@ -237,11 +237,15 @@ public class DgApplyAmountInfoServiceImpl extends ServiceImpl<DgApplyAmountInfoM
applyAmountInfo.setCompanyId(dgApplyAmountInfo.getCompanyId());
ResponseResult result = crmsFeignService.queryCustomerInfoById(applyAmountInfo);
LinkedHashMap linkedList = (LinkedHashMap)result.getData();
Object o1 = linkedList.get("linkman");
Object o2 = linkedList.get("linkPhone");
//备份企业信息,以防企业信息改动从而影响业务信息变更
DgBusinessCompany dgBusinessCompany = new DgBusinessCompany();
BeanUtils.copyProperties(businessApplication,dgBusinessCompany);
dgBusinessCompany.setBusinessId(dgApplyAmountInfo.getId());
dgBusinessCompany.setLinkman(o1.toString());
dgBusinessCompany.setLinkPhone(o2.toString());
dgBusinessCompanyMapper.insert(dgBusinessCompany);
//如果审批状态为审核中,操作状态为已发起,则往担保部经理添加一条待审核的记录
@ -466,9 +470,18 @@ public class DgApplyAmountInfoServiceImpl extends ServiceImpl<DgApplyAmountInfoM
//根据业务id删除对应的附件信息
dgEnclosureInfoMapper.delete(new QueryWrapper<DgEnclosureInfo>().eq("business_id",businessApplication.getBusinessId()));
//根据企业id查询企业详情
DgApplyAmountInfoRequest applyAmountInfo = new DgApplyAmountInfoRequest();
applyAmountInfo.setCompanyId(dgApplyAmountInfo.getCompanyId());
ResponseResult result = crmsFeignService.queryCustomerInfoById(applyAmountInfo);
LinkedHashMap linkedList = (LinkedHashMap)result.getData();
Object o1 = linkedList.get("linkman");
Object o2 = linkedList.get("linkPhone");
//修改备份企业信息
DgBusinessCompany dgBusinessCompany = new DgBusinessCompany();
BeanUtils.copyProperties(businessApplication,dgBusinessCompany);
dgBusinessCompany.setLinkPhone(String.valueOf(o2));
dgBusinessCompany.setLinkman(String.valueOf(o1));
System.out.println("dgBusinessCompany============="+dgBusinessCompany);
dgBusinessCompanyMapper.update(dgBusinessCompany,new QueryWrapper<DgBusinessCompany>()
.eq("business_id",businessApplication.getBusinessId()));

@ -1,10 +1,12 @@
package com.daqing.financial.hrauth.filter;
import com.alibaba.fastjson.JSON;
import com.daqing.financial.hrauth.enums.Constants;
import com.daqing.financial.hrauth.handle.SecurityUser;
import com.daqing.financial.hrauth.service.impl.UserDetailsServiceImpl;
import com.daqing.financial.hrauth.util.MultiReadHttpServletRequest;
import com.daqing.financial.hrauth.util.MultiReadHttpServletResponse;
import com.daqing.framework.model.response.ResponseResult;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.security.access.AccessDeniedException;
@ -19,6 +21,7 @@ import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
/**
@ -38,6 +41,25 @@ public class MyAuthenticationFilter extends OncePerRequestFilter {
this.userDetailsService = userDetailsService;
}
private static void printJson(HttpServletResponse response) {
ResponseResult responseResult = new ResponseResult(false,401,"TOKEN已过期,请重新登录","TOKEN已过期,请重新登录");
String content = JSON.toJSONString(responseResult);
printContent(response, content);
}
private static void printContent(HttpServletResponse response, String content) {
try {
response.reset();
response.setContentType("application/json");
response.setHeader("Cache-Control", "no-store");
response.setCharacterEncoding("UTF-8");
PrintWriter pw = response.getWriter();
pw.write(content);
pw.flush();
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
System.out.println("请求头类型: " + request.getContentType());
@ -70,15 +92,17 @@ public class MyAuthenticationFilter extends OncePerRequestFilter {
// 检查token
SecurityUser securityUser = userDetailsService.getUserByToken(token);
if (securityUser == null || securityUser.getCurrentUserInfo() == null) {
throw new AccessDeniedException("TOKEN已过期,请重新登录!");
//throw new AccessDeniedException("TOKEN已过期,请重新登录!");
printJson(response);
return;
}
UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(securityUser, null, securityUser.getAuthorities());
// 全局注入角色权限信息和登录用户基本信息
SecurityContextHolder.getContext().setAuthentication(authentication);
}
/* else {
else {
throw new AccessDeniedException("TOKEN不存在,请重新登录!");
}*/
}
filterChain.doFilter(wrappedRequest, wrappedResponse);
} finally {
stopWatch.stop();

Loading…
Cancel
Save