Search in sources :

Example 16 with RangerTag

use of org.apache.ranger.plugin.model.RangerTag in project ranger by apache.

the class ServiceTagsProcessor method findMatchingTag.

private RangerTag findMatchingTag(RangerTag incomingTag, List<RangerTag> existingTags) throws Exception {
    RangerTag ret = null;
    if (StringUtils.isNotEmpty(incomingTag.getGuid())) {
        ret = tagStore.getTagByGuid(incomingTag.getGuid());
    }
    if (ret == null) {
        if (isResourcePrivateTag(incomingTag)) {
            for (RangerTag existingTag : existingTags) {
                if (StringUtils.equals(incomingTag.getType(), existingTag.getType())) {
                    // Check attribute values
                    Map<String, String> incomingTagAttributes = incomingTag.getAttributes();
                    Map<String, String> existingTagAttributes = existingTag.getAttributes();
                    if (CollectionUtils.isEqualCollection(incomingTagAttributes.keySet(), existingTagAttributes.keySet())) {
                        boolean matched = true;
                        for (Map.Entry<String, String> entry : incomingTagAttributes.entrySet()) {
                            String key = entry.getKey();
                            String value = entry.getValue();
                            if (!StringUtils.equals(value, existingTagAttributes.get(key))) {
                                matched = false;
                                break;
                            }
                        }
                        if (matched) {
                            ret = existingTag;
                            break;
                        }
                    }
                }
            }
        }
    }
    return ret;
}
Also used : RangerTag(org.apache.ranger.plugin.model.RangerTag) RangerTagResourceMap(org.apache.ranger.plugin.model.RangerTagResourceMap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 17 with RangerTag

use of org.apache.ranger.plugin.model.RangerTag in project ranger by apache.

the class TagREST method updateTag.

@PUT
@Path(TagRESTConstants.TAG_RESOURCE + "{id}")
@Produces({ "application/json", "application/xml" })
@PreAuthorize("hasRole('ROLE_SYS_ADMIN')")
public RangerTag updateTag(@PathParam("id") Long id, RangerTag tag) {
    RangerTag ret;
    try {
        validator.preUpdateTag(id, tag);
        ret = tagStore.updateTag(tag);
    } catch (Exception excp) {
        LOG.error("updateTag(" + id + ") failed", excp);
        throw restErrorUtil.createRESTException(HttpServletResponse.SC_BAD_REQUEST, excp.getMessage(), true);
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== TagREST.updateTag(" + id + "): " + ret);
    }
    return ret;
}
Also used : RangerTag(org.apache.ranger.plugin.model.RangerTag) WebApplicationException(javax.ws.rs.WebApplicationException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) PUT(javax.ws.rs.PUT)

Example 18 with RangerTag

use of org.apache.ranger.plugin.model.RangerTag in project ranger by apache.

the class RangerTagService method getTagsForResourceGuid.

public List<RangerTag> getTagsForResourceGuid(String resourceGuid) {
    List<RangerTag> ret = new ArrayList<RangerTag>();
    List<XXTag> xxTags = daoMgr.getXXTag().findForResourceGuid(resourceGuid);
    if (CollectionUtils.isNotEmpty(xxTags)) {
        for (XXTag xxTag : xxTags) {
            RangerTag tag = populateViewBean(xxTag);
            ret.add(tag);
        }
    }
    return ret;
}
Also used : RangerTag(org.apache.ranger.plugin.model.RangerTag) ArrayList(java.util.ArrayList) XXTag(org.apache.ranger.entity.XXTag)

Example 19 with RangerTag

use of org.apache.ranger.plugin.model.RangerTag in project ranger by apache.

the class RangerTagService method getTagByGuid.

public RangerTag getTagByGuid(String guid) {
    RangerTag ret = null;
    XXTag xxTag = daoMgr.getXXTag().findByGuid(guid);
    if (xxTag != null) {
        ret = populateViewBean(xxTag);
    }
    return ret;
}
Also used : RangerTag(org.apache.ranger.plugin.model.RangerTag) XXTag(org.apache.ranger.entity.XXTag)

Example 20 with RangerTag

use of org.apache.ranger.plugin.model.RangerTag in project ranger by apache.

the class RangerTagService method getTagsByServiceId.

public List<RangerTag> getTagsByServiceId(Long serviceId) {
    List<RangerTag> ret = new ArrayList<RangerTag>();
    List<XXTag> xxTags = daoMgr.getXXTag().findByServiceId(serviceId);
    if (CollectionUtils.isNotEmpty(xxTags)) {
        for (XXTag xxTag : xxTags) {
            RangerTag tag = populateViewBean(xxTag);
            ret.add(tag);
        }
    }
    return ret;
}
Also used : RangerTag(org.apache.ranger.plugin.model.RangerTag) ArrayList(java.util.ArrayList) XXTag(org.apache.ranger.entity.XXTag)

Aggregations

RangerTag (org.apache.ranger.plugin.model.RangerTag)30 WebApplicationException (javax.ws.rs.WebApplicationException)13 ArrayList (java.util.ArrayList)12 Test (org.junit.Test)10 ExpectedException (org.junit.rules.ExpectedException)10 XXTag (org.apache.ranger.entity.XXTag)5 HashMap (java.util.HashMap)4 Map (java.util.Map)4 RangerServiceResource (org.apache.ranger.plugin.model.RangerServiceResource)4 RangerTagDef (org.apache.ranger.plugin.model.RangerTagDef)4 RangerTagResourceMap (org.apache.ranger.plugin.model.RangerTagResourceMap)4 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 Predicate (org.apache.commons.collections.Predicate)3 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)3 HashSet (java.util.HashSet)2 List (java.util.List)2 PUT (javax.ws.rs.PUT)2 RangerServiceResourceSignature (org.apache.ranger.plugin.store.RangerServiceResourceSignature)2 ServiceTags (org.apache.ranger.plugin.util.ServiceTags)2