Search in sources :

Example 1 with UserGroup

use of com.emc.storageos.db.client.model.UserGroup in project coprhd-controller by CoprHD.

the class TenantsService method isValidMapping.

/**
 * Validate an attribute string
 *
 * @param userMapping
 *            attribute string to validate
 * @return True if the attribute string is valid
 */
public boolean isValidMapping(UserMapping userMapping) {
    if (CollectionUtils.isEmpty(userMapping.getGroups())) {
        return true;
    }
    for (String group : userMapping.getGroups()) {
        if (StringUtils.isBlank(group)) {
            _log.warn("Invalid group in the user mapping groups list");
            continue;
        }
        StorageOSPrincipal groupPrincipal = new StorageOSPrincipal();
        groupPrincipal.setType(StorageOSPrincipal.Type.Group);
        // First add the group with "@domain" suffix and after that
        // if we find that the group is a userGroup reset the
        // name to just the group name without "@domain" suffix.
        groupPrincipal.setName(group + "@" + userMapping.getDomain());
        List<UserGroup> userGroupList = _permissionsHelper.getAllUserGroupByLabel(group);
        if (!CollectionUtils.isEmpty(userGroupList)) {
            for (UserGroup userGroup : userGroupList) {
                // in order to treat the group as UserGroup.
                if (userGroup != null && userGroup.getDomain().equalsIgnoreCase(userMapping.getDomain())) {
                    _log.debug("Group {} is considered as user group", group);
                    groupPrincipal.setName(group);
                }
            }
        }
        if (!Validator.isValidPrincipal(groupPrincipal, null)) {
            return false;
        }
    }
    return true;
}
Also used : StorageOSPrincipal(com.emc.storageos.security.validator.StorageOSPrincipal) UserGroup(com.emc.storageos.db.client.model.UserGroup)

Example 2 with UserGroup

use of com.emc.storageos.db.client.model.UserGroup in project coprhd-controller by CoprHD.

the class ApiTestUserGroup method buildUserGroupFromUpdateParam.

UserGroup buildUserGroupFromUpdateParam(UserGroupUpdateParam updateParam, UserGroup userGroup) {
    Assert.assertNotNull(updateParam);
    Assert.assertNotNull(userGroup);
    UserGroup userGroupToReturn = new UserGroup();
    userGroupToReturn.setLabel(userGroup.getLabel());
    userGroupToReturn.setDomain(updateParam.getDomain());
    if (!CollectionUtils.isEmpty(updateParam.getAddAttributes())) {
        for (UserAttributeParam attributeParam : updateParam.getAddAttributes()) {
            userGroup.getAttributes().add(attributeParam.toString());
        }
    }
    if (!CollectionUtils.isEmpty(updateParam.getRemoveAttributes())) {
        for (String removeAttributeKey : updateParam.getRemoveAttributes()) {
            Iterator<String> it = userGroup.getAttributes().iterator();
            while (it.hasNext()) {
                String userAttributeParamString = it.next();
                UserAttributeParam userAttributeParam = UserAttributeParam.fromString(userAttributeParamString);
                Assert.assertNotNull(userAttributeParam);
                if (userAttributeParam.getKey().equalsIgnoreCase(removeAttributeKey)) {
                    userGroup.getAttributes().remove(userAttributeParam.toString());
                }
            }
        }
    }
    return removeDuplicateAttributes(userGroup);
}
Also used : UserGroup(com.emc.storageos.db.client.model.UserGroup)

Example 3 with UserGroup

use of com.emc.storageos.db.client.model.UserGroup in project coprhd-controller by CoprHD.

the class ApiTestUserGroup method testUserGroupEditWithoutAttributes.

@Test
public void testUserGroupEditWithoutAttributes() {
    final String testName = "testUserGroupEditWithoutAttributes - ";
    createDefaultAuthnProvider(testName + DEFAULT_AUTH_PROVIDER_CREATION);
    UserGroupCreateParam createParam = getDefaultUserGroupCreateParam();
    ClientResponse clientUserGroupCreateResp = rSys.path(getTestApi()).post(ClientResponse.class, createParam);
    UserGroupRestRep userGroupCreateResp = validateUserGroupCreateSuccess(createParam, clientUserGroupCreateResp);
    UserGroup createdUserGroup = buildUserGroupFromRestRep(userGroupCreateResp);
    UserGroupUpdateParam updateParam = getUserGroupUpdateParamFromRestRep(userGroupCreateResp);
    // Clear both add and remove attributes. This should be successful.
    updateParam.getAddAttributes().clear();
    updateParam.getRemoveAttributes().clear();
    String testEditAPI = getTestEditApi(userGroupCreateResp.getId());
    ClientResponse clientUserGroupEditResp = rSys.path(testEditAPI).put(ClientResponse.class, updateParam);
    validateUserGroupEditSuccess(createdUserGroup, updateParam, clientUserGroupEditResp);
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) UserGroup(com.emc.storageos.db.client.model.UserGroup) Test(org.junit.Test)

Example 4 with UserGroup

use of com.emc.storageos.db.client.model.UserGroup in project coprhd-controller by CoprHD.

the class ApiTestUserGroup method validateUserGroupEditSuccess.

private void validateUserGroupEditSuccess(UserGroup userGroup, UserGroupUpdateParam expected, ClientResponse actual) {
    Assert.assertEquals(HttpStatus.SC_OK, actual.getStatus());
    UserGroupRestRep resp = actual.getEntity(UserGroupRestRep.class);
    Assert.assertNotNull(resp);
    validateUserGroupCommon(expected, resp);
    UserGroup expectedUserGroup = buildUserGroupFromUpdateParam(expected, userGroup);
    UserGroup actualUserGroup = buildUserGroupFromRestRep(resp);
    Assert.assertTrue(isSame(expectedUserGroup, actualUserGroup));
}
Also used : UserGroup(com.emc.storageos.db.client.model.UserGroup)

Example 5 with UserGroup

use of com.emc.storageos.db.client.model.UserGroup in project coprhd-controller by CoprHD.

the class ApiTestUserGroup method buildUserGroupFromRestRep.

UserGroup buildUserGroupFromRestRep(UserGroupRestRep restRep) {
    Assert.assertNotNull(restRep);
    Assert.assertFalse(CollectionUtils.isEmpty(restRep.getAttributes()));
    UserGroup userGroup = new UserGroup();
    userGroup.setLabel(restRep.getName());
    userGroup.setDomain(restRep.getDomain());
    for (UserAttributeParam attributeParam : restRep.getAttributes()) {
        userGroup.getAttributes().add(attributeParam.toString());
    }
    return removeDuplicateAttributes(userGroup);
}
Also used : UserGroup(com.emc.storageos.db.client.model.UserGroup)

Aggregations

UserGroup (com.emc.storageos.db.client.model.UserGroup)24 MapUserGroup (com.emc.storageos.api.mapper.functions.MapUserGroup)7 StringSet (com.emc.storageos.db.client.model.StringSet)5 StringSetMap (com.emc.storageos.db.client.model.StringSetMap)4 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)3 ClientResponse (com.sun.jersey.api.client.ClientResponse)3 Test (org.junit.Test)3 UserAttributeParam (com.emc.storageos.model.usergroup.UserAttributeParam)2 URI (java.net.URI)2 NamedElementQueryResultList (com.emc.storageos.db.client.constraint.NamedElementQueryResultList)1 StorageOSPrincipal (com.emc.storageos.security.validator.StorageOSPrincipal)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1