diff --git a/ruoyi-auth/src/main/java/org/dromara/auth/controller/TokenController.java b/ruoyi-auth/src/main/java/org/dromara/auth/controller/TokenController.java index 8de19740..a9370d26 100644 --- a/ruoyi-auth/src/main/java/org/dromara/auth/controller/TokenController.java +++ b/ruoyi-auth/src/main/java/org/dromara/auth/controller/TokenController.java @@ -107,6 +107,22 @@ public class TokenController { return R.ok(loginVo); } + // @ApiEncrypt + @PostMapping("/pdaLogin") + public R pdaLogin(@RequestBody String body) { + LoginBody loginBody = JsonUtils.parseObject(body, LoginBody.class); + // 授权类型和客户端id + String clientId = "428a8310cd442757ae699df5d894f051"; + String grantType = "pda"; + RemoteClientVo clientVo = remoteClientService.queryByClientId(clientId); + System.out.println(clientVo.toString()); + // 校验租户 + sysLoginService.checkTenant(loginBody.getTenantId()); + // 登录 + LoginVo loginVo = IAuthStrategy.login(body, clientVo, grantType); + return R.ok(loginVo); + } + /** * 第三方登录请求 * @@ -114,8 +130,7 @@ public class TokenController { * @return 结果 */ @GetMapping("/binding/{source}") - public R authBinding(@PathVariable("source") String source, - @RequestParam String tenantId, @RequestParam String domain) { + public R authBinding(@PathVariable("source") String source, @RequestParam String tenantId, @RequestParam String domain) { SocialLoginConfigProperties obj = socialProperties.getType().get(source); if (ObjectUtil.isNull(obj)) { return R.fail(source + "平台账号暂不支持"); @@ -138,9 +153,7 @@ public class TokenController { @PostMapping("/social/callback") public R socialCallback(@RequestBody SocialLoginBody loginBody) { // 获取第三方登录信息 - AuthResponse response = SocialUtils.loginAuth( - loginBody.getSource(), loginBody.getSocialCode(), - loginBody.getSocialState(), socialProperties); + AuthResponse response = SocialUtils.loginAuth(loginBody.getSource(), loginBody.getSocialCode(), loginBody.getSocialState(), socialProperties); AuthUser authUserData = response.getData(); // 判断授权响应是否成功 if (!response.ok()) { @@ -222,8 +235,7 @@ public class TokenController { host = new URL(request.getRequestURL().toString()).getHost(); } // 根据域名进行筛选 - List list = StreamUtils.filter(voList, vo -> - StringUtils.equals(vo.getDomain(), host)); + List list = StreamUtils.filter(voList, vo -> StringUtils.equals(vo.getDomain(), host)); result.setVoList(CollUtil.isNotEmpty(list) ? list : voList); return R.ok(result); } diff --git a/ruoyi-auth/src/main/java/org/dromara/auth/service/IAuthStrategy.java b/ruoyi-auth/src/main/java/org/dromara/auth/service/IAuthStrategy.java index 28307c38..26f74900 100644 --- a/ruoyi-auth/src/main/java/org/dromara/auth/service/IAuthStrategy.java +++ b/ruoyi-auth/src/main/java/org/dromara/auth/service/IAuthStrategy.java @@ -1,6 +1,7 @@ package org.dromara.auth.service; import org.dromara.auth.domain.vo.LoginVo; +import org.dromara.auth.service.impl.PdaAuthStrategy; import org.dromara.common.core.exception.ServiceException; import org.dromara.common.core.utils.SpringUtils; import org.dromara.system.api.domain.vo.RemoteClientVo; @@ -29,6 +30,8 @@ public interface IAuthStrategy { throw new ServiceException("授权类型不正确!"); } IAuthStrategy instance = SpringUtils.getBean(beanName); + System.out.println("真实类型="+beanName); + System.out.println(instance instanceof PdaAuthStrategy); return instance.login(body, client); } diff --git a/ruoyi-auth/src/main/java/org/dromara/auth/service/impl/PdaAuthStrategy.java b/ruoyi-auth/src/main/java/org/dromara/auth/service/impl/PdaAuthStrategy.java new file mode 100644 index 00000000..647edca6 --- /dev/null +++ b/ruoyi-auth/src/main/java/org/dromara/auth/service/impl/PdaAuthStrategy.java @@ -0,0 +1,108 @@ +package org.dromara.auth.service.impl; + +import cn.dev33.satoken.secure.BCrypt; +import cn.dev33.satoken.stp.SaLoginModel; +import cn.dev33.satoken.stp.StpUtil; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.apache.dubbo.config.annotation.DubboReference; +import org.dromara.auth.domain.vo.LoginVo; +import org.dromara.auth.form.PasswordLoginBody; +import org.dromara.auth.properties.CaptchaProperties; +import org.dromara.auth.service.IAuthStrategy; +import org.dromara.auth.service.SysLoginService; +import org.dromara.common.core.constant.Constants; +import org.dromara.common.core.constant.GlobalConstants; +import org.dromara.common.core.enums.LoginType; +import org.dromara.common.core.exception.user.CaptchaException; +import org.dromara.common.core.exception.user.CaptchaExpireException; +import org.dromara.common.core.utils.MessageUtils; +import org.dromara.common.core.utils.StringUtils; +import org.dromara.common.core.utils.ValidatorUtils; +import org.dromara.common.json.utils.JsonUtils; +import org.dromara.common.redis.utils.RedisUtils; +import org.dromara.common.satoken.utils.LoginHelper; +import org.dromara.common.tenant.helper.TenantHelper; +import org.dromara.system.api.RemoteUserService; +import org.dromara.system.api.domain.vo.RemoteClientVo; +import org.dromara.system.api.model.LoginUser; +import org.springframework.stereotype.Service; + +/** + * 密码认证策略 + * + * @author Michelle.Chung + */ +@Slf4j +@Service("pdaAuthStrategy") +@RequiredArgsConstructor +public class PdaAuthStrategy implements IAuthStrategy { + + private final CaptchaProperties captchaProperties; + + private final SysLoginService loginService; + + @DubboReference + private RemoteUserService remoteUserService; + + @Override + public LoginVo login(String body, RemoteClientVo client) { + System.out.println("PDA service"); + PasswordLoginBody loginBody = JsonUtils.parseObject(body, PasswordLoginBody.class); + ValidatorUtils.validate(loginBody); + String tenantId = loginBody.getTenantId(); + String username = loginBody.getUsername(); + String password = loginBody.getPassword(); + String code = loginBody.getCode(); + String uuid = loginBody.getUuid(); + + // 验证码开关 + // if (captchaProperties.getEnabled()) { + // validateCaptcha(tenantId, username, code, uuid); + // } + LoginUser loginUser = TenantHelper.dynamic(tenantId, () -> { + LoginUser user = remoteUserService.getUserInfo(username, tenantId); + loginService.checkLogin(LoginType.PASSWORD, tenantId, username, () -> !BCrypt.checkpw(password, user.getPassword())); + return user; + }); + loginUser.setClientKey(client.getClientKey()); + loginUser.setDeviceType(client.getDeviceType()); + SaLoginModel model = new SaLoginModel(); + model.setDevice(client.getDeviceType()); + // 自定义分配 不同用户体系 不同 token 授权时间 不设置默认走全局 yml 配置 + // 例如: 后台用户30分钟过期 app用户1天过期 + model.setTimeout(client.getTimeout()); + model.setActiveTimeout(client.getActiveTimeout()); + model.setExtra(LoginHelper.CLIENT_KEY, client.getClientId()); + // 生成token + LoginHelper.login(loginUser, model); + + LoginVo loginVo = new LoginVo(); + loginVo.setAccessToken(StpUtil.getTokenValue()); + loginVo.setExpireIn(StpUtil.getTokenTimeout()); + loginVo.setClientId(client.getClientId()); + return loginVo; + } + + /** + * 校验验证码 + * + * @param username 用户名 + * @param code 验证码 + * @param uuid 唯一标识 + */ + private void validateCaptcha(String tenantId, String username, String code, String uuid) { + String verifyKey = GlobalConstants.CAPTCHA_CODE_KEY + StringUtils.blankToDefault(uuid, ""); + String captcha = RedisUtils.getCacheObject(verifyKey); + RedisUtils.deleteObject(verifyKey); + if (captcha == null) { + loginService.recordLogininfor(tenantId, username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.expire")); + throw new CaptchaExpireException(); + } + if (!code.equalsIgnoreCase(captcha)) { + loginService.recordLogininfor(tenantId, username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.error")); + throw new CaptchaException(); + } + } + +} diff --git a/ruoyi-modules/hwmom-wms/pom.xml b/ruoyi-modules/hwmom-wms/pom.xml index 402d4317..bd7e65db 100644 --- a/ruoyi-modules/hwmom-wms/pom.xml +++ b/ruoyi-modules/hwmom-wms/pom.xml @@ -111,7 +111,7 @@ com.microsoft.sqlserver mssql-jdbc - + diff --git a/ruoyi-modules/hwmom-wms/src/main/resources/application.yml b/ruoyi-modules/hwmom-wms/src/main/resources/application.yml index 0d92de05..ae394080 100644 --- a/ruoyi-modules/hwmom-wms/src/main/resources/application.yml +++ b/ruoyi-modules/hwmom-wms/src/main/resources/application.yml @@ -9,7 +9,7 @@ spring: name: hwmom-wms profiles: # 环境配置 - active: @profiles.active@ + active: ${profiles.active} --- # nacos 配置 spring: @@ -22,11 +22,11 @@ spring: discovery: # 注册组 group: @nacos.discovery.group@ - namespace: dlmom + namespace: ${spring.profiles.active} config: # 配置组 group: @nacos.config.group@ - namespace: dlmom + namespace: ${spring.profiles.active} config: import: - optional:nacos:application-common.yml diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/controller/system/SysMenuController.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/controller/system/SysMenuController.java index 5edb6f60..2ca0cd39 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/controller/system/SysMenuController.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/controller/system/SysMenuController.java @@ -47,6 +47,16 @@ public class SysMenuController extends BaseController { List menus = menuService.selectMenuTreeByUserId(LoginHelper.getUserId()); return R.ok(menuService.buildMenus(menus)); } + /** + * 获取路由信息 + * + * @return 路由信息 + */ + @GetMapping("/getPdaRouters") + public R> getPdaRouters() { + List menus = menuService.selectMenuTreeByUserId(LoginHelper.getUserId(),1995); + return R.ok(menus); + } /** * 获取菜单列表 diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/ISysMenuService.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/ISysMenuService.java index 72d705e9..a1bdbb5f 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/ISysMenuService.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/ISysMenuService.java @@ -56,6 +56,7 @@ public interface ISysMenuService { * @return 菜单列表 */ List selectMenuTreeByUserId(Long userId); + List selectMenuTreeByUserId(Long userId,int pId); /** * 根据角色ID查询菜单树信息 diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysMenuServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysMenuServiceImpl.java index 1b6a9aa8..897d94a7 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysMenuServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysMenuServiceImpl.java @@ -139,6 +139,16 @@ public class SysMenuServiceImpl implements ISysMenuService { } return getChildPerms(menus, 0); } + @Override + public List selectMenuTreeByUserId(Long userId,int pId) { + List menus; + if (LoginHelper.isSuperAdmin(userId)) { + menus = baseMapper.selectMenuTreeAll(); + } else { + menus = baseMapper.selectMenuTreeByUserId(userId); + } + return getChildPerms(menus, pId); + } /** * 根据角色ID查询菜单树信息