Skip to content

ibanity/ibanity-java

Repository files navigation

Java wrapper for the Ibanity API

Maven Central Build Status License Maintainability Security Reliability

This Java Client library offers various Services you can use in order to submit requests towards the Ibanity Platform.

Quick start

Configure the library using IbanityServiceBuilder.builder().

Minimal configuration values are:

  • The ibanity url
  • Your application private key
  • the passphrase for the private key
  • the application public certificate
    IbanityService ibanityServiceBuilder = IbanityServiceBuilder.builder()
            .ibanityApiEndpoint("https://api.ibanity.com")
            .tlsPrivateKey(myPrivateKey)
            .passphrase("aPassphrase")
            .tlsCertificate(myCertificate)
            .build();

You can then make use of Xs2a services through your IbanityService instance.

CustomerAccessTokenService customerAccessTokensService = ibanityService.xs2aService().customerAccessTokensService();

All services are thread safe and can be configured as singleton if you want to leverage frameworks like Spring.

See ClientSample class for extended examples.

Perform custom request to Ibanity

You can perform custom http calls to Ibanity using the IbanityHttpClient. It can be accessed by calling :

IbanityHttpClient ibanityHttpClient = ibanityService.ibanityHttpClient();

Configure proxy

If you are using a Web application firewall or a proxy, you can configure it in the IbanityServiceBuilder.

public interface OptionalPropertiesBuilder {

...

    OptionalPropertiesBuilder proxyEndpoint(String proxyEndpoint);

}
    IbanityService ibanityServiceBuilder = IbanityServiceBuilder.builder()
            .ibanityApiEndpoint("https://api.ibanity.com")
            .tlsPrivateKey(myPrivateKey)
            .passphrase("aPassphrase")
            .tlsCertificate(myCertificate)
            .proxyEndpoint("https://interal.proxy.com")
            .build();

Use HttpSignatureService

If you want to sign http request, you can use the HttpSignatureService from the library.

Instantiate the implementation class by calling:

IbanityHttpSignatureService = new IbanityHttpSignatureServiceImpl(
                                              privateKey,
                                              certificate,
                                              certificateId);
    public interface IbanityHttpSignatureService {
    
        /**
         * Alias to be used when the request has no payload.
         * @see IbanityHttpSignatureService#getHttpSignatureHeaders(String, URL, Map, String)
         * Allows you to create the needed headers to sign an http request following draft http signature
         * @see <a href="https://tools.ietf.org/html/draft-cavage-http-signatures-09">https://tools.ietf.org/html/draft-cavage-http-signatures-09</a>
         * @param httpMethod the http method of the current request.
         * @param url the url containing host, path and query parameters.
         * @param requestHeaders the headers of the current request. All ibanity-* headers will included in the signature.
         * @return the map with signature related headers: date, digest and signature headers.
         */
        Map<String, String> getHttpSignatureHeaders(String httpMethod, URL url, Map<String, String> requestHeaders);
    
        /**
         * Allows you to create the needed headers to sign an http request following draft http signature
         * @see <a href="https://tools.ietf.org/html/draft-cavage-http-signatures-09">https://tools.ietf.org/html/draft-cavage-http-signatures-09</a>
         * @param httpMethod the http method of the current request.
         * @param url the url containing host, path and query parameters.
         * @param requestHeaders the headers of the current request. All ibanity-* headers will included in the signature.
         * @param payload the payload of the actual request.
         * @return the map with signature related headers: date, digest and signature headers.
         */
        Map<String, String> getHttpSignatureHeaders(String httpMethod, URL url, Map<String, String> requestHeaders, String payload);

        /**
         * Allows you to create the needed headers to sign an http request following draft http signature
         * @see <a href="https://tools.ietf.org/html/draft-cavage-http-signatures-12">https://tools.ietf.org/html/draft-cavage-http-signatures-12</a>
         * @param httpMethod the http method of the current request.
         * @param url the url containing host, path and query parameters.
         * @param requestHeaders the headers of the current request. All ibanity-* headers will included in the signature.
         * @param payload the payload of the actual request as {@link java.io.File}.
         * @return the map with signature related headers: date, digest and signature headers.
         */
        Map<String, String> getHttpSignatureHeaders(String httpMethod, URL url, Map<String, String> requestHeaders, File payload);
    }

Add custom Http Interceptors

The library uses Apache HttpClient.

You can add your own HttpRequestInterceptor and HttpResponseInterceptor.

Configuring custom interceptors can be done through the IbanityServiceBuilder. They are optional.

public interface OptionalPropertiesBuilder {

...

    OptionalPropertiesBuilder withHttpRequestInterceptors(HttpRequestInterceptor... httpRequestInterceptor);

    OptionalPropertiesBuilder withHttpResponseInterceptors(HttpResponseInterceptor... httpResponseInterceptor);
}
        OptionalPropertiesBuilder ibanityServiceBuilder = IbanityServiceBuilder.builder()
                .ibanityApiEndpoint("https://api.ibanity.com")
                .tlsPrivateKey(privateKey)
                .passphrase(passphrase)
                .tlsCertificate(certificate)
                .withHttpRequestInterceptors((request, context) -> LOGGER.info("This is a HttpRequestInterceptor"))
                .withHttpResponseInterceptors((response, context) -> LOGGER.info("This is a HttpResponseInterceptor"));

Configure Http timeouts

The following Http timeouts can be configured

  • Connect Timeout (default 30 000 milliseconds)
  • Socket Timeout (default 30 000 milliseconds)
  • Connection Request Timeout (default 30 000 milliseconds)
public interface OptionalPropertiesBuilder {

...

    OptionalPropertiesBuilder socketTimeout(int socketTimeout);

    OptionalPropertiesBuilder connectTimeout(int connectTimeout);

    OptionalPropertiesBuilder connectionRequestTimeout(int connectionRequestTimeout);
}
        OptionalPropertiesBuilder ibanityServiceBuilder = IbanityServiceBuilder.builder()
                .ibanityApiEndpoint("https://api.ibanity.com")
                .tlsPrivateKey(privateKey)
                .passphrase(passphrase)
                .tlsCertificate(certificate)
                .connectTimeout(10_000)
                .socketTimeout(60_000)
                .connectionRequestTimeout(10_000);

Requirements

  • Java 8 (or above)
  • Maven (for compilation)

JCE Unlimited Strength Jurisdiction Policy Files

https://golb.hplar.ch/2017/10/JCE-policy-changes-in-Java-SE-8u151-and-8u152.html