Browse Source

REPORT-131067 远程设计密码次数过多抛错异常 优化重复代码

fbp/release
Destiny.Lin 3 months ago
parent
commit
355d63e191
  1. 38
      designer-base/src/main/java/com/fr/design/env/HttpWorkspaceConnector.java

38
designer-base/src/main/java/com/fr/design/env/HttpWorkspaceConnector.java vendored

@ -46,17 +46,7 @@ public class HttpWorkspaceConnector implements WorkspaceConnector {
LoginResponseInfoBean bean; LoginResponseInfoBean bean;
try { try {
bean = RemoteAuthorityRepository.getInstance().login(createLoginBean(connectionInfo)); bean = RemoteAuthorityRepository.getInstance().login(createLoginBean(connectionInfo));
WorkspaceConnection connection = new WorkspaceConnection( checkValidAndUpdateInfo(client, connectionInfo, bean);
UUID.randomUUID().toString(),
connectionInfo.getUserName(),
HttpConstants.AUTHORIZATION_PREFIX + bean.getAccessToken(),
InetAddress.getLocalHost().getHostAddress());
client.updateConnection(connection);
// 检查远程权限
if (!checkRemoteAuthority(connection)) {
// 无权限则抛出无权限的错
throw new RemoteDesignPermissionDeniedException();
}
} finally { } finally {
client.closePool(); client.closePool();
} }
@ -78,17 +68,7 @@ public class HttpWorkspaceConnector implements WorkspaceConnector {
throw new RuntimeException("Empty token, try connect again and check server"); throw new RuntimeException("Empty token, try connect again and check server");
} }
FineLoggerFactory.getLogger().info("[connector] infos:{}", bean.getAccessToken()); FineLoggerFactory.getLogger().info("[connector] infos:{}", bean.getAccessToken());
WorkspaceConnection connection = new WorkspaceConnection( checkValidAndUpdateInfo(client, connectionInfo, bean);
UUID.randomUUID().toString(),
connectionInfo.getUserName(),
HttpConstants.AUTHORIZATION_PREFIX + bean.getAccessToken(),
InetAddress.getLocalHost().getHostAddress());
client.updateConnection(connection);
// 检查远程权限
if (!checkRemoteAuthority(connection)) {
// 无权限则抛出无权限的错
throw new RemoteDesignPermissionDeniedException();
}
client.startHeartBeat(); client.startHeartBeat();
} catch (Exception e) { } catch (Exception e) {
client.closePool(); client.closePool();
@ -99,6 +79,20 @@ public class HttpWorkspaceConnector implements WorkspaceConnector {
return client; 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) { private boolean checkRemoteAuthority(WorkspaceConnection connection) {
try { try {
return RemoteAuthorityRepository.getInstance().isRoot(connection.getUserName()) || RemoteAuthorityRepository.getInstance().hasAuthority(connection.getUserName()); return RemoteAuthorityRepository.getInstance().isRoot(connection.getUserName()) || RemoteAuthorityRepository.getInstance().hasAuthority(connection.getUserName());

Loading…
Cancel
Save