Search in sources :

Example 1 with APIInfoDTO

use of org.wso2.carbon.apimgt.impl.dto.APIInfoDTO in project carbon-apimgt by wso2.

the class MappingUtil method toAPIInfo.

/**
 * Converts {@link API} List to an {@link APIInfoDTO} List.
 *
 * @param apiSummaryList
 * @return
 */
private static List<APIInfoDTO> toAPIInfo(List<API> apiSummaryList) {
    List<APIInfoDTO> apiInfoList = new ArrayList<APIInfoDTO>();
    for (API apiSummary : apiSummaryList) {
        APIInfoDTO apiInfo = new APIInfoDTO();
        apiInfo.setId(apiSummary.getId());
        apiInfo.setContext(apiSummary.getContext());
        apiInfo.setDescription(apiSummary.getDescription());
        apiInfo.setName(apiSummary.getName());
        apiInfo.setProvider(apiSummary.getProvider());
        apiInfo.setLifeCycleStatus(apiSummary.getLifeCycleStatus());
        apiInfo.setVersion(apiSummary.getVersion());
        apiInfo.setWorkflowStatus(apiSummary.getWorkflowStatus());
        apiInfo.setSecurityScheme(mapSecuritySchemeIntToList(apiSummary.getSecurityScheme()));
        apiInfoList.add(apiInfo);
    }
    return apiInfoList;
}
Also used : ArrayList(java.util.ArrayList) API(org.wso2.carbon.apimgt.core.models.API) APIInfoDTO(org.wso2.carbon.apimgt.rest.api.publisher.dto.APIInfoDTO)

Example 2 with APIInfoDTO

use of org.wso2.carbon.apimgt.impl.dto.APIInfoDTO in project carbon-apimgt by wso2.

the class AnalyticsMappingUtil method fromAPIInfoListToDTO.

/**
 * Converts and APIInfoList to APIInfoListDTO.
 *
 * @param apiInfoList list of ApiInfo objects
 * @return corresponding APIInfoListDTO object
 */
public static APIInfoListDTO fromAPIInfoListToDTO(List<APIInfo> apiInfoList, ZoneId zoneId) {
    APIInfoListDTO apiInfoListDTO = new APIInfoListDTO();
    List<APIInfoDTO> apiInfoDTOList = new ArrayList<>();
    apiInfoListDTO.setCount(apiInfoList.size());
    for (APIInfo apiInfo : apiInfoList) {
        apiInfoDTOList.add(fromAPIInfoToDTO(apiInfo, zoneId));
    }
    apiInfoListDTO.setList(apiInfoDTOList);
    return apiInfoListDTO;
}
Also used : ArrayList(java.util.ArrayList) APIInfo(org.wso2.carbon.apimgt.core.models.analytics.APIInfo) APIInfoDTO(org.wso2.carbon.apimgt.rest.api.analytics.dto.APIInfoDTO) APIInfoListDTO(org.wso2.carbon.apimgt.rest.api.analytics.dto.APIInfoListDTO)

Example 3 with APIInfoDTO

use of org.wso2.carbon.apimgt.impl.dto.APIInfoDTO in project carbon-apimgt by wso2.

the class APIInfoMappingUtil method fromAPIInfoListToDTO.

/**
 * Converts a List object of APIIdentifiers into a DTO
 *
 * @param apiIds a list of APIIdentifier objects
 * @return APIInfoListDTO object containing APIInfoDTOs
 */
public static APIInfoListDTO fromAPIInfoListToDTO(List<APIIdentifier> apiIds) throws UnsupportedEncodingException {
    APIInfoListDTO apiInfoListDTO = new APIInfoListDTO();
    List<APIInfoDTO> apiInfoDTOs = apiInfoListDTO.getList();
    if (apiInfoDTOs == null) {
        apiInfoDTOs = new ArrayList<>();
        apiInfoListDTO.setList(apiInfoDTOs);
    }
    for (APIIdentifier apiId : apiIds) {
        apiInfoDTOs.add(fromAPIInfoToDTO(apiId));
    }
    apiInfoListDTO.setCount(apiInfoDTOs.size());
    return apiInfoListDTO;
}
Also used : APIIdentifier(org.wso2.carbon.apimgt.api.model.APIIdentifier) APIInfoDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.APIInfoDTO) APIInfoListDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.APIInfoListDTO)

Example 4 with APIInfoDTO

use of org.wso2.carbon.apimgt.impl.dto.APIInfoDTO in project carbon-apimgt by wso2.

the class APIKeyValidator method mapToAPIInfo.

private APIInfoDTO mapToAPIInfo(ArrayList<URITemplate> uriTemplates, String context, String apiVersion) {
    APIInfoDTO apiInfoDTO = new APIInfoDTO();
    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.setContentAware(uriTemplate.checkContentAwareFromThrottlingTiers());
        verbInfoDTO.setThrottlingConditions(uriTemplate.getThrottlingConditions());
        verbInfoDTO.setConditionGroups(uriTemplate.getConditionGroups());
        verbInfoDTO.setApplicableLevel(uriTemplate.getApplicableLevel());
        resourceInfoDTO.getHttpVerbs().add(verbInfoDTO);
    }
    return apiInfoDTO;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) VerbInfoDTO(org.wso2.carbon.apimgt.impl.dto.VerbInfoDTO) URITemplate(org.wso2.carbon.apimgt.api.model.URITemplate) APIInfoDTO(org.wso2.carbon.apimgt.impl.dto.APIInfoDTO) ResourceInfoDTO(org.wso2.carbon.apimgt.impl.dto.ResourceInfoDTO) LinkedHashMap(java.util.LinkedHashMap)

Example 5 with APIInfoDTO

use of org.wso2.carbon.apimgt.impl.dto.APIInfoDTO in project carbon-apimgt by wso2.

the class APIKeyValidator method getVerbInfoDTOFromAPIData.

/**
 * @param messageContext     The message context
 * @param context     API context of API
 * @param apiVersion  Version of API
 * @param requestPath Incoming request path
 * @param httpMethod  http method of request
 * @return verbInfoDTO which contains throttling tier for given resource and verb+resource key
 */
public VerbInfoDTO getVerbInfoDTOFromAPIData(MessageContext messageContext, String context, String apiVersion, String requestPath, String httpMethod) throws APISecurityException {
    String cacheKey = context + ':' + apiVersion;
    APIInfoDTO apiInfoDTO = null;
    if (isGatewayAPIResourceValidationEnabled) {
        apiInfoDTO = (APIInfoDTO) getResourceCache().get(cacheKey);
    }
    if (apiInfoDTO == null) {
        apiInfoDTO = doGetAPIInfo(messageContext, context, apiVersion);
        if (isGatewayAPIResourceValidationEnabled) {
            getResourceCache().put(cacheKey, apiInfoDTO);
        }
    }
    // Match the case where the direct api context is matched
    if ("/".equals(requestPath)) {
        String requestCacheKey = context + '/' + apiVersion + requestPath + ':' + httpMethod;
        // Get decision from cache.
        VerbInfoDTO matchingVerb = null;
        if (isGatewayAPIResourceValidationEnabled) {
            matchingVerb = (VerbInfoDTO) getResourceCache().get(requestCacheKey);
        }
        // On a cache hit
        if (matchingVerb != null) {
            matchingVerb.setRequestKey(requestCacheKey);
            return matchingVerb;
        } else {
            if (apiInfoDTO.getResources() != null) {
                for (ResourceInfoDTO resourceInfoDTO : apiInfoDTO.getResources()) {
                    String urlPattern = resourceInfoDTO.getUrlPattern();
                    // If the request patch is '/', it can only be matched with a resource whose url-context is '/*'
                    if ("/*".equals(urlPattern)) {
                        for (VerbInfoDTO verbDTO : resourceInfoDTO.getHttpVerbs()) {
                            if (verbDTO.getHttpVerb().equals(httpMethod)) {
                                // Store verb in cache
                                if (isGatewayAPIResourceValidationEnabled) {
                                    getResourceCache().put(requestCacheKey, verbDTO);
                                }
                                verbDTO.setRequestKey(requestCacheKey);
                                return verbDTO;
                            }
                        }
                    }
                }
            }
        }
    }
    // Remove the ending '/' from request
    requestPath = RESTUtils.trimTrailingSlashes(requestPath);
    while (requestPath.length() > 1) {
        String requestCacheKey = context + '/' + apiVersion + requestPath + ':' + httpMethod;
        // Get decision from cache.
        VerbInfoDTO matchingVerb = null;
        if (isGatewayAPIResourceValidationEnabled) {
            matchingVerb = (VerbInfoDTO) getResourceCache().get(requestCacheKey);
        }
        // On a cache hit
        if (matchingVerb != null) {
            matchingVerb.setRequestKey(requestCacheKey);
            return matchingVerb;
        } else // On a cache miss
        {
            for (ResourceInfoDTO resourceInfoDTO : apiInfoDTO.getResources()) {
                String urlPattern = resourceInfoDTO.getUrlPattern();
                if (urlPattern.endsWith("/*")) {
                    // Remove the ending '/*'
                    urlPattern = urlPattern.substring(0, urlPattern.length() - 2);
                }
                // If the urlPattern ends with a '/', remove that as well.
                urlPattern = RESTUtils.trimTrailingSlashes(urlPattern);
                if (requestPath.endsWith(urlPattern)) {
                    for (VerbInfoDTO verbDTO : resourceInfoDTO.getHttpVerbs()) {
                        if (verbDTO.getHttpVerb().equals(httpMethod)) {
                            // Store verb in cache
                            if (isGatewayAPIResourceValidationEnabled) {
                                getResourceCache().put(requestCacheKey, verbDTO);
                            }
                            verbDTO.setRequestKey(requestCacheKey);
                            return verbDTO;
                        }
                    }
                }
            }
        }
        // Remove the section after the last occurrence of the '/' character
        int index = requestPath.lastIndexOf('/');
        requestPath = requestPath.substring(0, index <= 0 ? 0 : index);
    }
    // nothing found. return the highest level of security
    return null;
}
Also used : VerbInfoDTO(org.wso2.carbon.apimgt.impl.dto.VerbInfoDTO) APIInfoDTO(org.wso2.carbon.apimgt.impl.dto.APIInfoDTO) ResourceInfoDTO(org.wso2.carbon.apimgt.impl.dto.ResourceInfoDTO)

Aggregations

ArrayList (java.util.ArrayList)11 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)7 Tier (org.wso2.carbon.apimgt.api.model.Tier)7 APIInfoDTO (org.wso2.carbon.apimgt.rest.api.store.v1.dto.APIInfoDTO)7 APIConsumer (org.wso2.carbon.apimgt.api.APIConsumer)5 API (org.wso2.carbon.apimgt.api.model.API)4 APIInfoDTO (org.wso2.carbon.apimgt.impl.dto.APIInfoDTO)4 JSONObject (org.json.simple.JSONObject)3 API (org.wso2.carbon.apimgt.core.models.API)3 ResourceInfoDTO (org.wso2.carbon.apimgt.impl.dto.ResourceInfoDTO)3 VerbInfoDTO (org.wso2.carbon.apimgt.impl.dto.VerbInfoDTO)3 APIBusinessInformationDTO (org.wso2.carbon.apimgt.rest.api.store.v1.dto.APIBusinessInformationDTO)3 JsonObject (com.google.gson.JsonObject)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 LinkedHashSet (java.util.LinkedHashSet)2 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)2 APIProduct (org.wso2.carbon.apimgt.api.model.APIProduct)2 APIProductIdentifier (org.wso2.carbon.apimgt.api.model.APIProductIdentifier)2 Application (org.wso2.carbon.apimgt.api.model.Application)2