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.
63 lines
2.3 KiB
63 lines
2.3 KiB
2 years ago
|
package com.eco.plugin.xx.hysso.login;
|
||
|
|
||
|
import com.eco.plugin.xx.hysso.config.PluginSimpleConfig;
|
||
|
import com.eco.plugin.xx.hysso.utils.EncryptUtils;
|
||
|
import com.eco.plugin.xx.hysso.utils.FRUtils;
|
||
|
import com.eco.plugin.xx.hysso.utils.ResponseUtils;
|
||
|
import com.eco.plugin.xx.hysso.utils.Utils;
|
||
|
import com.fr.decision.webservice.annotation.LoginStatusChecker;
|
||
|
import com.fr.json.JSONObject;
|
||
|
import com.fr.plugin.context.PluginContexts;
|
||
|
import com.fr.stable.fun.Authorize;
|
||
|
import com.fr.third.springframework.stereotype.Controller;
|
||
|
import com.fr.third.springframework.web.bind.annotation.GetMapping;
|
||
|
import com.fr.third.springframework.web.bind.annotation.ResponseBody;
|
||
|
import javax.servlet.http.HttpServletRequest;
|
||
|
import javax.servlet.http.HttpServletResponse;
|
||
|
|
||
|
@Controller
|
||
|
@LoginStatusChecker(required = false)
|
||
|
@Authorize(callSignKey = "com.eco.plugin.xx.hysso")
|
||
|
public class ControllerSelf {
|
||
|
|
||
|
@GetMapping(value = "/ssologin")
|
||
|
@ResponseBody
|
||
|
public void ssologin(HttpServletRequest req,HttpServletResponse res){
|
||
|
if(!PluginContexts.currentContext().isAvailable()){
|
||
|
ResponseUtils.failedResponse(res,"插件授权过期,请联系管理员!");
|
||
|
return ;
|
||
|
}
|
||
|
|
||
|
String token = req.getParameter("ssotoken");
|
||
|
String redirect = req.getParameter("redirect");
|
||
|
PluginSimpleConfig psc = PluginSimpleConfig.getInstance();
|
||
|
|
||
|
String plaintext = null;
|
||
|
try {
|
||
|
plaintext = EncryptUtils.rsaDecrypt(token,psc.getPrivatekey());
|
||
|
} catch (Exception e) {
|
||
|
ResponseUtils.failedResponse(res,"token解析失败,请联系管理员!错误信息:"+e.getMessage());
|
||
|
return ;
|
||
|
}
|
||
|
|
||
|
if(Utils.isNullStr(plaintext)){
|
||
|
ResponseUtils.failedResponse(res,"token解析失败,请联系管理员!");
|
||
|
return ;
|
||
|
}
|
||
|
|
||
|
JSONObject json = new JSONObject(plaintext);
|
||
|
String username = json.getString("username");
|
||
|
Long timestamp = json.getLong("timestamp");
|
||
|
Long now = System.currentTimeMillis();
|
||
|
|
||
|
if((now - timestamp)/1000 > psc.getTimeout()){
|
||
|
ResponseUtils.failedResponse(res,"token超时,请重新生成!");
|
||
|
return ;
|
||
|
}
|
||
|
|
||
|
redirect = Utils.encodeCH(redirect);
|
||
|
|
||
|
FRUtils.login(req,res,username,redirect);
|
||
|
}
|
||
|
}
|