cmccabe commented on a change in pull request #11649: URL: https://github.com/apache/kafka/pull/11649#discussion_r801174494
########## File path: metadata/src/main/java/org/apache/kafka/metadata/authorizer/StandardAcl.java ########## @@ -0,0 +1,176 @@ +/* + * 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.kafka.metadata.authorizer; + +import org.apache.kafka.common.acl.AccessControlEntry; +import org.apache.kafka.common.acl.AclBinding; +import org.apache.kafka.common.acl.AclOperation; +import org.apache.kafka.common.acl.AclPermissionType; +import org.apache.kafka.common.metadata.AccessControlEntryRecord; +import org.apache.kafka.common.resource.PatternType; +import org.apache.kafka.common.resource.ResourcePattern; +import org.apache.kafka.common.resource.ResourceType; + +import java.util.Objects; + + +/** + * A Kafka ACLs which is identified by a UUID and stored in the metadata log. + */ +final public class StandardAcl implements Comparable<StandardAcl> { + public static StandardAcl fromRecord(AccessControlEntryRecord record) { + return new StandardAcl( + ResourceType.fromCode(record.resourceType()), + record.resourceName(), + PatternType.fromCode(record.patternType()), + record.principal(), + record.host(), + AclOperation.fromCode(record.operation()), + AclPermissionType.fromCode(record.permissionType())); + } + + public static StandardAcl fromAclBinding(AclBinding acl) { + return new StandardAcl( + acl.pattern().resourceType(), + acl.pattern().name(), + acl.pattern().patternType(), + acl.entry().principal(), + acl.entry().host(), + acl.entry().operation(), + acl.entry().permissionType()); + } + + private final ResourceType resourceType; + private final String resourceName; + private final PatternType patternType; + private final String principal; + private final String host; + private final AclOperation operation; + private final AclPermissionType permissionType; + + public StandardAcl( + ResourceType resourceType, + String resourceName, + PatternType patternType, + String principal, + String host, + AclOperation operation, + AclPermissionType permissionType) { + this.resourceType = resourceType; + this.resourceName = resourceName; + this.patternType = patternType; + this.principal = principal; + this.host = host; + this.operation = operation; + this.permissionType = permissionType; + } + + public ResourceType resourceType() { + return resourceType; + } + + public String resourceName() { + return resourceName; + } + + public PatternType patternType() { + return patternType; + } + + public String principal() { + return principal; + } + + public String host() { + return host; + } + + public AclOperation operation() { + return operation; + } + + public AclPermissionType permissionType() { + return permissionType; + } + + public AclBinding toBinding() { + ResourcePattern resourcePattern = + new ResourcePattern(resourceType, resourceName, patternType); + AccessControlEntry accessControlEntry = + new AccessControlEntry(principal, host, operation, permissionType); + return new AclBinding(resourcePattern, accessControlEntry); + } + + @Override + public boolean equals(Object o) { + if (o == null || !o.getClass().equals(StandardAcl.class)) return false; + if (o == this) return true; + StandardAcl other = (StandardAcl) o; + return resourceType.equals(other.resourceType) && + resourceName.equals(other.resourceName) && + patternType.equals(other.patternType) && + principal.equals(other.principal) && + host.equals(other.host) && + operation.equals(other.operation) && + permissionType.equals(other.permissionType); + } + + @Override + public int hashCode() { + return Objects.hash( + resourceType, + resourceName, + patternType, + principal, + host, + operation, + permissionType); + } + + @Override + public int compareTo(StandardAcl other) { + int result; + result = resourceType.compareTo(other.resourceType); + if (result != 0) return result; + result = patternType.compareTo(other.patternType); + if (result != 0) return result; + result = resourceName.compareTo(other.resourceName); + if (result != 0) return result; + result = principal.compareTo(other.principal); + if (result != 0) return result; + result = host.compareTo(other.host); + if (result != 0) return result; + result = operation.compareTo(other.operation); + if (result != 0) return result; + result = permissionType.compareTo(other.permissionType); + return 0; Review comment: yes, good catch. should be fixed -- 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