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.
92 lines
2.4 KiB
92 lines
2.4 KiB
package com.fr.plugin.zgfysso.filter; |
|
|
|
import com.fr.decision.fun.impl.AbstractGlobalRequestFilterProvider; |
|
import com.fr.file.TableDataConfig; |
|
import com.fr.json.JSONObject; |
|
import com.fr.plugin.zgfysso.config.PluginSimpleConfig; |
|
import com.fr.plugin.zgfysso.utils.FRUtils; |
|
import com.fr.plugin.zgfysso.utils.HttpUtils; |
|
import com.fr.plugin.zgfysso.utils.Utils; |
|
import com.fr.record.analyzer.EnableMetrics; |
|
import com.fr.stable.fun.mark.API; |
|
|
|
import javax.servlet.FilterChain; |
|
import javax.servlet.http.HttpServletRequest; |
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
|
|
@EnableMetrics |
|
public class SSOFilter extends AbstractGlobalRequestFilterProvider { |
|
|
|
@Override |
|
public String filterName() { |
|
return "zgfyssoFilter"; |
|
} |
|
|
|
@Override |
|
public String[] urlPatterns() { |
|
return new String[]{"/decision/*"}; |
|
} |
|
|
|
@Override |
|
public void doFilter(HttpServletRequest req, HttpServletResponse res, FilterChain chain ){ |
|
PluginSimpleConfig psc = PluginSimpleConfig.getInstance(); |
|
String tokenStr = psc.getTokenStr(); |
|
//code |
|
String tokenid = req.getParameter(tokenStr); |
|
|
|
FRUtils.FRLogInfo("url:"+FRUtils.getAllUrl(req)); |
|
FRUtils.FRLogInfo("tokenid:"+tokenid); |
|
FRUtils.FRLogInfo("isNUll:"+Utils.isNotNullStr(tokenid)); |
|
|
|
if(Utils.isNotNullStr(tokenid)){ |
|
String username = getToken(tokenid,psc); |
|
|
|
FRUtils.FRLogInfo("username:"+username); |
|
//登录 |
|
FRUtils.login(req,res,username,""); |
|
} |
|
|
|
release(req,res,chain); |
|
} |
|
|
|
/** |
|
* 获取token |
|
* @param tokenid |
|
* @return |
|
*/ |
|
private String getToken(String tokenid,PluginSimpleConfig psc) { |
|
String tokenUrl = psc.getTokenUrl(); |
|
tokenUrl += (psc.getSysid()+"?token="+tokenid); |
|
|
|
String result = HttpUtils.get(tokenUrl,null,null); |
|
|
|
if(Utils.isNullStr(result)){ |
|
return ""; |
|
} |
|
|
|
JSONObject json = new JSONObject(result); |
|
|
|
if(json == null){ |
|
return ""; |
|
} |
|
|
|
String code = json.getString("code"); |
|
|
|
if(!code.equals("200")){ |
|
return ""; |
|
} |
|
|
|
return json.getJSONObject("data").getString("id"); |
|
} |
|
|
|
//放行拦截器 |
|
private void release(HttpServletRequest req, HttpServletResponse res, FilterChain chain) { |
|
try{ |
|
chain.doFilter(req,res); |
|
}catch (Exception e){ |
|
FRUtils.FRLogInfo("拦截失败"); |
|
} |
|
} |
|
} |
|
|
|
|