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.
78 lines
2.1 KiB
78 lines
2.1 KiB
2 years ago
|
package com.eco.plugin.xx.gfjjwhite.filter;
|
||
|
|
||
|
import com.eco.plugin.xx.gfjjwhite.config.PluginSimpleConfig;
|
||
|
import com.eco.plugin.xx.gfjjwhite.utils.FRUtils;
|
||
|
import com.eco.plugin.xx.gfjjwhite.utils.IPWhiteUtils;
|
||
|
import com.eco.plugin.xx.gfjjwhite.utils.ResponseUtils;
|
||
|
import com.eco.plugin.xx.gfjjwhite.utils.Utils;
|
||
|
import com.fr.decision.fun.impl.AbstractGlobalRequestFilterProvider;
|
||
|
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;
|
||
|
|
||
|
@EnableMetrics
|
||
|
@Authorize(callSignKey = "com.eco.plugin.xx.gfjjwhite")
|
||
|
public class WhiteFilter extends AbstractGlobalRequestFilterProvider {
|
||
|
@Override
|
||
|
public String filterName() {
|
||
|
return "fqlssoFilter";
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public String[] urlPatterns() {
|
||
|
return new String[]{"/*"};
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void doFilter(HttpServletRequest req, HttpServletResponse res, FilterChain chain ){
|
||
|
|
||
|
if(PluginContexts.currentContext().isAvailable()){
|
||
|
if(isRelease(req)){
|
||
|
release(req,res,chain);
|
||
|
return ;
|
||
|
}
|
||
|
|
||
|
//如果白名单为空,则直接放行
|
||
|
if(Utils.isNullStr(PluginSimpleConfig.getInstance().getIpwhite())){
|
||
|
release(req,res,chain);
|
||
|
return ;
|
||
|
}
|
||
|
|
||
|
boolean inWhite = IPWhiteUtils.inWhite(req);
|
||
|
|
||
|
if(!inWhite){
|
||
|
ResponseUtils.failedResponse(res,"禁止登录");
|
||
|
return ;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
release(req,res,chain);
|
||
|
}
|
||
|
|
||
|
private boolean isRelease(HttpServletRequest req) {
|
||
|
String url = FRUtils.getAllUrl(req);
|
||
|
if(url.contains("/login")){
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
//放行拦截器
|
||
|
private void release(HttpServletRequest req, HttpServletResponse res, FilterChain chain) {
|
||
|
try{
|
||
|
chain.doFilter(req,res);
|
||
|
}catch (Exception e){
|
||
|
FRUtils.FRLogInfo("拦截失败");
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|