Search in sources :

Example 1 with AuthObjectType

use of io.confluent.ksql.security.AuthObjectType in project ksql by confluentinc.

the class AuthTest method shouldAllowAccessWithPermissionCheck.

private void shouldAllowAccessWithPermissionCheck(final String expectedUser, final String expectedMethod, final String expectedPath, final ExceptionThrowingRunnable action) throws Exception {
    stopServer();
    stopClient();
    AtomicReference<Principal> principalAtomicReference = new AtomicReference<>();
    AtomicReference<String> methodAtomicReference = new AtomicReference<>();
    AtomicReference<String> pathAtomicReference = new AtomicReference<>();
    this.authorizationProvider = new KsqlAuthorizationProvider() {

        @Override
        public void checkEndpointAccess(final Principal user, final String method, final String path) {
            throwIfNullPrincipal(user);
            principalAtomicReference.set(user);
            methodAtomicReference.set(method);
            pathAtomicReference.set(path);
        }

        @Override
        public void checkPrivileges(final KsqlSecurityContext securityContext, final AuthObjectType objectType, final String objectName, final List<AclOperation> privileges) {
        // Not required for vert.x authX as it only authorizes endpoints
        }
    };
    createServer(createServerConfig());
    client = createClient();
    action.run();
    assertThat(principalAtomicReference.get().getName(), is(expectedUser));
    assertThat(methodAtomicReference.get(), is(expectedMethod));
    assertThat(pathAtomicReference.get(), is(expectedPath));
}
Also used : KsqlSecurityContext(io.confluent.ksql.security.KsqlSecurityContext) AuthObjectType(io.confluent.ksql.security.AuthObjectType) AclOperation(org.apache.kafka.common.acl.AclOperation) AtomicReference(java.util.concurrent.atomic.AtomicReference) KsqlAuthorizationProvider(io.confluent.ksql.security.KsqlAuthorizationProvider) Principal(java.security.Principal)

Example 2 with AuthObjectType

use of io.confluent.ksql.security.AuthObjectType in project ksql by confluentinc.

the class AuthTest method shouldAllowAccessWithoutAuthentication.

private void shouldAllowAccessWithoutAuthentication(final ExceptionThrowingRunnable action) throws Exception {
    stopServer();
    stopClient();
    AtomicReference<Boolean> authorizationCallReference = new AtomicReference<>(false);
    this.authorizationProvider = new KsqlAuthorizationProvider() {

        @Override
        public void checkEndpointAccess(final Principal user, final String method, final String path) {
            authorizationCallReference.set(true);
        }

        @Override
        public void checkPrivileges(final KsqlSecurityContext securityContext, final AuthObjectType objectType, final String objectName, final List<AclOperation> privileges) {
        // Not required for vert.x authX as it only authorizes endpoints
        }
    };
    createServer(createServerConfig());
    client = createClient();
    action.run();
    assertThat("Should not call authorization", authorizationCallReference.get(), is(false));
}
Also used : KsqlSecurityContext(io.confluent.ksql.security.KsqlSecurityContext) AuthObjectType(io.confluent.ksql.security.AuthObjectType) AclOperation(org.apache.kafka.common.acl.AclOperation) AtomicReference(java.util.concurrent.atomic.AtomicReference) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) KsqlAuthorizationProvider(io.confluent.ksql.security.KsqlAuthorizationProvider) Principal(java.security.Principal)

Example 3 with AuthObjectType

use of io.confluent.ksql.security.AuthObjectType in project ksql by confluentinc.

the class AuthTest method shouldNotAllowAccessIfPermissionCheckThrowsException.

private void shouldNotAllowAccessIfPermissionCheckThrowsException(ExceptionThrowingRunnable runnable) throws Exception {
    stopServer();
    stopClient();
    this.authorizationProvider = new KsqlAuthorizationProvider() {

        @Override
        public void checkEndpointAccess(final Principal user, final String method, final String path) {
            throw new KsqlException("Forbidden");
        }

        @Override
        public void checkPrivileges(final KsqlSecurityContext securityContext, final AuthObjectType objectType, final String objectName, final List<AclOperation> privileges) {
        // Not required for vert.x authX as it only authorizes endpoints
        }
    };
    createServer(createServerConfig());
    client = createClient();
    runnable.run();
}
Also used : KsqlSecurityContext(io.confluent.ksql.security.KsqlSecurityContext) AuthObjectType(io.confluent.ksql.security.AuthObjectType) AclOperation(org.apache.kafka.common.acl.AclOperation) KsqlAuthorizationProvider(io.confluent.ksql.security.KsqlAuthorizationProvider) KsqlException(io.confluent.ksql.util.KsqlException) Principal(java.security.Principal)

Aggregations

AuthObjectType (io.confluent.ksql.security.AuthObjectType)3 KsqlAuthorizationProvider (io.confluent.ksql.security.KsqlAuthorizationProvider)3 KsqlSecurityContext (io.confluent.ksql.security.KsqlSecurityContext)3 Principal (java.security.Principal)3 AclOperation (org.apache.kafka.common.acl.AclOperation)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 KsqlException (io.confluent.ksql.util.KsqlException)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1