liurunyu
2023-11-07 b2364d7c11aea1b2a512184102036517fccd1385
pipIrr-platform/pipIrr-web/pipIrr-web-sso/src/main/java/com/dy/sso/busi/SsoCtrl.java
@@ -1,6 +1,7 @@
package com.dy.sso.busi;
import com.dy.common.aop.SsoVo;
import com.dy.common.multiDataSource.DataSourceContext;
import com.dy.common.webUtil.BaseResponse;
import com.dy.common.webUtil.BaseResponseUtils;
import com.dy.common.webUtil.ResultCodeMsg;
@@ -44,7 +45,6 @@
    //@Autowired
    //private CacheManager cacheManager ;
    @Autowired
    public void setSv(SsoSv sv ){
        this.sv = sv ;
@@ -54,6 +54,7 @@
    /**
     * 客户端请求用户登录,客户端提交Json数据
     * @param vo 用户登录值对象
     * @param bindingResult 输入验证
     * @return 登录用户值对象
     */
    @Operation(summary = "单点登录", description = "提交登录用户值对象(json格式),进行单点登录")
@@ -119,6 +120,11 @@
        if(bindingResult != null && bindingResult.hasErrors()){
            return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
        }
        if(vo.orgTag == null || vo.orgTag.trim().length() == 0){
            return BaseResponseUtils.buildFail("未选择组织单位");
        }
        //把组织单位标签作为数据源名称
        DataSourceContext.set(vo.orgTag);
        String uuid ;
        BaUser userPo ;
@@ -182,19 +188,72 @@
     * 此方法供子模块系统调用,所以不公开在API接口中
     * 方法功能:验证是否已经登录,如果登录了,再验证权限
     * @param token 登录用户token
     * @param power 验证一个权限
     * @param allPower 验证所有权限
     * @param anyPower 验证任何一个权限
     * @param privilege 验证一个权限
     * @param allPrivilege 验证所有权限
     * @param anyPrivilege 验证任何一个权限
     * @return SsoVo
     */
    @Hidden
    @GetMapping(path = "ssoCheck")
    public SsoVo ssoCheck(String token, String power, String[] allPower, String[] anyPower){
    public SsoVo ssoCheck(String token, String privilege, String[] allPrivilege, String[] anyPrivilege){
        BaUser userPo = this.sv.getByUuid(token) ;
        SsoVo vo = new SsoVo();
        if(userPo != null){
            vo.logined = true ;
            vo.hasPower = true ;
            vo.hasPower = false ;//默认是无权限
            if(userPo.supperAdmin != null && userPo.supperAdmin == 1){
                vo.hasPower = true ;
            }else{
                if(userPo.privileges != null && userPo.privileges.size() > 0){
                    if(privilege != null && !privilege.trim().equals("")){
                        int intPri = Integer.parseInt(privilege) ;
                        for(Integer pri : userPo.privileges){
                            if(pri == intPri){
                                vo.hasPower = true ;
                                break ;
                            }
                        }
                    }else{
                        if(allPrivilege != null && allPrivilege.length > 0){
                            int intPri ;
                            boolean ok = false ;
                            boolean allOk = true ;
                            for(String strPri : allPrivilege){
                                intPri = Integer.parseInt(strPri) ;
                                for(Integer pri : userPo.privileges){
                                    if(pri == intPri){
                                        ok = true ;
                                        break ;
                                    }
                                }
                                if(!ok){
                                    allOk = false ;
                                    break ;
                                }
                            }
                            if(allOk){
                                vo.hasPower = true ;
                            }
                        }else{
                            int intPri ;
                            if(anyPrivilege != null && anyPrivilege.length > 0){
                                for(String strPri : anyPrivilege){
                                    intPri = Integer.parseInt(strPri) ;
                                    for(Integer pri : userPo.privileges){
                                        if(pri == intPri){
                                            vo.hasPower = true ;
                                            break ;
                                        }
                                    }
                                    if(vo.hasPower){
                                        break ;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            vo.dataSourceName = userPo.getOrgTag() ;
        }else{
            vo.logined = false ;