|
@@ -21,8 +21,11 @@ import com.usoftchina.saas.exception.BizException;
|
|
|
import com.usoftchina.saas.exception.ExceptionCode;
|
|
import com.usoftchina.saas.exception.ExceptionCode;
|
|
|
import com.usoftchina.saas.page.PageDefault;
|
|
import com.usoftchina.saas.page.PageDefault;
|
|
|
import com.usoftchina.saas.page.PageRequest;
|
|
import com.usoftchina.saas.page.PageRequest;
|
|
|
|
|
+import com.usoftchina.saas.socket.api.SocketMessageApi;
|
|
|
import com.usoftchina.saas.utils.BeanMapper;
|
|
import com.usoftchina.saas.utils.BeanMapper;
|
|
|
import com.usoftchina.saas.utils.CollectionUtils;
|
|
import com.usoftchina.saas.utils.CollectionUtils;
|
|
|
|
|
+import com.usoftchina.saas.utils.JsonUtils;
|
|
|
|
|
+import com.usoftchina.saas.utils.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
@@ -61,6 +64,9 @@ public class AuthController {
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private AuthorizeCountService authorizeCountService;
|
|
private AuthorizeCountService authorizeCountService;
|
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private SocketMessageApi socketMessageApi;
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 登录认证获取token
|
|
* 登录认证获取token
|
|
|
*
|
|
*
|
|
@@ -107,22 +113,24 @@ public class AuthController {
|
|
|
/**
|
|
/**
|
|
|
* 账户中心登录回调
|
|
* 账户中心登录回调
|
|
|
*
|
|
*
|
|
|
|
|
+ * @param clientId 客户端唯一标志,发起请求到账户中心时带上
|
|
|
* @param info
|
|
* @param info
|
|
|
* @return
|
|
* @return
|
|
|
*/
|
|
*/
|
|
|
@PostMapping("/sso/callback")
|
|
@PostMapping("/sso/callback")
|
|
|
- public Result ssoCallback(CookieInfo info) {
|
|
|
|
|
|
|
+ public Result ssoCallback(HttpServletRequest request, @RequestParam String clientId, CookieInfo info) {
|
|
|
if (null != info && null != info.getMobile()) {
|
|
if (null != info && null != info.getMobile()) {
|
|
|
|
|
+ AccountDTO accountDTO = null;
|
|
|
Result<AccountDTO> result = accountApi.getAccount(info.getMobile());
|
|
Result<AccountDTO> result = accountApi.getAccount(info.getMobile());
|
|
|
if (!result.isSuccess()) {
|
|
if (!result.isSuccess()) {
|
|
|
if (ExceptionCode.USER_NOT_EXIST.getCode() == result.getCode()) {
|
|
if (ExceptionCode.USER_NOT_EXIST.getCode() == result.getCode()) {
|
|
|
// 新用户,自动注册
|
|
// 新用户,自动注册
|
|
|
- createAccountByCookieInfo(info);
|
|
|
|
|
|
|
+ accountDTO = createAccountByCookieInfo(info);
|
|
|
} else {
|
|
} else {
|
|
|
return Result.error(result.getCode(), result.getMessage());
|
|
return Result.error(result.getCode(), result.getMessage());
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
- AccountDTO accountDTO = result.getData();
|
|
|
|
|
|
|
+ accountDTO = result.getData();
|
|
|
// 检测uu是否正确
|
|
// 检测uu是否正确
|
|
|
if (null == accountDTO.getUu() || !info.getUserUU().equals(accountDTO.getUu())) {
|
|
if (null == accountDTO.getUu() || !info.getUserUU().equals(accountDTO.getUu())) {
|
|
|
accountDTO.setUu(info.getUserUU());
|
|
accountDTO.setUu(info.getUserUU());
|
|
@@ -132,6 +140,23 @@ public class AuthController {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ // TODO
|
|
|
|
|
+ String appId = "trade-app";
|
|
|
|
|
+ // 登录日志
|
|
|
|
|
+ authorizeLogService.save(AuthorizeLog.from(request)
|
|
|
|
|
+ .setAccountId(accountDTO.getId())
|
|
|
|
|
+ .setAppId(appId).build());
|
|
|
|
|
+ // 将登录信息推送到客户端
|
|
|
|
|
+ if (!StringUtils.isEmpty(clientId)) {
|
|
|
|
|
+ Long companyId = null;
|
|
|
|
|
+ if (!CollectionUtils.isEmpty(accountDTO.getCompanies())) {
|
|
|
|
|
+ companyId = accountDTO.getCompanies().get(0).getId();
|
|
|
|
|
+ }
|
|
|
|
|
+ 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);
|
|
|
|
|
+ socketMessageApi.sendToClient(clientId, JsonUtils.toJsonString(new AuthDTO(tokenDTO, accountDTO)));
|
|
|
|
|
+ }
|
|
|
return Result.success();
|
|
return Result.success();
|
|
|
}
|
|
}
|
|
|
return Result.error(ExceptionCode.COOKIE_ILLEGAL_ARGUMENT);
|
|
return Result.error(ExceptionCode.COOKIE_ILLEGAL_ARGUMENT);
|