oss 单点
This commit is contained in:
@@ -2,7 +2,7 @@ package com.ruoyi.common.constant;
|
||||
|
||||
/**
|
||||
* 缓存的key 常量
|
||||
*
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class CacheConstants
|
||||
@@ -11,11 +11,12 @@ public class CacheConstants
|
||||
* 登录用户 redis key
|
||||
*/
|
||||
public static final String LOGIN_TOKEN_KEY = "login_tokens:";
|
||||
|
||||
public static final String SITE_LOGIN_TOKEN_KEY = "site_login_tokens:";
|
||||
/**
|
||||
* 验证码 redis key
|
||||
*/
|
||||
public static final String CAPTCHA_CODE_KEY = "captcha_codes:";
|
||||
public static final String SMG_CODE_KEY = "smg_codes:";
|
||||
|
||||
/**
|
||||
* 参数管理 cache key
|
||||
@@ -42,4 +43,5 @@ public class CacheConstants
|
||||
* 登录账户密码错误次数 redis key
|
||||
*/
|
||||
public static final String PWD_ERR_CNT_KEY = "pwd_err_cnt:";
|
||||
public static final String PWD_ERR_CNT_KEY_SITE = "site:pwd_err_cnt:";
|
||||
}
|
||||
|
@@ -5,7 +5,7 @@ import io.jsonwebtoken.Claims;
|
||||
|
||||
/**
|
||||
* 通用常量信息
|
||||
*
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class Constants
|
||||
@@ -109,6 +109,10 @@ public class Constants
|
||||
* 令牌前缀
|
||||
*/
|
||||
public static final String LOGIN_USER_KEY = "login_user_key";
|
||||
public static final String APP_LOGIN_USER_KEY = "app_login_user_key";
|
||||
public static final String LOGIN_USER_ID = "login_user_id";
|
||||
public static final String APP_LOGIN_USER_ID = "login_user_id";
|
||||
public static final String EXP = "exp";
|
||||
|
||||
/**
|
||||
* 用户ID
|
||||
|
@@ -0,0 +1,116 @@
|
||||
package com.ruoyi.common.core.domain.entity;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
import com.ruoyi.common.annotation.Excel;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.ruoyi.common.core.domain.BaseEntity;
|
||||
/**
|
||||
* APP用户对象 app_user
|
||||
* @author lishundong
|
||||
* @date 2024-09-03
|
||||
*/
|
||||
@Data
|
||||
@ApiModel("APP用户")
|
||||
@TableName(value = "app_user")
|
||||
public class AppUser extends BaseEntity
|
||||
{
|
||||
@TableField(exist = false)
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId(value = "user_id",type = IdType.AUTO)
|
||||
@ApiModelProperty("用户ID")
|
||||
private Long userId;
|
||||
|
||||
@Excel(name = "用户名称")
|
||||
@ApiModelProperty("用户名称")
|
||||
private String name;
|
||||
|
||||
@Excel(name = "年龄段 对应字典age")
|
||||
@ApiModelProperty("年龄段 对应字典age")
|
||||
private String age;
|
||||
|
||||
@Excel(name = "用户性别", readConverterExp = "0=男,1=女")
|
||||
@ApiModelProperty("用户性别(0男 1女)对应字典sex")
|
||||
private String sex;
|
||||
|
||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||
@Excel(name = "生日", width = 30, dateFormat = "yyyy-MM-dd")
|
||||
@ApiModelProperty("生日")
|
||||
private Date birthDate;
|
||||
|
||||
@Excel(name = "学历 对应字典education")
|
||||
@ApiModelProperty("学历 对应字典education")
|
||||
private String education;
|
||||
|
||||
@Excel(name = "政治面貌")
|
||||
@ApiModelProperty("政治面貌")
|
||||
private String politicalAffiliation;
|
||||
|
||||
@Excel(name = "手机号码")
|
||||
@ApiModelProperty("手机号码")
|
||||
private String phone;
|
||||
|
||||
@Excel(name = "头像地址")
|
||||
@ApiModelProperty("头像地址")
|
||||
private String avatar;
|
||||
|
||||
@Excel(name = "最低工资")
|
||||
@ApiModelProperty("最低工资")
|
||||
private String salaryMin;
|
||||
|
||||
@Excel(name = "最高工资")
|
||||
@ApiModelProperty("最高工资")
|
||||
private String salaryMax;
|
||||
|
||||
@Excel(name = "期望工作地 对应字典area")
|
||||
@ApiModelProperty("期望工作地 对应字典area")
|
||||
private String area;
|
||||
|
||||
@Excel(name = "帐号状态", readConverterExp = "0=正常,1=停用")
|
||||
@ApiModelProperty("帐号状态(0正常 1停用)")
|
||||
private String status;
|
||||
|
||||
@Excel(name = "最后登录IP")
|
||||
@ApiModelProperty("最后登录IP")
|
||||
private String loginIp;
|
||||
|
||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||
@Excel(name = "最后登录时间", width = 30, dateFormat = "yyyy-MM-dd")
|
||||
@ApiModelProperty("最后登录时间")
|
||||
private Date loginDate;
|
||||
|
||||
@ApiModelProperty("期望岗位,逗号分隔")
|
||||
private String jobTitleId;
|
||||
|
||||
@ApiModelProperty("期望薪资")
|
||||
private String experience;
|
||||
|
||||
@ApiModelProperty("是否开启推荐(0不推荐 1推荐)")
|
||||
private Integer isRecommend;
|
||||
|
||||
@TableField(exist = false)
|
||||
@ApiModelProperty("期望岗位列表")
|
||||
private List<String> jobTitle;
|
||||
|
||||
@ApiModelProperty("身份证")
|
||||
private String idCard;
|
||||
|
||||
@ApiModelProperty("是否录用 0录用,1未录用")
|
||||
private String hire;
|
||||
|
||||
@ApiModelProperty("是否企业用户 0是,1否")
|
||||
private String isCompanyUser;
|
||||
|
||||
@TableField(exist = false)
|
||||
@ApiModelProperty("密码")
|
||||
private String password;
|
||||
}
|
@@ -0,0 +1,226 @@
|
||||
package com.ruoyi.common.core.domain.model;
|
||||
|
||||
import com.alibaba.fastjson2.annotation.JSONField;
|
||||
import com.ruoyi.common.core.domain.entity.AppUser;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* 登录用户身份权限
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class LoginSiteUser implements UserDetails
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 用户ID
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 用户唯一标识
|
||||
*/
|
||||
private String token;
|
||||
|
||||
/**
|
||||
* 登录时间
|
||||
*/
|
||||
private Long loginTime;
|
||||
|
||||
/**
|
||||
* 过期时间
|
||||
*/
|
||||
private Long expireTime;
|
||||
|
||||
/**
|
||||
* 登录IP地址
|
||||
*/
|
||||
private String ipaddr;
|
||||
|
||||
/**
|
||||
* 登录地点
|
||||
*/
|
||||
private String loginLocation;
|
||||
|
||||
/**
|
||||
* 浏览器类型
|
||||
*/
|
||||
private String browser;
|
||||
|
||||
/**
|
||||
* 操作系统
|
||||
*/
|
||||
private String os;
|
||||
|
||||
/**
|
||||
* 用户信息
|
||||
*/
|
||||
private AppUser user;
|
||||
|
||||
public LoginSiteUser(){
|
||||
|
||||
}
|
||||
public LoginSiteUser(Long userId, AppUser user){
|
||||
this.userId = userId;
|
||||
this.user = user;
|
||||
}
|
||||
public Long getUserId()
|
||||
{
|
||||
return userId;
|
||||
}
|
||||
|
||||
public void setUserId(Long userId)
|
||||
{
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public String getToken()
|
||||
{
|
||||
return token;
|
||||
}
|
||||
|
||||
public void setToken(String token)
|
||||
{
|
||||
this.token = token;
|
||||
}
|
||||
|
||||
@JSONField(serialize = false)
|
||||
@Override
|
||||
public String getPassword()
|
||||
{
|
||||
return user.getPassword();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsername()
|
||||
{
|
||||
return user.getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* 账户是否未过期,过期无法验证
|
||||
*/
|
||||
@JSONField(serialize = false)
|
||||
@Override
|
||||
public boolean isAccountNonExpired()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定用户是否解锁,锁定的用户无法进行身份验证
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@JSONField(serialize = false)
|
||||
@Override
|
||||
public boolean isAccountNonLocked()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 指示是否已过期的用户的凭据(密码),过期的凭据防止认证
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@JSONField(serialize = false)
|
||||
@Override
|
||||
public boolean isCredentialsNonExpired()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否可用 ,禁用的用户不能身份验证
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@JSONField(serialize = false)
|
||||
@Override
|
||||
public boolean isEnabled()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public Long getLoginTime()
|
||||
{
|
||||
return loginTime;
|
||||
}
|
||||
|
||||
public void setLoginTime(Long loginTime)
|
||||
{
|
||||
this.loginTime = loginTime;
|
||||
}
|
||||
|
||||
public String getIpaddr()
|
||||
{
|
||||
return ipaddr;
|
||||
}
|
||||
|
||||
public void setIpaddr(String ipaddr)
|
||||
{
|
||||
this.ipaddr = ipaddr;
|
||||
}
|
||||
|
||||
public String getLoginLocation()
|
||||
{
|
||||
return loginLocation;
|
||||
}
|
||||
|
||||
public void setLoginLocation(String loginLocation)
|
||||
{
|
||||
this.loginLocation = loginLocation;
|
||||
}
|
||||
|
||||
public String getBrowser()
|
||||
{
|
||||
return browser;
|
||||
}
|
||||
|
||||
public void setBrowser(String browser)
|
||||
{
|
||||
this.browser = browser;
|
||||
}
|
||||
|
||||
public String getOs()
|
||||
{
|
||||
return os;
|
||||
}
|
||||
|
||||
public void setOs(String os)
|
||||
{
|
||||
this.os = os;
|
||||
}
|
||||
|
||||
public Long getExpireTime()
|
||||
{
|
||||
return expireTime;
|
||||
}
|
||||
|
||||
public void setExpireTime(Long expireTime)
|
||||
{
|
||||
this.expireTime = expireTime;
|
||||
}
|
||||
|
||||
|
||||
public AppUser getUser()
|
||||
{
|
||||
return user;
|
||||
}
|
||||
|
||||
public void setUser(AppUser user)
|
||||
{
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<? extends GrantedAuthority> getAuthorities()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
@@ -0,0 +1,122 @@
|
||||
package com.ruoyi.common.utils;
|
||||
|
||||
import com.ruoyi.common.constant.HttpStatus;
|
||||
import com.ruoyi.common.core.domain.model.LoginSiteUser;
|
||||
import com.ruoyi.common.exception.ServiceException;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
|
||||
/**
|
||||
* 安全服务工具类
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class SiteSecurityUtils
|
||||
{
|
||||
|
||||
/**
|
||||
* 用户ID
|
||||
**/
|
||||
public static Long getUserId()
|
||||
{
|
||||
try
|
||||
{
|
||||
return getLoginSiteUser().getUserId();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new ServiceException("获取用户ID异常", HttpStatus.UNAUTHORIZED);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取用户账户
|
||||
**/
|
||||
public static String getUsername()
|
||||
{
|
||||
try
|
||||
{
|
||||
return getLoginSiteUser().getUsername();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new ServiceException("获取用户账户异常", HttpStatus.UNAUTHORIZED);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户
|
||||
**/
|
||||
public static LoginSiteUser getLoginSiteUser()
|
||||
{
|
||||
try
|
||||
{
|
||||
return (LoginSiteUser) getAuthentication().getPrincipal();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new ServiceException("获取用户信息异常", HttpStatus.UNAUTHORIZED);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取Authentication
|
||||
*/
|
||||
public static Authentication getAuthentication()
|
||||
{
|
||||
return SecurityContextHolder.getContext().getAuthentication();
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成BCryptPasswordEncoder密码
|
||||
*
|
||||
* @param password 密码
|
||||
* @return 加密字符串
|
||||
*/
|
||||
public static String encryptPassword(String password)
|
||||
{
|
||||
BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
|
||||
return passwordEncoder.encode(password);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断密码是否相同
|
||||
*
|
||||
* @param rawPassword 真实密码
|
||||
* @param encodedPassword 加密后字符
|
||||
* @return 结果
|
||||
*/
|
||||
public static boolean matchesPassword(String rawPassword, String encodedPassword)
|
||||
{
|
||||
BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
|
||||
return passwordEncoder.matches(rawPassword, encodedPassword);
|
||||
}
|
||||
|
||||
public static Boolean isLogin(){
|
||||
try
|
||||
{
|
||||
Object principal = getAuthentication().getPrincipal();
|
||||
if(principal.toString().equals("anonymousUser")){
|
||||
return false;
|
||||
}else {
|
||||
return true;
|
||||
}
|
||||
} catch (Exception e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static LoginSiteUser getLoginUser() {
|
||||
try
|
||||
{
|
||||
return (LoginSiteUser) getAuthentication().getPrincipal();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new ServiceException("获取用户信息异常", HttpStatus.UNAUTHORIZED);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user