From ac36bcd41519764d9a79eaffca3fe41e6ecb89f9 Mon Sep 17 00:00:00 2001 From: liurunyu <lry9898@163.com> Date: 星期四, 09 十一月 2023 11:30:17 +0800 Subject: [PATCH] 1、增加是否为开发阶段的配置,基于此配置,进行判断,若开发阶段设置临时数据源名称,及不进行登录及权限验证。 2、分配各个子系统id生成器的后缀 --- pipIrr-platform/pipIrr-web/pipIrr-web-sso/src/main/java/com/dy/sso/busi/SsoCtrl.java | 121 +++++++++++++++++++++++++++++++++++++--- 1 files changed, 112 insertions(+), 9 deletions(-) diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-sso/src/main/java/com/dy/sso/busi/SsoCtrl.java b/pipIrr-platform/pipIrr-web/pipIrr-web-sso/src/main/java/com/dy/sso/busi/SsoCtrl.java index 321f2c2..6ca0341 100644 --- a/pipIrr-platform/pipIrr-web/pipIrr-web-sso/src/main/java/com/dy/sso/busi/SsoCtrl.java +++ b/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 @@ /** * 瀹㈡埛绔姹傜敤鎴风櫥褰曪紝瀹㈡埛绔彁浜son鏁版嵁 * @param vo 鐢ㄦ埛鐧诲綍鍊煎璞� + * @param bindingResult 杈撳叆楠岃瘉 * @return 鐧诲綍鐢ㄦ埛鍊煎璞� */ @Operation(summary = "鍗曠偣鐧诲綍", description = "鎻愪氦鐧诲綍鐢ㄦ埛鍊煎璞★紙json鏍煎紡锛夛紝杩涜鍗曠偣鐧诲綍") @@ -85,7 +86,7 @@ try { //Boolean flag = cacheManager.getCacheNames().isEmpty() ; uuid = UUID.randomUUID().toString(); - userPo = this.sv.login(uuid, vo.phone, vo.password); + userPo = this.sv.loginWithMapperXml(uuid, vo.phone, vo.password); } catch (Exception e) { log.error("鐢ㄦ埛鐧诲綍寮傚父", e); return BaseResponseUtils.buildException(e.getMessage()) ; @@ -119,13 +120,18 @@ 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 ; try { //Boolean flag = cacheManager.getCacheNames().isEmpty() ; uuid = UUID.randomUUID().toString(); - userPo = this.sv.login(uuid, vo.phone, vo.password); + userPo = this.sv.loginWithMapperXml(uuid, vo.phone, vo.password); } catch (Exception e) { log.error("鐢ㄦ埛鐧诲綍寮傚父", e); return BaseResponseUtils.buildException(e.getMessage()) ; @@ -182,20 +188,38 @@ * 姝ゆ柟娉曚緵瀛愭ā鍧楃郴缁熻皟鐢紝鎵�浠ヤ笉鍏紑鍦ˋPI鎺ュ彛涓� * 鏂规硶鍔熻兘锛氶獙璇佹槸鍚﹀凡缁忕櫥褰曪紝濡傛灉鐧诲綍浜嗭紝鍐嶉獙璇佹潈闄� * @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.dataSourceName = userPo.orgTag ; vo.logined = true ; - vo.hasPower = true ; - vo.dataSourceName = userPo.getOrgTag() ; + vo.hasPower = false ;//榛樿鏄棤鏉冮檺 + if(userPo.supperAdmin != null && userPo.supperAdmin == 1){ + vo.hasPower = true ; + }else{ + if(privilege.equals("-1")){ + //鏃犻渶鏉冮檺楠岃瘉 + vo.hasPower = true ; + }else{ + if(userPo.privileges != null && userPo.privileges.size() > 0){ + vo.hasPower = this.hasOnePrivilege(privilege, userPo) ; + if(!vo.hasPower){ + vo.hasPower = this.hasAllPrivilege(allPrivilege, userPo) ; + if(!vo.hasPower){ + vo.hasPower = this.hasAnyPrivilege(anyPrivilege, userPo) ; + } + } + } + } + } }else{ vo.logined = false ; vo.hasPower = false ; @@ -203,5 +227,84 @@ return vo ; } + ///////////////////////////////////////////////////////////////// + // + // 浠ヤ笅绉佹湁鏂规硶 + // + ///////////////////////////////////////////////////////////////// + /** + * 鍒ゆ柇鐧诲綍鐢ㄦ埛鏄惁鎷ユ湁鎸囧畾鐨勪竴涓潈闄� + * @param privilege 鎸囧畾鐨勪竴涓潈闄� + * @param userPo 褰撳墠鐧诲綍鐢ㄦ埛 + * @return 鏄惁鏈夋潈闄� + */ + private boolean hasOnePrivilege(String privilege, BaUser userPo){ + boolean hasPrivilege = false ; + if (privilege != null && !privilege.trim().equals("")) { + int intPri = Integer.parseInt(privilege); + for (Integer pri : userPo.privileges) { + if (pri == intPri) { + hasPrivilege = true; + break; + } + } + } + return hasPrivilege ; + } + + /** + * 鍒ゆ柇鐧诲綍鐢ㄦ埛鏄惁鎷ユ湁鎸囧畾鐨勫涓潈闄� + * @param allPrivilege 鎸囧畾鐨勫涓潈闄� + * @param userPo 褰撳墠鐧诲綍鐢ㄦ埛 + * @return 鏄惁鏈夋潈闄� + */ + private boolean hasAllPrivilege(String[] allPrivilege, BaUser userPo){ + boolean hasPrivilege = false ; + if(allPrivilege != null && allPrivilege.length > 0){ + int intPri ; + int count = 0 ; + for(String strPri : allPrivilege){ + intPri = Integer.parseInt(strPri) ; + for(Integer pri : userPo.privileges){ + if(pri == intPri){ + count++ ; + break ; + } + } + } + if(count == allPrivilege.length){ + hasPrivilege = true ; + } + } + return hasPrivilege ; + } + + + /** + * 鍒ゆ柇鐧诲綍鐢ㄦ埛鏄惁鎷ユ湁鎸囧畾鐨勬煇涓潈闄� + * @param anyPrivilege 鎸囧畾鐨勫涓潈闄� + * @param userPo 褰撳墠鐧诲綍鐢ㄦ埛 + * @return 鏄惁鏈夋潈闄� + */ + private boolean hasAnyPrivilege(String[] anyPrivilege, BaUser userPo){ + boolean hasPrivilege = false ; + int intPri ; + if(anyPrivilege != null && anyPrivilege.length > 0){ + for(String strPri : anyPrivilege){ + intPri = Integer.parseInt(strPri) ; + for(Integer pri : userPo.privileges){ + if(pri == intPri){ + hasPrivilege = true ; + break ; + } + } + if(hasPrivilege){ + break ; + } + } + } + return hasPrivilege ; + } + } -- Gitblit v1.8.0