@Test public void testAssumeRoleWithSourceAfterRole() throws Exception { ProfilesConfigFile profilesFile = new ProfilesConfigFile( ProfileResourceLoader.profileWithSourceAfterRole().asFile(), new ProfileCredentialsService() { @Override public AWSCredentialsProvider getAssumeRoleCredentialsProvider( RoleInfo targetRoleInfo) { AWSCredentials credentials = targetRoleInfo .getLongLivedCredentialsProvider().getCredentials(); Assert.assertEquals("sourceProfile AWSAccessKeyId", "defaultAccessKey", credentials.getAWSAccessKeyId()); Assert.assertEquals("sourceProfile AWSSecretKey", "defaultSecretAccessKey", credentials.getAWSSecretKey()); Assert.assertEquals("role_arn", "arn:aws:iam::123456789012:role/testRole", targetRoleInfo.getRoleArn()); Assert.assertNull("external_id", targetRoleInfo.getExternalId()); Assert.assertTrue("role_session_name", targetRoleInfo.getRoleSessionName() .startsWith("aws-sdk-java-")); return new StaticCredentialsProvider( new BasicAWSCredentials("sessionAccessKey", "sessionSecretKey")); } }); ProfileCredentialsProvider profileCredentialsProvider = new ProfileCredentialsProvider( profilesFile, "test"); AWSCredentials credentials = profileCredentialsProvider.getCredentials(); Assert.assertEquals("sessionAccessKey", credentials.getAWSAccessKeyId()); Assert.assertEquals("sessionSecretKey", credentials.getAWSSecretKey()); }
@Override public AWSCredentials getCredentials() { if (profilesConfigFile == null) { synchronized (this) { if (profilesConfigFile == null) { profilesConfigFile = new ProfilesConfigFile(); lastRefreshed = System.nanoTime(); } } } long now = System.nanoTime(); long age = now - lastRefreshed; if (age > refreshForceIntervalNanos) { refresh(); } else if (age > refreshIntervalNanos) { if (refreshSemaphore.tryAcquire()) { try { refresh(); } finally { refreshSemaphore.release(); } } } return profilesConfigFile.getCredentials(profileName); }
ProfileCredentialsProvider implements AWSCredentialsProvider { @Override public AWSCredentials getCredentials() { if (profilesConfigFile == null) { synchronized (this) { if (profilesConfigFile == null) { profilesConfigFile = new ProfilesConfigFile(); lastRefreshed = System.nanoTime(); } } } long now = System.nanoTime(); long age = now - lastRefreshed; if (age > refreshForceIntervalNanos) { refresh(); } else if (age > refreshIntervalNanos) { if (refreshSemaphore.tryAcquire()) { try { refresh(); } finally { refreshSemaphore.release(); } } } return profilesConfigFile.getCredentials(profileName); } }
ProfileCredentialsProvider implements AWSCredentialsProvider { @Override public AWSCredentials getCredentials() { if (profilesConfigFile == null) { synchronized (this) { if (profilesConfigFile == null) { profilesConfigFile = new ProfilesConfigFile(); lastRefreshed = System.nanoTime(); } } } long now = System.nanoTime(); long age = now - lastRefreshed; if (age > refreshForceIntervalNanos) { refresh(); } else if (age > refreshIntervalNanos) { if (refreshSemaphore.tryAcquire()) { try { refresh(); } finally { refreshSemaphore.release(); } } } return profilesConfigFile.getCredentials(profileName); } ProfileCredentialsProvider();  ProfileCredentialsProvider(String profileName);  ProfileCredentialsProvider(String profilesConfigFilePath, String profileName);  ProfileCredentialsProvider(ProfilesConfigFile profilesConfigFile, String profileName); }
ProfileCredentialsProvider implements AWSCredentialsProvider { @Override public AWSCredentials getCredentials() { if (profilesConfigFile == null) { synchronized (this) { if (profilesConfigFile == null) { profilesConfigFile = new ProfilesConfigFile(); lastRefreshed = System.nanoTime(); } } } long now = System.nanoTime(); long age = now - lastRefreshed; if (age > refreshForceIntervalNanos) { refresh(); } else if (age > refreshIntervalNanos) { if (refreshSemaphore.tryAcquire()) { try { refresh(); } finally { refreshSemaphore.release(); } } } return profilesConfigFile.getCredentials(profileName); } ProfileCredentialsProvider();  ProfileCredentialsProvider(String profileName);  ProfileCredentialsProvider(String profilesConfigFilePath, String profileName);  ProfileCredentialsProvider(ProfilesConfigFile profilesConfigFile, String profileName); @Override AWSCredentials getCredentials(); @Override void refresh(); long getRefreshIntervalNanos(); void setRefreshIntervalNanos(long refreshIntervalNanos); long getRefreshForceIntervalNanos(); void setRefreshForceIntervalNanos(long refreshForceIntervalNanos); }
ProfileCredentialsProvider implements AWSCredentialsProvider { @Override public AWSCredentials getCredentials() { if (profilesConfigFile == null) { synchronized (this) { if (profilesConfigFile == null) { profilesConfigFile = new ProfilesConfigFile(); lastRefreshed = System.nanoTime(); } } } long now = System.nanoTime(); long age = now - lastRefreshed; if (age > refreshForceIntervalNanos) { refresh(); } else if (age > refreshIntervalNanos) { if (refreshSemaphore.tryAcquire()) { try { refresh(); } finally { refreshSemaphore.release(); } } } return profilesConfigFile.getCredentials(profileName); } ProfileCredentialsProvider();  ProfileCredentialsProvider(String profileName);  ProfileCredentialsProvider(String profilesConfigFilePath, String profileName);  ProfileCredentialsProvider(ProfilesConfigFile profilesConfigFile, String profileName); @Override AWSCredentials getCredentials(); @Override void refresh(); long getRefreshIntervalNanos(); void setRefreshIntervalNanos(long refreshIntervalNanos); long getRefreshForceIntervalNanos(); void setRefreshForceIntervalNanos(long refreshForceIntervalNanos);  }