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

com.amazonaws.opensdk.protect.auth.RequestSignerRegistry Maven / Gradle / Ivy

There is a newer version: 1.12.778
Show newest version
/*
 * Copyright 2011-2024 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 com.amazonaws.opensdk.protect.auth;

import com.amazonaws.auth.RequestSigner;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

/**
 * Hold references to all of the available RequestSigners and can
 * retrieve a RequestSigner implementation of a given type (if it
 * exists in the registry)
 */
public final class RequestSignerRegistry implements RequestSignerProvider {

    private final Map, RequestSigner> signerForType;

    public RequestSignerRegistry() {
        signerForType = Collections.emptyMap();
    }

    private RequestSignerRegistry(Map, RequestSigner> registeredSignersMap) {
        signerForType = Collections.unmodifiableMap(registeredSignersMap);
    }

    /**
     * Register an requestSigner
     * @param requestSigner
     *      an instance of an RequestSigner to use for a given type
     * @param signerType
     *      the type of requestSigner that this instance will be used for
     */
    public RequestSignerRegistry register(RequestSigner requestSigner, Class signerType) {
        Map, RequestSigner> registeredSigners = new HashMap<>();
        registeredSigners.putAll(signerForType);
        registeredSigners.put(signerType, requestSigner);
        return new RequestSignerRegistry(registeredSigners);
    }

    @Override
    public Optional getSigner(Class requestSignerType) {
        return Optional.ofNullable(signerForType.get(requestSignerType));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy