use of io.confluent.ksql.security.KsqlAuthorizationProvider 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));
}
use of io.confluent.ksql.security.KsqlAuthorizationProvider 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));
}
use of io.confluent.ksql.security.KsqlAuthorizationProvider in project ksql by confluentinc.
the class AuthTest method createServer.
@Override
protected void createServer(KsqlRestConfig serverConfig) {
server = new Server(vertx, serverConfig, testEndpoints, new KsqlSecurityExtension() {
@Override
public void initialize(final KsqlConfig ksqlConfig) {
}
@Override
public Optional<KsqlAuthorizationProvider> getAuthorizationProvider() {
return Optional.ofNullable(authorizationProvider);
}
@Override
public Optional<KsqlUserContextProvider> getUserContextProvider() {
return Optional.ofNullable(userContextProvider);
}
@Override
public void close() {
}
}, Optional.ofNullable(securityHandlerPlugin), serverState, Optional.empty());
server.start();
}
use of io.confluent.ksql.security.KsqlAuthorizationProvider 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();
}
Aggregations