Search in sources :

Example 1 with GreengrassEventStreamConnectMessage

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;
}
Also used : AuthenticationData(software.amazon.awssdk.eventstreamrpc.AuthenticationData) UnauthenticatedException(com.aws.greengrass.ipc.exceptions.UnauthenticatedException) IOException(java.io.IOException) GreengrassEventStreamConnectMessage(software.amazon.awssdk.eventstreamrpc.GreengrassEventStreamConnectMessage)

Aggregations

UnauthenticatedException (com.aws.greengrass.ipc.exceptions.UnauthenticatedException)1 IOException (java.io.IOException)1 AuthenticationData (software.amazon.awssdk.eventstreamrpc.AuthenticationData)1 GreengrassEventStreamConnectMessage (software.amazon.awssdk.eventstreamrpc.GreengrassEventStreamConnectMessage)1