|
@@ -13,11 +13,13 @@ import com.gz.common.DataGlobalVariable;
|
|
|
import com.gz.core.exception.BusinessException;
|
|
import com.gz.core.exception.BusinessException;
|
|
|
import com.gz.core.exception.CustomExceptionEnum;
|
|
import com.gz.core.exception.CustomExceptionEnum;
|
|
|
import com.gz.dto.system.AdminDTO;
|
|
import com.gz.dto.system.AdminDTO;
|
|
|
|
|
+import com.gz.dto.system.DeptDTO;
|
|
|
import com.gz.dto.system.LogDTO;
|
|
import com.gz.dto.system.LogDTO;
|
|
|
import com.gz.dto.system.MenuDTO;
|
|
import com.gz.dto.system.MenuDTO;
|
|
|
import com.gz.jwt.JwtConfig;
|
|
import com.gz.jwt.JwtConfig;
|
|
|
import com.gz.jwt.JwtPayload;
|
|
import com.gz.jwt.JwtPayload;
|
|
|
import com.gz.mapper.system.AdminMapper;
|
|
import com.gz.mapper.system.AdminMapper;
|
|
|
|
|
+import com.gz.mapper.system.DeptMapper;
|
|
|
import com.gz.mapper.system.LogMapper;
|
|
import com.gz.mapper.system.LogMapper;
|
|
|
import com.gz.mapper.system.MenuMapper;
|
|
import com.gz.mapper.system.MenuMapper;
|
|
|
import com.gz.rvo.system.InitialHomeRVO;
|
|
import com.gz.rvo.system.InitialHomeRVO;
|
|
@@ -43,6 +45,7 @@ import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 身份验证Service
|
|
* 身份验证Service
|
|
|
|
|
+ *
|
|
|
* @author LiuchangLan
|
|
* @author LiuchangLan
|
|
|
* @date 2021/1/28 12:55
|
|
* @date 2021/1/28 12:55
|
|
|
*/
|
|
*/
|
|
@@ -65,6 +68,9 @@ public class AuthServiceImpl implements AuthService {
|
|
|
@Resource
|
|
@Resource
|
|
|
private LogMapper logMapper;
|
|
private LogMapper logMapper;
|
|
|
|
|
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private DeptMapper deptMapper;
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
public LoginRVO login(LoginVO vo) {
|
|
public LoginRVO login(LoginVO vo) {
|
|
|
// 后台存储的验证码
|
|
// 后台存储的验证码
|
|
@@ -78,7 +84,7 @@ public class AuthServiceImpl implements AuthService {
|
|
|
param.setAccount(vo.getAccount());
|
|
param.setAccount(vo.getAccount());
|
|
|
AdminDTO loginDTO = adminMapper.selectOne(param);
|
|
AdminDTO loginDTO = adminMapper.selectOne(param);
|
|
|
// 用户名没查到
|
|
// 用户名没查到
|
|
|
- if (loginDTO == null){
|
|
|
|
|
|
|
+ if (loginDTO == null) {
|
|
|
throw new BusinessException(CustomExceptionEnum.ACCOUNT_OR_PASSWORD_INCORRECT);
|
|
throw new BusinessException(CustomExceptionEnum.ACCOUNT_OR_PASSWORD_INCORRECT);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -88,11 +94,12 @@ public class AuthServiceImpl implements AuthService {
|
|
|
throw new BusinessException(CustomExceptionEnum.ACCOUNT_DISABLE);
|
|
throw new BusinessException(CustomExceptionEnum.ACCOUNT_DISABLE);
|
|
|
}
|
|
}
|
|
|
// 密码不正确
|
|
// 密码不正确
|
|
|
- if (!PasswordUtils.verification(vo.getPassword(), loginDTO.getSalt(), loginDTO.getPassword())){
|
|
|
|
|
|
|
+ if (!PasswordUtils.verification(vo.getPassword(), loginDTO.getSalt(), loginDTO.getPassword())) {
|
|
|
throw new BusinessException(CustomExceptionEnum.ACCOUNT_OR_PASSWORD_INCORRECT);
|
|
throw new BusinessException(CustomExceptionEnum.ACCOUNT_OR_PASSWORD_INCORRECT);
|
|
|
}
|
|
}
|
|
|
|
|
+ DeptDTO deptDTO = deptMapper.selectByPrimaryKey(loginDTO.getDeptId());
|
|
|
// 生成jwt载体
|
|
// 生成jwt载体
|
|
|
- JwtPayload jwtPayload = new JwtPayload(loginDTO.getId(), loginDTO.getAccount(), loginDTO.getAdminName(),loginDTO.getRoleId());
|
|
|
|
|
|
|
+ JwtPayload jwtPayload = new JwtPayload(loginDTO.getId(), loginDTO.getAccount(), loginDTO.getAdminName(), loginDTO.getRoleId(), loginDTO.getDeptId(), deptDTO.getDeptName());
|
|
|
// token
|
|
// token
|
|
|
String token = JwtUtils.createToken(jwtPayload, JwtConfig.ACCESS_TOKEN_EFFECTIVE);
|
|
String token = JwtUtils.createToken(jwtPayload, JwtConfig.ACCESS_TOKEN_EFFECTIVE);
|
|
|
// refreshToken
|
|
// refreshToken
|
|
@@ -106,15 +113,15 @@ public class AuthServiceImpl implements AuthService {
|
|
|
// refresh token 设置过期时间
|
|
// refresh token 设置过期时间
|
|
|
stringRedisTemplate.expire(refreshTokenKey, JwtConfig.REFRESH_TOKEN_EXPIRE_TIME, TimeUnit.SECONDS);
|
|
stringRedisTemplate.expire(refreshTokenKey, JwtConfig.REFRESH_TOKEN_EXPIRE_TIME, TimeUnit.SECONDS);
|
|
|
// 记录登录日志
|
|
// 记录登录日志
|
|
|
- logMapper.insertSelective(new LogDTO(DataGlobalVariable.LOGIN_LOG_CODE,"系统管理","登录","com.gz.controller.system.login",null,null, RequestUtils.getIpAddress(request),null,null));
|
|
|
|
|
- log.info("账号:{} 密码:{} 登录成功",vo.getAccount(),vo.getPassword());
|
|
|
|
|
|
|
+ logMapper.insertSelective(new LogDTO(DataGlobalVariable.LOGIN_LOG_CODE, "系统管理", "登录", "com.gz.controller.system.login", null, null, RequestUtils.getIpAddress(request), null, null));
|
|
|
|
|
+ log.info("账号:{} 密码:{} 登录成功", vo.getAccount(), vo.getPassword());
|
|
|
return new LoginRVO(token, refreshToken, System.currentTimeMillis());
|
|
return new LoginRVO(token, refreshToken, System.currentTimeMillis());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public LoginRVO refreshToken(String refreshToken) {
|
|
public LoginRVO refreshToken(String refreshToken) {
|
|
|
String refreshTokenKey = String.format(JwtConfig.REFRESH_TOKEN_KEY_FORMAT, refreshToken);
|
|
String refreshTokenKey = String.format(JwtConfig.REFRESH_TOKEN_KEY_FORMAT, refreshToken);
|
|
|
- String payload = (String)stringRedisTemplate.opsForHash().get(refreshTokenKey, JwtConfig.REDIS_JWT_PAYLOAD_KEY);
|
|
|
|
|
|
|
+ String payload = (String) stringRedisTemplate.opsForHash().get(refreshTokenKey, JwtConfig.REDIS_JWT_PAYLOAD_KEY);
|
|
|
|
|
|
|
|
if (StringUtils.isEmpty(payload)) { // refreshtoken 已经过期
|
|
if (StringUtils.isEmpty(payload)) { // refreshtoken 已经过期
|
|
|
throw new BusinessException(CustomExceptionEnum.LOGIN_TIMEOUT);
|
|
throw new BusinessException(CustomExceptionEnum.LOGIN_TIMEOUT);
|
|
@@ -123,7 +130,7 @@ public class AuthServiceImpl implements AuthService {
|
|
|
JwtPayload JwtPayload = JSONObject.parseObject(payload, JwtPayload.class);
|
|
JwtPayload JwtPayload = JSONObject.parseObject(payload, JwtPayload.class);
|
|
|
String newAccessToken = JwtUtils.createToken(JwtPayload, JwtConfig.ACCESS_TOKEN_EFFECTIVE);
|
|
String newAccessToken = JwtUtils.createToken(JwtPayload, JwtConfig.ACCESS_TOKEN_EFFECTIVE);
|
|
|
|
|
|
|
|
- String oldAccessToken = (String)stringRedisTemplate.opsForHash().get(refreshTokenKey, JwtConfig.REDIS_JWT_TOKEN_KEY);
|
|
|
|
|
|
|
+ String oldAccessToken = (String) stringRedisTemplate.opsForHash().get(refreshTokenKey, JwtConfig.REDIS_JWT_TOKEN_KEY);
|
|
|
stringRedisTemplate.opsForHash().put(refreshTokenKey, JwtConfig.REDIS_JWT_TOKEN_KEY, newAccessToken);
|
|
stringRedisTemplate.opsForHash().put(refreshTokenKey, JwtConfig.REDIS_JWT_TOKEN_KEY, newAccessToken);
|
|
|
|
|
|
|
|
// 旧 token 放入黑名单,防止超过 10s 后被再次使用
|
|
// 旧 token 放入黑名单,防止超过 10s 后被再次使用
|
|
@@ -131,7 +138,7 @@ public class AuthServiceImpl implements AuthService {
|
|
|
stringRedisTemplate.opsForValue()
|
|
stringRedisTemplate.opsForValue()
|
|
|
.set(blacklistKey, oldAccessToken, JwtConfig.ACCESS_TOKEN_EFFECTIVE, TimeUnit.SECONDS);
|
|
.set(blacklistKey, oldAccessToken, JwtConfig.ACCESS_TOKEN_EFFECTIVE, TimeUnit.SECONDS);
|
|
|
|
|
|
|
|
- return new LoginRVO(newAccessToken,refreshToken,System.currentTimeMillis());
|
|
|
|
|
|
|
+ return new LoginRVO(newAccessToken, refreshToken, System.currentTimeMillis());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -146,7 +153,7 @@ public class AuthServiceImpl implements AuthService {
|
|
|
@Override
|
|
@Override
|
|
|
public void logout(String refreshToken) {
|
|
public void logout(String refreshToken) {
|
|
|
String refreshTokenKey = String.format(JwtConfig.REFRESH_TOKEN_KEY_FORMAT, refreshToken);
|
|
String refreshTokenKey = String.format(JwtConfig.REFRESH_TOKEN_KEY_FORMAT, refreshToken);
|
|
|
- String oldAccessToken = (String)stringRedisTemplate.opsForHash().get(refreshTokenKey, JwtConfig.REDIS_JWT_TOKEN_KEY);
|
|
|
|
|
|
|
+ String oldAccessToken = (String) stringRedisTemplate.opsForHash().get(refreshTokenKey, JwtConfig.REDIS_JWT_TOKEN_KEY);
|
|
|
if (!StringUtils.isEmpty(oldAccessToken)) {
|
|
if (!StringUtils.isEmpty(oldAccessToken)) {
|
|
|
// 旧 token 放入黑名单,防止再次被调用
|
|
// 旧 token 放入黑名单,防止再次被调用
|
|
|
String blacklistKey = String.format(JwtConfig.BLACKLIST_KEY_FORMAT, oldAccessToken); // 被黑名单的 key
|
|
String blacklistKey = String.format(JwtConfig.BLACKLIST_KEY_FORMAT, oldAccessToken); // 被黑名单的 key
|
|
@@ -161,12 +168,12 @@ public class AuthServiceImpl implements AuthService {
|
|
|
public InitialHomeRVO getLoginMenus() {
|
|
public InitialHomeRVO getLoginMenus() {
|
|
|
InitialHomeRVO initialHomeRVO = new InitialHomeRVO();
|
|
InitialHomeRVO initialHomeRVO = new InitialHomeRVO();
|
|
|
// 设置首页信息
|
|
// 设置首页信息
|
|
|
- initialHomeRVO.getHomeInfo().put("title","首页");
|
|
|
|
|
- initialHomeRVO.getHomeInfo().put("href","page/home/welcome.html?t=1");
|
|
|
|
|
|
|
+ initialHomeRVO.getHomeInfo().put("title", "首页");
|
|
|
|
|
+ initialHomeRVO.getHomeInfo().put("href", "page/home/welcome.html?t=1");
|
|
|
// logo信息
|
|
// logo信息
|
|
|
- initialHomeRVO.getLogoInfo().put("title","档案管理");
|
|
|
|
|
- initialHomeRVO.getLogoInfo().put("image","images/logo.png");
|
|
|
|
|
- initialHomeRVO.getLogoInfo().put("href","");
|
|
|
|
|
|
|
+ initialHomeRVO.getLogoInfo().put("title", "南京市规划和自然资源局-综合档案数字化信息系统");
|
|
|
|
|
+ initialHomeRVO.getLogoInfo().put("image", "images/logo.png");
|
|
|
|
|
+ initialHomeRVO.getLogoInfo().put("href", "");
|
|
|
|
|
|
|
|
// 获取所有菜单
|
|
// 获取所有菜单
|
|
|
List<MenuDTO> menusOrder = menuMapper.getRoleMenu(JwtUtils.getCurrentUserJwtPayload().getRoleId());
|
|
List<MenuDTO> menusOrder = menuMapper.getRoleMenu(JwtUtils.getCurrentUserJwtPayload().getRoleId());
|
|
@@ -185,8 +192,8 @@ public class AuthServiceImpl implements AuthService {
|
|
|
tree.setId(treeNode.getId().toString());
|
|
tree.setId(treeNode.getId().toString());
|
|
|
tree.setParentId(treeNode.getParentId().toString());
|
|
tree.setParentId(treeNode.getParentId().toString());
|
|
|
tree.setName(treeNode.getTitle());
|
|
tree.setName(treeNode.getTitle());
|
|
|
- tree.putExtra("href",treeNode.getHref());
|
|
|
|
|
- tree.putExtra("icon",treeNode.getIcon());
|
|
|
|
|
|
|
+ tree.putExtra("href", treeNode.getHref());
|
|
|
|
|
+ tree.putExtra("icon", treeNode.getIcon());
|
|
|
});
|
|
});
|
|
|
initialHomeRVO.setMenuInfo(treeNodes);
|
|
initialHomeRVO.setMenuInfo(treeNodes);
|
|
|
|
|
|
|
@@ -196,13 +203,13 @@ public class AuthServiceImpl implements AuthService {
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public Integer updatePassword(UpdatePasswordVO vo) throws BusinessException {
|
|
public Integer updatePassword(UpdatePasswordVO vo) throws BusinessException {
|
|
|
- Integer id = JwtUtils.getCurrentUserJwtPayload().getId();
|
|
|
|
|
|
|
+ String id = JwtUtils.getCurrentUserJwtPayload().getId();
|
|
|
AdminDTO adminDTO = adminMapper.selectByPrimaryKey(id);
|
|
AdminDTO adminDTO = adminMapper.selectByPrimaryKey(id);
|
|
|
String salt = adminDTO.getSalt();
|
|
String salt = adminDTO.getSalt();
|
|
|
String password = adminDTO.getPassword();
|
|
String password = adminDTO.getPassword();
|
|
|
|
|
|
|
|
// 密码不正确
|
|
// 密码不正确
|
|
|
- if (!PasswordUtils.verification(vo.getOldPassword(),salt,password)) {
|
|
|
|
|
|
|
+ if (!PasswordUtils.verification(vo.getOldPassword(), salt, password)) {
|
|
|
throw new BusinessException(CustomExceptionEnum.PASSWORD_NO_INCORRECT);
|
|
throw new BusinessException(CustomExceptionEnum.PASSWORD_NO_INCORRECT);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -217,7 +224,7 @@ public class AuthServiceImpl implements AuthService {
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public List<MenuDTO> getLoginButtons(Integer menuId) {
|
|
public List<MenuDTO> getLoginButtons(Integer menuId) {
|
|
|
- return menuMapper.getRoleButtle(JwtUtils.getCurrentUserJwtPayload().getRoleId(),menuId);
|
|
|
|
|
|
|
+ return menuMapper.getRoleButtle(JwtUtils.getCurrentUserJwtPayload().getRoleId(), menuId);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -228,17 +235,17 @@ public class AuthServiceImpl implements AuthService {
|
|
|
HttpSession session = request.getSession();
|
|
HttpSession session = request.getSession();
|
|
|
// lineCaptcha = CaptchaUtil.createLineCaptcha(200, 100);
|
|
// lineCaptcha = CaptchaUtil.createLineCaptcha(200, 100);
|
|
|
circleCaptcha = CaptchaUtil.createCircleCaptcha(200, 100, 4, 20);
|
|
circleCaptcha = CaptchaUtil.createCircleCaptcha(200, 100, 4, 20);
|
|
|
- session.setAttribute("captcha",circleCaptcha.getCode());
|
|
|
|
|
- log.info("生成验证码:{}",circleCaptcha.getCode());
|
|
|
|
|
|
|
+ session.setAttribute("captcha", circleCaptcha.getCode());
|
|
|
|
|
+ log.info("生成验证码:{}", circleCaptcha.getCode());
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
- throw new BusinessException(500,"生成验证码失败");
|
|
|
|
|
|
|
+ throw new BusinessException(500, "生成验证码失败");
|
|
|
}
|
|
}
|
|
|
return "data:image/jpg;base64," + circleCaptcha.getImageBase64();
|
|
return "data:image/jpg;base64," + circleCaptcha.getImageBase64();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public AdminDTO currLoginAdmin() {
|
|
public AdminDTO currLoginAdmin() {
|
|
|
- Integer id = JwtUtils.getCurrentUserJwtPayload().getId();
|
|
|
|
|
|
|
+ String id = JwtUtils.getCurrentUserJwtPayload().getId();
|
|
|
return adminMapper.selectByPrimaryKey(id);
|
|
return adminMapper.selectByPrimaryKey(id);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|