pms-parent/pms-global/src/main/java/com/dy/pmsGlobal/global/SysSetCtrl.java
@@ -1,9 +1,9 @@ package com.dy.pmsGlobal.global; import com.dy.common.aop.SsoPowerAop; import com.dy.common.webUtil.BaseResponse; import com.dy.common.webUtil.BaseResponseUtils; import com.dy.pmsGlobal.pojoBa.BaSysSet; import com.dy.pmsGlobal.pojoBa.BaUser; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; @@ -28,10 +28,10 @@ * @return 唯一系统设置 */ //@GetMapping(path = "one", consumes = MediaType.TEXT_PLAIN_VALUE)//指前端向后传的参数类型 @GetMapping(path = "one") @GetMapping(path = "single") //@SsoAop() //只有登录验证,没有权限验证 @SsoPowerAop(power = "-1") //登录与权限同时验证 public BaseResponse<BaUser> single() { public BaseResponse<BaSysSet> single() { try { return BaseResponseUtils.buildSuccess(this.sv.selectSingle()); } catch (Exception e) { pms-parent/pms-global/src/main/resources/application-global.yml
@@ -35,10 +35,13 @@ aggressiveLazyLoading: false # 将积极加载改为消极加载(即按需加载),默认值是false lazy-load-trigger-methods: "" # 阻挡不相干的操作触发,实现懒加载 cache-enabled: true #打开全局缓存开关(二级环境),默认值是true default-enum-type-handler: com.dy.common.mybatis.envm.EnumCodeTypeHandler #default-enum-type-handler: com.dy.common.mybatis.envm.EnumCodeTypeHandler pms: global: dev: true #是否开发阶段,true或false,开发阶段不进行登录验证及权限验证 ssoUserExpireAfterAccess: 60 #sso登录后,用户在一定时间(ssoUserExpireAfterAccess)(分钟)内未访问系统,系统清除缓存信息,使用重新登录系统 ssoCacheSizeInit: 10 #sso缓存初始容量 ssoCacheSizeMax: 10000 #sso缓存最大容量,即支持ssoCacheSizeMax个用户同时登录 sso: checkUrl: http://127.0.0.1:12344/sso/sso/ssoCheck webPort: 12344 pms-parent/pms-web-base/src/main/java/com/dy/pmsBase/user/UserCtrl.java
@@ -137,14 +137,14 @@ //@SsoAop() //只有登录验证,没有权限验证 @SsoPowerAop(power = "10100011") //登录与权限同时验证 public BaseResponse<Boolean> update(@RequestBody @Validated BaUser po, BindingResult bindingResult) { int count; try { if (bindingResult != null && bindingResult.hasErrors()) { return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); } if (po.id == null) { return BaseResponseUtils.buildFail("无数据实体ID"); } int count; try { po.password = null;//设置为null,不做更新 po.supperAdmin = null;//设置为null,不做更新 po.deleted = null;//设置为null,不做更新 @@ -168,7 +168,9 @@ //@GetMapping(path = "changePassword", consumes = MediaType.TEXT_PLAIN_VALUE) @GetMapping(path = "changePassword") @SsoAop() public BaseResponse<Boolean> changePassword(String id, String oldPassword, String newPassword) throws Exception { public BaseResponse<Boolean> changePassword(String id, String oldPassword, String newPassword) { int count; try { if (id == null) { return BaseResponseUtils.buildFail("id不能为空"); } @@ -187,8 +189,7 @@ newPassword = MD5.encrypt(newPassword);//进行加密码 Long idLg = Long.parseLong(id); int count; try { BaUser po = this.sv.selectById(idLg); if (Objects.isNull(po)) { return BaseResponseUtils.buildFail("未得到用户,请求失败"); @@ -219,14 +220,14 @@ @PostMapping(path = "resetPassword", consumes = MediaType.APPLICATION_JSON_VALUE) //@SsoAop() //只有登录验证,没有权限验证 @SsoPowerAop(power = "10100011") //登录与权限同时验证 public BaseResponse<Boolean> resetPassword(@RequestBody @Validated ResetPasswordVo vo, BindingResult bindingResult) throws Exception { public BaseResponse<Boolean> resetPassword(@RequestBody @Validated ResetPasswordVo vo, BindingResult bindingResult) { int count; try { if (bindingResult != null && bindingResult.hasErrors()) { return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); } String password = MD5.encrypt(vo.password);//进行加密码 Long idLg = Long.parseLong(vo.id); int count; try { BaUser po = this.sv.selectById(idLg); if (Objects.isNull(po)) { return BaseResponseUtils.buildFail("未得到用户,请求失败"); pms-parent/pms-web-sso/src/main/java/com/dy/sso/busi/SsoCtrl.java
@@ -46,10 +46,15 @@ */ @PostMapping(path = "login", consumes = MediaType.APPLICATION_JSON_VALUE)//前端提交json数据 public BaseResponse<UserVo> login(@RequestBody @Valid LoginVo vo, BindingResult bindingResult) { try { if(bindingResult != null && bindingResult.hasErrors()){ return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); } return this.doLogin(vo) ; } catch (Exception e) { log.error("查询一个用户数据异常", e); return BaseResponseUtils.buildException(e.getMessage()); } } /** @@ -59,10 +64,15 @@ */ @PostMapping(path = "loginForm", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)//前端提交form表单数据 public BaseResponse<UserVo> loginForm(@RequestBody @Valid LoginVo vo, BindingResult bindingResult){ try{ if(bindingResult != null && bindingResult.hasErrors()){ return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); } return this.doLogin(vo) ; } catch (Exception e) { log.error("查询一个用户数据异常", e); return BaseResponseUtils.buildException(e.getMessage()); } } @@ -73,6 +83,7 @@ */ @GetMapping(path = "logout") public BaseResponse<Boolean> logout(HttpServletRequest hr){ try{ String token = hr.getHeader("token") ; if(token != null){ this.sv.logout(token) ; @@ -80,6 +91,10 @@ }else{ return BaseResponseUtils.buildFail("未从header中得到token"); } } catch (Exception e) { log.error("查询一个用户数据异常", e); return BaseResponseUtils.buildException(e.getMessage()); } } /** pms-parent/pms-web-sso/src/main/java/com/dy/sso/config/CaffeineCacheConfiguration.java
@@ -2,6 +2,7 @@ import com.github.benmanes.caffeine.cache.Caffeine; import org.springframework.beans.factory.annotation.Value; import org.springframework.cache.CacheManager; import org.springframework.cache.caffeine.CaffeineCacheManager; import org.springframework.context.annotation.Bean; @@ -27,13 +28,21 @@ maximumSize和maximumWeight不可以同时使用 weakValues和softValues不可以同时使用weakValues和softValues不可以同时使用 */ @Value("${pms.global.ssoUserExpireAfterAccess:60}") private Integer defaultTrueRandomFalsePassword; @Value("${pms.global.ssoCacheSizeInit:10}") private Integer ssoCacheSizeInit; @Value("${pms.global.ssoCacheSizeMax:10000}") private Integer ssoCacheSizeMax; @Bean public CacheManager cacheManager() { CaffeineCacheManager cacheManager = new CaffeineCacheManager(); cacheManager.setCaffeine(Caffeine.newBuilder() .initialCapacity(10) .maximumSize(10000) .expireAfterAccess(30, TimeUnit.MINUTES)); .initialCapacity(ssoCacheSizeInit) .maximumSize(ssoCacheSizeMax) .expireAfterAccess(defaultTrueRandomFalsePassword, TimeUnit.MINUTES)); return cacheManager; }