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

@ -1,10 +1,12 @@
package com.daqing.financial.hrauth.filter; package com.daqing.financial.hrauth.filter;
import com.alibaba.fastjson.JSON;
import com.daqing.financial.hrauth.enums.Constants; import com.daqing.financial.hrauth.enums.Constants;
import com.daqing.financial.hrauth.handle.SecurityUser; import com.daqing.financial.hrauth.handle.SecurityUser;
import com.daqing.financial.hrauth.service.impl.UserDetailsServiceImpl; import com.daqing.financial.hrauth.service.impl.UserDetailsServiceImpl;
import com.daqing.financial.hrauth.util.MultiReadHttpServletRequest; import com.daqing.financial.hrauth.util.MultiReadHttpServletRequest;
import com.daqing.financial.hrauth.util.MultiReadHttpServletResponse; import com.daqing.financial.hrauth.util.MultiReadHttpServletResponse;
import com.daqing.framework.model.response.ResponseResult;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.security.access.AccessDeniedException; import org.springframework.security.access.AccessDeniedException;
@ -19,6 +21,7 @@ import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
/** /**
@ -38,6 +41,25 @@ public class MyAuthenticationFilter extends OncePerRequestFilter {
this.userDetailsService = userDetailsService; 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 @Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
System.out.println("请求头类型: " + request.getContentType()); System.out.println("请求头类型: " + request.getContentType());
@ -70,15 +92,17 @@ public class MyAuthenticationFilter extends OncePerRequestFilter {
// 检查token // 检查token
SecurityUser securityUser = userDetailsService.getUserByToken(token); SecurityUser securityUser = userDetailsService.getUserByToken(token);
if (securityUser == null || securityUser.getCurrentUserInfo() == null) { 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()); UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(securityUser, null, securityUser.getAuthorities());
// 全局注入角色权限信息和登录用户基本信息 // 全局注入角色权限信息和登录用户基本信息
SecurityContextHolder.getContext().setAuthentication(authentication); SecurityContextHolder.getContext().setAuthentication(authentication);
} }
/* else { else {
throw new AccessDeniedException("TOKEN不存在,请重新登录!"); throw new AccessDeniedException("TOKEN不存在,请重新登录!");
}*/ }
filterChain.doFilter(wrappedRequest, wrappedResponse); filterChain.doFilter(wrappedRequest, wrappedResponse);
} finally { } finally {
stopWatch.stop(); stopWatch.stop();

Loading…
Cancel
Save