diff --git a/storage-jdbc/src/main/java/org/apache/rocketmq/schema/registry/storage/jdbc/JdbcStorageService.java b/storage-jdbc/src/main/java/org/apache/rocketmq/schema/registry/storage/jdbc/JdbcStorageService.java index 1d94c57..03c91ee 100644 --- a/storage-jdbc/src/main/java/org/apache/rocketmq/schema/registry/storage/jdbc/JdbcStorageService.java +++ b/storage-jdbc/src/main/java/org/apache/rocketmq/schema/registry/storage/jdbc/JdbcStorageService.java @@ -17,6 +17,7 @@ package org.apache.rocketmq.schema.registry.storage.jdbc; +import com.google.common.collect.Lists; import org.apache.avro.Schema; import org.apache.rocketmq.schema.registry.common.QualifiedName; import org.apache.rocketmq.schema.registry.common.context.StoragePluginContext; @@ -138,7 +139,7 @@ public List listSubjectsByTenant(StorageServiceContext context, Qualifie @Override public List listTenants(StorageServiceContext storageService, QualifiedName qualifiedName) { - return handler.getTenants(qualifiedName.getCluster()); + return Lists.newArrayList(handler.getTenants(qualifiedName.getCluster())); } @Override diff --git a/storage-jdbc/src/main/java/org/apache/rocketmq/schema/registry/storage/jdbc/handler/IHandler.java b/storage-jdbc/src/main/java/org/apache/rocketmq/schema/registry/storage/jdbc/handler/IHandler.java index 798d00e..9aed85f 100644 --- a/storage-jdbc/src/main/java/org/apache/rocketmq/schema/registry/storage/jdbc/handler/IHandler.java +++ b/storage-jdbc/src/main/java/org/apache/rocketmq/schema/registry/storage/jdbc/handler/IHandler.java @@ -24,6 +24,7 @@ import java.io.Closeable; import java.util.List; +import java.util.Set; public abstract class IHandler implements Closeable { /** @@ -100,7 +101,7 @@ public abstract class IHandler implements Closeable { * @param cluster * @return */ - public abstract List getTenants(String cluster); + public abstract Set getTenants(String cluster); protected void changeNotify() { diff --git a/storage-jdbc/src/main/java/org/apache/rocketmq/schema/registry/storage/jdbc/handler/SchemaHandler.java b/storage-jdbc/src/main/java/org/apache/rocketmq/schema/registry/storage/jdbc/handler/SchemaHandler.java index 4527437..6962260 100644 --- a/storage-jdbc/src/main/java/org/apache/rocketmq/schema/registry/storage/jdbc/handler/SchemaHandler.java +++ b/storage-jdbc/src/main/java/org/apache/rocketmq/schema/registry/storage/jdbc/handler/SchemaHandler.java @@ -17,7 +17,7 @@ package org.apache.rocketmq.schema.registry.storage.jdbc.handler; -import com.google.common.collect.Lists; +import com.google.common.collect.Sets; import com.hazelcast.config.Config; import com.hazelcast.core.EntryEvent; import com.hazelcast.core.Hazelcast; @@ -42,6 +42,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.stream.Collectors; import static org.apache.rocketmq.schema.registry.storage.jdbc.store.JdbcSchemaMapStore.SCHEMAS; @@ -214,16 +215,18 @@ public List getSubjects(StorageServiceContext context, String tenant) { for (Map.Entry schemaRecordEntry : subjects.entrySet()) { String subjectFullName = schemaRecordEntry.getKey(); String[] subjectFromCache = subjectFullName.split(String.valueOf(SchemaConstants.SUBJECT_SEPARATOR)); + String tenantFromKey = subjectFromCache[1]; String subjectFromKey = subjectFromCache[2]; - // Check permission - allSubjects.add(subjectFromKey); + if (tenant.equals(tenantFromKey)) { + allSubjects.add(subjectFromKey); + } } return allSubjects; } @Override - public List getTenants(String cluster) { - List tenants = Lists.newArrayList(); + public Set getTenants(String cluster) { + Set tenants = Sets.newHashSet(); for (Map.Entry schemaRecordEntry : subjects.entrySet()) { String subjectFullName = schemaRecordEntry.getKey(); String tenant = subjectFullName.split(String.valueOf(SchemaConstants.SUBJECT_SEPARATOR))[1];