Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2010-2015 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.auth;
 
 import java.util.Map;
 
Signer factory.
 
 public final class SignerFactory {
 
     private static final String QUERY_STRING_SIGNER = "QueryStringSignerType";
     private static final String VERSION_THREE_SIGNER = "AWS3SignerType";
     private static final String VERSION_FOUR_SIGNER = "AWS4SignerType";
     private static final String NO_OP_SIGNER = "NoOpSignerType";
 
     private static final Map<StringClass<? extends Signer>> SIGNERS
         = new ConcurrentHashMap<StringClass<? extends Signer>>();
 
     static {
         // Register the standard signer types.
         .put(AWS3Signer.class);
         .put(AWS4Signer.class);
         .put(NoOpSigner.class);
     }

    
Private so you're not tempted to instantiate me.
 
     private SignerFactory() {
     }

    
Register an implementation class for the given signer type.

Parameters:
signerType The name of the signer type to register.
signerClass The class implementing the given signature protocol.
 
     public static void registerSigner(
             final String signerType,
             final Class<? extends SignersignerClass) {
 
         if (signerType == null) {
             throw new IllegalArgumentException("signerType cannot be null");
         }
         if (signerClass == null) {
             throw new IllegalArgumentException("signerClass cannot be null");
         }
 
         .put(signerTypesignerClass);
     }

    
Returns a non-null signer for the specified service and region according to the internal configuration which provides a basic default algorithm used for signer determination.

Parameters:
serviceName The name of the service to talk to.
regionName The name of the region to talk to; not necessarily the region used for signing.
 
     public static Signer getSigner(String serviceNameString regionName) {
         return lookupAndCreateSigner(serviceNameregionName);
     }

    
Returns an instance of the given signer type and configures it with the given service name (if applicable).

Parameters:
signerType The type of signer to create.
serviceName The name of the service to configure on the signer.
Returns:
a non-null signer.
 
     public static Signer getSignerByTypeAndService(String signerType,
             final String serviceName) {
         return createSigner(signerTypeserviceName);
     }

    
Internal implementation for looking up and creating a signer by service name and region.
    private static Signer lookupAndCreateSigner(String serviceNameString regionName) {
        InternalConfig config = InternalConfig.Factory.getInternalConfig();
        SignerConfig signerConfig =
            config.getSignerConfig(serviceNameregionName);
        String signerType = signerConfig.getSignerType();
        return createSigner(signerTypeserviceName);
    }

    
Internal implementation to create a signer by type and service name, and configuring it with the service name if applicable.
    private static Signer createSigner(String signerType,
            final String serviceName) {
        Class<? extends SignersignerClass = .get(signerType);
        if (signerClass == null)
            throw new IllegalArgumentException("unknown signer type: " + signerType);
        Signer signer;
        try {
            signer = signerClass.newInstance();
        } catch (InstantiationException ex) {
            throw new IllegalStateException(
                "Cannot create an instance of " + signerClass.getName(),
                ex);
        } catch (IllegalAccessException ex) {
            throw new IllegalStateException(
                "Cannot create an instance of " + signerClass.getName(),
                ex);
        }
        if (signer instanceof ServiceAwareSigner) {
            ((ServiceAwareSignersigner).setServiceName(serviceName);
        }
        return signer;
    }
New to GrepCode? Check out our FAQ X