Hi Konrad,

Thanks a lot for showing me the pointers.

I have written code to disable cert check while fetching repository via
https url.

My code is like below


package org.example;

import javax.jcr.Repository;
import java.io.OutputStreamWriter;
import java.io.File;
import org.apache.jackrabbit.rmi.repository.URLRemoteRepository;
//import org.apache.jackrabbit.commons.JcrUtils;
import javax.jcr.Session;
import javax.jcr.SimpleCredentials;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.*;
import javax.jcr.NamespaceException;
import org.apache.jackrabbit.vault.fs.api.RepositoryAddress;
import org.apache.jackrabbit.spi2dav.ConnectionOptions.Builder;
import org.apache.jackrabbit.spi2dav.ConnectionOptions;
import org.apache.jackrabbit.spi2davex.Spi2davexRepositoryServiceFactory;
import org.apache.jackrabbit.jcr2spi.Jcr2spiRepositoryFactory;
import javax.jcr.RepositoryException;
import org.apache.jackrabbit.spi.commons.logging.WriterLogWriterProvider;
import org.apache.jackrabbit.spi2davex.BatchReadConfig;
import org.apache.jackrabbit.client.RepositoryFactoryImpl;
import org.apache.commons.io.FileUtils;
import org.apache.jackrabbit.spi.Path;
import org.apache.jackrabbit.spi.commons.conversion.PathResolver;


public class Main {

    private static final Set<String> SCHEMES = new HashSet<String>();
    static {
        SCHEMES.add("http");
        SCHEMES.add("https");
    }
    public static final String PARAM_JCR_REMOTING_DEPTH = "jcr.remoting.depth";

    /**
     * Name of the system property that controls the spi log.
     */
    public static final String PARAM_JCR_REMOTING_SPILOG =
"jcr.remoting.spilog";


    public static void main(String[] args) {


    try {
        RepositoryAddress address = new
RepositoryAddress("https://my-server:46443/jackrabbit-webapp-2.20.6/rmi";);

        Repository repository = getRepository(address);
        Session session = repository.login(new
SimpleCredentials("admin","admin".toCharArray()));

    }
    catch(Exception e){
        e.printStackTrace();
    }
    }

    public static Repository getRepository(RepositoryAddress address)
throws RepositoryException {
        if (!SCHEMES.contains(address.getSpecificURI().getScheme())) {
            return null;
        }
        try {
            // get uri without credentials
            URI uri = address.getSpecificURI();
            if (uri.getUserInfo() != null) {
                try {
                    uri = new URI(uri.getScheme(), null,
uri.getHost(), uri.getPort(), uri.getPath(), uri.getQuery(),
uri.getFragment());
                } catch (URISyntaxException e) {
                    // ignore
                }
            }
            Map<String, Object> parameters = new HashMap<String, Object>();
            
parameters.put(Jcr2spiRepositoryFactory.PARAM_REPOSITORY_SERVICE_FACTORY,
Spi2davexRepositoryServiceFactory.class.getName());
            parameters.put(Jcr2spiRepositoryFactory.PARAM_ITEM_CACHE_SIZE,
Integer.getInteger(PARAM_JCR_REMOTING_DEPTH, 128));
            
parameters.put(Spi2davexRepositoryServiceFactory.PARAM_REPOSITORY_URI,
uri.toString());
          DefaultBatchReadConfig br = new DefaultBatchReadConfig();
            br.setDefaultDepth(Integer.getInteger(PARAM_JCR_REMOTING_DEPTH, 4));
            br.setDepth("/", 2);
            br.setDepth("/jcr:system", 1);
            
parameters.put(Spi2davexRepositoryServiceFactory.PARAM_BATCHREAD_CONFIG,
br);
            String file = System.getProperty(PARAM_JCR_REMOTING_SPILOG);
            if (file != null) {
                WriterLogWriterProvider provider = new WriterLogWriterProvider(
                        new
OutputStreamWriter(FileUtils.openOutputStream(new File(file)))
                );
                parameters.put(
                        Jcr2spiRepositoryFactory.PARAM_LOG_WRITER_PROVIDER,
                        provider
                );
            }

            String workspace = address.getWorkspace();
            if (workspace != null) {

parameters.put(Spi2davexRepositoryServiceFactory.PARAM_WORKSPACE_NAME_DEFAULT,
workspace);
            }

            ConnectionOptions.Builder builder = ConnectionOptions.builder();
           /* builder.proxyHost("127.0.0.1");
            builder.proxyPort(8080);
            builder.proxyUsername("test");
            builder.proxyPassword("invalid");*/
            builder.allowSelfSignedCertificates(true);
            builder.disableHostnameVerification(true);

            parameters.putAll(builder.build().toServiceFactoryParameters());


           /* if (connectionOptions != null) {

parameters.putAll(connectionOptions.toServiceFactoryParameters());
            }*/
            System.out.printf("Connecting via JCR remoting to %s%n",
address.getSpecificURI().toString());
            return new RepositoryFactoryImpl().getRepository(parameters);
        } catch (Exception e) {
            throw new RepositoryException(e);
        }
    }


}

class DefaultBatchReadConfig implements BatchReadConfig {

    public static final int DEPTH_INFINITE = -1;

    private final Map<String, Integer> depthMap = new HashMap<String,
Integer>();

    private int defaultDepth = 0;

    public int getDepth(Path path, PathResolver resolver) throws
NamespaceException {
        String jcrPath = resolver.getJCRPath(path);
        Integer depth = depthMap.get(jcrPath);
        return depth == null ? defaultDepth : depth;
    }

    public void setDepth(String path, int depth) {
        depthMap.put(path, depth);
    }

    public void setDefaultDepth(int defaultDepth) {
        this.defaultDepth = defaultDepth;
    }
}


But I am getting below error

PS C:\Users\Praveen\IdeaProjects\mymvnproj> java -cp
target/mymvnproj-1.0-SNAPSHOT.jar org.example.Main
Connecting via JCR remoting to
https://myserver:46443/jackrabbit-webapp-2.20.6
log4j:WARN No appenders could be found for logger
(org.apache.jackrabbit.jcr2spi.Jcr2spiRepositoryFactory).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for
more info.
javax.jcr.RepositoryException:
javax.jcr.nodetype.ConstraintViolationException:
        at org.example.Main.getRepository(Main.java:116)
        at org.example.Main.main(Main.java:51)
Caused by: javax.jcr.nodetype.ConstraintViolationException:
        at
org.apache.jackrabbit.spi2dav.ExceptionConverter.generate(ExceptionConverter.java:106)
        at
org.apache.jackrabbit.spi2dav.ExceptionConverter.generate(ExceptionConverter.java:52)
        at
org.apache.jackrabbit.spi2dav.ExceptionConverter.generate(ExceptionConverter.java:46)
        at
org.apache.jackrabbit.spi2dav.RepositoryServiceImpl.getRepositoryDescriptors(RepositoryServiceImpl.java:809)
        at
org.apache.jackrabbit.jcr2spi.RepositoryImpl.create(RepositoryImpl.java:95)
        at
org.apache.jackrabbit.jcr2spi.Jcr2spiRepositoryFactory.getRepository(Jcr2spiRepositoryFactory.java:163)
        at
org.apache.jackrabbit.client.RepositoryFactoryImpl.getRepository(RepositoryFactoryImpl.java:75)
        at org.example.Main.getRepository(Main.java:114)
        at
org.apache.jackrabbit.jcr2spi.RepositoryImpl.<init>(RepositoryImpl.java:82)
        at
org.apache.jackrabbit.jcr2spi.RepositoryImpl.create(RepositoryImpl.java:95)
        at
org.apache.jackrabbit.jcr2spi.Jcr2spiRepositoryFactory.getRepository(Jcr2spiRepositoryFactory.java:163)
        at
org.apache.jackrabbit.client.RepositoryFactoryImpl.getRepository(RepositoryFactoryImpl.java:75)
        at org.example.Main.getRepository(Main.java:113)
        ... 1 more
Caused by: org.apache.jackrabbit.webdav.DavException:
        at
org.apache.jackrabbit.webdav.client.methods.BaseDavRequest.getResponseException(BaseDavRequest.java:207)
        at
org.apache.jackrabbit.webdav.client.methods.BaseDavRequest.checkSuccess(BaseDavRequest.java:184)
        at
org.apache.jackrabbit.spi2dav.RepositoryServiceImpl.getRepositoryDescriptors(RepositoryServiceImpl.java:780)
        ... 6 more



Please let me know what I am missing in my code.

I just want to disable cert check while getting repository instance.


Thanks
Praveen.











On Thu, Aug 18, 2022 at 11:35 AM Konrad Windszus <konra...@gmx.de> wrote:

> Hi Praveen,
> You should find all necessary information in
> https://github.com/apache/jackrabbit/pull/92/files <
> https://github.com/apache/jackrabbit/pull/92/files> but be aware that you
> need 2.20.2 or newer for it to work (
> https://issues.apache.org/jira/browse/JCR-4536 <
> https://issues.apache.org/jira/browse/JCR-4536>).
>
> An example usage can be found in
> https://github.com/apache/jackrabbit-filevault/blob/0b8a264140b23daf474443e30117bd77a70667de/vault-davex/src/main/java/org/apache/jackrabbit/vault/davex/DAVExRepositoryFactory.java#L115
> <
> https://github.com/apache/jackrabbit-filevault/blob/0b8a264140b23daf474443e30117bd77a70667de/vault-davex/src/main/java/org/apache/jackrabbit/vault/davex/DAVExRepositoryFactory.java#L115
> >
> You have to populate the
> https://jackrabbit.apache.org/api/2.20/org/apache/jackrabbit/spi2dav/ConnectionOptions.html
> <
> https://jackrabbit.apache.org/api/2.20/org/apache/jackrabbit/spi2dav/ConnectionOptions.html>
> first and then call
> https://jackrabbit.apache.org/api/2.20/org/apache/jackrabbit/spi2dav/ConnectionOptions.html#toServiceFactoryParameters--
> <
> https://jackrabbit.apache.org/api/2.20/org/apache/jackrabbit/spi2dav/ConnectionOptions.html#toServiceFactoryParameters--
> >.
> Those parameters you have to pass to the repository factory.
>
> Hope this helps,
> Konrad
>
>
> > On 18. Aug 2022, at 07:53, Praveen Kumar SM <
> praveenkumar0809...@gmail.com> wrote:
> >
> > Hi All,
> >
> > Please let me know how to disable cert check from java code for https
> > jackrabbit url.
> >
> > I tried below approaches but did not work.
> >
> >
> > *java -Dcom.sun.jndi.ldap.object.disableEndpointIdentification=true -cp
> > target/mymvnproj-1.0-SNAPSHOT.jar org.example.Main*
> >
> > *java -Dcom.sun.net.ssl.checkRevocation=false -cp
> > target/mymvnproj-1.0-SNAPSHOT.jar org.example.Main*
> >
> > My code is below,
> >
> > Repository repository = new URLRemoteRepository("
> > https://myhost:8443/jackrabbit-webapp-2.20.6/rmi",verify=False);
> > Session session = repository.login(new
> > SimpleCredentials("admin","admin".toCharArray()));
> >
> > I am getting below exception.
> >
> > javax.jcr.RepositoryException: Remote repository not found: The resource
> at
> > https:// myhost:8443/jackrabbit-webapp-2.20.6/rmi could not be
> retrieved:
> > sun.security.validator.ValidatorException: PKIX path building failed:
> > sun.secur
> > ity.provider.certpath.SunCertPathBuilderException: unable to find valid
> > certification path to requested target:
> > sun.security.validator.ValidatorException: PKIX path building failed:
> > sun.security.provider.certpath.SunCertPathBuilderE
> > xception: unable to find valid certification path to requested target
> >        at
> >
> org.apache.jackrabbit.rmi.repository.URLRemoteRepositoryFactory.getRemoteRepository(URLRemoteRepositoryFactory.java:84)
> >        at
> >
> org.apache.jackrabbit.rmi.repository.AbstractRemoteRepositoryFactory.getRepository(AbstractRemoteRepositoryFactory.java:59)
> >        at
> >
> org.apache.jackrabbit.commons.repository.ProxyRepository.getRepository(ProxyRepository.java:101)
> >        at
> >
> org.apache.jackrabbit.commons.repository.ProxyRepository.login(ProxyRepository.java:198)
> >        at
> >
> org.apache.jackrabbit.commons.AbstractRepository.login(AbstractRepository.java:144)
> >        at org.example.Main.main(Main.java:19)
> > Caused by: javax.net.ssl.SSLHandshakeException:
> > sun.security.validator.ValidatorException: PKIX path building failed:
> > sun.security.provider.certpath.SunCertPathBuilderException: unable to
> find
> > valid certification path to requested t
> > arget
> >        at sun.security.ssl.Alert.createSSLException(Unknown Source)
> >        at sun.security.ssl.TransportContext.fatal(Unknown Source)
> >
> >
> > Thanks
> > Praveen.
>
>

Reply via email to