| | |
| | | package com.kidgrow.zuul.filter; |
| | | |
| | | import cn.hutool.core.collection.CollectionUtil; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.kidgrow.common.constant.CommonConstant; |
| | | import com.kidgrow.common.constant.SecurityConstants; |
| | | import com.kidgrow.common.model.ResultBody; |
| | |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.net.URLEncoder; |
| | | import java.util.List; |
| | | |
| | | import static org.springframework.cloud.netflix.zuul.filters.support.FilterConstants.FORM_BODY_WRAPPER_FILTER_ORDER; |
| | | import static org.springframework.cloud.netflix.zuul.filters.support.FilterConstants.PRE_DECORATION_FILTER_ORDER; |
| | | |
| | | /** |
| | | * 石家庄喜高科技有限责任公司 版权所有 © Copyright 2020<br> |
| | | * |
| | | * @Description: 将认证用户的相关信息放入header中, 后端服务可以直接读取使用<br> |
| | | * @Description: 将认证用户的相关信息放入header中, 后端服务可以直接读取使用 包含了----组织的拦截---<br> |
| | | * @Project: <br> |
| | | * @CreateDate: Created in 2020/2/21 10:12 <br> |
| | | * @Author: <a href="4345453@kidgrow.com">liuke</a> |
| | |
| | | ctx.addZuulRequestHeader(SecurityConstants.USER_HEADER, user.getUsername()); |
| | | ctx.addZuulRequestHeader(SecurityConstants.USER_REAL_NAME, "");//待完善 |
| | | List<SysOrganization> organizations = (List<SysOrganization>)user.getOrganizations(); |
| | | //如果有组织架构 |
| | | if(organizations!=null && organizations.size()==2){ |
| | | if(organizations.get(0)!=null){ |
| | | ctx.addZuulRequestHeader(SecurityConstants.USER_ORG_ID_HEADER,String.valueOf(organizations.get(0).getId())); |
| | | ctx.addZuulRequestHeader(SecurityConstants.USER_ORG_NAME_HEADER, URLEncoder.encode(organizations.get(0).getOrgName(),"UTF-8")); |
| | | tenantId=String.valueOf(organizations.get(0).getId()); |
| | | }else{ |
| | | return ResultBody.failed("您的组织,已经被禁用,请联系管理员"); |
| | | } |
| | | if(organizations.get(1)!=null){ |
| | | ctx.addZuulRequestHeader(SecurityConstants.USER_DEP_ID_HEADER,String.valueOf(organizations.get(1).getId())); |
| | | ctx.addZuulRequestHeader(SecurityConstants.USER_DEP_NAME_HEADER,URLEncoder.encode(organizations.get(1).getOrgName(),"UTF-8")); |
| | | }else { |
| | | return ResultBody.failed("您组织部门或者科室,已经被禁用,请联系管理员"); |
| | | } |
| | | } |
| | | //如果没有有组织架构 |
| | | //将组织数据 存到header 里面 |
| | | ctx.addZuulRequestHeader(SecurityConstants.USER_ORGS_HEADER, JSON.toJSONString(organizations)); |
| | | // log.error("用户ID写入Header成功,用户ID为:"+String.valueOf(user.getId())); |
| | | } |
| | | |