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.
67 lines
2.1 KiB
67 lines
2.1 KiB
package com.fr.plugin; |
|
|
|
import com.fr.decision.fun.impl.AbstractGlobalRequestFilterProvider; |
|
import com.fr.log.FineLoggerFactory; |
|
import com.fr.plugin.transform.FunctionRecorder; |
|
import com.fr.stable.StringUtils; |
|
|
|
import javax.servlet.FilterChain; |
|
import javax.servlet.FilterConfig; |
|
import javax.servlet.ServletException; |
|
import javax.servlet.http.HttpServletRequest; |
|
import javax.servlet.http.HttpServletResponse; |
|
import java.io.IOException; |
|
import java.io.PrintWriter; |
|
import java.io.StringWriter; |
|
|
|
@FunctionRecorder(localeKey = "dd") |
|
public class QYFilter extends AbstractGlobalRequestFilterProvider { |
|
@Override |
|
public String filterName() { |
|
return "qywxfilter"; |
|
} |
|
|
|
@Override |
|
public String[] urlPatterns() { |
|
return new String[]{ |
|
"/dddfds" |
|
}; |
|
} |
|
|
|
@Override |
|
public void init(FilterConfig filterConfig) { |
|
super.init(filterConfig); |
|
} |
|
|
|
|
|
@Override |
|
public void doFilter(HttpServletRequest request, HttpServletResponse httpServletResponse, FilterChain filterChain) { |
|
try { |
|
if (isInnerIp(request)) { |
|
filterChain.doFilter(request, httpServletResponse); |
|
} else { |
|
String header = request.getHeader("User-Agent"); |
|
if (StringUtils.isNotBlank(header) && header.contains("wxwork")) { |
|
filterChain.doFilter(request, httpServletResponse); |
|
} |
|
} |
|
} catch (IOException e) { |
|
printException2FrLog(e); |
|
} catch (ServletException e) { |
|
printException2FrLog(e); |
|
} |
|
} |
|
|
|
private boolean isInnerIp(HttpServletRequest request) throws IOException { |
|
String realIp = IPUtils.getRealIp(request); |
|
return IPUtils.isInnerIP(realIp, "10.27.82.*") || IPUtils.isInnerIP(realIp, "10.27.84.*"); |
|
} |
|
|
|
public static void printException2FrLog(Throwable e) { |
|
StringWriter writer = new StringWriter(); |
|
e.printStackTrace(new PrintWriter(writer)); |
|
String s = writer.toString(); |
|
FineLoggerFactory.getLogger().error("错误:{}", s); |
|
} |
|
|
|
}
|
|
|