本文整理汇总了Java中io.apiman.gateway.engine.beans.ApiRequest类的典型用法代码示例。如果您正苦于以下问题:Java ApiRequest类的具体用法?Java ApiRequest怎么用?Java ApiRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ApiRequest类属于io.apiman.gateway.engine.beans包,在下文中一共展示了ApiRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: verifyResult
import io.apiman.gateway.engine.beans.ApiRequest; //导入依赖的package包/类
/**
* Verify the session data.
*
* @param result the result of retrieving session data
* @param sessionId the ID of the session
* @param request the service request
* @param context the policy context
* @param config the policy configuration
* @return the result of the validation
*/
private ValidationResult verifyResult(IAsyncResult<Session> result, String sessionId, ApiRequest request,
IPolicyContext context, CookieValidateConfigBean config) {
final ValidationResult validationResult;
final Session sessionData = result.getResult();
if (result.isSuccess() && null != sessionData && StringUtils.isNotBlank(sessionData.getSessionId())) {
validationResult = verifySessionData(sessionData, sessionId, request, context, config);
} else {
//noinspection ThrowableResultOfMethodCallIgnored
if (null != result.getError()) {
LOGGER.error(MESSAGES.format("ErrorReadingSessionData", sessionId), result.getError());
}
// session not present
validationResult = new ValidationResult(false,
MESSAGES.format("MissingSessionData", sessionId));
}
return validationResult;
}
示例2: invoke
import io.apiman.gateway.engine.beans.ApiRequest; //导入依赖的package包/类
@Override
public PolicyTestBackEndApiResponse invoke(ApiRequest apiRequest, byte[] requestBody) {
try {
final ApiResponse apiResponse = new ApiResponse();
final String responseBody;
if (CommonTestUtil.AUTHENTICATED_PRINICPAL.equals(apiRequest.getHeaders().get(AUTH_HEADER_NAME))) {
// success
responseBody = RESPONSE_BODY;
apiResponse.setCode(HttpURLConnection.HTTP_OK);
apiResponse.getHeaders().put("Content-Type", "application/json");
apiResponse.getHeaders().put("Content-Length", String.valueOf(responseBody.getBytes("UTF-8").length));
} else {
// login failure
responseBody = "";
apiResponse.setCode(HttpURLConnection.HTTP_UNAUTHORIZED);
apiResponse.getHeaders().put("Content-Length", "0");
}
return new PolicyTestBackEndApiResponse(apiResponse, responseBody);
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
}
示例3: doContinue
import io.apiman.gateway.engine.beans.ApiRequest; //导入依赖的package包/类
/**
* Either continue the policy chain or skip, depending on the policy configuration.
*
* @param request the service request
* @param context the policy context
* @param config the policy configuration
* @param chain the policy chain
*/
private void doContinue(ApiRequest request, IPolicyContext context, CookieRemoveConfigBean config,
IPolicyChain<ApiRequest> chain) {
if (config.getSkipBackendCall()) {
// don't call the back-end service
LOGGER.info(MESSAGES.format("SkippingBackEndCall"));
context.setConnectorInterceptor(new ShortcircuitConnectorInterceptor());
chain.doSkip(request);
} else {
// call the back-end service
chain.doApply(request);
}
}
示例4: invalidateSession
import io.apiman.gateway.engine.beans.ApiRequest; //导入依赖的package包/类
/**
* Invalidate session data for the given session, then manipulate the chain accordingly.
*
* @param sessionId the ID of the session
* @param request the service request
* @param context the policy context
* @param chain the policy chain
* @param config the policy configuration
*/
private void invalidateSession(final String sessionId, final ApiRequest request, final IPolicyContext context,
final IPolicyChain<ApiRequest> chain, final CookieRemoveConfigBean config) {
final ISessionStore sessionStore = SessionStoreFactory.getSessionStore(context);
sessionStore.deleteSession(sessionId, result -> {
if (result.isSuccess()) {
// session data removed
LOGGER.info(MESSAGES.format("SessionInvalidated", sessionId));
doContinue(request, context, config, chain);
} else {
// failed to remove session data
final String failureMessage = MESSAGES.format(
"SessionInvalidationFailed", sessionId);
LOGGER.error(failureMessage, result.getError());
// policy failure
chain.doFailure(new PolicyFailure(PolicyFailureType.Other,
HttpURLConnection.HTTP_INTERNAL_ERROR, failureMessage));
}
});
}
示例5: getCookie
import io.apiman.gateway.engine.beans.ApiRequest; //导入依赖的package包/类
/**
* Parse the 'Cookie' request header to extract the value of a cookie with the given name.
*
* @param request the service request
* @param cookieName the name of the cookie to extract
* @return a Cookie containing the value of the named cookie, or <code>null</code> if not found
*/
public static Cookie getCookie(ApiRequest request, String cookieName) {
final String headerValue = request.getHeaders().get(Constants.HEADER_COOKIE);
if (StringUtils.isNotBlank(headerValue)) {
for (String keyValuePair : headerValue.split(";")) {
final String[] cookie = keyValuePair.split("=");
if (2 == cookie.length) {
// build a Cookie with the given name and value
final String trimmedCookieName = cookie[0].trim();
if (cookieName.equalsIgnoreCase(trimmedCookieName)) {
return new Cookie(trimmedCookieName, cookie[1].trim());
}
}
}
}
return null;
}
示例6: doTokenAuth
import io.apiman.gateway.engine.beans.ApiRequest; //导入依赖的package包/类
private Holder<Boolean> doTokenAuth(Holder<Boolean> successStatus, ApiRequest request,
IPolicyContext context, KeycloakOauthConfigBean config, IPolicyChain<ApiRequest> chain,
String rawToken) {
try {
AccessToken parsedToken = RSATokenVerifier.verifyToken(rawToken, config.getRealmCertificate()
.getPublicKey(), config.getRealm());
delegateKerberosTicket(request, config, parsedToken);
forwardHeaders(request, config, rawToken, parsedToken);
stripAuthTokens(request, config);
forwardAuthRoles(context, config, parsedToken);
RequestMetric metric = context.getAttribute(PolicyContextKeys.REQUEST_METRIC, (RequestMetric) null);
if (metric != null) {
metric.setUser(parsedToken.getPreferredUsername());
}
return successStatus.setValue(true);
} catch (VerificationException e) {
System.out.println(e);
chain.doFailure(failureFactory.verificationException(context, e));
return successStatus.setValue(false);
}
}
示例7: shouldBlacklistUnsafeToken
import io.apiman.gateway.engine.beans.ApiRequest; //导入依赖的package包/类
@Test
public void shouldBlacklistUnsafeToken() throws CertificateEncodingException, IOException {
// Require transport security
config.setRequireTransportSecurity(true);
// Blacklist invalidly used tokens
config.setBlacklistUnsafeTokens(true);
// But set the connection as insecure
apiRequest.setTransportSecure(false);
String encoded = generateAndSerializeToken();
apiRequest.getHeaders().put("Authorization", "Bearer " + encoded);
keycloakOauthPolicy.apply(apiRequest, mContext, config, mChain);
verify(mChain, times(1)).doFailure(any(PolicyFailure.class));
verify(mChain, never()).doApply(any(ApiRequest.class));
}
示例8: shouldTerminateOnBlacklistedToken
import io.apiman.gateway.engine.beans.ApiRequest; //导入依赖的package包/类
@Test
public void shouldTerminateOnBlacklistedToken() throws CertificateEncodingException, IOException {
config.setRequireTransportSecurity(true);
config.setBlacklistUnsafeTokens(true);
apiRequest.setTransportSecure(false);
// First, do a request that causes the token to be blacklisted.
String encoded = generateAndSerializeToken();
apiRequest.getHeaders().put("Authorization", "Bearer " + encoded);
keycloakOauthPolicy.apply(apiRequest, mContext, config, mChain);
// Second, do the request again with the blacklisted token *with secure*.
// It *must* still be blocked.
apiRequest.setTransportSecure(true);
keycloakOauthPolicy.apply(apiRequest, mContext, config, mChain);
verify(mChain, times(2)).doFailure(any(PolicyFailure.class));
verify(mChain, never()).doApply(any(ApiRequest.class));
}
示例9: shouldForwardAppRoles
import io.apiman.gateway.engine.beans.ApiRequest; //导入依赖的package包/类
@SuppressWarnings("serial")
@Test
public void shouldForwardAppRoles() throws CertificateEncodingException, IOException {
forwardRoles.setActive(true);
forwardRoles.setApplicationName("apiman-api");
String encoded = generateAndSerializeToken();
apiRequest.getHeaders().put("Authorization", "Bearer " + encoded);
keycloakOauthPolicy.apply(apiRequest, mContext, config, mChain);
Set<String> roles = new HashSet<String>() {
{
add("apiman-gateway-user-role");
add("a-nother-role");
}
};
verify(mContext).setAttribute(eq(AuthorizationPolicy.AUTHENTICATED_USER_ROLES), eq(roles));
verify(mChain).doApply(any(ApiRequest.class));
}
示例10: shouldForwardRealmRoles
import io.apiman.gateway.engine.beans.ApiRequest; //导入依赖的package包/类
@Test
public void shouldForwardRealmRoles() throws CertificateEncodingException, IOException {
forwardRoles.setActive(true);
String encoded = generateAndSerializeToken();
apiRequest.getHeaders().put("Authorization", "Bearer " + encoded);
keycloakOauthPolicy.apply(apiRequest, mContext, config, mChain);
@SuppressWarnings("serial")
Set<String> roles = new HashSet<String>() {
{
add("lets-use-a-realm-role");
}
};
verify(mContext).setAttribute(eq(AuthorizationPolicy.AUTHENTICATED_USER_ROLES), eq(roles));
verify(mChain).doApply(any(ApiRequest.class));
}
示例11: getNormalisedPath
import io.apiman.gateway.engine.beans.ApiRequest; //导入依赖的package包/类
/**
* Normalise the request URL before evaluating any access control rules, for safety. Returns the path
* component of the normalised URL.
*
* @param config the policy configuration
* @param request the incoming request
* @return the normalised path
* @throws URISyntaxException
*/
private String getNormalisedPath(UrlWhitelistBean config, ApiRequest request) throws URISyntaxException {
// normalise, for safety
final URI normalisedUrl = new URI(request.getUrl()).normalize();
String path = normalisedUrl.getPath();
if (config.isRemovePathPrefix()) {
if (path.startsWith(APIMAN_GATEWAY)) {
path = path.substring(APIMAN_GATEWAY.length());
}
// remove org/API/version prefix, e.g. '/myorg/myapi/1.0'
final String apiPrefix = String.format("/%s/%s/%s", //$NON-NLS-1$
request.getApiOrgId(),
request.getApiId(),
request.getApiVersion());
path = path.substring(apiPrefix.length());
}
return path;
}
示例12: doApply
import io.apiman.gateway.engine.beans.ApiRequest; //导入依赖的package包/类
@Override
protected void doApply(ApiRequest request, IPolicyContext context, TransformationConfigBean config,
IPolicyChain<ApiRequest> chain) {
DataFormat clientFormat = config.getClientFormat();
DataFormat serverFormat = config.getServerFormat();
if (isValidTransformation(clientFormat, serverFormat)) {
context.setAttribute(CLIENT_FORMAT, clientFormat);
context.setAttribute(SERVER_FORMAT, serverFormat);
request.getHeaders().put(CONTENT_TYPE, serverFormat.getContentType());
request.getHeaders().remove(CONTENT_LENGTH);
request.getHeaders().put(ACCEPT, serverFormat.getContentType());
}
super.doApply(request, context, config, chain);
}
示例13: invoke
import io.apiman.gateway.engine.beans.ApiRequest; //导入依赖的package包/类
@Override
public PolicyTestBackEndApiResponse invoke(ApiRequest apiRequest, byte[] requestBody) {
try {
String responseBody = "{\r\n" +
" \"property-1\" : \"value-1\",\r\n" +
" \"property-2\" : \"value-2\",\r\n" +
" \"object-1\" : {\r\n" +
" \"p1\" : \"v1\",\r\n" +
" \"p2\" : \"v2\"\r\n" +
" },\r\n" +
" \"array-1\" : [\r\n" +
" 10,\r\n" +
" 5,\r\n" +
" 3,\r\n" +
" 12\r\n" +
" ]\r\n" +
"}";
ApiResponse apiResponse = new ApiResponse();
apiResponse.getHeaders().put("Content-Type", "application/json");
apiResponse.getHeaders().put("Content-Length", String.valueOf(responseBody.getBytes("UTF-8").length));
return new PolicyTestBackEndApiResponse(apiResponse, responseBody);
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
}
示例14: BatchedRep
import io.apiman.gateway.engine.beans.ApiRequest; //导入依赖的package包/类
public BatchedRep(Auth3ScaleBean auth3ScaleBean,
ApiRequest request,
ApiResponse response,
IPolicyContext context,
ReporterImpl<BatchedReportData> reporter,
StandardAuthCache authCache,
BatchedAuthCache heuristicCache) {
this.config = auth3ScaleBean.getThreescaleConfig().getProxyConfig().getBackendConfig();
this.backendUri = auth3ScaleBean.getBackendEndpoint();
this.request = request;
this.context = context;
this.reporter = reporter;
this.authCache = authCache;
this.heuristicCache = heuristicCache;
this.httpClient = context.getComponent(IHttpClientComponent.class);
this.failureFactory = context.getComponent(IPolicyFailureFactoryComponent.class);
this.logger = context.getLogger(BatchedRep.class);
}
示例15: BatchedAuth
import io.apiman.gateway.engine.beans.ApiRequest; //导入依赖的package包/类
public BatchedAuth(Auth3ScaleBean auth3ScaleBean,
ApiRequest request,
IPolicyContext context,
StandardAuthCache authCache,
BatchedAuthCache heuristicCache) {
this.backendUri = auth3ScaleBean.getBackendEndpoint();
this.config = auth3ScaleBean.getThreescaleConfig().getProxyConfig().getBackendConfig();
this.request = request;
this.context = context;
this.authCache = authCache;
this.heuristicCache = heuristicCache;
this.logger = context.getLogger(BatchedAuth.class);
this.serviceId = config.getProxy().getServiceId();
this.httpClient = context.getComponent(IHttpClientComponent.class);
this.failureFactory = context.getComponent(IPolicyFailureFactoryComponent.class);
}