增加 pda登录和菜单接口

master
wanghao 5 days ago
parent 5fb4dc48bf
commit 5a999fa873

@ -107,6 +107,22 @@ public class TokenController {
return R.ok(loginVo);
}
// @ApiEncrypt
@PostMapping("/pdaLogin")
public R<LoginVo> 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<String> authBinding(@PathVariable("source") String source,
@RequestParam String tenantId, @RequestParam String domain) {
public R<String> 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<Void> socialCallback(@RequestBody SocialLoginBody loginBody) {
// 获取第三方登录信息
AuthResponse<AuthUser> response = SocialUtils.loginAuth(
loginBody.getSource(), loginBody.getSocialCode(),
loginBody.getSocialState(), socialProperties);
AuthResponse<AuthUser> 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<TenantListVo> list = StreamUtils.filter(voList, vo ->
StringUtils.equals(vo.getDomain(), host));
List<TenantListVo> list = StreamUtils.filter(voList, vo -> StringUtils.equals(vo.getDomain(), host));
result.setVoList(CollUtil.isNotEmpty(list) ? list : voList);
return R.ok(result);
}

@ -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);
}

@ -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();
}
}
}

@ -111,7 +111,7 @@
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
</dependency>
<!-- <dependency>-->
<!-- <groupId>com.microsoft.sqlserver</groupId>-->
<!-- <artifactId>mssql-jdbc</artifactId>-->
<!-- </dependency>-->

@ -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

@ -47,6 +47,16 @@ public class SysMenuController extends BaseController {
List<SysMenu> menus = menuService.selectMenuTreeByUserId(LoginHelper.getUserId());
return R.ok(menuService.buildMenus(menus));
}
/**
*
*
* @return
*/
@GetMapping("/getPdaRouters")
public R<List<SysMenu>> getPdaRouters() {
List<SysMenu> menus = menuService.selectMenuTreeByUserId(LoginHelper.getUserId(),1995);
return R.ok(menus);
}
/**
*

@ -56,6 +56,7 @@ public interface ISysMenuService {
* @return
*/
List<SysMenu> selectMenuTreeByUserId(Long userId);
List<SysMenu> selectMenuTreeByUserId(Long userId,int pId);
/**
* ID

@ -139,6 +139,16 @@ public class SysMenuServiceImpl implements ISysMenuService {
}
return getChildPerms(menus, 0);
}
@Override
public List<SysMenu> selectMenuTreeByUserId(Long userId,int pId) {
List<SysMenu> menus;
if (LoginHelper.isSuperAdmin(userId)) {
menus = baseMapper.selectMenuTreeAll();
} else {
menus = baseMapper.selectMenuTreeByUserId(userId);
}
return getChildPerms(menus, pId);
}
/**
* ID

Loading…
Cancel
Save