d8tltanc commented on a change in pull request #9485: URL: https://github.com/apache/kafka/pull/9485#discussion_r543099934
########## File path: core/src/main/scala/kafka/security/authorizer/AuthorizerWrapper.scala ########## @@ -175,4 +185,39 @@ class AuthorizerWrapper(private[kafka] val baseAuthorizer: kafka.security.auth.A override def close(): Unit = { baseAuthorizer.close() } + + override def authorizeByResourceType(requestContext: AuthorizableRequestContext, + op: AclOperation, + resourceType: ResourceType): AuthorizationResult = { + SecurityUtils.authorizeByResourceTypeCheckArgs(op, resourceType) + + if (denyAllResource(requestContext, op, resourceType)) { + AuthorizationResult.DENIED + } else if (shouldAllowEveryoneIfNoAclIsFound) { + AuthorizationResult.ALLOWED + } else { + super.authorizeByResourceType(requestContext, op, resourceType) + } + } + + private def denyAllResource(requestContext: AuthorizableRequestContext, + op: AclOperation, + resourceType: ResourceType): Boolean = { + val resourceTypeFilter = new ResourcePatternFilter( + resourceType, Resource.WildCardResource, PatternType.LITERAL) + val principal = new KafkaPrincipal(requestContext.principal.getPrincipalType, requestContext.principal.getName) + val host = requestContext.clientAddress().getHostAddress + val accessControlEntry = new AccessControlEntryFilter(null, null, op, AclPermissionType.DENY) + val aclFilter = new AclBindingFilter(resourceTypeFilter, accessControlEntry) + + acls(aclFilter).asScala.exists(b => principalHostMatch(b.entry(), principal, host)) + } + + private def principalHostMatch(ace: AccessControlEntry, + principal: KafkaPrincipal, + host: String): Boolean = { + ((ace.host() == AclEntry.WildcardHost || ace.host() == host) + && (ace.principal() == AclEntry.WildcardPrincipalString || ace.principal() == principal.toString)) Review comment: Yeah. I was trying to restrict the type in order to remind people to construct a KafkaPrinciple first. But toString() is an expensive operation. commit 16576f85a858648cfc4ff882b554ddc65922021c ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org