Example usage for com.amazonaws.auth AWSCredentialsProvider refresh

List of usage examples for com.amazonaws.auth AWSCredentialsProvider refresh

Introduction

In this page you can find the example usage for com.amazonaws.auth AWSCredentialsProvider refresh.

Prototype

public void refresh();

Source Link

Document

Forces this credentials provider to refresh its credentials.

Usage

From source file:com.epam.dlab.auth.aws.service.AwsCredentialRefreshService.java

License:Apache License

private void refresh(AWSCredentialsProvider credentialsProvider) {
    try {//from  ww w.ja v  a 2  s. c o m
        credentialsProvider.refresh();
        this.awsUserDAO.updateCredentials(credentialsProvider.getCredentials());
        log.debug("provider credentials refreshed");
    } catch (Exception e) {
        log.error("AWS provider error", e);
        throw e;
    }
}

From source file:com.eucalyptus.simpleworkflow.common.client.Config.java

License:Open Source License

public static AmazonSimpleWorkflow buildClient(final Supplier<User> user, final String text)
        throws AuthException {
    final AWSCredentialsProvider credentialsProvider = new SecurityTokenAWSCredentialsProvider(user);
    final AmazonSimpleWorkflowClient client = new AmazonSimpleWorkflowClient(credentialsProvider,
            buildConfiguration(text));/*from   www. ja  va 2 s. c o m*/
    client.setEndpoint(ServiceUris.remote(Topology.lookup(SimpleWorkflow.class)).toString());
    client.addRequestHandler(new RequestHandler2() {
        @Override
        public void beforeRequest(final Request<?> request) {
            // Add nonce to ensure unique request signature
            request.addHeader("Euca-Nonce", UUID.randomUUID().toString());
        }

        @Override
        public void afterResponse(final Request<?> request, final Response<?> response) {
        }

        @Override
        public void afterError(final Request<?> request, final Response<?> response, final Exception e) {
            final String errorMessage = Strings.nullToEmpty(e.getMessage());
            boolean resetEndpoint = false;
            if (Exceptions.isCausedBy(e, JSONException.class) && (errorMessage.contains("Response Code: 404")
                    || errorMessage.contains("Response Code: 503"))) {
                resetEndpoint = true;
            } else if (Exceptions.isCausedBy(e, ConnectException.class)) {
                resetEndpoint = true;
            } else if (Exceptions.isCausedBy(e, NoHttpResponseException.class)) {
                resetEndpoint = true;
            }
            if (resetEndpoint) {
                try {
                    client.setEndpoint(ServiceUris.remote(Topology.lookup(SimpleWorkflow.class)).toString());
                } catch (final Exception e2) {
                    // retry on next failure
                }
            }

            if (e instanceof AmazonServiceException) {
                final int status = ((AmazonServiceException) e).getStatusCode();
                if (status == 403) {
                    credentialsProvider.refresh();
                }
            }
        }
    });
    return client;
}

From source file:org.apache.hadoop.fs.s3a.AWSCredentialProviderList.java

License:Apache License

/**
 * Refresh all child entries.//from  w w w  .j a  v  a  2  s. c o  m
 */
@Override
public void refresh() {
    for (AWSCredentialsProvider provider : providers) {
        provider.refresh();
    }
}