Java 类com.amazonaws.auth.Signer 实例源码

项目:ibm-cos-sdk-java    文件:AmazonWebServiceClient.java   
/**
 * Returns the signer for the given service name, region id, and the current
 * client configuration.
 * <p>
 * Note, however, the signer returned for S3 is incomplete at this stage as
 * the information on the S3 bucket and key is not yet known.
 *
 * @param regionId
 *            the region for sending AWS requests
 * @param signerRegionOverride
 *            the overriding signer region; or null if there is none.
 * @param isRegionIdAsSignerParam
 *            true if the "regionId" is used to configure the signer if
 *            applicable; false if this method is called for the purpose of
 *            purely setting the communication end point of this AWS client,
 *            and therefore the "regionId" parameter will not be used
 *            directly for configuring the signer.
 */
private Signer computeSignerByServiceRegion(
        String serviceName, String regionId,
        String signerRegionOverride,
        boolean isRegionIdAsSignerParam) {

    String signerType = clientConfiguration.getSignerOverride();
    Signer signer = signerType == null
         ? SignerFactory.getSigner(serviceName, regionId)
         : SignerFactory.getSignerByTypeAndService(signerType, serviceName)
         ;
     if (signer instanceof RegionAwareSigner) {
         // Overrides the default region computed
         RegionAwareSigner regionAwareSigner = (RegionAwareSigner)signer;
        // (signerRegionOverride != null) means that it is likely to be AWS
        // internal dev work, as "signerRegionOverride" is typically null
         // when used in the external release
         if (signerRegionOverride != null)
             regionAwareSigner.setRegionName(signerRegionOverride);
         else if (regionId != null && isRegionIdAsSignerParam)
             regionAwareSigner.setRegionName(regionId);
     }
     return signer;
}
项目:aws-request-signing-apache-interceptor    文件:AWSRequestSigningApacheInterceptor.java   
/**
 *
 * @param service service that we're connecting to
 * @param signer particular signer implementation
 * @param awsCredentialsProvider source of AWS credentials for signing
 */
public AWSRequestSigningApacheInterceptor(final String service,
                            final Signer signer,
                            final AWSCredentialsProvider awsCredentialsProvider) {
    this.service = service;
    this.signer = signer;
    this.awsCredentialsProvider = awsCredentialsProvider;
}
项目:ibm-cos-sdk-java    文件:AmazonWebServiceClient.java   
/**
 * An internal method used to explicitly override the internal signer region
 * computed by the default implementation. This method is not expected to be
 * normally called except for AWS internal development purposes.
 */
public final void setSignerRegionOverride(String signerRegionOverride) {
    checkMutability();
    Signer signer = computeSignerByURI(endpoint, signerRegionOverride, true);
    synchronized(this)  {
        this.signerRegionOverride = signerRegionOverride;
        this.signerProvider = createSignerProvider(signer);
    }
}
项目:ibm-cos-sdk-java    文件:ExecutionContext.java   
@Deprecated
public ExecutionContext(List<RequestHandler2> requestHandler2s, boolean isMetricEnabled,
        AmazonWebServiceClient awsClient) {
    this.requestHandler2s = requestHandler2s;
    awsRequestMetrics = isMetricEnabled ? new AWSRequestMetricsFullSupport() : new AWSRequestMetrics();
    this.awsClient = awsClient;
    this.signerProvider = new SignerProvider() {
        @Override
        public Signer getSigner(SignerProviderContext context) {
            return getSignerByURI(context.getUri());
        }
    };
}
项目:ibm-cos-sdk-java    文件:DefaultSignerProvider.java   
@Override
public Signer getSigner(SignerProviderContext context) {
Request<?> request = context.getRequest();
    if (request == null || shouldUseDefaultSigner(request.getOriginalRequest())) {
        if (context.isRedirect()) {
            return awsClient.getSignerByURI(context.getUri());
        }
        return defaultSigner;
    }

    SignerTypeAware signerTypeAware = (SignerTypeAware) request.getOriginalRequest();
    SignerParams params = new SignerParams(awsClient.getServiceName(), getSigningRegionForRequestURI(request.getEndpoint()));
    return SignerFactory.createSigner(signerTypeAware.getSignerType(), params);
}
项目:ibm-cos-sdk-java    文件:AuthRetryParameters.java   
public AuthRetryParameters(Signer signer, URI endpoint) {
    if (signer == null)
        throw new NullPointerException("signer");
    if (endpoint == null)
        throw new NullPointerException("endpoint");

    this.signerForRetry = signer;
    this.endpointForRetry = endpoint;
}
项目:ibm-cos-sdk-java    文件:DefaultSignerProviderTest.java   
@Test
public void configuresServiceAndRegionWhenUsingOperationSigner() throws URISyntaxException {
    when(mockClient.getServiceName()).thenReturn("MockService");

    SignerProviderContext ctx = SignerProviderContext.builder()
            .withRequest(signerAwareRequest)
            .build();

    Signer signer = defaultSignerProvider.getSigner(ctx);

    FooSigner fooSigner = (FooSigner) signer;

    assertThat(fooSigner.getRegionName(), is(equalTo("us-east-1")));
    assertThat(fooSigner.getServiceName(), is(equalTo("MockService")));
}
项目:ibm-cos-sdk-java    文件:S3SignerProvider.java   
@Override
public Signer getSigner(SignerProviderContext signerProviderContext) {
    URI uri = signerProviderContext.getUri();

    // Return the default signer if no URI is passed, the client is configured with region override,
    // or if we are hitting an accelerate endpoint.
    if (uri == null || ServiceUtils.isS3AccelerateEndpoint(uri.getHost()) || isSignerRegionOverrideSet()) {
        return signer;
    }

    if (signer instanceof RegionAwareSigner) {
        // Parse region name from the host component of the URL and
        // assign it to the signer
        RegionAwareSigner regionSigner = (RegionAwareSigner) signer;

        try {
            regionSigner.setRegionName(AwsHostNameUtils.parseRegionName(
                    uri.getHost(), "s3"));

        } catch (RuntimeException e) {
            log.warn("Failed to parse the endpoint " + uri +
                    ", and skip re-assigning the signer region", e);
        }
    }

    return signer;
}
项目:ibm-cos-sdk-java    文件:AmazonWebServiceClient.java   
/**
 * An alternative to {@link AmazonWebServiceClient#setEndpoint(String)}, sets the regional
 * endpoint for this client's service calls. Callers can use this method to control which AWS
 * region they want to work with.
 * <p>
 * <b>This method is not threadsafe. A region should be configured when the client is created
 * and before any service requests are made. Changing it afterwards creates inevitable race
 * conditions for any service requests in transit or retrying.</b>
 * <p>
 * By default, all service endpoints in all regions use the https protocol. To use http instead,
 * specify it in the {@link ClientConfiguration} supplied at construction.
 *
 * @param region
 *            The region this client will communicate with. See
 *            {@link Region#getRegion(com.amazonaws.regions.Regions)} for accessing a given
 *            region.
 * @throws java.lang.IllegalArgumentException
 *             If the given region is null, or if this service isn't available in the given
 *             region. See {@link Region#isServiceSupported(String)}
 * @see Region#getRegion(com.amazonaws.regions.Regions)
 * @see Region#createClient(Class, com.amazonaws.auth.AWSCredentialsProvider,
 *      ClientConfiguration)
 * @deprecated use {@link AwsClientBuilder#setRegion(String)}
 */
@Deprecated
public void setRegion(Region region) throws IllegalArgumentException {
    checkMutability();
    if (region == null) {
        throw new IllegalArgumentException("No region provided");
    }
    final String serviceNameForEndpoint = getEndpointPrefix();
    final String serviceNameForSigner = getServiceNameIntern();
    URI uri = new DefaultServiceEndpointBuilder(serviceNameForEndpoint, clientConfiguration.getProtocol()
            .toString()).withRegion(region).getServiceEndpoint();
    Signer signer = computeSignerByServiceRegion(serviceNameForSigner, region.getName(), signerRegionOverride, false);
    synchronized (this) {
        this.endpoint = uri;
        this.signerProvider = createSignerProvider(signer);
    }
}
项目:ibm-cos-sdk-java    文件:AmazonWebServiceClient.java   
protected SignerProvider createSignerProvider(Signer signer) {
    return new DefaultSignerProvider(this, signer);
}
项目:ibm-cos-sdk-java    文件:ExecutionContext.java   
/**
 * Returns the signer for the given uri. Note S3 in particular overrides this method.
 */
@Deprecated
public Signer getSignerByURI(URI uri) {
    return awsClient == null ? null : awsClient.getSignerByURI(uri);
}
项目:ibm-cos-sdk-java    文件:NoOpSignerProvider.java   
@Override
public Signer getSigner(SignerProviderContext context) {
    return signer;
}
项目:ibm-cos-sdk-java    文件:DefaultSignerProvider.java   
public DefaultSignerProvider(final AmazonWebServiceClient awsClient,
                             final Signer defaultSigner) {
    this.awsClient = awsClient;
    this.defaultSigner = defaultSigner;
}
项目:ibm-cos-sdk-java    文件:AuthRetryParameters.java   
public Signer getSignerForRetry() {
    return signerForRetry;
}
项目:ibm-cos-sdk-java    文件:AmazonS3Client.java   
/**
 * Returns a "complete" S3 specific signer, taking into the S3 bucket, key,
 * and the current S3 client configuration into account.
 */
protected Signer createSigner(final Request<?> request,
                              final String bucketName,
                              final String key) {
    return createSigner(request, bucketName, key, false);
}
项目:ibm-cos-sdk-java    文件:AmazonS3Client.java   
/**
 * Returns a "complete" S3 specific signer, taking into the S3 bucket, key,
 * and the current S3 client configuration into account.
 */
protected Signer createSigner(final Request<?> request,
                              final String bucketName,
                              final String key,
                              final boolean isAdditionalHeadRequestToFindRegion) {

    // Instead of using request.getEndpoint() for this parameter, we use endpoint which is because
    // in accelerate mode, the endpoint in request is regionless. We need the client-wide endpoint
    // to fetch the region information and pick the correct signer.
    URI uri = clientOptions.isAccelerateModeEnabled() ? endpoint : request.getEndpoint();
    final Signer signer = getSignerByURI(uri);

    if(this.awsCredentialsProvider.getCredentials() instanceof IBMOAuthCredentials) {
        IBMOAuthCredentials oAuthCreds = (IBMOAuthCredentials)this.awsCredentialsProvider.getCredentials();
        if (oAuthCreds.getApiKey() != null || oAuthCreds.getTokenManager() != null) {
            return new IBMOAuthSigner();    
        }
    }

    if (!isSignerOverridden()) {

        if ((signer instanceof AWSS3V4Signer) && bucketRegionShouldBeCached(request)) {

            String region = bucketRegionCache.get(bucketName);
            if (region != null) {
                 // If cache contains the region for the bucket, create an endpoint for the region and
                 // update the request with that endpoint.
                 resolveRequestEndpoint(request, bucketName, key, RuntimeHttpUtils.toUri(RegionUtils.getRegion(region).getServiceEndpoint(S3_SERVICE_NAME), clientConfiguration));
                 return updateSigV4SignerWithRegion((AWSS3V4Signer) signer, region);
            } else if (request.getOriginalRequest() instanceof GeneratePresignedUrlRequest) {
                return createSigV2Signer(request, bucketName, key);
            } else if (isAdditionalHeadRequestToFindRegion) {
                return updateSigV4SignerWithRegion((AWSS3V4Signer) signer, "us-east-1");
            }
        }

        String regionOverride = getSignerRegionOverride();
        if (regionOverride != null) {
            return updateSigV4SignerWithRegion(new AWSS3V4Signer(), regionOverride);
        }
    }
    if (signer instanceof S3Signer) {
        // The old S3Signer needs a method and path passed to its
        // constructor; if that's what we should use, getSigner()
        // will return a dummy instance and we need to create a
        // new one with the appropriate values for this request.
        return createSigV2Signer(request, bucketName, key);
    }

    return signer;
}
项目:ibm-cos-sdk-java    文件:AmazonS3Client.java   
@Override
protected final SignerProvider createSignerProvider(Signer signer) {
    return new S3SignerProvider(this, signer);
}
项目:ibm-cos-sdk-java    文件:S3SignerProvider.java   
public S3SignerProvider(final AmazonWebServiceClient awsClient,
                        final Signer defaultSigner) {
    this.awsClient = awsClient;
    this.signer = defaultSigner;
}
项目:ivona-speechcloud-sdk-java    文件:IvonaSpeechCloudClient.java   
@Override
public Signer getSignerByURI(URI uri) {
    return this.signer;
}
项目:ibm-cos-sdk-java    文件:AmazonWebServiceClient.java   
/**
 * Overrides the default endpoint for this client. Callers can use this
 * method to control which AWS region they want to work with.
 * <p>
 * <b>This method is not threadsafe. Endpoints should be configured when the
 * client is created and before any service requests are made. Changing it
 * afterwards creates inevitable race conditions for any service requests in
 * transit.</b>
 * <p>
 * Callers can pass in just the endpoint (ex: "ec2.amazonaws.com") or a full
 * URL, including the protocol (ex: "https://ec2.amazonaws.com"). If the
 * protocol is not specified here, the default protocol from this client's
 * {@link ClientConfiguration} will be used, which by default is HTTPS.
 * <p>
 * For more information on using AWS regions with the AWS SDK for Java, and
 * a complete list of all available endpoints for all AWS services, see:
 * <a href="http://developer.amazonwebservices.com/connect/entry.jspa?externalID=3912">
 * http://developer.amazonwebservices.com/connect/entry.jspa?externalID=3912</a>
 *
 * @param endpoint
 *            The endpoint (ex: "ec2.amazonaws.com") or a full URL,
 *            including the protocol (ex: "https://ec2.amazonaws.com") of
 *            the region specific AWS endpoint this client will communicate
 *            with.
 * @throws IllegalArgumentException
 *             If any problems are detected with the specified endpoint.
 *
 * @deprecated use {@link AwsClientBuilder#setEndpointConfiguration(AwsClientBuilder.EndpointConfiguration)} for example:
 * {@code builder.setEndpointConfiguration(new EndpointConfiguration(endpoint, signingRegion));}
 */
@Deprecated
public void setEndpoint(String endpoint) throws IllegalArgumentException {
    checkMutability();
    URI uri = toURI(endpoint);
    Signer signer = computeSignerByURI(uri, signerRegionOverride, false);
    synchronized(this)  {
        this.endpoint = uri;
        this.signerProvider = createSignerProvider(signer);
    }
}
项目:ibm-cos-sdk-java    文件:AmazonWebServiceClient.java   
/**
 * Returns the signer for the given uri and the current client
 * configuration.
 * <p>
 * Note, however, the signer returned for S3 is incomplete at this stage as
 * the information on the S3 bucket and key is not yet known.
 *
 * @param signerRegionOverride
 *            the overriding signer region; or null if there is none.
 * @param isRegionIdAsSignerParam
 *            true if the "regionId" is used to configure the signer if
 *            applicable; false if this method is called for the purpose of
 *            purely setting the communication end point of this AWS client,
 *            and therefore the "regionId" parameter will not be used
 *            directly for configuring the signer.
 */
private Signer computeSignerByURI(URI uri, String signerRegionOverride,
        boolean isRegionIdAsSignerParam) {
    if (uri == null) {
        throw new IllegalArgumentException(
                "Endpoint is not set. Use setEndpoint to set an endpoint before performing any request.");
    }
    String service = getServiceNameIntern();
    String region = AwsHostNameUtils.parseRegionName(uri.getHost(), service);

    return computeSignerByServiceRegion(
            service, region, signerRegionOverride, isRegionIdAsSignerParam);
}
项目:ibm-cos-sdk-java    文件:AmazonWebServiceClient.java   
/**
 * Returns the signer.
 * <p>
 * Note, however, the signer configured for S3 is incomplete at this stage
 * as the information on the S3 bucket and key is not yet known.
 */
@Deprecated
protected Signer getSigner() {
    return signerProvider.getSigner(SignerProviderContext.builder().build());
}
项目:ibm-cos-sdk-java    文件:AmazonWebServiceClient.java   
/**
 * Returns the signer based on the given URI and the current AWS client
 * configuration. Currently only the SQS client can have different region on
 * a per request basis. For other AWS clients, the region remains the same
 * on a per AWS client level.
 * <p>
 * Note, however, the signer returned for S3 is incomplete at this stage as
 * the information on the S3 bucket and key is not yet known.
 */
public Signer getSignerByURI(URI uri) {
    return computeSignerByURI(uri, signerRegionOverride, true);
}
项目:ibm-cos-sdk-java    文件:ExecutionContext.java   
/**
 * There is in general no need to set the signer in the execution context, since the signer for
 * each request may differ depending on the URI of the request. The exception is S3 where the
 * signer is currently determined only when the S3 client is constructed. Hence the need for
 * this method. We may consider supporting a per request level signer determination for S3 later
 * on.
 */
@Deprecated
public void setSigner(Signer signer) {
}
项目:ibm-cos-sdk-java    文件:ExecutionContext.java   
/**
 * Passes in the provided {@link SignerProviderContext} into a {@link SignerProvider} and returns
 * a {@link Signer} instance.
 */
public Signer getSigner(SignerProviderContext context) { return signerProvider.getSigner(context); }
项目:ibm-cos-sdk-java    文件:S3SignerProvider.java   
/**
 * This is necessary for S3 since we update the signer during request processing dependent on
 * which region the bucket exists in.
 */
public void setSigner(Signer signer) {
    this.signer = signer;
}
项目:ibm-cos-sdk-java    文件:SignerProvider.java   
public abstract Signer getSigner(SignerProviderContext context);