Search in sources :

Example 1 with Action

use of org.apache.kafka.server.authorizer.Action in project kafka by apache.

the class AclAuthorizerBenchmark method setup.

@Setup(Level.Trial)
public void setup() throws Exception {
    prepareAclCache();
    prepareAclToUpdate();
    // By adding `-95` to the resource name prefix, we cause the `TreeMap.from/to` call to return
    // most map entries. In such cases, we rely on the filtering based on `String.startsWith`
    // to return the matching ACLs. Using a more efficient data structure (e.g. a prefix
    // tree) should improve performance significantly).
    actions = Collections.singletonList(new Action(AclOperation.WRITE, new ResourcePattern(ResourceType.TOPIC, resourceNamePrefix + 95, PatternType.LITERAL), 1, true, true));
    authorizeContext = new RequestContext(new RequestHeader(ApiKeys.PRODUCE, Integer.valueOf(1).shortValue(), "someclient", 1), "1", InetAddress.getByName("127.0.0.1"), principal, ListenerName.normalised("listener"), SecurityProtocol.PLAINTEXT, ClientInformation.EMPTY, false);
    authorizeByResourceTypeContext = new RequestContext(new RequestHeader(ApiKeys.PRODUCE, Integer.valueOf(1).shortValue(), "someclient", 1), "1", InetAddress.getByName(authorizeByResourceTypeHostName), principal, ListenerName.normalised("listener"), SecurityProtocol.PLAINTEXT, ClientInformation.EMPTY, false);
}
Also used : Action(org.apache.kafka.server.authorizer.Action) ResourcePattern(org.apache.kafka.common.resource.ResourcePattern) RequestHeader(org.apache.kafka.common.requests.RequestHeader) RequestContext(org.apache.kafka.common.requests.RequestContext) Setup(org.openjdk.jmh.annotations.Setup)

Example 2 with Action

use of org.apache.kafka.server.authorizer.Action in project kafka by apache.

the class StandardAuthorizerTest method testHostAddressAclValidation.

@Test
public void testHostAddressAclValidation() throws Exception {
    InetAddress host1 = InetAddress.getByName("192.168.1.1");
    InetAddress host2 = InetAddress.getByName("192.168.1.2");
    StandardAuthorizer authorizer = new StandardAuthorizer();
    authorizer.configure(Collections.emptyMap());
    List<StandardAcl> acls = Arrays.asList(new StandardAcl(TOPIC, "foo", LITERAL, "User:alice", host1.getHostAddress(), READ, DENY), new StandardAcl(TOPIC, "foo", LITERAL, "User:alice", "*", READ, ALLOW), new StandardAcl(TOPIC, "bar", LITERAL, "User:bob", host2.getHostAddress(), READ, ALLOW), new StandardAcl(TOPIC, "bar", LITERAL, "User:*", InetAddress.getLocalHost().getHostAddress(), DESCRIBE, ALLOW));
    acls.forEach(acl -> {
        StandardAclWithId aclWithId = withId(acl);
        authorizer.addAcl(aclWithId.id(), aclWithId.acl());
    });
    List<Action> actions = Arrays.asList(newAction(READ, TOPIC, "foo"), newAction(READ, TOPIC, "bar"), newAction(DESCRIBE, TOPIC, "bar"));
    assertEquals(Arrays.asList(ALLOWED, DENIED, ALLOWED), authorizer.authorize(newRequestContext("alice", InetAddress.getLocalHost()), actions));
    assertEquals(Arrays.asList(DENIED, DENIED, DENIED), authorizer.authorize(newRequestContext("alice", host1), actions));
    assertEquals(Arrays.asList(ALLOWED, DENIED, DENIED), authorizer.authorize(newRequestContext("alice", host2), actions));
    assertEquals(Arrays.asList(DENIED, DENIED, ALLOWED), authorizer.authorize(newRequestContext("bob", InetAddress.getLocalHost()), actions));
    assertEquals(Arrays.asList(DENIED, DENIED, DENIED), authorizer.authorize(newRequestContext("bob", host1), actions));
    assertEquals(Arrays.asList(DENIED, ALLOWED, ALLOWED), authorizer.authorize(newRequestContext("bob", host2), actions));
}
Also used : Action(org.apache.kafka.server.authorizer.Action) InetAddress(java.net.InetAddress) Test(org.junit.jupiter.api.Test)

Example 3 with Action

use of org.apache.kafka.server.authorizer.Action in project kafka by apache.

the class StandardAuthorizer method authorize.

@Override
public List<AuthorizationResult> authorize(AuthorizableRequestContext requestContext, List<Action> actions) {
    StandardAuthorizerData curData = data;
    List<AuthorizationResult> results = new ArrayList<>(actions.size());
    for (Action action : actions) {
        AuthorizationResult result = curData.authorize(requestContext, action);
        results.add(result);
    }
    return results;
}
Also used : Action(org.apache.kafka.server.authorizer.Action) ArrayList(java.util.ArrayList) AuthorizationResult(org.apache.kafka.server.authorizer.AuthorizationResult)

Aggregations

Action (org.apache.kafka.server.authorizer.Action)3 InetAddress (java.net.InetAddress)1 ArrayList (java.util.ArrayList)1 RequestContext (org.apache.kafka.common.requests.RequestContext)1 RequestHeader (org.apache.kafka.common.requests.RequestHeader)1 ResourcePattern (org.apache.kafka.common.resource.ResourcePattern)1 AuthorizationResult (org.apache.kafka.server.authorizer.AuthorizationResult)1 Test (org.junit.jupiter.api.Test)1 Setup (org.openjdk.jmh.annotations.Setup)1