|
|
@@ -21,16 +21,21 @@ import com.usoftchina.saas.exception.BizException;
|
|
|
import com.usoftchina.saas.exception.ExceptionCode;
|
|
|
import com.usoftchina.saas.page.PageDefault;
|
|
|
import com.usoftchina.saas.page.PageRequest;
|
|
|
+import com.usoftchina.saas.server.error.ServletErrorUtils;
|
|
|
import com.usoftchina.saas.socket.api.SocketMessageApi;
|
|
|
import com.usoftchina.saas.utils.BeanMapper;
|
|
|
import com.usoftchina.saas.utils.CollectionUtils;
|
|
|
import com.usoftchina.saas.utils.JsonUtils;
|
|
|
import com.usoftchina.saas.utils.StringUtils;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.IOException;
|
|
|
|
|
|
/**
|
|
|
* @author yingp
|
|
|
@@ -67,6 +72,8 @@ public class AuthController {
|
|
|
@Autowired
|
|
|
private SocketMessageApi socketMessageApi;
|
|
|
|
|
|
+ private Logger logger = LoggerFactory.getLogger(AuthController.class);
|
|
|
+
|
|
|
/**
|
|
|
* 登录认证获取token
|
|
|
*
|
|
|
@@ -111,14 +118,15 @@ public class AuthController {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 账户中心登录回调
|
|
|
+ * 账户中心登录时jsonp回调
|
|
|
*
|
|
|
* @param clientId 客户端唯一标志,发起请求到账户中心时带上
|
|
|
* @param info
|
|
|
* @return
|
|
|
*/
|
|
|
@GetMapping("/sso/callback")
|
|
|
- public Result ssoCallback(HttpServletRequest request, @RequestParam String clientId, CookieInfo info) {
|
|
|
+ public void ssoCallback(HttpServletRequest request, HttpServletResponse response,
|
|
|
+ String clientId, CookieInfo info) throws IOException{
|
|
|
if (null != info && null != info.getMobile()) {
|
|
|
AccountDTO accountDTO = null;
|
|
|
Result<AccountDTO> result = accountApi.getAccount(info.getMobile());
|
|
|
@@ -127,7 +135,9 @@ public class AuthController {
|
|
|
// 新用户,自动注册
|
|
|
accountDTO = createAccountByCookieInfo(info);
|
|
|
} else {
|
|
|
- return Result.error(result.getCode(), result.getMessage());
|
|
|
+ logger.error(result.getMessage());
|
|
|
+ ServletErrorUtils.writeMessage(response, "successCallback({success:'0'})");
|
|
|
+ return;
|
|
|
}
|
|
|
} else {
|
|
|
accountDTO = result.getData();
|
|
|
@@ -136,7 +146,9 @@ public class AuthController {
|
|
|
accountDTO.setUu(info.getUserUU());
|
|
|
Result updateResult = accountApi.update(BeanMapper.map(accountDTO, AccountUpdateDTO.class));
|
|
|
if (!updateResult.isSuccess()) {
|
|
|
- return Result.error(updateResult.getCode(), updateResult.getMessage());
|
|
|
+ logger.error(updateResult.getMessage());
|
|
|
+ ServletErrorUtils.writeMessage(response, "successCallback({success:'0'})");
|
|
|
+ return;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -157,9 +169,8 @@ public class AuthController {
|
|
|
TokenDTO tokenDTO = BeanMapper.map(jwtToken, TokenDTO.class);
|
|
|
socketMessageApi.sendToClient(clientId, JsonUtils.toJsonString(new AuthDTO(tokenDTO, accountDTO)));
|
|
|
}
|
|
|
- return Result.success();
|
|
|
+ ServletErrorUtils.writeMessage(response, "successCallback({success:'1'})");
|
|
|
}
|
|
|
- return Result.error(ExceptionCode.COOKIE_ILLEGAL_ARGUMENT);
|
|
|
}
|
|
|
|
|
|
/**
|