@@ -0,0 +1,2872 @@
+/*%0A * Copyright 2012-2014 MarkLogic Corporation%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *    http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0Apackage com.marklogic.client.test;%0A%0Aimport static org.junit.Assert.assertEquals;%0A%0Aimport javax.net.ssl.SSLContext;%0Aimport javax.net.ssl.TrustManager;%0Aimport javax.net.ssl.X509TrustManager;%0Aimport java.security.KeyManagementException;%0Aimport java.security.NoSuchAlgorithmException;%0Aimport java.security.cert.X509Certificate;%0A%0Aimport org.junit.Test;%0A%0Aimport com.marklogic.client.DatabaseClient;%0Aimport com.marklogic.client.DatabaseClientFactory;%0Aimport com.marklogic.client.DatabaseClientFactory.Authentication;%0Aimport com.marklogic.client.DatabaseClientFactory.SSLHostnameVerifier;%0Aimport com.marklogic.client.document.TextDocumentManager;%0Aimport com.marklogic.client.io.StringHandle;%0A%0Apublic class SSLTest %7B%0A    @Test%0A    public void testSSLAuth() throws NoSuchAlgorithmException, KeyManagementException %7B%0A%0A%09%09// create a trust manager%0A%09%09// (note: a real application should verify certificates)%0A%09%09TrustManager naiveTrustMgr = new X509TrustManager() %7B%0A%09%09%09@Override%0A%09%09%09public void checkClientTrusted(X509Certificate%5B%5D chain, String authType) %7B%0A%09%09%09%7D%0A%09%09%09@Override%0A%09%09%09public void checkServerTrusted(X509Certificate%5B%5D chain, String authType) %7B%0A%09%09%09%7D%0A%09%09%09@Override%0A%09%09%09public X509Certificate%5B%5D getAcceptedIssuers() %7B%0A%09%09%09%09return new X509Certificate%5B0%5D;%0A%09%09%09%7D%0A%09%09%7D;%0A%0A        // create an SSL context%0A        SSLContext sslContext = SSLContext.getInstance(%22SSLv3%22);%0A        sslContext.init(null, new TrustManager%5B%5D %7B naiveTrustMgr %7D, null);%0A%0A        // create the client%0A        DatabaseClient client = DatabaseClientFactory.newClient(%22localhost%22, 8012, %22MyFooUser%22, %22x%22, Authentication.DIGEST, sslContext, SSLHostnameVerifier.ANY);%0A%0A%0A        String expectedException = %22FailedRequestException: Local message: write failed: Unauthorized%22;%0A        String exception = %22%22;%0A%0A        // write doc%0A        try%0A        %7B%0A            // make use of the client connection%0A            TextDocumentManager docMgr = client.newTextDocumentManager();%0A            String docId = %22/example/text.txt%22;%0A            StringHandle handle = new StringHandle();%0A            handle.set(%22A simple text document%22);%0A            docMgr.write(docId, handle);%0A        %7D%0A        catch (Exception e) %7B%0A            exception = e.toString();%0A        %7D%0A        assertEquals(expectedException, exception);%0A%0A    %7D%0A%7D%0A

fix #4 since my logic in InvalidUserTest.java needed fixing to actually run the assert; also added SSLTest.java for additional validation