Author: bblfish
Date: Mon Apr 4 09:27:56 2011
New Revision: 1088519
URL: http://svn.apache.org/viewvc?rev=1088519&view=rev
Log:
Rename the test foafssl package, and get first test case to work using renderlet
Added:
incubator/clerezza/trunk/parent/platform.security.foafssl/test/src/main/scala/org/apache/clerezza/foafssl/test/
incubator/clerezza/trunk/parent/platform.security.foafssl/test/src/main/scala/org/apache/clerezza/foafssl/test/WebIDTester.scala
- copied, changed from r1088518,
incubator/clerezza/trunk/parent/platform.security.foafssl/test/src/main/scala/org/apache/clerezza/foafssl/testservlets/TestMe.scala
incubator/clerezza/trunk/parent/platform.security.foafssl/test/src/main/scala/org/apache/clerezza/foafssl/test/pages/
incubator/clerezza/trunk/parent/platform.security.foafssl/test/src/main/scala/org/apache/clerezza/foafssl/test/pages/CertificateDescription.scala
Removed:
incubator/clerezza/trunk/parent/platform.security.foafssl/test/src/main/scala/org/apache/clerezza/foafssl/testservlets/TestMe.scala
Modified:
incubator/clerezza/trunk/parent/platform.security.foafssl/test/pom.xml
incubator/clerezza/trunk/parent/platform.security.foafssl/test/src/main/resources/OSGI-INF/serviceComponents.xml
Modified: incubator/clerezza/trunk/parent/platform.security.foafssl/test/pom.xml
URL:
http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/platform.security.foafssl/test/pom.xml?rev=1088519&r1=1088518&r2=1088519&view=diff
==============================================================================
--- incubator/clerezza/trunk/parent/platform.security.foafssl/test/pom.xml
(original)
+++ incubator/clerezza/trunk/parent/platform.security.foafssl/test/pom.xml Mon
Apr 4 09:27:56 2011
@@ -57,6 +57,10 @@
</dependency>
<dependency>
<groupId>org.apache.clerezza</groupId>
+ <artifactId>platform.typerendering.scala</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.clerezza</groupId>
<artifactId>platform.security.foafssl.core</artifactId>
</dependency>
<dependency>
@@ -110,7 +114,7 @@
<configuration>
<instructions>
<Service-Component>OSGI-INF/serviceComponents.xml</Service-Component>
-
<Export-Package>org.apache.clerezza.foafssl.testservlets</Export-Package>
+
<Export-Package>org.apache.clerezza.foafssl.test.*</Export-Package>
<Bundle-SymbolicName>${project.groupId}.${project.artifactId}</Bundle-SymbolicName>
</instructions>
</configuration>
Modified:
incubator/clerezza/trunk/parent/platform.security.foafssl/test/src/main/resources/OSGI-INF/serviceComponents.xml
URL:
http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/platform.security.foafssl/test/src/main/resources/OSGI-INF/serviceComponents.xml?rev=1088519&r1=1088518&r2=1088519&view=diff
==============================================================================
---
incubator/clerezza/trunk/parent/platform.security.foafssl/test/src/main/resources/OSGI-INF/serviceComponents.xml
(original)
+++
incubator/clerezza/trunk/parent/platform.security.foafssl/test/src/main/resources/OSGI-INF/serviceComponents.xml
Mon Apr 4 09:27:56 2011
@@ -1,13 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<components xmlns:scr="http://www.osgi.org/xmlns/scr/v1.0.0">
- <scr:component enabled="true"
name="org.apache.clerezza.foafssl.testserlvets.TestMe" immediate="true">
- <implementation
class="org.apache.clerezza.foafssl.testservlets.TestMe"/>
+ <scr:component enabled="true"
name="org.apache.clerezza.foafssl.testserlvets.TestMe" immediate="true">
+ <implementation class="org.apache.clerezza.foafssl.test.WebIDTester"/>
<service servicefactory="false">
<provide interface="java.lang.Object"/>
</service>
- <reference name="UserManager"
- interface="org.apache.clerezza.platform.usermanager.UserManager"
- cardinality="1..1" policy="static" bind="bindUserManager"
unbind="unbindUserManager"/>
<property name="javax.ws.rs" type="Boolean" value="true"/>
- </scr:component>
+ </scr:component>
+ <scr:component enabled="true"
name="org.apache.clerezza.foafssl.testservlets.pages.CertificateDescription">
+ <implementation
class="org.apache.clerezza.foafssl.test.pages.CertificateDescription"/>
+ <service servicefactory="false">
+ <provide
interface="org.apache.clerezza.platform.typerendering.TypeRenderlet"/>
+ </service>
+ <property name="service.pid"
value="org.apache.clerezza.foafssl.test.pages.CertificateDescription"/>
+ </scr:component>
</components>
Copied:
incubator/clerezza/trunk/parent/platform.security.foafssl/test/src/main/scala/org/apache/clerezza/foafssl/test/WebIDTester.scala
(from r1088518,
incubator/clerezza/trunk/parent/platform.security.foafssl/test/src/main/scala/org/apache/clerezza/foafssl/testservlets/TestMe.scala)
URL:
http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/platform.security.foafssl/test/src/main/scala/org/apache/clerezza/foafssl/test/WebIDTester.scala?p2=incubator/clerezza/trunk/parent/platform.security.foafssl/test/src/main/scala/org/apache/clerezza/foafssl/test/WebIDTester.scala&p1=incubator/clerezza/trunk/parent/platform.security.foafssl/test/src/main/scala/org/apache/clerezza/foafssl/testservlets/TestMe.scala&r1=1088518&r2=1088519&rev=1088519&view=diff
==============================================================================
---
incubator/clerezza/trunk/parent/platform.security.foafssl/test/src/main/scala/org/apache/clerezza/foafssl/testservlets/TestMe.scala
(original)
+++
incubator/clerezza/trunk/parent/platform.security.foafssl/test/src/main/scala/org/apache/clerezza/foafssl/test/WebIDTester.scala
Mon Apr 4 09:27:56 2011
@@ -17,13 +17,19 @@
* under the License.
*/
-package org.apache.clerezza.foafssl.testservlets
+package org.apache.clerezza.foafssl.test
import org.apache.clerezza.platform.security.UserUtil
import org.apache.clerezza.platform.usermanager.UserManager
import javax.ws.rs.{Produces, GET, Path}
import org.osgi.service.component.ComponentContext
import org.apache.clerezza.foafssl.auth.X509Claim
+import javax.ws.rs.core.Response
+import org.apache.clerezza.rdf.utils.GraphNode
+import org.apache.clerezza.rdf.core.impl.SimpleMGraph
+import org.apache.clerezza.rdf.ontologies.{FOAF, PLATFORM, RDF}
+import org.apache.clerezza.rdf.core.{BNode, UriRef}
+import pages.XhtmlCertificate
/**
* implementation of (very early) version of test server for WebID so that the
following tests
@@ -32,43 +38,27 @@ import org.apache.clerezza.foafssl.auth.
* http://lists.w3.org/Archives/Public/public-xg-webid/2011Jan/0107.html
*/
-@Path("/test/WebId")
-class TestMe {
-
- var userManager: UserManager = null;
+object WebIDTester {
+ val testCls = new UriRef("https://localhost/test/WebID/ont/tests") //todo:
change url
+}
- protected def bindUserManager(um: UserManager) = {
- userManager = um
- }
+@Path("/test/WebId")
+class WebIDTester {
+ import WebIDTester._
- protected def unbindUserManager(um: UserManager) = {
- userManager = null
- }
protected def activate(componentContext: ComponentContext) = {
// configure(componentContext.getBundleContext(),
"profile-staticweb");
}
@GET
- @Produces(Array("text/plain"))
- def getTestMe(): String = {
- val subject = UserUtil.getCurrentSubject();
- val creds = subject.getPublicCredentials
- if (creds.size == 0) return "No public keys found"
- val cred = creds.iterator.next
- def outString(x509: X509Claim): String = {
- val res = for (id <- x509.webidclaims) yield {
- id.verified + " webid " + id.webId + " hasname " + id.userName
- }
- res.toString
- }
-
- return cred match {
- case x509: X509Claim => outString(x509)
- case other: AnyRef => "no X509 certificate found: found " +
other.getClass()
- }
+ def getTestMe(): GraphNode = {
+ val resultNode: GraphNode = new GraphNode(new BNode(),new SimpleMGraph())
+ resultNode.addProperty(RDF.`type`, testCls)
+ return resultNode
}
+
@GET
@Path("x509")
@Produces(Array("text/plain"))
@@ -80,6 +70,7 @@ class TestMe {
case x509: X509Claim => "X509 Certificate found. " + x509.cert.toString
case other: Any => "no X509 certificate found: found " + other.getClass()
}
+
}
Added:
incubator/clerezza/trunk/parent/platform.security.foafssl/test/src/main/scala/org/apache/clerezza/foafssl/test/pages/CertificateDescription.scala
URL:
http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/platform.security.foafssl/test/src/main/scala/org/apache/clerezza/foafssl/test/pages/CertificateDescription.scala?rev=1088519&view=auto
==============================================================================
---
incubator/clerezza/trunk/parent/platform.security.foafssl/test/src/main/scala/org/apache/clerezza/foafssl/test/pages/CertificateDescription.scala
(added)
+++
incubator/clerezza/trunk/parent/platform.security.foafssl/test/src/main/scala/org/apache/clerezza/foafssl/test/pages/CertificateDescription.scala
Mon Apr 4 09:27:56 2011
@@ -0,0 +1,129 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.clerezza.foafssl.test.pages
+
+import org.apache.clerezza.platform.typerendering.scala.{XmlResult, SRenderlet}
+import org.apache.clerezza.platform.security.UserUtil
+import org.apache.clerezza.foafssl.test.WebIDTester
+import org.apache.clerezza.rdf.web.proxy.{Cache, WebProxy}
+import org.apache.clerezza.rdf.scala.utils.RichGraphNode
+import org.apache.clerezza.rdf.ontologies.RDF
+import org.apache.clerezza.foafssl.ontologies.{RSA, CERT}
+import org.apache.clerezza.rdf.scala.utils.Preamble._
+import java.security.{PrivilegedAction, AccessController}
+import org.apache.clerezza.rdf.utils.GraphNode
+import org.apache.clerezza.rdf.core.Graph
+import org.apache.clerezza.rdf.core.serializedform.Serializer
+import org.apache.clerezza.foafssl.auth.{Verification, WebIDClaim, X509Claim}
+import java.io.{PrintStream, ByteArrayOutputStream}
+
+/**
+ * @author hjs
+ * @created: 01/04/2011
+ */
+
+class CertificateDescription extends SRenderlet {
+ def getRdfType() = WebIDTester.testCls
+
+ override def renderedPage(arguments: XmlResult.Arguments) = new
XhtmlCertificate(arguments)
+}
+
+class XhtmlCertificate(arguments: XmlResult.Arguments) extends
XmlResult(arguments ) {
+ val subject = UserUtil.getCurrentSubject();
+
+
+ override def content = <span>
+ <p>The TLS connection was established. We do not test the basic TLS
connection.</p>
+ {
+ val subj = UserUtil.getCurrentSubject();
+ val creds: scala.collection.mutable.Set[X509Claim] =
collection.JavaConversions.asScalaSet(subj.getPublicCredentials(classOf[X509Claim]));
+ if (creds.size==0) <p>No credentials available. Cannot tell how we came to
accept identity</p>
+ else for (cred <- creds) yield describeX509Claim(cred)
+ }
+ </span>
+
+
+ def describeX509Claim(claim: X509Claim) = {
+ <p>The Certificate sent can be viewed in detail <a
href="WebId/x509">here</a>. The public key shown there is:
+ <pre>{claim.cert.getPublicKey}</pre>
+ </p>
+
+ <p>The certificate sent contains {claim.webidclaims.size} WebId Claims.
They are listed here, and it is shown if
+ they have been verified.</p>
+ <ul>{
+ for (idClaim <- claim.webidclaims) yield
<li>{describeWebIDClaim(idClaim)}</li>
+ }</ul>
+ }
+
+ def getWebIDProfile(claim: WebIDClaim): Option[GraphNode] = {
+ val som = AccessController.doPrivileged(new
PrivilegedAction[Option[GraphNode]] {
+ def run = $[WebProxy].fetchSemantics(claim.webId, Cache.CacheOnly)
+ })
+ som
+ }
+
+ def describeWebIDClaim(claim: WebIDClaim) = {
+ <span>
+ Claimed ID: <a
href={claim.webId.getUnicodeString}>{claim.webId.getUnicodeString}</a><br/>
+ Claim was {claim.verified}<br/>
+ {
+ claim.verified match {
+ case Verification.Verified => verifiedClaim(claim)
+ case Verification.Failed => claimFailure(claim)
+ case Verification.Unverified => <p>Currently this is not possible, but
in asynchronous situations it will be</p>
+ }
+ }
+ </span>
+ }
+
+ def verifiedClaim(claim: WebIDClaim) = {
+ <p>Supporting information from the WebID Profile
+ {val som: Option[GraphNode] = getWebIDProfile(claim)
+ som match {
+ case Some(profile) => {
+ val keys = profile /- CERT.identity
+ for (key <- keys) yield displayKey(key)
+ }
+ case None => "No remote graph?"
+ }}
+ </p>
+ }
+
+ def claimFailure(claim: WebIDClaim) = <p>
+ The Claim failed because { import collection.JavaConversions._
+ for (e: Throwable <- claim.errors) yield <pre>{
+ val str = new ByteArrayOutputStream(1024)
+ val out = new PrintStream(str)
+ e.printStackTrace(out)
+ str.toString("UTF-8")
+ }</pre>
+ }
+ </p>
+
+ def displayKey(key: RichGraphNode) = <pre>
+ {val graph: Graph = key.getNodeContext
+ val sout = Serializer.getInstance()
+ val out = new ByteArrayOutputStream(1024)
+ sout.serialize(out, graph, "text/rdf+n3")
+ out.toString("UTF-8")}
+ </pre>
+
+
+}
\ No newline at end of file