Search in sources :

Example 6 with UserGroup

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

the class UserGroupService method getUserGroup.

/**
 * Gets the details of one user group.
 *
 * @param id of the user group to be returned.
 * @brief Show details of a user group
 * @return The user groups details as UserGroupRestRep
 * @see UserGroupRestRep
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}")
public UserGroupRestRep getUserGroup(@PathParam("id") URI id) {
    checkCompatibleVersion();
    checkIfUserHasPermissions();
    UserGroup userGroup = getUserGroupById(id, false);
    ArgValidator.checkEntityNotNull(userGroup, id, isIdEmbeddedInURL(id));
    return map(userGroup);
}
Also used : UserGroup(com.emc.storageos.db.client.model.UserGroup) MapUserGroup(com.emc.storageos.api.mapper.functions.MapUserGroup)

Example 7 with UserGroup

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

the class UserGroupService method checkForOverlappingUserGroup.

private void checkForOverlappingUserGroup(UserGroup userGroup) {
    if (userGroup == null) {
        _log.error("Invalid user group to compare");
        return;
    }
    List<UserGroup> userGroupList = _permissionsHelper.getAllUserGroupForDomain(userGroup.getDomain());
    if (CollectionUtils.isEmpty(userGroupList)) {
        _log.debug("No user group found for the domain {}", userGroup.getDomain());
        return;
    }
    Set<String> overlappingGroups = new HashSet<String>();
    for (UserGroup existingUserGroup : userGroupList) {
        if (existingUserGroup == null) {
            _log.info("Invalid user group found in db");
            continue;
        }
        if ((!userGroup.getLabel().equalsIgnoreCase(existingUserGroup.getLabel())) && userGroup.overlap(existingUserGroup)) {
            overlappingGroups.add(existingUserGroup.getLabel());
        }
        if ((!userGroup.getLabel().equalsIgnoreCase(existingUserGroup.getLabel())) && existingUserGroup.overlap(userGroup)) {
            overlappingGroups.add(existingUserGroup.getLabel());
        }
    }
    if (!CollectionUtils.isEmpty(overlappingGroups)) {
        throw APIException.badRequests.overlappingAttributesNotAllowed(userGroup.getLabel(), overlappingGroups);
    }
}
Also used : UserGroup(com.emc.storageos.db.client.model.UserGroup) MapUserGroup(com.emc.storageos.api.mapper.functions.MapUserGroup)

Example 8 with UserGroup

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

the class UserGroupService method createUserGroup.

/**
 * Creates user group.
 * The submitted user group element values will be validated.
 * <p>
 * The minimal set of parameters include: name, domain, attributes (key and values pair).
 * <p>
 *
 * @param param Representation of UserGroup with all necessary elements
 *
 * @brief Create a user group
 * @return Newly created User Group details as UserGroupRestRep
 * @see UserGroupCreateParam
 * @see UserGroupRestRep
 */
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SECURITY_ADMIN })
public UserGroupRestRep createUserGroup(UserGroupCreateParam param) {
    checkCompatibleVersion();
    validateUserGroupCreateParam(param);
    // Check for active UserGroup with same name
    checkDuplicateLabel(UserGroup.class, param.getLabel());
    UserGroup userGroup = map(param);
    URI id = URIUtil.createId(UserGroup.class);
    userGroup.setId(id);
    _log.debug("Saving the UserGroup: {}: {}", userGroup.getId(), userGroup.toString());
    // Check if there is any existing user group with same set of properties.
    checkForOverlappingUserGroup(userGroup);
    _dbClient.createObject(userGroup);
    auditOp(OperationTypeEnum.CREATE_USERGROUP, true, null, userGroup.toString(), userGroup.getId().toString());
    return map(getUserGroupById(id, false));
}
Also used : URI(java.net.URI) UserGroup(com.emc.storageos.db.client.model.UserGroup) MapUserGroup(com.emc.storageos.api.mapper.functions.MapUserGroup) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 9 with UserGroup

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

the class UserGroupService method deleteUserGroup.

/**
 * Deletes the active user group.
 *
 * @param id of the user group to be deleted.
 * @brief Delete a user group
 * @return Ok if deletion is successful otherwise valid exception.
 */
@DELETE
@CheckPermission(roles = { Role.SECURITY_ADMIN })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}")
public Response deleteUserGroup(@PathParam("id") URI id) {
    checkCompatibleVersion();
    UserGroup userGroup = getUserGroupById(id, false);
    ArgValidator.checkEntityNotNull(userGroup, id, isIdEmbeddedInURL(id));
    // check that there are no active resources that uses this user group.
    checkForActiveUsageOfUserGroup(userGroup.getDomain(), userGroup.getLabel());
    _dbClient.removeObject(userGroup);
    auditOp(OperationTypeEnum.DELETE_USERGROUP, true, null, userGroup.getId().toString());
    return Response.ok().build();
}
Also used : UserGroup(com.emc.storageos.db.client.model.UserGroup) MapUserGroup(com.emc.storageos.api.mapper.functions.MapUserGroup) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 10 with UserGroup

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

the class UserGroupService method updateUserGroup.

/**
 * Updates user group.
 * The submitted user group element values will be validated.
 * <p>
 * The minimal set of parameters include: name, domain, attributes (key and values pair).
 * <p>
 *
 * @param param Representation of UserGroup with all necessary elements
 *
 * @brief Update a user group
 * @return The updated User Group details as UserGroupRestRep
 * @see UserGroupUpdateParam
 * @see UserGroupRestRep
 */
@PUT
@Path("/{id}")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SECURITY_ADMIN })
public UserGroupRestRep updateUserGroup(@PathParam("id") URI id, UserGroupUpdateParam param) {
    checkCompatibleVersion();
    UserGroup userGroup = getUserGroupById(id, false);
    ArgValidator.checkEntityNotNull(userGroup, id, isIdEmbeddedInURL(id));
    validateUserGroupUpdateParam(param);
    // Update the db object with new information.
    overlayUserGroup(userGroup, param);
    // Check if there is any existing user group with same set of properties.
    checkForOverlappingUserGroup(userGroup);
    _dbClient.persistObject(userGroup);
    auditOp(OperationTypeEnum.UPDATE_USERGROUP, true, null, userGroup.toString(), userGroup.getId().toString());
    return map(getUserGroupById(id, false));
}
Also used : UserGroup(com.emc.storageos.db.client.model.UserGroup) MapUserGroup(com.emc.storageos.api.mapper.functions.MapUserGroup) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

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