Java Code Examples for com.amazonaws.services.securitytoken.model.Credentials#setSecretAccessKey()
The following examples show how to use
com.amazonaws.services.securitytoken.model.Credentials#setSecretAccessKey() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AwsSessionServiceTest.java From Gatekeeper with Apache License 2.0 | 5 votes |
@Before public void before() { awsEnvironment = new AWSEnvironment("Dev", "us-west-2"); Mockito.when(gatekeeperAwsProperties.getSessionTimeout()).thenReturn(900000); Mockito.when(gatekeeperAwsProperties.getSessionTimeoutPad()).thenReturn(60000); List<Region> regions = new ArrayList<>(); Region testRegion1 = new Region(); Region testRegion2 = new Region(); testRegion1.setName("us-west-2"); testRegion2.setName("us-east-1"); regions.add(testRegion1); regions.add(testRegion2); Account fakeAccount = new Account(); fakeAccount.setAccountId("123"); fakeAccount.setAlias("hello"); fakeAccount.setRegions(regions); fakeAccount.setSdlc("Test"); fakeAccount.setName("Test Account"); AssumeRoleResult fakeRoleResult = new AssumeRoleResult(); Credentials fakeFreshCredentials = new Credentials(); // ( ͡° ͜ʖ ͡°) fakeFreshCredentials.setAccessKeyId("testing"); fakeFreshCredentials.setSecretAccessKey("s3cr3t"); fakeFreshCredentials.setSessionToken("s35510nt0k3n"); fakeRoleResult.setCredentials(fakeFreshCredentials); when(accountInformationService.getAccountByAlias("Dev")).thenReturn(fakeAccount); when(awsSecurityTokenServiceClient.assumeRole(any())).thenReturn(fakeRoleResult); when(awsSessionFactory.createEc2Session(any(), any())).thenReturn(amazonEC2Client); when(awsSessionFactory.createSsmSession(any(), any())).thenReturn(awsSimpleSystemsManagementClient); }
Example 2
Source File: ZTSClientMock.java From athenz with Apache License 2.0 | 5 votes |
@Override Credentials assumeAWSRole(String account, String roleName) { Credentials creds = new Credentials(); creds.setAccessKeyId("access"); creds.setSecretAccessKey("secret"); creds.setSessionToken("token"); return creds; }
Example 3
Source File: StsDaoTest.java From herd with Apache License 2.0 | 5 votes |
@Test public void testGetTemporarySecurityCredentials() { // Create an AWS parameters DTO with proxy settings. AwsParamsDto awsParamsDto = new AwsParamsDto(); awsParamsDto.setHttpProxyHost(HTTP_PROXY_HOST); awsParamsDto.setHttpProxyPort(HTTP_PROXY_PORT); // Specify the duration, in seconds, of the role session. int awsRoleDurationSeconds = INTEGER_VALUE; // Create an IAM policy. Policy policy = new Policy(STRING_VALUE); // Create a retry policy. RetryPolicy retryPolicy = new RetryPolicy(PredefinedRetryPolicies.DEFAULT_RETRY_CONDITION, PredefinedRetryPolicies.DEFAULT_BACKOFF_STRATEGY, INTEGER_VALUE, true); // Create the expected assume role request. AssumeRoleRequest assumeRoleRequest = new AssumeRoleRequest().withRoleArn(AWS_ROLE_ARN).withRoleSessionName(SESSION_NAME).withPolicy(policy.toJson()) .withDurationSeconds(awsRoleDurationSeconds); // Create AWS credentials for API authentication. Credentials credentials = new Credentials(); credentials.setAccessKeyId(AWS_ASSUMED_ROLE_ACCESS_KEY); credentials.setSecretAccessKey(AWS_ASSUMED_ROLE_SECRET_KEY); credentials.setSessionToken(AWS_ASSUMED_ROLE_SESSION_TOKEN); // Create an assume role result. AssumeRoleResult assumeRoleResult = new AssumeRoleResult(); assumeRoleResult.setCredentials(credentials); // Mock the external calls. when(retryPolicyFactory.getRetryPolicy()).thenReturn(retryPolicy); when(stsOperations.assumeRole(any(AWSSecurityTokenServiceClient.class), eq(assumeRoleRequest))).thenReturn(assumeRoleResult); // Call the method under test. Credentials result = stsDaoImpl.getTemporarySecurityCredentials(awsParamsDto, SESSION_NAME, AWS_ROLE_ARN, awsRoleDurationSeconds, policy); // Verify the external calls. verify(retryPolicyFactory).getRetryPolicy(); verify(stsOperations).assumeRole(any(AWSSecurityTokenServiceClient.class), eq(assumeRoleRequest)); verifyNoMoreInteractionsHelper(); // Validate the returned object. assertEquals(credentials, result); }
Example 4
Source File: StsDaoTest.java From herd with Apache License 2.0 | 5 votes |
@Test public void testGetTemporarySecurityCredentialsMissingOptionalParameters() { // Create an AWS parameters DTO without proxy settings. AwsParamsDto awsParamsDto = new AwsParamsDto(); // Specify the duration, in seconds, of the role session. int awsRoleDurationSeconds = INTEGER_VALUE; // Create a retry policy. RetryPolicy retryPolicy = new RetryPolicy(PredefinedRetryPolicies.DEFAULT_RETRY_CONDITION, PredefinedRetryPolicies.DEFAULT_BACKOFF_STRATEGY, INTEGER_VALUE, true); // Create the expected assume role request. AssumeRoleRequest assumeRoleRequest = new AssumeRoleRequest().withRoleArn(AWS_ROLE_ARN).withRoleSessionName(SESSION_NAME).withDurationSeconds(awsRoleDurationSeconds); // Create AWS credentials for API authentication. Credentials credentials = new Credentials(); credentials.setAccessKeyId(AWS_ASSUMED_ROLE_ACCESS_KEY); credentials.setSecretAccessKey(AWS_ASSUMED_ROLE_SECRET_KEY); credentials.setSessionToken(AWS_ASSUMED_ROLE_SESSION_TOKEN); // Create an assume role result. AssumeRoleResult assumeRoleResult = new AssumeRoleResult(); assumeRoleResult.setCredentials(credentials); // Mock the external calls. when(retryPolicyFactory.getRetryPolicy()).thenReturn(retryPolicy); when(stsOperations.assumeRole(any(AWSSecurityTokenServiceClient.class), eq(assumeRoleRequest))).thenReturn(assumeRoleResult); // Call the method under test. Please note that we do not specify an IAM policy. Credentials result = stsDaoImpl.getTemporarySecurityCredentials(awsParamsDto, SESSION_NAME, AWS_ROLE_ARN, awsRoleDurationSeconds, null); // Verify the external calls. verify(retryPolicyFactory).getRetryPolicy(); verify(stsOperations).assumeRole(any(AWSSecurityTokenServiceClient.class), eq(assumeRoleRequest)); verifyNoMoreInteractionsHelper(); // Validate the returned object. assertEquals(credentials, result); }