/** * Builds a cached request id composed by the API key followed by the HTTP * verb and the destination. In the case where there's no API key the ID * will contain ApiOrgId + ApiId + ApiVersion */ private static String buildCacheID(ApiRequest request) { StringBuilder req = new StringBuilder(); if (request.getContract() != null) { req.append(request.getApiKey()); } else { req.append(request.getApiOrgId()).append(KEY_SEPARATOR).append(request.getApiId()) .append(KEY_SEPARATOR).append(request.getApiVersion()); } req.append(KEY_SEPARATOR).append(request.getType()).append(KEY_SEPARATOR) .append(request.getDestination()); return req.toString(); }
/** * @see io.apiman.gateway.engine.policies.AbstractMappedPolicy#doApply(io.apiman.gateway.engine.beans.ApiRequest, * io.apiman.gateway.engine.policy.IPolicyContext, java.lang.Object, * io.apiman.gateway.engine.policy.IPolicyChain) */ @Override protected void doApply(ApiRequest request, IPolicyContext context, IgnoredResourcesConfig config, IPolicyChain<ApiRequest> chain) { if (!satisfiesAnyPath(config, request.getDestination(), request.getType())) { super.doApply(request, context, config, chain); } else { IPolicyFailureFactoryComponent ffactory = context .getComponent(IPolicyFailureFactoryComponent.class); String msg = Messages.i18n.format("IgnoredResourcesPolicy.PathIgnored", //$NON-NLS-1$ request.getDestination()); PolicyFailure failure = ffactory.createFailure(PolicyFailureType.NotFound, PolicyFailureCodes.PATHS_TO_IGNORE, msg); chain.doFailure(failure); } }
echoResponse.setMethod(request.getType()); echoResponse.setResource(request.getDestination()); echoResponse.setUri("urn:" + request.getDestination());
echoResponse.setMethod(request.getType()); echoResponse.setResource(request.getDestination()); echoResponse.setUri("urn:" + request.getDestination());
public HttpConnector connect() { String endpoint = ApimanPathUtils.join(apiPath, destination + queryParams(apiRequest.getQueryParams())); logger.debug("Connecting to {0} | ssl?: {1} port: {2} verb: {3} path: {4}", apiHost, options.isSsl(), apiPort, HttpMethod.valueOf(apiRequest.getType()), endpoint); clientRequest = client.request(HttpMethod.valueOf(apiRequest.getType()), apiPort, apiHost,
/** * @see io.apiman.gateway.engine.policies.AbstractMappedPolicy#doApply(io.apiman.gateway.engine.beans.ApiRequest, io.apiman.gateway.engine.policy.IPolicyContext, java.lang.Object, io.apiman.gateway.engine.policy.IPolicyChain) */ @Override protected void doApply(ApiRequest request, IPolicyContext context, AuthorizationConfig config, IPolicyChain<ApiRequest> chain) { Set<String> userRoles = context.getAttribute(AUTHENTICATED_USER_ROLES, (HashSet<String>) null); String verb = request.getType(); String resource = request.getDestination(); // If no roles are set in the context - then fail with a configuration error if (userRoles == null) { String msg = Messages.i18n.format("AuthorizationPolicy.MissingRoles"); //$NON-NLS-1$ PolicyFailure failure = context.getComponent(IPolicyFailureFactoryComponent.class).createFailure( PolicyFailureType.Other, PolicyFailureCodes.CONFIGURATION_ERROR, msg); chain.doFailure(failure); return; } if (isAuthorized(config, verb, resource, userRoles)) { chain.doApply(request); } else { String msg = Messages.i18n.format("AuthorizationPolicy.Unauthorized"); //$NON-NLS-1$ PolicyFailure failure = context.getComponent(IPolicyFailureFactoryComponent.class).createFailure( PolicyFailureType.Authorization, PolicyFailureCodes.USER_NOT_AUTHORIZED, msg); chain.doFailure(failure); } }
requestMetric.setUrl(request.getUrl()); requestMetric.setResource(request.getDestination()); requestMetric.setMethod(request.getType()); requestMetric.setApiOrgId(request.getApiOrgId()); requestMetric.setApiId(request.getApiId());
requestMetric.setUrl(request.getUrl()); requestMetric.setResource(request.getDestination()); requestMetric.setMethod(request.getType()); requestMetric.setApiOrgId(request.getApiOrgId()); requestMetric.setApiId(request.getApiId());