Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejava
titleAuthorizable Action
package org.apache.kafka.server.authorizer;

import java.util.Objects;
import org.apache.kafka.common.acl.AclOperation;
import org.apache.kafka.common.annotation.InterfaceStability;
import org.apache.kafka.common.resource.PatternType;
import org.apache.kafka.common.resource.ResourcePattern;
import org.apache.kafka.common.resource.ResourceType;

@InterfaceStability.Evolving
public class Action {

    private final ResourcePattern resourcePattern;
    private final AclOperation operation;
    private final AuditFlag auditFlag;
    private final int resourceReferenceCount;

    public Action(AclOperation operation,
        ResourceType resourceType,
        String resourceName,
        AuditFlag auditFlag,
        int resourceReferenceCount) {
        this.operation = operation;
        this.resourcePattern = new ResourcePattern(resourceType, resourceName, PatternType.LITERAL);
        this.auditFlag = auditFlag;
        this.resourceReferenceCount = resourceReferenceCount;
    }

    /**
     * Resource on which action is being performed.
     */
    public ResourcePattern resourcePattern() {
        return resourcePattern;
    }

    /**
     * Operation being performed.
     */
    public AclOperation operation() {
        return operation;
    }

    /**
     * Authorization usage flag to enable authorization logs to distinguish between attempts
     * to access unauthorized resources and other filtering operations performed by the broker.
     */
    public AuditFlag auditFlag() {
        return auditFlag;
    }

    /**
     * Number of times the authorizationresource being resultauthorized is used referenced within the request. For example, a single topic
     * authorizationrequest result may bereference used`n` with `resourceReferenceCount`topic partitions of the same topic within a single. Brokers will authorize the topic once
     * request with `resourceReferenceCount=n`. Authorizers may include the count in audit logs.
     */
    public int resourceReferenceCount() {
        return resourceReferenceCount;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (!(o instanceof Action)) {
            return false;
        }

        Action that = (Action) o;
        return Objects.equals(this.resourcePattern, that.resourcePattern) &&
            Objects.equals(this.operation, that.operation) &&
            Objects.equals(this.auditFlag, that.auditFlag) &&
            Objects.equals(this.resourceReferenceCount, that.resourceReferenceCount);

    }

    @Override
    public int hashCode() {
        return Objects.hash(resourcePattern, operation, auditFlag);
    }

    @Override
    public String toString() {
        return "Action(" +
            ", resourcePattern='" + resourcePattern + '\'' +
            ", operation='" + operation + '\'' +
            ", auditFlag='" + auditFlag + '\'' +
            ", resourceReferenceCount='" + resourceReferenceCount + '\'' +
            ')';
    }
}

...