private String buildMqtt5FinalUsername()

in sdk/src/main/java/software/amazon/awssdk/iot/AwsIotMqtt5ClientBuilder.java [859:931]


    private String buildMqtt5FinalUsername(MqttConnectCustomAuthConfig config) throws Exception {

        ArrayList<String> paramList = new ArrayList<String>();

        if (config != null) {
            boolean usingSigning = false;
            if (config.tokenValue != null || config.tokenKeyName != null || config.tokenSignature != null) {
                if (config.tokenValue == null || config.tokenKeyName == null || config.tokenSignature == null) {
                    throw new Exception("Token-based custom authentication requires all token-related properties to be set");
                }

                usingSigning = true;
            }

            String username = config.username;
            if (username != null) {
                if (username.contains("?")) {
                    // split and process
                    String[] questionSplit = username.split("?");
                    if (questionSplit.length > 1) {
                        throw new Exception("Custom auth username property value is invalid");
                    }
                    else {
                        // Add the username:
                        addToUsernameParam(paramList, null, questionSplit[0]);

                        // Is there multiple key-value pairs or just one? If multiple, split on the &
                        if (questionSplit[1].contains("&")) {
                            String[] ampSplit = questionSplit[1].split("&");
                            for (int i = 0; i < ampSplit.length; i++) {
                                // We only want pairs
                                String[] keyValueSplit = ampSplit[i].split("=");
                                if (keyValueSplit.length == 1) {
                                    addToUsernameParam(paramList, keyValueSplit[0], keyValueSplit[1]);
                                }
                            }
                        } else {
                            // We only want pairs
                            String[] keyValueSplit = questionSplit[1].split("=");
                            if (keyValueSplit.length == 1) {
                                addToUsernameParam(paramList, keyValueSplit[0], keyValueSplit[1]);
                            }
                        }
                    }

                } else {
                    addToUsernameParam(paramList, null, username);
                }
            }

            addToUsernameParam(paramList, "x-amz-customauthorizer-name", config.authorizerName);

            if (usingSigning == true) {
                addToUsernameParam(paramList, config.tokenKeyName, config.tokenValue);

                String encodedSignature = config.tokenSignature;
                if (!encodedSignature.contains("%")) {
                    encodedSignature = URLEncoder.encode(encodedSignature, StandardCharsets.UTF_8.toString());
                }

                addToUsernameParam(paramList, "x-amz-customauthorizer-signature", encodedSignature);
            }
        }

        if(CRT.getOSIdentifier() == "android"){
            addToUsernameParam(paramList, "SDK", "AndroidV2");
        } else {
            addToUsernameParam(paramList, "SDK", "JavaV2");
        }
        addToUsernameParam(paramList, "Version", new PackageInfo().version.toString());

        return formUsernameFromParam(paramList);
    }