feat: 登录认证的类型分为sys/u,对应系统和用户平台
This commit is contained in:
@@ -21,4 +21,10 @@ public class ServiceNameConstants
|
||||
* 文件服务的serviceid
|
||||
*/
|
||||
public static final String FILE_SERVICE = "wfc-file";
|
||||
|
||||
|
||||
/**
|
||||
* 用户平台模块的 service_id
|
||||
*/
|
||||
public static final String USER_SERVICE = "wfc-modules-user";
|
||||
}
|
||||
|
||||
@@ -0,0 +1,148 @@
|
||||
package org.wfc.common.core.domain;
|
||||
import java.io.Serializable;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 用户信息
|
||||
*
|
||||
* @author wfc
|
||||
*/
|
||||
public class LoginUser<T> implements Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 用户唯一标识
|
||||
*/
|
||||
private String token;
|
||||
|
||||
/**
|
||||
* 用户名id
|
||||
*/
|
||||
private Long userid;
|
||||
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
private String username;
|
||||
|
||||
/**
|
||||
* 登录时间
|
||||
*/
|
||||
private Long loginTime;
|
||||
|
||||
/**
|
||||
* 过期时间
|
||||
*/
|
||||
private Long expireTime;
|
||||
|
||||
/**
|
||||
* 登录IP地址
|
||||
*/
|
||||
private String ipaddr;
|
||||
|
||||
/**
|
||||
* 权限列表
|
||||
*/
|
||||
private Set<String> permissions;
|
||||
|
||||
/**
|
||||
* 角色列表
|
||||
*/
|
||||
private Set<String> roles;
|
||||
|
||||
/**
|
||||
* 用户信息
|
||||
*/
|
||||
private T user;
|
||||
|
||||
public String getToken()
|
||||
{
|
||||
return token;
|
||||
}
|
||||
|
||||
public void setToken(String token)
|
||||
{
|
||||
this.token = token;
|
||||
}
|
||||
|
||||
public Long getUserid()
|
||||
{
|
||||
return userid;
|
||||
}
|
||||
|
||||
public void setUserid(Long userid)
|
||||
{
|
||||
this.userid = userid;
|
||||
}
|
||||
|
||||
public String getUsername()
|
||||
{
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username)
|
||||
{
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public Long getLoginTime()
|
||||
{
|
||||
return loginTime;
|
||||
}
|
||||
|
||||
public void setLoginTime(Long loginTime)
|
||||
{
|
||||
this.loginTime = loginTime;
|
||||
}
|
||||
|
||||
public Long getExpireTime()
|
||||
{
|
||||
return expireTime;
|
||||
}
|
||||
|
||||
public void setExpireTime(Long expireTime)
|
||||
{
|
||||
this.expireTime = expireTime;
|
||||
}
|
||||
|
||||
public String getIpaddr()
|
||||
{
|
||||
return ipaddr;
|
||||
}
|
||||
|
||||
public void setIpaddr(String ipaddr)
|
||||
{
|
||||
this.ipaddr = ipaddr;
|
||||
}
|
||||
|
||||
public Set<String> getPermissions()
|
||||
{
|
||||
return permissions;
|
||||
}
|
||||
|
||||
public void setPermissions(Set<String> permissions)
|
||||
{
|
||||
this.permissions = permissions;
|
||||
}
|
||||
|
||||
public Set<String> getRoles()
|
||||
{
|
||||
return roles;
|
||||
}
|
||||
|
||||
public void setRoles(Set<String> roles)
|
||||
{
|
||||
this.roles = roles;
|
||||
}
|
||||
|
||||
public T getUser()
|
||||
{
|
||||
return user;
|
||||
}
|
||||
|
||||
public void setUser(T user)
|
||||
{
|
||||
this.user = user;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package org.wfc.common.core.web.form;
|
||||
|
||||
/**
|
||||
* 用户登录对象
|
||||
*
|
||||
* @author wfc
|
||||
*/
|
||||
public class LoginBody
|
||||
{
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
private String username;
|
||||
|
||||
/**
|
||||
* 用户密码
|
||||
*/
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* 认证类型 用户u/客户sys
|
||||
*/
|
||||
private String authType;
|
||||
|
||||
public String getUsername()
|
||||
{
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username)
|
||||
{
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getPassword()
|
||||
{
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password)
|
||||
{
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getAuthType() {
|
||||
return authType;
|
||||
}
|
||||
|
||||
public void setAuthType(String authType) {
|
||||
this.authType = authType;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package org.wfc.common.core.web.form;
|
||||
|
||||
/**
|
||||
* 用户注册对象
|
||||
*
|
||||
* @author wfc
|
||||
*/
|
||||
public class RegisterBody extends LoginBody
|
||||
{
|
||||
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import org.aspectj.lang.annotation.Before;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.wfc.common.core.constant.UserConstants;
|
||||
import org.wfc.common.core.context.SecurityContextHolder;
|
||||
import org.wfc.common.core.domain.LoginUser;
|
||||
import org.wfc.common.core.text.Convert;
|
||||
import org.wfc.common.core.utils.StringUtils;
|
||||
import org.wfc.common.core.web.domain.BaseEntity;
|
||||
@@ -15,7 +16,6 @@ import org.wfc.common.datascope.annotation.DataScope;
|
||||
import org.wfc.common.security.utils.SecurityUtils;
|
||||
import org.wfc.system.api.domain.SysRole;
|
||||
import org.wfc.system.api.domain.SysUser;
|
||||
import org.wfc.system.api.model.LoginUser;
|
||||
|
||||
/**
|
||||
* 数据过滤处理
|
||||
@@ -66,10 +66,10 @@ public class DataScopeAspect
|
||||
protected void handleDataScope(final JoinPoint joinPoint, DataScope controllerDataScope)
|
||||
{
|
||||
// 获取当前的用户
|
||||
LoginUser loginUser = SecurityUtils.getLoginUser();
|
||||
LoginUser<SysUser> loginUser = SecurityUtils.getLoginUser();
|
||||
if (StringUtils.isNotNull(loginUser))
|
||||
{
|
||||
SysUser currentUser = loginUser.getSysUser();
|
||||
SysUser currentUser = loginUser.getUser();
|
||||
// 如果是超级管理员,则不过滤数据
|
||||
if (StringUtils.isNotNull(currentUser) && !currentUser.isAdmin())
|
||||
{
|
||||
|
||||
@@ -28,12 +28,17 @@
|
||||
<artifactId>wfc-api-system</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- WFC Api User -->
|
||||
<dependency>
|
||||
<groupId>org.wfc</groupId>
|
||||
<artifactId>wfc-api-user</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- WFC Common Redis-->
|
||||
<dependency>
|
||||
<groupId>org.wfc</groupId>
|
||||
<artifactId>wfc-common-redis</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
||||
@@ -16,7 +16,7 @@ import org.wfc.common.security.annotation.RequiresPermissions;
|
||||
import org.wfc.common.security.annotation.RequiresRoles;
|
||||
import org.wfc.common.security.service.TokenService;
|
||||
import org.wfc.common.security.utils.SecurityUtils;
|
||||
import org.wfc.system.api.model.LoginUser;
|
||||
import org.wfc.common.core.domain.LoginUser;
|
||||
|
||||
/**
|
||||
* Token 权限验证,逻辑实现类
|
||||
@@ -98,7 +98,7 @@ public class AuthLogic
|
||||
*
|
||||
* @param loginUser 当前用户信息
|
||||
*/
|
||||
public void verifyLoginUserExpire(LoginUser loginUser)
|
||||
public <T> void verifyLoginUserExpire(LoginUser<T> loginUser)
|
||||
{
|
||||
tokenService.verifyToken(loginUser);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package org.wfc.common.security.auth;
|
||||
|
||||
import org.wfc.common.security.annotation.RequiresPermissions;
|
||||
import org.wfc.common.security.annotation.RequiresRoles;
|
||||
import org.wfc.system.api.model.LoginUser;
|
||||
import org.wfc.common.core.domain.LoginUser;
|
||||
|
||||
/**
|
||||
* Token 权限验证工具类
|
||||
|
||||
@@ -10,7 +10,7 @@ import org.wfc.common.core.utils.ServletUtils;
|
||||
import org.wfc.common.core.utils.StringUtils;
|
||||
import org.wfc.common.security.auth.AuthUtil;
|
||||
import org.wfc.common.security.utils.SecurityUtils;
|
||||
import org.wfc.system.api.model.LoginUser;
|
||||
import org.wfc.common.core.domain.LoginUser;
|
||||
|
||||
/**
|
||||
* 自定义请求头拦截器,将Header数据封装到线程变量中方便获取
|
||||
|
||||
@@ -17,7 +17,9 @@ import org.wfc.common.core.utils.ip.IpUtils;
|
||||
import org.wfc.common.core.utils.uuid.IdUtils;
|
||||
import org.wfc.common.redis.service.RedisService;
|
||||
import org.wfc.common.security.utils.SecurityUtils;
|
||||
import org.wfc.system.api.model.LoginUser;
|
||||
import org.wfc.common.core.domain.LoginUser;
|
||||
import org.wfc.system.api.domain.SysUser;
|
||||
import org.wfc.user.api.domain.UUser;
|
||||
|
||||
/**
|
||||
* token验证处理
|
||||
@@ -45,11 +47,21 @@ public class TokenService
|
||||
/**
|
||||
* 创建令牌
|
||||
*/
|
||||
public Map<String, Object> createToken(LoginUser loginUser)
|
||||
public <T> Map<String, Object> createToken(LoginUser<T> loginUser)
|
||||
{
|
||||
String token = IdUtils.fastUUID();
|
||||
Long userId = loginUser.getSysUser().getUserId();
|
||||
String userName = loginUser.getSysUser().getUserName();
|
||||
Long userId = 0L;
|
||||
String userName = "";
|
||||
T user = loginUser.getUser();
|
||||
if (user instanceof SysUser) {
|
||||
SysUser sysUser = (SysUser) user;
|
||||
userId = sysUser.getUserId();
|
||||
userName = sysUser.getUserName();
|
||||
}else if (user instanceof UUser) {
|
||||
UUser uUser = (UUser) user;
|
||||
userId = uUser.getUserId();
|
||||
userName = uUser.getUserName();
|
||||
}
|
||||
loginUser.setToken(token);
|
||||
loginUser.setUserid(userId);
|
||||
loginUser.setUsername(userName);
|
||||
@@ -74,7 +86,7 @@ public class TokenService
|
||||
*
|
||||
* @return 用户信息
|
||||
*/
|
||||
public LoginUser getLoginUser()
|
||||
public <T> LoginUser<T> getLoginUser()
|
||||
{
|
||||
return getLoginUser(ServletUtils.getRequest());
|
||||
}
|
||||
@@ -84,7 +96,7 @@ public class TokenService
|
||||
*
|
||||
* @return 用户信息
|
||||
*/
|
||||
public LoginUser getLoginUser(HttpServletRequest request)
|
||||
public <T> LoginUser<T> getLoginUser(HttpServletRequest request)
|
||||
{
|
||||
// 获取请求携带的令牌
|
||||
String token = SecurityUtils.getToken(request);
|
||||
@@ -96,9 +108,9 @@ public class TokenService
|
||||
*
|
||||
* @return 用户信息
|
||||
*/
|
||||
public LoginUser getLoginUser(String token)
|
||||
public <T> LoginUser<T> getLoginUser(String token)
|
||||
{
|
||||
LoginUser user = null;
|
||||
LoginUser<T> user = null;
|
||||
try
|
||||
{
|
||||
if (StringUtils.isNotEmpty(token))
|
||||
@@ -118,7 +130,7 @@ public class TokenService
|
||||
/**
|
||||
* 设置用户身份信息
|
||||
*/
|
||||
public void setLoginUser(LoginUser loginUser)
|
||||
public <T> void setLoginUser(LoginUser<T> loginUser)
|
||||
{
|
||||
if (StringUtils.isNotNull(loginUser) && StringUtils.isNotEmpty(loginUser.getToken()))
|
||||
{
|
||||
@@ -141,9 +153,9 @@ public class TokenService
|
||||
/**
|
||||
* 验证令牌有效期,相差不足120分钟,自动刷新缓存
|
||||
*
|
||||
* @param loginUser
|
||||
* @param loginUser 登录用户
|
||||
*/
|
||||
public void verifyToken(LoginUser loginUser)
|
||||
public <T> void verifyToken(LoginUser<T> loginUser)
|
||||
{
|
||||
long expireTime = loginUser.getExpireTime();
|
||||
long currentTime = System.currentTimeMillis();
|
||||
@@ -158,7 +170,7 @@ public class TokenService
|
||||
*
|
||||
* @param loginUser 登录信息
|
||||
*/
|
||||
public void refreshToken(LoginUser loginUser)
|
||||
public <T> void refreshToken(LoginUser<T> loginUser)
|
||||
{
|
||||
loginUser.setLoginTime(System.currentTimeMillis());
|
||||
loginUser.setExpireTime(loginUser.getLoginTime() + expireTime * MILLIS_MINUTE);
|
||||
|
||||
@@ -22,7 +22,7 @@ public class DictUtils
|
||||
* @param key 参数键
|
||||
* @param dictDatas 字典数据列表
|
||||
*/
|
||||
public static void setDictCache(String key, List<SysDictData> dictDatas)
|
||||
public static <T> void setDictCache(String key, List<T> dictDatas)
|
||||
{
|
||||
SpringUtils.getBean(RedisService.class).setCacheObject(getCacheKey(key), dictDatas);
|
||||
}
|
||||
@@ -33,12 +33,12 @@ public class DictUtils
|
||||
* @param key 参数键
|
||||
* @return dictDatas 字典数据列表
|
||||
*/
|
||||
public static List<SysDictData> getDictCache(String key)
|
||||
public static <T> List<T> getDictCache(String key, Class<T> clazz)
|
||||
{
|
||||
JSONArray arrayCache = SpringUtils.getBean(RedisService.class).getCacheObject(getCacheKey(key));
|
||||
if (StringUtils.isNotNull(arrayCache))
|
||||
{
|
||||
return arrayCache.toList(SysDictData.class);
|
||||
return arrayCache.toList(clazz);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import org.wfc.common.core.constant.TokenConstants;
|
||||
import org.wfc.common.core.context.SecurityContextHolder;
|
||||
import org.wfc.common.core.utils.ServletUtils;
|
||||
import org.wfc.common.core.utils.StringUtils;
|
||||
import org.wfc.system.api.model.LoginUser;
|
||||
import org.wfc.common.core.domain.LoginUser;
|
||||
|
||||
/**
|
||||
* 权限获取工具类
|
||||
@@ -43,7 +43,7 @@ public class SecurityUtils
|
||||
/**
|
||||
* 获取登录用户信息
|
||||
*/
|
||||
public static LoginUser getLoginUser()
|
||||
public static <T> LoginUser<T> getLoginUser()
|
||||
{
|
||||
return SecurityContextHolder.get(SecurityConstants.LOGIN_USER, LoginUser.class);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user