Search in sources :

Example 1 with InheritCheckPermission

use of com.emc.storageos.security.authorization.InheritCheckPermission in project coprhd-controller by CoprHD.

the class TaggedResource method assignTags.

/**
 * @brief Assign tags to resource
 *        Assign tags
 *
 * @prereq none
 *
 * @param id the URN of a ViPR resource
 * @param assignment tag assignments
 * @return No data returned in response body
 */
@PUT
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/tags")
@InheritCheckPermission(writeAccess = true)
public Tags assignTags(@PathParam("id") URI id, TagAssignment assignment) {
    DataObject object = queryResource(id);
    ArgValidator.checkEntityNotNull(object, id, isIdEmbeddedInURL(id));
    InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_082);
    ScopedLabelSet tagSet = object.getTag();
    if (tagSet == null) {
        tagSet = new ScopedLabelSet();
        object.setTag(tagSet);
    }
    if (assignment.getAdd() != null && !assignment.getAdd().isEmpty()) {
        Iterator<String> it = assignment.getAdd().iterator();
        while (it.hasNext()) {
            String tagName = it.next();
            if (tagName == null || tagName.isEmpty() || tagName.length() < 2) {
                throw APIException.badRequests.parameterTooShortOrEmpty("Tag", 2);
            }
            ScopedLabel tagLabel = new ScopedLabel(getTenantOwnerIdString(id), tagName);
            tagSet.add(tagLabel);
        }
    }
    if (assignment.getRemove() != null && !assignment.getRemove().isEmpty()) {
        Iterator<String> it = assignment.getRemove().iterator();
        while (it.hasNext()) {
            String tagName = it.next();
            if (tagName == null || tagName.isEmpty()) {
                continue;
            }
            ScopedLabel tagLabel = new ScopedLabel(getTenantOwnerIdString(id), tagName);
            if (tagSet.contains(tagLabel)) {
                tagSet.remove(tagLabel);
            }
        }
    }
    _dbClient.updateAndReindexObject(object);
    return getTagsResponse(object);
}
Also used : DataObject(com.emc.storageos.db.client.model.DataObject) ScopedLabel(com.emc.storageos.db.client.model.ScopedLabel) ScopedLabelSet(com.emc.storageos.db.client.model.ScopedLabelSet) Path(javax.ws.rs.Path) InheritCheckPermission(com.emc.storageos.security.authorization.InheritCheckPermission) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Example 2 with InheritCheckPermission

use of com.emc.storageos.security.authorization.InheritCheckPermission in project coprhd-controller by CoprHD.

the class TaggedResource method getTags.

/**
 * @brief List tags assigned to resource
 *        Returns assigned tags
 *
 * @prereq none
 *
 * @param id the URN of a ViPR Resource
 * @return Tags information
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/tags")
@InheritCheckPermission
public Tags getTags(@PathParam("id") URI id) {
    DataObject object = queryResource(id);
    ArgValidator.checkEntityNotNull(object, id, isIdEmbeddedInURL(id));
    return getTagsResponse(object);
}
Also used : DataObject(com.emc.storageos.db.client.model.DataObject) Path(javax.ws.rs.Path) InheritCheckPermission(com.emc.storageos.security.authorization.InheritCheckPermission) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

DataObject (com.emc.storageos.db.client.model.DataObject)2 InheritCheckPermission (com.emc.storageos.security.authorization.InheritCheckPermission)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 ScopedLabel (com.emc.storageos.db.client.model.ScopedLabel)1 ScopedLabelSet (com.emc.storageos.db.client.model.ScopedLabelSet)1 GET (javax.ws.rs.GET)1 PUT (javax.ws.rs.PUT)1