diff --git a/src/main/java/io/cryostat/rules/RulesModule.java b/src/main/java/io/cryostat/rules/RulesModule.java index 6ba72f8d7a..186f00c059 100644 --- a/src/main/java/io/cryostat/rules/RulesModule.java +++ b/src/main/java/io/cryostat/rules/RulesModule.java @@ -16,11 +16,9 @@ package io.cryostat.rules; import java.io.IOException; -import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.util.concurrent.Executors; -import java.util.function.Function; import javax.inject.Named; import javax.inject.Singleton; @@ -30,13 +28,9 @@ import io.cryostat.configuration.ConfigurationModule; import io.cryostat.configuration.CredentialsManager; import io.cryostat.core.log.Logger; -import io.cryostat.core.net.Credentials; import io.cryostat.core.sys.FileSystem; import io.cryostat.discovery.DiscoveryStorage; -import io.cryostat.net.HttpServer; -import io.cryostat.net.NetworkConfiguration; import io.cryostat.net.TargetConnectionManager; -import io.cryostat.net.web.http.AbstractAuthenticatedRequestHandler; import io.cryostat.recordings.RecordingArchiveHelper; import io.cryostat.recordings.RecordingMetadataManager; import io.cryostat.recordings.RecordingOptionsBuilderFactory; @@ -46,17 +40,11 @@ import dagger.Lazy; import dagger.Module; import dagger.Provides; -import io.vertx.core.MultiMap; -import io.vertx.core.Vertx; -import io.vertx.ext.web.client.WebClient; -import io.vertx.ext.web.client.WebClientOptions; -import org.apache.commons.codec.binary.Base64; @Module public abstract class RulesModule { public static final String RULES_SUBDIRECTORY = "rules"; public static final String RULES_WEB_CLIENT = "RULES_WEB_CLIENT"; - public static final String RULES_HEADERS_FACTORY = "RULES_HEADERS_FACTORY"; @Provides @Singleton @@ -141,45 +129,7 @@ static RuleProcessor provideRuleProcessor( @Provides @Singleton - static PeriodicArchiverFactory providePeriodicArchivedFactory( - @Named(RULES_HEADERS_FACTORY) Function headersFactory, - Logger logger) { + static PeriodicArchiverFactory providePeriodicArchivedFactory(Logger logger) { return new PeriodicArchiverFactory(logger); } - - @Provides - @Singleton - @Named(RULES_WEB_CLIENT) - static WebClient provideRulesWebClient( - Vertx vertx, HttpServer server, NetworkConfiguration netConf) { - WebClientOptions opts = - new WebClientOptions() - .setSsl(server.isSsl()) - .setDefaultHost("localhost") - .setDefaultPort(netConf.getInternalWebServerPort()) - .setTrustAll(true) - .setVerifyHost(false); - return WebClient.create(vertx, opts); - } - - @Provides - @Named(RULES_HEADERS_FACTORY) - static Function provideRulesHeadersFactory() { - return credentials -> { - MultiMap headers = MultiMap.caseInsensitiveMultiMap(); - if (credentials != null) { - headers.add( - AbstractAuthenticatedRequestHandler.JMX_AUTHORIZATION_HEADER, - String.format( - "Basic %s", - Base64.encodeBase64String( - String.format( - "%s:%s", - credentials.getUsername(), - credentials.getPassword()) - .getBytes(StandardCharsets.UTF_8)))); - } - return headers; - }; - } } diff --git a/src/test/java/io/cryostat/rules/RulesHeadersFactoryTest.java b/src/test/java/io/cryostat/rules/RulesHeadersFactoryTest.java deleted file mode 100644 index 0a8933de3b..0000000000 --- a/src/test/java/io/cryostat/rules/RulesHeadersFactoryTest.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright The Cryostat Authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.cryostat.rules; - -import java.util.Map; -import java.util.function.Function; - -import io.cryostat.core.net.Credentials; -import io.cryostat.net.web.http.AbstractAuthenticatedRequestHandler; - -import io.vertx.core.MultiMap; -import org.apache.commons.codec.binary.Base64; -import org.hamcrest.MatcherAssert; -import org.hamcrest.Matchers; -import org.junit.jupiter.api.Test; - -class RulesHeadersFactoryTest { - - Function factory = RulesModule.provideRulesHeadersFactory(); - - @Test - void testNoHeaderAddedIfCredentialsAreNull() { - MultiMap result = factory.apply(null); - MatcherAssert.assertThat(result, Matchers.emptyIterable()); - } - - @Test - void ensureCorrectHeaderWhenCredentialsProvided() { - Credentials credentials = new Credentials("foouser", "barpassword"); - MultiMap result = factory.apply(credentials); - MatcherAssert.assertThat(result.size(), Matchers.is(1)); - Map.Entry header = result.entries().get(0); - MatcherAssert.assertThat( - header.getKey(), - Matchers.equalTo(AbstractAuthenticatedRequestHandler.JMX_AUTHORIZATION_HEADER)); - MatcherAssert.assertThat( - header.getValue(), - Matchers.equalTo( - "Basic " - + Base64.encodeBase64String( - (credentials.getUsername() - + ":" - + credentials.getPassword()) - .getBytes()))); - } -}