Search in sources :

Example 6 with UserAttributeParam

use of com.emc.storageos.model.usergroup.UserAttributeParam in project coprhd-controller by CoprHD.

the class StorageOSLdapPersonAttributeDao method getReturningAttributesFromUserGroups.

/**
 * Get the list of returning attributes AD or LDAP servers
 * based on the configured user group.
 *
 * @param permissionsHelper to find and match the db objects.
 * @param domain to find all the configured user group for the domain.
 * @param attrs out param, to be updated with the list of attributes
 *            to be returned from the AD or LDAP servers.
 */
private void getReturningAttributesFromUserGroups(BasePermissionsHelper permissionsHelper, String domain, List<String> attrs) {
    if (StringUtils.isBlank(domain)) {
        _log.info("Invalid domain {} to search user group", domain);
        return;
    }
    List<UserGroup> userGroupList = permissionsHelper.getAllUserGroupForDomain(domain);
    if (CollectionUtils.isEmpty(userGroupList)) {
        _log.debug("User group not found for the domain {}", domain);
        return;
    }
    for (UserGroup userGroup : userGroupList) {
        if (userGroup == null || CollectionUtils.isEmpty(userGroup.getAttributes())) {
            continue;
        }
        for (String userAttributesString : userGroup.getAttributes()) {
            if (StringUtils.isBlank(userAttributesString)) {
                _log.info("Invalid user attributes param string {}", userAttributesString);
                continue;
            }
            UserAttributeParam userAttributeParam = UserAttributeParam.fromString(userAttributesString);
            if (userAttributeParam == null) {
                _log.info("Conversion from user attributes param string {} to attributes param object failed.", userAttributesString);
                continue;
            }
            _log.debug("Adding attribute {} to the returning attributes list", userAttributeParam.getKey());
            attrs.add(userAttributeParam.getKey());
        }
    }
}
Also used : UserGroup(com.emc.storageos.db.client.model.UserGroup) UserAttributeParam(com.emc.storageos.model.usergroup.UserAttributeParam)

Example 7 with UserAttributeParam

use of com.emc.storageos.model.usergroup.UserAttributeParam in project coprhd-controller by CoprHD.

the class StorageOSUserMapper method mapFromAttributes.

/*
     * @see org.springframework.ldap.core.AttributesMapper#mapFromAttributes(javax.naming.directory.Attributes)
     * creates StorageOSUserDAO from attributes
     */
@Override
public Object mapFromAttributes(Attributes attributes) throws NamingException {
    StorageOSUserDAO storageOSUser = new StorageOSUserDAO();
    storageOSUser.setUserName(_username);
    NamingEnumeration<? extends Attribute> attributesEnumeration = attributes.getAll();
    while (attributesEnumeration.hasMoreElements()) {
        Attribute attribute = attributesEnumeration.nextElement();
        NamingEnumeration<?> attributeValues = attribute.getAll();
        if (attribute.getID().equals(_distinguishedNameAttribute)) {
            if (null != attribute.get(0)) {
                storageOSUser.setDistinguishedName(attribute.get(0).toString());
            }
        }
        List<String> values = new ArrayList<String>();
        while (attributeValues.hasMoreElements()) {
            values.add(attributeValues.nextElement().toString());
        }
        _attrKeyValueMap.put(attribute.getID(), values);
        // Add the returned attributes from the AD/LDAP to the user.
        UserAttributeParam userAttributeParam = new UserAttributeParam(attribute.getID(), new HashSet(values));
        String attributeString = userAttributeParam.toString();
        storageOSUser.addAttribute(attributeString);
        _log.debug("Adding attribute {} to user", attributeString);
    }
    return storageOSUser;
}
Also used : StorageOSUserDAO(com.emc.storageos.db.client.model.StorageOSUserDAO) Attribute(javax.naming.directory.Attribute) ArrayList(java.util.ArrayList) UserAttributeParam(com.emc.storageos.model.usergroup.UserAttributeParam) HashSet(java.util.HashSet)

Example 8 with UserAttributeParam

use of com.emc.storageos.model.usergroup.UserAttributeParam in project coprhd-controller by CoprHD.

the class UserGroupMapper method map.

public static final UserGroupRestRep map(UserGroup from) {
    if (from == null) {
        _log.info("Invalid user group");
        return null;
    }
    UserGroupRestRep to = new UserGroupRestRep();
    mapDataObjectFields(from, to);
    to.setDomain(from.getDomain());
    if (CollectionUtils.isEmpty(from.getAttributes())) {
        _log.error("Empty attributes list in user group {}", from.getLabel());
        return to;
    }
    for (String attributeString : from.getAttributes()) {
        if (StringUtils.isBlank(attributeString)) {
            _log.info("Invalid attribute param string in user group {}", from.getLabel());
            continue;
        }
        UserAttributeParam attribute = UserAttributeParam.fromString(attributeString);
        to.getAttributes().add(attribute);
    }
    return to;
}
Also used : UserGroupRestRep(com.emc.storageos.model.usergroup.UserGroupRestRep) UserAttributeParam(com.emc.storageos.model.usergroup.UserAttributeParam)

Example 9 with UserAttributeParam

use of com.emc.storageos.model.usergroup.UserAttributeParam in project coprhd-controller by CoprHD.

the class UserGroupMapper method map.

public static final UserGroup map(UserGroupCreateParam from) {
    if (from == null) {
        _log.info("Invalid user group create param");
        return null;
    }
    UserGroup to = new UserGroup();
    to.setDomain(from.getDomain());
    to.setLabel(from.getLabel());
    Map<String, UserAttributeParam> attributeParamMap = new TreeMap<String, UserAttributeParam>(String.CASE_INSENSITIVE_ORDER);
    if (!CollectionUtils.isEmpty(from.getAttributes())) {
        for (UserAttributeParam attribute : from.getAttributes()) {
            UserAttributeParam userAttributeParam = attributeParamMap.get(attribute.getKey());
            if (userAttributeParam == null) {
                userAttributeParam = new UserAttributeParam(attribute.getKey(), attribute.getValues());
                attributeParamMap.put(attribute.getKey(), userAttributeParam);
            } else {
                userAttributeParam.getValues().addAll(attribute.getValues());
            }
        }
    } else {
        _log.error("Empty attributes list in user group create param {}", from.getLabel());
    }
    if (!CollectionUtils.isEmpty(attributeParamMap)) {
        for (UserAttributeParam attribute : attributeParamMap.values()) {
            to.getAttributes().add(attribute.toString());
        }
    } else {
        _log.warn("Mapping from UserGroupCreateParam {} to UserGroup did not create any attributes list", from.getLabel());
    }
    return to;
}
Also used : TreeMap(java.util.TreeMap) UserGroup(com.emc.storageos.db.client.model.UserGroup) UserAttributeParam(com.emc.storageos.model.usergroup.UserAttributeParam)

Aggregations

UserAttributeParam (com.emc.storageos.model.usergroup.UserAttributeParam)9 UserGroup (com.emc.storageos.db.client.model.UserGroup)2 UserGroupRestRep (com.emc.storageos.model.usergroup.UserGroupRestRep)2 HashSet (java.util.HashSet)2 StorageOSUserDAO (com.emc.storageos.db.client.model.StorageOSUserDAO)1 UserGroupCreateParam (com.emc.storageos.model.usergroup.UserGroupCreateParam)1 ClientResponse (com.sun.jersey.api.client.ClientResponse)1 ArrayList (java.util.ArrayList)1 TreeMap (java.util.TreeMap)1 Attribute (javax.naming.directory.Attribute)1