当前位置: 首页>>代码示例>>Java>>正文


Java IPolicyChain类代码示例

本文整理汇总了Java中io.apiman.gateway.engine.policy.IPolicyChain的典型用法代码示例。如果您正苦于以下问题:Java IPolicyChain类的具体用法?Java IPolicyChain怎么用?Java IPolicyChain使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


IPolicyChain类属于io.apiman.gateway.engine.policy包,在下文中一共展示了IPolicyChain类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: doContinue

import io.apiman.gateway.engine.policy.IPolicyChain; //导入依赖的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);
    }
}
 
开发者ID:outofcoffee,项目名称:apiman-plugins-session,代码行数:24,代码来源:CookieRemovePolicy.java

示例2: invalidateSession

import io.apiman.gateway.engine.policy.IPolicyChain; //导入依赖的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));
        }
    });
}
 
开发者ID:outofcoffee,项目名称:apiman-plugins-session,代码行数:32,代码来源:CookieRemovePolicy.java

示例3: doTokenAuth

import io.apiman.gateway.engine.policy.IPolicyChain; //导入依赖的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);
    }
}
 
开发者ID:apiman,项目名称:apiman-plugins,代码行数:25,代码来源:KeycloakOauthPolicy.java

示例4: doApply

import io.apiman.gateway.engine.policy.IPolicyChain; //导入依赖的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);
}
 
开发者ID:apiman,项目名称:apiman-plugins,代码行数:19,代码来源:TransformationPolicy.java

示例5: doApply

import io.apiman.gateway.engine.policy.IPolicyChain; //导入依赖的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);
}
 
开发者ID:apiman,项目名称:apiman-plugins,代码行数:22,代码来源:CircuitBreakerPolicy.java

示例6: doApply

import io.apiman.gateway.engine.policy.IPolicyChain; //导入依赖的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);
}
 
开发者ID:apiman,项目名称:apiman-plugins,代码行数:19,代码来源:LogHeadersPolicy.java

示例7: doApply

import io.apiman.gateway.engine.policy.IPolicyChain; //导入依赖的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);
    }
}
 
开发者ID:apiman,项目名称:apiman-plugins,代码行数:25,代码来源:Auth3Scale.java

示例8: shouldNotSaveCallbackFunctionNameInContextWhenNotPresent

import io.apiman.gateway.engine.policy.IPolicyChain; //导入依赖的package包/类
@Test
public void shouldNotSaveCallbackFunctionNameInContextWhenNotPresent() throws Exception {
    // given
    JsonpConfigBean config = new JsonpConfigBean();
    config.setCallbackParamName("testParam");
    QueryMap queryParams = new QueryMap();
    ApiRequest request = new ApiRequest();
    request.setQueryParams(queryParams);

    IPolicyChain<ApiRequest> chain = mock(IPolicyChain.class);
    // when
    jsonpPolicy.doApply(request, sContext, config, chain);
    // then
    assertNull(sContext.getAttribute("callbackFunctionName", null));
    verify(chain).doApply(request);
}
 
开发者ID:apiman,项目名称:apiman-plugins,代码行数:17,代码来源:JsonpPolicyTest.java

示例9: shouldSaveCallbackParamNameInContextWhenPresent

import io.apiman.gateway.engine.policy.IPolicyChain; //导入依赖的package包/类
@Test
public void shouldSaveCallbackParamNameInContextWhenPresent() throws Exception {
    // given
    JsonpConfigBean config = new JsonpConfigBean();
    config.setCallbackParamName("testParam");
    QueryMap queryParams = new QueryMap();
    queryParams.put("testParam", "testFunction");
    ApiRequest request = new ApiRequest();
    request.setQueryParams(queryParams);

    IPolicyChain<ApiRequest> chain = mock(IPolicyChain.class);
    // when
    jsonpPolicy.doApply(request, sContext, config, chain);
    // then
    assertEquals("testFunction", sContext.getAttribute("callbackFunctionName", null));
    verify(chain).doApply(request);
}
 
开发者ID:apiman,项目名称:apiman-plugins,代码行数:18,代码来源:JsonpPolicyTest.java

示例10: shouldRemoveCallbackParamNameFromRequest

import io.apiman.gateway.engine.policy.IPolicyChain; //导入依赖的package包/类
@Test
public void shouldRemoveCallbackParamNameFromRequest() throws Exception {
    // given
    JsonpConfigBean config = new JsonpConfigBean();
    config.setCallbackParamName("testParam");
    QueryMap queryParams = new QueryMap();
    queryParams.put("testParam", "testFunction");
    ApiRequest request = new ApiRequest();
    request.setQueryParams(queryParams);

    IPolicyChain<ApiRequest> chain = mock(IPolicyChain.class);
    // when
    jsonpPolicy.doApply(request, sContext, config, chain);
    // then
    assertNull(request.getQueryParams().get("testParam"));
    verify(chain).doApply(request);
}
 
开发者ID:apiman,项目名称:apiman-plugins,代码行数:18,代码来源:JsonpPolicyTest.java

示例11: doApply

import io.apiman.gateway.engine.policy.IPolicyChain; //导入依赖的package包/类
/**
 * @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, TimeRestrictedAccessConfig config,
        IPolicyChain<ApiRequest> chain) {
    if (canProcessRequest(config, request.getDestination())) {
        super.doApply(request, context, config, chain);
    } else {
        IPolicyFailureFactoryComponent ffactory = context
                .getComponent(IPolicyFailureFactoryComponent.class);
        String msg = Messages.i18n.format("TimeRestrictedAccessPolicy.Unavailable", //$NON-NLS-1$
                request.getDestination());
        PolicyFailure failure = ffactory.createFailure(PolicyFailureType.Other,
                PolicyFailureCodes.ACCESS_TIME_RESTRICTED, msg);
        chain.doFailure(failure);
    }
}
 
开发者ID:apiman,项目名称:apiman,代码行数:21,代码来源:TimeRestrictedAccessPolicy.java

示例12: doApply

import io.apiman.gateway.engine.policy.IPolicyChain; //导入依赖的package包/类
/**
 * @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, IPListConfig config,
        IPolicyChain<ApiRequest> chain) {
    String remoteAddr = getRemoteAddr(request, config);
    if (isMatch(config, remoteAddr)) {
        IPolicyFailureFactoryComponent ffactory = context.getComponent(IPolicyFailureFactoryComponent.class);
        String msg = Messages.i18n.format("IPBlacklistPolicy.Blacklisted", remoteAddr); //$NON-NLS-1$
        PolicyFailure failure = ffactory.createFailure(PolicyFailureType.Other, PolicyFailureCodes.IP_BLACKLISTED, msg);
        failure.setResponseCode(config.getResponseCode());
        if (config.getResponseCode() == 404) {
            failure.setType(PolicyFailureType.NotFound);
        } else if (config.getResponseCode() == 403) {
            failure.setType(PolicyFailureType.Authorization);
        } else if (config.getResponseCode() == 0) {
            failure.setResponseCode(500);
        }

        chain.doFailure(failure);
    } else {
        super.doApply(request, context, config, chain);
    }
}
 
开发者ID:apiman,项目名称:apiman,代码行数:26,代码来源:IPBlacklistPolicy.java

示例13: doApply

import io.apiman.gateway.engine.policy.IPolicyChain; //导入依赖的package包/类
/**
 * @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, IPListConfig config,
        IPolicyChain<ApiRequest> chain) {
    String remoteAddr = getRemoteAddr(request, config);
    if (isMatch(config, remoteAddr)) {
        super.doApply(request, context, config, chain);
    } else {
        IPolicyFailureFactoryComponent ffactory = context.getComponent(IPolicyFailureFactoryComponent.class);
        String msg = Messages.i18n.format("IPWhitelistPolicy.NotWhitelisted", remoteAddr); //$NON-NLS-1$
        PolicyFailure failure = ffactory.createFailure(PolicyFailureType.Other, PolicyFailureCodes.IP_NOT_WHITELISTED, msg);
        failure.setResponseCode(config.getResponseCode());
        if (config.getResponseCode() == 404) {
            failure.setType(PolicyFailureType.NotFound);
        } else if (config.getResponseCode() == 403) {
            failure.setType(PolicyFailureType.Authorization);
        } else if (config.getResponseCode() == 0) {
            failure.setResponseCode(500);
        }
        chain.doFailure(failure);
    }
}
 
开发者ID:apiman,项目名称:apiman,代码行数:25,代码来源:IPWhitelistPolicy.java

示例14: doApply

import io.apiman.gateway.engine.policy.IPolicyChain; //导入依赖的package包/类
/**
 * @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);
    }
}
 
开发者ID:apiman,项目名称:apiman,代码行数:21,代码来源:IgnoredResourcesPolicy.java

示例15: testApplyJdbcWithRoles

import io.apiman.gateway.engine.policy.IPolicyChain; //导入依赖的package包/类
public void testApplyJdbcWithRoles(String json) throws Exception {
    // A live LDAP server is required to run this test!
    BasicAuthenticationPolicy policy = new BasicAuthenticationPolicy();
    BasicAuthenticationConfig config = policy.parseConfiguration(json);
    ApiRequest request = new ApiRequest();
    request.setType("GET");
    request.setApiKey("12345");
    request.setRemoteAddr("1.2.3.4");
    request.setDestination("/");
    IPolicyContext context = Mockito.mock(IPolicyContext.class);
    Mockito.when(context.getComponent(IJdbcComponent.class)).thenReturn(new DefaultJdbcComponent());
    IPolicyChain<ApiRequest> chain = Mockito.mock(IPolicyChain.class);

    // Success
    request.getHeaders().put("Authorization", createBasicAuthorization(JDBC_USER, JDBC_PASSWORD));
    chain = Mockito.mock(IPolicyChain.class);
    policy.apply(request, context, config, chain);
    Mockito.verify(chain).doApply(request);
    Set<String> expectedRoles = new HashSet<>();
    expectedRoles.add("admin");
    expectedRoles.add("user");
    Mockito.verify(context).setAttribute(AuthorizationPolicy.AUTHENTICATED_USER_ROLES, expectedRoles);
}
 
开发者ID:apiman,项目名称:apiman,代码行数:24,代码来源:BasicAuthJDBCTest.java


注:本文中的io.apiman.gateway.engine.policy.IPolicyChain类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。