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


Java PolicyFailure类代码示例

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


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

示例1: invalidateSession

import io.apiman.gateway.engine.beans.PolicyFailure; //导入依赖的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

示例2: shouldBlacklistUnsafeToken

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

示例3: shouldTerminateOnBlacklistedToken

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

示例4: shouldFailWhenNoTokenProvided

import io.apiman.gateway.engine.beans.PolicyFailure; //导入依赖的package包/类
@Test
@Configuration("{\n" +
        "  \"requireJWT\": true,\n" +
        "  \"requireSigned\": false,\n" +
        "  \"requireTransportSecurity\": true,\n" +
        "  \"stripTokens\": true,\n" +
        "  \"signingKeyString\": \""+ PUBLIC_KEY_PEM +"\",\n" +
        "  \"allowedClockSkew\": 0,\n" +
        "  \"requiredClaims\": [{ \"claimName\": \"sub\", \"claimValue\": \"france frichot\" }]\n" +
        "}"
)
public void shouldFailWhenNoTokenProvided() throws Throwable {
    PolicyFailure failure = null;
    PolicyTestRequest request = PolicyTestRequest.build(PolicyTestRequestType.GET, "/amirante");
    try {
        send(request);
    } catch (PolicyFailureError pfe) {
        failure = pfe.getFailure();
    }
    Assert.assertNotNull(failure);
    Assert.assertEquals(401, failure.getResponseCode());
    Assert.assertEquals(12005, failure.getFailureCode());
    Assert.assertEquals(PolicyFailureType.Authentication, failure.getType());
}
 
开发者ID:apiman,项目名称:apiman-plugins,代码行数:25,代码来源:JWTPolicyTest.java

示例5: shouldFailWhenTokenInvalid

import io.apiman.gateway.engine.beans.PolicyFailure; //导入依赖的package包/类
@Test
@Configuration("{\n" +
        "  \"requireJWT\": true,\n" +
        "  \"requireSigned\": false,\n" +
        "  \"requireTransportSecurity\": true,\n" +
        "  \"stripTokens\": true,\n" +
        "  \"signingKeyString\": \""+ PUBLIC_KEY_PEM +"\",\n" +
        "  \"allowedClockSkew\": 0,\n" +
        "  \"requiredClaims\": [{ \"claimName\": \"sub\", \"claimValue\": \"france frichot\" }]\n" +
        "}"
)
public void shouldFailWhenTokenInvalid() throws Throwable {
    PolicyFailure failure = null;
    PolicyTestRequest request = PolicyTestRequest.build(PolicyTestRequestType.GET, "/amirante")
                .header("Authorization", "Bearer <Obviously invalid token>");
    try {
        send(request);
    } catch (PolicyFailureError pfe) {
        failure = pfe.getFailure();
    }
    Assert.assertNotNull(failure);
    Assert.assertEquals(401, failure.getResponseCode());
    Assert.assertEquals(12007, failure.getFailureCode());
    Assert.assertEquals(PolicyFailureType.Authentication, failure.getType());
}
 
开发者ID:apiman,项目名称:apiman-plugins,代码行数:26,代码来源:JWTPolicyTest.java

示例6: shouldFailWhenTokenNotYetValid

import io.apiman.gateway.engine.beans.PolicyFailure; //导入依赖的package包/类
@Test
@Configuration("{\n" +
        "  \"requireJWT\": true,\n" +
        "  \"requireSigned\": false,\n" +
        "  \"requireTransportSecurity\": true,\n" +
        "  \"stripTokens\": true,\n" +
        "  \"signingKeyString\": \""+ PUBLIC_KEY_PEM +"\",\n" +
        "  \"allowedClockSkew\": 0,\n" +
        "  \"requiredClaims\": [{ \"claimName\": \"sub\", \"claimValue\": \"france frichot\" }]\n" +
        "}"
)
public void shouldFailWhenTokenNotYetValid() throws Throwable {
    PolicyFailure failure = null;
    PolicyTestRequest request = PolicyTestRequest.build(PolicyTestRequestType.GET, "/amirante")
                .header("Authorization", "Bearer " + unsignedNotYetValidToken());
    try {
        send(request);
    } catch (PolicyFailureError pfe) {
        failure = pfe.getFailure();
    }
    Assert.assertNotNull(failure);
    Assert.assertEquals(401, failure.getResponseCode());
    Assert.assertEquals(12010, failure.getFailureCode());
    Assert.assertEquals(PolicyFailureType.Authentication, failure.getType());
}
 
开发者ID:apiman,项目名称:apiman-plugins,代码行数:26,代码来源:JWTPolicyTest.java

示例7: shouldFailWhenTokenExpired

import io.apiman.gateway.engine.beans.PolicyFailure; //导入依赖的package包/类
@Test
@Configuration("{\n" +
        "  \"requireJWT\": true,\n" +
        "  \"requireSigned\": false,\n" +
        "  \"requireTransportSecurity\": true,\n" +
        "  \"stripTokens\": true,\n" +
        "  \"signingKeyString\": \""+ PUBLIC_KEY_PEM +"\",\n" +
        "  \"allowedClockSkew\": 0,\n" +
        "  \"requiredClaims\": [{ \"claimName\": \"sub\", \"claimValue\": \"france frichot\" }]\n" +
        "}"
)
public void shouldFailWhenTokenExpired() throws Throwable {
    PolicyFailure failure = null;
    PolicyTestRequest request = PolicyTestRequest.build(PolicyTestRequestType.GET, "/amirante")
                .header("Authorization", "Bearer " + unsignedExpiredToken());
    try {
        send(request);
    } catch (PolicyFailureError pfe) {
        failure = pfe.getFailure();
    }
    Assert.assertNotNull(failure);
    Assert.assertEquals(401, failure.getResponseCode());
    Assert.assertEquals(12006, failure.getFailureCode());
    Assert.assertEquals(PolicyFailureType.Authentication, failure.getType());
}
 
开发者ID:apiman,项目名称:apiman-plugins,代码行数:26,代码来源:JWTPolicyTest.java

示例8: shouldFailWithUnexpectedClaimValue

import io.apiman.gateway.engine.beans.PolicyFailure; //导入依赖的package包/类
@Test
@Configuration("{\n" +
        "  \"requireJWT\": true,\n" +
        "  \"requireSigned\": false,\n" +
        "  \"requireTransportSecurity\": true,\n" +
        "  \"stripTokens\": true,\n" +
        "  \"signingKeyString\": \""+ PUBLIC_KEY_PEM +"\",\n" +
        "  \"allowedClockSkew\": 0,\n" +
        "  \"requiredClaims\": [{ \"claimName\": \"sub\", \"claimValue\": \"will_not_match\" }]\n" +
        "}"
)
public void shouldFailWithUnexpectedClaimValue() throws Throwable {
    PolicyFailure failure = null;
    PolicyTestRequest request = PolicyTestRequest.build(PolicyTestRequestType.GET, "/amirante")
                .header("Authorization", "Bearer " + unsignedToken());
    try {
        send(request);
    } catch (PolicyFailureError pfe) {
        failure = pfe.getFailure();
    }
    Assert.assertNotNull(failure);
    Assert.assertEquals(401, failure.getResponseCode());
    Assert.assertEquals(12009, failure.getFailureCode());
    Assert.assertEquals(PolicyFailureType.Authentication, failure.getType());
}
 
开发者ID:apiman,项目名称:apiman-plugins,代码行数:26,代码来源:JWTPolicyTest.java

示例9: shouldFailWithMissingClaim

import io.apiman.gateway.engine.beans.PolicyFailure; //导入依赖的package包/类
@Test
@Configuration("{\n" +
        "  \"requireJWT\": true,\n" +
        "  \"requireSigned\": false,\n" +
        "  \"requireTransportSecurity\": true,\n" +
        "  \"stripTokens\": true,\n" +
        "  \"signingKeyString\": \""+ PUBLIC_KEY_PEM +"\",\n" +
        "  \"allowedClockSkew\": 0,\n" +
        "  \"requiredClaims\": [{ \"claimName\": \"sub\", \"claimValue\": \"will_not_match\" }]\n" +
        "}"
)
public void shouldFailWithMissingClaim() throws Throwable {
    PolicyFailure failure = null;
    PolicyTestRequest request = PolicyTestRequest.build(PolicyTestRequestType.GET, "/amirante")
                .header("Authorization", "Bearer " + Jwts.builder().claim("x", "x").compact());
    try {
        send(request);
    } catch (PolicyFailureError pfe) {
        failure = pfe.getFailure();
    }
    Assert.assertNotNull(failure);
    Assert.assertEquals(401, failure.getResponseCode());
    Assert.assertEquals(12009, failure.getFailureCode());
    Assert.assertEquals(PolicyFailureType.Authentication, failure.getType());
}
 
开发者ID:apiman,项目名称:apiman-plugins,代码行数:26,代码来源:JWTPolicyTest.java

示例10: shouldFailWithNoTls

import io.apiman.gateway.engine.beans.PolicyFailure; //导入依赖的package包/类
@Test
@Configuration("{\n" +
        "  \"requireJWT\": true,\n" +
        "  \"requireSigned\": false,\n" +
        "  \"requireTransportSecurity\": true,\n" +
        "  \"stripTokens\": true,\n" +
        "  \"signingKeyString\": \""+ PUBLIC_KEY_PEM +"\",\n" +
        "  \"allowedClockSkew\": 0,\n" +
        "  \"requiredClaims\": [{ \"claimName\": \"sub\", \"claimValue\": \"will_not_match\" }]\n" +
        "}"
)
public void shouldFailWithNoTls() throws Throwable {
    PolicyFailure failure = null;
    PolicyTestRequest request = PolicyTestRequest.build(PolicyTestRequestType.GET, "/amirante")
                .header("Authorization", "Bearer " + Jwts.builder().claim("x", "x").compact());
    try {
        send(request);
    } catch (PolicyFailureError pfe) {
        failure = pfe.getFailure();
    }
    Assert.assertNotNull(failure);
    Assert.assertEquals(401, failure.getResponseCode());
    Assert.assertEquals(12009, failure.getFailureCode());
    Assert.assertEquals(PolicyFailureType.Authentication, failure.getType());
}
 
开发者ID:apiman,项目名称:apiman-plugins,代码行数:26,代码来源:JWTPolicyTest.java

示例11: doApply

import io.apiman.gateway.engine.beans.PolicyFailure; //导入依赖的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.beans.PolicyFailure; //导入依赖的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.beans.PolicyFailure; //导入依赖的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.beans.PolicyFailure; //导入依赖的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: shouldCallFailureHandlerOnDoFail

import io.apiman.gateway.engine.beans.PolicyFailure; //导入依赖的package包/类
@Test
public void shouldCallFailureHandlerOnDoFail() {
    policies.add(pwcOne);
    policies.add(pwcTwo);

    requestChain = new RequestChain(policies, mockContext);

    IAsyncHandler<PolicyFailure> mPolicyFailureHandler = mock(IAsyncHandler.class);

    PolicyFailure mPolicyFailure = mock(PolicyFailure.class);

    requestChain.policyFailureHandler(mPolicyFailureHandler);
    requestChain.bodyHandler(mockBodyHandler);
    requestChain.endHandler(mockEndHandler);

    requestChain.doApply(mockRequest);
    requestChain.doFailure(mPolicyFailure);

    verify(mPolicyFailureHandler).handle(mPolicyFailure);
}
 
开发者ID:apiman,项目名称:apiman,代码行数:21,代码来源:PolicyChainTest.java


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