Author: bcarothers
Date: 2009-12-29 20:15:22 -0500 (Tue, 29 Dec 2009)
New Revision: 1494
Added:
trunk/docs/examples/gettingstarted/repositories/src/main/resources/ufoSource/
trunk/docs/examples/gettingstarted/repositories/src/main/resources/ufoSource/workspace1/
trunk/docs/examples/gettingstarted/repositories/src/main/resources/ufoSource/workspace1/README.txt
trunk/docs/examples/gettingstarted/repositories/src/main/resources/ufoSource/workspace1/martians/
trunk/docs/examples/gettingstarted/repositories/src/main/resources/ufoSource/workspace1/martians/zzyzx.txt
trunk/docs/examples/gettingstarted/repositories/src/main/resources/ufoSource/workspace1/venutians/
trunk/docs/examples/gettingstarted/repositories/src/main/resources/ufoSource/workspace1/venutians/frobozz.txt
Modified:
trunk/docs/examples/gettingstarted/repositories/pom.xml
trunk/docs/examples/gettingstarted/repositories/src/main/assembly/basic.xml
trunk/docs/examples/gettingstarted/repositories/src/main/java/org/jboss/example/dna/repository/ConsoleInput.java
trunk/docs/examples/gettingstarted/repositories/src/main/java/org/jboss/example/dna/repository/RepositoryClient.java
trunk/docs/examples/gettingstarted/repositories/src/main/resources/configRepository.xml
trunk/docs/examples/gettingstarted/repositories/src/test/java/org/jboss/example/dna/repository/RepositoryClientTest.java
trunk/docs/gettingstarted/src/main/docbook/en-US/content/repository_example.xml
Log:
DNA-464 Add use of file system connector to repositories example
Applied a patch that adds a file system connector (for UFOs, which are so strange that
they can't be placed in a normal in-memory repository!) and updates the tests and
documentation accordingly* The patch also removes the need to manually log in to each
repository, something I found seriously annoying and impossible to use without reading
either the manual or the source code. I can replace the old code if anyone disagrees with
this change.
* - I do not have "graffle" installed, so I did not update any of the images in
the Repositories Example chapter of the Getting Started Guide
Modified: trunk/docs/examples/gettingstarted/repositories/pom.xml
===================================================================
--- trunk/docs/examples/gettingstarted/repositories/pom.xml 2009-12-29 22:48:24 UTC (rev
1493)
+++ trunk/docs/examples/gettingstarted/repositories/pom.xml 2009-12-30 01:15:22 UTC (rev
1494)
@@ -34,6 +34,11 @@
<version>${project.version}</version>
<scope>runtime</scope>
</dependency>
+ <dependency>
+ <groupId>org.jboss.dna</groupId>
+ <artifactId>dna-connector-filesystem</artifactId>
+ <version>${project.version}</version>
+ </dependency>
<!--
Logging (require SLF4J API for compiling, but use Log4J and its SLF4J binding for
running)
-->
Modified: trunk/docs/examples/gettingstarted/repositories/src/main/assembly/basic.xml
===================================================================
--- trunk/docs/examples/gettingstarted/repositories/src/main/assembly/basic.xml 2009-12-29
22:48:24 UTC (rev 1493)
+++ trunk/docs/examples/gettingstarted/repositories/src/main/assembly/basic.xml 2009-12-30
01:15:22 UTC (rev 1494)
@@ -24,6 +24,10 @@
<directory>src/main/resources/security/</directory>
<outputDirectory/>
</fileSet>
+ <fileSet>
+ <directory>src/main/resources/ufoSource</directory>
+ <outputDirectory>src/main/resources/ufoSource</outputDirectory>
+ </fileSet>
</fileSets>
<files>
<file>
Modified:
trunk/docs/examples/gettingstarted/repositories/src/main/java/org/jboss/example/dna/repository/ConsoleInput.java
===================================================================
---
trunk/docs/examples/gettingstarted/repositories/src/main/java/org/jboss/example/dna/repository/ConsoleInput.java 2009-12-29
22:48:24 UTC (rev 1493)
+++
trunk/docs/examples/gettingstarted/repositories/src/main/java/org/jboss/example/dna/repository/ConsoleInput.java 2009-12-30
01:15:22 UTC (rev 1494)
@@ -34,7 +34,7 @@
import java.util.Map;
import javax.security.auth.callback.CallbackHandler;
import org.jboss.dna.common.util.StringUtil;
-import com.sun.security.auth.callback.TextCallbackHandler;
+import org.jboss.dna.graph.JaasSecurityContext;
/**
* The {@link UserInterface} implementation that uses the console.
@@ -323,7 +323,7 @@
* @see org.jboss.example.dna.repository.UserInterface#getCallbackHandler()
*/
public CallbackHandler getCallbackHandler() {
- return new TextCallbackHandler();
+ return new JaasSecurityContext.UserPasswordCallbackHandler("jsmith",
"secret".toCharArray());
}
}
Modified:
trunk/docs/examples/gettingstarted/repositories/src/main/java/org/jboss/example/dna/repository/RepositoryClient.java
===================================================================
---
trunk/docs/examples/gettingstarted/repositories/src/main/java/org/jboss/example/dna/repository/RepositoryClient.java 2009-12-29
22:48:24 UTC (rev 1493)
+++
trunk/docs/examples/gettingstarted/repositories/src/main/java/org/jboss/example/dna/repository/RepositoryClient.java 2009-12-30
01:15:22 UTC (rev 1494)
@@ -40,6 +40,7 @@
import javax.security.auth.login.LoginContext;
import javax.security.auth.login.LoginException;
import net.jcip.annotations.Immutable;
+import org.jboss.dna.common.collection.Problem;
import org.jboss.dna.common.text.NoOpEncoder;
import org.jboss.dna.common.util.CheckArg;
import org.jboss.dna.graph.ExecutionContext;
@@ -151,6 +152,13 @@
engine = configuration.build();
engine.start();
+ if (engine.getProblems().hasProblems()) {
+ for (Problem problem : engine.getProblems()) {
+ System.err.println(problem.getMessageString());
+ }
+ throw new RuntimeException("Could not start due to problems");
+ }
+
// For this example, we're using a couple of in-memory repositories
(including one for the configuration repository).
// Normally, these would exist already and would simply be accessed. But in this
example, we're going to
// populate these repositories here by importing from files. First do the
configuration repository ...
Modified:
trunk/docs/examples/gettingstarted/repositories/src/main/resources/configRepository.xml
===================================================================
---
trunk/docs/examples/gettingstarted/repositories/src/main/resources/configRepository.xml 2009-12-29
22:48:24 UTC (rev 1493)
+++
trunk/docs/examples/gettingstarted/repositories/src/main/resources/configRepository.xml 2009-12-30
01:15:22 UTC (rev 1494)
@@ -45,6 +45,15 @@
<defaultWorkspaceName>workspace2</defaultWorkspaceName>
</dna:source>
<!--
+ The 'UFO' repository is a file system source with a single default
workspace. The file system connector exposes
+ files and folders as JCR nodes. It can save JCR nodes too, but only if they have
certain primary types.
+ -->
+ <dna:source jcr:name="UFOs"
dna:classname="org.jboss.dna.connector.filesystem.FileSystemSource"
+ dna:workspaceRootPath="./src/main/resources/ufoSource"
+ dna:defaultWorkspaceName="workspace1"
+ dna:creatingWorkspacesAllowed="false"
+ dna:updatesAllowed="true"/>
+ <!--
The 'Vehicles' repository is a federated source that owns none of its own
content, but instead
projects (in this case) all of the content from the 'Cars' source as if
it appears
under '/Vehicles/Cars', while all the 'Aircraft' content appears
under '/Vehicles/Aircraft'.
@@ -64,10 +73,14 @@
<dna:projection jcr:name="Cars projection"
dna:source="Cars" dna:workspaceName="workspace1">
<dna:projectionRules>/Vehicles/Cars =>
/Cars</dna:projectionRules>
</dna:projection>
- <!-- Project the 'Aicraft' content, starting with the
'/Aircraft' node. -->
+ <!-- Project the 'Aircraft' content, starting with the
'/Aircraft' node. -->
<dna:projection jcr:name="Aircarft projection"
dna:source="Aircraft" dna:workspaceName="workspace2">
<dna:projectionRules>/Vehicles/Aircraft =>
/Aircraft</dna:projectionRules>
</dna:projection>
+ <!-- Project the 'UFO' content, starting with the root
node. -->
+ <dna:projection jcr:name="UFO projection"
dna:source="UFOs" dna:workspaceName="workspace1">
+ <dna:projectionRules>/Vehicles/UFOs =>
/</dna:projectionRules>
+ </dna:projection>
<!-- Project the 'System' content. Only needed when
this source is accessed through JCR. -->
<!-- dna:projection jcr:name="System projection"
dna:source="System" dna:workspaceName="default">
<dna:projectionRules>/jcr:system =>
/</dna:projectionRules>
@@ -149,6 +162,22 @@
</dna:options>
</dna:repository>
<!--
+ Define a JCR repository that accesses the 'UFO' source directly.
+ This of course is optional, since we could access the same content through
'vehicles'.
+ -->
+ <dna:repository jcr:name="UFOs">
+ <!-- Specify the source that should be used for the repository -->
+ <dna:source>UFOs</dna:source>
+ <!-- Define the options for the JCR repository, using camelcase version of
JcrRepository.Option names -->
+ <dna:options jcr:primaryType="dna:options">
+ <jaasLoginConfigName jcr:primaryType="dna:option"
dna:value="dna-jcr"/>
+ </dna:options>
+ <!-- Define any custom node types. Importing CND files via
JcrConfiguration is equivalent to specifying here. -->
+ <dna:nodeTypes jcr:primaryType="dna:nodeTypes"/>
+ <!-- Define any namespaces for this repository, other than those already
defined by JCR or DNA -->
+ <namespaces jcr:primaryType="dna:namespaces" />
+ </dna:repository>
+ <!--
Define a JCR repository that accesses the 'Vehicles' federated source
directly,
which is defined in the sources to be a projection of the 'Cars' and
'Vehicles' content.
-->
Added:
trunk/docs/examples/gettingstarted/repositories/src/main/resources/ufoSource/workspace1/README.txt
===================================================================
---
trunk/docs/examples/gettingstarted/repositories/src/main/resources/ufoSource/workspace1/README.txt
(rev 0)
+++
trunk/docs/examples/gettingstarted/repositories/src/main/resources/ufoSource/workspace1/README.txt 2009-12-30
01:15:22 UTC (rev 1494)
@@ -0,0 +1 @@
+This workspace contains skeletal information on unconfirmed UFOs.
\ No newline at end of file
Property changes on:
trunk/docs/examples/gettingstarted/repositories/src/main/resources/ufoSource/workspace1/README.txt
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added:
trunk/docs/examples/gettingstarted/repositories/src/main/resources/ufoSource/workspace1/martians/zzyzx.txt
===================================================================
---
trunk/docs/examples/gettingstarted/repositories/src/main/resources/ufoSource/workspace1/martians/zzyzx.txt
(rev 0)
+++
trunk/docs/examples/gettingstarted/repositories/src/main/resources/ufoSource/workspace1/martians/zzyzx.txt 2009-12-30
01:15:22 UTC (rev 1494)
@@ -0,0 +1,2 @@
+The Zzyzx is the fastest vehicle in the Martian fleet. It has spinning lasers and can
drop
+disintegration bombs on unsuspecting targets.
Property changes on:
trunk/docs/examples/gettingstarted/repositories/src/main/resources/ufoSource/workspace1/martians/zzyzx.txt
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added:
trunk/docs/examples/gettingstarted/repositories/src/main/resources/ufoSource/workspace1/venutians/frobozz.txt
===================================================================
---
trunk/docs/examples/gettingstarted/repositories/src/main/resources/ufoSource/workspace1/venutians/frobozz.txt
(rev 0)
+++
trunk/docs/examples/gettingstarted/repositories/src/main/resources/ufoSource/workspace1/venutians/frobozz.txt 2009-12-30
01:15:22 UTC (rev 1494)
@@ -0,0 +1 @@
+The Venutian Frobozz travels faster than the speed of light and fires a death ray.
\ No newline at end of file
Property changes on:
trunk/docs/examples/gettingstarted/repositories/src/main/resources/ufoSource/workspace1/venutians/frobozz.txt
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Modified:
trunk/docs/examples/gettingstarted/repositories/src/test/java/org/jboss/example/dna/repository/RepositoryClientTest.java
===================================================================
---
trunk/docs/examples/gettingstarted/repositories/src/test/java/org/jboss/example/dna/repository/RepositoryClientTest.java 2009-12-29
22:48:24 UTC (rev 1493)
+++
trunk/docs/examples/gettingstarted/repositories/src/test/java/org/jboss/example/dna/repository/RepositoryClientTest.java 2009-12-30
01:15:22 UTC (rev 1494)
@@ -34,6 +34,7 @@
import java.util.Map;
import javax.security.auth.callback.CallbackHandler;
import org.jboss.dna.graph.JaasSecurityContext;
+import org.jboss.dna.graph.property.Binary;
import org.jboss.security.config.IDTrustConfiguration;
import org.junit.After;
import org.junit.Before;
@@ -94,6 +95,14 @@
assertThat(actualValues, is(values));
}
+ protected String string( Object rawValue ) {
+ if (rawValue instanceof Binary) {
+ return new String(((Binary)rawValue).getBytes());
+ }
+
+ return rawValue.toString();
+ }
+
protected void getNodeInfo( String source,
String path ) throws Throwable {
properties.clear();
@@ -239,6 +248,27 @@
}
@Test
+ public void shouldHaveContentFromUfosRepository() throws Throwable {
+ client.startRepositories();
+
+ getNodeInfo("UFOs", "/");
+ assertThat(children, hasItems("martians", "venutians",
"README.txt"));
+ assertThat(properties.containsKey("jcr:primaryType"), is(true));
+
+ getNodeInfo("UFOs", "/martians/zzyzx.txt");
+ assertThat(children, hasItems("jcr:content"));
+ assertThat(properties.containsKey("jcr:primaryType"), is(true));
+
+ getNodeInfo("UFOs", "/martians/zzyzx.txt/jcr:content");
+ assertThat(children.size(), is(0));
+ assertThat(properties.containsKey("jcr:primaryType"), is(true));
+
+ assertThat(string(properties.get("jcr:data")[0]).startsWith("The
Zzyzx is the fastest vehicle in the Martian fleet."),
+ is(true));
+
+ }
+
+ @Test
public void shouldHaveContentFromVehiclesRepository() throws Throwable {
client.startRepositories();
@@ -282,6 +312,12 @@
assertProperty("maxSpeed", "30mph");
assertProperty("emptyWeight", "605lb");
assertProperty("crew", "1");
+
+ getNodeInfo("Vehicles",
"/Vehicles/UFOs/martians/zzyzx.txt/jcr:content");
+ assertThat(children.size(), is(0));
+ assertThat(properties.containsKey("jcr:primaryType"), is(true));
+ assertThat(string(properties.get("jcr:data")[0]).startsWith("The
Zzyzx is the fastest vehicle in the Martian fleet."),
+ is(true));
}
@Test
@@ -296,6 +332,7 @@
// shouldHaveContentFromConfigurationRepository();
shouldHaveContentFromCarsRepository();
shouldHaveContentFromAircraftRepository();
+ shouldHaveContentFromUfosRepository();
shouldHaveContentFromVehiclesRepository();
}
}
Modified: trunk/docs/gettingstarted/src/main/docbook/en-US/content/repository_example.xml
===================================================================
---
trunk/docs/gettingstarted/src/main/docbook/en-US/content/repository_example.xml 2009-12-29
22:48:24 UTC (rev 1493)
+++
trunk/docs/gettingstarted/src/main/docbook/en-US/content/repository_example.xml 2009-12-30
01:15:22 UTC (rev 1494)
@@ -38,7 +38,7 @@
</para>
<sect1 id="running_repository_example">
<title>Running the repository example</title>
- <para>The repository example consists of a client application that sets up two
DNA repositories (named "Cars" and "Airplanes") and
+ <para>The repository example consists of a client application that sets up three
DNA repositories (named "Cars", "Airplanes", and "UFOs") and
a federated repository ("Vehicles") that dynamically federates the
information from the other two repositories.
The client application allows you to interactively navigate each of these repositories
just as you would navigate the
directory structure on a file system.</para>
@@ -47,10 +47,11 @@
<title>Repositories used in the example client</title>
<graphic align="center" scale="60"
fileref="example-repositories.png"/>
</figure>
- Most of the repositories are in-memory repositories (using the In-Memory repository
connector), but the federated "Vehicles" repository
+ The "Cars" and "Airplanes" repositories are in-memory repositories
(using the In-Memory repository connector) and the "UFOs" repository is
+ a file system repository (using the File System repository connector). The federated
"Vehicles" repository
content is federated from the other repositories and cached into the "Cache"
repository. This is shown in the following figure:
<figure id="example-federated-repository">
- <title>Vehicles repository content is federated from the Cars, Airplanes and
Configuration repositories</title>
+ <title>Vehicles repository content is federated from the Cars, Airplanes, UFOs,
and Configuration repositories</title>
<graphic align="center" scale="60"
fileref="example-federated-repository.png"/>
</figure>
</para>
@@ -87,10 +88,12 @@
</table>
<note>
<para>
- The first time you access any repository, you will be prompted to log in. This is
JAAS at work, and the example application
- should prompt you for a username and password. As configured in the
"jaas.conf.xml" and "users.properties" files,
- enter "jsmith" for the username and "secret" for the password.
And, yes, the password is shown in cleartext - this
- is a simple example, after all!
+ The first time you access any repository, the application is automatically logging
you in to DNA's JAAS-based security
+ system. To make the application easier to use, it always logs in with the
"jsmith" as the username and "secret" as the
+ password. This matches what is configured in the "jaas.conf.xml" and
"users.properties" files. If you want to confirm
+ that the security feature is working, change the password in
target/dna-example-repositories-basic.dir/users.properties to
+ something else and re-run the application. After you select a repository and try to
view a directory with 'ls', you
+ will get a LoginException!
</para>
</note>
<para>If you were to select the "Cars" repository and use some of the
commands, you should see something similar to: