| | |
| | | import com.dy.common.multiDataSource.DataSourceContext; |
| | | import com.dy.common.webFilter.UserTokenContext; |
| | | import com.dy.common.webUtil.BaseResponseUtils; |
| | | import com.mysql.jdbc.StringUtils; |
| | | import com.mysql.cj.util.StringUtils; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.aspectj.lang.ProceedingJoinPoint; |
| | | import org.aspectj.lang.annotation.Around; |
| | |
| | | @Component |
| | | public class SsoAspect { |
| | | |
| | | @Value("${pipIrr.global.dev}") |
| | | public String isDevStage ;//是否为开发阶段 |
| | | |
| | | @Value("${pipIrr.sso.checkUrl}") |
| | | public String SsoCheckUrl ; |
| | | |
| | |
| | | |
| | | @Around("dyPointCut()") |
| | | public Object execute(ProceedingJoinPoint point) throws Throwable { |
| | | MethodSignature signature = (MethodSignature) point.getSignature(); |
| | | Method method = signature.getMethod(); |
| | | SsoAop aop = method.getAnnotation(SsoAop.class) ; |
| | | if (Objects.nonNull(aop)){ |
| | | String token = UserTokenContext.get() ; |
| | | String power = aop.power() ; |
| | | String[] allPower = aop.ifAllPower() ; |
| | | String[] anyPower = aop.ifAnyPower() ; |
| | | Object rObj = this.check(token, power, allPower, anyPower); |
| | | if(rObj != null){ |
| | | if(rObj instanceof SsoVo ssoVo){ |
| | | if(ssoVo.logined){ |
| | | if(ssoVo.hasPower){ |
| | | if(!StringUtils.isNullOrEmpty(ssoVo.dataSourceName)){ |
| | | DataSourceContext.set(ssoVo.dataSourceName); |
| | | return point.proceed(); |
| | | if(isDevStage != null && !isDevStage.trim().equals("") && isDevStage.trim().equalsIgnoreCase("true")){ |
| | | return point.proceed(); |
| | | }else{ |
| | | MethodSignature signature = (MethodSignature) point.getSignature(); |
| | | Method method = signature.getMethod(); |
| | | SsoAop aop = method.getAnnotation(SsoAop.class) ; |
| | | if (Objects.nonNull(aop)){ |
| | | String power = aop.value() ; |
| | | if(power.trim().equals("")){ |
| | | power = aop.power() ; |
| | | } |
| | | if(power.trim().equals("-1")){ |
| | | //不进行登录及权限验证 |
| | | return point.proceed(); |
| | | }else{ |
| | | String[] allPower = aop.ifAllPower() ; |
| | | String[] anyPower = aop.ifAnyPower() ; |
| | | String token = UserTokenContext.get() ; |
| | | Object rObj = this.check(token, power, allPower, anyPower); |
| | | if(rObj != null){ |
| | | if(rObj instanceof SsoVo ssoVo){ |
| | | if(ssoVo.logined){ |
| | | if(ssoVo.hasPower){ |
| | | if(!StringUtils.isNullOrEmpty(ssoVo.dataSourceName)){ |
| | | DataSourceContext.set(ssoVo.dataSourceName); |
| | | return point.proceed(); |
| | | }else{ |
| | | //无数据源 |
| | | return BaseResponseUtils.buildError("后端系统出错,未得到当前登录用户所属机构标签(数据源名)") ; |
| | | } |
| | | }else{ |
| | | //无权限 |
| | | return BaseResponseUtils.buildNoPower() ; |
| | | } |
| | | }else{ |
| | | //无数据源 |
| | | return BaseResponseUtils.buildError("后端系统出错,未得到当前登录用户所属机构标签(数据源名)") ; |
| | | //未登录 |
| | | return BaseResponseUtils.buildToLogin() ; |
| | | } |
| | | }else{ |
| | | //无权限 |
| | | return BaseResponseUtils.buildNoPower() ; |
| | | return rObj ; |
| | | } |
| | | }else{ |
| | | //未登录 |
| | | return BaseResponseUtils.buildToLogin() ; |
| | | return BaseResponseUtils.buildError("后端系统出错,check方法返回null") ; |
| | | } |
| | | }else{ |
| | | return rObj ; |
| | | } |
| | | }else{ |
| | | return BaseResponseUtils.buildError("后端系统出错,check方法返回null") ; |
| | | //已经进入注解处理了,还得不到注解,这种情况是不可能的。 |
| | | return BaseResponseUtils.buildError("后端系统出错,DyAop注解为null") ; |
| | | } |
| | | }else{ |
| | | //已经进入注解处理了,还得不到注解,这种情况是不可能的。 |
| | | return BaseResponseUtils.buildError("后端系统出错,DyAop注解为null") ; |
| | | } |
| | | } |
| | | |