com.amazonaws.services.identitymanagement.model.User Java Examples
The following examples show how to use
com.amazonaws.services.identitymanagement.model.User.
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: IAMService.java From Serverless-Programming-Cookbook with MIT License | 6 votes |
/** * Check user. * @param userName - user name. * @return IAMOperationResponse */ public final IAMOperationResponse checkUser(final String userName) { boolean done = false; ListUsersRequest request = new ListUsersRequest(); while (!done) { ListUsersResult response = iamClient.listUsers(request); for (User user : response.getUsers()) { if (user.getUserName().equals(userName)) { return new IAMOperationResponse("User " + userName + " exist", null); } } request.setMarker(response.getMarker()); if (!response.getIsTruncated()) { done = true; } } return new IAMOperationResponse(null, "User " + userName + " does not exist"); }
Example #2
Source File: IAMServiceImpl.java From Serverless-Programming-Cookbook with MIT License | 6 votes |
@Override public final IAMOperationResponse checkUser(final String userName) { boolean done = false; ListUsersRequest request = new ListUsersRequest(); while (!done) { ListUsersResult response = iamClient.listUsers(request); for (User user : response.getUsers()) { if (user.getUserName().equals(userName)) { return new IAMOperationResponse("User " + userName + " exist", null); } } request.setMarker(response.getMarker()); if (!response.getIsTruncated()) { done = true; } } return new IAMOperationResponse(null, "User " + userName + " does not exist"); }
Example #3
Source File: ListUsers.java From aws-doc-sdk-examples with Apache License 2.0 | 6 votes |
public static void main(String[] args) { final AmazonIdentityManagement iam = AmazonIdentityManagementClientBuilder.defaultClient(); boolean done = false; ListUsersRequest request = new ListUsersRequest(); while(!done) { ListUsersResult response = iam.listUsers(request); for(User user : response.getUsers()) { System.out.format("Retrieved user %s", user.getUserName()); } request.setMarker(response.getMarker()); if(!response.getIsTruncated()) { done = true; } } }
Example #4
Source File: BasicPlan.java From s3-cf-service-broker with Apache License 2.0 | 6 votes |
public ServiceInstanceBinding createServiceInstanceBinding(String bindingId, ServiceInstance serviceInstance, String serviceId, String planId, String appGuid) { User user = iam.createUserForBinding(bindingId); AccessKey accessKey = iam.createAccessKey(user); // TODO create password and add to credentials iam.addUserToGroup(user, iam.getGroupNameForInstance(serviceInstance.getId())); String bucketName = s3.getBucketNameForInstance(serviceInstance.getId()); Map<String, Object> credentials = new HashMap<String, Object>(); credentials.put("bucket", bucketName); credentials.put("username", user.getUserName()); credentials.put("access_key_id", accessKey.getAccessKeyId()); credentials.put("secret_access_key", accessKey.getSecretAccessKey()); credentials.put("host", AMAZON_S3_HOST); credentials.put("uri", this.generateUri(accessKey.getAccessKeyId(), accessKey.getSecretAccessKey(), bucketName)); return new ServiceInstanceBinding(bindingId, serviceInstance.getId(), credentials, null, appGuid); }
Example #5
Source File: IAMServiceImplTest.java From Serverless-Programming-Cookbook with MIT License | 5 votes |
@Test public void testCreateUser() { IAMOperationResponse expectedResponse = new IAMOperationResponse( "Created user test_user", null); when(iamClient.createUser(any())) .thenReturn(new CreateUserResult() .withUser(new User().withUserName("test_user"))); IAMOperationResponse actualResponse = service.createUser("test_user"); Assert.assertEquals(expectedResponse, actualResponse); }
Example #6
Source File: KeyRotationJobTest.java From fullstop with Apache License 2.0 | 5 votes |
@Before public void setUp() { mockIAMDataSource = mock(IdentityManagementDataSource.class); mockViolationWriter = mock(KeyRotationViolationWriter.class); mockAccountIdSupplier = mock(AccountIdSupplier.class); when(mockAccountIdSupplier.get()).thenReturn(newHashSet("account01", "account02")); when(mockIAMDataSource.getUsers(eq("account01"))).thenReturn(singletonList(new User())); when(mockIAMDataSource.getUsers(eq("account02"))).thenReturn(asList(new User(), new User())); when(mockIAMDataSource.getAccessKeys(eq("account01"), any())).thenReturn(asList( upToDate(active(new AccessKeyMetadata())), expired(active(new AccessKeyMetadata())), expired(inactive(new AccessKeyMetadata())))); when(mockIAMDataSource.getAccessKeys(eq("account02"), any())).thenReturn(singletonList(upToDate(inactive(new AccessKeyMetadata())))); }
Example #7
Source File: AmazonRdsDataSourceUserTagsFactoryBeanTest.java From spring-cloud-aws with Apache License 2.0 | 5 votes |
@Test void getObject_instanceWithTagsConfiguredWithCustomResourceResolverAndCustomRegion_mapWithTagsReturned() throws Exception { // Arrange AmazonRDS amazonRds = mock(AmazonRDS.class); ResourceIdResolver resourceIdResolver = mock(ResourceIdResolver.class); AmazonIdentityManagement amazonIdentityManagement = mock( AmazonIdentityManagement.class); AmazonRdsDataSourceUserTagsFactoryBean factoryBean = new AmazonRdsDataSourceUserTagsFactoryBean( amazonRds, "test", amazonIdentityManagement); factoryBean.setResourceIdResolver(resourceIdResolver); factoryBean.setRegion(Region.getRegion(Regions.EU_WEST_1)); when(resourceIdResolver.resolveToPhysicalResourceId("test")) .thenReturn("stack-test"); when(amazonIdentityManagement.getUser()).thenReturn( new GetUserResult().withUser(new User("/", "aemruli", "123456789012", "arn:aws:iam::1234567890:user/aemruli", new Date()))); when(amazonRds.listTagsForResource(new ListTagsForResourceRequest() .withResourceName("arn:aws:rds:eu-west-1:1234567890:db:stack-test"))) .thenReturn(new ListTagsForResourceResult().withTagList( new Tag().withKey("key1").withValue("value1"), new Tag().withKey("key2").withValue("value2"))); // Act factoryBean.afterPropertiesSet(); Map<String, String> userTagMap = factoryBean.getObject(); // Assert assertThat(userTagMap.get("key1")).isEqualTo("value1"); assertThat(userTagMap.get("key2")).isEqualTo("value2"); }
Example #8
Source File: AmazonRdsDataSourceUserTagsFactoryBeanTest.java From spring-cloud-aws with Apache License 2.0 | 5 votes |
@Test void getObject_instanceWithOutTags_emptyMapReturned() throws Exception { // Arrange AmazonRDS amazonRds = mock(AmazonRDS.class); ResourceIdResolver resourceIdResolver = mock(ResourceIdResolver.class); AmazonIdentityManagement amazonIdentityManagement = mock( AmazonIdentityManagement.class); AmazonRdsDataSourceUserTagsFactoryBean factoryBean = new AmazonRdsDataSourceUserTagsFactoryBean( amazonRds, "test", amazonIdentityManagement); factoryBean.setResourceIdResolver(resourceIdResolver); factoryBean.setResourceIdResolver(resourceIdResolver); factoryBean.setRegion(Region.getRegion(Regions.EU_WEST_1)); when(resourceIdResolver.resolveToPhysicalResourceId("test")) .thenReturn("stack-test"); when(amazonIdentityManagement.getUser()).thenReturn( new GetUserResult().withUser(new User("/", "aemruli", "123456789012", "arn:aws:iam::1234567890:user/aemruli", new Date()))); when(amazonRds.listTagsForResource(new ListTagsForResourceRequest() .withResourceName("arn:aws:rds:eu-west-1:1234567890:db:stack-test"))) .thenReturn(new ListTagsForResourceResult()); // Act factoryBean.afterPropertiesSet(); Map<String, String> userTagMap = factoryBean.getObject(); // Assert assertThat(userTagMap.isEmpty()).isTrue(); }
Example #9
Source File: AmazonRdsDataSourceUserTagsFactoryBeanTest.java From spring-cloud-aws with Apache License 2.0 | 5 votes |
@Test void getObject_instanceWithTagsAndNoResourceIdResolverAndDefaultRegion_mapWithTagsReturned() throws Exception { // Arrange AmazonRDS amazonRds = mock(AmazonRDS.class); AmazonIdentityManagement amazonIdentityManagement = mock( AmazonIdentityManagement.class); AmazonRdsDataSourceUserTagsFactoryBean factoryBean = new AmazonRdsDataSourceUserTagsFactoryBean( amazonRds, "test", amazonIdentityManagement); when(amazonIdentityManagement.getUser()).thenReturn( new GetUserResult().withUser(new User("/", "aemruli", "123456789012", "arn:aws:iam::1234567890:user/aemruli", new Date()))); when(amazonRds.listTagsForResource(new ListTagsForResourceRequest() .withResourceName("arn:aws:rds:us-west-2:1234567890:db:test"))) .thenReturn(new ListTagsForResourceResult().withTagList( new Tag().withKey("key1").withValue("value1"), new Tag().withKey("key2").withValue("value2"))); // Act factoryBean.afterPropertiesSet(); Map<String, String> userTagMap = factoryBean.getObject(); // Assert assertThat(userTagMap.get("key1")).isEqualTo("value1"); assertThat(userTagMap.get("key2")).isEqualTo("value2"); }
Example #10
Source File: IAMServiceImplTest.java From Serverless-Programming-Cookbook with MIT License | 4 votes |
private ListUsersResult getListUsersResult() { ListUsersResult result = new ListUsersResult(); result.getUsers().add(new User().withUserName("test_user")); return result; }
Example #11
Source File: InventoryUtilTest.java From pacbot with Apache License 2.0 | 4 votes |
/** * Fetch IAM users test. * * @throws Exception the exception */ @SuppressWarnings("static-access") @Test public void fetchIAMUsersTest() throws Exception { mockStatic(AmazonIdentityManagementClientBuilder.class); AmazonIdentityManagement iamClient = PowerMockito.mock(AmazonIdentityManagement.class); AmazonIdentityManagementClientBuilder amazonIdentityManagementClientBuilder = PowerMockito.mock(AmazonIdentityManagementClientBuilder.class); AWSStaticCredentialsProvider awsStaticCredentialsProvider = PowerMockito.mock(AWSStaticCredentialsProvider.class); PowerMockito.whenNew(AWSStaticCredentialsProvider.class).withAnyArguments().thenReturn(awsStaticCredentialsProvider); when(amazonIdentityManagementClientBuilder.standard()).thenReturn(amazonIdentityManagementClientBuilder); when(amazonIdentityManagementClientBuilder.withCredentials(anyObject())).thenReturn(amazonIdentityManagementClientBuilder); when(amazonIdentityManagementClientBuilder.withRegion(anyString())).thenReturn(amazonIdentityManagementClientBuilder); when(amazonIdentityManagementClientBuilder.build()).thenReturn(iamClient); ListUsersResult listUsersResult = new ListUsersResult(); List<User> users = new ArrayList<>(); User user = new User(); user.setUserName("name"); users.add(user); listUsersResult.setUsers(users); when(iamClient.listUsers(anyObject())).thenReturn(listUsersResult); ListAccessKeysResult listAccessKeysResult = new ListAccessKeysResult(); List<AccessKeyMetadata> accessKeyMetadataList = new ArrayList<>(); AccessKeyMetadata accessKeyMetadata = new AccessKeyMetadata(); accessKeyMetadata.setAccessKeyId("accessKeyId"); accessKeyMetadataList.add(accessKeyMetadata); listAccessKeysResult.setAccessKeyMetadata(accessKeyMetadataList ); when(iamClient.listAccessKeys(anyObject())).thenReturn(listAccessKeysResult); GetAccessKeyLastUsedResult getAccessKeyLastUsedResult = new GetAccessKeyLastUsedResult(); AccessKeyLastUsed accessKeyLastUsed = new AccessKeyLastUsed(); accessKeyLastUsed.setLastUsedDate(new Date()); getAccessKeyLastUsedResult.setAccessKeyLastUsed(accessKeyLastUsed ); when(iamClient.getAccessKeyLastUsed(anyObject())).thenReturn(getAccessKeyLastUsedResult); GetLoginProfileResult getLoginProfileResult = new GetLoginProfileResult(); LoginProfile loginProfile = new LoginProfile(); loginProfile.setCreateDate(new Date()); loginProfile.setPasswordResetRequired(false); getLoginProfileResult.setLoginProfile(loginProfile ); when(iamClient.getLoginProfile(anyObject())).thenReturn(getLoginProfileResult ); ListGroupsForUserResult listGroupsForUserResult = new ListGroupsForUserResult(); List<Group> groups = new ArrayList<>(); Group group = new Group(); group.setGroupName("groupName"); groups.add(group); listGroupsForUserResult.setGroups(groups ); when(iamClient.listGroupsForUser(anyObject())).thenReturn(listGroupsForUserResult ); ListMFADevicesResult listMFADevicesResult = new ListMFADevicesResult(); listMFADevicesResult.setMFADevices(new ArrayList<>());; when(iamClient.listMFADevices(anyObject())).thenReturn(listMFADevicesResult ); assertThat(inventoryUtil.fetchIAMUsers(new BasicSessionCredentials("awsAccessKey", "awsSecretKey", "sessionToken"), "account","accountName").size(), is(1)); listMFADevicesResult = new ListMFADevicesResult(); List<MFADevice> mfaDevices = new ArrayList<>(); mfaDevices.add(new MFADevice()); listMFADevicesResult.setMFADevices(mfaDevices); when(iamClient.listMFADevices(anyObject())).thenReturn(listMFADevicesResult ); assertThat(inventoryUtil.fetchIAMUsers(new BasicSessionCredentials("awsAccessKey", "awsSecretKey", "sessionToken"), "account","accountName").size(), is(1)); }
Example #12
Source File: BasicPlanIam.java From s3-cf-service-broker with Apache License 2.0 | 4 votes |
public User createUserForBinding(String bindingId) { String userName = getUserNameForBinding(bindingId); logger.info("Creating user '{}' for service binding '{}'", userName, bindingId); return createUser(userName); }
Example #13
Source File: UserVH.java From pacbot with Apache License 2.0 | 2 votes |
/** * Instantiates a new user VH. * * @param usr the usr */ public UserVH(User usr){ this.user = usr; }