本文整理匯總了Java中io.apiman.gateway.engine.IApiConnection類的典型用法代碼示例。如果您正苦於以下問題:Java IApiConnection類的具體用法?Java IApiConnection怎麽用?Java IApiConnection使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
IApiConnection類屬於io.apiman.gateway.engine包,在下文中一共展示了IApiConnection類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: shouldSucceedWhenAllowedSelfSigned
import io.apiman.gateway.engine.IApiConnection; //導入依賴的package包/類
/**
* Scenario:
* - no CA inherited trust
* - gateway does not explicitly trust the API, but automatically validates against self-signed
* - API trusts gateway certificate
*/
@Test
public void shouldSucceedWhenAllowedSelfSigned() {
config.put(TLSOptions.TLS_TRUSTSTORE, getResourcePath("2waytest/basic_mutual_auth/gateway_ts.jks"));
config.put(TLSOptions.TLS_TRUSTSTOREPASSWORD, "password");
config.put(TLSOptions.TLS_KEYSTORE, getResourcePath("2waytest/basic_mutual_auth/gateway_ks.jks"));
config.put(TLSOptions.TLS_KEYSTOREPASSWORD, "password");
config.put(TLSOptions.TLS_KEYPASSWORD, "password");
config.put(TLSOptions.TLS_ALLOWANYHOST, "true");
config.put(TLSOptions.TLS_ALLOWSELFSIGNED, "true");
HttpConnectorFactory factory = new HttpConnectorFactory(config);
IApiConnector connector = factory.createConnector(request, api, RequiredAuthType.MTLS, false);
IApiConnection connection = connector.connect(request,
new IAsyncResultHandler<IApiConnectionResponse>() {
@Override
public void handle(IAsyncResult<IApiConnectionResponse> result) {
Assert.assertTrue(result.isSuccess());
}
});
connection.end();
}
示例2: shouldFailWithInValidKeyAlias
import io.apiman.gateway.engine.IApiConnection; //導入依賴的package包/類
/**
* Scenario:
* - Select invalid key alias (no such key).
* - Negotiation will fail
* @throws CertificateException the certificate exception
* @throws IOException the IO exception
*/
@Test
public void shouldFailWithInValidKeyAlias() throws CertificateException, IOException {
config.put(TLSOptions.TLS_TRUSTSTORE, getResourcePath("2waytest/basic_mutual_auth_2/gateway_ts.jks"));
config.put(TLSOptions.TLS_TRUSTSTOREPASSWORD, "password");
config.put(TLSOptions.TLS_KEYSTORE, getResourcePath("2waytest/basic_mutual_auth_2/gateway_ks.jks"));
config.put(TLSOptions.TLS_KEYSTOREPASSWORD, "password");
config.put(TLSOptions.TLS_KEYPASSWORD, "password");
config.put(TLSOptions.TLS_ALLOWANYHOST, "true");
config.put(TLSOptions.TLS_ALLOWSELFSIGNED, "false");
// No such key exists in the keystore
config.put(TLSOptions.TLS_KEYALIASES, "xxx");
HttpConnectorFactory factory = new HttpConnectorFactory(config);
IApiConnector connector = factory.createConnector(request, api, RequiredAuthType.MTLS, false);
IApiConnection connection = connector.connect(request,
new IAsyncResultHandler<IApiConnectionResponse>() {
@Override
public void handle(IAsyncResult<IApiConnectionResponse> result) {
Assert.assertTrue(result.isError());
}
});
connection.end();
}
示例3: shouldFailWithDevModeAndNoClientKeys
import io.apiman.gateway.engine.IApiConnection; //導入依賴的package包/類
/**
* Scenario:
* - Development mode TLS pass-through. Gateway accepts anything.
* - Server should still refuse on basis of requiring client auth.
*/
@Test
public void shouldFailWithDevModeAndNoClientKeys() {
config.put(TLSOptions.TLS_DEVMODE, "true");
HttpConnectorFactory factory = new HttpConnectorFactory(config);
IApiConnector connector = factory.createConnector(request, api, RequiredAuthType.DEFAULT, false);
IApiConnection connection = connector.connect(request,
new IAsyncResultHandler<IApiConnectionResponse>() {
@Override
public void handle(IAsyncResult<IApiConnectionResponse> result) {
Assert.assertTrue(result.isError());
System.out.println(result.getError());
}
});
connection.end();
}
示例4: shouldSucceedWithValidTLS
import io.apiman.gateway.engine.IApiConnection; //導入依賴的package包/類
/**
* Scenario:
* - CA inherited trust
* - gateway trusts API via CA
* - API does not evaluate trust
*/
@Test
public void shouldSucceedWithValidTLS() {
config.put(TLSOptions.TLS_TRUSTSTORE, getResourcePath("2waytest/mutual_trust_via_ca/common_ts.jks"));
config.put(TLSOptions.TLS_TRUSTSTOREPASSWORD, "password");
config.put(TLSOptions.TLS_ALLOWANYHOST, "true");
config.put(TLSOptions.TLS_ALLOWSELFSIGNED, "false");
HttpConnectorFactory factory = new HttpConnectorFactory(config);
IApiConnector connector = factory.createConnector(request, api, RequiredAuthType.DEFAULT, false);
IApiConnection connection = connector.connect(request,
new IAsyncResultHandler<IApiConnectionResponse>() {
@Override
public void handle(IAsyncResult<IApiConnectionResponse> result) {
if (result.isError())
throw new RuntimeException(result.getError());
Assert.assertTrue(result.isSuccess());
}
});
connection.end();
}
示例5: shouldFailWhenCANotTrusted
import io.apiman.gateway.engine.IApiConnection; //導入依賴的package包/類
/**
* Scenario:
* - CA is only in API trust store, missing from gateway trust store
* - Gateway does not trust API, as it does not trust CA
* - API trusts gateway via CA
*/
@Test
public void shouldFailWhenCANotTrusted() {
// Keystore does not trust the root CA API is signed with.
config.put(TLSOptions.TLS_TRUSTSTORE, getResourcePath("2waytest/basic_mutual_auth/gateway_ts.jks"));
config.put(TLSOptions.TLS_TRUSTSTOREPASSWORD, "password");
config.put(TLSOptions.TLS_ALLOWANYHOST, "true");
config.put(TLSOptions.TLS_ALLOWSELFSIGNED, "false");
HttpConnectorFactory factory = new HttpConnectorFactory(config);
IApiConnector connector = factory.createConnector(request, api, RequiredAuthType.DEFAULT, false);
IApiConnection connection = connector.connect(request,
new IAsyncResultHandler<IApiConnectionResponse>() {
@Override
public void handle(IAsyncResult<IApiConnectionResponse> result) {
Assert.assertTrue(result.isError());
System.out.println(result.getError());
Assert.assertTrue(result.getError() instanceof ConnectorException);
}
});
connection.end();
}
示例6: shouldAllowAllWhenDevMode
import io.apiman.gateway.engine.IApiConnection; //導入依賴的package包/類
/**
* Scenario:
* - Development mode TLS pass-through. Accepts anything.
*/
@Test
public void shouldAllowAllWhenDevMode() {
config.put(TLSOptions.TLS_DEVMODE, "true");
HttpConnectorFactory factory = new HttpConnectorFactory(config);
IApiConnector connector = factory.createConnector(request, api, RequiredAuthType.DEFAULT, false);
IApiConnection connection = connector.connect(request,
new IAsyncResultHandler<IApiConnectionResponse>() {
@Override
public void handle(IAsyncResult<IApiConnectionResponse> result) {
Assert.assertTrue(result.isSuccess());
}
});
connection.end();
}
示例7: shouldFailWithNoSettings
import io.apiman.gateway.engine.IApiConnection; //導入依賴的package包/類
/**
* Scenario:
* - No settings whatsoever.
* - Will fail, as defaults are relatively safe,
* and API certificate will not be recognised.
*/
@Test
public void shouldFailWithNoSettings() {
HttpConnectorFactory factory = new HttpConnectorFactory(config);
IApiConnector connector = factory.createConnector(request, api, RequiredAuthType.DEFAULT, false);
IApiConnection connection = connector.connect(request,
new IAsyncResultHandler<IApiConnectionResponse>() {
@Override
public void handle(IAsyncResult<IApiConnectionResponse> result) {
Assert.assertTrue(result.isError());
System.out.println(result.getError());
}
});
connection.end();
}
示例8: shouldSucceedWithBasicAuth
import io.apiman.gateway.engine.IApiConnection; //導入依賴的package包/類
/**
* Scenario successful connection to the back end API via basic auth.
*/
@Test
public void shouldSucceedWithBasicAuth() {
endpointProperties.put(BasicAuthOptions.BASIC_USERNAME, "user");
endpointProperties.put(BasicAuthOptions.BASIC_PASSWORD, "user123!");
endpointProperties.put(BasicAuthOptions.BASIC_REQUIRE_SSL, "false");
api.setEndpointProperties(endpointProperties);
api.setEndpoint("http://localhost:8008/echo");
HttpConnectorFactory factory = new HttpConnectorFactory(globalConfig);
IApiConnector connector = factory.createConnector(request, api, RequiredAuthType.BASIC, false);
IApiConnection connection = connector.connect(request,
new IAsyncResultHandler<IApiConnectionResponse>() {
@Override
public void handle(IAsyncResult<IApiConnectionResponse> result) {
Assert.assertTrue("Expected a successful connection response.", result.isSuccess());
IApiConnectionResponse scr = result.getResult();
Assert.assertEquals("Expected a 200 response from the echo server (valid creds).", 200, scr.getHead().getCode());
}
});
if (connection.isConnected()) {
connection.end();
}
}
示例9: shouldSucceedWithBasicAuthAndSSL
import io.apiman.gateway.engine.IApiConnection; //導入依賴的package包/類
/**
* Scenario successful connection to the back end API via basic auth.
*/
@Test
public void shouldSucceedWithBasicAuthAndSSL() {
endpointProperties.put(BasicAuthOptions.BASIC_USERNAME, "user");
endpointProperties.put(BasicAuthOptions.BASIC_PASSWORD, "user123!");
endpointProperties.put(BasicAuthOptions.BASIC_REQUIRE_SSL, "true");
api.setEndpointProperties(endpointProperties);
api.setEndpoint("https://localhost:8009/echo");
HttpConnectorFactory factory = new HttpConnectorFactory(globalConfig);
IApiConnector connector = factory.createConnector(request, api, RequiredAuthType.BASIC, false);
IApiConnection connection = connector.connect(request,
new IAsyncResultHandler<IApiConnectionResponse>() {
@Override
public void handle(IAsyncResult<IApiConnectionResponse> result) {
Assert.assertTrue("Expected a successful connection response.", result.isSuccess());
IApiConnectionResponse scr = result.getResult();
Assert.assertEquals("Expected a 200 response from the echo server (valid creds).", 200, scr.getHead().getCode());
}
});
if (connection.isConnected()) {
connection.end();
}
}
示例10: shouldFailWithNoSSL
import io.apiman.gateway.engine.IApiConnection; //導入依賴的package包/類
/**
* Scenario successful connection to the back end API via basic auth.
*/
@Test
public void shouldFailWithNoSSL() {
endpointProperties.put(BasicAuthOptions.BASIC_USERNAME, "user");
endpointProperties.put(BasicAuthOptions.BASIC_PASSWORD, "user123!");
endpointProperties.put(BasicAuthOptions.BASIC_REQUIRE_SSL, "true");
api.setEndpointProperties(endpointProperties);
api.setEndpoint("http://localhost:8008/echo");
HttpConnectorFactory factory = new HttpConnectorFactory(globalConfig);
IApiConnector connector = factory.createConnector(request, api, RequiredAuthType.BASIC, false);
IApiConnection connection = connector.connect(request,
new IAsyncResultHandler<IApiConnectionResponse>() {
@Override
public void handle(IAsyncResult<IApiConnectionResponse> result) {
Assert.assertTrue("Expected an error due to not using SSL.", result.isError());
Assert.assertTrue("Expected a ConnectorException due to not using SSL.", result.getError() instanceof ConnectorException);
Assert.assertEquals("Endpoint security requested (BASIC auth) but endpoint is not secure (SSL).", result.getError().getMessage());
}
});
if (connection.isConnected()) {
connection.end();
}
}
示例11: shouldFailWithBadCredentials
import io.apiman.gateway.engine.IApiConnection; //導入依賴的package包/類
/**
* Should fail because the credentials provided are not valid/
*/
@Test
public void shouldFailWithBadCredentials() {
endpointProperties.put(BasicAuthOptions.BASIC_USERNAME, "user");
endpointProperties.put(BasicAuthOptions.BASIC_PASSWORD, "bad-password");
endpointProperties.put(BasicAuthOptions.BASIC_REQUIRE_SSL, "false");
api.setEndpointProperties(endpointProperties);
api.setEndpoint("http://localhost:8008/echo");
HttpConnectorFactory factory = new HttpConnectorFactory(globalConfig);
IApiConnector connector = factory.createConnector(request, api, RequiredAuthType.BASIC, false);
IApiConnection connection = connector.connect(request,
new IAsyncResultHandler<IApiConnectionResponse>() {
@Override
public void handle(IAsyncResult<IApiConnectionResponse> result) {
Assert.assertTrue("Expected a successful connection response.", result.isSuccess());
IApiConnectionResponse scr = result.getResult();
Assert.assertEquals("Expected a 401 response from the echo server (invalid creds).", 401, scr.getHead().getCode());
}
});
if (connection.isConnected()) {
connection.end();
}
}
示例12: shouldFailWithNoCredentials
import io.apiman.gateway.engine.IApiConnection; //導入依賴的package包/類
/**
* Should fail because no credentials were provided.
*/
@Test
public void shouldFailWithNoCredentials() {
endpointProperties.remove(BasicAuthOptions.BASIC_USERNAME);
endpointProperties.remove(BasicAuthOptions.BASIC_PASSWORD);
endpointProperties.put(BasicAuthOptions.BASIC_REQUIRE_SSL, "false");
api.setEndpointProperties(endpointProperties);
api.setEndpoint("http://localhost:8008/echo");
HttpConnectorFactory factory = new HttpConnectorFactory(globalConfig);
IApiConnector connector = factory.createConnector(request, api, RequiredAuthType.BASIC, false);
IApiConnection connection = connector.connect(request,
new IAsyncResultHandler<IApiConnectionResponse>() {
@Override
public void handle(IAsyncResult<IApiConnectionResponse> result) {
Assert.assertTrue("Expected a successful connection response.", result.isSuccess());
IApiConnectionResponse scr = result.getResult();
Assert.assertEquals("Expected a 401 response from the echo server (invalid creds).", 401, scr.getHead().getCode());
}
});
if (connection.isConnected()) {
connection.end();
}
}
示例13: createConnector
import io.apiman.gateway.engine.IApiConnection; //導入依賴的package包/類
@Override
public IApiConnector createConnector() {
return new IApiConnector() {
@Override
public IApiConnection connect(ApiRequest request, IAsyncResultHandler<IApiConnectionResponse> handler) throws ConnectorException {
return new ShortcircuitServiceConnection(handler);
}
};
}
示例14: shouldSucceedWithValidMTLS
import io.apiman.gateway.engine.IApiConnection; //導入依賴的package包/類
/**
* Scenario:
* - no CA inherited trust
* - gateway trusts API certificate directly
* - API trusts gateway certificate directly
*/
@Test
public void shouldSucceedWithValidMTLS() {
config.put(TLSOptions.TLS_TRUSTSTORE, getResourcePath("2waytest/basic_mutual_auth_2/gateway_ts.jks"));
config.put(TLSOptions.TLS_TRUSTSTOREPASSWORD, "password");
config.put(TLSOptions.TLS_KEYSTORE, getResourcePath("2waytest/basic_mutual_auth_2/gateway_ks.jks"));
config.put(TLSOptions.TLS_KEYSTOREPASSWORD, "password");
config.put(TLSOptions.TLS_KEYPASSWORD, "password");
config.put(TLSOptions.TLS_ALLOWANYHOST, "true");
config.put(TLSOptions.TLS_ALLOWSELFSIGNED, "false");
HttpConnectorFactory factory = new HttpConnectorFactory(config);
IApiConnector connector = factory.createConnector(request, api, RequiredAuthType.MTLS, false);
IApiConnection connection = connector.connect(request,
new IAsyncResultHandler<IApiConnectionResponse>() {
@Override
public void handle(IAsyncResult<IApiConnectionResponse> result) {
if (result.isError())
throw new RuntimeException(result.getError());
Assert.assertTrue(result.isSuccess());
}
});
connection.end();
}
示例15: shouldFailWhenGatewayDoesNotTrustApi
import io.apiman.gateway.engine.IApiConnection; //導入依賴的package包/類
/**
* Scenario:
* - no CA inherited trust
* - gateway does <em>not</em> trust the API
* - API trusts gateway certificate
*/
@Test
public void shouldFailWhenGatewayDoesNotTrustApi() {
config.put(TLSOptions.TLS_TRUSTSTORE, getResourcePath("2waytest/basic_mutual_auth/gateway_ts.jks"));
config.put(TLSOptions.TLS_TRUSTSTOREPASSWORD, "password");
config.put(TLSOptions.TLS_KEYSTORE, getResourcePath("2waytest/basic_mutual_auth/gateway_ks.jks"));
config.put(TLSOptions.TLS_KEYSTOREPASSWORD, "password");
config.put(TLSOptions.TLS_KEYPASSWORD, "password");
config.put(TLSOptions.TLS_ALLOWANYHOST, "true");
config.put(TLSOptions.TLS_ALLOWSELFSIGNED, "false");
HttpConnectorFactory factory = new HttpConnectorFactory(config);
IApiConnector connector = factory.createConnector(request, api, RequiredAuthType.MTLS, false);
IApiConnection connection = connector.connect(request,
new IAsyncResultHandler<IApiConnectionResponse>() {
@Override
public void handle(IAsyncResult<IApiConnectionResponse> result) {
Assert.assertTrue(result.isError());
System.out.println(result.getError());
Assert.assertTrue(result.getError() instanceof ConnectorException);
// Would like to assert on SSL error, but is sun specific info
// TODO improve connector to handle this situation better
}
});
connection.end();
}