diff --git a/auth/src/main/java/org/apache/rocketmq/auth/authentication/builder/DefaultAuthenticationContextBuilder.java b/auth/src/main/java/org/apache/rocketmq/auth/authentication/builder/DefaultAuthenticationContextBuilder.java index 6b178b96573..c1e970fa6eb 100644 --- a/auth/src/main/java/org/apache/rocketmq/auth/authentication/builder/DefaultAuthenticationContextBuilder.java +++ b/auth/src/main/java/org/apache/rocketmq/auth/authentication/builder/DefaultAuthenticationContextBuilder.java @@ -98,12 +98,12 @@ public DefaultAuthenticationContext build(Metadata metadata, GeneratedMessageV3 @Override public DefaultAuthenticationContext build(ChannelHandlerContext context, RemotingCommand request) { HashMap fields = request.getExtFields(); - if (MapUtils.isEmpty(fields)) { - throw new AuthenticationException("authentication field is null."); - } DefaultAuthenticationContext result = new DefaultAuthenticationContext(); result.setChannelId(context.channel().id().asLongText()); result.setRpcCode(String.valueOf(request.getCode())); + if (MapUtils.isEmpty(fields)) { + return result; + } if (!fields.containsKey(SessionCredentials.ACCESS_KEY)) { return result; } diff --git a/auth/src/main/java/org/apache/rocketmq/auth/authorization/builder/DefaultAuthorizationContextBuilder.java b/auth/src/main/java/org/apache/rocketmq/auth/authorization/builder/DefaultAuthorizationContextBuilder.java index daa039162b4..d6d1556ca20 100644 --- a/auth/src/main/java/org/apache/rocketmq/auth/authorization/builder/DefaultAuthorizationContextBuilder.java +++ b/auth/src/main/java/org/apache/rocketmq/auth/authorization/builder/DefaultAuthorizationContextBuilder.java @@ -40,6 +40,7 @@ import java.util.HashMap; import java.util.List; import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.collections.MapUtils; import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.StringUtils; import org.apache.rocketmq.acl.common.AclException; @@ -160,6 +161,9 @@ public List build(ChannelHandlerContext context, Re List result = new ArrayList<>(); try { HashMap fields = command.getExtFields(); + if (MapUtils.isEmpty(fields)) { + return result; + } Subject subject = null; if (fields.containsKey(SessionCredentials.ACCESS_KEY)) { subject = User.of(fields.get(SessionCredentials.ACCESS_KEY));