List of usage examples for com.amazonaws.services.identitymanagement.model ListGroupsForUserRequest ListGroupsForUserRequest
public ListGroupsForUserRequest(String userName)
From source file:com.denismo.aws.iam.LDAPIAMPoller.java
License:Apache License
private void populateUsersFromIAM() { AmazonIdentityManagementClient client = new AmazonIdentityManagementClient(credentials); try {/*from w w w .j ava 2 s .co m*/ ListUsersResult res = client.listUsers(); Set<String> allUsers = new HashSet<String>(); while (true) { for (User user : res.getUsers()) { try { Collection<Group> groups = client .listGroupsForUser(new ListGroupsForUserRequest(user.getUserName())).getGroups(); Group primaryGroup = groups.size() > 0 ? groups.iterator().next() : null; if (primaryGroup == null) { LOG.warn("Unable to determine primary group for " + user.getUserName()); continue; } Entry groupEntry = getExistingGroup(primaryGroup); if (groupEntry == null) { LOG.warn("Unable to retrieve matching group entry for group " + primaryGroup.getGroupName() + " user " + user.getUserName()); continue; } addUser(user, getUserAccessKey(client, user), groupEntry); updateGroups(groups, user); allUsers.add(user.getUserName()); LOG.info("Added user " + user.getUserName()); } catch (Throwable e) { LOG.error("Exception processing user " + user.getUserName(), e); } } if (res.isTruncated()) { res = client.listUsers(new ListUsersRequest().withMarker(res.getMarker())); } else { break; } } removeDeletedUsers(allUsers); } finally { client.shutdown(); } }
From source file:org.dasein.prototype.iamc.AWS.java
License:Apache License
public boolean deleteUser(String username) { try {//from ww w . j a va2 s .c o m for (String policy : iamClient.listUserPolicies(new ListUserPoliciesRequest(username)) .getPolicyNames()) { iamClient.deleteUserPolicy(new DeleteUserPolicyRequest(username, policy)); } } catch (NoSuchEntityException ignore) { } try { for (Group group : iamClient.listGroupsForUser(new ListGroupsForUserRequest(username)).getGroups()) { iamClient.removeUserFromGroup(new RemoveUserFromGroupRequest(group.getGroupName(), username)); } } catch (NoSuchEntityException ignore) { } try { iamClient.deleteLoginProfile(new DeleteLoginProfileRequest(username)); } catch (Exception ignore) { } try { iamClient.deleteUser(new DeleteUserRequest(username)); return true; } catch (NoSuchEntityException e) { } catch (DeleteConflictException e) { e.printStackTrace(System.err); } return false; }