Search in sources :

Example 1 with ApiRequest

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

the class KeycloakOauthPolicyLegacyTest method initTest.

@Before
public void initTest() {
    MockitoAnnotations.initMocks(this);
    token = new AccessToken();
    // KC seems to use issuer for realm?
    AccessToken realm = token.type("Bearer").subject("CN=Client").issuer("apiman-realm");
    realm.addAccess("apiman-api").addRole("apiman-gateway-user-role").addRole("a-nother-role");
    realm.setRealmAccess(new Access().addRole("lets-use-a-realm-role"));
    keycloakOauthPolicy = new KeycloakOauthPolicy();
    config = new KeycloakOauthConfigBean();
    config.setRequireOauth(true);
    config.setStripTokens(false);
    config.setBlacklistUnsafeTokens(false);
    config.setRequireTransportSecurity(false);
    forwardRoles = new ForwardRoles();
    config.setForwardRoles(forwardRoles);
    apiRequest = new ApiRequest();
    // Set up components.
    // Failure factory
    given(mContext.getComponent(IPolicyFailureFactoryComponent.class)).willReturn(new DefaultPolicyFailureFactoryComponent());
    // Data store
    given(mContext.getComponent(ISharedStateComponent.class)).willReturn(new InMemorySharedStateComponent());
}
Also used : AccessToken(org.keycloak.representations.AccessToken) InMemorySharedStateComponent(io.apiman.gateway.engine.impl.InMemorySharedStateComponent) Access(org.keycloak.representations.AccessToken.Access) ApiRequest(io.apiman.gateway.engine.beans.ApiRequest) KeycloakOauthConfigBean(io.apiman.plugins.keycloak_oauth_policy.beans.KeycloakOauthConfigBean) ForwardRoles(io.apiman.plugins.keycloak_oauth_policy.beans.ForwardRoles) DefaultPolicyFailureFactoryComponent(io.apiman.gateway.engine.impl.DefaultPolicyFailureFactoryComponent) Before(org.junit.Before)

Example 2 with ApiRequest

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

the class KeycloakOauthPolicyTest method initTest.

@Before
public void initTest() {
    MockitoAnnotations.initMocks(this);
    token = new AccessToken();
    // KC seems to use issuer for realm?
    AccessToken realm = token.type("Bearer").subject("CN=Client").issuer("apiman-realm");
    realm.addAccess("apiman-api").addRole("apiman-gateway-user-role").addRole("a-nother-role");
    realm.setRealmAccess(new Access().addRole("lets-use-a-realm-role"));
    keycloakOauthPolicy = new KeycloakOauthPolicy();
    config = new KeycloakOauthConfigBean();
    config.setRequireOauth(true);
    config.setStripTokens(false);
    config.setBlacklistUnsafeTokens(false);
    config.setRequireTransportSecurity(false);
    forwardRoles = new ForwardRoles();
    config.setForwardRoles(forwardRoles);
    apiRequest = new ApiRequest();
    // Set up components.
    // Failure factory
    given(mContext.getComponent(IPolicyFailureFactoryComponent.class)).willReturn(new DefaultPolicyFailureFactoryComponent());
    // Data store
    given(mContext.getComponent(ISharedStateComponent.class)).willReturn(new InMemorySharedStateComponent());
    initializeJwksBackend();
}
Also used : AccessToken(org.keycloak.representations.AccessToken) InMemorySharedStateComponent(io.apiman.gateway.engine.impl.InMemorySharedStateComponent) Access(org.keycloak.representations.AccessToken.Access) ApiRequest(io.apiman.gateway.engine.beans.ApiRequest) KeycloakOauthConfigBean(io.apiman.plugins.keycloak_oauth_policy.beans.KeycloakOauthConfigBean) ForwardRoles(io.apiman.plugins.keycloak_oauth_policy.beans.ForwardRoles) DefaultPolicyFailureFactoryComponent(io.apiman.gateway.engine.impl.DefaultPolicyFailureFactoryComponent)

Example 3 with ApiRequest

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

the class JsonpPolicyTest method shouldNotSaveCallbackFunctionNameInContextWhenNotPresent.

@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);
}
Also used : JsonpConfigBean(io.apiman.plugins.jsonp_policy.beans.JsonpConfigBean) QueryMap(io.apiman.gateway.engine.beans.util.QueryMap) ApiRequest(io.apiman.gateway.engine.beans.ApiRequest) Test(org.junit.Test)

Example 4 with ApiRequest

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

the class TransformationPolicy method getRequestDataHandler.

/**
 * @see io.apiman.gateway.engine.policy.IDataPolicy#getRequestDataHandler(io.apiman.gateway.engine.beans.ApiRequest, io.apiman.gateway.engine.policy.IPolicyContext, java.lang.Object)
 */
@Override
public IReadWriteStream<ApiRequest> getRequestDataHandler(final ApiRequest request, IPolicyContext context, Object policyConfiguration) {
    final IBufferFactoryComponent bufferFactory = context.getComponent(IBufferFactoryComponent.class);
    final int contentLength = request.getHeaders().containsKey(CONTENT_LENGTH) ? Integer.parseInt(request.getHeaders().get(CONTENT_LENGTH)) : 0;
    return new AbstractStream<ApiRequest>() {

        private IApimanBuffer readBuffer = bufferFactory.createBuffer(contentLength);

        @Override
        public ApiRequest getHead() {
            return request;
        }

        @Override
        protected void handleHead(ApiRequest head) {
        }

        @Override
        public void write(IApimanBuffer chunk) {
            readBuffer.append(chunk.getBytes());
        }

        @Override
        public void end() {
            final DataFormat clientFormat = (DataFormat) context.getAttribute(CLIENT_FORMAT, null);
            final DataFormat serverFormat = (DataFormat) context.getAttribute(SERVER_FORMAT, null);
            if (readBuffer.length() > 0) {
                if (isValidTransformation(clientFormat, serverFormat)) {
                    DataTransformer dataTransformer = DataTransformerFactory.getDataTransformer(clientFormat, serverFormat);
                    IApimanBuffer writeBuffer = bufferFactory.createBuffer(readBuffer.length());
                    String data = dataTransformer.transform(new String(readBuffer.getBytes()));
                    writeBuffer.append(data);
                    super.write(writeBuffer);
                } else {
                    super.write(readBuffer);
                }
            }
            super.end();
        }
    };
}
Also used : IApimanBuffer(io.apiman.gateway.engine.io.IApimanBuffer) IBufferFactoryComponent(io.apiman.gateway.engine.components.IBufferFactoryComponent) DataTransformer(io.apiman.plugins.transformation_policy.transformer.DataTransformer) AbstractStream(io.apiman.gateway.engine.io.AbstractStream) DataFormat(io.apiman.plugins.transformation_policy.beans.DataFormat) ApiRequest(io.apiman.gateway.engine.beans.ApiRequest)

Example 5 with ApiRequest

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

the class SimpleHeaderPolicyTest method setup.

@Before
public void setup() {
    MockitoAnnotations.initMocks(this);
    policy = new SimpleHeaderPolicy();
    config = new SimpleHeaderPolicyDefBean();
    request = new ApiRequest();
    response = new ApiResponse();
}
Also used : ApiRequest(io.apiman.gateway.engine.beans.ApiRequest) SimpleHeaderPolicyDefBean(io.apiman.plugins.simpleheaderpolicy.beans.SimpleHeaderPolicyDefBean) ApiResponse(io.apiman.gateway.engine.beans.ApiResponse) Before(org.junit.Before)

Aggregations

ApiRequest (io.apiman.gateway.engine.beans.ApiRequest)34 IPolicyContext (io.apiman.gateway.engine.policy.IPolicyContext)15 PolicyFailure (io.apiman.gateway.engine.beans.PolicyFailure)13 Test (org.junit.Test)13 IPolicyChain (io.apiman.gateway.engine.policy.IPolicyChain)9 PolicyFailureType (io.apiman.gateway.engine.beans.PolicyFailureType)8 IPolicyFailureFactoryComponent (io.apiman.gateway.engine.components.IPolicyFailureFactoryComponent)7 IApimanBuffer (io.apiman.gateway.engine.io.IApimanBuffer)7 IEngineResult (io.apiman.gateway.engine.IEngineResult)5 ApiResponse (io.apiman.gateway.engine.beans.ApiResponse)5 ISignalWriteStream (io.apiman.gateway.engine.io.ISignalWriteStream)5 ArrayList (java.util.ArrayList)5 IApiRequestExecutor (io.apiman.gateway.engine.IApiRequestExecutor)4 QueryMap (io.apiman.gateway.engine.beans.util.QueryMap)4 IApiConnector (io.apiman.gateway.engine.IApiConnector)3 IConnectorConfig (io.apiman.gateway.engine.IConnectorConfig)3 IAsyncResultHandler (io.apiman.gateway.engine.async.IAsyncResultHandler)3 IBufferFactoryComponent (io.apiman.gateway.engine.components.IBufferFactoryComponent)3 PolicyWithConfiguration (io.apiman.gateway.engine.policy.PolicyWithConfiguration)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3