예제 #1
0
  @Test
  public void shouldAllowAddingRepositorySourceInstance() {
    UUID rootUuid = UUID.randomUUID();
    CachePolicy cachePolicy = new ImmutableCachePolicy(100);

    // Update the configuration and save it ...
    configuration
        .repositorySource("name")
        .usingClass(InMemoryRepositorySource.class)
        .setRetryLimit(100)
        .setProperty("defaultCachePolicy", cachePolicy)
        .setProperty("defaultWorkspaceName", "default workspace name")
        .setProperty("rootNodeUuid", rootUuid)
        .and()
        .save();

    // Verify that the graph has been updated correctly ...
    ModeShapeConfiguration.ConfigurationDefinition content =
        configuration.getConfigurationDefinition();
    Subgraph subgraph = content.graph().getSubgraphOfDepth(3).at("/");
    assertThat(subgraph.getNode("/mode:sources"), is(notNullValue()));
    assertThat(subgraph.getNode("/mode:sources/name"), is(notNullValue()));
    assertThat(
        subgraph.getNode("/mode:sources/name"), hasProperty(ModeShapeLexicon.RETRY_LIMIT, 100));
    assertThat(
        subgraph.getNode("/mode:sources/name"), hasProperty("defaultCachePolicy", cachePolicy));
    assertThat(
        subgraph.getNode("/mode:sources/name"),
        hasProperty("defaultWorkspaceName", "default workspace name"));
    assertThat(subgraph.getNode("/mode:sources/name"), hasProperty("rootNodeUuid", rootUuid));
  }
예제 #2
0
  @Test
  public void shouldLoadConfigurationWithCustomAuthenticators() throws Exception {
    File file = new File("src/test/resources/config/configRepositoryWithAuthenticators.xml");
    assertThat(file.exists(), is(true));
    assertThat(file.canRead(), is(true));
    assertThat(file.isFile(), is(true));

    configuration.loadFrom("src/test/resources/config/configRepositoryWithAuthenticators.xml");

    assertThat(configuration.getProblems().isEmpty(), is(true));

    // Verify that the graph has been updated correctly ...
    ModeShapeConfiguration.ConfigurationDefinition content =
        configuration.getConfigurationDefinition();
    Subgraph subgraph = content.graph().getSubgraphOfDepth(6).at("/");

    assertThat(subgraph.getNode("/mode:sources"), is(notNullValue()));
    assertThat(subgraph.getNode("/mode:sources/Stuff"), is(notNullValue()));

    assertThat(
        subgraph.getNode("/mode:repositories").getChildren(), hasChild(segment("My Repository")));
    assertThat(subgraph.getNode("/mode:repositories/My Repository"), is(notNullValue()));
    assertThat(
        subgraph.getNode("/mode:repositories/My Repository"),
        hasProperty(ModeShapeLexicon.SOURCE_NAME, "Stuff"));
    assertThat(
        subgraph.getNode("/mode:repositories/My Repository").getChildren(),
        hasChildren(segment("mode:options"), segment("mode:authenticationProviders")));
    assertThat(
        subgraph.getNode("/mode:repositories/My Repository/mode:options"), is(notNullValue()));
    assertThat(
        subgraph.getNode("/mode:repositories/My Repository/mode:options").getChildren(),
        hasChild(segment("jaasLoginConfigName")));
    assertThat(
        subgraph.getNode("/mode:repositories/My Repository/mode:options/jaasLoginConfigName"),
        is(notNullValue()));
    assertThat(
        subgraph.getNode("/mode:repositories/My Repository/mode:authenticationProviders"),
        is(notNullValue()));
    assertThat(
        subgraph.getNode(
            "/mode:repositories/My Repository/mode:authenticationProviders/CustomProviderA"),
        is(notNullValue()));

    // Initialize PicketBox ...
    JaasTestUtil.initJaas("security/jaas.conf.xml");

    // Create and start the engine ...
    engine = configuration.build();
    engine.start();
    Repository repository = engine.getRepository("My Repository");
    assertThat(repository, is(notNullValue()));

    // Create a session, authenticating using one of the usernames defined by our JAAS policy
    // file(s) ...
    Session session = null;
    try {
      session = repository.login(new SimpleCredentials("superuser", "superuser".toCharArray()));
    } finally {
      if (session != null) session.logout();
    }

    // Create a session, authenticating using a SecurityContextCredentials
    try {
      SecurityContext mockSecurityContext =
          new MockSecurityContext("testuser", Collections.singleton(ModeShapeRoles.READWRITE));
      session = repository.login(new TestSecurityContextCredentials(mockSecurityContext));
    } finally {
      if (session != null) session.logout();
    }
  }
예제 #3
0
  @Test
  public void shouldAddNodeTypesAndNamespaces() throws Exception {
    File file = new File("src/test/resources/config/configRepository.xml");
    assertThat(file.exists(), is(true));
    assertThat(file.canRead(), is(true));
    assertThat(file.isFile(), is(true));

    configuration.loadFrom("src/test/resources/config/configRepository.xml");
    // Verify that the configration was loaded correctly ...
    assertThat(configuration.repository("Car Repository").getSource(), is("Cars"));
    // ModeShapeConfiguration.ConfigurationDefinition content1 =
    // configuration.getConfigurationDefinition();
    // Subgraph subgraph1 = content1.graph().getSubgraphOfDepth(6).at("/");

    // Load the node types from the CND file, and save the configuration ...
    InputStream nodeTypes = getClass().getResourceAsStream("/tck/tck_test_types.cnd");
    configuration.repository("Car Repository").addNodeTypes(nodeTypes);
    configuration.save();
    // ModeShapeConfiguration.ConfigurationDefinition content2 =
    // configuration.getConfigurationDefinition();
    // Subgraph subgraph2 = content2.graph().getSubgraphOfDepth(6).at("/");

    // Verify there were no problems loading the CND file ...
    assertThat(configuration.getProblems().isEmpty(), is(true));
    assertThat(
        configuration
            .getConfigurationDefinition()
            .getContext()
            .getNamespaceRegistry()
            .isRegisteredNamespaceUri("http://www.modeshape.org/test/1.0"),
        is(true));

    // Verify that the graph has been updated correctly ...
    ModeShapeConfiguration.ConfigurationDefinition content =
        configuration.getConfigurationDefinition();
    Subgraph subgraph = content.graph().getSubgraphOfDepth(6).at("/");

    assertThat(
        subgraph.getNode("/mode:repositories").getChildren(), hasChild(segment("Car Repository")));
    assertThat(subgraph.getNode("/mode:repositories/Car Repository"), is(notNullValue()));
    assertThat(
        subgraph.getNode("/mode:repositories/Car Repository"),
        hasProperty(ModeShapeLexicon.SOURCE_NAME, "Cars"));
    assertThat(
        subgraph.getNode("/mode:repositories/Car Repository").getChildren(),
        hasChild(segment("mode:options")));
    assertThat(
        subgraph.getNode("/mode:repositories/Car Repository/jcr:nodeTypes"), is(notNullValue()));
    // for (Location child : subgraph.getNode("/mode:repositories/Car
    // Repository/mode:nodeTypes").getChildren()) {
    // System.out.println(child.getPath().getLastSegment().getString(context().getNamespaceRegistry()));
    // }
    assertThat(
        subgraph.getNode("/mode:repositories/Car Repository/jcr:nodeTypes").getChildren(),
        hasChildren(
            segment("modetest:noSameNameSibs"),
            segment("modetest:referenceableUnstructured"),
            segment("modetest:nodeWithMandatoryProperty"),
            segment("modetest:nodeWithMandatoryChild"),
            segment("modetest:unorderableUnstructured")));
    assertThat(
        subgraph.getNode("/mode:repositories/Car Repository/mode:namespaces"), is(notNullValue()));

    // Check that the namespace in the CND file was persisted correctly ...
    assertThat(
        subgraph.getNode("/mode:repositories/Car Repository/mode:namespaces").getChildren(),
        hasChild(segment("modetest")));
    assertThat(
        subgraph.getNode("/mode:repositories/Car Repository/mode:namespaces/modetest"),
        hasProperty(ModeShapeLexicon.URI, "http://www.modeshape.org/test/1.0"));

    // Initialize IDTrust and a policy file (which defines the "modeshape-jcr" login config name)
    JaasTestUtil.initJaas("security/jaas.conf.xml");

    // Create and start the engine ...
    engine = configuration.build();
    engine.start();
    Repository repository = engine.getRepository("Car Repository");
    assertThat(repository, is(notNullValue()));

    // Create a session, authenticating using one of the usernames defined by our JAAS policy
    // file(s) ...
    Session session = null;
    try {
      session = repository.login(new SimpleCredentials("superuser", "superuser".toCharArray()));

      // Check that the namespace showed up ...
      assertThat(session.getNamespacePrefix("http://www.modeshape.org/test/1.0"), is("modetest"));

      // Check that some of the node types showed up ...
      NodeTypeManager ntm = session.getWorkspace().getNodeTypeManager();
      assertThat(
          ntm.getNodeType("modetest:noSameNameSibs"), is(notNullValue())); // throws exception
      assertThat(
          ntm.getNodeType("modetest:referenceableUnstructured"),
          is(notNullValue())); // throws exception
      assertThat(
          ntm.getNodeType("modetest:nodeWithMandatoryProperty"),
          is(notNullValue())); // throws exception
      assertThat(
          ntm.getNodeType("modetest:nodeWithMandatoryChild"),
          is(notNullValue())); // throws exception
      assertThat(
          ntm.getNodeType("modetest:unorderableUnstructured"),
          is(notNullValue())); // throws exception
    } finally {
      if (session != null) session.logout();
    }
  }
예제 #4
0
  @Test
  public void shouldLoadConfigurationFromFilePath() throws Exception {
    File file = new File("src/test/resources/config/configRepository.xml");
    assertThat(file.exists(), is(true));
    assertThat(file.canRead(), is(true));
    assertThat(file.isFile(), is(true));

    configuration.loadFrom("src/test/resources/config/configRepository.xml");

    assertThat(configuration.getProblems().isEmpty(), is(true));

    // Verify that the graph has been updated correctly ...
    ModeShapeConfiguration.ConfigurationDefinition content =
        configuration.getConfigurationDefinition();
    Subgraph subgraph = content.graph().getSubgraphOfDepth(6).at("/");

    assertThat(subgraph.getNode("/mode:sources"), is(notNullValue()));
    assertThat(subgraph.getNode("/mode:sources/Cars"), is(notNullValue()));
    assertThat(
        subgraph.getNode("/mode:sources/Cars"), hasProperty(ModeShapeLexicon.RETRY_LIMIT, "3"));
    assertThat(
        subgraph.getNode("/mode:sources/Cars"),
        hasProperty(ModeShapeLexicon.CLASSNAME, InMemoryRepositorySource.class.getName()));
    assertThat(subgraph.getNode("/mode:sources/Aircraft"), is(notNullValue()));
    assertThat(
        subgraph.getNode("/mode:sources/Aircraft"), hasProperty("defaultWorkspaceName", "default"));
    assertThat(
        subgraph.getNode("/mode:sources/Aircraft"),
        hasProperty(ModeShapeLexicon.CLASSNAME, InMemoryRepositorySource.class.getName()));
    assertThat(subgraph.getNode("/mode:sources/Cache"), is(notNullValue()));
    assertThat(
        subgraph.getNode("/mode:sources/Cache"),
        hasProperty(ModeShapeLexicon.CLASSNAME, InMemoryRepositorySource.class.getName()));

    assertThat(
        subgraph.getNode("/mode:mimeTypeDetectors").getChildren(), hasChild(segment("Detector")));
    assertThat(subgraph.getNode("/mode:mimeTypeDetectors/Detector"), is(notNullValue()));
    assertThat(
        subgraph.getNode("/mode:mimeTypeDetectors/Detector"),
        hasProperty(ModeShapeLexicon.DESCRIPTION, "Standard extension-based MIME type detector"));
    assertThat(
        subgraph.getNode("/mode:mimeTypeDetectors/Detector"),
        hasProperty(ModeShapeLexicon.CLASSNAME, ExtensionBasedMimeTypeDetector.class.getName()));

    assertThat(
        subgraph.getNode("/mode:repositories").getChildren(), hasChild(segment("Car Repository")));
    assertThat(subgraph.getNode("/mode:repositories/Car Repository"), is(notNullValue()));
    assertThat(
        subgraph.getNode("/mode:repositories/Car Repository"),
        hasProperty(ModeShapeLexicon.SOURCE_NAME, "Cars"));
    assertThat(
        subgraph.getNode("/mode:repositories/Car Repository").getChildren(),
        hasChild(segment("mode:options")));
    assertThat(
        subgraph.getNode("/mode:repositories/Car Repository/mode:options"), is(notNullValue()));
    assertThat(
        subgraph.getNode("/mode:repositories/Car Repository/mode:options").getChildren(),
        hasChild(segment("jaasLoginConfigName")));
    assertThat(
        subgraph.getNode("/mode:repositories/Car Repository/mode:options/jaasLoginConfigName"),
        is(notNullValue()));
    assertThat(
        subgraph.getNode(
            "/mode:repositories/Car Repository/mode:descriptors/query.xpath.doc.order"),
        is(notNullValue()));
    assertThat(
        subgraph.getNode("/mode:repositories/Car Repository/mode:descriptors/myDescriptor"),
        is(notNullValue()));

    // Initialize PicketBox ...
    JaasTestUtil.initJaas("security/jaas.conf.xml");

    // Create and start the engine ...
    engine = configuration.build();
    engine.start();
    Repository repository = engine.getRepository("Car Repository");
    assertThat(repository, is(notNullValue()));
    assertThat(repository.getDescriptor("query.xpath.doc.order"), is("false"));
    assertThat(repository.getDescriptor("myDescriptor"), is("foo"));

    // Create a session, authenticating using one of the usernames defined by our JAAS policy
    // file(s) ...
    Session session = null;
    try {
      session = repository.login(new SimpleCredentials("superuser", "superuser".toCharArray()));
    } finally {
      if (session != null) session.logout();
    }
  }