chia7712 commented on code in PR #18614: URL: https://github.com/apache/kafka/pull/18614#discussion_r1923628348
########## server/src/main/java/org/apache/kafka/security/authorizer/AclEntry.java: ########## @@ -55,96 +44,17 @@ import static org.apache.kafka.common.acl.AclOperation.WRITE; public class AclEntry extends AccessControlEntry { - private static final DecodeJson.DecodeInteger INT = new DecodeJson.DecodeInteger(); - private static final DecodeJson.DecodeString STRING = new DecodeJson.DecodeString(); public static final KafkaPrincipal WILDCARD_PRINCIPAL = new KafkaPrincipal(KafkaPrincipal.USER_TYPE, "*"); public static final String WILDCARD_PRINCIPAL_STRING = WILDCARD_PRINCIPAL.toString(); public static final String WILDCARD_HOST = "*"; public static final String WILDCARD_RESOURCE = ResourcePattern.WILDCARD_RESOURCE; - public static final String RESOURCE_SEPARATOR = ":"; - public static final Set<ResourceType> RESOURCE_TYPES = Arrays.stream(ResourceType.values()) - .filter(t -> !(t == ResourceType.UNKNOWN || t == ResourceType.ANY)) - .collect(Collectors.toSet()); public static final Set<AclOperation> ACL_OPERATIONS = Arrays.stream(AclOperation.values()) .filter(t -> !(t == AclOperation.UNKNOWN || t == AclOperation.ANY)) .collect(Collectors.toSet()); - - private static final String PRINCIPAL_KEY = "principal"; - private static final String PERMISSION_TYPE_KEY = "permissionType"; - private static final String OPERATION_KEY = "operation"; - private static final String HOSTS_KEY = "host"; - public static final String VERSION_KEY = "version"; - public static final int CURRENT_VERSION = 1; - private static final String ACLS_KEY = "acls"; - - public final AccessControlEntry ace; - public final KafkaPrincipal kafkaPrincipal; - - public AclEntry(AccessControlEntry ace) { - super(ace.principal(), ace.host(), ace.operation(), ace.permissionType()); - this.ace = ace; - - kafkaPrincipal = ace.principal() == null - ? null - : SecurityUtils.parseKafkaPrincipal(ace.principal()); - } - - /** - * Parse JSON representation of ACLs - * @param bytes of acls json string - * - * <p> - { - "version": 1, - "acls": [ - { - "host":"host1", - "permissionType": "Deny", - "operation": "Read", - "principal": "User:alice" - } - ] - } - * </p> - * - * @return set of AclEntry objects from the JSON string - */ - public static Set<AclEntry> fromBytes(byte[] bytes) throws IOException { - if (bytes == null || bytes.length == 0) - return Collections.emptySet(); - - Optional<JsonValue> jsonValue = Json.parseBytes(bytes); - if (jsonValue.isEmpty()) - return Collections.emptySet(); - - JsonObject js = jsonValue.get().asJsonObject(); - - //the acl json version. - Utils.require(js.apply(VERSION_KEY).to(INT) == CURRENT_VERSION); - - Set<AclEntry> res = new HashSet<>(); - - Iterator<JsonValue> aclsIter = js.apply(ACLS_KEY).asJsonArray().iterator(); - while (aclsIter.hasNext()) { - JsonObject itemJs = aclsIter.next().asJsonObject(); - KafkaPrincipal principal = SecurityUtils.parseKafkaPrincipal(itemJs.apply(PRINCIPAL_KEY).to(STRING)); - AclPermissionType permissionType = SecurityUtils.permissionType(itemJs.apply(PERMISSION_TYPE_KEY).to(STRING)); - String host = itemJs.apply(HOSTS_KEY).to(STRING); - AclOperation operation = SecurityUtils.operation(itemJs.apply(OPERATION_KEY).to(STRING)); - - res.add(new AclEntry(new AccessControlEntry(principal.toString(), - host, operation, permissionType))); - } - - return res; - } - - public static Map<String, Object> toJsonCompatibleMap(Set<AclEntry> acls) { - Map<String, Object> res = new HashMap<>(); - res.put(AclEntry.VERSION_KEY, AclEntry.CURRENT_VERSION); - res.put(AclEntry.ACLS_KEY, acls.stream().map(AclEntry::toMap).collect(Collectors.toList())); - return res; + + public AclEntry(String principal, String host, AclOperation operation, AclPermissionType permissionType) { Review Comment: agree to @mimaison @m1a2st could you please refactor `AuthorizerBenchmark` to use `AccessControlEntry` instead of `AclEntry`? With that refactor, in codebase we don't have any usage of constructor of `AclEntry`, and hence we can do more cleanup for `AclEntry` -- 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: jira-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org