From cb1d74bc3d3a208aa2c4358ee34fa16eee52f00a Mon Sep 17 00:00:00 2001 From: "Destiny.Lin" Date: Mon, 26 Aug 2024 14:49:12 +0800 Subject: [PATCH 1/3] =?UTF-8?q?REPORT-130000=20fbp=E7=9A=84fr=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E5=90=AF=E5=8A=A8=E5=A4=B1=E8=B4=A5=EF=BC=8C=E4=BD=86?= =?UTF-8?q?=E6=98=AFfbp=E8=AE=BE=E8=AE=A1=E5=99=A8=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E8=BF=9E=E6=8E=A5=E8=BF=98=E6=98=AF=E6=88=90=E5=8A=9F=E7=9A=84?= =?UTF-8?q?=EF=BC=8C=E7=82=B9=E5=87=BB=E7=A1=AE=E5=AE=9A=E8=AE=BE=E8=AE=A1?= =?UTF-8?q?=E5=99=A8=E9=A1=B5=E9=9D=A2=E5=8D=A1=E6=AD=BB=20&=20REPORT-1310?= =?UTF-8?q?68=20=E8=BF=9C=E7=A8=8B=E8=AE=BE=E8=AE=A1=E6=9D=83=E9=99=90?= =?UTF-8?q?=E6=A0=A1=E9=AA=8C=E4=B8=8D=E7=94=9F=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fr/design/env/HttpWorkspaceConnector.java | 32 +++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/env/HttpWorkspaceConnector.java b/designer-base/src/main/java/com/fr/design/env/HttpWorkspaceConnector.java index 3687735601..1c069bbb0e 100644 --- a/designer-base/src/main/java/com/fr/design/env/HttpWorkspaceConnector.java +++ b/designer-base/src/main/java/com/fr/design/env/HttpWorkspaceConnector.java @@ -4,8 +4,10 @@ import com.fanruan.workplace.http.HttpConstants; import com.fanruan.workplace.http.HttpServiceMap; import com.fanruan.workplace.http.RepositoryManager; import com.fanruan.workplace.http.info.Stub; +import com.fr.exception.RemoteDesignPermissionDeniedException; import com.fr.log.FineLoggerFactory; import com.fr.stable.StringUtils; +import com.fr.workspace.engine.exception.RemoteDesignConnectionException; import com.fr.workspace.server.repository.authority.RemoteAuthorityRepository; import com.fr.workspace.server.repository.compatible.register.CompatibleRegister; import com.fr.workspace.server.repository.connect.FineWorkspaceHttpClient; @@ -43,7 +45,18 @@ public class HttpWorkspaceConnector implements WorkspaceConnector { FineWorkspaceHttpClient client = FineWorkspaceHttpClient.create("Http-Client", connectionInfo); LoginResponseInfoBean bean; try { - bean = RemoteAuthorityRepository.getInstance().login(createLoginBean(connectionInfo)); + bean = RemoteAuthorityRepository.getInstance().login(createLoginBean(connectionInfo)); + WorkspaceConnection connection = new WorkspaceConnection( + UUID.randomUUID().toString(), + connectionInfo.getUserName(), + HttpConstants.AUTHORIZATION_PREFIX + bean.getAccessToken(), + InetAddress.getLocalHost().getHostAddress()); + client.updateConnection(connection); + // 检查远程权限 + if (!checkRemoteAuthority(connection)) { + // 无权限则抛出无权限的错 + throw new RemoteDesignPermissionDeniedException(); + } } finally { client.closePool(); } @@ -71,16 +84,31 @@ public class HttpWorkspaceConnector implements WorkspaceConnector { HttpConstants.AUTHORIZATION_PREFIX + bean.getAccessToken(), InetAddress.getLocalHost().getHostAddress()); client.updateConnection(connection); + // 检查远程权限 + if (!checkRemoteAuthority(connection)) { + // 无权限则抛出无权限的错 + throw new RemoteDesignPermissionDeniedException(); + } client.startHeartBeat(); } catch (Exception e) { client.closePool(); - throw e; + throw new RemoteDesignConnectionException(e, StringUtils.EMPTY); } CompatibleRegister.registerCompatibleEnv(); RepositoryManager.getInstance().clearLastPool(); return client; } + private boolean checkRemoteAuthority(WorkspaceConnection connection) { + try { + return RemoteAuthorityRepository.getInstance().isRoot(connection.getUserName()) || RemoteAuthorityRepository.getInstance().hasAuthority(connection.getUserName()); + } catch (Exception e) { + // 如果这里出现异常,就认为fr服务没启动 + throw new RemoteDesignConnectionException(e, StringUtils.EMPTY); + } + + } + private LoginRequestInfoBean createLoginBean(WorkspaceConnectionInfo connectionInfo) { LoginRequestInfoBean bean = new LoginRequestInfoBean(); bean.setUsername(connectionInfo.getUserName()); From 11b942ec7522d34c084d01d642da03a44bb9844e Mon Sep 17 00:00:00 2001 From: "Destiny.Lin" Date: Mon, 26 Aug 2024 16:17:07 +0800 Subject: [PATCH 2/3] =?UTF-8?q?REPORT-131067=20=E8=BF=9C=E7=A8=8B=E8=AE=BE?= =?UTF-8?q?=E8=AE=A1=E5=AF=86=E7=A0=81=E6=AC=A1=E6=95=B0=E8=BF=87=E5=A4=9A?= =?UTF-8?q?=E6=8A=9B=E9=94=99=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fr/design/env/HttpWorkspaceConnector.java | 2 +- .../boot/init/DesignWorkContextComponent.java | 20 ++++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/env/HttpWorkspaceConnector.java b/designer-base/src/main/java/com/fr/design/env/HttpWorkspaceConnector.java index 1c069bbb0e..e6a9720bc1 100644 --- a/designer-base/src/main/java/com/fr/design/env/HttpWorkspaceConnector.java +++ b/designer-base/src/main/java/com/fr/design/env/HttpWorkspaceConnector.java @@ -92,7 +92,7 @@ public class HttpWorkspaceConnector implements WorkspaceConnector { client.startHeartBeat(); } catch (Exception e) { client.closePool(); - throw new RemoteDesignConnectionException(e, StringUtils.EMPTY); + throw e; } CompatibleRegister.registerCompatibleEnv(); RepositoryManager.getInstance().clearLastPool(); diff --git a/designer-realize/src/main/java/com/fanruan/boot/init/DesignWorkContextComponent.java b/designer-realize/src/main/java/com/fanruan/boot/init/DesignWorkContextComponent.java index ee93d96369..51adb2fd57 100644 --- a/designer-realize/src/main/java/com/fanruan/boot/init/DesignWorkContextComponent.java +++ b/designer-realize/src/main/java/com/fanruan/boot/init/DesignWorkContextComponent.java @@ -11,6 +11,11 @@ import com.fanruan.workplace.conetxt.CompatiblePool; import com.fanruan.workplace.http.HttpConstants; import com.fanruan.workplace.http.RepositoryManager; import com.fanruan.workplace.http.WorkspaceHeartBeatShell; +import com.fr.workspace.engine.exception.RemoteDesignLoginLockHandler; +import com.fr.workspace.engine.exception.RemoteDesignNoAuthHandler; +import com.fr.workspace.engine.exception.RemoteDesignPasswordNeedUpdateHandler; +import com.fr.workspace.engine.exception.RemoteDesignPasswordStrengthHandler; +import com.fr.workspace.engine.exception.RemoteDesignUserPwdErrorHandler; import com.fanruan.workplace.http.exception.RemoteExceptionConvert; import com.fanruan.workplace.standard.ServerInfo; import com.fanruan.workplace.standard.ServerInfoOperator; @@ -43,10 +48,6 @@ import com.fr.workspace.engine.FineWorkspaceFactory; import com.fr.workspace.engine.base.FineObjectPool; import com.fr.workspace.engine.client.heartbeart.FineWorkspaceHeartbeat; import com.fr.workspace.engine.client.heartbeart.WorkspaceHeartbeat; -import com.fr.workspace.engine.exception.RemoteDesignNoAuthException; -import com.fr.workspace.engine.exception.RemoteDesignPasswordNeedUpdateException; -import com.fr.workspace.engine.exception.RemoteDesignPasswordStrengthException; -import com.fr.workspace.engine.exception.RemoteDesignUserPwdErrorException; import com.fr.workspace.engine.resource.FineWorkResource; import com.fr.workspace.engine.resource.FineWorkResourceAdaptor; import com.fr.workspace.pool.WorkRPCRegister; @@ -144,11 +145,12 @@ public class DesignWorkContextComponent { private void startErrorConvert() { - RemoteExceptionConvert.registerException(HttpConstants.USER_PWD_ERROR_CODE, new RemoteDesignUserPwdErrorException()); - RemoteExceptionConvert.registerException(HttpConstants.USER_PWD_NEED_UPDATE, new RemoteDesignPasswordNeedUpdateException()); - RemoteExceptionConvert.registerException(HttpConstants.PASSWORD_STRENGTH_ERROR_CODE, new RemoteDesignPasswordStrengthException()); - RemoteExceptionConvert.registerException(HttpConstants.REMOTE_AUTHORITY_ERROR_CODE, new RemoteDesignNoAuthException()); - RemoteExceptionConvert.registerException(HttpConstants.PASSWORD_EMPTY_ERROR_CODE, new RemoteDesignUserPwdErrorException()); + RemoteExceptionConvert.registerException(HttpConstants.USER_PWD_ERROR_CODE, new RemoteDesignUserPwdErrorHandler()); + RemoteExceptionConvert.registerException(HttpConstants.USER_PWD_NEED_UPDATE, new RemoteDesignPasswordNeedUpdateHandler()); + RemoteExceptionConvert.registerException(HttpConstants.PASSWORD_STRENGTH_ERROR_CODE, new RemoteDesignPasswordStrengthHandler()); + RemoteExceptionConvert.registerException(HttpConstants.REMOTE_AUTHORITY_ERROR_CODE, new RemoteDesignNoAuthHandler()); + RemoteExceptionConvert.registerException(HttpConstants.PASSWORD_EMPTY_ERROR_CODE, new RemoteDesignUserPwdErrorHandler()); + RemoteExceptionConvert.registerException(HttpConstants.LOGIN_LOCK, new RemoteDesignLoginLockHandler()); } private void supplementalCommon() { From 355d63e19104061d04ae9f63ab19cb8b4f178d61 Mon Sep 17 00:00:00 2001 From: "Destiny.Lin" Date: Mon, 26 Aug 2024 16:29:32 +0800 Subject: [PATCH 3/3] =?UTF-8?q?REPORT-131067=20=E8=BF=9C=E7=A8=8B=E8=AE=BE?= =?UTF-8?q?=E8=AE=A1=E5=AF=86=E7=A0=81=E6=AC=A1=E6=95=B0=E8=BF=87=E5=A4=9A?= =?UTF-8?q?=E6=8A=9B=E9=94=99=E5=BC=82=E5=B8=B8=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E9=87=8D=E5=A4=8D=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fr/design/env/HttpWorkspaceConnector.java | 38 ++++++++----------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/env/HttpWorkspaceConnector.java b/designer-base/src/main/java/com/fr/design/env/HttpWorkspaceConnector.java index e6a9720bc1..d3d1d06176 100644 --- a/designer-base/src/main/java/com/fr/design/env/HttpWorkspaceConnector.java +++ b/designer-base/src/main/java/com/fr/design/env/HttpWorkspaceConnector.java @@ -46,17 +46,7 @@ public class HttpWorkspaceConnector implements WorkspaceConnector { LoginResponseInfoBean bean; try { bean = RemoteAuthorityRepository.getInstance().login(createLoginBean(connectionInfo)); - WorkspaceConnection connection = new WorkspaceConnection( - UUID.randomUUID().toString(), - connectionInfo.getUserName(), - HttpConstants.AUTHORIZATION_PREFIX + bean.getAccessToken(), - InetAddress.getLocalHost().getHostAddress()); - client.updateConnection(connection); - // 检查远程权限 - if (!checkRemoteAuthority(connection)) { - // 无权限则抛出无权限的错 - throw new RemoteDesignPermissionDeniedException(); - } + checkValidAndUpdateInfo(client, connectionInfo, bean); } finally { client.closePool(); } @@ -78,17 +68,7 @@ public class HttpWorkspaceConnector implements WorkspaceConnector { throw new RuntimeException("Empty token, try connect again and check server"); } FineLoggerFactory.getLogger().info("[connector] infos:{}", bean.getAccessToken()); - WorkspaceConnection connection = new WorkspaceConnection( - UUID.randomUUID().toString(), - connectionInfo.getUserName(), - HttpConstants.AUTHORIZATION_PREFIX + bean.getAccessToken(), - InetAddress.getLocalHost().getHostAddress()); - client.updateConnection(connection); - // 检查远程权限 - if (!checkRemoteAuthority(connection)) { - // 无权限则抛出无权限的错 - throw new RemoteDesignPermissionDeniedException(); - } + checkValidAndUpdateInfo(client, connectionInfo, bean); client.startHeartBeat(); } catch (Exception e) { client.closePool(); @@ -99,6 +79,20 @@ public class HttpWorkspaceConnector implements WorkspaceConnector { return client; } + private void checkValidAndUpdateInfo(FineWorkspaceHttpClient client, WorkspaceConnectionInfo connectionInfo, LoginResponseInfoBean bean) throws Exception { + WorkspaceConnection connection = new WorkspaceConnection( + UUID.randomUUID().toString(), + connectionInfo.getUserName(), + HttpConstants.AUTHORIZATION_PREFIX + bean.getAccessToken(), + InetAddress.getLocalHost().getHostAddress()); + client.updateConnection(connection); + // 检查远程权限 + if (!checkRemoteAuthority(connection)) { + // 无权限则抛出无权限的错 + throw new RemoteDesignPermissionDeniedException(); + } + } + private boolean checkRemoteAuthority(WorkspaceConnection connection) { try { return RemoteAuthorityRepository.getInstance().isRoot(connection.getUserName()) || RemoteAuthorityRepository.getInstance().hasAuthority(connection.getUserName());