From 11a7657a4b66192d466c83f71b0fb4cd3d060e30 Mon Sep 17 00:00:00 2001 From: richie Date: Fri, 9 Nov 2018 14:39:34 +0800 Subject: [PATCH] =?UTF-8?q?=E8=87=AA=E5=AE=9A=E4=B9=89=E8=BF=87=E6=BB=A4?= =?UTF-8?q?=E5=99=A8=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 4 + build.xml | 130 ++++++++++++++++++ lib/report/.gitkeep | 0 plugin.xml | 19 +++ pom.xml | 35 +++++ .../DemoGlobalRequestFilterBridge.java | 54 ++++++++ .../demo/request/DemoRequestFilterBridge.java | 23 ++++ src/main/resources/.gitkeep | 0 8 files changed, 265 insertions(+) create mode 100644 .gitignore create mode 100644 build.xml create mode 100644 lib/report/.gitkeep create mode 100644 plugin.xml create mode 100644 pom.xml create mode 100644 src/main/java/com/fr/plugin/demo/request/DemoGlobalRequestFilterBridge.java create mode 100644 src/main/java/com/fr/plugin/demo/request/DemoRequestFilterBridge.java create mode 100644 src/main/resources/.gitkeep diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f610933 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.idea/ +*.iml +target/ +lib/report/*.jar \ No newline at end of file diff --git a/build.xml b/build.xml new file mode 100644 index 0000000..b3fe56c --- /dev/null +++ b/build.xml @@ -0,0 +1,130 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/lib/report/.gitkeep b/lib/report/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/plugin.xml b/plugin.xml new file mode 100644 index 0000000..4203a77 --- /dev/null +++ b/plugin.xml @@ -0,0 +1,19 @@ + + + com.fr.plugin.demo.request.filter + + yes + 1.0 + 10.0 + 2018-11-09 + author + + + ]]> + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..23d41b2 --- /dev/null +++ b/pom.xml @@ -0,0 +1,35 @@ + + + 4.0.0 + + + + com.fr.maven + finereport-maven + 10.0 + + jar + demo-web-request + + + com.fr.decision + decision-sdk + 10.0 + + + + + + ${web-inf-path}/plugins/plugin-com.fr.plugin.demo.request.filter-1.0/classes + + \ No newline at end of file diff --git a/src/main/java/com/fr/plugin/demo/request/DemoGlobalRequestFilterBridge.java b/src/main/java/com/fr/plugin/demo/request/DemoGlobalRequestFilterBridge.java new file mode 100644 index 0000000..9284896 --- /dev/null +++ b/src/main/java/com/fr/plugin/demo/request/DemoGlobalRequestFilterBridge.java @@ -0,0 +1,54 @@ +package com.fr.plugin.demo.request; + +import com.fr.data.NetworkHelper; +import com.fr.decision.authority.data.User; +import com.fr.decision.fun.impl.AbstractGlobalRequestFilterProvider; +import com.fr.decision.webservice.exception.user.UserNotExistException; +import com.fr.decision.webservice.utils.DecisionServiceConstants; +import com.fr.decision.webservice.v10.login.LoginService; +import com.fr.decision.webservice.v10.login.TokenResource; +import com.fr.decision.webservice.v10.user.UserService; +import com.fr.log.FineLoggerFactory; +import com.fr.stable.StringUtils; + +import javax.servlet.FilterChain; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +public class DemoGlobalRequestFilterBridge extends AbstractGlobalRequestFilterProvider { + @Override + public String filterName() { + return "MyFilter"; + } + + @Override + public String[] urlPatterns() { + return new String[]{"/decision"}; + } + + @Override + public void doFilter(HttpServletRequest req, HttpServletResponse res, FilterChain filterChain) { + String username = NetworkHelper.getHTTPRequestParameter(req, "username"); + try { + if (StringUtils.isNotEmpty(username)) { + FineLoggerFactory.getLogger().info("current username:" + username); + User user = UserService.getInstance().getUserByUserName(username); + if (user == null) { + throw new UserNotExistException(); + } + String oldToken = TokenResource.COOKIE.getToken(req); + if (oldToken == null) { + String token = LoginService.getInstance().login(req, res, username); + req.setAttribute(DecisionServiceConstants.FINE_AUTH_TOKEN_NAME, token); + filterChain.doFilter(req, res); + } else { + filterChain.doFilter(req, res); + } + } else { + filterChain.doFilter(req, res); + } + } catch (Exception e) { + FineLoggerFactory.getLogger().error(e.getMessage(), e); + } + } +} diff --git a/src/main/java/com/fr/plugin/demo/request/DemoRequestFilterBridge.java b/src/main/java/com/fr/plugin/demo/request/DemoRequestFilterBridge.java new file mode 100644 index 0000000..eaf2e62 --- /dev/null +++ b/src/main/java/com/fr/plugin/demo/request/DemoRequestFilterBridge.java @@ -0,0 +1,23 @@ +package com.fr.plugin.demo.request; + +import com.fr.decision.fun.impl.AbstractEmbedRequestFilterProvider; +import com.fr.intelli.record.Focus; +import com.fr.intelli.record.Original; +import com.fr.log.FineLoggerFactory; +import com.fr.record.analyzer.EnableMetrics; + +import javax.servlet.FilterChain; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + +@EnableMetrics +public class DemoRequestFilterBridge extends AbstractEmbedRequestFilterProvider { + + @Override + @Focus(id="com.fr.plugin.demo.request.filter", text = "", source = Original.PLUGIN) + public void doFilter(HttpServletRequest req, HttpServletResponse res, FilterChain filterChain) throws IOException, ServletException { + FineLoggerFactory.getLogger().info("=========Test Filter========"); + } +} diff --git a/src/main/resources/.gitkeep b/src/main/resources/.gitkeep new file mode 100644 index 0000000..e69de29