use of software.amazon.awssdk.eventstreamrpc.GreengrassEventStreamConnectMessage in project aws-greengrass-nucleus by aws-greengrass.
the class IPCEventStreamService method ipcAuthenticationHandler.
@SuppressWarnings({ "PMD.UnusedFormalParameter", "PMD.PreserveStackTrace" })
private AuthenticationData ipcAuthenticationHandler(byte[] payload) {
String authToken = null;
try {
GreengrassEventStreamConnectMessage connectMessage = OBJECT_MAPPER.readValue(payload, GreengrassEventStreamConnectMessage.class);
authToken = connectMessage.getAuthToken();
} catch (IOException e) {
String errorMessage = "Invalid auth token in connect message";
logger.atError().setCause(e).log(errorMessage);
// GG_NEEDS_REVIEW: TODO: Add BadRequestException to smithy model
throw new RuntimeException(errorMessage);
}
if (Utils.isEmpty(authToken)) {
String errorMessage = "Received empty auth token to authenticate IPC client";
logger.atError().log(errorMessage);
throw new RuntimeException(errorMessage);
}
AuthenticationData authenticationData;
try {
final String serviceName = authenticationHandler.doAuthentication(authToken);
authenticationData = () -> serviceName;
} catch (UnauthenticatedException e) {
throw new RuntimeException("Unrecognized client connecting to GGC over IPC");
}
return authenticationData;
}
Aggregations