| | |
| | | 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 com.kidgrow.common.model.SysOrganization; |
| | | import com.kidgrow.common.model.SysUser; |
| | | import com.kidgrow.common.model.SysUserOrg; |
| | | import com.kidgrow.common.utils.AddrUtil; |
| | | import com.kidgrow.redis.util.RedisConstant; |
| | | import com.kidgrow.redis.util.RedisUtils; |
| | | import com.kidgrow.zuul.feign.SysOrganizationService; |
| | | import com.kidgrow.zuul.feign.SysUserOrgService; |
| | | import com.netflix.zuul.ZuulFilter; |
| | | import com.netflix.zuul.context.RequestContext; |
| | | import eu.bitwalker.useragentutils.UserAgent; |
| | | import lombok.SneakyThrows; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.hibernate.validator.constraints.NotBlank; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.cloud.netflix.zuul.filters.support.FilterConstants; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.security.authentication.AnonymousAuthenticationToken; |
| | | import org.springframework.security.core.Authentication; |
| | | import org.springframework.security.core.context.SecurityContextHolder; |
| | | import org.springframework.security.oauth2.provider.OAuth2Authentication; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import static org.springframework.cloud.netflix.zuul.filters.support.FilterConstants.PRE_DECORATION_FILTER_ORDER; |
| | | |
| | |
| | | //运营端进行 |
| | | OAuth2Authentication oauth2Authentication = (OAuth2Authentication) authentication; |
| | | String clientId = oauth2Authentication.getOAuth2Request().getClientId(); |
| | | if (CLIENTID.equals(clientId)) { |
| | | // 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"); |
| | | // String str = new String("您的组织已经被禁用,请联系管理员".getBytes("utf-8"), "utf-8"); |
| | | ctx.setResponseBody(JSON.toJSONString(ResultBody.fail(1000, "您的组织已经被禁用,请联系管理员"))); |
| | | } 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()); |
| | | if (orgIds == null || orgIds.size() <= 0) { |
| | | ctx.setSendZuulResponse(false); |
| | | ctx.setResponseBody(JSON.toJSONString(ResultBody.fail(1000, "您的组织已经被禁用,请联系管理员"))); |
| | | } |
| | | } |
| | | } |
| | | 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()); |
| | | // if (orgIds == null || orgIds.size() <= 0) { |
| | | // 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, "您的组织已经被禁用,请联系管理员"))); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | // } |
| | | } |
| | | } |
| | | return null; |