List of usage examples for com.amazonaws.services.cognitoidentity.model GetCredentialsForIdentityRequest setIdentityId
public void setIdentityId(String identityId)
A unique identifier in the format REGION:GUID.
From source file:cf.funge.aworldofplants.provider.CognitoCredentialsProvider.java
License:Open Source License
/** * Retreives a set of AWS temporary credentials from Amazon Cognito using Developer Authenticated Identities. * * @param user The end user object. The identity property in the User object needs to be populated with a valid * identityId and openID Token * @return A valid set of temporary AWS credentials * @throws AuthorizationException//from w ww . j a va2 s .c o m */ public UserCredentials getUserCredentials(User user) throws AuthorizationException { if (user == null || user.getCognitoIdentityId() == null || user.getCognitoIdentityId().trim().equals("")) { throw new AuthorizationException("Invalid user"); } GetCredentialsForIdentityRequest credsRequest = new GetCredentialsForIdentityRequest(); credsRequest.setIdentityId(user.getCognitoIdentityId()); credsRequest.addLoginsEntry(CognitoConfiguration.COGNITO_PROVIDER_NAME, user.getIdentity().getOpenIdToken()); GetCredentialsForIdentityResult resp = identityClient.getCredentialsForIdentity(credsRequest); if (resp == null) { throw new AuthorizationException("Empty GetCredentialsForIdentity response"); } UserCredentials creds = new UserCredentials(); creds.setAccessKey(resp.getCredentials().getAccessKeyId()); creds.setSecretKey(resp.getCredentials().getSecretKey()); creds.setSessionToken(resp.getCredentials().getSessionToken()); creds.setExpiration(resp.getCredentials().getExpiration().getTime()); return creds; }