public FederatedUserCredentials getFederatedTokenFor(String username) { Policy policy = DefaultS3FolderPolicy.getForUser(bucket, username); GetFederationTokenRequest getFederationTokenRequest = new GetFederationTokenRequest() .withName(username) .withDurationSeconds(TEMPORARY_CREDENTIALS_VALIDITY) .withPolicy(policy.toJson()); GetFederationTokenResult federationTokenResult = tokenService.getFederationToken(getFederationTokenRequest); return new FederatedUserCredentials(region, bucket, username, federationTokenResult.getCredentials()); }
/** * Retrieves temporary credentials for the given user. * * @param username * a given user name * @return temporary AWS credentials * @throws DataAccessException * When it fails to get federation token from STS */ public Credentials getTemporaryCredentials(String username) throws DataAccessException { GetFederationTokenRequest getFederationTokenRequest = new GetFederationTokenRequest(); getFederationTokenRequest.setName(username); getFederationTokenRequest.setPolicy(getPolicyObject()); getFederationTokenRequest.setDurationSeconds(new Integer(Configuration.SESSION_DURATION)); try { return sts.getFederationToken(getFederationTokenRequest).getCredentials(); } catch (AmazonClientException e) { throw new DataAccessException("Failed to get federation token for user: " + username, e); } }
/** * Retrieves temporary credentials for the given user. * * @param username * a given user name * @return temporary AWS credentials * @throws DataAccessException * When it fails to get federation token from STS */ public Credentials getTemporaryCredentials(String username) throws DataAccessException { GetFederationTokenRequest getFederationTokenRequest = new GetFederationTokenRequest(); getFederationTokenRequest.setName(username); getFederationTokenRequest.setPolicy(getPolicyObject(username)); getFederationTokenRequest.setDurationSeconds(new Integer(Configuration.SESSION_DURATION)); try { return sts.getFederationToken(getFederationTokenRequest).getCredentials(); } catch (AmazonClientException e) { throw new DataAccessException("Failed to get federation token for user: " + username, e); } }