Skip to content

Commit

Permalink
reduce log level of 2 WARN log messages to INFO
Browse files Browse the repository at this point in the history
* and get rid of thrown IllegalStateException, causing log WARNings

Signed-off-by: Thomas Jäckle <thomas.jaeckle@beyonnex.io>
  • Loading branch information
thjaeckle committed Oct 10, 2023
1 parent 795f574 commit 53e8cad
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
import java.util.concurrent.CompletionStage;
import java.util.function.Function;

import org.apache.pekko.http.javadsl.model.HttpHeader;
import org.apache.pekko.http.javadsl.server.AuthorizationFailedRejection;
import org.apache.pekko.http.javadsl.server.Directives;
import org.apache.pekko.http.javadsl.server.RequestContext;
import org.apache.pekko.http.javadsl.server.Route;
import org.eclipse.ditto.base.model.headers.DittoHeaders;
import org.eclipse.ditto.gateway.api.GatewayAuthenticationFailedException;
import org.eclipse.ditto.gateway.service.security.authentication.AuthenticationResult;
Expand All @@ -28,11 +33,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.apache.pekko.http.javadsl.model.HttpHeader;
import org.apache.pekko.http.javadsl.server.AuthorizationFailedRejection;
import org.apache.pekko.http.javadsl.server.Directives;
import org.apache.pekko.http.javadsl.server.RequestContext;
import org.apache.pekko.http.javadsl.server.Route;
import scala.util.Try;

/**
Expand Down Expand Up @@ -123,7 +123,7 @@ private Route handleAuthenticationTry(final Try<AuthenticationResult> authentica
if (authenticationResultTry.isSuccess()) {
final AuthenticationResult authenticationResult = authenticationResultTry.get();
if (!authenticationResult.isSuccess()) {
LOGGER.warn("DevOps Oauth authentication was not successful for request: '{}' because of '{}'.",
LOGGER.info("DevOps OAuth authentication was not successful for request: '{}' because of '{}'.",
requestContext.getRequest(), authenticationResult.getReasonOfFailure().getMessage());
return Directives.failWith(authenticationResult.getReasonOfFailure());
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,18 @@
import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;

import org.eclipse.ditto.json.JsonRuntimeException;
import org.eclipse.ditto.base.model.exceptions.DittoJsonException;
import org.eclipse.ditto.base.model.exceptions.DittoRuntimeException;
import org.eclipse.ditto.base.model.headers.DittoHeaders;
import org.eclipse.ditto.internal.utils.pekko.logging.DittoLoggerFactory;
import org.eclipse.ditto.internal.utils.pekko.logging.ThreadSafeDittoLogger;

import org.apache.pekko.http.javadsl.model.HttpResponse;
import org.apache.pekko.http.javadsl.model.StatusCodes;
import org.apache.pekko.http.javadsl.server.Directives;
import org.apache.pekko.http.javadsl.server.ExceptionHandler;
import org.apache.pekko.http.javadsl.server.Route;
import org.apache.pekko.japi.pf.FI;
import org.eclipse.ditto.base.model.exceptions.DittoJsonException;
import org.eclipse.ditto.base.model.exceptions.DittoRuntimeException;
import org.eclipse.ditto.base.model.headers.DittoHeaders;
import org.eclipse.ditto.internal.utils.pekko.logging.DittoLoggerFactory;
import org.eclipse.ditto.internal.utils.pekko.logging.ThreadSafeDittoLogger;
import org.eclipse.ditto.json.JsonRuntimeException;

/**
* This class provides an {@link ExceptionHandler} for the root route.
Expand Down Expand Up @@ -104,7 +103,7 @@ private static void logException(final DittoRuntimeException exception) {
final Optional<String> correlationIdOptional = dittoHeaders.getCorrelationId();
final String simpleExceptionName = exception.getClass().getSimpleName();
if (correlationIdOptional.isEmpty()) {
LOGGER.warn("Correlation ID was missing in headers of <{}>!", simpleExceptionName);
LOGGER.info("Correlation ID was missing in headers of <{}>!", simpleExceptionName);
}

// We do not want to print stack trace of exception thus exception must not be last argument of logger call.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@
import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;

import org.apache.pekko.http.javadsl.server.RequestContext;
import org.eclipse.ditto.base.model.headers.DittoHeaders;
import org.eclipse.ditto.gateway.api.GatewayAuthenticationFailedException;
import org.eclipse.ditto.internal.utils.pekko.logging.DittoLoggerFactory;
import org.eclipse.ditto.internal.utils.pekko.logging.ThreadSafeDittoLogger;

import org.apache.pekko.http.javadsl.server.RequestContext;

/**
* Handles authentication by multiple authentication providers.
*/
Expand Down Expand Up @@ -199,8 +199,9 @@ private CompletableFuture<AuthResultAccumulator> andThen(

private AuthenticationResult asFailure() {
if (failureResults.isEmpty()) {
return DefaultAuthenticationResult.failed(dittoHeaders,
new IllegalStateException("No applicable authentication provider was found!"));
return DefaultAuthenticationResult.failed(dittoHeaders, GatewayAuthenticationFailedException
.newBuilder("No applicable authentication provider was found!")
.build());
}

if (1 == failureResults.size()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

import org.apache.pekko.http.javadsl.server.RequestContext;
import org.assertj.core.api.JUnitSoftAssertions;
import org.eclipse.ditto.base.model.auth.AuthorizationContext;
import org.eclipse.ditto.base.model.auth.AuthorizationSubject;
Expand All @@ -46,8 +47,6 @@
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;

import org.apache.pekko.http.javadsl.server.RequestContext;

/**
* Unit test for {@link AuthenticationChain}.
*/
Expand Down Expand Up @@ -144,8 +143,9 @@ public void authenticateReturnsIllegalStateAuthenticationResultIfCalledWhenNoPro
throws ExecutionException, InterruptedException {

final RequestContext requestContextMock = mock(RequestContext.class);
final IllegalStateException expectedException = new IllegalStateException("No applicable authentication " +
"provider was found!");
final GatewayAuthenticationFailedException expectedException = GatewayAuthenticationFailedException
.newBuilder("No applicable authentication provider was found!")
.build();
when(authenticationProviderA.isApplicable(requestContextMock)).thenReturn(false);
when(authenticationProviderB.isApplicable(requestContextMock)).thenReturn(false);
final AuthenticationChain underTest =
Expand Down

0 comments on commit 53e8cad

Please sign in to comment.