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;
}
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);
}
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);
}
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));
}
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);
}
Aggregations