All Downloads are FREE. Search and download functionalities are using the official Maven repository.

software.amazon.awssdk.services.eventbridge.auth.scheme.internal.DefaultEventBridgeAuthSchemeProvider Maven / Gradle / Ivy

Go to download

The AWS Java SDK for EventBridge module holds the client classes that are used for communicating with EventBridge.

There is a newer version: 2.29.39
Show newest version
/*
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
 * the License. A copy of the License is located at
 * 
 * http://aws.amazon.com/apache2.0
 * 
 * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
 * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
 * and limitations under the License.
 */

package software.amazon.awssdk.services.eventbridge.auth.scheme.internal;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import software.amazon.awssdk.annotations.Generated;
import software.amazon.awssdk.annotations.SdkInternalApi;
import software.amazon.awssdk.awscore.endpoints.AwsEndpointAttribute;
import software.amazon.awssdk.awscore.endpoints.authscheme.EndpointAuthScheme;
import software.amazon.awssdk.awscore.endpoints.authscheme.SigV4AuthScheme;
import software.amazon.awssdk.awscore.endpoints.authscheme.SigV4aAuthScheme;
import software.amazon.awssdk.endpoints.Endpoint;
import software.amazon.awssdk.http.auth.aws.signer.AwsV4HttpSigner;
import software.amazon.awssdk.http.auth.aws.signer.AwsV4aHttpSigner;
import software.amazon.awssdk.http.auth.aws.signer.RegionSet;
import software.amazon.awssdk.http.auth.spi.scheme.AuthSchemeOption;
import software.amazon.awssdk.services.eventbridge.auth.scheme.EventBridgeAuthSchemeParams;
import software.amazon.awssdk.services.eventbridge.auth.scheme.EventBridgeAuthSchemeProvider;
import software.amazon.awssdk.services.eventbridge.endpoints.EventBridgeEndpointParams;
import software.amazon.awssdk.services.eventbridge.endpoints.EventBridgeEndpointProvider;
import software.amazon.awssdk.utils.CompletableFutureUtils;
import software.amazon.awssdk.utils.Validate;

@Generated("software.amazon.awssdk:codegen")
@SdkInternalApi
public final class DefaultEventBridgeAuthSchemeProvider implements EventBridgeAuthSchemeProvider {
    private static final DefaultEventBridgeAuthSchemeProvider DEFAULT = new DefaultEventBridgeAuthSchemeProvider();

    private static final EventBridgeAuthSchemeProvider MODELED_RESOLVER = ModeledEventBridgeAuthSchemeProvider.create();

    private static final EventBridgeEndpointProvider DELEGATE = EventBridgeEndpointProvider.defaultProvider();

    private DefaultEventBridgeAuthSchemeProvider() {
    }

    public static EventBridgeAuthSchemeProvider create() {
        return DEFAULT;
    }

    @Override
    public List resolveAuthScheme(EventBridgeAuthSchemeParams params) {
        EventBridgeEndpointParams endpointParameters = EventBridgeEndpointParams.builder().region(params.region())
                .endpointId(params.endpointId()).build();
        Endpoint endpoint = CompletableFutureUtils.joinLikeSync(DELEGATE.resolveEndpoint(endpointParameters));
        List authSchemes = endpoint.attribute(AwsEndpointAttribute.AUTH_SCHEMES);
        if (authSchemes == null) {
            return MODELED_RESOLVER.resolveAuthScheme(params);
        }
        List options = new ArrayList<>();
        for (EndpointAuthScheme authScheme : authSchemes) {
            String name = authScheme.name();
            switch (name) {
            case "sigv4":
                SigV4AuthScheme sigv4AuthScheme = Validate.isInstanceOf(SigV4AuthScheme.class, authScheme,
                        "Expecting auth scheme of class SigV4AuthScheme, got instead object of class %s", authScheme.getClass()
                                .getName());
                options.add(AuthSchemeOption.builder().schemeId("aws.auth#sigv4")
                        .putSignerProperty(AwsV4HttpSigner.SERVICE_SIGNING_NAME, sigv4AuthScheme.signingName())
                        .putSignerProperty(AwsV4HttpSigner.REGION_NAME, sigv4AuthScheme.signingRegion())
                        .putSignerProperty(AwsV4HttpSigner.DOUBLE_URL_ENCODE, !sigv4AuthScheme.disableDoubleEncoding()).build());
                break;
            case "sigv4a":
                SigV4aAuthScheme sigv4aAuthScheme = Validate.isInstanceOf(SigV4aAuthScheme.class, authScheme,
                        "Expecting auth scheme of class SigV4AuthScheme, got instead object of class %s", authScheme.getClass()
                                .getName());
                RegionSet regionSet = RegionSet.create(sigv4aAuthScheme.signingRegionSet());
                options.add(AuthSchemeOption.builder().schemeId("aws.auth#sigv4a")
                        .putSignerProperty(AwsV4aHttpSigner.SERVICE_SIGNING_NAME, sigv4aAuthScheme.signingName())
                        .putSignerProperty(AwsV4aHttpSigner.REGION_SET, regionSet)
                        .putSignerProperty(AwsV4aHttpSigner.DOUBLE_URL_ENCODE, !sigv4aAuthScheme.disableDoubleEncoding()).build());
                break;
            default:
                throw new IllegalArgumentException("Unknown auth scheme: " + name);
            }
        }
        return Collections.unmodifiableList(options);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy