|
|
|
@ -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()); |
|
|
|
|