Search in sources :

Example 1 with RepositoryService

use of org.apache.jackrabbit.spi.RepositoryService in project jackrabbit by apache.

the class ConnectionTest method testObtainInvalidURIWithConnectionTimeout.

public void testObtainInvalidURIWithConnectionTimeout() throws URISyntaxException, RepositoryException {
    // make sure it takes long enough before a timeout is happening
    Map<String, String> parameters = new HashMap<>();
    ConnectionOptions.Builder builder = ConnectionOptions.builder();
    int connectionTimeoutMs = 1000;
    builder.connectionTimeoutMs(connectionTimeoutMs);
    parameters.putAll(builder.build().toServiceFactoryParameters());
    // overwrite URI (use non-routable IP to run into connection timeout)
    parameters.put(Spi2davexRepositoryServiceFactory.PARAM_REPOSITORY_URI, "http://10.0.0.0");
    RepositoryService repositoryService = createRepositoryService(true, parameters);
    long beforeTimeMs = System.currentTimeMillis();
    try {
        repositoryService.obtain(new SimpleCredentials("admin", "admin".toCharArray()), null);
        fail("Should have run into a connect exception");
    } catch (RepositoryException e) {
        if (!(e.getCause() instanceof ConnectTimeoutException)) {
            fail("Expected a connect timeout but received " + e);
        }
    }
    long afterTimeMs = System.currentTimeMillis();
    assertTrue("Have not waited long enough!", afterTimeMs - beforeTimeMs >= connectionTimeoutMs);
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) HashMap(java.util.HashMap) RepositoryException(javax.jcr.RepositoryException) RepositoryService(org.apache.jackrabbit.spi.RepositoryService) ConnectTimeoutException(org.apache.http.conn.ConnectTimeoutException)

Example 2 with RepositoryService

use of org.apache.jackrabbit.spi.RepositoryService in project jackrabbit by apache.

the class ConnectionTest method testObtainWithTLSSelfSignedCertAllowed.

public void testObtainWithTLSSelfSignedCertAllowed() throws RepositoryException, URISyntaxException {
    Map<String, String> parameters = new HashMap<>();
    ConnectionOptions.Builder builder = ConnectionOptions.builder();
    builder.allowSelfSignedCertificates(true);
    parameters.putAll(builder.build().toServiceFactoryParameters());
    RepositoryService repositoryService = createRepositoryService(true, parameters);
    try {
        repositoryService.obtain(new SimpleCredentials("admin", "admin".toCharArray()), null);
    } catch (RepositoryException e) {
        Throwable cause = ExceptionUtils.getRootCause(e);
        if (!(cause instanceof SSLPeerUnverifiedException)) {
            fail("should have failed with SSLPeerUnverifiedException but got " + e.getCause());
        }
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) HashMap(java.util.HashMap) SSLPeerUnverifiedException(javax.net.ssl.SSLPeerUnverifiedException) RepositoryException(javax.jcr.RepositoryException) RepositoryService(org.apache.jackrabbit.spi.RepositoryService)

Example 3 with RepositoryService

use of org.apache.jackrabbit.spi.RepositoryService in project jackrabbit by apache.

the class ConnectionTest method testObtainViaProxy.

public void testObtainViaProxy() throws URISyntaxException, RepositoryException {
    HttpProxyServer proxyServer = DefaultHttpProxyServer.bootstrap().withPort(// use arbitrary port
    0).start();
    try {
        Map<String, String> parameters = new HashMap<>();
        ConnectionOptions.Builder builder = ConnectionOptions.builder();
        builder.proxyHost("127.0.0.1");
        builder.proxyPort(proxyServer.getListenAddress().getPort());
        parameters.putAll(builder.build().toServiceFactoryParameters());
        RepositoryService repositoryService = createRepositoryService(false, parameters);
        repositoryService.obtain(new SimpleCredentials("admin", "admin".toCharArray()), null);
    } finally {
        proxyServer.stop();
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) HttpProxyServer(org.littleshoot.proxy.HttpProxyServer) DefaultHttpProxyServer(org.littleshoot.proxy.impl.DefaultHttpProxyServer) HashMap(java.util.HashMap) RepositoryService(org.apache.jackrabbit.spi.RepositoryService)

Example 4 with RepositoryService

use of org.apache.jackrabbit.spi.RepositoryService in project jackrabbit by apache.

the class ConnectionTest method testObtainViaProxyWithInvalidCredentials.

public void testObtainViaProxyWithInvalidCredentials() throws URISyntaxException, RepositoryException {
    ProxyAuthenticator authenticator = new ProxyAuthenticator() {

        @Override
        public String getRealm() {
            return null;
        }

        @Override
        public boolean authenticate(String userName, String password) {
            return false;
        }
    };
    HttpProxyServer proxyServer = DefaultHttpProxyServer.bootstrap().withPort(// use arbitrary port
    0).withProxyAuthenticator(authenticator).start();
    try {
        Map<String, String> parameters = new HashMap<>();
        ConnectionOptions.Builder builder = ConnectionOptions.builder();
        builder.proxyHost("127.0.0.1");
        builder.proxyPort(proxyServer.getListenAddress().getPort());
        builder.proxyUsername("test");
        builder.proxyPassword("invalid");
        parameters.putAll(builder.build().toServiceFactoryParameters());
        RepositoryService repositoryService = createRepositoryService(false, parameters);
        try {
            repositoryService.obtain(new SimpleCredentials("admin", "admin".toCharArray()), null);
            fail("should have failed with proxy authentication failure!");
        } catch (RepositoryException expected) {
        }
    } finally {
        proxyServer.stop();
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) HttpProxyServer(org.littleshoot.proxy.HttpProxyServer) DefaultHttpProxyServer(org.littleshoot.proxy.impl.DefaultHttpProxyServer) ProxyAuthenticator(org.littleshoot.proxy.ProxyAuthenticator) HashMap(java.util.HashMap) RepositoryException(javax.jcr.RepositoryException) RepositoryService(org.apache.jackrabbit.spi.RepositoryService)

Example 5 with RepositoryService

use of org.apache.jackrabbit.spi.RepositoryService in project jackrabbit by apache.

the class RepositoryStubImpl method getRepository.

/**
 * @return the repository instance to test.
 * @throws RepositoryStubException if an error occurs while starting up the
 *                                 repository.
 */
public Repository getRepository() throws RepositoryStubException {
    if (repo == null) {
        try {
            final RepositoryService service = getRepositoryService();
            repo = RepositoryImpl.create(new AbstractRepositoryConfig() {

                public RepositoryService getRepositoryService() {
                    return service;
                }
            });
        } catch (RepositoryException e) {
            throw new RepositoryStubException(e);
        }
    }
    return repo;
}
Also used : RepositoryException(javax.jcr.RepositoryException) RepositoryStubException(org.apache.jackrabbit.test.RepositoryStubException) AbstractRepositoryConfig(org.apache.jackrabbit.jcr2spi.AbstractRepositoryConfig) RepositoryService(org.apache.jackrabbit.spi.RepositoryService)

Aggregations

RepositoryService (org.apache.jackrabbit.spi.RepositoryService)10 SimpleCredentials (javax.jcr.SimpleCredentials)8 HashMap (java.util.HashMap)6 RepositoryException (javax.jcr.RepositoryException)6 HttpProxyServer (org.littleshoot.proxy.HttpProxyServer)3 DefaultHttpProxyServer (org.littleshoot.proxy.impl.DefaultHttpProxyServer)3 AbstractRepositoryConfig (org.apache.jackrabbit.jcr2spi.AbstractRepositoryConfig)2 RepositoryStubException (org.apache.jackrabbit.test.RepositoryStubException)2 ProxyAuthenticator (org.littleshoot.proxy.ProxyAuthenticator)2 CertPathBuilderException (java.security.cert.CertPathBuilderException)1 SSLPeerUnverifiedException (javax.net.ssl.SSLPeerUnverifiedException)1 ConnectTimeoutException (org.apache.http.conn.ConnectTimeoutException)1 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)1