Skip to content

Commit

Permalink
chore: remove unused method
Browse files Browse the repository at this point in the history
  • Loading branch information
spena committed Oct 22, 2020
1 parent f49fbf2 commit 807260d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import static java.util.Objects.requireNonNull;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.util.concurrent.ListeningScheduledExecutorService;
Expand All @@ -28,7 +27,6 @@
import io.confluent.kafka.schemaregistry.client.SchemaRegistryClient;
import io.confluent.ksql.ServiceInfo;
import io.confluent.ksql.api.auth.AuthenticationPlugin;
import io.confluent.ksql.api.auth.KsqlAuthorizationProviderHandler;
import io.confluent.ksql.api.impl.DefaultKsqlSecurityContextProvider;
import io.confluent.ksql.api.impl.KsqlSecurityContextProvider;
import io.confluent.ksql.api.impl.MonitoredEndpoints;
Expand Down Expand Up @@ -117,13 +115,11 @@
import java.time.Duration;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executors;
Expand Down Expand Up @@ -739,7 +735,7 @@ static KsqlRestApplication buildApplication(
serviceContext,
ksqlEngine,
ksqlConfig,
injectPathsWithoutAuthentication(restConfig),
restConfig,
commandRunner,
commandStore,
statusResource,
Expand Down Expand Up @@ -1009,22 +1005,6 @@ private static DropwizardMetricsOptions setUpHttpMetrics(final KsqlConfig ksqlCo
return metricsOptions;
}

private static KsqlRestConfig injectPathsWithoutAuthentication(final KsqlRestConfig restConfig) {
final Set<String> authenticationSkipPaths = new HashSet<>(
restConfig.getList(KsqlRestConfig.AUTHENTICATION_SKIP_PATHS_CONFIG)
);

authenticationSkipPaths.addAll(KsqlAuthorizationProviderHandler.KSQL_AUTHENTICATION_SKIP_PATHS);

final Map<String, Object> restConfigs = restConfig.getOriginals();

// REST paths that are public and do not require authentication
restConfigs.put(KsqlRestConfig.AUTHENTICATION_SKIP_PATHS_CONFIG,
Joiner.on(",").join(authenticationSkipPaths));

return new KsqlRestConfig(restConfigs);
}

@VisibleForTesting
static Map<String, String> toClientProps(final Map<String, Object> config) {
final Map<String, String> clientProps = new HashMap<>();
Expand Down
17 changes: 10 additions & 7 deletions ksqldb-rest-app/src/test/java/io/confluent/ksql/api/AuthTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,7 @@ public void shouldAllowInfoWithPermissionCheck() throws Exception {

@Test
public void shouldAllowServiceMetadataIdWithoutAuthentication() throws Exception {
shouldAllowAccessWithoutAuthentication("GET",
"/v1/metadata/id", super::shouldExecuteServerMetadataIdRequest);
shouldAllowAccessWithoutAuthentication(super::shouldExecuteServerMetadataIdRequest);
}

@Test
Expand Down Expand Up @@ -545,29 +544,33 @@ private void throwIfNullPrincipal(final Principal user) {
}
}

private void shouldAllowAccessWithoutAuthentication(final String expectedMethod,
final String expectedPath, final ExceptionThrowingRunnable action) throws Exception {
private void shouldAllowAccessWithoutAuthentication(
final ExceptionThrowingRunnable action) throws Exception {
stopServer();
stopClient();
AtomicReference<Boolean> authorizationCallReference = new AtomicReference<>(false);
AtomicReference<Boolean> userContextCallReference = new AtomicReference<>(false);
this.authorizationProvider = (user, method, path) -> {
new KsqlException("Should not call authorization");
authorizationCallReference.set(true);
};
this.userContextProvider = new KsqlUserContextProvider() {
@Override
public ConfiguredKafkaClientSupplier getKafkaClientSupplier(Principal principal) {
new KsqlException("Should not call get kafka client supplier");
userContextCallReference.set(true);
return null;
}

@Override
public Supplier<SchemaRegistryClient> getSchemaRegistryClientFactory(Principal principal) {
new KsqlException("Should not call get schema registry client factory");
userContextCallReference.set(true);
return null;
}
};
createServer(createServerConfig());
client = createClient();
action.run();
assertThat("Should not call authorization", authorizationCallReference.get(), is(false));
assertThat("Should not call user context", userContextCallReference.get(), is(false));
}

private void shouldAllowAccessWithPermissionCheck(final String expectedUser,
Expand Down

0 comments on commit 807260d

Please sign in to comment.