From 6bcde586922550f0cf93051c045ba04b9adaf5ae Mon Sep 17 00:00:00 2001 From: Andrew Azores Date: Sat, 22 Apr 2023 10:32:38 -0400 Subject: [PATCH] Revert "fix(credentials): store JMX session credentials in ThreadLocal (#1388)" This reverts commit 39695d073f587754069c933f0ddb8adbe97104bd. --- repeated-integration-tests.bash | 8 +- .../configuration/CredentialsManager.java | 24 -- .../io/cryostat/net/ConnectionDescriptor.java | 12 +- .../java/io/cryostat/net/NetworkModule.java | 5 +- .../net/openshift/OpenShiftNetworkModule.java | 6 +- .../io/cryostat/net/web/Vertexecutor.java | 99 -------- .../java/io/cryostat/net/web/WebModule.java | 10 - .../AbstractAuthenticatedRequestHandler.java | 3 - .../http/api/v2/AbstractV2RequestHandler.java | 5 - .../AbstractPermissionedDataFetcher.java | 82 +------ .../api/v2/graph/ActiveRecordingsFetcher.java | 5 +- .../graph/AllArchivedRecordingsFetcher.java | 8 +- .../api/v2/graph/ArchiveRecordingMutator.java | 16 +- .../v2/graph/ArchivedRecordingsFetcher.java | 5 +- .../graph/DeleteActiveRecordingMutator.java | 16 +- .../graph/DeleteArchivedRecordingMutator.java | 7 +- .../graph/EnvironmentNodeChildrenFetcher.java | 5 +- .../api/v2/graph/EnvironmentNodesFetcher.java | 8 +- .../web/http/api/v2/graph/GraphModule.java | 101 +++----- .../api/v2/graph/MBeanMetricsFetcher.java | 21 +- .../web/http/api/v2/graph/NodeFetcher.java | 8 +- .../PutActiveRecordingMetadataMutator.java | 11 +- .../PutArchivedRecordingMetadataMutator.java | 7 +- .../http/api/v2/graph/RecordingsFetcher.java | 14 +- .../http/api/v2/graph/RootNodeFetcher.java | 6 +- .../api/v2/graph/SnapshotOnTargetMutator.java | 22 +- .../graph/StartRecordingOnTargetMutator.java | 17 +- .../api/v2/graph/StopRecordingMutator.java | 13 +- .../v2/graph/TargetNodeRecurseFetcher.java | 7 +- .../http/api/v2/graph/TargetNodesFetcher.java | 7 +- .../internal/KubeApiPlatformStrategy.java | 7 +- .../internal/OpenShiftPlatformStrategy.java | 5 +- .../internal/PlatformStrategyModule.java | 10 +- .../io/cryostat/recordings/JvmIdHelper.java | 25 +- .../cryostat/recordings/RecordingsModule.java | 8 +- ...adLocalPropagatingPoolExecutorService.java | 78 ------ src/main/resources/types.graphqls | 9 +- .../api/v2/AbstractV2RequestHandlerTest.java | 3 +- .../AbstractPermissionedDataFetcherTest.java | 8 +- .../v2/graph/ActiveRecordingsFetcherTest.java | 4 +- .../AllArchivedRecordingsFetcherTest.java | 5 +- .../v2/graph/ArchiveRecordingMutatorTest.java | 10 +- .../graph/ArchivedRecordingsFetcherTest.java | 4 +- .../DeleteActiveRecordingMutatorTest.java | 10 +- .../DeleteArchivedRecordingMutatorTest.java | 6 +- .../EnvironmentNodeChildrenFetcherTest.java | 4 +- .../v2/graph/EnvironmentNodesFetcherTest.java | 4 +- .../http/api/v2/graph/NodeFetcherTest.java | 4 +- .../api/v2/graph/RecordingsFetcherTest.java | 18 +- .../api/v2/graph/RootNodeFetcherTest.java | 4 +- .../v2/graph/SnapshotOnTargetMutatorTest.java | 10 +- .../StartRecordingOnTargetMutatorTest.java | 10 +- .../v2/graph/StopRecordingMutatorTest.java | 10 +- .../graph/TargetNodeRecurseFetcherTest.java | 20 +- .../api/v2/graph/TargetNodesFetcherTest.java | 30 +-- src/test/java/itest/AutoRulesCleanupIT.java | 3 - src/test/java/itest/CredentialsV2_2IT.java | 3 + .../InterleavedExternalTargetRequestsIT.java | 225 ++++++++---------- .../{JmxSessionAuthIT.java => JmxAuthIT.java} | 87 +------ .../resources/JmxSessionAuthIT.query.graphql | 11 - 60 files changed, 272 insertions(+), 921 deletions(-) delete mode 100644 src/main/java/io/cryostat/net/web/Vertexecutor.java delete mode 100644 src/main/java/io/cryostat/sys/ThreadLocalPropagatingPoolExecutorService.java rename src/test/java/itest/{JmxSessionAuthIT.java => JmxAuthIT.java} (63%) delete mode 100644 src/test/resources/JmxSessionAuthIT.query.graphql diff --git a/repeated-integration-tests.bash b/repeated-integration-tests.bash index 4c7d758bfb..4c0689c6ae 100755 --- a/repeated-integration-tests.bash +++ b/repeated-integration-tests.bash @@ -17,7 +17,7 @@ fi getPomProperty() { if command -v xpath > /dev/null 2>&1 ; then - xpath -q -e "project/$1/text()" pom.xml + xpath -q -e "project/properties/$1/text()" pom.xml elif command -v mvnd > /dev/null 2>&1 ; then mvnd help:evaluate -o -B -q -DforceStdout -Dexpression="$1" else @@ -26,15 +26,15 @@ getPomProperty() { } if [ -z "${POD_NAME}" ]; then - POD_NAME="$(getPomProperty properties/cryostat.itest.podName)" + POD_NAME="$(getPomProperty cryostat.itest.podName)" fi if [ -z "${CONTAINER_NAME}" ]; then - CONTAINER_NAME="$(getPomProperty properties/cryostat.itest.containerName)" + CONTAINER_NAME="$(getPomProperty cryostat.itest.containerName)" fi if [ -z "${ITEST_IMG_VERSION}" ]; then - ITEST_IMG_VERSION="$(getPomProperty version)" + ITEST_IMG_VERSION="$(getPomProperty project.version)" ITEST_IMG_VERSION="${ITEST_IMG_VERSION,,}" # lowercase fi diff --git a/src/main/java/io/cryostat/configuration/CredentialsManager.java b/src/main/java/io/cryostat/configuration/CredentialsManager.java index dd0f29e446..78110ff598 100644 --- a/src/main/java/io/cryostat/configuration/CredentialsManager.java +++ b/src/main/java/io/cryostat/configuration/CredentialsManager.java @@ -80,9 +80,6 @@ public class CredentialsManager private final Gson gson; private final Logger logger; - public static final ThreadLocal> SESSION_CREDENTIALS = - ThreadLocal.withInitial(() -> new HashMap<>()); - CredentialsManager( Path credentialsDir, MatchExpressionValidator matchExpressionValidator, @@ -184,23 +181,7 @@ public int removeCredentials(String matchExpression) throws MatchExpressionValid return -1; } - public void setSessionCredentials(String targetId, Credentials credentials) { - if (credentials == null) { - SESSION_CREDENTIALS.get().remove(targetId); - } else { - SESSION_CREDENTIALS.get().put(targetId, credentials); - } - } - - public Credentials getSessionCredentials(String targetId) { - return SESSION_CREDENTIALS.get().get(targetId); - } - public Credentials getCredentialsByTargetId(String targetId) throws ScriptException { - Credentials sessionCredentials = getSessionCredentials(targetId); - if (sessionCredentials != null) { - return sessionCredentials; - } for (ServiceRef service : this.platformClient.listDiscoverableServices()) { if (Objects.equals(targetId, service.getServiceUri().toString())) { return getCredentials(service); @@ -210,11 +191,6 @@ public Credentials getCredentialsByTargetId(String targetId) throws ScriptExcept } public Credentials getCredentials(ServiceRef serviceRef) throws ScriptException { - Credentials sessionCredentials = - getSessionCredentials(serviceRef.getServiceUri().toString()); - if (sessionCredentials != null) { - return sessionCredentials; - } for (StoredCredentials sc : dao.getAll()) { if (matchExpressionEvaluator.get().applies(sc.getMatchExpression(), serviceRef)) { return sc.getCredentials(); diff --git a/src/main/java/io/cryostat/net/ConnectionDescriptor.java b/src/main/java/io/cryostat/net/ConnectionDescriptor.java index 27d51acde2..d6d2c335e0 100644 --- a/src/main/java/io/cryostat/net/ConnectionDescriptor.java +++ b/src/main/java/io/cryostat/net/ConnectionDescriptor.java @@ -39,7 +39,6 @@ import java.util.Optional; -import io.cryostat.configuration.CredentialsManager; import io.cryostat.core.net.Credentials; import io.cryostat.platform.ServiceRef; @@ -55,19 +54,12 @@ public ConnectionDescriptor(ServiceRef serviceRef) { this(serviceRef.getServiceUri().toString()); } - // TODO remove this constructor, all descriptors should explicitly specify any credentials public ConnectionDescriptor(String targetId) { - this(targetId, CredentialsManager.SESSION_CREDENTIALS.get().get(targetId)); + this(targetId, null); } public ConnectionDescriptor(ServiceRef serviceRef, Credentials credentials) { - this( - serviceRef.getServiceUri().toString(), - Optional.ofNullable( - CredentialsManager.SESSION_CREDENTIALS - .get() - .get(serviceRef.getServiceUri().toString())) - .orElse(credentials)); + this(serviceRef.getServiceUri().toString(), credentials); } public ConnectionDescriptor(String targetId, Credentials credentials) { diff --git a/src/main/java/io/cryostat/net/NetworkModule.java b/src/main/java/io/cryostat/net/NetworkModule.java index 35cc69eb25..30867499a3 100644 --- a/src/main/java/io/cryostat/net/NetworkModule.java +++ b/src/main/java/io/cryostat/net/NetworkModule.java @@ -41,7 +41,7 @@ import java.net.UnknownHostException; import java.nio.file.Path; import java.time.Duration; -import java.util.concurrent.ExecutorService; +import java.util.concurrent.ForkJoinPool; import javax.inject.Named; import javax.inject.Singleton; @@ -144,13 +144,12 @@ static TargetConnectionManager provideTargetConnectionManager( DiscoveryStorage storage, @Named(Variables.TARGET_CACHE_TTL) Duration maxTargetTtl, @Named(Variables.TARGET_MAX_CONCURRENT_CONNECTIONS) int maxTargetConnections, - @Named(WebModule.VERTX_EXECUTOR) ExecutorService executor, Logger logger) { return new TargetConnectionManager( connectionToolkit, agentConnectionFactory, storage, - executor, + ForkJoinPool.commonPool(), Scheduler.systemScheduler(), maxTargetTtl, maxTargetConnections, diff --git a/src/main/java/io/cryostat/net/openshift/OpenShiftNetworkModule.java b/src/main/java/io/cryostat/net/openshift/OpenShiftNetworkModule.java index b6060f8c9b..060acf1772 100644 --- a/src/main/java/io/cryostat/net/openshift/OpenShiftNetworkModule.java +++ b/src/main/java/io/cryostat/net/openshift/OpenShiftNetworkModule.java @@ -40,7 +40,7 @@ import java.io.BufferedReader; import java.io.IOException; import java.nio.file.Paths; -import java.util.concurrent.ExecutorService; +import java.util.concurrent.ForkJoinPool; import java.util.function.Function; import javax.inject.Named; @@ -50,7 +50,6 @@ import io.cryostat.core.sys.Environment; import io.cryostat.core.sys.FileSystem; import io.cryostat.net.AuthManager; -import io.cryostat.net.web.WebModule; import io.cryostat.util.resource.ClassPropertiesLoader; import com.github.benmanes.caffeine.cache.Scheduler; @@ -123,7 +122,6 @@ static OpenShiftClient provideServiceAccountClient( @Singleton static OpenShiftAuthManager provideOpenShiftAuthManager( Environment env, - @Named(WebModule.VERTX_EXECUTOR) ExecutorService executor, @Named(OPENSHIFT_NAMESPACE) Lazy namespace, Lazy serviceAccountClient, @Named(TOKENED_CLIENT) Function clientProvider, @@ -137,7 +135,7 @@ static OpenShiftAuthManager provideOpenShiftAuthManager( clientProvider, classPropertiesLoader, gson, - executor, + ForkJoinPool.commonPool(), Scheduler.systemScheduler(), logger); } diff --git a/src/main/java/io/cryostat/net/web/Vertexecutor.java b/src/main/java/io/cryostat/net/web/Vertexecutor.java deleted file mode 100644 index 35cb0d07ca..0000000000 --- a/src/main/java/io/cryostat/net/web/Vertexecutor.java +++ /dev/null @@ -1,99 +0,0 @@ -package io.cryostat.net.web; -/* - * Copyright The Cryostat Authors - * - * The Universal Permissive License (UPL), Version 1.0 - * - * Subject to the condition set forth below, permission is hereby granted to any - * person obtaining a copy of this software, associated documentation and/or data - * (collectively the "Software"), free of charge and under any and all copyright - * rights in the Software, and any and all patent rights owned or freely - * licensable by each licensor hereunder covering either (i) the unmodified - * Software as contributed to or provided by such licensor, or (ii) the Larger - * Works (as defined below), to deal in both - * - * (a) the Software, and - * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if - * one is included with the Software (each a "Larger Work" to which the Software - * is contributed by such licensors), - * - * without restriction, including without limitation the rights to copy, create - * derivative works of, display, perform, and distribute the Software and make, - * use, sell, offer for sale, import, export, have made, and have sold the - * Software and the Larger Work(s), and to sublicense the foregoing rights on - * either these or other terms. - * - * This license is subject to the following condition: - * The above copyright notice and either this complete permission notice or at - * a minimum a reference to the UPL must be included in all copies or - * substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -import java.util.List; -import java.util.concurrent.AbstractExecutorService; -import java.util.concurrent.TimeUnit; - -import io.cryostat.core.log.Logger; - -import io.vertx.core.Vertx; - -public class Vertexecutor extends AbstractExecutorService { - - private final Vertx vertx; - private final Logger logger; - - Vertexecutor(Vertx vertx, Logger logger) { - this.vertx = vertx; - this.logger = logger; - } - - @Override - public void execute(Runnable command) { - vertx.executeBlocking( - promise -> { - try { - command.run(); - promise.complete(); - } catch (Exception e) { - promise.fail(e); - } - }, - false, - ar -> { - if (ar.failed()) { - logger.warn("Async task failure", ar.cause()); - } - }); - } - - @Override - public void shutdown() {} - - @Override - public List shutdownNow() { - return List.of(); - } - - @Override - public boolean isShutdown() { - return false; - } - - @Override - public boolean isTerminated() { - return false; - } - - @Override - public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException { - return false; - } -} diff --git a/src/main/java/io/cryostat/net/web/WebModule.java b/src/main/java/io/cryostat/net/web/WebModule.java index 0447135f12..866c1d7646 100644 --- a/src/main/java/io/cryostat/net/web/WebModule.java +++ b/src/main/java/io/cryostat/net/web/WebModule.java @@ -40,7 +40,6 @@ import java.io.IOException; import java.nio.file.Path; import java.util.Set; -import java.util.concurrent.ExecutorService; import javax.inject.Named; import javax.inject.Singleton; @@ -57,12 +56,10 @@ import com.google.gson.Gson; import dagger.Module; import dagger.Provides; -import io.vertx.core.Vertx; @Module(includes = {HttpModule.class}) public abstract class WebModule { public static final String WEBSERVER_TEMP_DIR_PATH = "WEBSERVER_TEMP_DIR_PATH"; - public static final String VERTX_EXECUTOR = "VERTX_EXECUTOR"; @Provides static WebServer provideWebServer( @@ -93,11 +90,4 @@ static Path provideWebServerTempDirPath(FileSystem fs) { throw new RuntimeException(ioe); } } - - @Provides - @Singleton - @Named(VERTX_EXECUTOR) - static ExecutorService provideVertexecutor(Vertx vertx, Logger logger) { - return new Vertexecutor(vertx, logger); - } } diff --git a/src/main/java/io/cryostat/net/web/http/AbstractAuthenticatedRequestHandler.java b/src/main/java/io/cryostat/net/web/http/AbstractAuthenticatedRequestHandler.java index 016746fce3..d4e341669d 100644 --- a/src/main/java/io/cryostat/net/web/http/AbstractAuthenticatedRequestHandler.java +++ b/src/main/java/io/cryostat/net/web/http/AbstractAuthenticatedRequestHandler.java @@ -156,9 +156,6 @@ protected ConnectionDescriptor getConnectionDescriptorFromContext(RoutingContext 427, "Unrecognized " + JMX_AUTHORIZATION_HEADER + " credential format"); } credentials = new Credentials(parts[0], parts[1]); - credentialsManager.setSessionCredentials(targetId, credentials); - ctx.addEndHandler( - unused -> credentialsManager.setSessionCredentials(targetId, null)); } else { credentials = credentialsManager.getCredentialsByTargetId(targetId); } diff --git a/src/main/java/io/cryostat/net/web/http/api/v2/AbstractV2RequestHandler.java b/src/main/java/io/cryostat/net/web/http/api/v2/AbstractV2RequestHandler.java index 07a852397d..0ab1546065 100644 --- a/src/main/java/io/cryostat/net/web/http/api/v2/AbstractV2RequestHandler.java +++ b/src/main/java/io/cryostat/net/web/http/api/v2/AbstractV2RequestHandler.java @@ -94,10 +94,6 @@ public abstract IntermediateResponse handle(RequestParameters requestParams) @Override public final void handle(RoutingContext ctx) { RequestParameters requestParams = RequestParameters.from(ctx); - String targetId = requestParams.getPathParams().get("targetId"); - if (targetId != null) { - ctx.addEndHandler(unused -> credentialsManager.setSessionCredentials(targetId, null)); - } try { if (requiresAuthentication()) { boolean permissionGranted = @@ -168,7 +164,6 @@ protected ConnectionDescriptor getConnectionDescriptorFromParams(RequestParamete + " credential format"); } credentials = new Credentials(parts[0], parts[1]); - credentialsManager.setSessionCredentials(targetId, credentials); } } } else { diff --git a/src/main/java/io/cryostat/net/web/http/api/v2/graph/AbstractPermissionedDataFetcher.java b/src/main/java/io/cryostat/net/web/http/api/v2/graph/AbstractPermissionedDataFetcher.java index 196e72ae6b..5a50577a4e 100644 --- a/src/main/java/io/cryostat/net/web/http/api/v2/graph/AbstractPermissionedDataFetcher.java +++ b/src/main/java/io/cryostat/net/web/http/api/v2/graph/AbstractPermissionedDataFetcher.java @@ -37,35 +37,24 @@ */ package io.cryostat.net.web.http.api.v2.graph; -import java.nio.charset.StandardCharsets; -import java.util.Base64; -import java.util.Optional; import java.util.Set; -import java.util.regex.Matcher; -import io.cryostat.configuration.CredentialsManager; -import io.cryostat.core.net.Credentials; import io.cryostat.net.AuthManager; import io.cryostat.net.AuthorizationErrorException; import io.cryostat.net.security.PermissionedAction; -import io.cryostat.net.web.http.AbstractAuthenticatedRequestHandler; -import io.cryostat.net.web.http.api.v2.ApiException; import graphql.GraphQLContext; import graphql.schema.DataFetcher; import graphql.schema.DataFetchingEnvironment; import io.vertx.core.http.HttpHeaders; import io.vertx.ext.web.RoutingContext; -import io.vertx.ext.web.handler.graphql.GraphQLHandler; abstract class AbstractPermissionedDataFetcher implements DataFetcher, PermissionedAction { protected final AuthManager auth; - protected final CredentialsManager credentialsManager; - AbstractPermissionedDataFetcher(AuthManager auth, CredentialsManager credentialsManager) { + AbstractPermissionedDataFetcher(AuthManager auth) { this.auth = auth; - this.credentialsManager = credentialsManager; } abstract Set applicableContexts(); @@ -92,73 +81,4 @@ public final T get(DataFetchingEnvironment environment) throws Exception { } abstract T getAuthenticated(DataFetchingEnvironment environment) throws Exception; - - // FIXME targetId should not be supplied, this method should either figure it out from context, - // or the X-JMX-Authorization header should actually have a value that encodes a map from - // targetId to credentials - protected Optional getSessionCredentials( - DataFetchingEnvironment environment, String targetId) { - RoutingContext ctx = GraphQLHandler.getRoutingContext(environment.getGraphQlContext()); - if (!ctx.request() - .headers() - .contains(AbstractAuthenticatedRequestHandler.JMX_AUTHORIZATION_HEADER)) { - return Optional.empty(); - } - String proxyAuth = - ctx.request() - .getHeader(AbstractAuthenticatedRequestHandler.JMX_AUTHORIZATION_HEADER); - Matcher m = AbstractAuthenticatedRequestHandler.AUTH_HEADER_PATTERN.matcher(proxyAuth); - if (!m.find()) { - ctx.response() - .putHeader( - AbstractAuthenticatedRequestHandler.JMX_AUTHENTICATE_HEADER, "Basic"); - throw new ApiException( - 427, - "Invalid " - + AbstractAuthenticatedRequestHandler.JMX_AUTHORIZATION_HEADER - + " format"); - } - String t = m.group("type"); - if (!"basic".equals(t.toLowerCase())) { - ctx.response() - .putHeader( - AbstractAuthenticatedRequestHandler.JMX_AUTHENTICATE_HEADER, "Basic"); - throw new ApiException( - 427, - "Unacceptable " - + AbstractAuthenticatedRequestHandler.JMX_AUTHORIZATION_HEADER - + " type"); - } - String c; - try { - c = - new String( - Base64.getUrlDecoder().decode(m.group("credentials")), - StandardCharsets.UTF_8); - } catch (IllegalArgumentException iae) { - ctx.response() - .putHeader( - AbstractAuthenticatedRequestHandler.JMX_AUTHENTICATE_HEADER, "Basic"); - throw new ApiException( - 427, - AbstractAuthenticatedRequestHandler.JMX_AUTHORIZATION_HEADER - + " credentials do not appear to be Base64-encoded", - iae); - } - String[] parts = c.split(":"); - if (parts.length != 2) { - ctx.response() - .putHeader( - AbstractAuthenticatedRequestHandler.JMX_AUTHENTICATE_HEADER, "Basic"); - throw new ApiException( - 427, - "Unrecognized " - + AbstractAuthenticatedRequestHandler.JMX_AUTHORIZATION_HEADER - + " credential format"); - } - Credentials credentials = new Credentials(parts[0], parts[1]); - credentialsManager.setSessionCredentials(targetId, credentials); - ctx.addEndHandler(unused -> credentialsManager.setSessionCredentials(targetId, null)); - return Optional.of(credentials); - } } diff --git a/src/main/java/io/cryostat/net/web/http/api/v2/graph/ActiveRecordingsFetcher.java b/src/main/java/io/cryostat/net/web/http/api/v2/graph/ActiveRecordingsFetcher.java index 738e4440ee..1fcefce100 100644 --- a/src/main/java/io/cryostat/net/web/http/api/v2/graph/ActiveRecordingsFetcher.java +++ b/src/main/java/io/cryostat/net/web/http/api/v2/graph/ActiveRecordingsFetcher.java @@ -46,7 +46,6 @@ import javax.inject.Inject; -import io.cryostat.configuration.CredentialsManager; import io.cryostat.net.AuthManager; import io.cryostat.net.security.ResourceAction; import io.cryostat.net.web.http.api.v2.graph.ActiveRecordingsFetcher.Active; @@ -64,8 +63,8 @@ class ActiveRecordingsFetcher extends AbstractPermissionedDataFetcher { @Inject - ActiveRecordingsFetcher(AuthManager auth, CredentialsManager credentialsManager) { - super(auth, credentialsManager); + ActiveRecordingsFetcher(AuthManager auth) { + super(auth); } @Override diff --git a/src/main/java/io/cryostat/net/web/http/api/v2/graph/AllArchivedRecordingsFetcher.java b/src/main/java/io/cryostat/net/web/http/api/v2/graph/AllArchivedRecordingsFetcher.java index 6685eb0367..2d59f8cb33 100644 --- a/src/main/java/io/cryostat/net/web/http/api/v2/graph/AllArchivedRecordingsFetcher.java +++ b/src/main/java/io/cryostat/net/web/http/api/v2/graph/AllArchivedRecordingsFetcher.java @@ -47,7 +47,6 @@ import javax.inject.Inject; -import io.cryostat.configuration.CredentialsManager; import io.cryostat.core.log.Logger; import io.cryostat.net.AuthManager; import io.cryostat.net.security.ResourceAction; @@ -66,11 +65,8 @@ class AllArchivedRecordingsFetcher extends AbstractPermissionedDataFetcher { private final RecordingArchiveHelper recordingArchiveHelper; + private final CredentialsManager credentialsManager; @Inject ArchiveRecordingMutator( AuthManager auth, - CredentialsManager credentialsManager, - RecordingArchiveHelper recordingArchiveHelper) { - super(auth, credentialsManager); + RecordingArchiveHelper recordingArchiveHelper, + CredentialsManager credentialsManager) { + super(auth); this.recordingArchiveHelper = recordingArchiveHelper; + this.credentialsManager = credentialsManager; } @Override @@ -91,11 +92,8 @@ public ArchivedRecordingInfo getAuthenticated(DataFetchingEnvironment environmen GraphRecordingDescriptor source = environment.getSource(); ServiceRef target = source.target; String uri = target.getServiceUri().toString(); - - Credentials credentials = - getSessionCredentials(environment, uri.toString()) - .orElse(credentialsManager.getCredentials(target)); - ConnectionDescriptor cd = new ConnectionDescriptor(uri, credentials); + ConnectionDescriptor cd = + new ConnectionDescriptor(uri, credentialsManager.getCredentials(target)); return recordingArchiveHelper.saveRecording(cd, source.getName()).get(); } diff --git a/src/main/java/io/cryostat/net/web/http/api/v2/graph/ArchivedRecordingsFetcher.java b/src/main/java/io/cryostat/net/web/http/api/v2/graph/ArchivedRecordingsFetcher.java index f30be8553f..f8ef1a42ec 100644 --- a/src/main/java/io/cryostat/net/web/http/api/v2/graph/ArchivedRecordingsFetcher.java +++ b/src/main/java/io/cryostat/net/web/http/api/v2/graph/ArchivedRecordingsFetcher.java @@ -46,7 +46,6 @@ import javax.inject.Inject; -import io.cryostat.configuration.CredentialsManager; import io.cryostat.net.AuthManager; import io.cryostat.net.security.ResourceAction; import io.cryostat.net.web.http.api.v2.graph.ArchivedRecordingsFetcher.Archived; @@ -65,8 +64,8 @@ class ArchivedRecordingsFetcher extends AbstractPermissionedDataFetcher { @Inject - ArchivedRecordingsFetcher(AuthManager auth, CredentialsManager credentialsManager) { - super(auth, credentialsManager); + ArchivedRecordingsFetcher(AuthManager auth) { + super(auth); } @Override diff --git a/src/main/java/io/cryostat/net/web/http/api/v2/graph/DeleteActiveRecordingMutator.java b/src/main/java/io/cryostat/net/web/http/api/v2/graph/DeleteActiveRecordingMutator.java index e48b9d9ab7..93dcc7f14c 100644 --- a/src/main/java/io/cryostat/net/web/http/api/v2/graph/DeleteActiveRecordingMutator.java +++ b/src/main/java/io/cryostat/net/web/http/api/v2/graph/DeleteActiveRecordingMutator.java @@ -43,7 +43,6 @@ import javax.inject.Inject; import io.cryostat.configuration.CredentialsManager; -import io.cryostat.core.net.Credentials; import io.cryostat.net.AuthManager; import io.cryostat.net.ConnectionDescriptor; import io.cryostat.net.security.ResourceAction; @@ -56,14 +55,16 @@ class DeleteActiveRecordingMutator extends AbstractPermissionedDataFetcher { private final RecordingTargetHelper recordingTargetHelper; + private final CredentialsManager credentialsManager; @Inject DeleteActiveRecordingMutator( AuthManager auth, - CredentialsManager credentialsManager, - RecordingTargetHelper recordingTargetHelper) { - super(auth, credentialsManager); + RecordingTargetHelper recordingTargetHelper, + CredentialsManager credentialsManager) { + super(auth); this.recordingTargetHelper = recordingTargetHelper; + this.credentialsManager = credentialsManager; } @Override @@ -91,11 +92,8 @@ public GraphRecordingDescriptor getAuthenticated(DataFetchingEnvironment environ GraphRecordingDescriptor source = environment.getSource(); ServiceRef target = source.target; String uri = target.getServiceUri().toString(); - - Credentials credentials = - getSessionCredentials(environment, uri.toString()) - .orElse(credentialsManager.getCredentials(target)); - ConnectionDescriptor cd = new ConnectionDescriptor(uri, credentials); + ConnectionDescriptor cd = + new ConnectionDescriptor(uri, credentialsManager.getCredentials(target)); recordingTargetHelper.deleteRecording(cd, source.getName()).get(); return source; diff --git a/src/main/java/io/cryostat/net/web/http/api/v2/graph/DeleteArchivedRecordingMutator.java b/src/main/java/io/cryostat/net/web/http/api/v2/graph/DeleteArchivedRecordingMutator.java index 201feff5ef..f84c7ab938 100644 --- a/src/main/java/io/cryostat/net/web/http/api/v2/graph/DeleteArchivedRecordingMutator.java +++ b/src/main/java/io/cryostat/net/web/http/api/v2/graph/DeleteArchivedRecordingMutator.java @@ -42,7 +42,6 @@ import javax.inject.Inject; -import io.cryostat.configuration.CredentialsManager; import io.cryostat.net.AuthManager; import io.cryostat.net.security.ResourceAction; import io.cryostat.recordings.RecordingArchiveHelper; @@ -57,10 +56,8 @@ class DeleteArchivedRecordingMutator @Inject DeleteArchivedRecordingMutator( - AuthManager auth, - CredentialsManager credentialsManager, - RecordingArchiveHelper recordingArchiveHelper) { - super(auth, credentialsManager); + AuthManager auth, RecordingArchiveHelper recordingArchiveHelper) { + super(auth); this.recordingArchiveHelper = recordingArchiveHelper; } diff --git a/src/main/java/io/cryostat/net/web/http/api/v2/graph/EnvironmentNodeChildrenFetcher.java b/src/main/java/io/cryostat/net/web/http/api/v2/graph/EnvironmentNodeChildrenFetcher.java index bf981090d5..34b93242c1 100644 --- a/src/main/java/io/cryostat/net/web/http/api/v2/graph/EnvironmentNodeChildrenFetcher.java +++ b/src/main/java/io/cryostat/net/web/http/api/v2/graph/EnvironmentNodeChildrenFetcher.java @@ -44,7 +44,6 @@ import javax.inject.Inject; -import io.cryostat.configuration.CredentialsManager; import io.cryostat.net.AuthManager; import io.cryostat.net.security.ResourceAction; import io.cryostat.platform.discovery.AbstractNode; @@ -55,8 +54,8 @@ class EnvironmentNodeChildrenFetcher extends AbstractPermissionedDataFetcher> { @Inject - EnvironmentNodeChildrenFetcher(AuthManager auth, CredentialsManager credentialsManager) { - super(auth, credentialsManager); + EnvironmentNodeChildrenFetcher(AuthManager auth) { + super(auth); } @Override diff --git a/src/main/java/io/cryostat/net/web/http/api/v2/graph/EnvironmentNodesFetcher.java b/src/main/java/io/cryostat/net/web/http/api/v2/graph/EnvironmentNodesFetcher.java index 8b88477544..1cbca95301 100644 --- a/src/main/java/io/cryostat/net/web/http/api/v2/graph/EnvironmentNodesFetcher.java +++ b/src/main/java/io/cryostat/net/web/http/api/v2/graph/EnvironmentNodesFetcher.java @@ -48,7 +48,6 @@ import javax.inject.Inject; -import io.cryostat.configuration.CredentialsManager; import io.cryostat.net.AuthManager; import io.cryostat.net.security.ResourceAction; import io.cryostat.net.web.http.api.v2.graph.labels.LabelSelectorMatcher; @@ -62,11 +61,8 @@ class EnvironmentNodesFetcher extends AbstractPermissionedDataFetcher> fetchers, Set resolvers) { - Executor executor = - new ThreadLocalPropagatingPoolExecutorService<>( - CredentialsManager.SESSION_CREDENTIALS::get, - CredentialsManager.SESSION_CREDENTIALS::set, - CredentialsManager.SESSION_CREDENTIALS::remove); RuntimeWiring.Builder wiringBuilder = RuntimeWiring.newRuntimeWiring() .scalar(ExtendedScalars.Object) @@ -128,7 +121,7 @@ static GraphQL provideGraphQL( for (String ctx : fetcher.applicableContexts()) { DataFetcher df = fetcher; if (fetcher.blocking()) { - df = AsyncDataFetcher.async(df, executor); + df = AsyncDataFetcher.async(df); } wiringBuilder = wiringBuilder.type( @@ -182,9 +175,8 @@ public PreparsedDocumentEntry getDocument( abstract AbstractTypeResolver bindRecordingResolver(RecordingTypeResolver typeResolver); @Provides - static RootNodeFetcher provideRootNodeFetcher( - AuthManager auth, CredentialsManager credentialsManager, DiscoveryStorage storage) { - return new RootNodeFetcher(auth, credentialsManager, storage); + static RootNodeFetcher provideRootNodeFetcher(AuthManager auth, DiscoveryStorage storage) { + return new RootNodeFetcher(auth, storage); } @Binds @@ -194,14 +186,14 @@ static RootNodeFetcher provideRootNodeFetcher( @Provides static RecordingsFetcher provideRecordingsFetcher( AuthManager auth, - CredentialsManager credentialsManager, TargetConnectionManager tcm, RecordingArchiveHelper archiveHelper, + CredentialsManager credentialsManager, RecordingMetadataManager metadataManager, Provider webServer, Logger logger) { return new RecordingsFetcher( - auth, credentialsManager, tcm, archiveHelper, metadataManager, webServer, logger); + auth, tcm, archiveHelper, credentialsManager, metadataManager, webServer, logger); } @Binds @@ -209,9 +201,8 @@ static RecordingsFetcher provideRecordingsFetcher( abstract AbstractPermissionedDataFetcher bindRecordingsFetcher(RecordingsFetcher apdf); @Provides - static ActiveRecordingsFetcher provideActiveRecordingsFetcher( - AuthManager auth, CredentialsManager credentialsManager) { - return new ActiveRecordingsFetcher(auth, credentialsManager); + static ActiveRecordingsFetcher provideActiveRecordingsFetcher(AuthManager auth) { + return new ActiveRecordingsFetcher(auth); } @Binds @@ -221,12 +212,8 @@ abstract AbstractPermissionedDataFetcher bindActiveRecordingsFetcher( @Provides static AllArchivedRecordingsFetcher provideAllArchivedRecordingsFetcher( - AuthManager auth, - CredentialsManager credentialsManager, - RecordingArchiveHelper recordingArchiveHelper, - Logger logger) { - return new AllArchivedRecordingsFetcher( - auth, credentialsManager, recordingArchiveHelper, logger); + AuthManager auth, RecordingArchiveHelper recordingArchiveHelper, Logger logger) { + return new AllArchivedRecordingsFetcher(auth, recordingArchiveHelper, logger); } @Binds @@ -235,9 +222,8 @@ abstract AbstractPermissionedDataFetcher bindAllArchivedRecordingsFetcher( AllArchivedRecordingsFetcher apdf); @Provides - static ArchivedRecordingsFetcher provideArchivedRecordingsFetcher( - AuthManager auth, CredentialsManager credentialsManager) { - return new ArchivedRecordingsFetcher(auth, credentialsManager); + static ArchivedRecordingsFetcher provideArchivedRecordingsFetcher(AuthManager auth) { + return new ArchivedRecordingsFetcher(auth); } @Binds @@ -246,9 +232,8 @@ abstract AbstractPermissionedDataFetcher bindArchivedRecordingsFetcher( ArchivedRecordingsFetcher apdf); @Provides - static EnvironmentNodeChildrenFetcher provideEnvironmentNodeChildrenFetcher( - AuthManager auth, CredentialsManager credentialsManager) { - return new EnvironmentNodeChildrenFetcher(auth, credentialsManager); + static EnvironmentNodeChildrenFetcher provideEnvironmentNodeChildrenFetcher(AuthManager auth) { + return new EnvironmentNodeChildrenFetcher(auth); } @Binds @@ -257,9 +242,8 @@ abstract AbstractPermissionedDataFetcher bindEnvironmentNodeChildrenFetcher( EnvironmentNodeChildrenFetcher apdf); @Provides - static TargetNodeRecurseFetcher provideTargetNodeRecurseFetcher( - AuthManager auth, CredentialsManager credentialsManager) { - return new TargetNodeRecurseFetcher(auth, credentialsManager); + static TargetNodeRecurseFetcher provideTargetNodeRecurseFetcher(AuthManager auth) { + return new TargetNodeRecurseFetcher(auth); } @Binds @@ -268,11 +252,8 @@ abstract AbstractPermissionedDataFetcher bindTargetNodeRecurseFetcher( TargetNodeRecurseFetcher apdf); @Provides - static NodeFetcher provideNodeFetcher( - AuthManager auth, - CredentialsManager credentialsManager, - RootNodeFetcher rootNodeFetcher) { - return new NodeFetcher(auth, credentialsManager, rootNodeFetcher); + static NodeFetcher provideNodeFetcher(AuthManager auth, RootNodeFetcher rootNodeFetcher) { + return new NodeFetcher(auth, rootNodeFetcher); } @Binds @@ -281,10 +262,8 @@ static NodeFetcher provideNodeFetcher( @Provides static EnvironmentNodesFetcher provideEnvironmentNodesFetcher( - AuthManager auth, - CredentialsManager credentialsManager, - RootNodeFetcher rootNodeFetcher) { - return new EnvironmentNodesFetcher(auth, credentialsManager, rootNodeFetcher); + AuthManager auth, RootNodeFetcher rootNodeFetcher) { + return new EnvironmentNodesFetcher(auth, rootNodeFetcher); } @Binds @@ -295,10 +274,9 @@ abstract AbstractPermissionedDataFetcher bindEnvironmentNodesFetcher( @Provides static TargetNodesFetcher provideTargetNodesFetcher( AuthManager auth, - CredentialsManager credentialsManager, RootNodeFetcher rootNodeFetcher, TargetNodeRecurseFetcher recurseFetcher) { - return new TargetNodesFetcher(auth, credentialsManager, rootNodeFetcher, recurseFetcher); + return new TargetNodesFetcher(auth, rootNodeFetcher, recurseFetcher); } @Binds @@ -308,19 +286,19 @@ static TargetNodesFetcher provideTargetNodesFetcher( @Provides static StartRecordingOnTargetMutator provideStartRecordingOnTargetMutator( AuthManager auth, - CredentialsManager credentialsManager, TargetConnectionManager targetConnectionManager, RecordingTargetHelper recordingTargetHelper, RecordingOptionsBuilderFactory recordingOptionsBuilderFactory, + CredentialsManager credentialsManager, RecordingMetadataManager metadataManager, Provider webServer, Gson gson) { return new StartRecordingOnTargetMutator( auth, - credentialsManager, targetConnectionManager, recordingTargetHelper, recordingOptionsBuilderFactory, + credentialsManager, metadataManager, webServer, gson); @@ -334,9 +312,9 @@ abstract AbstractPermissionedDataFetcher bindStartRecordingOnTargetMutator( @Provides static SnapshotOnTargetMutator provideSnapshotOnTargetMutator( AuthManager auth, - CredentialsManager credentialsManager, - RecordingTargetHelper recordingTargetHelper) { - return new SnapshotOnTargetMutator(auth, credentialsManager, recordingTargetHelper); + RecordingTargetHelper recordingTargetHelper, + CredentialsManager credentialsManager) { + return new SnapshotOnTargetMutator(auth, recordingTargetHelper, credentialsManager); } @Binds @@ -347,9 +325,9 @@ abstract AbstractPermissionedDataFetcher bindSnapshotOnTargetMutator( @Provides static ArchiveRecordingMutator provideArchiveRecordingMutator( AuthManager auth, - CredentialsManager credentialsManager, - RecordingArchiveHelper recordingArchiveHelper) { - return new ArchiveRecordingMutator(auth, credentialsManager, recordingArchiveHelper); + RecordingArchiveHelper recordingArchiveHelper, + CredentialsManager credentialsManager) { + return new ArchiveRecordingMutator(auth, recordingArchiveHelper, credentialsManager); } @Binds @@ -360,16 +338,16 @@ abstract AbstractPermissionedDataFetcher bindArchiveRecordingMutator( @Provides static StopRecordingMutator provideStopRecordingsOnTargetMutator( AuthManager auth, - CredentialsManager credentialsManager, TargetConnectionManager targetConnectionManager, RecordingTargetHelper recordingTargetHelper, + CredentialsManager credentialsManager, RecordingMetadataManager metadataManager, Provider webServer) { return new StopRecordingMutator( auth, - credentialsManager, targetConnectionManager, recordingTargetHelper, + credentialsManager, metadataManager, webServer); } @@ -405,13 +383,12 @@ abstract AbstractPermissionedDataFetcher bindPutActiveRecordingMetadataMutato @Provides static PutArchivedRecordingMetadataMutator providePutArchivedRecordingMetadataMutator( AuthManager auth, - CredentialsManager credentialsManager, RecordingMetadataManager metadataManager, Provider webServer, Gson gson, Base32 base32) { return new PutArchivedRecordingMetadataMutator( - auth, credentialsManager, metadataManager, webServer, gson, base32); + auth, metadataManager, webServer, gson, base32); } @Binds @@ -422,9 +399,9 @@ abstract AbstractPermissionedDataFetcher bindPutArchivedRecordingMetadataMuta @Provides static DeleteActiveRecordingMutator provideDeleteActiveRecordingMutator( AuthManager auth, - CredentialsManager credentialsManager, - RecordingTargetHelper recordingTargetHelper) { - return new DeleteActiveRecordingMutator(auth, credentialsManager, recordingTargetHelper); + RecordingTargetHelper recordingTargetHelper, + CredentialsManager credentialsManager) { + return new DeleteActiveRecordingMutator(auth, recordingTargetHelper, credentialsManager); } @Binds @@ -434,10 +411,8 @@ abstract AbstractPermissionedDataFetcher bindDeleteActiveRecordingMutator( @Provides static DeleteArchivedRecordingMutator provideDeleteArchivedRecordingMutator( - AuthManager auth, - CredentialsManager credentialsManager, - RecordingArchiveHelper recordingArchiveHelper) { - return new DeleteArchivedRecordingMutator(auth, credentialsManager, recordingArchiveHelper); + AuthManager auth, RecordingArchiveHelper recordingArchiveHelper) { + return new DeleteArchivedRecordingMutator(auth, recordingArchiveHelper); } @Binds @@ -448,10 +423,10 @@ abstract AbstractPermissionedDataFetcher bindDeleteArchivedRecordingMutator( @Provides static MBeanMetricsFetcher provideMBeanMetricsFetcher( AuthManager auth, - CredentialsManager credentialsManager, TargetConnectionManager tcm, + CredentialsManager credentialsManager, Logger logger) { - return new MBeanMetricsFetcher(auth, credentialsManager, tcm, logger); + return new MBeanMetricsFetcher(auth, tcm, credentialsManager, logger); } @Binds diff --git a/src/main/java/io/cryostat/net/web/http/api/v2/graph/MBeanMetricsFetcher.java b/src/main/java/io/cryostat/net/web/http/api/v2/graph/MBeanMetricsFetcher.java index 0d0d4e2c1a..5b7595d0d2 100644 --- a/src/main/java/io/cryostat/net/web/http/api/v2/graph/MBeanMetricsFetcher.java +++ b/src/main/java/io/cryostat/net/web/http/api/v2/graph/MBeanMetricsFetcher.java @@ -44,7 +44,6 @@ import io.cryostat.configuration.CredentialsManager; import io.cryostat.core.log.Logger; -import io.cryostat.core.net.Credentials; import io.cryostat.core.net.MBeanMetrics; import io.cryostat.net.AuthManager; import io.cryostat.net.ConnectionDescriptor; @@ -58,16 +57,18 @@ public class MBeanMetricsFetcher extends AbstractPermissionedDataFetcher { private final TargetConnectionManager tcm; + private final CredentialsManager credentialsManager; private final Logger logger; @Inject MBeanMetricsFetcher( AuthManager auth, - CredentialsManager credentialsManager, TargetConnectionManager tcm, + CredentialsManager credentialsManager, Logger logger) { - super(auth, credentialsManager); + super(auth); this.tcm = tcm; + this.credentialsManager = credentialsManager; this.logger = logger; } @@ -91,11 +92,13 @@ public MBeanMetrics getAuthenticated(DataFetchingEnvironment environment) throws TargetNode source = (TargetNode) environment.getSource(); ServiceRef target = source.getTarget(); String targetId = target.getServiceUri().toString(); - - Credentials credentials = - getSessionCredentials(environment, targetId) - .orElse(credentialsManager.getCredentials(target)); - ConnectionDescriptor cd = new ConnectionDescriptor(targetId, credentials); - return tcm.executeConnectedTask(cd, conn -> conn.getMBeanMetrics()); + ConnectionDescriptor cd = + new ConnectionDescriptor(targetId, credentialsManager.getCredentials(target)); + try { + return tcm.executeConnectedTask(cd, conn -> conn.getMBeanMetrics()); + } catch (Exception e) { + logger.warn(e); + return null; + } } } diff --git a/src/main/java/io/cryostat/net/web/http/api/v2/graph/NodeFetcher.java b/src/main/java/io/cryostat/net/web/http/api/v2/graph/NodeFetcher.java index abc86dfe6f..423d171139 100644 --- a/src/main/java/io/cryostat/net/web/http/api/v2/graph/NodeFetcher.java +++ b/src/main/java/io/cryostat/net/web/http/api/v2/graph/NodeFetcher.java @@ -44,7 +44,6 @@ import javax.inject.Inject; -import io.cryostat.configuration.CredentialsManager; import io.cryostat.net.AuthManager; import io.cryostat.net.security.ResourceAction; import io.cryostat.platform.discovery.AbstractNode; @@ -57,11 +56,8 @@ class NodeFetcher extends AbstractPermissionedDataFetcher { private final RootNodeFetcher rootNodeFetcher; @Inject - NodeFetcher( - AuthManager auth, - CredentialsManager credentialsManager, - RootNodeFetcher rootNodeFetcher) { - super(auth, credentialsManager); + NodeFetcher(AuthManager auth, RootNodeFetcher rootNodeFetcher) { + super(auth); this.rootNodeFetcher = rootNodeFetcher; } diff --git a/src/main/java/io/cryostat/net/web/http/api/v2/graph/PutActiveRecordingMetadataMutator.java b/src/main/java/io/cryostat/net/web/http/api/v2/graph/PutActiveRecordingMetadataMutator.java index 65582711ab..ffb215e0b4 100644 --- a/src/main/java/io/cryostat/net/web/http/api/v2/graph/PutActiveRecordingMetadataMutator.java +++ b/src/main/java/io/cryostat/net/web/http/api/v2/graph/PutActiveRecordingMetadataMutator.java @@ -48,7 +48,6 @@ import org.openjdk.jmc.rjmx.services.jfr.IRecordingDescriptor; import io.cryostat.configuration.CredentialsManager; -import io.cryostat.core.net.Credentials; import io.cryostat.jmc.serialization.HyperlinkedSerializableRecordingDescriptor; import io.cryostat.net.AuthManager; import io.cryostat.net.ConnectionDescriptor; @@ -67,6 +66,7 @@ class PutActiveRecordingMetadataMutator extends AbstractPermissionedDataFetcher { + private final CredentialsManager credentialsManager; private final TargetConnectionManager targetConnectionManager; private final RecordingMetadataManager metadataManager; private final RecordingTargetHelper recordingTargetHelper; @@ -82,7 +82,8 @@ class PutActiveRecordingMetadataMutator RecordingMetadataManager metadataManager, Provider webServer, Gson gson) { - super(auth, credentialsManager); + super(auth); + this.credentialsManager = credentialsManager; this.targetConnectionManager = targetConnectionManager; this.recordingTargetHelper = recordingTargetHelper; this.metadataManager = metadataManager; @@ -128,10 +129,8 @@ public HyperlinkedSerializableRecordingDescriptor getAuthenticated( } } - Credentials credentials = - getSessionCredentials(environment, uri.toString()) - .orElse(credentialsManager.getCredentials(target)); - ConnectionDescriptor cd = new ConnectionDescriptor(uri, credentials); + ConnectionDescriptor cd = + new ConnectionDescriptor(uri, credentialsManager.getCredentials(target)); return targetConnectionManager.executeConnectedTask( cd, diff --git a/src/main/java/io/cryostat/net/web/http/api/v2/graph/PutArchivedRecordingMetadataMutator.java b/src/main/java/io/cryostat/net/web/http/api/v2/graph/PutArchivedRecordingMetadataMutator.java index e681d34756..ae8e413ae5 100644 --- a/src/main/java/io/cryostat/net/web/http/api/v2/graph/PutArchivedRecordingMetadataMutator.java +++ b/src/main/java/io/cryostat/net/web/http/api/v2/graph/PutArchivedRecordingMetadataMutator.java @@ -45,7 +45,6 @@ import javax.inject.Inject; import javax.inject.Provider; -import io.cryostat.configuration.CredentialsManager; import io.cryostat.net.AuthManager; import io.cryostat.net.ConnectionDescriptor; import io.cryostat.net.security.ResourceAction; @@ -71,12 +70,11 @@ class PutArchivedRecordingMetadataMutator @Inject PutArchivedRecordingMetadataMutator( AuthManager auth, - CredentialsManager credentialsManager, RecordingMetadataManager metadataManager, Provider webServer, Gson gson, Base32 base32) { - super(auth, credentialsManager); + super(auth); this.metadataManager = metadataManager; this.webServer = webServer; this.gson = gson; @@ -121,8 +119,7 @@ public ArchivedRecordingInfo getAuthenticated(DataFetchingEnvironment environmen Metadata metadata = metadataManager .setRecordingMetadata( - new ConnectionDescriptor( - uri, credentialsManager.getCredentialsByTargetId(uri)), + new ConnectionDescriptor(uri), recordingName, new Metadata(labels), true) diff --git a/src/main/java/io/cryostat/net/web/http/api/v2/graph/RecordingsFetcher.java b/src/main/java/io/cryostat/net/web/http/api/v2/graph/RecordingsFetcher.java index cb7886c8e2..14894e28b3 100644 --- a/src/main/java/io/cryostat/net/web/http/api/v2/graph/RecordingsFetcher.java +++ b/src/main/java/io/cryostat/net/web/http/api/v2/graph/RecordingsFetcher.java @@ -53,7 +53,6 @@ import io.cryostat.configuration.CredentialsManager; import io.cryostat.core.log.Logger; -import io.cryostat.core.net.Credentials; import io.cryostat.net.AuthManager; import io.cryostat.net.ConnectionDescriptor; import io.cryostat.net.TargetConnectionManager; @@ -74,6 +73,7 @@ class RecordingsFetcher extends AbstractPermissionedDataFetcher { private final TargetConnectionManager targetConnectionManager; private final RecordingArchiveHelper archiveHelper; + private final CredentialsManager credentialsManager; private final RecordingMetadataManager metadataManager; private final Provider webServer; private final Logger logger; @@ -81,15 +81,16 @@ class RecordingsFetcher extends AbstractPermissionedDataFetcher { @Inject RecordingsFetcher( AuthManager auth, - CredentialsManager credentialsManager, TargetConnectionManager targetConnectionManager, RecordingArchiveHelper archiveHelper, + CredentialsManager credentialsManager, RecordingMetadataManager metadataManager, Provider webServer, Logger logger) { - super(auth, credentialsManager); + super(auth); this.targetConnectionManager = targetConnectionManager; this.archiveHelper = archiveHelper; + this.credentialsManager = credentialsManager; this.metadataManager = metadataManager; this.webServer = webServer; this.logger = logger; @@ -131,11 +132,8 @@ public Recordings getAuthenticated(DataFetchingEnvironment environment) throws E .collect(Collectors.toList()); if (requestedFields.contains("active")) { - - Credentials credentials = - getSessionCredentials(environment, targetId) - .orElse(credentialsManager.getCredentials(target)); - ConnectionDescriptor cd = new ConnectionDescriptor(targetId, credentials); + ConnectionDescriptor cd = + new ConnectionDescriptor(targetId, credentialsManager.getCredentials(target)); // FIXME populating these two struct members are each async tasks. we should do them in // parallel recordings.active = diff --git a/src/main/java/io/cryostat/net/web/http/api/v2/graph/RootNodeFetcher.java b/src/main/java/io/cryostat/net/web/http/api/v2/graph/RootNodeFetcher.java index 5045b75702..faadaaa8ac 100644 --- a/src/main/java/io/cryostat/net/web/http/api/v2/graph/RootNodeFetcher.java +++ b/src/main/java/io/cryostat/net/web/http/api/v2/graph/RootNodeFetcher.java @@ -42,7 +42,6 @@ import javax.inject.Inject; -import io.cryostat.configuration.CredentialsManager; import io.cryostat.discovery.DiscoveryStorage; import io.cryostat.net.AuthManager; import io.cryostat.net.security.ResourceAction; @@ -55,9 +54,8 @@ class RootNodeFetcher extends AbstractPermissionedDataFetcher { private final DiscoveryStorage storage; @Inject - RootNodeFetcher( - AuthManager auth, CredentialsManager credentialsManager, DiscoveryStorage storage) { - super(auth, credentialsManager); + RootNodeFetcher(AuthManager auth, DiscoveryStorage storage) { + super(auth); this.storage = storage; } diff --git a/src/main/java/io/cryostat/net/web/http/api/v2/graph/SnapshotOnTargetMutator.java b/src/main/java/io/cryostat/net/web/http/api/v2/graph/SnapshotOnTargetMutator.java index 9fceb0741b..e716a1a07d 100644 --- a/src/main/java/io/cryostat/net/web/http/api/v2/graph/SnapshotOnTargetMutator.java +++ b/src/main/java/io/cryostat/net/web/http/api/v2/graph/SnapshotOnTargetMutator.java @@ -43,11 +43,9 @@ import javax.inject.Inject; import io.cryostat.configuration.CredentialsManager; -import io.cryostat.core.net.Credentials; import io.cryostat.net.AuthManager; import io.cryostat.net.ConnectionDescriptor; import io.cryostat.net.security.ResourceAction; -import io.cryostat.platform.ServiceRef; import io.cryostat.platform.discovery.TargetNode; import io.cryostat.recordings.RecordingTargetHelper; @@ -56,14 +54,16 @@ class SnapshotOnTargetMutator extends AbstractPermissionedDataFetcher { private final RecordingTargetHelper recordingTargetHelper; + private final CredentialsManager credentialsManager; @Inject SnapshotOnTargetMutator( AuthManager auth, - CredentialsManager credentialsManager, - RecordingTargetHelper recordingTargetHelper) { - super(auth, credentialsManager); + RecordingTargetHelper recordingTargetHelper, + CredentialsManager credentialsManager) { + super(auth); this.recordingTargetHelper = recordingTargetHelper; + this.credentialsManager = credentialsManager; } @Override @@ -91,13 +91,11 @@ public Set resourceActions() { public GraphRecordingDescriptor getAuthenticated(DataFetchingEnvironment environment) throws Exception { TargetNode node = environment.getSource(); - ServiceRef target = node.getTarget(); - String uri = target.getServiceUri().toString(); - Credentials credentials = - getSessionCredentials(environment, uri.toString()) - .orElse(credentialsManager.getCredentials(target)); - ConnectionDescriptor cd = new ConnectionDescriptor(uri, credentials); - return new GraphRecordingDescriptor(target, recordingTargetHelper.createSnapshot(cd).get()); + String uri = node.getTarget().getServiceUri().toString(); + ConnectionDescriptor cd = + new ConnectionDescriptor(uri, credentialsManager.getCredentials(node.getTarget())); + return new GraphRecordingDescriptor( + node.getTarget(), recordingTargetHelper.createSnapshot(cd).get()); } } diff --git a/src/main/java/io/cryostat/net/web/http/api/v2/graph/StartRecordingOnTargetMutator.java b/src/main/java/io/cryostat/net/web/http/api/v2/graph/StartRecordingOnTargetMutator.java index edf17e49de..4d5bf87e6c 100644 --- a/src/main/java/io/cryostat/net/web/http/api/v2/graph/StartRecordingOnTargetMutator.java +++ b/src/main/java/io/cryostat/net/web/http/api/v2/graph/StartRecordingOnTargetMutator.java @@ -51,7 +51,6 @@ import org.openjdk.jmc.rjmx.services.jfr.IRecordingDescriptor; import io.cryostat.configuration.CredentialsManager; -import io.cryostat.core.net.Credentials; import io.cryostat.core.templates.TemplateType; import io.cryostat.jmc.serialization.HyperlinkedSerializableRecordingDescriptor; import io.cryostat.net.AuthManager; @@ -60,7 +59,6 @@ import io.cryostat.net.security.ResourceAction; import io.cryostat.net.web.WebServer; import io.cryostat.net.web.http.api.v2.graph.PutActiveRecordingMetadataMutator.InputRecordingLabel; -import io.cryostat.platform.ServiceRef; import io.cryostat.platform.discovery.TargetNode; import io.cryostat.recordings.RecordingMetadataManager; import io.cryostat.recordings.RecordingMetadataManager.Metadata; @@ -77,6 +75,7 @@ class StartRecordingOnTargetMutator private final TargetConnectionManager targetConnectionManager; private final RecordingTargetHelper recordingTargetHelper; private final RecordingOptionsBuilderFactory recordingOptionsBuilderFactory; + private final CredentialsManager credentialsManager; private final RecordingMetadataManager metadataManager; private final Provider webServer; private final Gson gson; @@ -84,17 +83,18 @@ class StartRecordingOnTargetMutator @Inject StartRecordingOnTargetMutator( AuthManager auth, - CredentialsManager credentialsManager, TargetConnectionManager targetConnectionManager, RecordingTargetHelper recordingTargetHelper, RecordingOptionsBuilderFactory recordingOptionsBuilderFactory, + CredentialsManager credentialsManager, RecordingMetadataManager metadataManager, Provider webServer, Gson gson) { - super(auth, credentialsManager); + super(auth); this.targetConnectionManager = targetConnectionManager; this.recordingTargetHelper = recordingTargetHelper; this.recordingOptionsBuilderFactory = recordingOptionsBuilderFactory; + this.credentialsManager = credentialsManager; this.metadataManager = metadataManager; this.webServer = webServer; this.gson = gson; @@ -124,14 +124,11 @@ public Set resourceActions() { public HyperlinkedSerializableRecordingDescriptor getAuthenticated( DataFetchingEnvironment environment) throws Exception { TargetNode node = environment.getSource(); - ServiceRef target = node.getTarget(); Map settings = environment.getArgument("recording"); - String uri = target.getServiceUri().toString(); - Credentials credentials = - getSessionCredentials(environment, uri.toString()) - .orElse(credentialsManager.getCredentials(target)); - ConnectionDescriptor cd = new ConnectionDescriptor(uri, credentials); + String uri = node.getTarget().getServiceUri().toString(); + ConnectionDescriptor cd = + new ConnectionDescriptor(uri, credentialsManager.getCredentials(node.getTarget())); return targetConnectionManager.executeConnectedTask( cd, conn -> { diff --git a/src/main/java/io/cryostat/net/web/http/api/v2/graph/StopRecordingMutator.java b/src/main/java/io/cryostat/net/web/http/api/v2/graph/StopRecordingMutator.java index 5073823851..71ad4defc2 100644 --- a/src/main/java/io/cryostat/net/web/http/api/v2/graph/StopRecordingMutator.java +++ b/src/main/java/io/cryostat/net/web/http/api/v2/graph/StopRecordingMutator.java @@ -46,7 +46,6 @@ import org.openjdk.jmc.rjmx.services.jfr.IRecordingDescriptor; import io.cryostat.configuration.CredentialsManager; -import io.cryostat.core.net.Credentials; import io.cryostat.net.AuthManager; import io.cryostat.net.ConnectionDescriptor; import io.cryostat.net.TargetConnectionManager; @@ -63,20 +62,22 @@ class StopRecordingMutator extends AbstractPermissionedDataFetcher webServer; @Inject StopRecordingMutator( AuthManager auth, - CredentialsManager credentialsManager, TargetConnectionManager targetConnectionManager, RecordingTargetHelper recordingTargetHelper, + CredentialsManager credentialsManager, RecordingMetadataManager metadataManager, Provider webServer) { - super(auth, credentialsManager); + super(auth); this.targetConnectionManager = targetConnectionManager; this.recordingTargetHelper = recordingTargetHelper; + this.credentialsManager = credentialsManager; this.metadataManager = metadataManager; this.webServer = webServer; } @@ -106,10 +107,8 @@ public GraphRecordingDescriptor getAuthenticated(DataFetchingEnvironment environ GraphRecordingDescriptor source = environment.getSource(); ServiceRef target = source.target; String uri = target.getServiceUri().toString(); - Credentials credentials = - getSessionCredentials(environment, uri.toString()) - .orElse(credentialsManager.getCredentials(target)); - ConnectionDescriptor cd = new ConnectionDescriptor(uri, credentials); + ConnectionDescriptor cd = + new ConnectionDescriptor(uri, credentialsManager.getCredentials(target)); return targetConnectionManager.executeConnectedTask( cd, diff --git a/src/main/java/io/cryostat/net/web/http/api/v2/graph/TargetNodeRecurseFetcher.java b/src/main/java/io/cryostat/net/web/http/api/v2/graph/TargetNodeRecurseFetcher.java index 0de9c06f86..6656de4fef 100644 --- a/src/main/java/io/cryostat/net/web/http/api/v2/graph/TargetNodeRecurseFetcher.java +++ b/src/main/java/io/cryostat/net/web/http/api/v2/graph/TargetNodeRecurseFetcher.java @@ -49,7 +49,6 @@ import javax.inject.Inject; -import io.cryostat.configuration.CredentialsManager; import io.cryostat.net.AuthManager; import io.cryostat.net.security.ResourceAction; import io.cryostat.net.web.http.api.v2.graph.labels.LabelSelectorMatcher; @@ -63,8 +62,8 @@ class TargetNodeRecurseFetcher extends AbstractPermissionedDataFetcher> { @Inject - TargetNodeRecurseFetcher(AuthManager auth, CredentialsManager credentialsManager) { - super(auth, credentialsManager); + TargetNodeRecurseFetcher(AuthManager auth) { + super(auth); } @Override @@ -147,8 +146,6 @@ public List getAuthenticated(DataFetchingEnvironment environment) th .collect(Collectors.toList()); } } - result.forEach( - t -> getSessionCredentials(environment, t.getTarget().getServiceUri().toString())); return result; } } diff --git a/src/main/java/io/cryostat/net/web/http/api/v2/graph/TargetNodesFetcher.java b/src/main/java/io/cryostat/net/web/http/api/v2/graph/TargetNodesFetcher.java index 2e6df720c7..2045688600 100644 --- a/src/main/java/io/cryostat/net/web/http/api/v2/graph/TargetNodesFetcher.java +++ b/src/main/java/io/cryostat/net/web/http/api/v2/graph/TargetNodesFetcher.java @@ -48,7 +48,6 @@ import javax.inject.Inject; -import io.cryostat.configuration.CredentialsManager; import io.cryostat.net.AuthManager; import io.cryostat.net.security.ResourceAction; import io.cryostat.net.web.http.api.v2.graph.labels.LabelSelectorMatcher; @@ -65,10 +64,9 @@ class TargetNodesFetcher extends AbstractPermissionedDataFetcher getAuthenticated(DataFetchingEnvironment environment) th .collect(Collectors.toList()); } } - - result.forEach( - t -> getSessionCredentials(environment, t.getTarget().getServiceUri().toString())); return result; } } diff --git a/src/main/java/io/cryostat/platform/internal/KubeApiPlatformStrategy.java b/src/main/java/io/cryostat/platform/internal/KubeApiPlatformStrategy.java index e1630a7ff1..6e7686a9c4 100644 --- a/src/main/java/io/cryostat/platform/internal/KubeApiPlatformStrategy.java +++ b/src/main/java/io/cryostat/platform/internal/KubeApiPlatformStrategy.java @@ -43,7 +43,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.concurrent.Executor; +import java.util.concurrent.ForkJoinPool; import io.cryostat.configuration.Variables; import io.cryostat.core.log.Logger; @@ -62,7 +62,6 @@ class KubeApiPlatformStrategy implements PlatformDetectionStrategy { protected final Logger logger; - protected final Executor executor; protected final Lazy authMgr; protected final Environment env; protected final FileSystem fs; @@ -70,13 +69,11 @@ class KubeApiPlatformStrategy implements PlatformDetectionStrategy authMgr, Lazy connectionToolkit, Environment env, FileSystem fs) { this.logger = logger; - this.executor = executor; this.authMgr = authMgr; this.connectionToolkit = connectionToolkit; this.env = env; @@ -112,7 +109,7 @@ public AuthManager getAuthManager() { } protected KubernetesClient createClient() { - return new KubernetesClientBuilder().withTaskExecutor(executor).build(); + return new KubernetesClientBuilder().withTaskExecutor(ForkJoinPool.commonPool()).build(); } @SuppressFBWarnings("DMI_HARDCODED_ABSOLUTE_FILENAME") diff --git a/src/main/java/io/cryostat/platform/internal/OpenShiftPlatformStrategy.java b/src/main/java/io/cryostat/platform/internal/OpenShiftPlatformStrategy.java index 5976f4194b..32dcf68b78 100644 --- a/src/main/java/io/cryostat/platform/internal/OpenShiftPlatformStrategy.java +++ b/src/main/java/io/cryostat/platform/internal/OpenShiftPlatformStrategy.java @@ -37,8 +37,6 @@ */ package io.cryostat.platform.internal; -import java.util.concurrent.Executor; - import io.cryostat.core.log.Logger; import io.cryostat.core.net.JFRConnectionToolkit; import io.cryostat.core.sys.Environment; @@ -53,12 +51,11 @@ class OpenShiftPlatformStrategy extends KubeApiPlatformStrategy { OpenShiftPlatformStrategy( Logger logger, - Executor executor, Lazy authMgr, Lazy connectionToolkit, Environment env, FileSystem fs) { - super(logger, executor, authMgr, connectionToolkit, env, fs); + super(logger, authMgr, connectionToolkit, env, fs); } @Override diff --git a/src/main/java/io/cryostat/platform/internal/PlatformStrategyModule.java b/src/main/java/io/cryostat/platform/internal/PlatformStrategyModule.java index 104e46f4d3..5507084250 100644 --- a/src/main/java/io/cryostat/platform/internal/PlatformStrategyModule.java +++ b/src/main/java/io/cryostat/platform/internal/PlatformStrategyModule.java @@ -38,9 +38,6 @@ package io.cryostat.platform.internal; import java.util.Set; -import java.util.concurrent.ExecutorService; - -import javax.inject.Named; import io.cryostat.core.log.Logger; import io.cryostat.core.net.JFRConnectionToolkit; @@ -50,7 +47,6 @@ import io.cryostat.net.NetworkResolver; import io.cryostat.net.NoopAuthManager; import io.cryostat.net.openshift.OpenShiftAuthManager; -import io.cryostat.net.web.WebModule; import com.google.gson.Gson; import dagger.Lazy; @@ -69,7 +65,6 @@ static Set> providePlatformDetectionStrategies( Lazy openShiftAuthManager, Lazy noopAuthManager, Lazy connectionToolkit, - @Named(WebModule.VERTX_EXECUTOR) ExecutorService executor, Vertx vertx, Gson gson, NetworkResolver resolver, @@ -77,9 +72,8 @@ static Set> providePlatformDetectionStrategies( FileSystem fs) { return Set.of( new OpenShiftPlatformStrategy( - logger, executor, openShiftAuthManager, connectionToolkit, env, fs), - new KubeApiPlatformStrategy( - logger, executor, noopAuthManager, connectionToolkit, env, fs), + logger, openShiftAuthManager, connectionToolkit, env, fs), + new KubeApiPlatformStrategy(logger, noopAuthManager, connectionToolkit, env, fs), new KubeEnvPlatformStrategy(logger, fs, noopAuthManager, connectionToolkit, env), new PodmanPlatformStrategy(logger, noopAuthManager, vertx, gson, fs), new DefaultPlatformStrategy( diff --git a/src/main/java/io/cryostat/recordings/JvmIdHelper.java b/src/main/java/io/cryostat/recordings/JvmIdHelper.java index 7a79634a09..f5725e754f 100644 --- a/src/main/java/io/cryostat/recordings/JvmIdHelper.java +++ b/src/main/java/io/cryostat/recordings/JvmIdHelper.java @@ -138,13 +138,7 @@ public ServiceRef resolveId(ServiceRef sr) throws JvmIdGetException { try { CompletableFuture future = this.targetConnectionManager.executeConnectedTaskAsync( - new ConnectionDescriptor( - uriStr, - Optional.ofNullable( - CredentialsManager.SESSION_CREDENTIALS - .get() - .get(serviceUri.toString())) - .orElse(credentialsManager.getCredentials(sr))), + new ConnectionDescriptor(uriStr, credentialsManager.getCredentials(sr)), JFRConnection::getJvmId); future.thenAccept( id -> { @@ -198,20 +192,11 @@ private CompletableFuture computeJvmId( } public String getJvmId(ConnectionDescriptor connectionDescriptor) throws JvmIdGetException { - return getJvmId( - connectionDescriptor.getTargetId(), - true, - Optional.ofNullable( - CredentialsManager.SESSION_CREDENTIALS - .get() - .get(connectionDescriptor.getTargetId()))); + return getJvmId(connectionDescriptor.getTargetId(), true, Optional.empty()); } public String getJvmId(String targetId) throws JvmIdGetException { - return getJvmId( - targetId, - true, - Optional.ofNullable(CredentialsManager.SESSION_CREDENTIALS.get().get(targetId))); + return getJvmId(targetId, true, Optional.empty()); } public String getJvmId(String targetId, boolean cache, Optional credentials) @@ -275,9 +260,7 @@ private class IdLoader implements AsyncCacheLoader { @Override public CompletableFuture asyncLoad(String key, Executor executor) throws Exception { - return computeJvmId( - key, - Optional.ofNullable(CredentialsManager.SESSION_CREDENTIALS.get().get(key))); + return computeJvmId(key, Optional.empty()); } @Override diff --git a/src/main/java/io/cryostat/recordings/RecordingsModule.java b/src/main/java/io/cryostat/recordings/RecordingsModule.java index b35149208d..cd770fe6cf 100644 --- a/src/main/java/io/cryostat/recordings/RecordingsModule.java +++ b/src/main/java/io/cryostat/recordings/RecordingsModule.java @@ -43,7 +43,7 @@ import java.nio.file.attribute.PosixFilePermission; import java.nio.file.attribute.PosixFilePermissions; import java.util.Set; -import java.util.concurrent.ExecutorService; +import java.util.concurrent.ForkJoinPool; import javax.inject.Named; import javax.inject.Provider; @@ -176,7 +176,6 @@ static RecordingMetadataManager provideRecordingMetadataManager( // CONFIGURATION_PATH @Named(ConfigurationModule.CONFIGURATION_PATH) Path confDir, @Named(MainModule.RECORDINGS_PATH) Path archivedRecordingsPath, - @Named(WebModule.VERTX_EXECUTOR) ExecutorService executor, @Named(Variables.JMX_CONNECTION_TIMEOUT) long connectionTimeoutSeconds, FileSystem fs, Provider archiveHelperProvider, @@ -200,7 +199,7 @@ static RecordingMetadataManager provideRecordingMetadataManager( PosixFilePermission.OWNER_EXECUTE))); } return new RecordingMetadataManager( - executor, + ForkJoinPool.commonPool(), metadataDir, archivedRecordingsPath, connectionTimeoutSeconds, @@ -223,7 +222,6 @@ static RecordingMetadataManager provideRecordingMetadataManager( @Singleton static JvmIdHelper provideJvmIdHelper( TargetConnectionManager targetConnectionManager, - @Named(WebModule.VERTX_EXECUTOR) ExecutorService executor, @Named(Variables.JMX_CONNECTION_TIMEOUT) long connectionTimeoutSeconds, CredentialsManager credentialsManager, DiscoveryStorage storage, @@ -234,7 +232,7 @@ static JvmIdHelper provideJvmIdHelper( credentialsManager, storage, connectionTimeoutSeconds, - executor, + ForkJoinPool.commonPool(), Scheduler.systemScheduler(), base32, logger); diff --git a/src/main/java/io/cryostat/sys/ThreadLocalPropagatingPoolExecutorService.java b/src/main/java/io/cryostat/sys/ThreadLocalPropagatingPoolExecutorService.java deleted file mode 100644 index 7feb316b3c..0000000000 --- a/src/main/java/io/cryostat/sys/ThreadLocalPropagatingPoolExecutorService.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright The Cryostat Authors - * - * The Universal Permissive License (UPL), Version 1.0 - * - * Subject to the condition set forth below, permission is hereby granted to any - * person obtaining a copy of this software, associated documentation and/or data - * (collectively the "Software"), free of charge and under any and all copyright - * rights in the Software, and any and all patent rights owned or freely - * licensable by each licensor hereunder covering either (i) the unmodified - * Software as contributed to or provided by such licensor, or (ii) the Larger - * Works (as defined below), to deal in both - * - * (a) the Software, and - * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if - * one is included with the Software (each a "Larger Work" to which the Software - * is contributed by such licensors), - * - * without restriction, including without limitation the rights to copy, create - * derivative works of, display, perform, and distribute the Software and make, - * use, sell, offer for sale, import, export, have made, and have sold the - * Software and the Larger Work(s), and to sublicense the foregoing rights on - * either these or other terms. - * - * This license is subject to the following condition: - * The above copyright notice and either this complete permission notice or at - * a minimum a reference to the UPL must be included in all copies or - * substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package io.cryostat.sys; - -import java.util.concurrent.SynchronousQueue; -import java.util.concurrent.ThreadPoolExecutor; -import java.util.concurrent.TimeUnit; -import java.util.function.Consumer; -import java.util.function.Supplier; - -public class ThreadLocalPropagatingPoolExecutorService extends ThreadPoolExecutor { - - private final Supplier getter; - private final Consumer setter; - private final Runnable cleaner; - - public ThreadLocalPropagatingPoolExecutorService( - Supplier getter, Consumer setter, Runnable cleaner) { - super( - 1, - Runtime.getRuntime().availableProcessors() * 2, - 1, - TimeUnit.MINUTES, - new SynchronousQueue<>()); - this.getter = getter; - this.setter = setter; - this.cleaner = cleaner; - } - - @Override - public void execute(Runnable task) { - T t = getter.get(); - super.execute( - () -> { - setter.accept(t); - try { - task.run(); - } finally { - cleaner.run(); - } - }); - } -} diff --git a/src/main/resources/types.graphqls b/src/main/resources/types.graphqls index 410efb66da..e45417208a 100644 --- a/src/main/resources/types.graphqls +++ b/src/main/resources/types.graphqls @@ -51,8 +51,6 @@ input ArchivedRecordingFilterInput { } type ServiceRef { - # This is the ID as currently known in the Discovery database at the time the query began. If - # the query includes session credentials, this ID will *not* be updated within the request. jvmId: String serviceUri: ServiceURI! alias: String @@ -181,15 +179,10 @@ type MBeanMetrics { memory: MemoryMetrics! thread: ThreadMetrics! os: OperatingSystemMetrics! - # This is the ID as retrieved over an open network connection to the target JVM. This may use - # either stored credentials or session credentials. If using session credentials for a target - # that has no matching stored credentials, then this field will be non-null and the ID under - # the ServiceRef structure will be null due to the difference between stored representation - # and "live" retrieval with session credentials. jvmId: String! } -# Currently all the relevant MXBean readable attributes in the Cryostat jvm +# Currently all the relevant MXBean readable attributes in the Cryostat jvm type RuntimeMetrics { bootClassPath: String classPath: String diff --git a/src/test/java/io/cryostat/net/web/http/api/v2/AbstractV2RequestHandlerTest.java b/src/test/java/io/cryostat/net/web/http/api/v2/AbstractV2RequestHandlerTest.java index c255caabe9..a68599a049 100644 --- a/src/test/java/io/cryostat/net/web/http/api/v2/AbstractV2RequestHandlerTest.java +++ b/src/test/java/io/cryostat/net/web/http/api/v2/AbstractV2RequestHandlerTest.java @@ -326,8 +326,7 @@ void shouldOverrideStoredCredentialsByAuthorizationHeader() throws ScriptExcepti desc.getCredentials().get(), Matchers.equalTo(new Credentials("jmxuser", "jmxpass"))); - Credentials storedCredential = new Credentials("jmxuser", "jmxpass"); - Mockito.verify(credentialsManager).setSessionCredentials(targetId, storedCredential); + Mockito.verifyNoInteractions(credentialsManager); } @ParameterizedTest diff --git a/src/test/java/io/cryostat/net/web/http/api/v2/graph/AbstractPermissionedDataFetcherTest.java b/src/test/java/io/cryostat/net/web/http/api/v2/graph/AbstractPermissionedDataFetcherTest.java index 1330e669d8..c4737ac374 100644 --- a/src/test/java/io/cryostat/net/web/http/api/v2/graph/AbstractPermissionedDataFetcherTest.java +++ b/src/test/java/io/cryostat/net/web/http/api/v2/graph/AbstractPermissionedDataFetcherTest.java @@ -42,7 +42,6 @@ import java.util.Set; import java.util.concurrent.CompletableFuture; -import io.cryostat.configuration.CredentialsManager; import io.cryostat.net.AuthManager; import io.cryostat.net.AuthorizationErrorException; import io.cryostat.net.security.ResourceAction; @@ -65,7 +64,6 @@ class AbstractPermissionedDataFetcherTest { AbstractPermissionedDataFetcher fetcher; @Mock AuthManager auth; - @Mock CredentialsManager credentialsManager; @Mock DataFetchingEnvironment env; @Mock GraphQLContext graphCtx; @@ -74,7 +72,7 @@ class AbstractPermissionedDataFetcherTest { @BeforeEach void setup() { - this.fetcher = new PermissionedDataFetcher(auth, credentialsManager); + this.fetcher = new PermissionedDataFetcher(auth); } @Test @@ -95,8 +93,8 @@ void shouldThrowAuthorizationError() throws Exception { } static class PermissionedDataFetcher extends AbstractPermissionedDataFetcher { - PermissionedDataFetcher(AuthManager auth, CredentialsManager credentialsManager) { - super(auth, credentialsManager); + PermissionedDataFetcher(AuthManager auth) { + super(auth); } @Override diff --git a/src/test/java/io/cryostat/net/web/http/api/v2/graph/ActiveRecordingsFetcherTest.java b/src/test/java/io/cryostat/net/web/http/api/v2/graph/ActiveRecordingsFetcherTest.java index e45d9c9905..e731b4ea89 100644 --- a/src/test/java/io/cryostat/net/web/http/api/v2/graph/ActiveRecordingsFetcherTest.java +++ b/src/test/java/io/cryostat/net/web/http/api/v2/graph/ActiveRecordingsFetcherTest.java @@ -46,7 +46,6 @@ import org.openjdk.jmc.rjmx.services.jfr.IRecordingDescriptor.RecordingState; -import io.cryostat.configuration.CredentialsManager; import io.cryostat.net.AuthManager; import io.cryostat.net.security.ResourceAction; import io.cryostat.net.web.http.api.v2.graph.ActiveRecordingsFetcher.Active; @@ -70,7 +69,6 @@ class ActiveRecordingsFetcherTest { ActiveRecordingsFetcher fetcher; @Mock AuthManager auth; - @Mock CredentialsManager credentialsManager; @Mock DataFetchingEnvironment env; @Mock GraphQLContext graphCtx; @@ -79,7 +77,7 @@ class ActiveRecordingsFetcherTest { @BeforeEach void setup() { - this.fetcher = new ActiveRecordingsFetcher(auth, credentialsManager); + this.fetcher = new ActiveRecordingsFetcher(auth); } @Test diff --git a/src/test/java/io/cryostat/net/web/http/api/v2/graph/AllArchivedRecordingsFetcherTest.java b/src/test/java/io/cryostat/net/web/http/api/v2/graph/AllArchivedRecordingsFetcherTest.java index dbe326d185..cac74a5d83 100644 --- a/src/test/java/io/cryostat/net/web/http/api/v2/graph/AllArchivedRecordingsFetcherTest.java +++ b/src/test/java/io/cryostat/net/web/http/api/v2/graph/AllArchivedRecordingsFetcherTest.java @@ -45,7 +45,6 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.Future; -import io.cryostat.configuration.CredentialsManager; import io.cryostat.core.log.Logger; import io.cryostat.net.AuthManager; import io.cryostat.net.security.ResourceAction; @@ -72,7 +71,6 @@ class AllArchivedRecordingsFetcherTest { AllArchivedRecordingsFetcher fetcher; @Mock AuthManager auth; - @Mock CredentialsManager credentialsManager; @Mock RecordingArchiveHelper archiveHelper; @Mock Logger logger; @@ -84,8 +82,7 @@ class AllArchivedRecordingsFetcherTest { @BeforeEach void setup() { - this.fetcher = - new AllArchivedRecordingsFetcher(auth, credentialsManager, archiveHelper, logger); + this.fetcher = new AllArchivedRecordingsFetcher(auth, archiveHelper, logger); } @Test diff --git a/src/test/java/io/cryostat/net/web/http/api/v2/graph/ArchiveRecordingMutatorTest.java b/src/test/java/io/cryostat/net/web/http/api/v2/graph/ArchiveRecordingMutatorTest.java index 1b72568e5b..8732a98d16 100644 --- a/src/test/java/io/cryostat/net/web/http/api/v2/graph/ArchiveRecordingMutatorTest.java +++ b/src/test/java/io/cryostat/net/web/http/api/v2/graph/ArchiveRecordingMutatorTest.java @@ -55,8 +55,6 @@ import graphql.GraphQLContext; import graphql.schema.DataFetchingEnvironment; -import io.vertx.core.MultiMap; -import io.vertx.core.http.HttpServerRequest; import io.vertx.ext.web.RoutingContext; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; @@ -72,8 +70,8 @@ class ArchiveRecordingMutatorTest { ArchiveRecordingMutator mutator; @Mock AuthManager auth; - @Mock CredentialsManager credentialsManager; @Mock RecordingArchiveHelper recordingArchiveHelper; + @Mock CredentialsManager credentialsManager; @Mock DataFetchingEnvironment env; @Mock GraphQLContext graphCtx; @@ -85,7 +83,7 @@ class ArchiveRecordingMutatorTest { @BeforeEach void setup() { this.mutator = - new ArchiveRecordingMutator(auth, credentialsManager, recordingArchiveHelper); + new ArchiveRecordingMutator(auth, recordingArchiveHelper, credentialsManager); } @Test @@ -103,10 +101,6 @@ void shouldHaveExpectedRequiredPermissions() { @Test void shouldArchiveAndReturnRecording() throws Exception { when(env.getGraphQlContext()).thenReturn(graphCtx); - when(graphCtx.get(RoutingContext.class)).thenReturn(ctx); - HttpServerRequest req = Mockito.mock(HttpServerRequest.class); - when(ctx.request()).thenReturn(req); - when(req.headers()).thenReturn(MultiMap.caseInsensitiveMultiMap()); when(auth.validateHttpHeader(Mockito.any(), Mockito.any())) .thenReturn(CompletableFuture.completedFuture(true)); diff --git a/src/test/java/io/cryostat/net/web/http/api/v2/graph/ArchivedRecordingsFetcherTest.java b/src/test/java/io/cryostat/net/web/http/api/v2/graph/ArchivedRecordingsFetcherTest.java index 9ef532e554..518c8ca120 100644 --- a/src/test/java/io/cryostat/net/web/http/api/v2/graph/ArchivedRecordingsFetcherTest.java +++ b/src/test/java/io/cryostat/net/web/http/api/v2/graph/ArchivedRecordingsFetcherTest.java @@ -45,7 +45,6 @@ import java.util.Set; import java.util.concurrent.CompletableFuture; -import io.cryostat.configuration.CredentialsManager; import io.cryostat.net.AuthManager; import io.cryostat.net.security.ResourceAction; import io.cryostat.net.web.http.api.v2.graph.ArchivedRecordingsFetcher.Archived; @@ -71,7 +70,6 @@ class ArchivedRecordingsFetcherTest { ArchivedRecordingsFetcher fetcher; @Mock AuthManager auth; - @Mock CredentialsManager credentialsManager; @Mock DataFetchingEnvironment env; @Mock GraphQLContext graphCtx; @@ -80,7 +78,7 @@ class ArchivedRecordingsFetcherTest { @BeforeEach void setup() { - this.fetcher = new ArchivedRecordingsFetcher(auth, credentialsManager); + this.fetcher = new ArchivedRecordingsFetcher(auth); } @Test diff --git a/src/test/java/io/cryostat/net/web/http/api/v2/graph/DeleteActiveRecordingMutatorTest.java b/src/test/java/io/cryostat/net/web/http/api/v2/graph/DeleteActiveRecordingMutatorTest.java index ed14453bf9..df816fb57b 100644 --- a/src/test/java/io/cryostat/net/web/http/api/v2/graph/DeleteActiveRecordingMutatorTest.java +++ b/src/test/java/io/cryostat/net/web/http/api/v2/graph/DeleteActiveRecordingMutatorTest.java @@ -54,8 +54,6 @@ import graphql.GraphQLContext; import graphql.schema.DataFetchingEnvironment; -import io.vertx.core.MultiMap; -import io.vertx.core.http.HttpServerRequest; import io.vertx.ext.web.RoutingContext; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; @@ -71,8 +69,8 @@ class DeleteActiveRecordingMutatorTest { DeleteActiveRecordingMutator mutator; @Mock AuthManager auth; - @Mock CredentialsManager credentialsManager; @Mock RecordingTargetHelper recordingTargetHelper; + @Mock CredentialsManager credentialsManager; @Mock DataFetchingEnvironment env; @Mock GraphQLContext graphCtx; @@ -84,7 +82,7 @@ class DeleteActiveRecordingMutatorTest { @BeforeEach void setup() { this.mutator = - new DeleteActiveRecordingMutator(auth, credentialsManager, recordingTargetHelper); + new DeleteActiveRecordingMutator(auth, recordingTargetHelper, credentialsManager); } @Test @@ -102,10 +100,6 @@ void shouldHaveExpectedRequiredPermissions() { @Test void shouldDeleteAndReturnSource() throws Exception { when(env.getGraphQlContext()).thenReturn(graphCtx); - when(graphCtx.get(RoutingContext.class)).thenReturn(ctx); - HttpServerRequest req = Mockito.mock(HttpServerRequest.class); - when(ctx.request()).thenReturn(req); - when(req.headers()).thenReturn(MultiMap.caseInsensitiveMultiMap()); when(auth.validateHttpHeader(Mockito.any(), Mockito.any())) .thenReturn(CompletableFuture.completedFuture(true)); diff --git a/src/test/java/io/cryostat/net/web/http/api/v2/graph/DeleteArchivedRecordingMutatorTest.java b/src/test/java/io/cryostat/net/web/http/api/v2/graph/DeleteArchivedRecordingMutatorTest.java index 282cb747db..b36153eb55 100644 --- a/src/test/java/io/cryostat/net/web/http/api/v2/graph/DeleteArchivedRecordingMutatorTest.java +++ b/src/test/java/io/cryostat/net/web/http/api/v2/graph/DeleteArchivedRecordingMutatorTest.java @@ -68,8 +68,8 @@ class DeleteArchivedRecordingMutatorTest { DeleteArchivedRecordingMutator mutator; @Mock AuthManager auth; - @Mock CredentialsManager credentialsManager; @Mock RecordingArchiveHelper recordingArchiveHelper; + @Mock CredentialsManager credentialsManager; @Mock DataFetchingEnvironment env; @Mock GraphQLContext graphCtx; @@ -80,9 +80,7 @@ class DeleteArchivedRecordingMutatorTest { @BeforeEach void setup() { - this.mutator = - new DeleteArchivedRecordingMutator( - auth, credentialsManager, recordingArchiveHelper); + this.mutator = new DeleteArchivedRecordingMutator(auth, recordingArchiveHelper); } @Test diff --git a/src/test/java/io/cryostat/net/web/http/api/v2/graph/EnvironmentNodeChildrenFetcherTest.java b/src/test/java/io/cryostat/net/web/http/api/v2/graph/EnvironmentNodeChildrenFetcherTest.java index b3d70661a2..846a46fce3 100644 --- a/src/test/java/io/cryostat/net/web/http/api/v2/graph/EnvironmentNodeChildrenFetcherTest.java +++ b/src/test/java/io/cryostat/net/web/http/api/v2/graph/EnvironmentNodeChildrenFetcherTest.java @@ -45,7 +45,6 @@ import java.util.Set; import java.util.concurrent.CompletableFuture; -import io.cryostat.configuration.CredentialsManager; import io.cryostat.net.AuthManager; import io.cryostat.net.security.ResourceAction; import io.cryostat.platform.discovery.AbstractNode; @@ -68,7 +67,6 @@ class EnvironmentNodeChildrenFetcherTest { EnvironmentNodeChildrenFetcher fetcher; @Mock AuthManager auth; - @Mock CredentialsManager credentialsManager; @Mock DataFetchingEnvironment env; @Mock GraphQLContext graphCtx; @@ -76,7 +74,7 @@ class EnvironmentNodeChildrenFetcherTest { @BeforeEach void setup() { - this.fetcher = new EnvironmentNodeChildrenFetcher(auth, credentialsManager); + this.fetcher = new EnvironmentNodeChildrenFetcher(auth); } @Test diff --git a/src/test/java/io/cryostat/net/web/http/api/v2/graph/EnvironmentNodesFetcherTest.java b/src/test/java/io/cryostat/net/web/http/api/v2/graph/EnvironmentNodesFetcherTest.java index 0b9271a2cf..81e36f4da0 100644 --- a/src/test/java/io/cryostat/net/web/http/api/v2/graph/EnvironmentNodesFetcherTest.java +++ b/src/test/java/io/cryostat/net/web/http/api/v2/graph/EnvironmentNodesFetcherTest.java @@ -44,7 +44,6 @@ import java.util.Set; import java.util.concurrent.CompletableFuture; -import io.cryostat.configuration.CredentialsManager; import io.cryostat.net.AuthManager; import io.cryostat.net.security.ResourceAction; import io.cryostat.platform.discovery.BaseNodeType; @@ -68,7 +67,6 @@ class EnvironmentNodesFetcherTest { EnvironmentNodesFetcher fetcher; @Mock AuthManager auth; - @Mock CredentialsManager credentialsManager; @Mock RootNodeFetcher rootNodeFetcher; @Mock DataFetchingEnvironment env; @@ -78,7 +76,7 @@ class EnvironmentNodesFetcherTest { @BeforeEach void setup() { - this.fetcher = new EnvironmentNodesFetcher(auth, credentialsManager, rootNodeFetcher); + this.fetcher = new EnvironmentNodesFetcher(auth, rootNodeFetcher); } @Test diff --git a/src/test/java/io/cryostat/net/web/http/api/v2/graph/NodeFetcherTest.java b/src/test/java/io/cryostat/net/web/http/api/v2/graph/NodeFetcherTest.java index 6c574a283c..f843882276 100644 --- a/src/test/java/io/cryostat/net/web/http/api/v2/graph/NodeFetcherTest.java +++ b/src/test/java/io/cryostat/net/web/http/api/v2/graph/NodeFetcherTest.java @@ -47,7 +47,6 @@ import java.util.Set; import java.util.concurrent.CompletableFuture; -import io.cryostat.configuration.CredentialsManager; import io.cryostat.net.AuthManager; import io.cryostat.net.security.ResourceAction; import io.cryostat.platform.discovery.AbstractNode; @@ -72,7 +71,6 @@ class NodeFetcherTest { NodeFetcher fetcher; @Mock AuthManager auth; - @Mock CredentialsManager credentialsManager; @Mock RootNodeFetcher rootNodeFetcher; @Mock DataFetchingEnvironment env; @@ -81,7 +79,7 @@ class NodeFetcherTest { @BeforeEach void setup() { - this.fetcher = new NodeFetcher(auth, credentialsManager, rootNodeFetcher); + this.fetcher = new NodeFetcher(auth, rootNodeFetcher); } @Test diff --git a/src/test/java/io/cryostat/net/web/http/api/v2/graph/RecordingsFetcherTest.java b/src/test/java/io/cryostat/net/web/http/api/v2/graph/RecordingsFetcherTest.java index 649195eda7..299fae085d 100644 --- a/src/test/java/io/cryostat/net/web/http/api/v2/graph/RecordingsFetcherTest.java +++ b/src/test/java/io/cryostat/net/web/http/api/v2/graph/RecordingsFetcherTest.java @@ -66,8 +66,6 @@ import graphql.schema.DataFetchingEnvironment; import graphql.schema.DataFetchingFieldSelectionSet; import graphql.schema.SelectedField; -import io.vertx.core.MultiMap; -import io.vertx.core.http.HttpServerRequest; import io.vertx.ext.web.RoutingContext; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; @@ -90,9 +88,9 @@ class RecordingsFetcherTest { RecordingsFetcher fetcher; @Mock AuthManager auth; - @Mock CredentialsManager credentialsManager; @Mock TargetConnectionManager targetConnectionManager; @Mock RecordingArchiveHelper archiveHelper; + @Mock CredentialsManager credentialsManager; @Mock RecordingMetadataManager metadataManager; @Mock Provider webServer; @Mock Logger logger; @@ -114,9 +112,9 @@ void setup() { this.fetcher = new RecordingsFetcher( auth, - credentialsManager, targetConnectionManager, archiveHelper, + credentialsManager, metadataManager, webServer, logger); @@ -162,10 +160,6 @@ void shouldReturnNone() throws Exception { @Test void shouldReturnNoneWithRequestedFields() throws Exception { when(env.getGraphQlContext()).thenReturn(graphCtx); - when(graphCtx.get(RoutingContext.class)).thenReturn(ctx); - HttpServerRequest req = Mockito.mock(HttpServerRequest.class); - when(ctx.request()).thenReturn(req); - when(req.headers()).thenReturn(MultiMap.caseInsensitiveMultiMap()); when(auth.validateHttpHeader(Mockito.any(), Mockito.any())) .thenReturn(CompletableFuture.completedFuture(true)); @@ -200,10 +194,6 @@ void shouldReturnNoneWithRequestedFields() throws Exception { @Test void shouldReturnActiveRecording() throws Exception { when(env.getGraphQlContext()).thenReturn(graphCtx); - when(graphCtx.get(RoutingContext.class)).thenReturn(ctx); - HttpServerRequest req = Mockito.mock(HttpServerRequest.class); - when(ctx.request()).thenReturn(req); - when(req.headers()).thenReturn(MultiMap.caseInsensitiveMultiMap()); when(auth.validateHttpHeader(Mockito.any(), Mockito.any())) .thenReturn(CompletableFuture.completedFuture(true)); @@ -275,10 +265,6 @@ void shouldReturnArchivedRecording() throws Exception { @Test void shouldReturnAllRecordings() throws Exception { when(env.getGraphQlContext()).thenReturn(graphCtx); - when(graphCtx.get(RoutingContext.class)).thenReturn(ctx); - HttpServerRequest req = Mockito.mock(HttpServerRequest.class); - when(ctx.request()).thenReturn(req); - when(req.headers()).thenReturn(MultiMap.caseInsensitiveMultiMap()); when(auth.validateHttpHeader(Mockito.any(), Mockito.any())) .thenReturn(CompletableFuture.completedFuture(true)); diff --git a/src/test/java/io/cryostat/net/web/http/api/v2/graph/RootNodeFetcherTest.java b/src/test/java/io/cryostat/net/web/http/api/v2/graph/RootNodeFetcherTest.java index b8ceb2cbdb..e825a54b5b 100644 --- a/src/test/java/io/cryostat/net/web/http/api/v2/graph/RootNodeFetcherTest.java +++ b/src/test/java/io/cryostat/net/web/http/api/v2/graph/RootNodeFetcherTest.java @@ -43,7 +43,6 @@ import java.util.Set; import java.util.concurrent.CompletableFuture; -import io.cryostat.configuration.CredentialsManager; import io.cryostat.discovery.DiscoveryStorage; import io.cryostat.net.AuthManager; import io.cryostat.net.security.ResourceAction; @@ -67,7 +66,6 @@ class RootNodeFetcherTest { RootNodeFetcher fetcher; @Mock AuthManager auth; - @Mock CredentialsManager credentialsManager; @Mock DiscoveryStorage storage; @Mock DataFetchingEnvironment env; @@ -76,7 +74,7 @@ class RootNodeFetcherTest { @BeforeEach void setup() { - this.fetcher = new RootNodeFetcher(auth, credentialsManager, storage); + this.fetcher = new RootNodeFetcher(auth, storage); } @Test diff --git a/src/test/java/io/cryostat/net/web/http/api/v2/graph/SnapshotOnTargetMutatorTest.java b/src/test/java/io/cryostat/net/web/http/api/v2/graph/SnapshotOnTargetMutatorTest.java index a2005081ed..4e31466e77 100644 --- a/src/test/java/io/cryostat/net/web/http/api/v2/graph/SnapshotOnTargetMutatorTest.java +++ b/src/test/java/io/cryostat/net/web/http/api/v2/graph/SnapshotOnTargetMutatorTest.java @@ -56,8 +56,6 @@ import graphql.GraphQLContext; import graphql.schema.DataFetchingEnvironment; -import io.vertx.core.MultiMap; -import io.vertx.core.http.HttpServerRequest; import io.vertx.ext.web.RoutingContext; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; @@ -73,8 +71,8 @@ class SnapshotOnTargetMutatorTest { SnapshotOnTargetMutator mutator; @Mock AuthManager auth; - @Mock CredentialsManager credentialsManager; @Mock RecordingTargetHelper recordingTargetHelper; + @Mock CredentialsManager credentialsManager; @Mock DataFetchingEnvironment env; @Mock GraphQLContext graphCtx; @@ -85,7 +83,7 @@ class SnapshotOnTargetMutatorTest { @BeforeEach void setup() { - this.mutator = new SnapshotOnTargetMutator(auth, credentialsManager, recordingTargetHelper); + this.mutator = new SnapshotOnTargetMutator(auth, recordingTargetHelper, credentialsManager); } @Test @@ -105,10 +103,6 @@ void shouldHaveExpectedRequiredPermissions() { @Test void shouldDeleteAndReturnSource() throws Exception { when(env.getGraphQlContext()).thenReturn(graphCtx); - when(graphCtx.get(RoutingContext.class)).thenReturn(ctx); - HttpServerRequest req = Mockito.mock(HttpServerRequest.class); - when(ctx.request()).thenReturn(req); - when(req.headers()).thenReturn(MultiMap.caseInsensitiveMultiMap()); when(auth.validateHttpHeader(Mockito.any(), Mockito.any())) .thenReturn(CompletableFuture.completedFuture(true)); diff --git a/src/test/java/io/cryostat/net/web/http/api/v2/graph/StartRecordingOnTargetMutatorTest.java b/src/test/java/io/cryostat/net/web/http/api/v2/graph/StartRecordingOnTargetMutatorTest.java index bd9bfe1a2b..7796609ecb 100644 --- a/src/test/java/io/cryostat/net/web/http/api/v2/graph/StartRecordingOnTargetMutatorTest.java +++ b/src/test/java/io/cryostat/net/web/http/api/v2/graph/StartRecordingOnTargetMutatorTest.java @@ -63,8 +63,6 @@ import com.google.gson.Gson; import graphql.GraphQLContext; import graphql.schema.DataFetchingEnvironment; -import io.vertx.core.MultiMap; -import io.vertx.core.http.HttpServerRequest; import io.vertx.ext.web.RoutingContext; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; @@ -80,10 +78,10 @@ class StartRecordingOnTargetMutatorTest { StartRecordingOnTargetMutator mutator; @Mock AuthManager auth; - @Mock CredentialsManager credentialsManager; @Mock TargetConnectionManager targetConnectionManager; @Mock RecordingTargetHelper recordingTargetHelper; @Mock RecordingOptionsBuilderFactory recordingOptionsBuilderFactory; + @Mock CredentialsManager credentialsManager; @Mock RecordingMetadataManager metadataManager; @Mock Provider webServer; @Mock Gson gson; @@ -99,10 +97,10 @@ void setup() { this.mutator = new StartRecordingOnTargetMutator( auth, - credentialsManager, targetConnectionManager, recordingTargetHelper, recordingOptionsBuilderFactory, + credentialsManager, metadataManager, webServer, gson); @@ -124,10 +122,6 @@ void shouldHaveExpectedRequiredPermissions() { @Test void shouldStartAndReturnRecording() throws Exception { when(env.getGraphQlContext()).thenReturn(graphCtx); - when(graphCtx.get(RoutingContext.class)).thenReturn(ctx); - HttpServerRequest req = Mockito.mock(HttpServerRequest.class); - when(ctx.request()).thenReturn(req); - when(req.headers()).thenReturn(MultiMap.caseInsensitiveMultiMap()); when(auth.validateHttpHeader(Mockito.any(), Mockito.any())) .thenReturn(CompletableFuture.completedFuture(true)); diff --git a/src/test/java/io/cryostat/net/web/http/api/v2/graph/StopRecordingMutatorTest.java b/src/test/java/io/cryostat/net/web/http/api/v2/graph/StopRecordingMutatorTest.java index 235040c0ec..71e8242224 100644 --- a/src/test/java/io/cryostat/net/web/http/api/v2/graph/StopRecordingMutatorTest.java +++ b/src/test/java/io/cryostat/net/web/http/api/v2/graph/StopRecordingMutatorTest.java @@ -59,8 +59,6 @@ import graphql.GraphQLContext; import graphql.schema.DataFetchingEnvironment; -import io.vertx.core.MultiMap; -import io.vertx.core.http.HttpServerRequest; import io.vertx.ext.web.RoutingContext; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; @@ -76,9 +74,9 @@ class StopRecordingMutatorTest { StopRecordingMutator mutator; @Mock AuthManager auth; - @Mock CredentialsManager credentialsManager; @Mock TargetConnectionManager targetConnectionManager; @Mock RecordingTargetHelper recordingTargetHelper; + @Mock CredentialsManager credentialsManager; @Mock RecordingMetadataManager metadataManager; @Mock Provider webServer; @@ -93,9 +91,9 @@ void setup() { this.mutator = new StopRecordingMutator( auth, - credentialsManager, targetConnectionManager, recordingTargetHelper, + credentialsManager, metadataManager, webServer); } @@ -115,10 +113,6 @@ void shouldHaveExpectedRequiredPermissions() { @Test void shouldStartAndReturnRecording() throws Exception { when(env.getGraphQlContext()).thenReturn(graphCtx); - when(graphCtx.get(RoutingContext.class)).thenReturn(ctx); - HttpServerRequest req = Mockito.mock(HttpServerRequest.class); - when(ctx.request()).thenReturn(req); - when(req.headers()).thenReturn(MultiMap.caseInsensitiveMultiMap()); when(auth.validateHttpHeader(Mockito.any(), Mockito.any())) .thenReturn(CompletableFuture.completedFuture(true)); diff --git a/src/test/java/io/cryostat/net/web/http/api/v2/graph/TargetNodeRecurseFetcherTest.java b/src/test/java/io/cryostat/net/web/http/api/v2/graph/TargetNodeRecurseFetcherTest.java index 4c002d5ed7..2b9fcb0336 100644 --- a/src/test/java/io/cryostat/net/web/http/api/v2/graph/TargetNodeRecurseFetcherTest.java +++ b/src/test/java/io/cryostat/net/web/http/api/v2/graph/TargetNodeRecurseFetcherTest.java @@ -47,7 +47,6 @@ import java.util.concurrent.CompletableFuture; import io.cryostat.UnknownNode; -import io.cryostat.configuration.CredentialsManager; import io.cryostat.net.AuthManager; import io.cryostat.net.security.ResourceAction; import io.cryostat.platform.ServiceRef; @@ -61,8 +60,6 @@ import graphql.GraphQLContext; import graphql.schema.DataFetchingEnvironment; import graphql.schema.DataFetchingEnvironmentImpl; -import io.vertx.core.MultiMap; -import io.vertx.core.http.HttpServerRequest; import io.vertx.ext.web.RoutingContext; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; @@ -87,7 +84,6 @@ class TargetNodeRecurseFetcherTest { TargetNodeRecurseFetcher fetcher; @Mock AuthManager auth; - @Mock CredentialsManager credentialsManager; @Mock DataFetchingEnvironment env; @Mock GraphQLContext graphCtx; @@ -99,7 +95,7 @@ class TargetNodeRecurseFetcherTest { @BeforeEach void setup() { - this.fetcher = new TargetNodeRecurseFetcher(auth, credentialsManager); + this.fetcher = new TargetNodeRecurseFetcher(auth); } @Test @@ -126,16 +122,10 @@ void shouldThrowIllegalStateExceptionOnUnknownNode() throws Exception { @Test void shouldReturnSource() throws Exception { when(env.getGraphQlContext()).thenReturn(graphCtx); - when(graphCtx.get(RoutingContext.class)).thenReturn(ctx); - HttpServerRequest req = Mockito.mock(HttpServerRequest.class); - when(ctx.request()).thenReturn(req); - when(req.headers()).thenReturn(MultiMap.caseInsensitiveMultiMap()); when(auth.validateHttpHeader(Mockito.any(), Mockito.any())) .thenReturn(CompletableFuture.completedFuture(true)); TargetNode source = Mockito.mock(TargetNode.class); - ServiceRef sr = new ServiceRef("id1", URI.create("uri1"), "alias1"); - when(source.getTarget()).thenReturn(sr); when(env.getSource()).thenReturn(source); @@ -156,10 +146,6 @@ void shouldReturnTargetNodes() throws Exception { Mockito.any(DataFetchingEnvironment.class))) .thenReturn(builder); when(env.getGraphQlContext()).thenReturn(graphCtx); - when(graphCtx.get(RoutingContext.class)).thenReturn(ctx); - HttpServerRequest req = Mockito.mock(HttpServerRequest.class); - when(ctx.request()).thenReturn(req); - when(req.headers()).thenReturn(MultiMap.caseInsensitiveMultiMap()); when(auth.validateHttpHeader(Mockito.any(), Mockito.any())) .thenReturn(CompletableFuture.completedFuture(true)); @@ -232,10 +218,6 @@ void shouldReturnTargetNodeFiltered() throws Exception { .when(() -> FilterInput.from(Mockito.any(DataFetchingEnvironment.class))) .thenReturn(filter); when(env.getGraphQlContext()).thenReturn(graphCtx); - when(graphCtx.get(RoutingContext.class)).thenReturn(ctx); - HttpServerRequest req = Mockito.mock(HttpServerRequest.class); - when(ctx.request()).thenReturn(req); - when(req.headers()).thenReturn(MultiMap.caseInsensitiveMultiMap()); when(auth.validateHttpHeader(Mockito.any(), Mockito.any())) .thenReturn(CompletableFuture.completedFuture(true)); diff --git a/src/test/java/io/cryostat/net/web/http/api/v2/graph/TargetNodesFetcherTest.java b/src/test/java/io/cryostat/net/web/http/api/v2/graph/TargetNodesFetcherTest.java index 82d86f570e..c4dfa36875 100644 --- a/src/test/java/io/cryostat/net/web/http/api/v2/graph/TargetNodesFetcherTest.java +++ b/src/test/java/io/cryostat/net/web/http/api/v2/graph/TargetNodesFetcherTest.java @@ -41,13 +41,11 @@ import static org.mockito.Mockito.lenient; import static org.mockito.Mockito.when; -import java.net.URI; import java.util.List; import java.util.Map; import java.util.Set; import java.util.concurrent.CompletableFuture; -import io.cryostat.configuration.CredentialsManager; import io.cryostat.net.AuthManager; import io.cryostat.net.security.ResourceAction; import io.cryostat.platform.ServiceRef; @@ -57,8 +55,6 @@ import graphql.GraphQLContext; import graphql.schema.DataFetchingEnvironment; import graphql.schema.DataFetchingEnvironmentImpl; -import io.vertx.core.MultiMap; -import io.vertx.core.http.HttpServerRequest; import io.vertx.ext.web.RoutingContext; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; @@ -75,7 +71,6 @@ class TargetNodesFetcherTest { TargetNodesFetcher fetcher; @Mock AuthManager auth; - @Mock CredentialsManager credentialsManager; @Mock RootNodeFetcher rootNodeFetcher; @Mock TargetNodeRecurseFetcher recurseFetcher; @@ -89,8 +84,7 @@ class TargetNodesFetcherTest { @BeforeEach void setup() { - this.fetcher = - new TargetNodesFetcher(auth, credentialsManager, rootNodeFetcher, recurseFetcher); + this.fetcher = new TargetNodesFetcher(auth, rootNodeFetcher, recurseFetcher); } @Test @@ -128,16 +122,10 @@ void shouldReturnTarget() throws Exception { .when(() -> DataFetchingEnvironmentImpl.newDataFetchingEnvironment(env)) .thenReturn(builder); when(env.getGraphQlContext()).thenReturn(graphCtx); - when(graphCtx.get(RoutingContext.class)).thenReturn(ctx); - HttpServerRequest req = Mockito.mock(HttpServerRequest.class); - when(ctx.request()).thenReturn(req); - when(req.headers()).thenReturn(MultiMap.caseInsensitiveMultiMap()); when(auth.validateHttpHeader(Mockito.any(), Mockito.any())) .thenReturn(CompletableFuture.completedFuture(true)); TargetNode target = Mockito.mock(TargetNode.class); - ServiceRef sr = new ServiceRef("id", URI.create("sr"), "alias"); - when(target.getTarget()).thenReturn(sr); when(recurseFetcher.get(Mockito.any())).thenReturn(List.of(target)); @@ -159,10 +147,6 @@ void shouldReturnTargetsFiltered() throws Exception { staticFilter.when(() -> FilterInput.from(env)).thenReturn(filter); when(env.getGraphQlContext()).thenReturn(graphCtx); - when(graphCtx.get(RoutingContext.class)).thenReturn(ctx); - HttpServerRequest req = Mockito.mock(HttpServerRequest.class); - when(ctx.request()).thenReturn(req); - when(req.headers()).thenReturn(MultiMap.caseInsensitiveMultiMap()); when(auth.validateHttpHeader(Mockito.any(), Mockito.any())) .thenReturn(CompletableFuture.completedFuture(true)); @@ -174,13 +158,9 @@ void shouldReturnTargetsFiltered() throws Exception { TargetNode target2 = Mockito.mock(TargetNode.class); TargetNode target3 = Mockito.mock(TargetNode.class); - ServiceRef sr = new ServiceRef("id", URI.create("sr"), "alias"); - when(target1.getName()).thenReturn("foo"); - when(target1.getTarget()).thenReturn(sr); when(target2.getName()).thenReturn("foobar"); when(target3.getName()).thenReturn("foo"); - when(target3.getTarget()).thenReturn(sr); when(recurseFetcher.get(Mockito.any())) .thenReturn(List.of(target1, target2, target3)); @@ -204,10 +184,6 @@ void shouldReturnTargetsMultipleFilters() throws Exception { staticFilter.when(() -> FilterInput.from(env)).thenReturn(filter); when(env.getGraphQlContext()).thenReturn(graphCtx); - when(graphCtx.get(RoutingContext.class)).thenReturn(ctx); - HttpServerRequest req = Mockito.mock(HttpServerRequest.class); - when(ctx.request()).thenReturn(req); - when(req.headers()).thenReturn(MultiMap.caseInsensitiveMultiMap()); when(auth.validateHttpHeader(Mockito.any(), Mockito.any())) .thenReturn(CompletableFuture.completedFuture(true)); @@ -230,12 +206,8 @@ void shouldReturnTargetsMultipleFilters() throws Exception { // annotation mocking ServiceRef ref1 = Mockito.mock(ServiceRef.class); - when(ref1.getServiceUri()).thenReturn(URI.create("uri1")); - when(target1.getTarget()).thenReturn(ref1); ServiceRef ref2 = Mockito.mock(ServiceRef.class); - when(target2.getTarget()).thenReturn(ref2); ServiceRef ref3 = Mockito.mock(ServiceRef.class); - when(target3.getTarget()).thenReturn(ref3); when(ref1.getCryostatAnnotations()) .thenReturn( Map.of( diff --git a/src/test/java/itest/AutoRulesCleanupIT.java b/src/test/java/itest/AutoRulesCleanupIT.java index fdd9438bb0..57d67437cb 100644 --- a/src/test/java/itest/AutoRulesCleanupIT.java +++ b/src/test/java/itest/AutoRulesCleanupIT.java @@ -223,9 +223,6 @@ void testAddRule() throws TimeoutException, InterruptedException, ExecutionExcep @Order(2) void testAddRuleTriggersRecordingCreation() throws TimeoutException, InterruptedException, ExecutionException { - // give time for the rule creation in the last test to trigger and execute. TODO listen for - // the corresponding WebSocket notification instead of sleeping - Thread.sleep(1_000); CompletableFuture future = new CompletableFuture<>(); webClient .get(String.format("/api/v1/targets/%s/recordings", jmxServiceUrlEncoded)) diff --git a/src/test/java/itest/CredentialsV2_2IT.java b/src/test/java/itest/CredentialsV2_2IT.java index 91896e1a1a..81cb0f8fca 100644 --- a/src/test/java/itest/CredentialsV2_2IT.java +++ b/src/test/java/itest/CredentialsV2_2IT.java @@ -72,6 +72,7 @@ import org.hamcrest.Matchers; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.MethodOrderer.OrderAnnotation; import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; @@ -290,6 +291,7 @@ void testAddCredentialsThrowsOnBlankPassword(String password) throws Exception { } @Test + @Disabled("TODO: Fix the way jvmIds are queried with credential permissions using GraphQL") @Order(8) void testWorkflow() throws Exception { List targetIds = startTargets(); @@ -498,6 +500,7 @@ void testWorkflow() throws Exception { } @Test + @Disabled("TODO: Fix the way jvmIds are queried with credential permissions using GraphQL") @Order(9) void testDeletion() throws Exception { CompletableFuture getResponse = new CompletableFuture<>(); diff --git a/src/test/java/itest/InterleavedExternalTargetRequestsIT.java b/src/test/java/itest/InterleavedExternalTargetRequestsIT.java index 6d3db3e373..9fa48781dd 100644 --- a/src/test/java/itest/InterleavedExternalTargetRequestsIT.java +++ b/src/test/java/itest/InterleavedExternalTargetRequestsIT.java @@ -45,6 +45,7 @@ import java.util.Map; import java.util.Set; import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; @@ -56,10 +57,8 @@ import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; import io.vertx.core.MultiMap; -import io.vertx.core.buffer.Buffer; import io.vertx.core.json.JsonArray; import io.vertx.core.json.JsonObject; -import io.vertx.ext.web.client.HttpRequest; import itest.bases.ExternalTargetsTest; import itest.util.ITestCleanupFailedException; import itest.util.Podman; @@ -67,6 +66,7 @@ import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.MethodOrderer.OrderAnnotation; import org.junit.jupiter.api.Order; @@ -78,7 +78,6 @@ class InterleavedExternalTargetRequestsIT extends ExternalTargetsTest { private static final Gson gson = MainModule.provideGson(Logger.INSTANCE); - static final int BASE_PORT = 9093; static final int NUM_EXT_CONTAINERS = 4; static final int NUM_AUTH_EXT_CONTAINERS = 4; static final int NUM_EXT_CONTAINERS_TOTAL = NUM_EXT_CONTAINERS + NUM_AUTH_EXT_CONTAINERS; @@ -90,7 +89,7 @@ static void setup() throws Exception { for (int i = 0; i < NUM_EXT_CONTAINERS; i++) { specs.add( new Podman.ImageSpec( - FIB_DEMO_IMAGESPEC, Map.of("JMX_PORT", String.valueOf(BASE_PORT + i)))); + FIB_DEMO_IMAGESPEC, Map.of("JMX_PORT", String.valueOf(9093 + i)))); } for (int i = 0; i < NUM_AUTH_EXT_CONTAINERS; i++) { specs.add( @@ -98,7 +97,7 @@ static void setup() throws Exception { FIB_DEMO_IMAGESPEC, Map.of( "JMX_PORT", - String.valueOf(BASE_PORT + NUM_EXT_CONTAINERS + i), + String.valueOf(9093 + NUM_EXT_CONTAINERS + i), "USE_AUTH", "true"))); } @@ -169,7 +168,7 @@ void testOtherContainersFound() throws Exception { new URI( String.format( "service:jmx:rmi:///jndi/rmi://%s:%d/jmxrmi", - Podman.POD_NAME, BASE_PORT + i)); + Podman.POD_NAME, 9093 + i)); String jvmId = JvmIdWebRequest.jvmIdRequest(uri, VERTX_FIB_CREDENTIALS); ServiceRef ext = new ServiceRef(jvmId, uri, "es.andrewazor.demo.Main"); ext.setCryostatAnnotations( @@ -181,7 +180,7 @@ void testOtherContainersFound() throws Exception { AnnotationKey.HOST, Podman.POD_NAME, AnnotationKey.PORT, - Integer.toString(BASE_PORT + i))); + Integer.toString(9093 + i))); expected.add(ext); } MatcherAssert.assertThat(actual, Matchers.equalTo(expected)); @@ -190,6 +189,8 @@ void testOtherContainersFound() throws Exception { @Test @Order(2) public void testInterleavedRequests() throws Exception { + /* FIXME: Fix front-end credentials handling with JMX auth and jvmIds so test can be re-enabled */ + /* See https://github.com/cryostatio/cryostat-web/issues/656 */ long start = System.nanoTime(); createInMemoryRecordings(false); @@ -200,36 +201,17 @@ public void testInterleavedRequests() throws Exception { verifyInMemoryRecordingsDeleted(false); - // Assertions.assertThrows( - // ExecutionException.class, - // () -> { - createInMemoryRecordings(true); + Assertions.assertThrows( + ExecutionException.class, + () -> { + createInMemoryRecordings(true); - verifyInMemoryRecordingsCreated(true); + verifyInMemoryRecordingsCreated(true); - deleteInMemoryRecordings(true); + deleteInMemoryRecordings(true); - verifyInMemoryRecordingsDeleted(true); - // }); - - long stop = System.nanoTime(); - long elapsed = stop - start; - System.out.println( - String.format("Elapsed time: %dms", TimeUnit.NANOSECONDS.toMillis(elapsed))); - } - - @Test - @Order(2) - public void testInterleavedRequestsWithAuth() throws Exception { - long start = System.nanoTime(); - - createInMemoryRecordings(true); - - verifyInMemoryRecordingsCreated(true); - - deleteInMemoryRecordings(true); - - verifyInMemoryRecordingsDeleted(true); + verifyInMemoryRecordingsDeleted(true); + }); long stop = System.nanoTime(); long elapsed = stop - start; @@ -239,7 +221,7 @@ public void testInterleavedRequestsWithAuth() throws Exception { private void createInMemoryRecordings(boolean useAuth) throws Exception { List> cfs = new ArrayList<>(); - int TARGET_PORT_NUMBER_START = useAuth ? (BASE_PORT + NUM_EXT_CONTAINERS) : BASE_PORT; + int TARGET_PORT_NUMBER_START = useAuth ? (9093 + NUM_EXT_CONTAINERS) : 9093; for (int i = 0; i < (useAuth ? NUM_AUTH_EXT_CONTAINERS : NUM_EXT_CONTAINERS); i++) { final int fi = i; CompletableFuture cf = new CompletableFuture<>(); @@ -249,30 +231,26 @@ private void createInMemoryRecordings(boolean useAuth) throws Exception { MultiMap form = MultiMap.caseInsensitiveMultiMap(); form.add("recordingName", "interleaved-" + fi); form.add("events", "template=Continuous"); - HttpRequest req = - webClient.post( + webClient + .post( String.format( "/api/v1/targets/%s/recordings", Podman.POD_NAME + ":" - + (TARGET_PORT_NUMBER_START + fi))); - if (useAuth) { - req = - req.putHeader( - "X-JMX-Authorization", - "Basic " - + Base64.getUrlEncoder() - .encodeToString( - "admin:adminpass123" - .getBytes())); - } - req.sendForm( - form, - ar -> { - if (assertRequestStatus(ar, cf)) { - cf.complete(null); - } - }); + + (TARGET_PORT_NUMBER_START + fi))) + .putHeader( + "X-JMX-Authorization", + "Basic " + + Base64.getUrlEncoder() + .encodeToString( + "admin:adminpass123".getBytes())) + .sendForm( + form, + ar -> { + if (assertRequestStatus(ar, cf)) { + cf.complete(null); + } + }); }); } CompletableFuture.allOf(cfs.toArray(new CompletableFuture[0])) @@ -281,42 +259,40 @@ private void createInMemoryRecordings(boolean useAuth) throws Exception { private void verifyInMemoryRecordingsCreated(boolean useAuth) throws Exception { List> cfs = new ArrayList<>(); - int TARGET_PORT_NUMBER_START = useAuth ? (BASE_PORT + NUM_EXT_CONTAINERS) : BASE_PORT; + int TARGET_PORT_NUMBER_START = useAuth ? (9093 + NUM_EXT_CONTAINERS) : 9093; for (int i = 0; i < (useAuth ? NUM_AUTH_EXT_CONTAINERS : NUM_EXT_CONTAINERS); i++) { final int fi = i; CompletableFuture cf = new CompletableFuture<>(); cfs.add(cf); - HttpRequest req = - webClient.get( + webClient + .get( String.format( "/api/v1/targets/%s/recordings", - Podman.POD_NAME + ":" + (TARGET_PORT_NUMBER_START + fi))); - if (useAuth) { - req = - req.putHeader( - "X-JMX-Authorization", - "Basic " - + Base64.getUrlEncoder() - .encodeToString("admin:adminpass123".getBytes())); - } - req.send( - ar -> { - if (assertRequestStatus(ar, cf)) { - JsonArray listResp = ar.result().bodyAsJsonArray(); - MatcherAssert.assertThat( - "list should have size 1 after recording creation", - listResp.size(), - Matchers.equalTo(1)); - JsonObject recordingInfo = listResp.getJsonObject(0); - MatcherAssert.assertThat( - recordingInfo.getString("name"), - Matchers.equalTo("interleaved-" + fi)); - MatcherAssert.assertThat( - recordingInfo.getString("state"), Matchers.equalTo("RUNNING")); + Podman.POD_NAME + ":" + (TARGET_PORT_NUMBER_START + fi))) + .putHeader( + "X-JMX-Authorization", + "Basic " + + Base64.getUrlEncoder() + .encodeToString("admin:adminpass123".getBytes())) + .send( + ar -> { + if (assertRequestStatus(ar, cf)) { + JsonArray listResp = ar.result().bodyAsJsonArray(); + MatcherAssert.assertThat( + "list should have size 1 after recording creation", + listResp.size(), + Matchers.equalTo(1)); + JsonObject recordingInfo = listResp.getJsonObject(0); + MatcherAssert.assertThat( + recordingInfo.getString("name"), + Matchers.equalTo("interleaved-" + fi)); + MatcherAssert.assertThat( + recordingInfo.getString("state"), + Matchers.equalTo("RUNNING")); - cf.complete(null); - } - }); + cf.complete(null); + } + }); } CompletableFuture.allOf(cfs.toArray(new CompletableFuture[0])) .get(REQUEST_TIMEOUT_SECONDS, TimeUnit.SECONDS); @@ -324,7 +300,7 @@ private void verifyInMemoryRecordingsCreated(boolean useAuth) throws Exception { private void deleteInMemoryRecordings(boolean useAuth) throws Exception { List> cfs = new ArrayList<>(); - int TARGET_PORT_NUMBER_START = useAuth ? (BASE_PORT + NUM_EXT_CONTAINERS) : BASE_PORT; + int TARGET_PORT_NUMBER_START = useAuth ? (9093 + NUM_EXT_CONTAINERS) : 9093; for (int i = 0; i < (useAuth ? NUM_AUTH_EXT_CONTAINERS : NUM_EXT_CONTAINERS); i++) { final int fi = i; CompletableFuture cf = new CompletableFuture<>(); @@ -332,31 +308,27 @@ private void deleteInMemoryRecordings(boolean useAuth) throws Exception { Podman.POOL.submit( () -> { MultiMap form = MultiMap.caseInsensitiveMultiMap(); - HttpRequest req = - webClient.delete( + webClient + .delete( String.format( "/api/v1/targets/%s/recordings/%s", Podman.POD_NAME + ":" + (TARGET_PORT_NUMBER_START + fi), - "interleaved-" + fi)); - if (useAuth) { - req = - req.putHeader( - "X-JMX-Authorization", - "Basic " - + Base64.getUrlEncoder() - .encodeToString( - "admin:adminpass123" - .getBytes())); - } - req.sendForm( - form, - ar -> { - if (assertRequestStatus(ar, cf)) { - cf.complete(null); - } - }); + "interleaved-" + fi)) + .putHeader( + "X-JMX-Authorization", + "Basic " + + Base64.getUrlEncoder() + .encodeToString( + "admin:adminpass123".getBytes())) + .sendForm( + form, + ar -> { + if (assertRequestStatus(ar, cf)) { + cf.complete(null); + } + }); }); } CompletableFuture.allOf(cfs.toArray(new CompletableFuture[0])) @@ -365,35 +337,32 @@ private void deleteInMemoryRecordings(boolean useAuth) throws Exception { private void verifyInMemoryRecordingsDeleted(boolean useAuth) throws Exception { List> cfs = new ArrayList<>(); - int TARGET_PORT_NUMBER_START = useAuth ? (BASE_PORT + NUM_EXT_CONTAINERS) : BASE_PORT; + int TARGET_PORT_NUMBER_START = useAuth ? (9093 + NUM_EXT_CONTAINERS) : 9093; for (int i = 0; i < (useAuth ? NUM_AUTH_EXT_CONTAINERS : NUM_EXT_CONTAINERS); i++) { final int fi = i; CompletableFuture cf = new CompletableFuture<>(); cfs.add(cf); - HttpRequest req = - webClient.get( + webClient + .get( String.format( "/api/v1/targets/%s/recordings", - Podman.POD_NAME + ":" + (TARGET_PORT_NUMBER_START + fi))); - if (useAuth) { - req = - req.putHeader( - "X-JMX-Authorization", - "Basic " - + Base64.getUrlEncoder() - .encodeToString("admin:adminpass123".getBytes())); - } - req.send( - ar -> { - if (assertRequestStatus(ar, cf)) { - JsonArray listResp = ar.result().bodyAsJsonArray(); - MatcherAssert.assertThat( - "list should have size 0 after recording deletion", - listResp.size(), - Matchers.equalTo(0)); - cf.complete(null); - } - }); + Podman.POD_NAME + ":" + (TARGET_PORT_NUMBER_START + fi))) + .putHeader( + "X-JMX-Authorization", + "Basic " + + Base64.getUrlEncoder() + .encodeToString("admin:adminpass123".getBytes())) + .send( + ar -> { + if (assertRequestStatus(ar, cf)) { + JsonArray listResp = ar.result().bodyAsJsonArray(); + MatcherAssert.assertThat( + "list should have size 0 after recording deletion", + listResp.size(), + Matchers.equalTo(0)); + cf.complete(null); + } + }); } CompletableFuture.allOf(cfs.toArray(new CompletableFuture[0])) .get(REQUEST_TIMEOUT_SECONDS, TimeUnit.SECONDS); diff --git a/src/test/java/itest/JmxSessionAuthIT.java b/src/test/java/itest/JmxAuthIT.java similarity index 63% rename from src/test/java/itest/JmxSessionAuthIT.java rename to src/test/java/itest/JmxAuthIT.java index da88207e8c..3ca0b1e948 100644 --- a/src/test/java/itest/JmxSessionAuthIT.java +++ b/src/test/java/itest/JmxAuthIT.java @@ -37,22 +37,15 @@ */ package itest; -import java.io.InputStream; -import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Base64; import java.util.List; import java.util.Map; import java.util.concurrent.CompletableFuture; -import io.vertx.core.buffer.Buffer; -import io.vertx.core.json.JsonObject; -import io.vertx.ext.web.client.HttpResponse; import itest.bases.ExternalTargetsTest; import itest.util.ITestCleanupFailedException; import itest.util.Podman; -import org.apache.commons.io.IOUtils; -import org.apache.commons.lang3.tuple.Pair; import org.hamcrest.Matcher; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; @@ -60,7 +53,7 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -public class JmxSessionAuthIT extends ExternalTargetsTest { +public class JmxAuthIT extends ExternalTargetsTest { private static final String TARGET_BASIC_CREDENTIALS = "Basic " + Base64.getEncoder().encodeToString("admin:adminpass123".getBytes()); @@ -82,12 +75,7 @@ static void setup() throws Exception { new Podman.ImageSpec( FIB_DEMO_IMAGESPEC, Map.of("JMX_PORT", "9093", "USE_AUTH", "true")))); - CONTAINERS.add( - Podman.run( - new Podman.ImageSpec( - FIB_DEMO_IMAGESPEC, - Map.of("JMX_PORT", "9094", "USE_AUTH", "true")))); - waitForDiscovery(2); + waitForDiscovery(1); } @AfterAll @@ -177,75 +165,4 @@ void checkStatusForV2EventsQueryWithoutCredentials() throws Exception { .send(ar -> response.complete(ar.result().statusCode())); MatcherAssert.assertThat(response.get(), SC_JMX_AUTH_FAIL); } - - @Test - void checkStatusForGraphqlQueryWithCredentials() throws Exception { - CompletableFuture> response = new CompletableFuture<>(); - try (InputStream is = - getClass().getClassLoader().getResourceAsStream("JmxSessionAuthIT.query.graphql")) { - String query = IOUtils.toString(is, StandardCharsets.UTF_8); - webClient - .post("/api/v2.2/graphql") - .putHeader(X_JMX_AUTHORIZATION, TARGET_BASIC_CREDENTIALS) - .sendJsonObject( - new JsonObject(Map.of("query", query)), - ar -> { - HttpResponse result = ar.result(); - response.complete( - Pair.of(result.statusCode(), result.bodyAsString())); - }); - Pair pair = response.get(); - MatcherAssert.assertThat(pair.getLeft(), SC_OK_RANGE); - JsonObject result = new JsonObject(pair.getRight()); - MatcherAssert.assertThat( - pair.getRight(), - Matchers.not( - Matchers.containsString(" org.openjdk.jmc.rjmx.ConnectionException"))); - for (int i = 0; i < CONTAINERS.size(); i++) { - long uptime = - result.getJsonObject("data") - .getJsonArray("targetNodes") - .getJsonObject(i) - .getJsonObject("mbeanMetrics") - .getJsonObject("runtime") - .getLong("uptime"); - MatcherAssert.assertThat(uptime, Matchers.greaterThan(0L)); - - String mbeanJvmId = - result.getJsonObject("data") - .getJsonArray("targetNodes") - .getJsonObject(i) - .getJsonObject("mbeanMetrics") - .getString("jvmId"); - MatcherAssert.assertThat(mbeanJvmId, Matchers.not(Matchers.emptyOrNullString())); - } - } - } - - @Test - void checkStatusForGraphqlQueryWithoutCredentials() throws Exception { - CompletableFuture> response = new CompletableFuture<>(); - try (InputStream is = - getClass().getClassLoader().getResourceAsStream("JmxSessionAuthIT.query.graphql")) { - String query = IOUtils.toString(is, StandardCharsets.UTF_8); - webClient - .post("/api/v2.2/graphql") - .sendJsonObject( - new JsonObject(Map.of("query", query)), - ar -> { - HttpResponse result = ar.result(); - response.complete( - Pair.of(result.statusCode(), result.bodyAsString())); - }); - Pair pair = response.get(); - MatcherAssert.assertThat(pair.getLeft(), SC_OK_RANGE); - MatcherAssert.assertThat( - pair.getRight(), - Matchers.containsString( - "Exception while fetching data (/targetNodes[0]/mbeanMetrics) :" - + " org.openjdk.jmc.rjmx.ConnectionException caused by" - + " java.lang.SecurityException: Authentication failed! Invalid" - + " username or password")); - } - } } diff --git a/src/test/resources/JmxSessionAuthIT.query.graphql b/src/test/resources/JmxSessionAuthIT.query.graphql deleted file mode 100644 index b9e8fa48b7..0000000000 --- a/src/test/resources/JmxSessionAuthIT.query.graphql +++ /dev/null @@ -1,11 +0,0 @@ -query { - targetNodes(filter: { annotations: ["PORT in (9093, 9094)"] }) { - name - mbeanMetrics { - runtime { - uptime - } - jvmId - } - } -}