/** * Construct a synchronous implementation of AmazonCognitoIdentity using the current builder configuration. * * @param params * Current builder configuration represented as a parameter object. * @return Fully configured implementation of AmazonCognitoIdentity. */ @Override protected AmazonCognitoIdentity build(AwsSyncClientParams params) { return new AmazonCognitoIdentityClient(params); }
@SdkInternalApi final DeleteIdentityPoolResult executeDeleteIdentityPool(DeleteIdentityPoolRequest deleteIdentityPoolRequest) { ExecutionContext executionContext = createExecutionContext(deleteIdentityPoolRequest); AWSRequestMetrics awsRequestMetrics = executionContext.getAwsRequestMetrics(); awsRequestMetrics.startEvent(Field.ClientExecuteTime); Request<DeleteIdentityPoolRequest> request = null; Response<DeleteIdentityPoolResult> response = null; try { awsRequestMetrics.startEvent(Field.RequestMarshallTime); try { request = new DeleteIdentityPoolRequestProtocolMarshaller(protocolFactory).marshall(super.beforeMarshalling(deleteIdentityPoolRequest)); // Binds the request metrics to the current request. request.setAWSRequestMetrics(awsRequestMetrics); request.addHandlerContext(HandlerContextKey.SIGNING_REGION, getSigningRegion()); request.addHandlerContext(HandlerContextKey.SERVICE_ID, "Cognito Identity"); request.addHandlerContext(HandlerContextKey.OPERATION_NAME, "DeleteIdentityPool"); request.addHandlerContext(HandlerContextKey.ADVANCED_CONFIG, advancedConfig); } finally { awsRequestMetrics.endEvent(Field.RequestMarshallTime); } HttpResponseHandler<AmazonWebServiceResponse<DeleteIdentityPoolResult>> responseHandler = protocolFactory.createResponseHandler( new JsonOperationMetadata().withPayloadJson(true).withHasStreamingSuccessResponse(false), new DeleteIdentityPoolResultJsonUnmarshaller()); response = invoke(request, responseHandler, executionContext); return response.getAwsResponse(); } finally { endClientExecution(awsRequestMetrics, request, response); } }
/** * Constructs a new client to invoke service methods on Amazon Cognito Identity using the specified parameters. * * <p> * All service calls made using this new client object are blocking, and will not return until the service call * completes. * * @param clientParams * Object providing client parameters. */ AmazonCognitoIdentityClient(AwsSyncClientParams clientParams, boolean endpointDiscoveryEnabled) { super(clientParams); this.awsCredentialsProvider = clientParams.getCredentialsProvider(); this.advancedConfig = clientParams.getAdvancedConfig(); init(); }
private void init() { setServiceNameIntern(DEFAULT_SIGNING_NAME); setEndpointPrefix(ENDPOINT_PREFIX); // calling this.setEndPoint(...) will also modify the signer accordingly setEndpoint("https://cognito-identity.us-east-1.amazonaws.com"); HandlerChainFactory chainFactory = new HandlerChainFactory(); requestHandler2s.addAll(chainFactory.newRequestHandlerChain("/com/amazonaws/services/cognitoidentity/request.handlers")); requestHandler2s.addAll(chainFactory.newRequestHandler2Chain("/com/amazonaws/services/cognitoidentity/request.handler2s")); requestHandler2s.addAll(chainFactory.getGlobalHandlers()); }
ExecutionContext executionContext = createExecutionContext(getIdRequest); AWSRequestMetrics awsRequestMetrics = executionContext.getAwsRequestMetrics(); awsRequestMetrics.startEvent(Field.ClientExecuteTime); unmarshaller); response = invoke(request, responseHandler, executionContext); endClientExecution(awsRequestMetrics, request, response, LOGGING_AWS_REQUEST_METRIC);
/** * Constructs a new client to invoke service methods on * AmazonCognitoIdentity using the specified AWS account credentials * provider, client configuration options and request metric collector. * <p> * All service calls made using this new client object are blocking, and * will not return until the service call completes. * * @param awsCredentialsProvider The AWS credentials provider which will * provide credentials to authenticate requests with AWS * services. * @param clientConfiguration The client configuration options controlling * how this client connects to AmazonCognitoIdentity (ex: proxy * settings, retry counts, etc.). * @param httpClient A http client */ public AmazonCognitoIdentityClient(AWSCredentialsProvider awsCredentialsProvider, ClientConfiguration clientConfiguration, HttpClient httpClient) { super(adjustClientConfiguration(clientConfiguration), httpClient); this.awsCredentialsProvider = awsCredentialsProvider; init(); }
private static AmazonCognitoIdentityClient createIdentityClient(ClientConfiguration clientConfiguration, final Regions region) { AmazonCognitoIdentityClient identityClient = new AmazonCognitoIdentityClient(new AnonymousAWSCredentials(), clientConfiguration); identityClient.setRegion(Region.getRegion(region)); return identityClient; }
private void init() { jsonErrorUnmarshallers = new ArrayList<JsonErrorUnmarshaller>(); jsonErrorUnmarshallers.add(new ExternalServiceExceptionUnmarshaller()); jsonErrorUnmarshallers.add(new InternalErrorExceptionUnmarshaller()); jsonErrorUnmarshallers.add(new InvalidIdentityPoolConfigurationExceptionUnmarshaller()); jsonErrorUnmarshallers.add(new InvalidParameterExceptionUnmarshaller()); jsonErrorUnmarshallers.add(new LimitExceededExceptionUnmarshaller()); jsonErrorUnmarshallers.add(new NotAuthorizedExceptionUnmarshaller()); jsonErrorUnmarshallers.add(new ResourceConflictExceptionUnmarshaller()); jsonErrorUnmarshallers.add(new ResourceNotFoundExceptionUnmarshaller()); jsonErrorUnmarshallers.add(new TooManyRequestsExceptionUnmarshaller()); jsonErrorUnmarshallers.add(new JsonErrorUnmarshaller()); // calling this.setEndPoint(...) will also modify the signer accordingly this.setEndpoint("cognito-identity.us-east-1.amazonaws.com"); this.endpointPrefix = "cognito-identity"; HandlerChainFactory chainFactory = new HandlerChainFactory(); requestHandler2s.addAll(chainFactory.newRequestHandlerChain( "/com/amazonaws/services/cognitoidentity/request.handlers")); requestHandler2s.addAll(chainFactory.newRequestHandler2Chain( "/com/amazonaws/services/cognitoidentity/request.handler2s")); }
String cognitoIdentityId = "your user's identity id"; String openIdToken = "open id token for the user created on backend"; Map<String,String> logins = new HashMap<>(); logins.put("cognito-identity.amazonaws.com", openIdToken); GetCredentialsForIdentityRequest getCredentialsRequest = new GetCredentialsForIdentityRequest() .withIdentityId(cognitoIdentityId) .withLogins(logins); AmazonCognitoIdentityClient cognitoIdentityClient = new AmazonCognitoIdentityClient(); GetCredentialsForIdentityResult getCredentialsResult = cognitoIdentityClient.getCredentialsForIdentity(getCredentialsRequest); Credentials credentials = getCredentialsResult.getCredentials(); AWSSessionCredentials sessionCredentials = new BasicSessionCredentials( credentials.getAccessKeyId(), credentials.getSecretKey(), credentials.getSessionToken() ); AmazonS3Client s3Client = new AmazonS3Client(sessionCredentials); ...
/** * Normal invoke with authentication. Credentials are required and may be overriden at the request level. **/ private <X, Y extends AmazonWebServiceRequest> Response<X> invoke(Request<Y> request, HttpResponseHandler<AmazonWebServiceResponse<X>> responseHandler, ExecutionContext executionContext) { return invoke(request, responseHandler, executionContext, null, null); }
/** * Constructs a new CognitoCredentialsProvider, which will set up a link to * the provider passed in using the enhanced authentication flow to get * short-lived credentials from Amazon Cognito, which can be retrieved from * {@link #getCredentials()} * <p> * This version of the constructor allows you to specify your own Identity * Provider class and the Amazon Cognito client. * </p> * * @param provider a reference to the provider in question, including what's * needed to interact with it to later connect with Amazon * Cognito * @param cibClient Preconfigured CognitoIdentity client to make requests * with */ public CognitoCredentialsProvider(AWSCognitoIdentityProvider provider, AmazonCognitoIdentityClient cibClient) { this.cib = cibClient; this.region = cibClient.getRegions().getName(); this.identityProvider = provider; this.unauthRoleArn = null; this.authRoleArn = null; this.securityTokenService = null; this.sessionDuration = DEFAULT_DURATION_SECONDS; this.refreshThreshold = DEFAULT_THRESHOLD_SECONDS; this.useEnhancedFlow = true; this.credentialsLock = new ReentrantReadWriteLock(true); }
ExecutionContext executionContext = createExecutionContext(getOpenIdTokenRequest); AWSRequestMetrics awsRequestMetrics = executionContext.getAwsRequestMetrics(); awsRequestMetrics.startEvent(Field.ClientExecuteTime); unmarshaller); response = invoke(request, responseHandler, executionContext); endClientExecution(awsRequestMetrics, request, response, LOGGING_AWS_REQUEST_METRIC);
/** * Constructs a new client to invoke service methods on * AmazonCognitoIdentity using the specified AWS account credentials * provider, client configuration options and request metric collector. * <p> * All service calls made using this new client object are blocking, and * will not return until the service call completes. * * @param awsCredentialsProvider The AWS credentials provider which will * provide credentials to authenticate requests with AWS * services. * @param clientConfiguration The client configuration options controlling * how this client connects to AmazonCognitoIdentity (ex: proxy * settings, retry counts, etc.). * @param requestMetricCollector optional request metric collector */ @Deprecated public AmazonCognitoIdentityClient(AWSCredentialsProvider awsCredentialsProvider, ClientConfiguration clientConfiguration, RequestMetricCollector requestMetricCollector) { super(adjustClientConfiguration(clientConfiguration), requestMetricCollector); this.awsCredentialsProvider = awsCredentialsProvider; init(); }
private static AmazonCognitoIdentityClient createIdentityClient(ClientConfiguration clientConfiguration, final Regions region) { AmazonCognitoIdentityClient identityClient = new AmazonCognitoIdentityClient(new AnonymousAWSCredentials(), clientConfiguration); identityClient.setRegion(Region.getRegion(region)); return identityClient; }
private void init() { jsonErrorUnmarshallers = new ArrayList<JsonErrorUnmarshaller>(); jsonErrorUnmarshallers.add(new ExternalServiceExceptionUnmarshaller()); jsonErrorUnmarshallers.add(new InternalErrorExceptionUnmarshaller()); jsonErrorUnmarshallers.add(new InvalidIdentityPoolConfigurationExceptionUnmarshaller()); jsonErrorUnmarshallers.add(new InvalidParameterExceptionUnmarshaller()); jsonErrorUnmarshallers.add(new LimitExceededExceptionUnmarshaller()); jsonErrorUnmarshallers.add(new NotAuthorizedExceptionUnmarshaller()); jsonErrorUnmarshallers.add(new ResourceConflictExceptionUnmarshaller()); jsonErrorUnmarshallers.add(new ResourceNotFoundExceptionUnmarshaller()); jsonErrorUnmarshallers.add(new TooManyRequestsExceptionUnmarshaller()); jsonErrorUnmarshallers.add(new JsonErrorUnmarshaller()); // calling this.setEndPoint(...) will also modify the signer accordingly this.setEndpoint("cognito-identity.us-east-1.amazonaws.com"); this.endpointPrefix = "cognito-identity"; HandlerChainFactory chainFactory = new HandlerChainFactory(); requestHandler2s.addAll(chainFactory.newRequestHandlerChain( "/com/amazonaws/services/cognitoidentity/request.handlers")); requestHandler2s.addAll(chainFactory.newRequestHandler2Chain( "/com/amazonaws/services/cognitoidentity/request.handler2s")); }
this.region = cibClient.getRegions().getName(); this.securityTokenService = stsClient;
GetCredentialsForIdentityRequest getCredentialsForIdentityRequest) throws AmazonServiceException, AmazonClientException { ExecutionContext executionContext = createExecutionContext(getCredentialsForIdentityRequest); AWSRequestMetrics awsRequestMetrics = executionContext.getAwsRequestMetrics(); awsRequestMetrics.startEvent(Field.ClientExecuteTime); unmarshaller); response = invoke(request, responseHandler, executionContext); endClientExecution(awsRequestMetrics, request, response, LOGGING_AWS_REQUEST_METRIC);
@SdkInternalApi final GetOpenIdTokenResult executeGetOpenIdToken(GetOpenIdTokenRequest getOpenIdTokenRequest) { ExecutionContext executionContext = createExecutionContext(getOpenIdTokenRequest); AWSRequestMetrics awsRequestMetrics = executionContext.getAwsRequestMetrics(); awsRequestMetrics.startEvent(Field.ClientExecuteTime); Request<GetOpenIdTokenRequest> request = null; Response<GetOpenIdTokenResult> response = null; try { awsRequestMetrics.startEvent(Field.RequestMarshallTime); try { request = new GetOpenIdTokenRequestProtocolMarshaller(protocolFactory).marshall(super.beforeMarshalling(getOpenIdTokenRequest)); // Binds the request metrics to the current request. request.setAWSRequestMetrics(awsRequestMetrics); request.addHandlerContext(HandlerContextKey.SIGNING_REGION, getSigningRegion()); request.addHandlerContext(HandlerContextKey.SERVICE_ID, "Cognito Identity"); request.addHandlerContext(HandlerContextKey.OPERATION_NAME, "GetOpenIdToken"); request.addHandlerContext(HandlerContextKey.ADVANCED_CONFIG, advancedConfig); } finally { awsRequestMetrics.endEvent(Field.RequestMarshallTime); } HttpResponseHandler<AmazonWebServiceResponse<GetOpenIdTokenResult>> responseHandler = protocolFactory.createResponseHandler( new JsonOperationMetadata().withPayloadJson(true).withHasStreamingSuccessResponse(false), new GetOpenIdTokenResultJsonUnmarshaller()); response = invoke(request, responseHandler, executionContext); return response.getAwsResponse(); } finally { endClientExecution(awsRequestMetrics, request, response); } }
/** * An extension of the AbstractCognitoProvider that is used to communicate * with Cognito. * * @param accountId the account id of the developer * @param identityPoolId the identity pool id of the app/user in question * @param clientConfiguration the configuration to apply to service clients * created */ public AWSBasicCognitoIdentityProvider(String accountId, String identityPoolId, ClientConfiguration clientConfiguration) { this(accountId, identityPoolId, new AmazonCognitoIdentityClient (new AnonymousAWSCredentials(), clientConfiguration)); }
/** * Constructs a new client to invoke service methods on * AmazonCognitoIdentity using the specified AWS account credentials * provider, client configuration options and request metric collector. * <p> * All service calls made using this new client object are blocking, and * will not return until the service call completes. * * @param awsCredentialsProvider The AWS credentials provider which will * provide credentials to authenticate requests with AWS * services. * @param clientConfiguration The client configuration options controlling * how this client connects to AmazonCognitoIdentity (ex: proxy * settings, retry counts, etc.). * @param httpClient A http client */ public AmazonCognitoIdentityClient(AWSCredentialsProvider awsCredentialsProvider, ClientConfiguration clientConfiguration, HttpClient httpClient) { super(adjustClientConfiguration(clientConfiguration), httpClient); this.awsCredentialsProvider = awsCredentialsProvider; init(); }