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());
}
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();
}
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);
}
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();
}
};
}
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();
}
Aggregations