Search in sources :

Example 1 with UserAttributeParam

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

the class ApiTestVcenter method createUserGroup.

private void createUserGroup(String domain, String key, String value) {
    UserAttributeParam userAttributeParam = new UserAttributeParam();
    userAttributeParam.setKey(key);
    userAttributeParam.getValues().add(value);
    UserGroupCreateParam param = new UserGroupCreateParam();
    param.setLabel(value);
    param.setDomain(domain);
    param.getAttributes().add(userAttributeParam);
    ClientResponse clientResponse = rSys.path(getUserGroupApi()).post(ClientResponse.class, param);
    Assert.assertEquals(HttpStatus.SC_OK, clientResponse.getStatus());
    UserGroupRestRep userGroupRestRep = clientResponse.getEntity(UserGroupRestRep.class);
    Assert.assertNotNull(userGroupRestRep);
    // Add the created tenant to cleanup list, so that at the end of this test
    // the resource will be destroyed.
    final String deleteObjectURL = getUserGroupApiWithId(userGroupRestRep.getId());
    CleanupResource tenantToCleanup = new CleanupResource("delete", deleteObjectURL, rSys, null);
    apiTestVcenter.registerEnvironmentResourceForCleanup(tenantToCleanup);
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) UserGroupCreateParam(com.emc.storageos.model.usergroup.UserGroupCreateParam) UserAttributeParam(com.emc.storageos.model.usergroup.UserAttributeParam) UserGroupRestRep(com.emc.storageos.model.usergroup.UserGroupRestRep)

Example 2 with UserAttributeParam

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

the class UserGroup method getAttributeKeySet.

private StringSet getAttributeKeySet() {
    StringSet attributeKeySet = new StringSet();
    for (String attributeParamString : _attributes) {
        UserAttributeParam attributeParam = UserAttributeParam.fromString(attributeParamString);
        if (attributeParam == null) {
            _log.warn("Failed to convert attributes param string {} to object.", attributeParamString);
            continue;
        }
        attributeKeySet.add(attributeParam.getKey());
    }
    return attributeKeySet;
}
Also used : UserAttributeParam(com.emc.storageos.model.usergroup.UserAttributeParam)

Example 3 with UserAttributeParam

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

the class UserGroup method compareUserAttributeParam.

/**
 * Checks if the object's _attributes is available in the
 * userGroup's attributes or not .
 *
 * @param userGroup to be compared.
 * @param attributeParamString attribute of the object to be compared.
 * @return true if object's _attribute matches with one of
 *         userGroup's _attributes matches with otherwise false.
 */
private boolean compareUserAttributeParam(UserGroup userGroup, String attributeParamString) {
    boolean isEqual = false;
    if (StringUtils.isBlank(attributeParamString)) {
        _log.warn("Invalid attribute string {} in user group {}.", attributeParamString, this.getLabel());
        return isEqual;
    }
    UserAttributeParam attributeParam = UserAttributeParam.fromString(attributeParamString);
    if (attributeParam == null) {
        _log.warn("Failed to convert attributes param string {} to object.", attributeParamString);
        return isEqual;
    }
    if (CollectionUtils.isEmpty(userGroup._attributes)) {
        _log.info("No attributes to compare");
        return isEqual;
    }
    for (String comparingAttributeParamString : userGroup._attributes) {
        if (StringUtils.isBlank(comparingAttributeParamString)) {
            _log.info("Invalid attribute string {}", comparingAttributeParamString);
            break;
        }
        UserAttributeParam comparingAttributeParam = UserAttributeParam.fromString(comparingAttributeParamString);
        if (comparingAttributeParam == null) {
            _log.info("Failed to convert attributes param string {} to object.", comparingAttributeParamString);
            return isEqual;
        }
        if (comparingAttributeParam.isEqual(attributeParam)) {
            _log.debug("Attributes {} match with {}", attributeParamString, comparingAttributeParamString);
            isEqual = true;
            break;
        }
    }
    return isEqual;
}
Also used : UserAttributeParam(com.emc.storageos.model.usergroup.UserAttributeParam)

Example 4 with UserAttributeParam

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

the class UserGroup method checkOverlappingAttributes.

/**
 * Checks if the object's _attribute overlaps with
 * userGroup's attributes or not .
 *
 * @param userGroup to be compared.
 * @param attributeParamString attribute of the object to be compared.
 * @return true if object's _attribute overlaps with one of
 *         userGroup's _attributes otherwise false.
 */
private boolean checkOverlappingAttributes(UserGroup userGroup, String attributeParamString) {
    boolean overlaps = false;
    if (StringUtils.isBlank(attributeParamString)) {
        _log.warn("Invalid attribute string {} in user group {}.", attributeParamString, this.getLabel());
        return overlaps;
    }
    UserAttributeParam attributeParam = UserAttributeParam.fromString(attributeParamString);
    if (attributeParam == null) {
        _log.warn("Failed to convert attributes param string {} to object.", attributeParamString);
        return overlaps;
    }
    if (CollectionUtils.isEmpty(userGroup._attributes)) {
        _log.info("No attributes to compare");
        return overlaps;
    }
    for (String comparingAttributeParamString : userGroup._attributes) {
        if (StringUtils.isBlank(comparingAttributeParamString)) {
            _log.info("Invalid attribute string {}", comparingAttributeParamString);
            break;
        }
        UserAttributeParam comparingAttributeParam = UserAttributeParam.fromString(comparingAttributeParamString);
        if (comparingAttributeParam == null) {
            _log.info("Failed to convert attributes param string {} to object.", comparingAttributeParamString);
            return overlaps;
        }
        if (comparingAttributeParam.containsOverlappingAttributeValues(attributeParam)) {
            _log.debug("Attributes {} match with {}", attributeParamString, comparingAttributeParamString);
            overlaps = true;
            break;
        }
    }
    return overlaps;
}
Also used : UserAttributeParam(com.emc.storageos.model.usergroup.UserAttributeParam)

Example 5 with UserAttributeParam

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

the class BasePermissionsHelper method matchUserAttributesToUserGroup.

/**
 * Compare the user group with the list of user's attributes.
 *
 * @param user who's attributes list to be compared with user group.
 * @param roleAssignmentUserGroup to be compared with the user's attributes list.
 * @return true if user's attributes contains all the all attributes and its values of
 *         user group otherwise false.
 */
public boolean matchUserAttributesToUserGroup(StorageOSUserDAO user, UserGroup roleAssignmentUserGroup) {
    boolean isUserGroupMatchesUserAttributes = false;
    if (roleAssignmentUserGroup == null || user == null) {
        _log.error("Invalid user {} or user group {}", user, roleAssignmentUserGroup);
        return isUserGroupMatchesUserAttributes;
    }
    Set<String> userGroupDoNotMatch = new HashSet<String>();
    for (String roleAssignmentUserAttributeString : roleAssignmentUserGroup.getAttributes()) {
        if (StringUtils.isBlank(roleAssignmentUserAttributeString)) {
            _log.debug("Invalid user attributes param string");
            continue;
        }
        boolean isUserGroupMatchesUserAttribute = false;
        UserAttributeParam roleAssignmentUserAttribute = UserAttributeParam.fromString(roleAssignmentUserAttributeString);
        if (roleAssignmentUserAttribute == null) {
            _log.warn("Failed to convert user attributes param string {} to object.", roleAssignmentUserAttributeString);
            continue;
        }
        for (String userAttributeString : user.getAttributes()) {
            UserAttributeParam userAttribute = UserAttributeParam.fromString(userAttributeString);
            if (userAttribute == null) {
                _log.info("Failed to convert user attributes param string {} to object.", userAttributeString);
                continue;
            }
            _log.debug("Comparing user attributes {} with user group attribute {}", userAttributeString, roleAssignmentUserAttributeString);
            if (userAttribute.containsAllAttributeValues(roleAssignmentUserAttribute)) {
                _log.debug("Found user attributes {} matching with user group attributes {}", userAttributeString, roleAssignmentUserAttributeString);
                isUserGroupMatchesUserAttribute = true;
                break;
            }
        }
        if (isUserGroupMatchesUserAttribute == false) {
            _log.debug("Adding user group {} to the do not match list", roleAssignmentUserAttributeString);
            userGroupDoNotMatch.add(roleAssignmentUserAttributeString);
        }
    }
    if (CollectionUtils.isEmpty(userGroupDoNotMatch)) {
        isUserGroupMatchesUserAttributes = true;
    }
    return isUserGroupMatchesUserAttributes;
}
Also used : HashSet(java.util.HashSet) 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