0

Hi i what to do a programmatic configuration of repository, because most of the parameter for configuration in repository can only determine in run time.

Seems like i am unable to use anonymous credential when im try to print the session it throws NPE code below

   config.repositorySource("store")
          .usingClass(DiskSource.class)
          .setProperty("repositoryRootPath", "c:/x/repo1")
          .setProperty("defaultWorkspaceName","default");

          config.repository("content")
          .setOption(JcrRepository.Option.USE_ANONYMOUS_ACCESS_ON_FAILED_LOGIN, "true")
          .setSource("store");

    Session session  =  engine.getRepository("content").login("default");

Can I add Custom authenticator to JcrConfiguration?

1 Answers1

0

The correct way to configure a ModeShape engine is to use the JcrConfiguration object, as described here. This appears to be what you're doing, so that part is right.

Once you've created your configuration, you can check it for problems:

if ( !configuration.getProblems().isEmpty() ) {
    for ( Problem problem : configuration.getProblems() ) {
         // Report these problems!
    }
}

Assuming there are no problems, you can then use your configuration to create a new JcrEngine instance (see documentation):

JcrConfiguration config = ...
JcrEngine engine = config.build();
engine.start();

Then, look up your repository by its name and log in using the JCR API:

javax.jcr.Repository repository = engine.getRepository("Name of repository");

Credentials credentials = ...; // JCR credentials
String workspaceName = ...;  // Name of repository workspace
Session session = repository.login(credentials,workspaceName);
Randall Hauch
  • 7,069
  • 31
  • 28