use of org.wso2.carbon.apimgt.rest.api.gateway.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;
}
use of org.wso2.carbon.apimgt.rest.api.gateway.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;
}
use of org.wso2.carbon.apimgt.rest.api.gateway.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;
}
use of org.wso2.carbon.apimgt.rest.api.gateway.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;
}
use of org.wso2.carbon.apimgt.rest.api.gateway.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;
}
Aggregations