Пример #1
0
  @Test
  public void shouldAllowSettingUpConfigurationRepositoryWithAuthenticationProviders()
      throws Exception {
    InMemoryRepositorySource configSource = new InMemoryRepositorySource();
    configSource.setName("config2");
    configSource.setRetryLimit(5);
    configuration.loadFrom(configSource, "workspaceXYZ");
    configuration
        .repositorySource("Source2")
        .usingClass(InMemoryRepositorySource.class.getName())
        .loadedFromClasspath()
        .setDescription("description")
        .and()
        .repository("JCR Repository")
        .setSource("Source2")
        .setOption(Option.JAAS_LOGIN_CONFIG_NAME, "test")
        .authenticator("customAuth")
        .usingClass("org.modeshape.jcr.security.SecurityContextProvider")
        .loadedFromClasspath()
        .setDescription("customAuth Desc");
    configuration.save();
    // Save the configuration and start the engine ...
    engine = configuration.build();
    engine.start();

    ConfigurationDefinition configDefn = configuration.getConfigurationDefinition();
    assertThat(configDefn.getWorkspace(), is("workspaceXYZ"));
    assertThat(configDefn.getPath(), is(path("/")));

    // Get a graph to the configuration source ...
    RepositorySource configReposSource =
        engine.getRepositoryService().getRepositoryLibrary().getSource("config2");
    assertThat(configReposSource, is(notNullValue()));
    assertThat(configReposSource, is(instanceOf(InMemoryRepositorySource.class)));
    assertThat(configReposSource.getName(), is("config2"));
    InMemoryRepositorySource configSource2 = (InMemoryRepositorySource) configReposSource;
    assertThat(configSource2.getDefaultWorkspaceName(), is("")); // didn't change this

    Graph graph = engine.getGraph("config2");
    assertThat(graph, is(notNullValue()));
    assertThat(graph.getNodeAt("/"), is(notNullValue()));
    assertThat(graph.getNodeAt("/mode:sources"), is(notNullValue()));
    assertThat(
        graph.getNodeAt("/mode:sources/Source2"),
        hasProperty(ModeShapeLexicon.DESCRIPTION, "description"));
    assertThat(
        graph.getNodeAt("/mode:repositories/JCR Repository"),
        hasProperty(ModeShapeLexicon.SOURCE_NAME, "Source2"));
    assertThat(
        graph.getNodeAt("/mode:repositories/JCR Repository/mode:authenticationProviders"),
        is(notNullValue()));

    // Get the repository ...
    JcrRepository repository = engine.getRepository("JCR Repository");
    assertThat(repository, is(notNullValue()));
  }
Пример #2
0
  @Test
  public void shouldAllowSettingUpConfigurationRepositoryWithDifferentConfigurationSourceName()
      throws Exception {
    configuration
        .repositorySource("Source2")
        .usingClass(InMemoryRepositorySource.class.getName())
        .loadedFromClasspath()
        .setDescription("description")
        .and()
        .repository("JCR Repository")
        .setSource("Source2")
        .setOption(Option.JAAS_LOGIN_CONFIG_NAME, "test")
        .and()
        .save();

    // Start the engine ...
    engine = configuration.build();
    engine.start();
    // Get a graph to the configuration source ...
    RepositorySource configReposSource =
        engine
            .getRepositoryService()
            .getRepositoryLibrary()
            .getSource(JcrConfiguration.DEFAULT_CONFIGURATION_SOURCE_NAME);
    assertThat(configReposSource, is(notNullValue()));
    assertThat(configReposSource, is(instanceOf(InMemoryRepositorySource.class)));
    assertThat(configReposSource.getName(), is(JcrConfiguration.DEFAULT_CONFIGURATION_SOURCE_NAME));
    InMemoryRepositorySource configSource = (InMemoryRepositorySource) configReposSource;
    assertThat(configSource.getDefaultWorkspaceName(), is(JcrConfiguration.DEFAULT_WORKSPACE_NAME));
    Graph graph = engine.getGraph(JcrConfiguration.DEFAULT_CONFIGURATION_SOURCE_NAME);
    assertThat(graph, is(notNullValue()));
    assertThat(graph.getNodeAt("/"), is(notNullValue()));
    assertThat(graph.getNodeAt("/mode:sources"), is(notNullValue()));
    assertThat(
        graph.getNodeAt("/mode:sources/Source2"),
        hasProperty(ModeShapeLexicon.DESCRIPTION, "description"));
    assertThat(
        graph.getNodeAt("/mode:repositories/JCR Repository"),
        hasProperty(ModeShapeLexicon.SOURCE_NAME, "Source2"));

    // Get the repository ...
    JcrRepository repository = engine.getRepository("JCR Repository");
    assertThat(repository, is(notNullValue()));
  }