Search in sources :

Example 1 with AmazonIdentityManagementClient

use of com.amazonaws.services.identitymanagement.AmazonIdentityManagementClient in project aws-iam-ldap-bridge by denismo.

the class LDAPIAMPoller method populateUsersFromIAM.

private void populateUsersFromIAM() {
    AmazonIdentityManagementClient client = new AmazonIdentityManagementClient(credentials);
    try {
        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, groups);
                    updateGroups(groups, user);
                    allUsers.add(user.getUserName());
                    LOG.debug("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();
    }
}
Also used : AmazonIdentityManagementClient(com.amazonaws.services.identitymanagement.AmazonIdentityManagementClient)

Example 2 with AmazonIdentityManagementClient

use of com.amazonaws.services.identitymanagement.AmazonIdentityManagementClient in project aws-iam-ldap-bridge by denismo.

the class LDAPIAMPoller method populateRolesFromIAM.

private void populateRolesFromIAM() {
    AmazonIdentityManagementClient client = new AmazonIdentityManagementClient(credentials);
    try {
        ListRolesResult res = client.listRoles();
        while (true) {
            for (Role role : res.getRoles()) {
                try {
                    Entry groupEntry = getOrCreateRoleGroup(role);
                    addRole(role, groupEntry);
                    LOG.debug("Added role " + role.getRoleName() + " at " + rolesDN);
                } catch (Throwable e) {
                    LOG.error("Exception processing role " + role.getRoleName(), e);
                }
            }
            if (res.isTruncated()) {
                res = client.listRoles(new ListRolesRequest().withMarker(res.getMarker()));
            } else {
                break;
            }
        }
    } finally {
        client.shutdown();
    }
}
Also used : AmazonIdentityManagementClient(com.amazonaws.services.identitymanagement.AmazonIdentityManagementClient)

Example 3 with AmazonIdentityManagementClient

use of com.amazonaws.services.identitymanagement.AmazonIdentityManagementClient in project aws-iam-ldap-bridge by denismo.

the class IAMSecretKeyValidator method verifyIAMPassword.

@Override
public boolean verifyIAMPassword(Entry user, String pw) throws LdapInvalidAttributeValueException, LdapAuthenticationException {
    boolean role = false;
    AWSCredentials creds;
    if (isRole(user)) {
        role = true;
        String[] parts = pw.split("\\|");
        if (parts == null || parts.length < 3)
            throw new LdapAuthenticationException();
        creds = new BasicSessionCredentials(parts[0], parts[1], parts[2]);
    } else {
        creds = new BasicAWSCredentials(user.get("accessKey").getString(), pw);
    }
    LOG.debug("Verifying {} {} with accessKey <hidden> and secretKey <hidden>", role ? "role" : "user", user.get("uid").getString());
    AmazonIdentityManagementClient client = new AmazonIdentityManagementClient(creds);
    try {
        client.getAccountSummary();
    } catch (AmazonClientException e) {
        System.err.println(e.getMessage());
        return false;
    } finally {
        client.shutdown();
    }
    return true;
}
Also used : AmazonIdentityManagementClient(com.amazonaws.services.identitymanagement.AmazonIdentityManagementClient) LdapAuthenticationException(org.apache.directory.api.ldap.model.exception.LdapAuthenticationException) BasicSessionCredentials(com.amazonaws.auth.BasicSessionCredentials) AmazonClientException(com.amazonaws.AmazonClientException) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) AWSCredentials(com.amazonaws.auth.AWSCredentials) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials)

Example 4 with AmazonIdentityManagementClient

use of com.amazonaws.services.identitymanagement.AmazonIdentityManagementClient in project aws-iam-ldap-bridge by denismo.

the class LDAPIAMPoller method populateGroupsFromIAM.

private void populateGroupsFromIAM() {
    AmazonIdentityManagementClient client = new AmazonIdentityManagementClient(credentials);
    try {
        ListGroupsResult res = client.listGroups();
        Set<String> groupNames = new HashSet<String>();
        while (true) {
            for (Group group : res.getGroups()) {
                try {
                    addGroup(group);
                    groupNames.add(group.getGroupName());
                    LOG.debug("Added group " + group.getGroupName() + " at " + groupsDN);
                } catch (Throwable e) {
                    LOG.error("Exception processing group " + group.getGroupName(), e);
                }
            }
            if (res.isTruncated()) {
                res = client.listGroups(new ListGroupsRequest().withMarker(res.getMarker()));
            } else {
                break;
            }
        }
        removeDeletedGroups(groupNames);
    } finally {
        client.shutdown();
    }
}
Also used : AmazonIdentityManagementClient(com.amazonaws.services.identitymanagement.AmazonIdentityManagementClient)

Aggregations

AmazonIdentityManagementClient (com.amazonaws.services.identitymanagement.AmazonIdentityManagementClient)4 AmazonClientException (com.amazonaws.AmazonClientException)1 AWSCredentials (com.amazonaws.auth.AWSCredentials)1 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)1 BasicSessionCredentials (com.amazonaws.auth.BasicSessionCredentials)1 LdapAuthenticationException (org.apache.directory.api.ldap.model.exception.LdapAuthenticationException)1