| | |
| | | import org.springframework.cloud.netflix.zuul.filters.support.FilterConstants; |
| | | import org.springframework.security.authentication.AnonymousAuthenticationToken; |
| | | import org.springframework.security.core.Authentication; |
| | | import org.springframework.security.core.context.SecurityContextHolder; |
| | | import org.springframework.security.core.context.SecurityContextImpl; |
| | | import org.springframework.security.oauth2.provider.OAuth2Authentication; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | |
| | | @SneakyThrows |
| | | @Override |
| | | public Object run() { |
| | | Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); |
| | | // Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); |
| | | |
| | | RequestContext currentContext = RequestContext.getCurrentContext(); |
| | | //获取request对象 |
| | | HttpServletRequest request = currentContext.getRequest(); |
| | | |
| | | SecurityContextImpl securityContextImpl = (SecurityContextImpl) request |
| | | .getSession().getAttribute("SPRING_SECURITY_CONTEXT"); |
| | | Authentication authentication = securityContextImpl.getAuthentication(); |
| | | |
| | | if (authentication != null && !(authentication instanceof AnonymousAuthenticationToken)) { |
| | | Object principal = authentication.getPrincipal(); |
| | | RequestContext ctx = RequestContext.getCurrentContext(); |
| | |
| | | doctorId=sysDoctors.get(0).getId(); |
| | | departmentId=sysDoctors.get(0).getDepartmentId(); |
| | | departmentName=sysDoctors.get(0).getDepartmentName(); |
| | | ctx.addZuulRequestHeader(SecurityConstants.USER_ORG_NAME_HEADER, URLEncoder.encode(sysDoctors.get(0).getHospitalName(),"UTF-8")); |
| | | ctx.addZuulRequestHeader(SecurityConstants.USER_DEP_ID_HEADER,String.valueOf(departmentId)); |
| | | ctx.addZuulRequestHeader(SecurityConstants.USER_DEP_NAME_HEADER,URLEncoder.encode(departmentName,"UTF-8")); |
| | | } |
| | | ctx.addZuulRequestHeader(SecurityConstants.USER_ID_HEADER, String.valueOf(user.getId())); |
| | | ctx.addZuulRequestHeader(SecurityConstants.DOCTOR_ID_HEADER, String.valueOf(doctorId)); |
| | | ctx.addZuulRequestHeader(SecurityConstants.USER_HEADER, user.getUsername()); |
| | | |
| | | ctx.addZuulRequestHeader(SecurityConstants.USER_REAL_NAME,URLEncoder.encode(str,"UTF-8"));//待完善 |
| | | ctx.addZuulRequestHeader(SecurityConstants.USER_REAL_NAME,URLEncoder.encode(str,"UTF-8")); |
| | | ctx.addZuulRequestHeader(SecurityConstants.USER_HOSPITAL_ID_HEADER,hospital.toString()); |
| | | tenantId=hospital.toString(); |
| | | List<SysOrganization> organizations = (List<SysOrganization>) user.getOrganizations(); |
| | | //将组织数据 存到header 里面 |
| | | organizations.sort((e1,e2)->e1.getOrgLevel().compareTo(e2.getOrgLevel())); |
| | | if (organizations != null&&organizations.size()>0) { |
| | | System.out.println(organizations.size()); |
| | | System.out.println("111111111111111111111"); |
| | | for (SysOrganization organization : organizations) { |
| | | if(organization!=null){ |
| | | System.out.println(organization.getOrgLevel()); |
| | | } |
| | | } |
| | | System.out.println("22222222222222"); |
| | | organizations.sort((e1,e2)->e1.getOrgLevel().compareTo(e2.getOrgLevel())); |
| | | 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")); |
| | | ctx.addZuulRequestHeader(SecurityConstants.USER_DEP_ID_HEADER,String.valueOf(departmentId)); |
| | | ctx.addZuulRequestHeader(SecurityConstants.USER_DEP_NAME_HEADER,(departmentName.equals("")?URLEncoder.encode(organizations.get(organizations.size()-1).getOrgName(),"UTF-8"):departmentName)); |
| | | ctx.addZuulRequestHeader(SecurityConstants.USER_ORGS_HEADER,JSON.toJSONString(organizations)); |
| | | } |
| | | //将角色放到header |