コード例 #1
0
 private URITemplate toTemplates(org.wso2.carbon.apimgt.api.model.xsd.URITemplate dto) {
   URITemplate template = new URITemplate();
   template.setAuthType(dto.getAuthType());
   template.setHTTPVerb(dto.getHTTPVerb());
   template.setResourceSandboxURI(dto.getResourceSandboxURI());
   template.setUriTemplate(dto.getUriTemplate());
   return template;
 }
コード例 #2
0
  private URITemplate toTemplates(org.wso2.carbon.apimgt.api.model.xsd.URITemplate dto) {
    URITemplate template = new URITemplate();
    template.setAuthType(dto.getAuthType());
    template.setHTTPVerb(dto.getHTTPVerb());
    template.setResourceSandboxURI(dto.getResourceSandboxURI());
    template.setUriTemplate(dto.getUriTemplate());
    template.setThrottlingTier(dto.getThrottlingTier());

    ConditionGroupDTO[] xsdConditionGroups = dto.getConditionGroups();
    org.wso2.carbon.apimgt.api.dto.ConditionGroupDTO[] conditionGroups =
        new org.wso2.carbon.apimgt.api.dto.ConditionGroupDTO[xsdConditionGroups.length];

    for (short groupCounter = 0; groupCounter < xsdConditionGroups.length; groupCounter++) {
      org.wso2.carbon.apimgt.api.dto.ConditionGroupDTO conditionGroup =
          new org.wso2.carbon.apimgt.api.dto.ConditionGroupDTO();
      ConditionGroupDTO xsdConditionGroup = xsdConditionGroups[groupCounter];

      // Have to check nullity explicitly here because, in certain cases, length becomes 1 even when
      // there are
      // no elements in the array.
      if (xsdConditionGroup != null) {
        conditionGroup.setConditionGroupId(xsdConditionGroup.getConditionGroupId());
        ConditionDTO[] xsdConditions = xsdConditionGroup.getConditions();

        if (xsdConditions != null) {
          org.wso2.carbon.apimgt.api.dto.ConditionDTO[] conditions =
              new org.wso2.carbon.apimgt.api.dto.ConditionDTO[xsdConditions.length];
          for (short conditionCounter = 0;
              conditionCounter < xsdConditions.length;
              conditionCounter++) {

            ConditionDTO xsdCondition = xsdConditions[conditionCounter];
            if (xsdCondition != null) {
              org.wso2.carbon.apimgt.api.dto.ConditionDTO condition =
                  new org.wso2.carbon.apimgt.api.dto.ConditionDTO();
              condition.setConditionName(xsdCondition.getConditionName());
              condition.setConditionType(xsdCondition.getConditionType());
              condition.setConditionValue(xsdCondition.getConditionValue());
              conditions[conditionCounter] = condition;
            }
          }
          conditionGroup.setConditions(conditions);
        }
        conditionGroups[groupCounter] = conditionGroup;
      }
    }
    template.setConditionGroups(conditionGroups);
    template.setThrottlingConditions((Arrays.asList(dto.getThrottlingConditions())));
    return template;
  }
コード例 #3
0
  private APIInfoDTO doGetAPIInfo(String context, String apiVersion) throws APISecurityException {
    APIInfoDTO apiInfoDTO = new APIInfoDTO();

    ArrayList<URITemplate> uriTemplates = getAllURITemplates(context, apiVersion);

    apiInfoDTO.setApiName(context);
    apiInfoDTO.setContext(context);
    apiInfoDTO.setVersion(apiVersion);
    apiInfoDTO.setResources(new LinkedHashSet<ResourceInfoDTO>());

    ResourceInfoDTO resourceInfoDTO = null;
    VerbInfoDTO verbInfoDTO = null;

    // The following map is used to retrieve already created ResourceInfoDTO rather than iterating -
    // the resource Set in apiInfoDTO.
    LinkedHashMap<String, ResourceInfoDTO> resourcesMap =
        new LinkedHashMap<String, ResourceInfoDTO>();
    for (URITemplate uriTemplate : uriTemplates) {
      resourceInfoDTO = resourcesMap.get(uriTemplate.getUriTemplate());
      if (null == resourceInfoDTO) {
        resourceInfoDTO = new ResourceInfoDTO();
        resourceInfoDTO.setUrlPattern(uriTemplate.getUriTemplate());
        resourceInfoDTO.setHttpVerbs(new LinkedHashSet());
        apiInfoDTO.getResources().add(resourceInfoDTO);
        resourcesMap.put(uriTemplate.getUriTemplate(), resourceInfoDTO);
      }
      verbInfoDTO = new VerbInfoDTO();
      verbInfoDTO.setHttpVerb(uriTemplate.getHTTPVerb());
      verbInfoDTO.setAuthType(uriTemplate.getAuthType());
      verbInfoDTO.setThrottling(uriTemplate.getThrottlingTier());
      verbInfoDTO.setThrottlingConditions(uriTemplate.getThrottlingConditions());
      verbInfoDTO.setConditionGroups(uriTemplate.getConditionGroups());
      verbInfoDTO.setApplicableLevel(uriTemplate.getApplicableLevel());
      resourceInfoDTO.getHttpVerbs().add(verbInfoDTO);
    }

    return apiInfoDTO;
  }
コード例 #4
0
ファイル: APIKeyValidator.java プロジェクト: Johanes/platform
  private APIInfoDTO doGetAPIInfo(String context, String apiVersion) {
    APIInfoDTO apiInfoDTO = new APIInfoDTO();
    try {
      ArrayList<URITemplate> uriTemplates = getAllURITemplates(context, apiVersion);

      apiInfoDTO.setApiName(context);
      apiInfoDTO.setContext(context);
      apiInfoDTO.setVersion(apiVersion);
      apiInfoDTO.setResources(new HashSet<ResourceInfoDTO>());

      ResourceInfoDTO resourceInfoDTO = null;
      VerbInfoDTO verbInfoDTO = null;
      int i = 0;
      for (URITemplate uriTemplate : uriTemplates) {
        if (resourceInfoDTO != null
            && resourceInfoDTO.getUrlPattern().equalsIgnoreCase(uriTemplate.getUriTemplate())) {
          HashSet<VerbInfoDTO> verbs = (HashSet<VerbInfoDTO>) resourceInfoDTO.getHttpVerbs();
          verbInfoDTO = new VerbInfoDTO();
          verbInfoDTO.setHttpVerb(uriTemplate.getHTTPVerb());
          verbInfoDTO.setAuthType(uriTemplate.getAuthType());
          verbs.add(verbInfoDTO);
          resourceInfoDTO.setHttpVerbs(verbs);
          apiInfoDTO.getResources().add(resourceInfoDTO);
        } else {
          resourceInfoDTO = new ResourceInfoDTO();
          resourceInfoDTO.setUrlPattern(uriTemplate.getUriTemplate());
          verbInfoDTO = new VerbInfoDTO();
          verbInfoDTO.setHttpVerb(uriTemplate.getHTTPVerb());
          verbInfoDTO.setAuthType(uriTemplate.getAuthType());
          HashSet<VerbInfoDTO> httpVerbs2 = new HashSet();
          httpVerbs2.add(verbInfoDTO);
          resourceInfoDTO.setHttpVerbs(httpVerbs2);
          apiInfoDTO.getResources().add(resourceInfoDTO);
        }
      }
    } catch (APIManagementException e) {
      log.error("Loading URI templates for " + context + ":" + apiVersion + " failed", e);
    } catch (APISecurityException e) {
      log.error("Loading URI templates for " + context + ":" + apiVersion + " failed", e);
    }
    return apiInfoDTO;
  }