|
|
@@ -19,6 +19,7 @@ import com.usoftchina.saas.auth.po.VirtualAuthorizeLog;
|
|
|
import com.usoftchina.saas.auth.service.AuthorizeCountService;
|
|
|
import com.usoftchina.saas.auth.service.AuthorizeLogService;
|
|
|
import com.usoftchina.saas.base.Result;
|
|
|
+import com.usoftchina.saas.cache.CacheKeyHelper;
|
|
|
import com.usoftchina.saas.exception.BizException;
|
|
|
import com.usoftchina.saas.exception.ExceptionCode;
|
|
|
import com.usoftchina.saas.page.PageDefault;
|
|
|
@@ -98,7 +99,6 @@ public class AuthController {
|
|
|
if (authorizeCountService.isFrozen(username)) {
|
|
|
return Result.error(ExceptionCode.AUTH_FROZEN);
|
|
|
}
|
|
|
-
|
|
|
Result<AccountDTO> result = accountApi.validByUsernameAndPwd(username, password);
|
|
|
if (result.isSuccess()) {
|
|
|
authorizeCountService.clear(username);
|
|
|
@@ -114,6 +114,9 @@ public class AuthController {
|
|
|
JwtInfo info = new JwtInfo(appId, companyId, accountDTO.getId(), accountDTO.getUsername(), accountDTO.getRealname());
|
|
|
JwtToken jwtToken = JwtHelper.generateToken(info, privateKeyPath, expire);
|
|
|
TokenDTO tokenDTO = BeanMapper.map(jwtToken, TokenDTO.class);
|
|
|
+ //登陆成功记入redis
|
|
|
+ String key = CacheKeyHelper.generatePublicKey(tokenDTO.getToken());
|
|
|
+ RedisUtil.set(key, tokenDTO, expire);
|
|
|
// 登录日志
|
|
|
authorizeLogService.save(AuthorizeLog.from(request)
|
|
|
.setAccountId(accountDTO.getId())
|
|
|
@@ -153,6 +156,9 @@ public class AuthController {
|
|
|
JwtInfo info = new JwtInfo(appId, companyId, accountDTO.getId(), accountDTO.getUsername(), accountDTO.getRealname());
|
|
|
JwtToken jwtToken = JwtHelper.generateToken(info, privateKeyPath, expire);
|
|
|
TokenDTO tokenDTO = BeanMapper.map(jwtToken, TokenDTO.class);
|
|
|
+ //登陆成功记入redis
|
|
|
+ String key = CacheKeyHelper.generatePublicKey(tokenDTO.getToken());
|
|
|
+ RedisUtil.set(key, tokenDTO, expire);
|
|
|
// 登录日志
|
|
|
authorizeLogService.saveVirtual(VirtualAuthorizeLog.from(request)
|
|
|
.setMobile(Long.parseLong(accountDTO.getMobile()))
|
|
|
@@ -207,6 +213,9 @@ public class AuthController {
|
|
|
if (null != companyDTO){
|
|
|
authDTO.setCompanyId(companyDTO.getId());
|
|
|
}
|
|
|
+ //登陆成功记入redis
|
|
|
+ String key = CacheKeyHelper.generatePublicKey(tokenDTO.getToken());
|
|
|
+ RedisUtil.set(key, authDTO, expire);
|
|
|
return Result.success(authDTO);
|
|
|
}
|
|
|
return Result.error(ExceptionCode.COOKIE_ILLEGAL_ARGUMENT);
|
|
|
@@ -262,8 +271,12 @@ public class AuthController {
|
|
|
JwtInfo jwtInfo = new JwtInfo(appId, companyId, accountDTO.getId(), accountDTO.getUsername(), accountDTO.getRealname());
|
|
|
JwtToken jwtToken = JwtHelper.generateToken(jwtInfo, privateKeyPath, expire);
|
|
|
TokenDTO tokenDTO = BeanMapper.map(jwtToken, TokenDTO.class);
|
|
|
+ AuthDTO authDTO = new AuthDTO(tokenDTO, accountDTO);
|
|
|
+ //登陆成功记入redis
|
|
|
+ String key = CacheKeyHelper.generatePublicKey(tokenDTO.getToken());
|
|
|
+ RedisUtil.set(key, authDTO, expire);
|
|
|
socketMessageApi.sendToClient(new ClientMessage(clientId, "/sso/callback",
|
|
|
- JsonUtils.toJsonString(new AuthDTO(tokenDTO, accountDTO))));
|
|
|
+ JsonUtils.toJsonString(authDTO)));
|
|
|
}
|
|
|
ServletUtils.writeJsonPMessage(response, callback, true);
|
|
|
}
|
|
|
@@ -310,6 +323,9 @@ public class AuthController {
|
|
|
JwtInfo info = new JwtInfo(infoFromToken.getAppId(), companyId, infoFromToken.getUserId(),
|
|
|
infoFromToken.getUserName(), infoFromToken.getRealName());
|
|
|
JwtToken jwtToken = JwtHelper.generateToken(info, privateKeyPath, expire);
|
|
|
+ //登陆成功记入redis
|
|
|
+ String key = CacheKeyHelper.generatePublicKey(jwtToken.getToken());
|
|
|
+ RedisUtil.set(key, info, expire);
|
|
|
return Result.success(BeanMapper.map(jwtToken, TokenDTO.class));
|
|
|
}
|
|
|
return Result.error(ExceptionCode.COMPANY_NOT_BIND);
|
|
|
@@ -370,4 +386,23 @@ public class AuthController {
|
|
|
public Result<PageInfo<AuthorizeLogDTO>> getLogs(@PageDefault PageRequest page) {
|
|
|
return Result.success(authorizeLogService.findByPage(page));
|
|
|
}
|
|
|
+ /**
|
|
|
+ * @Description 重新生成Token
|
|
|
+ * @Param: [info]
|
|
|
+ * @return: TokenDTO
|
|
|
+ * @Author: guq
|
|
|
+ * @Date: 2018/12/27
|
|
|
+ */
|
|
|
+ @PostMapping("/generateToken")
|
|
|
+ public Result<TokenDTO> generateToken(@RequestBody JwtInfo info) {
|
|
|
+ TokenDTO tokenDTO = null;
|
|
|
+ if (!StringUtils.isEmpty(info)) {
|
|
|
+ JwtToken jwtToken = JwtHelper.generateToken(info, privateKeyPath, expire);
|
|
|
+ tokenDTO = BeanMapper.map(jwtToken, TokenDTO.class);
|
|
|
+ //登陆成功记入redis
|
|
|
+ String key = CacheKeyHelper.generatePublicKey(jwtToken.getToken());
|
|
|
+ RedisUtil.set(key, info, expire);
|
|
|
+ }
|
|
|
+ return Result.success(tokenDTO);
|
|
|
+ }
|
|
|
}
|