Commit 5e39eccd by 宋振民

feat:系统安全功能开发

parent dbabcc51
...@@ -69,10 +69,4 @@ public class LoginController { ...@@ -69,10 +69,4 @@ public class LoginController {
return Result.success(token); return Result.success(token);
} }
@GetMapping("init")
@ApiOperation("批量初始化密码")
public Object init() throws Exception {
int count = userService.init();
return Result.success(count);
}
} }
...@@ -135,7 +135,7 @@ public class UserController { ...@@ -135,7 +135,7 @@ public class UserController {
* *
* @return * @return
*/ */
@PostMapping("init") @GetMapping("init")
@ApiOperation("批量初始化密码") @ApiOperation("批量初始化密码")
public Object init() throws Exception { public Object init() throws Exception {
int count = userService.init(); int count = userService.init();
......
...@@ -14,6 +14,8 @@ public interface SysUserMapper { ...@@ -14,6 +14,8 @@ public interface SysUserMapper {
List<SysUser> selectAll(); List<SysUser> selectAll();
void copySysUser(@Param("tableName") String tableName);
int updateByPrimaryKey(SysUser record); int updateByPrimaryKey(SysUser record);
SysUser selectByCode(@Param("userCode") String loginName); SysUser selectByCode(@Param("userCode") String loginName);
......
...@@ -58,7 +58,7 @@ public class LoginServiceImpl implements LoginService { ...@@ -58,7 +58,7 @@ public class LoginServiceImpl implements LoginService {
SysUser user = userServiceImpl.findByLoginName(logName); SysUser user = userServiceImpl.findByLoginName(logName);
//判断是否被锁定 //判断是否被锁定
if(user.isLockFlag()) if(user != null && user.isLockFlag())
throw new DBConfigurationError("该账号已被锁定请联系管理员解锁!"); throw new DBConfigurationError("该账号已被锁定请联系管理员解锁!");
//判断是否很久没有更改密码 //判断是否很久没有更改密码
if(sysConfigService.getStateByKey(SysConfigKeyType.PWD_TIME_LIMIT.getCode()) if(sysConfigService.getStateByKey(SysConfigKeyType.PWD_TIME_LIMIT.getCode())
......
package com.hs.api.service.Impl; package com.hs.api.service.Impl;
import com.hs.api.common.utils.AESUtil; import com.hs.api.common.utils.AESUtil;
import com.hs.api.common.utils.DateUtils;
import com.hs.api.mapper.DicUserMapper; import com.hs.api.mapper.DicUserMapper;
import com.hs.api.mapper.SysUserMapper; import com.hs.api.mapper.SysUserMapper;
import com.hs.api.model.SysUser; import com.hs.api.model.SysUser;
...@@ -8,7 +9,10 @@ import com.hs.api.service.UserService; ...@@ -8,7 +9,10 @@ import com.hs.api.service.UserService;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.Calendar;
import java.util.Date;
import java.util.List; import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
@Service @Service
public class UserServiceImpl implements UserService { public class UserServiceImpl implements UserService {
...@@ -36,14 +40,18 @@ public class UserServiceImpl implements UserService { ...@@ -36,14 +40,18 @@ public class UserServiceImpl implements UserService {
@Override @Override
public int init() { public int init() {
List<SysUser> sysUsers = sysUserMapper.selectAll(); List<SysUser> sysUsers = sysUserMapper.selectAll();
Calendar calendar = DateUtils.getCalendar(new Date());
sysUserMapper.copySysUser("sys_user" + calendar.getTimeInMillis());
AtomicInteger count = new AtomicInteger();
sysUsers.stream().forEach(user -> { sysUsers.stream().forEach(user -> {
String password = user.getPassword(); String password = user.getPassword();
user.setPassword(AESUtil.encrypt(password)); user.setPassword(AESUtil.encrypt(password));
if(!user.getPwdInit()) { if(!user.getPwdInit()) {
user.setPwdInit(true); user.setPwdInit(true);
sysUserMapper.updateByPrimaryKey(user); sysUserMapper.updateByPrimaryKey(user);
count.getAndIncrement();
} }
}); });
return sysUsers.size(); return count.intValue();
} }
} }
...@@ -84,6 +84,9 @@ ...@@ -84,6 +84,9 @@
from SYS_USER from SYS_USER
where ID = #{id,jdbcType=DECIMAL} where ID = #{id,jdbcType=DECIMAL}
</select> </select>
<update id="copySysUser" parameterType="java.lang.String">
create table ${tableName} select * from sys_user
</update>
<select id="selectAll" resultMap="BaseResultMap"> <select id="selectAll" resultMap="BaseResultMap">
select ID, select ID,
CREATE_DATE, CREATE_DATE,
......
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