| | |
| | | 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(); |
| | | RequestContext currentContext = RequestContext.getCurrentContext(); |
| | | //获取request对象 |
| | | HttpServletRequest request = currentContext.getRequest(); |
| | | //security会把一个SecurityContextImpl对象存储到session中,此对象中有当前用户的各种资料 |
| | | SecurityContextImpl securityContextImpl = (SecurityContextImpl) request |
| | | .getSession().getAttribute("SPRING_SECURITY_CONTEXT"); |
| | | Authentication authentication = securityContextImpl.getAuthentication(); |
| | | Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); |
| | | |
| | | if (authentication != null && !(authentication instanceof AnonymousAuthenticationToken)) { |
| | | RequestContext currentContext = RequestContext.getCurrentContext(); |
| | | // 获取request对象 |
| | | HttpServletRequest request = currentContext.getRequest(); |
| | | //security会把一个SecurityContextImpl对象存储到session中,此对象中有当前用户的各种资料 |
| | | SecurityContextImpl securityContextImpl = (SecurityContextImpl) request |
| | | .getSession().getAttribute("SPRING_SECURITY_CONTEXT"); |
| | | authentication = securityContextImpl.getAuthentication(); |
| | | Object principal = authentication.getPrincipal(); |
| | | RequestContext ctx = RequestContext.getCurrentContext(); |
| | | if (principal instanceof SysUser) { |
| | |
| | | OAuth2Authentication oauth2Authentication = (OAuth2Authentication) authentication; |
| | | String clientId = oauth2Authentication.getOAuth2Request().getClientId(); |
| | | // if (CLIENTID.equals(clientId)) { |
| | | SysUser user = (SysUser) authentication.getPrincipal(); |
| | | /** |
| | | * 将组织中为空的拦截 |
| | | */ |
| | | List<SysUserOrg> sysUserOrgs = getSysUserOrg(user.getId()); |
| | | if (sysUserOrgs == null || sysUserOrgs.isEmpty()) { |
| | | ctx.setSendZuulResponse(false); |
| | | ctx.addZuulResponseHeader("Content-Type","application/json;charset=UTF-8"); |
| | | SysUser user = (SysUser) authentication.getPrincipal(); |
| | | /** |
| | | * 将组织中为空的拦截 |
| | | */ |
| | | List<SysUserOrg> sysUserOrgs = this.getSysUserOrg(user.getId()); |
| | | if (sysUserOrgs == null || sysUserOrgs.isEmpty()) { |
| | | ctx.setSendZuulResponse(false); |
| | | ctx.addZuulResponseHeader("Content-Type", "application/json;charset=UTF-8"); |
| | | // String str = new String("您的组织已经被禁用,请联系管理员".getBytes("utf-8"), "utf-8"); |
| | | ctx.setResponseBody(JSON.toJSONString(ResultBody.fail(1000, "您的组织已经被禁用,请联系管理员"))); |
| | | } |
| | | else { |
| | | ctx.setResponseBody(JSON.toJSONString(ResultBody.fail(1000, "您的组织已经被禁用1,请联系管理员"))); |
| | | } else { |
| | | // List<Long> collect = sysUserOrgs.stream().map(e -> e.getOrgId()).collect(Collectors.toList()); |
| | | // List<SysOrganization> sysOrganizations = getSysOrganization(); |
| | | // List<Long> orgIds = sysOrganizations.stream().filter(e -> e.getEnabled() == true && collect.contains(e.getId())).map(e -> e.getId()).collect(Collectors.toList()); |
| | |
| | | // ctx.setSendZuulResponse(false); |
| | | // ctx.setResponseBody(JSON.toJSONString(ResultBody.fail(1000, "您的组织已经被禁用,请联系管理员"))); |
| | | // } |
| | | //根据fegin客户端查询状态 |
| | | Map<String,Object> map; |
| | | for (SysUserOrg sysUserOrg : sysUserOrgs) { |
| | | map=new HashMap<>(); |
| | | map.put("id",sysUserOrg.getOrgId()); |
| | | List<SysOrganization> sysOrganizations = JSON.parseArray(JSON.toJSONString(sysOrganizationService.getListByMap(map).getData()), SysOrganization.class); |
| | | if(sysOrganizations==null||sysOrganizations.size()<=0){ |
| | | ctx.setSendZuulResponse(false); |
| | | ctx.addZuulResponseHeader("Content-Type","application/json;charset=UTF-8"); |
| | | ctx.setResponseBody(JSON.toJSONString(ResultBody.fail(1000, "您的组织已经被禁用,请联系管理员"))); |
| | | }else { |
| | | for (SysOrganization sysOrganization : sysOrganizations) { |
| | | if(!sysOrganization.getEnabled()||sysOrganization.getIsDel()){ |
| | | ctx.setSendZuulResponse(false); |
| | | ctx.addZuulResponseHeader("Content-Type","application/json;charset=UTF-8"); |
| | | ctx.setResponseBody(JSON.toJSONString(ResultBody.fail(1000, "您的组织已经被禁用,请联系管理员"))); |
| | | } |
| | | //根据fegin客户端查询状态 |
| | | Map<String, Object> map; |
| | | for (SysUserOrg sysUserOrg : sysUserOrgs) { |
| | | map = new HashMap<>(); |
| | | map.put("id", sysUserOrg.getOrgId()); |
| | | List<SysOrganization> sysOrganizations = JSON.parseArray(JSON.toJSONString(sysOrganizationService.getListByMap(map).getData()), SysOrganization.class); |
| | | System.out.println("5555555555555555"); |
| | | System.out.println(sysOrganizations.size()); |
| | | for (SysOrganization sysOrganization : sysOrganizations) { |
| | | System.out.println(sysOrganization.getOrgName()); |
| | | } |
| | | System.out.println("66666666666"); |
| | | if (sysOrganizations == null || sysOrganizations.size() <= 0) { |
| | | ctx.setSendZuulResponse(false); |
| | | ctx.addZuulResponseHeader("Content-Type", "application/json;charset=UTF-8"); |
| | | ctx.setResponseBody(JSON.toJSONString(ResultBody.fail(1000, "您的组织已经被禁用2,请联系管理员"))); |
| | | } else { |
| | | for (SysOrganization sysOrganization : sysOrganizations) { |
| | | if (!sysOrganization.getEnabled() || sysOrganization.getIsDel()) { |
| | | ctx.setSendZuulResponse(false); |
| | | ctx.addZuulResponseHeader("Content-Type", "application/json;charset=UTF-8"); |
| | | ctx.setResponseBody(JSON.toJSONString(ResultBody.fail(1000, "您的组织已经被禁用3,请联系管理员"))); |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | } |
| | | // } |
| | | } |
| | | } |
| | |
| | | public List<SysUserOrg> getSysUserOrg(Long str) { |
| | | //获取组织 Redis中获取 |
| | | List<SysUserOrg> sysUserOrgs = JSON.parseArray(JSON.toJSONString(redisUtils.hget(RedisConstant.USER_ORGANIZATION, str.toString())), SysUserOrg.class); |
| | | System.out.println("3333333333333333333333"); |
| | | System.out.println(sysUserOrgs.size()); |
| | | for (SysUserOrg sysUserOrg : sysUserOrgs) { |
| | | System.out.println(sysUserOrg.getFromLevel()); |
| | | } |
| | | System.out.println("444444444444444444"); |
| | | if (sysUserOrgs == null || sysUserOrgs.size() <= 0) { |
| | | //在数据库查询 |
| | | Map<String, Object> map = new HashMap<>(); |