Commit 2f2ed119 by 宋祥

1.德诚获取token接口

parent 425bd4e4
package com.baosight.xservices.xs.service;
import com.baosight.iplat4j.core.FrameworkInfo;
import com.baosight.iplat4j.core.ei.EiConstant;
import com.baosight.iplat4j.core.ei.EiInfo;
import com.baosight.iplat4j.core.log.Logger;
import com.baosight.iplat4j.core.log.LoggerFactory;
......@@ -11,11 +12,12 @@ import com.baosight.iplat4j.core.service.impl.ServiceBase;
import com.baosight.iplat4j.core.util.StringUtils;
import com.baosight.iplat4j.core.web.threadlocal.UserSession;
import com.baosight.xservices.xs.jwt.JwtTokenValidator;
import java.util.HashMap;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import java.util.HashMap;
import java.util.Map;
/**
* 重写
*
......@@ -76,6 +78,49 @@ public class ServiceXSUserJwt extends ServiceBase {
return outInfo;
}
/**
* 德诚系统对接专用
*
* @param inInfo
* @return
*/
public EiInfo generateJwtDc(EiInfo inInfo) {
String username = inInfo.getString("loginName");
String password = inInfo.getString("password");
String audience = inInfo.getString("audience");
EiInfo outInfo = new EiInfo();
try {
if (!StringUtils.isNotEmpty(audience)) {
audience = FrameworkInfo.getProjectEname().toUpperCase();
}
IUserManager um = SecurityFactory.getUserManager();
User user = um.getUser("DC" + username);
if (user == null) {
throw new UsernameNotFoundException("Can't find user!");
}
Map tokenMap = new HashMap();
tokenMap.put("sub", user.getLoginName());
tokenMap.put("uid", user.getUserId());
Object userCname = user.get("userName");
if (userCname != null) {
tokenMap.put("ucn", userCname.toString());
}
if (!StringUtils.isNotEmpty(audience)) {
audience = FrameworkInfo.getProjectEname().toUpperCase();
}
String token = this.jwtTokenValidator.generateToken(tokenMap, audience);
outInfo.setStatus(EiConstant.STATUS_SUCCESS);
outInfo.setMsg("登录成功!");
outInfo.set("token", token);
} catch (Exception var11) {
this.logger.error(var11.getMessage(), var11);
outInfo.setStatus(EiConstant.STATUS_FAILURE);
outInfo.setMsg(var11.getMessage());
}
return outInfo;
}
public EiInfo validateTest(EiInfo inInfo) {
new HashMap();
inInfo.set("userSessionData", new HashMap(UserSession.getData()));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment