Commit e085ac44 by 宋振民

feat:系统安全功能完善

parent 75dd53d1
...@@ -88,6 +88,17 @@ public class UserController { ...@@ -88,6 +88,17 @@ public class UserController {
return Result.error(); return Result.error();
} }
@PostMapping("unlock")
@Token
@ApiOperation("解锁用户")
public Object unlockUser(@RequestBody UserReq.UnlockUserReq user) throws Exception {
boolean result = userService.unlockUser(user);
if (result)
return Result.success(null);
else
return Result.error();
}
@PostMapping("update") @PostMapping("update")
@Token @Token
@ApiOperation("修改用户") @ApiOperation("修改用户")
......
...@@ -33,10 +33,14 @@ public class SysUser { ...@@ -33,10 +33,14 @@ public class SysUser {
private Date lastTime; private Date lastTime;
private Date lastUpdatePwdTime;
private String lastIp; private String lastIp;
private boolean isAdmin; private boolean isAdmin;
private boolean lockFlag;
public Integer getId() { public Integer getId() {
return id; return id;
} }
...@@ -164,4 +168,20 @@ public class SysUser { ...@@ -164,4 +168,20 @@ public class SysUser {
public void setIsAdmin(boolean isAdmin) { public void setIsAdmin(boolean isAdmin) {
this.isAdmin = isAdmin; this.isAdmin = isAdmin;
} }
public Date getLastUpdatePwdTime() {
return lastUpdatePwdTime;
}
public void setLastUpdatePwdTime(Date lastUpdatePwdTime) {
this.lastUpdatePwdTime = lastUpdatePwdTime;
}
public boolean getLockFlag() {
return lockFlag;
}
public void setLockFlag(boolean lockFlag) {
this.lockFlag = lockFlag;
}
} }
\ No newline at end of file
...@@ -165,6 +165,27 @@ public class UserReq { ...@@ -165,6 +165,27 @@ public class UserReq {
} }
} }
public static class UnlockUserReq {
@ApiModelProperty(value = "用户ID", required = true)
@NotNull(message = "用户ID 参数必传")
private Integer userId;
public Integer getUserId() {
return userId;
}
public void setUserId(Integer userId) {
this.userId = userId;
}
@Override
public String toString() {
return "UnlockReq{" +
"userId=" + userId +
'}';
}
}
public static class UpdateUserReq { public static class UpdateUserReq {
@ApiModelProperty(value = "用户ID", required = true) @ApiModelProperty(value = "用户ID", required = true)
@NotNull(message = "用户ID 参数必传") @NotNull(message = "用户ID 参数必传")
......
...@@ -17,6 +17,8 @@ public interface UserService { ...@@ -17,6 +17,8 @@ public interface UserService {
boolean deleteUser(UserReq.DeleteUserReq user); boolean deleteUser(UserReq.DeleteUserReq user);
boolean unlockUser(UserReq.UnlockUserReq user);
boolean updateUser(UpdateUserReq user); boolean updateUser(UpdateUserReq user);
List<SysUserList> getAll(UserReq.GetUserReq user); List<SysUserList> getAll(UserReq.GetUserReq user);
......
...@@ -54,6 +54,7 @@ public class UserServiceImpl implements UserService { ...@@ -54,6 +54,7 @@ public class UserServiceImpl implements UserService {
sysUser.setMobile(user.getMobile()); sysUser.setMobile(user.getMobile());
sysUser.setSex(user.getSex()); sysUser.setSex(user.getSex());
sysUser.setCreateDate(new Date()); sysUser.setCreateDate(new Date());
sysUser.setLastUpdatePwdTime(new Date());
sysUser.setCreateUserid(userId); sysUser.setCreateUserid(userId);
sysUser.setState((short) StateType.ON.getValue()); sysUser.setState((short) StateType.ON.getValue());
sysUser.setIsAdmin(user.getIsAdmin()); sysUser.setIsAdmin(user.getIsAdmin());
...@@ -84,6 +85,19 @@ public class UserServiceImpl implements UserService { ...@@ -84,6 +85,19 @@ public class UserServiceImpl implements UserService {
} }
@Override @Override
public boolean unlockUser(UserReq.UnlockUserReq user) {
if (user != null) {
SysUser sysUser = sysUserMapper.selectByPrimaryKey(user.getUserId());
if (sysUser != null) {
sysUser.setLockFlag(false);
sysUserMapper.updateByPrimaryKey(sysUser);
return true;
}
}
return false;
}
@Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public boolean updateUser(UpdateUserReq user) { public boolean updateUser(UpdateUserReq user) {
if (user != null) { if (user != null) {
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
<result column="LAST_TIME" jdbcType="TIMESTAMP" property="lastTime"/> <result column="LAST_TIME" jdbcType="TIMESTAMP" property="lastTime"/>
<result column="LAST_IP" jdbcType="VARCHAR" property="lastIp"/> <result column="LAST_IP" jdbcType="VARCHAR" property="lastIp"/>
<result column="IS_ADMIN" jdbcType="BOOLEAN" property="isAdmin"/> <result column="IS_ADMIN" jdbcType="BOOLEAN" property="isAdmin"/>
<result column="LOCK_FLAG" jdbcType="BOOLEAN" property="lockFlag"/>
</resultMap> </resultMap>
<resultMap id="SysUserList" extends="BaseResultMap" type="com.hs.admin.model.respmodel.SysUserList"> <resultMap id="SysUserList" extends="BaseResultMap" type="com.hs.admin.model.respmodel.SysUserList">
<result column="ROLE_ID" jdbcType="INTEGER" property="roleId"/> <result column="ROLE_ID" jdbcType="INTEGER" property="roleId"/>
...@@ -61,7 +62,8 @@ ...@@ -61,7 +62,8 @@
ERROR_TIME = #{errorTime,jdbcType=TIMESTAMP}, ERROR_TIME = #{errorTime,jdbcType=TIMESTAMP},
LAST_TIME = #{lastTime,jdbcType=TIMESTAMP}, LAST_TIME = #{lastTime,jdbcType=TIMESTAMP},
LAST_IP = #{lastIp,jdbcType=VARCHAR}, LAST_IP = #{lastIp,jdbcType=VARCHAR},
IS_ADMIN = #{isAdmin,jdbcType=VARCHAR} IS_ADMIN = #{isAdmin,jdbcType=VARCHAR},
LOCK_FLAG = #{lockFlag,jdbcType=VARCHAR}
where ID = #{id,jdbcType=INTEGER} where ID = #{id,jdbcType=INTEGER}
</update> </update>
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap"> <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
......
...@@ -8,18 +8,19 @@ import java.util.Map; ...@@ -8,18 +8,19 @@ import java.util.Map;
public enum SysConfigKeyType { public enum SysConfigKeyType {
MAC_ADDRESS_RANGE("MAC_ADDRESS_RANGE","MAC地址范围过滤"), MAC_ADDRESS_RANGE("MAC_ADDRESS_RANGE","MAC地址范围过滤"),
MAC_BINDING("MAC_BINDING","MAC地址绑定"); MAC_BINDING("MAC_BINDING","MAC地址绑定"),
PWD_TIME_LIMIT("PWD_TIME_LIMIT","密码有效期");
private String value; private String code;
private String desc; private String desc;
SysConfigKeyType(String value, String desc) { SysConfigKeyType(String code, String desc) {
this.value = value; this.code = code;
this.desc = desc; this.desc = desc;
} }
public String getValue() { public String getCode() {
return value; return code;
} }
public String getDesc() { public String getDesc() {
...@@ -31,7 +32,7 @@ public enum SysConfigKeyType { ...@@ -31,7 +32,7 @@ public enum SysConfigKeyType {
for(SysConfigKeyType projectType : values()){ for(SysConfigKeyType projectType : values()){
Map<String,Object> map = new HashMap<String,Object>() { Map<String,Object> map = new HashMap<String,Object>() {
{ {
put("value",projectType.getValue()); put("code",projectType.getCode());
put("description",projectType.getDesc()); put("description",projectType.getDesc());
} }
}; };
......
...@@ -7,6 +7,6 @@ import org.apache.ibatis.annotations.Param; ...@@ -7,6 +7,6 @@ import org.apache.ibatis.annotations.Param;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
public interface SysLoginConfigMapper { public interface SysConfigMapper {
List<SysConfig> selectByKey(String key); List<SysConfig> selectByKey(String key);
} }
\ No newline at end of file
...@@ -29,12 +29,16 @@ public class SysUser { ...@@ -29,12 +29,16 @@ public class SysUser {
private Date errorTime; private Date errorTime;
private Date lastUpdatePwdTime;
private Date lastTime; private Date lastTime;
private String lastIp; private String lastIp;
private String macAddress; private String macAddress;
private boolean lockFlag;
public Long getId() { public Long getId() {
return id; return id;
} }
...@@ -162,4 +166,24 @@ public class SysUser { ...@@ -162,4 +166,24 @@ public class SysUser {
public void setMacAddress(String macAddress) { public void setMacAddress(String macAddress) {
this.macAddress = macAddress; this.macAddress = macAddress;
} }
public Date getLastUpdatePwdTime() {
return lastUpdatePwdTime;
}
public void setLastUpdatePwdTime(Date lastUpdatePwdTime) {
this.lastUpdatePwdTime = lastUpdatePwdTime;
}
public boolean isLockFlag() {
return lockFlag;
}
public void setLockFlag(boolean lockFlag) {
this.lockFlag = lockFlag;
}
public void addErrorCount() {
this.errorCount = this.errorCount == null ? 1 : this.errorCount + 1;
}
} }
\ No newline at end of file
package com.hs.api.service.Impl; package com.hs.api.service.Impl;
import com.hs.api.common.enums.SysConfigKeyType;
import com.hs.api.common.exceptions.DBConfigurationError; import com.hs.api.common.exceptions.DBConfigurationError;
import com.hs.api.common.utils.DateUtils;
import com.hs.api.common.utils.TokenUtil; import com.hs.api.common.utils.TokenUtil;
import com.hs.api.mapper.DicOrgMapper; import com.hs.api.mapper.DicOrgMapper;
import com.hs.api.mapper.SysRoleMapper; import com.hs.api.mapper.SysRoleMapper;
...@@ -9,7 +11,9 @@ import com.hs.api.mapper.SysVersionMapper; ...@@ -9,7 +11,9 @@ import com.hs.api.mapper.SysVersionMapper;
import com.hs.api.model.*; import com.hs.api.model.*;
import com.hs.api.model.respmodel.LoginInfo; import com.hs.api.model.respmodel.LoginInfo;
import com.hs.api.service.LoginService; import com.hs.api.service.LoginService;
import com.hs.api.service.SysConfigService;
import com.hs.api.service.UserService; import com.hs.api.service.UserService;
import com.hs.common.utils.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -24,6 +28,9 @@ public class LoginServiceImpl implements LoginService { ...@@ -24,6 +28,9 @@ public class LoginServiceImpl implements LoginService {
@Autowired @Autowired
private UserService userServiceImpl; private UserService userServiceImpl;
@Autowired
private SysConfigService sysConfigService;
@Resource @Resource
private SysUserMapper sysUserMapper; private SysUserMapper sysUserMapper;
@Resource @Resource
...@@ -39,6 +46,14 @@ public class LoginServiceImpl implements LoginService { ...@@ -39,6 +46,14 @@ public class LoginServiceImpl implements LoginService {
LoginInfo loginInfo = new LoginInfo(); LoginInfo loginInfo = new LoginInfo();
SysUser user = userServiceImpl.findByLoginName(logName); SysUser user = userServiceImpl.findByLoginName(logName);
//判断是否被锁定
if(user.isLockFlag())
throw new DBConfigurationError("该账号已被锁定请联系管理员解锁!");
//判断是否很久没有更改密码
if(sysConfigService.getSysConfigStateByKey(SysConfigKeyType.PWD_TIME_LIMIT.getCode())
&& DateUtils.getDaysBetween(user.getLastUpdatePwdTime(), new Date()) > 90)
throw new DBConfigurationError("您已经超过90天没有更换密码,请修改密码后再登录!");
if (user != null && user.getPassword().equals(password) && (user.getMacAddress() == null || user.getMacAddress().equals(macAddrss))) { if (user != null && user.getPassword().equals(password) && (user.getMacAddress() == null || user.getMacAddress().equals(macAddrss))) {
String token = TokenUtil.getToken(password, user); String token = TokenUtil.getToken(password, user);
//修改ip以及最后登录时间、MAC地址 //修改ip以及最后登录时间、MAC地址
...@@ -64,17 +79,34 @@ public class LoginServiceImpl implements LoginService { ...@@ -64,17 +79,34 @@ public class LoginServiceImpl implements LoginService {
//查询病案信息 //查询病案信息
SysVersion version = sysVersionMapper.selectLastDate(); SysVersion version = sysVersionMapper.selectLastDate();
loginInfo.setVersion(version); loginInfo.setVersion(version);
RedisUtil.del(user.getUserCode());
} else { } else {
throw new DBConfigurationError("账号、密码或者MAC地址错误!"); if(user != null) checkErrorCount(user);
throw new DBConfigurationError("登录失败请检查用户名和密码!");
} }
return loginInfo; return loginInfo;
} }
private void checkErrorCount(SysUser user) {
String userCode = user.getUserCode();
if(RedisUtil.hasKey(userCode) && Integer.parseInt(RedisUtil.get(userCode).toString())>=5) {
user.setLockFlag(true);
sysUserMapper.updateByPrimaryKey(user);
return;
}
if(!RedisUtil.hasKey(userCode)) {
RedisUtil.set(userCode, 1, 5 * 60);
}else {
RedisUtil.incr(userCode, 1);
}
}
public boolean updatePass(String logName, String oldPassword, String newPassword) { public boolean updatePass(String logName, String oldPassword, String newPassword) {
int result = 0; int result = 0;
SysUser user = userServiceImpl.findByLoginName(logName); SysUser user = userServiceImpl.findByLoginName(logName);
if (user != null && user.getPassword().equals(oldPassword)) { if (user != null && user.getPassword().equals(oldPassword)) {
user.setPassword(newPassword); user.setPassword(newPassword);
user.setLastUpdatePwdTime(new Date());
result = sysUserMapper.updateByPrimaryKey(user); result = sysUserMapper.updateByPrimaryKey(user);
} else { } else {
throw new DBConfigurationError("旧密码错误!"); throw new DBConfigurationError("旧密码错误!");
......
package com.hs.api.service.Impl; package com.hs.api.service.Impl;
import com.hs.api.common.enums.DimType; import com.hs.api.mapper.SysConfigMapper;
import com.hs.api.mapper.DicDimMapper;
import com.hs.api.mapper.SerDimValueMapper;
import com.hs.api.mapper.SerPageBlockRsMapper;
import com.hs.api.mapper.SysLoginConfigMapper;
import com.hs.api.model.DicDim;
import com.hs.api.model.SerDimValue;
import com.hs.api.model.SysConfig; import com.hs.api.model.SysConfig;
import com.hs.api.model.respmodel.DimValue;
import com.hs.api.service.DicDimService;
import com.hs.api.service.SysConfigService; import com.hs.api.service.SysConfigService;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List; import java.util.List;
@Service @Service
public class SysConfigServiceImpl implements SysConfigService { public class SysConfigServiceImpl implements SysConfigService {
@Resource @Resource
private SysLoginConfigMapper sysLoginConfigMapper; private SysConfigMapper sysConfigMapper;
@Override @Override
public boolean getSysConfigStateByKey(String key) { public boolean getSysConfigStateByKey(String key) {
List<SysConfig> sysConfigList = sysLoginConfigMapper.selectByKey(key); List<SysConfig> sysConfigList = sysConfigMapper.selectByKey(key);
if(sysConfigList.size()==0) return false;
SysConfig sysConfig = sysConfigList.get(0); SysConfig sysConfig = sysConfigList.get(0);
return sysConfig.getState(); return sysConfig.getState();
} }
@Override
public String getSysConfigValueSByKey(String key) {
List<SysConfig> sysConfigList = sysConfigMapper.selectByKey(key);
if(sysConfigList.size()==0) return null;
SysConfig sysConfig = sysConfigList.get(0);
return sysConfig.getValue();
}
} }
...@@ -6,4 +6,6 @@ import java.util.List; ...@@ -6,4 +6,6 @@ import java.util.List;
public interface SysConfigService { public interface SysConfigService {
boolean getSysConfigStateByKey(String key); boolean getSysConfigStateByKey(String key);
String getSysConfigValueSByKey(String key);
} }
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.hs.api.mapper.SysLoginConfigMapper"> <mapper namespace="com.hs.api.mapper.SysConfigMapper">
<resultMap id="ResultMap" type="com.hs.api.model.SysConfig"> <resultMap id="ResultMap" type="com.hs.api.model.SysConfig">
<id column="ID" jdbcType="DECIMAL" property="id"/> <id column="ID" jdbcType="DECIMAL" property="id"/>
<result column="CREATE_DATE" jdbcType="TIMESTAMP" property="createDate"/> <result column="CREATE_DATE" jdbcType="TIMESTAMP" property="createDate"/>
......
...@@ -18,6 +18,8 @@ ...@@ -18,6 +18,8 @@
<result column="LAST_TIME" jdbcType="TIMESTAMP" property="lastTime"/> <result column="LAST_TIME" jdbcType="TIMESTAMP" property="lastTime"/>
<result column="LAST_IP" jdbcType="VARCHAR" property="lastIp"/> <result column="LAST_IP" jdbcType="VARCHAR" property="lastIp"/>
<result column="MAC_ADDRESS" jdbcType="VARCHAR" property="macAddress"/> <result column="MAC_ADDRESS" jdbcType="VARCHAR" property="macAddress"/>
<result column="LAST_UPDATE_PWD_TIME" jdbcType="TIMESTAMP" property="lastUpdatePwdTime"/>
<result column="LOCK_FLAG" jdbcType="BOOLEAN" property="lockFlag"/>
</resultMap> </resultMap>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long"> <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
delete delete
...@@ -55,7 +57,9 @@ ...@@ -55,7 +57,9 @@
ERROR_TIME = #{errorTime,jdbcType=TIMESTAMP}, ERROR_TIME = #{errorTime,jdbcType=TIMESTAMP},
LAST_TIME = #{lastTime,jdbcType=TIMESTAMP}, LAST_TIME = #{lastTime,jdbcType=TIMESTAMP},
LAST_IP = #{lastIp,jdbcType=VARCHAR}, LAST_IP = #{lastIp,jdbcType=VARCHAR},
MAC_ADDRESS = #{macAddress,jdbcType=VARCHAR} MAC_ADDRESS = #{macAddress,jdbcType=VARCHAR},
LAST_UPDATE_PWD_TIME = #{lastUpdatePwdTime,jdbcType=VARCHAR},
LOCK_FLAG = #{lockFlag,jdbcType=VARCHAR}
where ID = #{id,jdbcType=DECIMAL} where ID = #{id,jdbcType=DECIMAL}
</update> </update>
<select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap"> <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
...@@ -113,7 +117,9 @@ ...@@ -113,7 +117,9 @@
ERROR_TIME, ERROR_TIME,
LAST_TIME, LAST_TIME,
LAST_IP, LAST_IP,
MAC_ADDRESS MAC_ADDRESS,
LAST_UPDATE_PWD_TIME,
LOCK_FLAG
from SYS_USER from SYS_USER
where USER_CODE = #{userCode,jdbcType=VARCHAR} where USER_CODE = #{userCode,jdbcType=VARCHAR}
and `STATE` != 0 and `STATE` != 0
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment