Search in sources :

Example 6 with RepositoryService

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

the class RepositoryStubImpl method getRepository.

@Override
public synchronized Repository getRepository() throws RepositoryStubException {
    if (repository == null) {
        try {
            String url = environment.getProperty(PROP_REPOSITORY_URL);
            final RepositoryService service = createService(url);
            repository = RepositoryImpl.create(new AbstractRepositoryConfig() {

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

Example 7 with RepositoryService

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

the class ConnectionTest method testObtainWithoutTLS.

public void testObtainWithoutTLS() throws RepositoryException, URISyntaxException {
    RepositoryService repositoryService = createRepositoryService(false, null);
    repositoryService.obtain(new SimpleCredentials("admin", "admin".toCharArray()), null);
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) RepositoryService(org.apache.jackrabbit.spi.RepositoryService)

Example 8 with RepositoryService

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

the class ConnectionTest method testObtainWithTLSSelfSignedCertNotAllowed.

public void testObtainWithTLSSelfSignedCertNotAllowed() throws RepositoryException, URISyntaxException {
    RepositoryService repositoryService = createRepositoryService(true, null);
    try {
        repositoryService.obtain(new SimpleCredentials("admin", "admin".toCharArray()), null);
        fail("should have failed with CertPathBuilderException!");
    } catch (RepositoryException e) {
        Throwable cause = ExceptionUtils.getRootCause(e);
        if (!(cause instanceof CertPathBuilderException)) {
            fail("should have failed with CertPathBuilderException but got " + e.getCause());
        }
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) CertPathBuilderException(java.security.cert.CertPathBuilderException) RepositoryException(javax.jcr.RepositoryException) RepositoryService(org.apache.jackrabbit.spi.RepositoryService)

Example 9 with RepositoryService

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

the class ConnectionTest method testObtainWithTLSSelfSignedCertAllowedAndHostnameVerificationDisabled.

public void testObtainWithTLSSelfSignedCertAllowedAndHostnameVerificationDisabled() throws RepositoryException, URISyntaxException {
    Map<String, String> parameters = new HashMap<>();
    ConnectionOptions.Builder builder = ConnectionOptions.builder();
    builder.allowSelfSignedCertificates(true);
    builder.disableHostnameVerification(true);
    parameters.putAll(builder.build().toServiceFactoryParameters());
    RepositoryService repositoryService = createRepositoryService(true, parameters);
    repositoryService.obtain(new SimpleCredentials("admin", "admin".toCharArray()), null);
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) HashMap(java.util.HashMap) RepositoryService(org.apache.jackrabbit.spi.RepositoryService)

Example 10 with RepositoryService

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

the class ConnectionTest method testObtainViaProxyWithValidCredentials.

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

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

        @Override
        public boolean authenticate(String userName, String password) {
            if (userName.equals("test") && password.equals("valid")) {
                return true;
            }
            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("valid");
        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) ProxyAuthenticator(org.littleshoot.proxy.ProxyAuthenticator) HashMap(java.util.HashMap) 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