You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
122 lines
3.4 KiB
122 lines
3.4 KiB
3 years ago
|
package com.fr.plugin.bsSSO.handler;
|
||
|
|
||
|
import com.fr.decision.fun.impl.BaseHttpHandler;
|
||
|
import com.fr.json.JSONObject;
|
||
|
import com.fr.plugin.bsSSO.bean.simple.account.PluginSimpleConfig;
|
||
|
import com.fr.plugin.bsSSO.utils.*;
|
||
|
import com.fr.plugin.transform.FunctionRecorder;
|
||
|
import com.fr.third.springframework.web.bind.annotation.RequestMethod;
|
||
|
|
||
|
import javax.servlet.http.Cookie;
|
||
|
import javax.servlet.http.HttpServletRequest;
|
||
|
import javax.servlet.http.HttpServletResponse;
|
||
|
|
||
|
public class PCLogin extends BaseHttpHandler {
|
||
|
|
||
|
|
||
|
public PCLogin() {
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public RequestMethod getMethod() {
|
||
|
return RequestMethod.POST;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public String getPath() {
|
||
|
return "/openapi";
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public boolean isPublic() {
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void handle(HttpServletRequest req, HttpServletResponse res){
|
||
|
PluginSimpleConfig psc = PluginSimpleConfig.getInstance();
|
||
|
String access_key = req.getParameter("access_key");
|
||
|
|
||
|
FRUtils.FRLogInfo("pc access_key " + access_key);
|
||
|
if(Utils.isNullStr(access_key) || !psc.getPkey().equals(access_key)){
|
||
|
FRUtils.FRLogInfo("access_key 无效");
|
||
|
ResponseUtils.response(res,"access_key 无效","-1","","error");
|
||
|
return ;
|
||
|
}
|
||
|
|
||
|
String sig = req.getParameter("sig");
|
||
|
FRUtils.FRLogInfo("query sig "+sig);
|
||
|
|
||
|
String allUrl = FRUtils.getAllUrl(req);
|
||
|
FRUtils.FRLogInfo("allUrl: "+allUrl);
|
||
|
String queryStr = allUrl.split("\\?")[1];
|
||
|
|
||
|
String validateSign = OpenapiUtil.generateSign(queryStr,psc.getPsecret());
|
||
|
|
||
|
FRUtils.FRLogInfo("validateSign "+sig);
|
||
|
|
||
|
if(!sig.equals(validateSign)){
|
||
|
FRUtils.FRLogInfo("验签失败");
|
||
|
|
||
|
ResponseUtils.response(res,"验签失败","-1","","error");
|
||
|
return ;
|
||
|
}
|
||
|
|
||
|
//获取请求参数
|
||
|
String token = req.getParameter("token");
|
||
|
//获取用户名
|
||
|
String username = getUsername(token);
|
||
|
|
||
|
// String username = "xiamaofa";
|
||
|
|
||
|
if(Utils.isNullStr(username)){
|
||
|
FRUtils.FRLogInfo("获取用户信息失败");
|
||
|
|
||
|
ResponseUtils.response(res,"获取用户信息失败","-1","","error");
|
||
|
return ;
|
||
|
}
|
||
|
|
||
|
if(!FRUtils.isUserExist(username)){
|
||
|
FRUtils.FRLogInfo("数据平台不存在该账号:"+username);
|
||
|
ResponseUtils.response(res,"数据平台不存在该账号:"+username,"-1","","error");
|
||
|
return ;
|
||
|
}
|
||
|
|
||
|
String frtoken = FRUtils.getToken(req,res,username);
|
||
|
|
||
|
if(Utils.isNullStr(frtoken)){
|
||
|
FRUtils.FRLogInfo("生成token失败:");
|
||
|
|
||
|
ResponseUtils.response(res,"生成token失败","-1","","error");
|
||
|
return ;
|
||
|
}
|
||
|
|
||
|
String url = psc.getIndex()+"/url/pclogin?token="+frtoken;
|
||
|
|
||
|
ResponseUtils.response(res,"","200",url,"ok");
|
||
|
|
||
|
}
|
||
|
|
||
|
private String getUsername(String token) {
|
||
|
String url = PluginSimpleConfig.getInstance().getPuser();
|
||
|
url += "?token="+token;
|
||
|
|
||
|
String result = HttpUtils.get(url,null,null);
|
||
|
|
||
|
if(Utils.isNullStr(result)){
|
||
|
return "";
|
||
|
}
|
||
|
|
||
|
JSONObject resultJson = new JSONObject(result);
|
||
|
String status = resultJson.getString("Status");
|
||
|
|
||
|
if(!status.equals("S")){
|
||
|
return "";
|
||
|
}
|
||
|
|
||
|
return resultJson.getString("LoginId");
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|