Search in sources :

Example 1 with ListWrapper

use of com.sun.identity.idsvcs.ListWrapper in project OpenAM by OpenRock.

the class IdentityServicesImpl method convertToIdentityDetails.

private IdentityDetails convertToIdentityDetails(AMIdentity amIdentity, List<String> attrList) throws IdRepoException, SSOException {
    IdentityDetails rv = null;
    if (amIdentity != null) {
        IdType idType = amIdentity.getType();
        Map<String, Set<String>> attrs;
        boolean addUniversalId = false;
        rv = new IdentityDetails();
        rv.setName(amIdentity.getName());
        rv.setType(amIdentity.getType().getName());
        rv.setRealm(amIdentity.getRealm());
        if (IdType.USER.equals(idType)) {
            Set<AMIdentity> roles = amIdentity.getMemberships(IdType.ROLE);
            if (roles != null && !roles.isEmpty()) {
                AMIdentity[] rolesFound = new AMIdentity[roles.size()];
                String[] roleNames = new String[rolesFound.length];
                roles.toArray(rolesFound);
                for (int i = 0; i < rolesFound.length; i++) {
                    roleNames[i] = rolesFound[i].getName();
                }
                rv.setRoleList(new ListWrapper(roleNames));
            }
            Set<AMIdentity> groups = amIdentity.getMemberships(IdType.GROUP);
            if ((groups != null) && (groups.size() > 0)) {
                AMIdentity[] groupsFound = new AMIdentity[groups.size()];
                String[] groupNames = new String[groupsFound.length];
                groups.toArray(groupsFound);
                for (int i = 0; i < groupsFound.length; i++) {
                    groupNames[i] = groupsFound[i].getName();
                }
                rv.setGroupList(new ListWrapper(groupNames));
            }
        }
        if (IdType.GROUP.equals(idType) || IdType.ROLE.equals(idType)) {
            Set<AMIdentity> members = amIdentity.getMembers(IdType.USER);
            if ((members != null) && (members.size() > 0)) {
                AMIdentity[] membersFound = new AMIdentity[members.size()];
                String[] memberNames = new String[membersFound.length];
                members.toArray(membersFound);
                for (int i = 0; i < membersFound.length; i++) {
                    memberNames[i] = membersFound[i].getName();
                }
                rv.setMemberList(new ListWrapper(memberNames));
            }
        }
        if (attrList != null) {
            Set<String> attrNames = new HashSet<>();
            for (String attrName : attrList) {
                if ("universalid".equalsIgnoreCase(attrName)) {
                    addUniversalId = true;
                } else {
                    if (!attrNames.contains(attrName)) {
                        attrNames.add(attrName);
                    }
                }
            }
            attrs = amIdentity.getAttributes(attrNames);
        } else {
            attrs = amIdentity.getAttributes();
            addUniversalId = true;
        }
        if (addUniversalId) {
            if (attrs == null) {
                attrs = new HashMap<>();
            }
            Set<String> uidValue = new HashSet<>();
            uidValue.add(amIdentity.getUniversalId());
            attrs.put("universalid", uidValue);
        }
        if (attrs != null) {
            rv.setAttributes(asAttributeArray(attrs));
        }
    }
    return rv;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) ListWrapper(com.sun.identity.idsvcs.ListWrapper) IdType(com.sun.identity.idm.IdType) AMIdentity(com.sun.identity.idm.AMIdentity) IdentityDetails(com.sun.identity.idsvcs.IdentityDetails) HashSet(java.util.HashSet)

Aggregations

AMIdentity (com.sun.identity.idm.AMIdentity)1 IdType (com.sun.identity.idm.IdType)1 IdentityDetails (com.sun.identity.idsvcs.IdentityDetails)1 ListWrapper (com.sun.identity.idsvcs.ListWrapper)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1