添加单点登录相关
This commit is contained in:
@@ -300,10 +300,17 @@ public class SysLoginController
|
|||||||
return loginService.companyLoginOrRegister(loginBody);
|
return loginService.companyLoginOrRegister(loginBody);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation("单点登录")
|
@ApiOperation("单点登录-code")
|
||||||
@PostMapping("/sso/login")
|
@PostMapping("/sso/code/login")
|
||||||
public AjaxResult ssoCheck(@RequestBody JSONObject param) {
|
public AjaxResult codeLogin(@RequestBody JSONObject param) {
|
||||||
JSONObject result = ssoService.ssoCheck(param);
|
JSONObject result = ssoService.ssoCodeLogin(param);
|
||||||
|
return AjaxResult.success(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation("单点登录-token")
|
||||||
|
@PostMapping("/sso/token/login")
|
||||||
|
public AjaxResult ssoTokenLogin(@RequestBody JSONObject param) {
|
||||||
|
JSONObject result = ssoService.ssoTokenLogin(param);
|
||||||
return AjaxResult.success(result);
|
return AjaxResult.success(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ public class SsoService {
|
|||||||
|
|
||||||
final String APP_USER_TOKEN_KEY = "app:user:token:";
|
final String APP_USER_TOKEN_KEY = "app:user:token:";
|
||||||
|
|
||||||
public JSONObject ssoCheck(JSONObject param) {
|
public JSONObject ssoCodeLogin(JSONObject param) {
|
||||||
if (ObjectUtils.isEmpty(param)) {
|
if (ObjectUtils.isEmpty(param)) {
|
||||||
throw new RuntimeException("请求参数不能为空");
|
throw new RuntimeException("请求参数不能为空");
|
||||||
}
|
}
|
||||||
@@ -124,6 +124,53 @@ public class SsoService {
|
|||||||
return tokenSiteService.createToken(loginSiteUser);
|
return tokenSiteService.createToken(loginSiteUser);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public JSONObject ssoTokenLogin(JSONObject param) {
|
||||||
|
if (ObjectUtils.isEmpty(param)) {
|
||||||
|
throw new RuntimeException("请求参数不能为空");
|
||||||
|
}
|
||||||
|
//浪潮token
|
||||||
|
String lcToken = param.getString("token");
|
||||||
|
//获取用户信息
|
||||||
|
JSONObject pJson = new JSONObject();
|
||||||
|
pJson.put("appId", webAppId);
|
||||||
|
pJson.put("appSecret", webAppSecret);
|
||||||
|
JSONObject userJson = getUserInfo(WEB_GET_USER_INFO, lcToken, pJson.toJSONString());
|
||||||
|
if (ObjectUtils.isEmpty(userJson)) {
|
||||||
|
throw new RuntimeException("获取用户信息失败");
|
||||||
|
}
|
||||||
|
//获取身份证号
|
||||||
|
String personCardNo = null;
|
||||||
|
JSONObject info = null;
|
||||||
|
if (userJson.containsKey("info")) {
|
||||||
|
info = userJson.getJSONObject("info");
|
||||||
|
if (ObjectUtils.isNotEmpty(info) && info.containsKey("personCardNo")) {
|
||||||
|
personCardNo = info.getString("personCardNo");
|
||||||
|
//解密处理
|
||||||
|
if (StringUtils.isEmpty(personCardNo)) {
|
||||||
|
throw new RuntimeException("获取用户证件信息失败");
|
||||||
|
}
|
||||||
|
personCardNo = EncryptUtil.decryptByAppIdAndSecret(personCardNo, webAppId, webAppSecret);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//用身份证号查询用户
|
||||||
|
AppUser appUser = appUserService.selectAppuserByIdcard(personCardNo);
|
||||||
|
if (appUser == null) {
|
||||||
|
//用户不存在,则先保存用户
|
||||||
|
appUser = saveAppUser(userJson);
|
||||||
|
}
|
||||||
|
//用户存在,生成本系统用户的token
|
||||||
|
String token = loginApp(appUser, info.getString("userName"));
|
||||||
|
//缓存token
|
||||||
|
// String userKey = APP_USER_TOKEN_KEY + userJson.getString("userId");
|
||||||
|
// redisCache.setCacheObject(userKey, token, 2, TimeUnit.HOURS);
|
||||||
|
JSONObject backJson = new JSONObject();
|
||||||
|
backJson.put("token", token);
|
||||||
|
backJson.put("lcToken", lcToken);
|
||||||
|
return backJson;
|
||||||
|
}
|
||||||
|
|
||||||
//获取token
|
//获取token
|
||||||
private String getToken(String url, String token, String params) {
|
private String getToken(String url, String token, String params) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user