RockteMQ-AI commented on code in PR #10925: URL: https://github.com/apache/rocketmq/pull/10925#discussion_r3775003073
########## auth/src/main/java/org/apache/rocketmq/auth/authorization/AuthorizationCompatibility.java: ########## @@ -0,0 +1,116 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.rocketmq.auth.authorization; + +import apache.rocketmq.v2.ClientType; +import apache.rocketmq.v2.HeartbeatRequest; +import apache.rocketmq.v2.NotifyClientTerminationRequest; +import apache.rocketmq.v2.TelemetryCommand; +import com.google.protobuf.GeneratedMessageV3; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.rocketmq.remoting.protocol.RemotingCommand; +import org.apache.rocketmq.remoting.protocol.RequestCode; +import org.apache.rocketmq.remoting.protocol.heartbeat.HeartbeatData; +import org.apache.rocketmq.remoting.protocol.heartbeat.ProducerData; + +final class AuthorizationCompatibility { + + private AuthorizationCompatibility() { + } + + static boolean matches(RemotingCommand request) { + if (request == null) { + return false; + } + try { + switch (request.getCode()) { + case RequestCode.HEART_BEAT: + return isProducerHeartbeat(request); + case RequestCode.UNREGISTER_CLIENT: + return isProducerUnregister(request); + case RequestCode.END_TRANSACTION: + case RequestCode.VIEW_MESSAGE_BY_ID: + return isHistoricalTopicAbsent(request); + default: + return false; Review Comment: The `catch (Throwable ignored)` block silently swallows all exceptions. This is a deliberate defensive pattern for backward compatibility, but consider adding a brief comment explaining why all throwables are caught (e.g., 'catch-all to avoid breaking existing request flows when compatibility detection itself fails'). This helps future maintainers understand the intent and not 'fix' it away. ########## auth/src/main/java/org/apache/rocketmq/auth/authorization/AuthorizationEvaluator.java: ########## @@ -36,10 +39,37 @@ public AuthorizationEvaluator(AuthConfig authConfig, Supplier<?> metadataService this.authorizationStrategy = AuthorizationFactory.getStrategy(authConfig, metadataService); } - public void evaluate(List<AuthorizationContext> contexts) { + /** Review Comment: The behavior change from silently allowing empty contexts to throwing AuthorizationException is a security improvement. However, this could affect existing deployments that rely on the old pass-through behavior. Consider noting this in the PR description or commit message as a breaking change for operators who have ACL enabled but send requests without proper context building. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
