chore: adding logging in AuthorizationIPCAgent
@@ -7,6 +7,8 @@ package com.aws.greengrass.authorization;
import com.aws.greengrass.ipc.AuthenticationHandler;
import com.aws.greengrass.ipc.exceptions.UnauthenticatedException;
+import com.aws.greengrass.logging.api.Logger;
+import com.aws.greengrass.logging.impl.LogManager;
import lombok.AccessLevel;
import lombok.Setter;
import software.amazon.awssdk.aws.greengrass.GeneratedAbstractValidateAuthorizationTokenOperationHandler;
@@ -30,6 +32,7 @@ public class AuthorizationIPCAgent {
public static final String STREAM_MANAGER_SERVICE_NAME = "aws.greengrass.StreamManager";
private static final List<String> AUTHORIZED_COMPONENTS = Collections.singletonList(STREAM_MANAGER_SERVICE_NAME);
+ private static final Logger logger = LogManager.getLogger(AuthorizationIPCAgent.class);
@Inject
@Setter(AccessLevel.PACKAGE)
private AuthenticationHandler authenticationHandler;
@@ -62,6 +65,8 @@ public class AuthorizationIPCAgent {
@Override
public ValidateAuthorizationTokenResponse handleRequest(ValidateAuthorizationTokenRequest request) {
if (!AUTHORIZED_COMPONENTS.contains(serviceName)) {
+ logger.atDebug("service-unauthorized-error").log("{} is not authorized to perform {}",
+ serviceName, this.getOperationModelContext().getOperationName());
throw new UnauthorizedError(String.format("%s is not authorized to perform %s", serviceName,
this.getOperationModelContext().getOperationName()));
}
@@ -69,8 +74,12 @@ public class AuthorizationIPCAgent {
try {
authenticationHandler.doAuthentication(request.getToken());
response.setIsValid(true);
+ logger.atDebug("authorization-validated").log("Authorization validated for {} for {}",
+ serviceName, this.getOperationModelContext().getOperationName());
return response;
} catch (UnauthenticatedException e) {
+ logger.atDebug("invalid-token-error").log("Invalid token used when trying to authorize {} "
+ + "to perform {}", serviceName, this.getOperationModelContext().getOperationName());
throw new InvalidTokenError(e.getMessage());
}
}
