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.
96 lines
3.0 KiB
96 lines
3.0 KiB
2 years ago
|
package com.eco.plugin.xx.gesso.filter;
|
||
|
|
||
|
import com.eco.plugin.xx.gesso.config.xxPluginSimpleConfig;
|
||
|
import com.eco.plugin.xx.gesso.utils.EncryptUtils;
|
||
|
import com.eco.plugin.xx.gesso.utils.FRUtils;
|
||
|
import com.eco.plugin.xx.gesso.utils.HttpUtils;
|
||
|
import com.eco.plugin.xx.gesso.utils.Utils;
|
||
|
import com.fr.decision.fun.impl.AbstractGlobalRequestFilterProvider;
|
||
|
import com.fr.json.JSONObject;
|
||
|
import com.fr.plugin.context.PluginContexts;
|
||
|
import com.fr.record.analyzer.EnableMetrics;
|
||
|
import com.fr.stable.fun.Authorize;
|
||
|
import javax.servlet.FilterChain;
|
||
|
import javax.servlet.http.HttpServletRequest;
|
||
|
import javax.servlet.http.HttpServletResponse;
|
||
|
import java.util.HashMap;
|
||
|
import java.util.Map;
|
||
|
|
||
|
@EnableMetrics
|
||
|
@Authorize(callSignKey = "com.eco.plugin.xx.gesso")
|
||
|
public class SSOFilter extends AbstractGlobalRequestFilterProvider {
|
||
|
@Override
|
||
|
public String filterName() {
|
||
|
return "gessoFilter";
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public String[] urlPatterns() {
|
||
|
return new String[]{"/*"};
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void doFilter(HttpServletRequest req, HttpServletResponse res, FilterChain chain ){
|
||
|
|
||
|
if(PluginContexts.currentContext().isAvailable()){
|
||
|
xxPluginSimpleConfig psc = xxPluginSimpleConfig.getInstance();
|
||
|
String param = psc.getParamname();
|
||
|
String token = req.getParameter(param);
|
||
|
|
||
|
if(Utils.isNullStr(token)){
|
||
|
release(req,res,chain);
|
||
|
return ;
|
||
|
}
|
||
|
|
||
|
String username = getUsername(psc,token);
|
||
|
String url = FRUtils.getAllUrl(req);
|
||
|
url = Utils.removeParam(url,param);
|
||
|
url = Utils.encodeCH(url);
|
||
|
FRUtils.login(req,res,username,url);
|
||
|
}
|
||
|
|
||
|
release(req,res,chain);
|
||
|
}
|
||
|
|
||
|
private String getUsername(xxPluginSimpleConfig psc, String token) {
|
||
|
String sysKey = psc.getSysKey();
|
||
|
String secret = psc.getSecret();
|
||
|
Long timestamp = System.currentTimeMillis();
|
||
|
Map<String,Object> param = new HashMap<>();
|
||
|
param.put("sysKey",sysKey);
|
||
|
param.put("accessToken",token);
|
||
|
param.put("timestamp",timestamp);
|
||
|
|
||
|
String sign = EncryptUtils.getSign(param,secret);
|
||
|
|
||
|
// String url = psc.getUrl() + "?accessToken="+token+"&sysKey="+sysKey+"×tamp="+timestamp+"&sign="+sign;
|
||
|
String url = psc.getUrl() + "?accessToken="+token;
|
||
|
|
||
|
String result = HttpUtils.httpGet(url,null,null);
|
||
|
|
||
|
if(Utils.isNullStr(result)){
|
||
|
return "";
|
||
|
}
|
||
|
|
||
|
JSONObject resultJson = new JSONObject(result);
|
||
|
int code = resultJson.getInt("code");
|
||
|
if(code != 0){
|
||
|
return "";
|
||
|
}
|
||
|
|
||
|
String username = resultJson.getJSONObject("data").getJSONObject("userInfo").getString("employeeNumbe");
|
||
|
|
||
|
return username;
|
||
|
}
|
||
|
|
||
|
//放行拦截器
|
||
|
private void release(HttpServletRequest req, HttpServletResponse res, FilterChain chain) {
|
||
|
try{
|
||
|
chain.doFilter(req,res);
|
||
|
}catch (Exception e){
|
||
|
FRUtils.FRLogInfo("拦截失败");
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|