Search in sources :

Example 1 with PolicyFailure

use of io.apiman.gateway.engine.beans.PolicyFailure in project apiman-plugins by apiman.

the class JWTPolicyTest method shouldFailWithNoTls.

@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());
}
Also used : PolicyFailure(io.apiman.gateway.engine.beans.PolicyFailure) PolicyTestRequest(io.apiman.test.policies.PolicyTestRequest) PolicyFailureError(io.apiman.test.policies.PolicyFailureError) Configuration(io.apiman.test.policies.Configuration) ApimanPolicyTest(io.apiman.test.policies.ApimanPolicyTest) Test(org.junit.Test)

Example 2 with PolicyFailure

use of io.apiman.gateway.engine.beans.PolicyFailure in project apiman-plugins by apiman.

the class JWTPolicyTest method shouldFailWithUnexpectedClaimValue.

@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());
}
Also used : PolicyFailure(io.apiman.gateway.engine.beans.PolicyFailure) PolicyTestRequest(io.apiman.test.policies.PolicyTestRequest) PolicyFailureError(io.apiman.test.policies.PolicyFailureError) Configuration(io.apiman.test.policies.Configuration) ApimanPolicyTest(io.apiman.test.policies.ApimanPolicyTest) Test(org.junit.Test)

Example 3 with PolicyFailure

use of io.apiman.gateway.engine.beans.PolicyFailure in project apiman-plugins by apiman.

the class JWTPolicyTest method shouldFailWhenTokenInvalid.

@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());
}
Also used : PolicyFailure(io.apiman.gateway.engine.beans.PolicyFailure) PolicyTestRequest(io.apiman.test.policies.PolicyTestRequest) PolicyFailureError(io.apiman.test.policies.PolicyFailureError) Configuration(io.apiman.test.policies.Configuration) ApimanPolicyTest(io.apiman.test.policies.ApimanPolicyTest) Test(org.junit.Test)

Example 4 with PolicyFailure

use of io.apiman.gateway.engine.beans.PolicyFailure in project apiman-plugins by apiman.

the class JWTPolicyTest method shouldFailWithMissingClaim.

@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());
}
Also used : PolicyFailure(io.apiman.gateway.engine.beans.PolicyFailure) PolicyTestRequest(io.apiman.test.policies.PolicyTestRequest) PolicyFailureError(io.apiman.test.policies.PolicyFailureError) Configuration(io.apiman.test.policies.Configuration) ApimanPolicyTest(io.apiman.test.policies.ApimanPolicyTest) Test(org.junit.Test)

Example 5 with PolicyFailure

use of io.apiman.gateway.engine.beans.PolicyFailure in project apiman-plugins by apiman.

the class PolicyFailureFactory method createAuthenticationPolicyFailure.

private PolicyFailure createAuthenticationPolicyFailure(IPolicyContext context, int failureCode, String message) {
    PolicyFailure pf = getFailureFactory(context).createFailure(PolicyFailureType.Authentication, failureCode, message);
    pf.setResponseCode(HTTP_UNAUTHORIZED);
    return pf;
}
Also used : PolicyFailure(io.apiman.gateway.engine.beans.PolicyFailure)

Aggregations

PolicyFailure (io.apiman.gateway.engine.beans.PolicyFailure)54 Test (org.junit.Test)26 IPolicyFailureFactoryComponent (io.apiman.gateway.engine.components.IPolicyFailureFactoryComponent)19 ApimanPolicyTest (io.apiman.test.policies.ApimanPolicyTest)19 Configuration (io.apiman.test.policies.Configuration)19 PolicyFailureError (io.apiman.test.policies.PolicyFailureError)19 PolicyTestRequest (io.apiman.test.policies.PolicyTestRequest)19 ApiRequest (io.apiman.gateway.engine.beans.ApiRequest)11 IPolicyContext (io.apiman.gateway.engine.policy.IPolicyContext)11 PolicyTestResponse (io.apiman.test.policies.PolicyTestResponse)11 PolicyFailureType (io.apiman.gateway.engine.beans.PolicyFailureType)9 IPolicyChain (io.apiman.gateway.engine.policy.IPolicyChain)8 EchoResponse (io.apiman.test.common.mock.EchoResponse)7 HashSet (java.util.HashSet)6 BackEndApi (io.apiman.test.policies.BackEndApi)4 IPolicyTestBackEndApi (io.apiman.test.policies.IPolicyTestBackEndApi)4 IRateLimiterComponent (io.apiman.gateway.engine.components.IRateLimiterComponent)2 RateLimitResponse (io.apiman.gateway.engine.components.rate.RateLimitResponse)2 BasicAuthenticationConfig (io.apiman.gateway.engine.policies.config.BasicAuthenticationConfig)2 IPListConfig (io.apiman.gateway.engine.policies.config.IPListConfig)2