jayway/rest-assured — pull request #14 by theon (2013-04-23 10:13:39+00:00)
Title: Issue 205 - Fix bug where CertAuthScheme was removing any existing TrustStore

Hi,

We were facing [Issue 205](https://code.google.com/p/rest-assured/issues/detail?id=205) and have made the following change to resolve this issue.

#### Problem

_I need to use `CertAuthScheme` to set a keystore with client certs to authenticate myself, but also need to set a truststore to define which servers I trust._

Setting a truststore by calling either `RestAssured.keystore()` or `reqSpecBuilder.setkeystore()` calls [schemeRegistry.register(scheme)](https://github.com/jayway/rest-assured/blob/master/rest-assured/src/main/groovy/com/jayway/restassured/internal/KeystoreSpecImpl.groovy#L54) which removes the certs setup by `AuthConfig` which also calls [schemeRegistry.register(scheme)](https://github.com/jayway/rest-assured/blob/master/rest-assured/src/main/java/com/jayway/restassured/internal/http/AuthConfig.java#L101)

#### Solution

I was hoping that `SchemeRegistry` would allow us to get the `KeyStore` and `TrustStore` previously set and amend them, however I couldn't find a way to do this.

Instead, `CertAuthScheme` now is able to access the TrustStore, if one has been configured via `RestAssured.keystore()` or `reqSpecBuilder.setkeystore()` and adds both this TrustStore and the client cert.

Authentication now happens after setting truststore so `KeystoreSpecImpl` doesn't whack the client certs.

I've also externalised the port and cert type, but they still default to `443` and `KeyStore.getDefaultType()` for backwards compatibility.

#### Usage

This code now works as expected

RequestSpecBuilder request = ...
request.setKeystore("truststore.jks", "password");

CertAuthScheme scheme = new CertAuthScheme();
scheme.setCertURL("clientcert.p12");
scheme.setCertType("pkcs12");
scheme.setPassword("password");
scheme.setPort(8443);
request.setAuthentication(scheme);