|  |  | 
 |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
 |  |  | import org.springframework.beans.factory.annotation.Value; | 
 |  |  | import org.springframework.core.annotation.Order; | 
 |  |  | import org.springframework.http.*; | 
 |  |  | import org.springframework.stereotype.Component; | 
 |  |  | import org.springframework.web.client.RestTemplate; | 
 |  |  | import org.springframework.web.util.UriComponentsBuilder; | 
 |  |  |  | 
 |  |  | import java.lang.reflect.Method; | 
 |  |  | import java.util.Objects; | 
 |  |  | 
 |  |  |     @Value("${pipIrr.global.dev}") | 
 |  |  |     public String isDevStage ;//是否为开发阶段 | 
 |  |  |  | 
 |  |  |     @Value("${pipIrr.sso.checkUrl}") | 
 |  |  |     public String ssoCheckUrl; | 
 |  |  |  | 
 |  |  |     private RestTemplate restTemplate; | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  |     public void setRestTemplate(RestTemplate restTemplate){ | 
 |  |  |         this.restTemplate = restTemplate ; | 
 |  |  |     } | 
 |  |  |     private SsoCheck ssoCheck ; | 
 |  |  |  | 
 |  |  |     @Pointcut("@annotation(com.dy.common.aop.SsoAop)") | 
 |  |  |     public void ssoPointCut() { | 
 |  |  | 
 |  |  |             SsoAop aop = method.getAnnotation(SsoAop.class) ; | 
 |  |  |             if (Objects.nonNull(aop)){ | 
 |  |  |                 String token = UserTokenContext.get() ; | 
 |  |  |                 Object rObj = this.check(token); | 
 |  |  |                 Object rObj = this.ssoCheck.check(token); | 
 |  |  |                 if(rObj != null){ | 
 |  |  |                     if(rObj instanceof SsoVo ssoVo){ | 
 |  |  |                         if(ssoVo.logined){ | 
 |  |  | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 调用SSO系统进行验证 | 
 |  |  |      * @param token Header中的用户token | 
 |  |  |      * @return 返回对象 | 
 |  |  |      */ | 
 |  |  |     private Object check(String token){ | 
 |  |  |         if(!StringUtils.isNullOrEmpty(ssoCheckUrl)){ | 
 |  |  |             String url = UriComponentsBuilder.fromUriString(ssoCheckUrl) | 
 |  |  |                     .queryParam("token", token) | 
 |  |  |                     .build() | 
 |  |  |                     .toUriString(); | 
 |  |  |             HttpHeaders headers = new HttpHeaders(); | 
 |  |  |             headers.setContentType(MediaType.parseMediaType("application/json;charset=UTF-8")); | 
 |  |  |  | 
 |  |  |             HttpEntity<?> httpEntity = new HttpEntity<>(headers); | 
 |  |  |             ResponseEntity<SsoVo> response = null; | 
 |  |  |             try { | 
 |  |  |                 // 通过Get方式调用接口 | 
 |  |  |                 response = restTemplate.exchange(url, HttpMethod.GET, httpEntity, SsoVo.class); | 
 |  |  |             } catch (Exception e) { | 
 |  |  |                 e.printStackTrace(); | 
 |  |  |             } | 
 |  |  |             assert response != null; | 
 |  |  |             return response.getBody(); | 
 |  |  |         }else { | 
 |  |  |             return BaseResponseUtils.buildError("后端系统出错,未得到SsoCheckUrl"); | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  | } |