【问题标题】:Modeshape 2.8 programmatic configurationModeshape 2.8 编程配置
【发布时间】:2012-10-04 18:11:25
【问题描述】:

你好,我要如何对存储库进行编程配置,因为存储库中的大部分配置参数只能在运行时确定。

当我尝试打印它抛出 NPE 的会话时,我似乎无法使用匿名凭据 代码如下

   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");

我可以将自定义身份验证器添加到 JcrConfiguration 吗?

【问题讨论】:

  • NullPointerException 的堆栈跟踪是什么?

标签: authentication configuration jcr modeshape


【解决方案1】:

配置 ModeShape 引擎的正确方法是使用 JcrConfiguration 对象,如here 所述。这似乎是你正在做的,所以那部分是正确的。

创建配置后,您可以检查它是否存在问题:

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

假设没有问题,您可以使用您的配置创建一个新的 JcrEngine 实例(参见documentation):

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

然后,按名称查找您的存储库并使用 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,感谢您的快速响应是否有一种编程方式来验证身份
猜你喜欢
  • 1970-01-01
  • 2013-04-24
  • 1970-01-01
  • 1970-01-01
  • 2011-04-09
  • 1970-01-01
  • 2012-08-23
  • 1970-01-01
  • 2016-04-16
相关资源
最近更新 更多