You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rocketmq.apache.org by sh...@apache.org on 2023/03/22 01:58:13 UTC
[rocketmq-eventbridge] branch main updated: Add private network param check (#60)
This is an automated email from the ASF dual-hosted git repository.
shenlin pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/rocketmq-eventbridge.git
The following commit(s) were added to refs/heads/main by this push:
new 46b060d Add private network param check (#60)
46b060d is described below
commit 46b060de3ed201125966c59f84225553b4326ca3
Author: zhaohai <33...@users.noreply.github.com>
AuthorDate: Wed Mar 22 09:58:07 2023 +0800
Add private network param check (#60)
Add private network param check
---
.../common/exception/EventBridgeErrorCode.java | 1 +
.../domain/model/connection/ConnectionService.java | 118 +++++++++++++--------
2 files changed, 74 insertions(+), 45 deletions(-)
diff --git a/domain/src/main/java/org/apache/rocketmq/eventbridge/domain/common/exception/EventBridgeErrorCode.java b/domain/src/main/java/org/apache/rocketmq/eventbridge/domain/common/exception/EventBridgeErrorCode.java
index 52f5c62..71f45ce 100644
--- a/domain/src/main/java/org/apache/rocketmq/eventbridge/domain/common/exception/EventBridgeErrorCode.java
+++ b/domain/src/main/java/org/apache/rocketmq/eventbridge/domain/common/exception/EventBridgeErrorCode.java
@@ -133,6 +133,7 @@ public enum EventBridgeErrorCode implements BaseErrorCode {
ClientSecretLengthExceed(409, "ClientSecretLengthExceed", "ClientSecret length cannot exceed 127 !"),
AuthorizationEndpointLengthExceed(409, "AuthorizationEndpointLengthExceed", "Authorization endpoint length cannot exceed 127 !"),
+ NetworkParametersIsEmpty(409, "NetworkParametersIsEmpty", "Network required parameter is empty !"),
RequestParameterInvalid(409, "RequestParameterInvalid", "Request parameter Invalid !");
private final int httpCode;
diff --git a/domain/src/main/java/org/apache/rocketmq/eventbridge/domain/model/connection/ConnectionService.java b/domain/src/main/java/org/apache/rocketmq/eventbridge/domain/model/connection/ConnectionService.java
index a773d7e..d0ebad5 100644
--- a/domain/src/main/java/org/apache/rocketmq/eventbridge/domain/model/connection/ConnectionService.java
+++ b/domain/src/main/java/org/apache/rocketmq/eventbridge/domain/model/connection/ConnectionService.java
@@ -90,59 +90,80 @@ public class ConnectionService extends AbstractResourceService {
private void checkAuthParameters(AuthParameters authParameters) {
if (authParameters != null) {
- BasicAuthParameters basicAuthParameters = authParameters.getBasicAuthParameters();
- if (basicAuthParameters != null && AuthorizationTypeEnum.BASIC_AUTH.getType().equals(authParameters.getAuthorizationType())) {
- if (StringUtils.isBlank(basicAuthParameters.getUsername()) || StringUtils.isBlank(basicAuthParameters.getPassword())) {
- throw new EventBridgeException(EventBridgeErrorCode.BasicRequiredParameterIsEmpty);
- }
- String username = basicAuthParameters.getUsername();
- String password = basicAuthParameters.getPassword();
- if (username.length() > EventBridgeConstants.MAX_LENGTH_CONSTANT || username.length() < EventBridgeConstants.MIN_LENGTH_CONSTANT) {
- throw new EventBridgeException(EventBridgeErrorCode.BasicUserNameLengthExceed);
- }
- if (password.length() > EventBridgeConstants.MAX_LENGTH_CONSTANT || password.length() < EventBridgeConstants.MIN_LENGTH_CONSTANT) {
- throw new EventBridgeException(EventBridgeErrorCode.BasicPassWordLengthExceed);
- }
+ checkBasicAuthParameters(authParameters);
+ checkApiKeyAuthParameters(authParameters);
+ checkOAuthParameters(authParameters);
+ }
+ }
+
+ private void checkOAuthParameters(AuthParameters authParameters) {
+ OAuthParameters oauthParameters = authParameters.getOauthParameters();
+ if (AuthorizationTypeEnum.OAUTH_AUTH.getType().equals(authParameters.getAuthorizationType()) && oauthParameters == null) {
+ throw new EventBridgeException(EventBridgeErrorCode.OAuthRequiredParameterIsEmpty);
+ }
+ if (oauthParameters != null && AuthorizationTypeEnum.OAUTH_AUTH.getType().equals(authParameters.getAuthorizationType())) {
+ if (StringUtils.isBlank(oauthParameters.getAuthorizationEndpoint()) || StringUtils.isBlank(oauthParameters.getHttpMethod())) {
+ throw new EventBridgeException(EventBridgeErrorCode.OAuthRequiredParameterIsEmpty);
}
- ApiKeyAuthParameters apiKeyAuthParameters = authParameters.getApiKeyAuthParameters();
- if (apiKeyAuthParameters != null && AuthorizationTypeEnum.API_KEY_AUTH.getType().equals(authParameters.getAuthorizationType())) {
- if (StringUtils.isBlank(apiKeyAuthParameters.getApiKeyName()) || StringUtils.isBlank(apiKeyAuthParameters.getApiKeyValue())) {
- throw new EventBridgeException(EventBridgeErrorCode.ApiKeyRequiredParameterIsEmpty);
- }
- String apiKeyName = apiKeyAuthParameters.getApiKeyName();
- String apiKeyValue = apiKeyAuthParameters.getApiKeyValue();
- if (apiKeyName.length() > EventBridgeConstants.MAX_LENGTH_CONSTANT || apiKeyName.length() < EventBridgeConstants.MIN_LENGTH_CONSTANT) {
- throw new EventBridgeException(EventBridgeErrorCode.ApiKeyNameLengthExceed);
- }
- if (apiKeyValue.length() > EventBridgeConstants.MAX_LENGTH_CONSTANT || apiKeyValue.length() < EventBridgeConstants.MIN_LENGTH_CONSTANT) {
- throw new EventBridgeException(EventBridgeErrorCode.ApiKeyValueLengthExceed);
- }
+ if (oauthParameters.getAuthorizationEndpoint().length() > EventBridgeConstants.MAX_LENGTH_CONSTANT || oauthParameters.getAuthorizationEndpoint().length() < EventBridgeConstants.MIN_LENGTH_CONSTANT) {
+ throw new EventBridgeException(EventBridgeErrorCode.AuthorizationEndpointLengthExceed);
}
- OAuthParameters oauthParameters = authParameters.getOauthParameters();
- if (oauthParameters != null && AuthorizationTypeEnum.OAUTH_AUTH.getType().equals(authParameters.getAuthorizationType())) {
- if (StringUtils.isBlank(oauthParameters.getAuthorizationEndpoint()) || StringUtils.isBlank(oauthParameters.getHttpMethod())) {
- throw new EventBridgeException(EventBridgeErrorCode.OAuthRequiredParameterIsEmpty);
- }
- if (oauthParameters.getAuthorizationEndpoint().length() > EventBridgeConstants.MAX_LENGTH_CONSTANT || oauthParameters.getAuthorizationEndpoint().length() < EventBridgeConstants.MIN_LENGTH_CONSTANT) {
- throw new EventBridgeException(EventBridgeErrorCode.AuthorizationEndpointLengthExceed);
+ if (oauthParameters.getClientParameters() != null) {
+ OAuthParameters.ClientParameters clientParameters = oauthParameters.getClientParameters();
+ if (StringUtils.isNotBlank(clientParameters.getClientID())
+ && (clientParameters.getClientID().length() > EventBridgeConstants.MAX_LENGTH_CONSTANT
+ || clientParameters.getClientID().length() < EventBridgeConstants.MIN_LENGTH_CONSTANT)) {
+ throw new EventBridgeException(EventBridgeErrorCode.ClientIDLengthExceed);
}
- if (oauthParameters.getClientParameters() != null) {
- OAuthParameters.ClientParameters clientParameters = oauthParameters.getClientParameters();
- if (StringUtils.isNotBlank(clientParameters.getClientID())
- && (clientParameters.getClientID().length() > EventBridgeConstants.MAX_LENGTH_CONSTANT
- || clientParameters.getClientID().length() < EventBridgeConstants.MIN_LENGTH_CONSTANT)) {
- throw new EventBridgeException(EventBridgeErrorCode.ClientIDLengthExceed);
- }
- if (StringUtils.isNotBlank(clientParameters.getClientSecret())
- && (clientParameters.getClientSecret().length() > EventBridgeConstants.MAX_LENGTH_CONSTANT
- || clientParameters.getClientSecret().length() < EventBridgeConstants.MIN_LENGTH_CONSTANT)) {
- throw new EventBridgeException(EventBridgeErrorCode.ClientSecretLengthExceed);
- }
+ if (StringUtils.isNotBlank(clientParameters.getClientSecret())
+ && (clientParameters.getClientSecret().length() > EventBridgeConstants.MAX_LENGTH_CONSTANT
+ || clientParameters.getClientSecret().length() < EventBridgeConstants.MIN_LENGTH_CONSTANT)) {
+ throw new EventBridgeException(EventBridgeErrorCode.ClientSecretLengthExceed);
}
}
}
}
+ private void checkApiKeyAuthParameters(AuthParameters authParameters) {
+ ApiKeyAuthParameters apiKeyAuthParameters = authParameters.getApiKeyAuthParameters();
+ if (AuthorizationTypeEnum.API_KEY_AUTH.getType().equals(authParameters.getAuthorizationType()) && apiKeyAuthParameters == null) {
+ throw new EventBridgeException(EventBridgeErrorCode.ApiKeyRequiredParameterIsEmpty);
+ }
+ if (apiKeyAuthParameters != null && AuthorizationTypeEnum.API_KEY_AUTH.getType().equals(authParameters.getAuthorizationType())) {
+ if (StringUtils.isBlank(apiKeyAuthParameters.getApiKeyName()) || StringUtils.isBlank(apiKeyAuthParameters.getApiKeyValue())) {
+ throw new EventBridgeException(EventBridgeErrorCode.ApiKeyRequiredParameterIsEmpty);
+ }
+ String apiKeyName = apiKeyAuthParameters.getApiKeyName();
+ String apiKeyValue = apiKeyAuthParameters.getApiKeyValue();
+ if (apiKeyName.length() > EventBridgeConstants.MAX_LENGTH_CONSTANT || apiKeyName.length() < EventBridgeConstants.MIN_LENGTH_CONSTANT) {
+ throw new EventBridgeException(EventBridgeErrorCode.ApiKeyNameLengthExceed);
+ }
+ if (apiKeyValue.length() > EventBridgeConstants.MAX_LENGTH_CONSTANT || apiKeyValue.length() < EventBridgeConstants.MIN_LENGTH_CONSTANT) {
+ throw new EventBridgeException(EventBridgeErrorCode.ApiKeyValueLengthExceed);
+ }
+ }
+ }
+
+ private void checkBasicAuthParameters(AuthParameters authParameters) {
+ BasicAuthParameters basicAuthParameters = authParameters.getBasicAuthParameters();
+ if (AuthorizationTypeEnum.BASIC_AUTH.getType().equals(authParameters.getAuthorizationType()) && basicAuthParameters == null) {
+ throw new EventBridgeException(EventBridgeErrorCode.BasicRequiredParameterIsEmpty);
+ }
+ if (basicAuthParameters != null && AuthorizationTypeEnum.BASIC_AUTH.getType().equals(authParameters.getAuthorizationType())) {
+ if (StringUtils.isBlank(basicAuthParameters.getUsername()) || StringUtils.isBlank(basicAuthParameters.getPassword())) {
+ throw new EventBridgeException(EventBridgeErrorCode.BasicRequiredParameterIsEmpty);
+ }
+ String username = basicAuthParameters.getUsername();
+ String password = basicAuthParameters.getPassword();
+ if (username.length() > EventBridgeConstants.MAX_LENGTH_CONSTANT || username.length() < EventBridgeConstants.MIN_LENGTH_CONSTANT) {
+ throw new EventBridgeException(EventBridgeErrorCode.BasicUserNameLengthExceed);
+ }
+ if (password.length() > EventBridgeConstants.MAX_LENGTH_CONSTANT || password.length() < EventBridgeConstants.MIN_LENGTH_CONSTANT) {
+ throw new EventBridgeException(EventBridgeErrorCode.BasicPassWordLengthExceed);
+ }
+ }
+ }
+
@Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
public void deleteConnection(String accountId, String connectionName) {
if (CollectionUtils.isEmpty(checkConnection(accountId, connectionName))) {
@@ -318,5 +339,12 @@ public class ConnectionService extends AbstractResourceService {
if (check) {
throw new EventBridgeException(EventBridgeErrorCode.ConnectionNetworkParametersInvalid);
}
+ if (NetworkTypeEnum.PRIVATE_NETWORK.getNetworkType().equals(type)) {
+ if (StringUtils.isBlank(networkParameters.getVpcId())
+ || StringUtils.isBlank(networkParameters.getVswitcheId())
+ || StringUtils.isBlank(networkParameters.getSecurityGroupId())) {
+ throw new EventBridgeException(EventBridgeErrorCode.NetworkParametersIsEmpty);
+ }
+ }
}
}