本文整理汇总了Java中io.apiman.gateway.engine.policy.IPolicyContext类的典型用法代码示例。如果您正苦于以下问题:Java IPolicyContext类的具体用法?Java IPolicyContext怎么用?Java IPolicyContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IPolicyContext类属于io.apiman.gateway.engine.policy包,在下文中一共展示了IPolicyContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: verifyResult
import io.apiman.gateway.engine.policy.IPolicyContext; //导入依赖的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: extendSession
import io.apiman.gateway.engine.policy.IPolicyContext; //导入依赖的package包/类
/**
* Extend the session with a new expiry time.
*
* @param context the policy context
* @param sessionData the session to extend
*/
private void extendSession(final IPolicyContext context, final Session sessionData) {
final long newExpiry = (TimeUtil.getNowInMillis() + sessionData.getValidityPeriod());
sessionData.setExpires(newExpiry);
LOGGER.debug(MESSAGES.format("ExtendingSession", sessionData.getSessionId(), newExpiry));
// store updated session data
final ISessionStore sessionStore = SessionStoreFactory.getSessionStore(context);
sessionStore.storeSession(sessionData.getSessionId(), sessionData, result -> {
if (result.isSuccess()) {
LOGGER.info(MESSAGES.format(
"UpdatedSessionData", sessionData.getSessionId(), sessionData));
} else {
LOGGER.error(MESSAGES.format("ErrorUpdatingSessionData",
sessionData.getSessionId(), sessionData), result.getError());
}
});
}
示例3: doContinue
import io.apiman.gateway.engine.policy.IPolicyContext; //导入依赖的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.policy.IPolicyContext; //导入依赖的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: storeSessionData
import io.apiman.gateway.engine.policy.IPolicyContext; //导入依赖的package包/类
/**
* Store session information.
*
* @param context the policy context
* @param config the policy configuration
* @param sessionId the ID of the session generated in {@link #generateCookie(CookieIssueConfigBean)}
* @param authenticatedPrincipal the authenticated principal extracted from the API response
*/
private static void storeSessionData(IPolicyContext context, CookieIssueConfigBean config, final String sessionId,
String authenticatedPrincipal) {
// build and store a new session
final Session sessionData = SessionUtil.buildSession(sessionId, authenticatedPrincipal, config.getValidityPeriod());
LOGGER.debug(MESSAGES.format("StoringSessionData", sessionId, sessionData));
final ISessionStore sessionStore = SessionStoreFactory.getSessionStore(context);
sessionStore.storeSession(sessionId, sessionData, result -> {
if (result.isSuccess()) {
LOGGER.info(MESSAGES.format(
"StoredSessionData", sessionId, sessionData));
} else {
LOGGER.error(MESSAGES.format(
"ErrorStoringSessionData", sessionId, sessionData), result.getError());
}
});
}
示例6: doTokenAuth
import io.apiman.gateway.engine.policy.IPolicyContext; //导入依赖的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: forwardAuthRoles
import io.apiman.gateway.engine.policy.IPolicyContext; //导入依赖的package包/类
private void forwardAuthRoles(IPolicyContext context, KeycloakOauthConfigBean config,
AccessToken parsedToken) {
if (config.getForwardRoles().getActive()) {
Access access = null;
if (config.getForwardRoles().getApplicationName() != null) {
access = parsedToken.getResourceAccess(config.getForwardRoles().getApplicationName());
} else {
access = parsedToken.getRealmAccess();
}
if (access == null || access.getRoles() == null) {
context.setAttribute(AuthorizationPolicy.AUTHENTICATED_USER_ROLES, Collections.<String>emptySet());
} else {
context.setAttribute(AuthorizationPolicy.AUTHENTICATED_USER_ROLES, access.getRoles());
}
}
}
示例8: doApply
import io.apiman.gateway.engine.policy.IPolicyContext; //导入依赖的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);
}
示例9: doApply
import io.apiman.gateway.engine.policy.IPolicyContext; //导入依赖的package包/类
/**
* @see io.apiman.gateway.engine.policies.AbstractMappedPolicy#doApply(io.apiman.gateway.engine.beans.ApiResponse, io.apiman.gateway.engine.policy.IPolicyContext, java.lang.Object, io.apiman.gateway.engine.policy.IPolicyChain)
*/
@Override
protected void doApply(ApiResponse response, IPolicyContext context, CircuitBreakerConfigBean config,
IPolicyChain<ApiResponse> chain) {
Circuit circuit = context.getAttribute(CircuitBreakerPolicy.class.getName() + ".circuit", (Circuit) null); //$NON-NLS-1$
boolean isFault = isCircuitFault(response, config);
if (circuit.isResetting()) {
if (isFault) {
circuit.trip();
} else {
circuit.reset();
}
} else {
if (isFault) {
circuit.addFault();
}
}
super.doApply(response, context, config, chain);
}
示例10: doApply
import io.apiman.gateway.engine.policy.IPolicyContext; //导入依赖的package包/类
/**
* @see io.apiman.gateway.engine.policies.AbstractMappedPolicy#doApply(io.apiman.gateway.engine.beans.ApiResponse, io.apiman.gateway.engine.policy.IPolicyContext, java.lang.Object, io.apiman.gateway.engine.policy.IPolicyChain)
*/
@Override
protected void doApply(ApiResponse response, IPolicyContext context, LogHeadersConfigBean config,
IPolicyChain<ApiResponse> chain) {
IApimanLogger logger = context.getLogger(getClass());
if (config.getDirection() != LogHeadersDirectionType.request) {
String endpoint = context.getAttribute(ENDPOINT_ATTRIBUTE, ""); //$NON-NLS-1$
if (config.isLogStatusCode()) {
logger.info(String.format("Status code %d for %s", response.getCode(), endpoint));
}
if (config.isLogHeaders()) {
logHeaders(logger, response.getHeaders(), HttpDirection.RESPONSE, endpoint);
}
}
chain.doApply(response);
}
示例11: BatchedRep
import io.apiman.gateway.engine.policy.IPolicyContext; //导入依赖的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);
}
示例12: BatchedAuth
import io.apiman.gateway.engine.policy.IPolicyContext; //导入依赖的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);
}
示例13: doApply
import io.apiman.gateway.engine.policy.IPolicyContext; //导入依赖的package包/类
@Override
protected void doApply(ApiRequest request, IPolicyContext context, Auth3ScaleBean config, IPolicyChain<ApiRequest> chain) {
init(context);
try {
auth3scale.getAuth(config, request, context)
// If a policy failure occurs, call chain.doFailure.
.policyFailureHandler(chain::doFailure)
// If succeeded or error.
.auth(result -> {
if (result.isSuccess()) {
// Keep the API request around so the auth apikey(s) can be accessed, etc.
context.setAttribute(AUTH3SCALE_REQUEST, request);
chain.doApply(request);
} else {
chain.throwError(result.getError());
}
});
} catch (Exception e) {
logger.error("Unexpected error", e);
e.printStackTrace();
chain.throwError(UNEXPECTED_ERROR);
}
}
示例14: start
import io.apiman.gateway.engine.policy.IPolicyContext; //导入依赖的package包/类
public BatchedReporter start(IPolicyContext context, BatchedReporterOptions options) {
if (started) {
throw new IllegalStateException("Already started");
}
this.retryReporter = new RetryReporter(options.getRetryQueueMaxSize());
reporters.add(retryReporter);
this.httpClient = context.getComponent(IHttpClientComponent.class);
this.periodic = context.getComponent(IPeriodicComponent.class);
this.logger = context.getLogger(BatchedReporter.class);
this.timerId = periodic.setPeriodicTimer(options.getReportingInterval(),
options.getInitialWait(),
id -> send());
started = true;
return this;
}
示例15: AuthRep
import io.apiman.gateway.engine.policy.IPolicyContext; //导入依赖的package包/类
public AuthRep(IPolicyContext context) {
batchedReporter = new BatchedReporter()
.start(context, new BatchedReporterOptions());
// API Key
ApiKeyAuthRepFactory apiKeyFactory = new ApiKeyAuthRepFactory();
authTypeFactory.put(AuthTypeEnum.API_KEY, apiKeyFactory);
// App Id
AppIdAuthRepFactory appIdFactory = new AppIdAuthRepFactory();
authTypeFactory.put(AuthTypeEnum.APP_ID, appIdFactory);
// Add different RL strategies (bad name... TODO better name!).
// Standard naive rate limiting.
principalFactoryMap.put(RateLimitingStrategy.STANDARD, new StandardStrategyFactory());
principalFactoryMap.put(RateLimitingStrategy.BATCHED_HYBRID, new BatchedStrategyFactory(batchedReporter));
}