use of io.apiman.gateway.engine.async.IAsyncResult in project apiman by apiman.
the class LDAPIdentityValidator method handleLdapSearch.
private void handleLdapSearch(final ILdapClientConnection connection, List<ILdapSearchEntry> searchEntries, LDAPIdentitySource config, LdapConfigBean ldapConfigBean, ILdapComponent ldapComponent, IPolicyContext context, String username, String password, final IAsyncResultHandler<Boolean> handler) {
if (searchEntries.size() > 1) {
// $NON-NLS-1$
NamingException ex = new NamingException("Found multiple entries for the same username: " + username);
handler.handle(AsyncResultImpl.<Boolean>create(ex));
} else if (searchEntries.isEmpty()) {
handler.handle(AsyncResultImpl.create(Boolean.FALSE));
} else {
// Just one result
// First entry
String userDn = searchEntries.get(0).getDn();
if (userDn != null) {
ldapConfigBean.setBindDn(userDn);
ldapConfigBean.setBindPassword(password);
bind(config, ldapConfigBean, ldapComponent, context, new IAsyncResultHandler<ILdapResult>() {
@Override
public void handle(IAsyncResult<ILdapResult> result) {
if (result.isError()) {
if (result.getError() instanceof LdapException) {
LdapException ex = (LdapException) result.getError();
if (ex.getResultCode().isAuthFailure()) {
handler.handle(AsyncResultImpl.create(Boolean.FALSE));
} else {
handler.handle(AsyncResultImpl.<Boolean>create(ex));
}
connection.close(ex);
} else {
handler.handle(AsyncResultImpl.<Boolean>create(result.getError()));
connection.close();
}
} else {
LdapResultCode resultCode = result.getResult().getResultCode();
if (LdapResultCode.isSuccess(resultCode)) {
handler.handle(AsyncResultImpl.create(Boolean.TRUE));
} else {
// TODO handle errors better?
handler.handle(AsyncResultImpl.create(Boolean.FALSE));
}
connection.close();
}
}
});
} else {
handler.handle(AsyncResultImpl.create(Boolean.FALSE));
}
}
}
use of io.apiman.gateway.engine.async.IAsyncResult in project apiman by apiman.
the class SimpleSharedStatePolicy method apply.
/**
* @see io.apiman.gateway.engine.policy.IPolicy#apply(io.apiman.gateway.engine.beans.ApiRequest, io.apiman.gateway.engine.policy.IPolicyContext, java.lang.Object, io.apiman.gateway.engine.policy.IPolicyChain)
*/
@Override
public void apply(final ApiRequest request, final IPolicyContext context, final Object config, final IPolicyChain<ApiRequest> chain) {
final ISharedStateComponent sharedState = context.getComponent(ISharedStateComponent.class);
final String namespace = "urn:" + getClass().getName();
final String propName = "test-property";
sharedState.getProperty(namespace, propName, "", new IAsyncResultHandler<String>() {
@Override
public void handle(IAsyncResult<String> result) {
String propVal = result.getResult();
String newVal = propVal + "+";
sharedState.setProperty(namespace, propName, newVal, new IAsyncResultHandler<Void>() {
@Override
public void handle(IAsyncResult<Void> result) {
chain.doApply(request);
}
});
}
});
}
use of io.apiman.gateway.engine.async.IAsyncResult in project apiman by apiman.
the class DefaultPluginRegistry method downloadPlugin.
/**
* Downloads the plugin via its maven GAV information. This will first look in the local
* .m2 directory. If the plugin is not found there, then it will try to download the
* plugin from one of the configured remote maven repositories.
*/
protected void downloadPlugin(final PluginCoordinates coordinates, final IAsyncResultHandler<File> handler) {
if (pluginRepositories.isEmpty()) {
// Didn't find it - no repositories configured!
handler.handle(AsyncResultImpl.create((File) null));
return;
}
final Iterator<URI> iterator = pluginRepositories.iterator();
URI repoUrl = iterator.next();
final IAsyncResultHandler<File> handler2 = new IAsyncResultHandler<File>() {
@Override
public void handle(IAsyncResult<File> result) {
// If result is bad : No success or result empty And other repo exist
if ((!result.isSuccess() || result.getResult() == null) && iterator.hasNext()) {
downloadFromMavenRepo(coordinates, iterator.next(), this);
} else {
// If result is Good or all repo tried
handler.handle(result);
}
}
};
downloadFromMavenRepo(coordinates, repoUrl, handler2);
}
use of io.apiman.gateway.engine.async.IAsyncResult in project apiman by apiman.
the class BasicMutualAuthTest method shouldSucceedWhenAllowedSelfSigned.
/**
* 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, "changeme");
config.put(TLSOptions.TLS_KEYSTORE, getResourcePath("2waytest/basic_mutual_auth/gateway_ks.jks"));
config.put(TLSOptions.TLS_KEYSTOREPASSWORD, "changeme");
config.put(TLSOptions.TLS_KEYPASSWORD, "changeme");
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, new ConnectorConfigImpl());
IApiConnection connection = connector.connect(request, (IAsyncResult<IApiConnectionResponse> result) -> {
Assert.assertTrue(result.isSuccess());
});
connection.end();
}
use of io.apiman.gateway.engine.async.IAsyncResult in project apiman by apiman.
the class BasicMutualAuthTest method shouldFailWhenApiDoesNotTrustGateway.
/**
* Scenario:
* - no CA inherited trust
* - gateway does trust the API
* - API does <em>not</em> trust gateway
*/
@Test
public void shouldFailWhenApiDoesNotTrustGateway() {
config.put(TLSOptions.TLS_TRUSTSTORE, getResourcePath("2waytest/service_not_trust_gw/gateway_ts.jks"));
config.put(TLSOptions.TLS_TRUSTSTOREPASSWORD, "changeme");
config.put(TLSOptions.TLS_KEYSTORE, getResourcePath("2waytest/service_not_trust_gw/gateway_ks.jks"));
config.put(TLSOptions.TLS_KEYSTOREPASSWORD, "changeme");
config.put(TLSOptions.TLS_KEYPASSWORD, "changeme");
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, new ConnectorConfigImpl());
IApiConnection connection = connector.connect(request, (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();
}
Aggregations