mirror of
https://gitee.com/dromara/RuoYi-Vue-Plus.git
synced 2026-09-18 09:35:29 +08:00
包名调整
This commit is contained in:
parent
8bb82902c0
commit
8526f4f4e9
@ -1,4 +1,4 @@
|
|||||||
package com.pj;
|
package com.pj.auth;
|
||||||
|
|
||||||
import cn.dev33.satoken.sso.SaSsoManager;
|
import cn.dev33.satoken.sso.SaSsoManager;
|
||||||
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
|
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package com.pj.config;
|
package com.pj.auth.config;
|
||||||
|
|
||||||
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package com.pj.config;
|
package com.pj.auth.config;
|
||||||
|
|
||||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||||
@ -1,18 +1,18 @@
|
|||||||
package com.pj.config;
|
package com.pj.auth.config;
|
||||||
|
|
||||||
import cn.dev33.satoken.jwt.StpLogicJwtForSimple;
|
import cn.dev33.satoken.jwt.StpLogicJwtForSimple;
|
||||||
import cn.dev33.satoken.stp.StpInterface;
|
import cn.dev33.satoken.stp.StpInterface;
|
||||||
import cn.dev33.satoken.stp.StpLogic;
|
import cn.dev33.satoken.stp.StpLogic;
|
||||||
import com.pj.core.service.SaPermissionImpl;
|
import com.pj.auth.config.satoken.SaPermissionImpl;
|
||||||
import com.pj.handler.SaTokenExceptionHandler;
|
import com.pj.auth.config.satoken.SaTokenExceptionHandler;
|
||||||
import com.pj.helper.LoginSaasHelper;
|
import com.pj.auth.config.satoken.LoginSaasHelper;
|
||||||
import org.dromara.common.log.aspect.CommonLogTenantIntercept;
|
import org.dromara.common.log.aspect.CommonLogTenantIntercept;
|
||||||
import org.dromara.system.api.model.LoginUser;
|
import org.dromara.system.api.model.LoginUser;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* sa-token 配置
|
* sa-token 配置 转移到gateway后鉴权移到gateway
|
||||||
*
|
*
|
||||||
* @author Lion Li
|
* @author Lion Li
|
||||||
*/
|
*/
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package com.pj.helper;
|
package com.pj.auth.config.satoken;
|
||||||
|
|
||||||
import cn.dev33.satoken.session.SaSession;
|
import cn.dev33.satoken.session.SaSession;
|
||||||
import cn.dev33.satoken.stp.SaLoginModel;
|
import cn.dev33.satoken.stp.SaLoginModel;
|
||||||
@ -1,7 +1,6 @@
|
|||||||
package com.pj.core.service;
|
package com.pj.auth.config.satoken;
|
||||||
|
|
||||||
import cn.dev33.satoken.stp.StpInterface;
|
import cn.dev33.satoken.stp.StpInterface;
|
||||||
import com.pj.helper.LoginSaasHelper;
|
|
||||||
import org.dromara.common.core.enums.UserType;
|
import org.dromara.common.core.enums.UserType;
|
||||||
import org.dromara.system.api.model.LoginUser;
|
import org.dromara.system.api.model.LoginUser;
|
||||||
|
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package com.pj.handler;
|
package com.pj.auth.config.satoken;
|
||||||
|
|
||||||
import cn.dev33.satoken.exception.NotLoginException;
|
import cn.dev33.satoken.exception.NotLoginException;
|
||||||
import cn.dev33.satoken.exception.NotPermissionException;
|
import cn.dev33.satoken.exception.NotPermissionException;
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package com.pj.controller;
|
package com.pj.auth.controller;
|
||||||
|
|
||||||
import cn.dev33.satoken.context.SaHolder;
|
import cn.dev33.satoken.context.SaHolder;
|
||||||
import cn.dev33.satoken.stp.StpUtil;
|
import cn.dev33.satoken.stp.StpUtil;
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package com.pj.controller;
|
package com.pj.auth.controller;
|
||||||
|
|
||||||
import cn.dev33.satoken.context.SaHolder;
|
import cn.dev33.satoken.context.SaHolder;
|
||||||
import cn.dev33.satoken.context.model.SaRequest;
|
import cn.dev33.satoken.context.model.SaRequest;
|
||||||
@ -9,7 +9,7 @@ import cn.hutool.core.util.ObjectUtil;
|
|||||||
import com.pj.auth.domain.vo.LoginVo;
|
import com.pj.auth.domain.vo.LoginVo;
|
||||||
import com.pj.auth.service.IAuthStrategy;
|
import com.pj.auth.service.IAuthStrategy;
|
||||||
import com.pj.auth.service.SysLoginService;
|
import com.pj.auth.service.SysLoginService;
|
||||||
import com.pj.helper.LoginSaasHelper;
|
import com.pj.auth.config.satoken.LoginSaasHelper;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.dubbo.config.annotation.DubboReference;
|
import org.apache.dubbo.config.annotation.DubboReference;
|
||||||
@ -60,6 +60,7 @@ public class SsoServerController {
|
|||||||
return SaSsoServerProcessor.instance.dister();
|
return SaSsoServerProcessor.instance.dister();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @ApiEncrypt
|
||||||
@PostMapping("/sso/doLogin")
|
@PostMapping("/sso/doLogin")
|
||||||
public Object ssoDoLoginRequest(@RequestBody String body) {
|
public Object ssoDoLoginRequest(@RequestBody String body) {
|
||||||
LoginBody loginBody = JsonUtils.parseObject(body, LoginBody.class);
|
LoginBody loginBody = JsonUtils.parseObject(body, LoginBody.class);
|
||||||
@ -11,7 +11,7 @@ import com.pj.auth.form.RegisterBody;
|
|||||||
import com.pj.auth.form.SocialLoginBody;
|
import com.pj.auth.form.SocialLoginBody;
|
||||||
import com.pj.auth.service.IAuthStrategy;
|
import com.pj.auth.service.IAuthStrategy;
|
||||||
import com.pj.auth.service.SysLoginService;
|
import com.pj.auth.service.SysLoginService;
|
||||||
import com.pj.helper.LoginSaasHelper;
|
import com.pj.auth.config.satoken.LoginSaasHelper;
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|||||||
@ -7,7 +7,7 @@ import cn.dev33.satoken.stp.StpUtil;
|
|||||||
import cn.hutool.core.convert.Convert;
|
import cn.hutool.core.convert.Convert;
|
||||||
import cn.hutool.http.useragent.UserAgent;
|
import cn.hutool.http.useragent.UserAgent;
|
||||||
import cn.hutool.http.useragent.UserAgentUtil;
|
import cn.hutool.http.useragent.UserAgentUtil;
|
||||||
import com.pj.helper.LoginSaasHelper;
|
import com.pj.auth.config.satoken.LoginSaasHelper;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.dubbo.config.annotation.DubboReference;
|
import org.apache.dubbo.config.annotation.DubboReference;
|
||||||
|
|||||||
@ -10,7 +10,7 @@ import com.baomidou.lock.annotation.Lock4j;
|
|||||||
import com.pj.auth.form.RegisterBody;
|
import com.pj.auth.form.RegisterBody;
|
||||||
import com.pj.auth.properties.CaptchaProperties;
|
import com.pj.auth.properties.CaptchaProperties;
|
||||||
import com.pj.auth.properties.UserPasswordProperties;
|
import com.pj.auth.properties.UserPasswordProperties;
|
||||||
import com.pj.helper.LoginSaasHelper;
|
import com.pj.auth.config.satoken.LoginSaasHelper;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import me.zhyd.oauth.model.AuthUser;
|
import me.zhyd.oauth.model.AuthUser;
|
||||||
|
|||||||
@ -6,7 +6,7 @@ import com.pj.auth.domain.vo.LoginVo;
|
|||||||
import com.pj.auth.form.EmailLoginBody;
|
import com.pj.auth.form.EmailLoginBody;
|
||||||
import com.pj.auth.service.IAuthStrategy;
|
import com.pj.auth.service.IAuthStrategy;
|
||||||
import com.pj.auth.service.SysLoginService;
|
import com.pj.auth.service.SysLoginService;
|
||||||
import com.pj.helper.LoginSaasHelper;
|
import com.pj.auth.config.satoken.LoginSaasHelper;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.dubbo.config.annotation.DubboReference;
|
import org.apache.dubbo.config.annotation.DubboReference;
|
||||||
|
|||||||
@ -8,7 +8,7 @@ import com.pj.auth.form.PasswordLoginBody;
|
|||||||
import com.pj.auth.properties.CaptchaProperties;
|
import com.pj.auth.properties.CaptchaProperties;
|
||||||
import com.pj.auth.service.IAuthStrategy;
|
import com.pj.auth.service.IAuthStrategy;
|
||||||
import com.pj.auth.service.SysLoginService;
|
import com.pj.auth.service.SysLoginService;
|
||||||
import com.pj.helper.LoginSaasHelper;
|
import com.pj.auth.config.satoken.LoginSaasHelper;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.dubbo.config.annotation.DubboReference;
|
import org.apache.dubbo.config.annotation.DubboReference;
|
||||||
|
|||||||
@ -6,7 +6,7 @@ import com.pj.auth.domain.vo.LoginVo;
|
|||||||
import com.pj.auth.form.SmsLoginBody;
|
import com.pj.auth.form.SmsLoginBody;
|
||||||
import com.pj.auth.service.IAuthStrategy;
|
import com.pj.auth.service.IAuthStrategy;
|
||||||
import com.pj.auth.service.SysLoginService;
|
import com.pj.auth.service.SysLoginService;
|
||||||
import com.pj.helper.LoginSaasHelper;
|
import com.pj.auth.config.satoken.LoginSaasHelper;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.dubbo.config.annotation.DubboReference;
|
import org.apache.dubbo.config.annotation.DubboReference;
|
||||||
|
|||||||
@ -6,7 +6,7 @@ import cn.hutool.core.collection.CollUtil;
|
|||||||
import cn.hutool.core.map.MapUtil;
|
import cn.hutool.core.map.MapUtil;
|
||||||
import cn.hutool.http.HttpUtil;
|
import cn.hutool.http.HttpUtil;
|
||||||
import cn.hutool.http.Method;
|
import cn.hutool.http.Method;
|
||||||
import com.pj.helper.LoginSaasHelper;
|
import com.pj.auth.config.satoken.LoginSaasHelper;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import me.zhyd.oauth.model.AuthResponse;
|
import me.zhyd.oauth.model.AuthResponse;
|
||||||
|
|||||||
@ -6,7 +6,7 @@ import com.pj.auth.domain.vo.LoginVo;
|
|||||||
import com.pj.auth.form.XcxLoginBody;
|
import com.pj.auth.form.XcxLoginBody;
|
||||||
import com.pj.auth.service.IAuthStrategy;
|
import com.pj.auth.service.IAuthStrategy;
|
||||||
import com.pj.auth.service.SysLoginService;
|
import com.pj.auth.service.SysLoginService;
|
||||||
import com.pj.helper.LoginSaasHelper;
|
import com.pj.auth.config.satoken.LoginSaasHelper;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.dubbo.config.annotation.DubboReference;
|
import org.apache.dubbo.config.annotation.DubboReference;
|
||||||
|
|||||||
@ -1,172 +0,0 @@
|
|||||||
package com.pj.core.dao;
|
|
||||||
|
|
||||||
import cn.dev33.satoken.dao.SaTokenDao;
|
|
||||||
import cn.dev33.satoken.util.SaFoxUtil;
|
|
||||||
import com.github.benmanes.caffeine.cache.Cache;
|
|
||||||
import com.github.benmanes.caffeine.cache.Caffeine;
|
|
||||||
import org.dromara.common.redis.utils.RedisUtils;
|
|
||||||
|
|
||||||
import java.time.Duration;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sa-Token持久层接口(使用框架自带RedisUtils实现 协议统一)
|
|
||||||
* <p>
|
|
||||||
* 采用 caffeine + redis 多级缓存 优化并发查询效率
|
|
||||||
*
|
|
||||||
* @author Lion Li
|
|
||||||
*/
|
|
||||||
public class PlusSaTokenDao implements SaTokenDao {
|
|
||||||
|
|
||||||
private static final Cache<String, Object> CAFFEINE = Caffeine.newBuilder()
|
|
||||||
// 设置最后一次写入或访问后经过固定时间过期
|
|
||||||
.expireAfterWrite(5, TimeUnit.SECONDS)
|
|
||||||
// 初始的缓存空间大小
|
|
||||||
.initialCapacity(100)
|
|
||||||
// 缓存的最大条数
|
|
||||||
.maximumSize(1000)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取Value,如无返空
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String get(String key) {
|
|
||||||
Object o = CAFFEINE.get(key, k -> RedisUtils.getCacheObject(key));
|
|
||||||
return (String) o;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 写入Value,并设定存活时间 (单位: 秒)
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void set(String key, String value, long timeout) {
|
|
||||||
if (timeout == 0 || timeout <= NOT_VALUE_EXPIRE) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// 判断是否为永不过期
|
|
||||||
if (timeout == NEVER_EXPIRE) {
|
|
||||||
RedisUtils.setCacheObject(key, value);
|
|
||||||
} else {
|
|
||||||
RedisUtils.setCacheObject(key, value, Duration.ofSeconds(timeout));
|
|
||||||
}
|
|
||||||
CAFFEINE.invalidate(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 修修改指定key-value键值对 (过期时间不变)
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void update(String key, String value) {
|
|
||||||
if (RedisUtils.hasKey(key)) {
|
|
||||||
RedisUtils.setCacheObject(key, value, true);
|
|
||||||
CAFFEINE.invalidate(key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 删除Value
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void delete(String key) {
|
|
||||||
RedisUtils.deleteObject(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取Value的剩余存活时间 (单位: 秒)
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public long getTimeout(String key) {
|
|
||||||
long timeout = RedisUtils.getTimeToLive(key);
|
|
||||||
return timeout < 0 ? timeout : timeout / 1000;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 修改Value的剩余存活时间 (单位: 秒)
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void updateTimeout(String key, long timeout) {
|
|
||||||
RedisUtils.expire(key, Duration.ofSeconds(timeout));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取Object,如无返空
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public Object getObject(String key) {
|
|
||||||
Object o = CAFFEINE.get(key, k -> RedisUtils.getCacheObject(key));
|
|
||||||
return o;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 写入Object,并设定存活时间 (单位: 秒)
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void setObject(String key, Object object, long timeout) {
|
|
||||||
if (timeout == 0 || timeout <= NOT_VALUE_EXPIRE) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// 判断是否为永不过期
|
|
||||||
if (timeout == NEVER_EXPIRE) {
|
|
||||||
RedisUtils.setCacheObject(key, object);
|
|
||||||
} else {
|
|
||||||
RedisUtils.setCacheObject(key, object, Duration.ofSeconds(timeout));
|
|
||||||
}
|
|
||||||
CAFFEINE.invalidate(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新Object (过期时间不变)
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void updateObject(String key, Object object) {
|
|
||||||
if (RedisUtils.hasKey(key)) {
|
|
||||||
RedisUtils.setCacheObject(key, object, true);
|
|
||||||
CAFFEINE.invalidate(key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 删除Object
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void deleteObject(String key) {
|
|
||||||
RedisUtils.deleteObject(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取Object的剩余存活时间 (单位: 秒)
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public long getObjectTimeout(String key) {
|
|
||||||
long timeout = RedisUtils.getTimeToLive(key);
|
|
||||||
return timeout < 0 ? timeout : timeout / 1000;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 修改Object的剩余存活时间 (单位: 秒)
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void updateObjectTimeout(String key, long timeout) {
|
|
||||||
RedisUtils.expire(key, Duration.ofSeconds(timeout));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 搜索数据
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
@Override
|
|
||||||
public List<String> searchData(String prefix, String keyword, int start, int size, boolean sortType) {
|
|
||||||
String keyStr = prefix + "*" + keyword + "*";
|
|
||||||
return (List<String>) CAFFEINE.get(keyStr, k -> {
|
|
||||||
Collection<String> keys = RedisUtils.keys(keyStr);
|
|
||||||
List<String> list = new ArrayList<>(keys);
|
|
||||||
return SaFoxUtil.searchList(list, start, size, sortType);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,100 +0,0 @@
|
|||||||
//package com.pj.service.impl;
|
|
||||||
//
|
|
||||||
//import cn.dev33.satoken.stp.SaLoginModel;
|
|
||||||
//import cn.dev33.satoken.stp.StpUtil;
|
|
||||||
//import cn.hutool.json.JSONUtil;
|
|
||||||
//import lombok.RequiredArgsConstructor;
|
|
||||||
//import lombok.extern.slf4j.Slf4j;
|
|
||||||
//import org.dromara.common.core.domain.model.EmailLoginBody;
|
|
||||||
//import org.dromara.common.core.domain.model.LoginUser;
|
|
||||||
//import org.dromara.common.core.utils.ValidatorUtils;
|
|
||||||
//import org.dromara.common.tenant.helper.TenantHelper;
|
|
||||||
//import org.springframework.stereotype.Service;
|
|
||||||
//
|
|
||||||
///**
|
|
||||||
// * 邮件认证策略
|
|
||||||
// *
|
|
||||||
// * @author Michelle.Chung
|
|
||||||
// */
|
|
||||||
//@Slf4j
|
|
||||||
//@Service("email" + IAuthStrategy.BASE_NAME)
|
|
||||||
//@RequiredArgsConstructor
|
|
||||||
//public class EmailAuthStrategy implements IAuthStrategy {
|
|
||||||
//
|
|
||||||
// //后续改为远程的
|
|
||||||
//// private final SysLoginService loginService;
|
|
||||||
//// private final SysUserMapper userMapper;
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public LoginVo login(String body, SysClientVo client) {
|
|
||||||
// EmailLoginBody loginBody = JSONUtil.toBean(body, EmailLoginBody.class);
|
|
||||||
// ValidatorUtils.validate(loginBody);
|
|
||||||
// String tenantId = loginBody.getTenantId();
|
|
||||||
// String email = loginBody.getEmail();
|
|
||||||
// String emailCode = loginBody.getEmailCode();
|
|
||||||
// LoginUser loginUser = TenantHelper.dynamic(tenantId, () -> {
|
|
||||||
//// SysUserVo user = loadUserByEmail(email);
|
|
||||||
//// loginService.checkLogin(LoginType.EMAIL, tenantId, user.getUserName(), () -> !validateEmailCode(tenantId, email, emailCode));
|
|
||||||
// // 此处可根据登录用户的数据不同 自行创建 loginUser 属性不够用继承扩展就行了
|
|
||||||
//// return loginService.buildLoginUser(user);
|
|
||||||
// return buildLoginUser();
|
|
||||||
// });
|
|
||||||
// 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(LoginSaasHelper.CLIENT_KEY, client.getClientId());
|
|
||||||
// // 生成token
|
|
||||||
// LoginSaasHelper.login(loginUser, model);
|
|
||||||
//
|
|
||||||
// LoginVo loginVo = new LoginVo();
|
|
||||||
// loginVo.setAccessToken(StpUtil.getTokenValue());
|
|
||||||
// loginVo.setExpireIn(StpUtil.getTokenTimeout());
|
|
||||||
// loginVo.setClientId(client.getClientId());
|
|
||||||
// return loginVo;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// /**
|
|
||||||
// * 构建登录用户
|
|
||||||
// */
|
|
||||||
// private LoginUser buildLoginUser() {
|
|
||||||
// LoginUser loginUser = new LoginUser();
|
|
||||||
// loginUser.setTenantId("1");
|
|
||||||
// loginUser.setUserId(1L);
|
|
||||||
// loginUser.setDeptId(2L);
|
|
||||||
// loginUser.setUsername("测试用户登录名");
|
|
||||||
// loginUser.setNickname("测试用户名称");
|
|
||||||
// loginUser.setUserType("用户类型1");
|
|
||||||
// return loginUser;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//// /**
|
|
||||||
//// * 校验邮箱验证码
|
|
||||||
//// */
|
|
||||||
//// private boolean validateEmailCode(String tenantId, String email, String emailCode) {
|
|
||||||
//// String code = RedisUtils.getCacheObject(GlobalConstants.CAPTCHA_CODE_KEY + email);
|
|
||||||
//// if (StringUtils.isBlank(code)) {
|
|
||||||
//// loginService.recordLogininfor(tenantId, email, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.expire"));
|
|
||||||
//// throw new CaptchaExpireException();
|
|
||||||
//// }
|
|
||||||
//// return code.equals(emailCode);
|
|
||||||
//// }
|
|
||||||
////
|
|
||||||
//// private SysUserVo loadUserByEmail(String email) {
|
|
||||||
//// SysUserVo user = userMapper.selectVoOne(new LambdaQueryWrapper<SysUser>().eq(SysUser::getEmail, email));
|
|
||||||
//// if (ObjectUtil.isNull(user)) {
|
|
||||||
//// log.info("登录用户:{} 不存在.", email);
|
|
||||||
//// throw new UserException("user.not.exists", email);
|
|
||||||
//// } else if (UserStatus.DISABLE.getCode().equals(user.getStatus())) {
|
|
||||||
//// log.info("登录用户:{} 已被停用.", email);
|
|
||||||
//// throw new UserException("user.blocked", email);
|
|
||||||
//// }
|
|
||||||
//// return user;
|
|
||||||
//// }
|
|
||||||
//
|
|
||||||
//}
|
|
||||||
@ -1,117 +0,0 @@
|
|||||||
//package com.pj.service.impl;
|
|
||||||
//
|
|
||||||
//import cn.dev33.satoken.stp.SaLoginModel;
|
|
||||||
//import cn.dev33.satoken.stp.StpUtil;
|
|
||||||
//import cn.hutool.json.JSONUtil;
|
|
||||||
//import com.pj.model.vo.LoginVo;
|
|
||||||
//import com.pj.model.vo.SysClientVo;
|
|
||||||
//import com.pj.service.IAuthStrategy;
|
|
||||||
//import lombok.RequiredArgsConstructor;
|
|
||||||
//import lombok.extern.slf4j.Slf4j;
|
|
||||||
//import org.dromara.common.core.domain.model.LoginUser;
|
|
||||||
//import org.dromara.common.core.domain.model.PasswordLoginBody;
|
|
||||||
//import org.dromara.common.core.utils.ValidatorUtils;
|
|
||||||
//import org.dromara.common.satoken.utils.LoginSaasHelper;
|
|
||||||
//import org.dromara.common.tenant.helper.TenantHelper;
|
|
||||||
//import org.springframework.stereotype.Service;
|
|
||||||
//
|
|
||||||
///**
|
|
||||||
// * 密码认证策略
|
|
||||||
// *
|
|
||||||
// * @author Michelle.Chung
|
|
||||||
// */
|
|
||||||
//@Slf4j
|
|
||||||
//@Service("password" + IAuthStrategy.BASE_NAME)
|
|
||||||
//@RequiredArgsConstructor
|
|
||||||
//public class PasswordAuthStrategy implements IAuthStrategy {
|
|
||||||
//
|
|
||||||
//// private final CaptchaProperties captchaProperties;
|
|
||||||
//// private final SysLoginService loginService;
|
|
||||||
//// private final SysUserMapper userMapper;
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public LoginVo login(String body, SysClientVo client) {
|
|
||||||
// PasswordLoginBody loginBody = JSONUtil.toBean(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();
|
|
||||||
//
|
|
||||||
//// boolean captchaEnabled = captchaProperties.getEnable();
|
|
||||||
//// // 验证码开关
|
|
||||||
//// if (captchaEnabled) {
|
|
||||||
//// validateCaptcha(tenantId, username, code, uuid);
|
|
||||||
//// }
|
|
||||||
// LoginUser loginUser = TenantHelper.dynamic(tenantId, () -> {
|
|
||||||
//// SysUserVo user = loadUserByUsername(username);
|
|
||||||
//// loginService.checkLogin(LoginType.PASSWORD, tenantId, username, () -> !BCrypt.checkpw(password, user.getPassword()));
|
|
||||||
//// // 此处可根据登录用户的数据不同 自行创建 loginUser
|
|
||||||
//// return loginService.buildLoginUser(user);
|
|
||||||
// return buildLoginUser();
|
|
||||||
// });
|
|
||||||
// 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(LoginSaasHelper.CLIENT_KEY, client.getClientId());
|
|
||||||
// // 生成token
|
|
||||||
// LoginSaasHelper.login(loginUser, model);
|
|
||||||
//
|
|
||||||
// LoginVo loginVo = new LoginVo();
|
|
||||||
// loginVo.setAccessToken(StpUtil.getTokenValue());
|
|
||||||
// loginVo.setExpireIn(StpUtil.getTokenTimeout());
|
|
||||||
// loginVo.setClientId(client.getClientId());
|
|
||||||
// return loginVo;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// private LoginUser buildLoginUser() {
|
|
||||||
// LoginUser loginUser = new LoginUser();
|
|
||||||
// loginUser.setTenantId("1");
|
|
||||||
// loginUser.setUserId(1L);
|
|
||||||
// loginUser.setDeptId(2L);
|
|
||||||
// loginUser.setUsername("测试用户登录名");
|
|
||||||
// loginUser.setNickname("测试用户名称");
|
|
||||||
// loginUser.setUserType("app_user");
|
|
||||||
// return loginUser;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// /**
|
|
||||||
// * 校验验证码
|
|
||||||
// *
|
|
||||||
// * @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();
|
|
||||||
//// }
|
|
||||||
//// }
|
|
||||||
////
|
|
||||||
//// private SysUserVo loadUserByUsername(String username) {
|
|
||||||
//// SysUserVo user = userMapper.selectVoOne(new LambdaQueryWrapper<SysUser>().eq(SysUser::getUserName, username));
|
|
||||||
//// if (ObjectUtil.isNull(user)) {
|
|
||||||
//// log.info("登录用户:{} 不存在.", username);
|
|
||||||
//// throw new UserException("user.not.exists", username);
|
|
||||||
//// } else if (UserStatus.DISABLE.getCode().equals(user.getStatus())) {
|
|
||||||
//// log.info("登录用户:{} 已被停用.", username);
|
|
||||||
//// throw new UserException("user.blocked", username);
|
|
||||||
//// }
|
|
||||||
//// return user;
|
|
||||||
//// }
|
|
||||||
//
|
|
||||||
//}
|
|
||||||
Loading…
Reference in New Issue
Block a user