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.

125 lines
3.9 KiB

3 years ago
package com.eco.plugin.xx.cjccfilter.login;
import com.eco.plugin.xx.cjccfilter.config.PluginSimpleConfig;
import com.eco.plugin.xx.cjccfilter.utils.FRUtils;
import com.eco.plugin.xx.cjccfilter.utils.IOUtils;
import com.eco.plugin.xx.cjccfilter.utils.ResponseUtils;
import com.eco.plugin.xx.cjccfilter.utils.Utils;
import com.fr.decision.fun.impl.AbstractGlobalRequestFilterProvider;
import com.fr.io.utils.ResourceIOUtils;
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.io.IOException;
import java.io.InputStream;
@EnableMetrics
@Authorize(callSignKey = "com.eco.plugin.xx.cjccfilter")
public class SSOFilter extends AbstractGlobalRequestFilterProvider {
@Override
public String filterName() {
return "cjccFilter";
}
@Override
public String[] urlPatterns() {
return new String[]{"/*"};
}
@Override
public void doFilter(HttpServletRequest req, HttpServletResponse res, FilterChain chain ){
if(PluginContexts.currentContext().isAvailable()){
PluginSimpleConfig psc = PluginSimpleConfig.getInstance();
String url = FRUtils.getAllUrl(req);
String refer = req.getHeader("Referer");
//不是模板链接放行
// if(!((url.contains("view/report") && url.contains(".cpt")) || (url.contains("view/form") && url.contains(".frm")))){
// release(req,res,chain);
// return ;
// }
if(url.contains("error.html")){
release(req,res,chain);
return ;
}
FRUtils.FRLogInfo("refer:"+refer);
// FRUtils.FRLogInfo("white:"+psc.getWhite());
//请求头为空跳转错误页面
// String refer = req.getParameter("refer");
if(Utils.isNullStr(refer)){
redirect(psc,res);
return ;
}
//非白名单跳转错误页面
boolean inwhite = inWhite(psc,refer,url);
if(!inwhite){
redirect(psc,res);
return ;
}
}else{
ResponseUtils.failedResponse(res,"插件授权失效,请联系管理员!");
return ;
}
release(req,res,chain);
}
private static boolean inWhite(PluginSimpleConfig psc,String refer,String url) {
// String[] urls = url.split("/webroot/decision");
// String frdomain = urls[0];
//
// //是否是帆软内部调用
// if(refer.startsWith(frdomain)){
// return true;
// }
InputStream is = ResourceIOUtils.read("/resources/config.txt");
String str = IOUtils.inputStreamToStr(is);
String[] whites = str.replaceAll("\r","").split("\n");
try {
is.close();
} catch (IOException e) {
FRUtils.FRLogInfo("io关闭异常:"+e.getMessage());
return false;
}
boolean isWhite = false;
for(int i = 0;i< whites.length;i++){
String white = whites[i];
if(refer.startsWith(white)){
isWhite = true;
break;
}
}
return isWhite;
}
//跳转认证中心
private void redirect(PluginSimpleConfig pluginSimpleConfig,HttpServletResponse res) {
try {
res.sendRedirect(pluginSimpleConfig.getErrorpage());
} catch (IOException e) {
FRUtils.FRLogInfo("跳转错误页面异常:"+e.getMessage());
}
}
//放行拦截器
private void release(HttpServletRequest req, HttpServletResponse res, FilterChain chain) {
try{
chain.doFilter(req,res);
}catch (Exception e){
FRUtils.FRLogInfo("拦截失败");
}
}
}