From bcd786c48cb6743d17a343ba1cb87a1f827b7708 Mon Sep 17 00:00:00 2001 From: fit2cloud-chenyw Date: Thu, 29 Jul 2021 16:46:17 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E6=9F=A5=E7=9C=8B=E5=88=86?= =?UTF-8?q?=E4=BA=AB=E9=93=BE=E6=8E=A5=E4=BD=BF=E7=94=A8=E7=8B=AC=E7=AB=8B?= =?UTF-8?q?=E6=8B=A6=E6=88=AA=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/dataease/auth/config/ShiroConfig.java | 1 + .../dataease/auth/filter/F2CLinkFilter.java | 51 +++++++++++++++++++ .../auth/service/impl/ShiroServiceImpl.java | 10 +++- .../java/io/dataease/auth/util/LinkUtil.java | 22 ++++++++ .../controller/panel/api/LinkApi.java | 9 ++++ .../controller/panel/server/LinkServer.java | 17 +++++++ .../service/panel/PanelLinkService.java | 21 +++++++- frontend/src/api/link/index.js | 14 ++++- .../canvas/custom-component/UserView.vue | 12 ++++- frontend/src/utils/request.js | 4 +- frontend/src/views/link/pwd/index.vue | 21 +++++++- 11 files changed, 171 insertions(+), 11 deletions(-) create mode 100644 backend/src/main/java/io/dataease/auth/filter/F2CLinkFilter.java create mode 100644 backend/src/main/java/io/dataease/auth/util/LinkUtil.java diff --git a/backend/src/main/java/io/dataease/auth/config/ShiroConfig.java b/backend/src/main/java/io/dataease/auth/config/ShiroConfig.java index 8e32c44079..a3d6e190de 100644 --- a/backend/src/main/java/io/dataease/auth/config/ShiroConfig.java +++ b/backend/src/main/java/io/dataease/auth/config/ShiroConfig.java @@ -50,6 +50,7 @@ public class ShiroConfig { filterMap.put("f2cPerms", new F2CPermissionsFilter()); filterMap.put("jwt", new JWTFilter()); filterMap.put("logout", new F2CLogoutFilter()); + filterMap.put("link", new F2CLinkFilter()); factoryBean.setSecurityManager(securityManager); factoryBean.setLoginUrl("/login"); factoryBean.setUnauthorizedUrl("/login"); diff --git a/backend/src/main/java/io/dataease/auth/filter/F2CLinkFilter.java b/backend/src/main/java/io/dataease/auth/filter/F2CLinkFilter.java new file mode 100644 index 0000000000..8cca8edbf7 --- /dev/null +++ b/backend/src/main/java/io/dataease/auth/filter/F2CLinkFilter.java @@ -0,0 +1,51 @@ +package io.dataease.auth.filter; + +import cn.hutool.core.util.ObjectUtil; +import com.auth0.jwt.JWT; +import com.auth0.jwt.interfaces.Claim; +import com.auth0.jwt.interfaces.DecodedJWT; +import io.dataease.auth.config.RsaProperties; +import io.dataease.auth.util.JWTUtils; +import io.dataease.auth.util.LinkUtil; +import io.dataease.auth.util.RsaUtil; +import io.dataease.base.domain.PanelLink; +import io.dataease.commons.utils.LogUtil; +import org.apache.commons.lang3.StringUtils; +import org.apache.shiro.web.filter.authc.AnonymousFilter; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; +import javax.servlet.http.HttpServletRequest; + +public class F2CLinkFilter extends AnonymousFilter { + + private static final Logger logger = LoggerFactory.getLogger(F2CLogoutFilter.class); + + private static final String LINK_TOKEN_KEY = "LINK-PWD-TOKEN"; + + @Override + protected boolean onPreHandle(ServletRequest request, ServletResponse response, Object mappedValue) { + try{ + HttpServletRequest req = (HttpServletRequest) request; + String link_token = req.getHeader(LINK_TOKEN_KEY); + DecodedJWT jwt = JWT.decode(link_token); + Claim resourceId = jwt.getClaim("resourceId"); + String id = resourceId.asString(); + PanelLink panelLink = LinkUtil.queryLink(id); + if (ObjectUtil.isEmpty(panelLink)) return false; + if (!panelLink.getEnablePwd()) { + panelLink.setPwd("dataease"); + } + return JWTUtils.verifyLink(link_token, id, RsaUtil.decryptByPrivateKey(RsaProperties.privateKey, panelLink.getPwd())); + }catch (Exception e) { + LogUtil.error(e); + } + return false; + + } + + + + +} diff --git a/backend/src/main/java/io/dataease/auth/service/impl/ShiroServiceImpl.java b/backend/src/main/java/io/dataease/auth/service/impl/ShiroServiceImpl.java index 954a6f7266..0298899473 100644 --- a/backend/src/main/java/io/dataease/auth/service/impl/ShiroServiceImpl.java +++ b/backend/src/main/java/io/dataease/auth/service/impl/ShiroServiceImpl.java @@ -41,8 +41,7 @@ public class ShiroServiceImpl implements ShiroService { //验证链接 filterChainDefinitionMap.put("/api/link/validate**", ANON); - filterChainDefinitionMap.put("/panel/group/findOne/**", ANON); - filterChainDefinitionMap.put("/chart/view/getData/**", ANON); + filterChainDefinitionMap.put("/system/ui/**", ANON); @@ -59,9 +58,16 @@ public class ShiroServiceImpl implements ShiroService { filterChainDefinitionMap.put("/tokenExpired", ANON); filterChainDefinitionMap.put("/downline", ANON); filterChainDefinitionMap.put("/common-files/**", ANON); + filterChainDefinitionMap.put("/api/auth/logout", "logout"); + + filterChainDefinitionMap.put("/api/link/resourceDetail/**", "link"); + filterChainDefinitionMap.put("/api/link/viewDetail/**", "link"); + filterChainDefinitionMap.put("/**", "authc"); + filterChainDefinitionMap.put("/**", "jwt"); + return filterChainDefinitionMap; } diff --git a/backend/src/main/java/io/dataease/auth/util/LinkUtil.java b/backend/src/main/java/io/dataease/auth/util/LinkUtil.java new file mode 100644 index 0000000000..df29abc08a --- /dev/null +++ b/backend/src/main/java/io/dataease/auth/util/LinkUtil.java @@ -0,0 +1,22 @@ +package io.dataease.auth.util; + +import io.dataease.base.domain.PanelLink; +import io.dataease.service.panel.PanelLinkService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +public class LinkUtil { + + + private static PanelLinkService panelLinkService; + + @Autowired + public void setPanelLinkService(PanelLinkService panelLinkService) { + LinkUtil.panelLinkService = panelLinkService; + } + + public static PanelLink queryLink(String resourceId) { + return panelLinkService.findOne(resourceId); + } +} diff --git a/backend/src/main/java/io/dataease/controller/panel/api/LinkApi.java b/backend/src/main/java/io/dataease/controller/panel/api/LinkApi.java index a58c407bf8..3508368537 100644 --- a/backend/src/main/java/io/dataease/controller/panel/api/LinkApi.java +++ b/backend/src/main/java/io/dataease/controller/panel/api/LinkApi.java @@ -1,6 +1,7 @@ package io.dataease.controller.panel.api; +import io.dataease.controller.request.chart.ChartExtRequest; import io.dataease.controller.request.panel.link.EnablePwdRequest; import io.dataease.controller.request.panel.link.LinkRequest; import io.dataease.controller.request.panel.link.PasswordRequest; @@ -40,4 +41,12 @@ public interface LinkApi { @ApiOperation("验证密码") @PostMapping("/validatePwd") boolean validatePwd(PasswordRequest request) throws Exception; + + @ApiOperation("资源详息") + @PostMapping("/resourceDetail/{resourceId}") + Object resourceDetail(@PathVariable String resourceId); + + @ApiOperation("视图详息") + @PostMapping("/viewDetail/{viewId}") + Object viewDetail(@PathVariable String viewId, @RequestBody ChartExtRequest requestList) throws Exception; } diff --git a/backend/src/main/java/io/dataease/controller/panel/server/LinkServer.java b/backend/src/main/java/io/dataease/controller/panel/server/LinkServer.java index 8a1734cd82..8931451652 100644 --- a/backend/src/main/java/io/dataease/controller/panel/server/LinkServer.java +++ b/backend/src/main/java/io/dataease/controller/panel/server/LinkServer.java @@ -4,18 +4,22 @@ package io.dataease.controller.panel.server; import com.google.gson.Gson; import io.dataease.base.domain.PanelLink; import io.dataease.controller.panel.api.LinkApi; +import io.dataease.controller.request.chart.ChartExtRequest; import io.dataease.controller.request.panel.link.EnablePwdRequest; import io.dataease.controller.request.panel.link.LinkRequest; import io.dataease.controller.request.panel.link.PasswordRequest; import io.dataease.controller.request.panel.link.ValidateRequest; import io.dataease.dto.panel.link.GenerateDto; import io.dataease.dto.panel.link.ValidateDto; +import io.dataease.service.chart.ChartViewService; import io.dataease.service.panel.PanelLinkService; import org.apache.commons.lang3.ObjectUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; import java.util.Map; @@ -27,6 +31,9 @@ public class LinkServer implements LinkApi { @Autowired private PanelLinkService panelLinkService; + @Resource + private ChartViewService chartViewService; + @Override public void replacePwd(@RequestBody PasswordRequest request) { @@ -73,4 +80,14 @@ public class LinkServer implements LinkApi { public boolean validatePwd(@RequestBody PasswordRequest request) throws Exception { return panelLinkService.validatePwd(request); } + + @Override + public Object resourceDetail(@PathVariable String resourceId) { + return panelLinkService.resourceInfo(resourceId); + } + + @Override + public Object viewDetail(String viewId, ChartExtRequest requestList) throws Exception{ + return chartViewService.getData(viewId, requestList); + } } diff --git a/backend/src/main/java/io/dataease/service/panel/PanelLinkService.java b/backend/src/main/java/io/dataease/service/panel/PanelLinkService.java index 53109c5b2d..9d6c9b1ab5 100644 --- a/backend/src/main/java/io/dataease/service/panel/PanelLinkService.java +++ b/backend/src/main/java/io/dataease/service/panel/PanelLinkService.java @@ -4,7 +4,9 @@ import com.google.gson.Gson; import io.dataease.auth.config.RsaProperties; import io.dataease.auth.util.JWTUtils; import io.dataease.auth.util.RsaUtil; +import io.dataease.base.domain.PanelGroupWithBLOBs; import io.dataease.base.domain.PanelLink; +import io.dataease.base.mapper.PanelGroupMapper; import io.dataease.base.mapper.PanelLinkMapper; import io.dataease.commons.utils.ServletUtils; import io.dataease.controller.request.panel.link.EnablePwdRequest; @@ -32,6 +34,9 @@ public class PanelLinkService { @Resource private PanelLinkMapper mapper; + @Resource + private PanelGroupMapper panelGroupMapper; + public void changeValid(LinkRequest request){ PanelLink po = new PanelLink(); po.setResourceId(request.getResourceId()); @@ -117,7 +122,16 @@ public class PanelLinkService { public Boolean validateHeads(PanelLink panelLink) throws Exception{ HttpServletRequest request = ServletUtils.request(); String token = request.getHeader("LINK-PWD-TOKEN"); - if (StringUtils.isEmpty(token) || StringUtils.equals("undefined", token) || StringUtils.equals("null", token)) return false; + if (!panelLink.getEnablePwd() || StringUtils.isEmpty(token) || StringUtils.equals("undefined", token) || StringUtils.equals("null", token)) { + String resourceId = panelLink.getResourceId(); + String pwd = "dataease"; + String tk = JWTUtils.signLink(resourceId, pwd); + HttpServletResponse httpServletResponse = ServletUtils.response(); + httpServletResponse.addHeader("Access-Control-Expose-Headers", "LINK-PWD-TOKEN"); + httpServletResponse.setHeader("LINK-PWD-TOKEN", tk); + return false; + } + if (StringUtils.isEmpty(panelLink.getPwd())) return false; boolean verify = JWTUtils.verifyLink(token, panelLink.getResourceId(), decryptParam(panelLink.getPwd())); return verify; } @@ -137,4 +151,9 @@ public class PanelLinkService { return pass; } + public PanelGroupWithBLOBs resourceInfo(String resourceId) { + return panelGroupMapper.selectByPrimaryKey(resourceId); + } + + } diff --git a/frontend/src/api/link/index.js b/frontend/src/api/link/index.js index 57b5e1933d..93cdcf568b 100644 --- a/frontend/src/api/link/index.js +++ b/frontend/src/api/link/index.js @@ -51,7 +51,17 @@ export function loadGenerate(resourceId) { export function loadResource(resourceId) { return request({ - url: 'panel/group/findOne/' + resourceId, - method: 'get' + url: 'api/link/resourceDetail/' + resourceId, + method: 'post' + }) +} + +export function viewInfo(id, data) { + return request({ + url: 'api/link/viewDetail/' + id, + method: 'post', + timeout: 30000, + hideMsg: true, + data }) } diff --git a/frontend/src/components/canvas/custom-component/UserView.vue b/frontend/src/components/canvas/custom-component/UserView.vue index 493f25eda9..1b1efa03dc 100644 --- a/frontend/src/components/canvas/custom-component/UserView.vue +++ b/frontend/src/components/canvas/custom-component/UserView.vue @@ -25,6 +25,7 @@