trait X509view[A,B] {
40 implicit def wc: WebCache
41 implicit def manif: Manifest[A]
43 def intent: Cycle.Intent[A, B] = {
44 case req @ Path(path) if path startsWith "/test/auth/x509" =>
45 Ok ~> ContentType("text/html") ~> Html(
46 <html><head><title>Authentication Page</title></head>
47 { req match {
48 case X509Claim(xclaim) => <body>
49 <h1>Authentication Info received</h1>
50 <p>You were identified with the following WebIDs</p>
51 <ul>{xclaim.webidclaims.filter(cl=>cl.verified).map(p=> <li>{p.webId}</li>)}</ul>
52 <p>You sent the following certificate</p>
53 <pre>{xclaim.cert.toString}</pre>
54 </body>
55 case _ => <body><p>We received no Authentication information</p></body>
56 }
57 }</html>)
59 }
61 }
33 object Certs {
36 def unapplySeq[T](r: HttpRequest[T]) (implicit m: Manifest[T]) : Option[IndexedSeq[Certificate]] = {
37 if (m <:< manifest[HttpServletRequest]) unapplyServletRequest(r.asInstanceOf[HttpRequest[HttpServletRequest]])
38 else if (m <:< manifest[ReceivedMessage]) unapplyReceivedMessage(r.asInstanceOf[HttpRequest[ReceivedMessage]])
39 else None //todo: should perhaps throw an exception here.
40 }
103 // configures and launches a Jetty server
104 service.filter(new FilterLogger(logger)).
105 context("/public"){ ctx:ContextBuilder =>
106 ctx.resources(ClasspathUtils.fromClasspath("public/").toURI.toURL)
107 }.
108 filter(app.plan).
109 filter(Planify(x509v.intent)).
110 filter(new EchoPlan().plan).run()
112 }
114 object x509v extends X509view[HttpServletRequest,HttpServletResponse] {
115 def wc = webCache
116 def manif = manifest[HttpServletRequest]
117 }
65 // configures and launches a Netty server
66 service.plan( x509v ).run()
68 }
70 object x509v extends cycle.Plan with cycle.ThreadPool with ServerErrorResponse with X509view[ReceivedMessage,HttpResponse] {
71 def wc = webCache
72 def manif = manifest[ReceivedMessage]
73 }
As I wrote up in a post yesterday, I found that TLS renegotiation is easy to do with netty, and probably impossible with jetty as it stands now - and furthermore the netty code is also elegant. So I want to transition from using jetty to netty, and if possible be able to develop for both simultaneously. So I set out to do this today, and it worked, but I am wondering if it could be done better.
First we have a very simple intent that is jetty/netty independent (the line numbers point to the source in the rich version, otherwise see [1])
[...]
But in fact hidden behind the X509Claim(xclaim) on line 48 there is a request to a Certs class that does require access to the underlying components. I could not write overloaded functions on the parameterized types due to type erasure: scala and java just see them as the same. So I had to use the Manifest technique:
PS. On IRC I had a conversation on unfiltered. Perhaps this will be helpful to someone here. I am not exactly sure what dobblego was driving at.
On Saturday, October 22, 2011 3:10:29 PM UTC-4, Henry Story wrote:As I wrote up in a post yesterday, I found that TLS renegotiation is easy to do with netty, and probably impossible with jetty as it stands now - and furthermore the netty code is also elegant.
im not aware of joining this list. Is google violating my privacy (again)? Is it acting without authority (again)?
On Sun, Oct 23, 2011 at 8:39 PM, n8han <nat...@technically.us> wrote:
On Saturday, October 22, 2011 3:10:29 PM UTC-4, Henry Story wrote:As I wrote up in a post yesterday, I found that TLS renegotiation is easy to do with netty, and probably impossible with jetty as it stands now - and furthermore the netty code is also elegant.Please let us know what your specific pain points are.
The Jetty version was simpler to author since it had a build in ssl connector but adds an extra layer for you do dig into and the Netty one was more difficult author because I had to hand author it with a side benefit of having no extra layer for you to dig into. If it's possible maybe we should roll whats common into the jetty version. It may be duplicating support that jetty has built in though.
58 req.underlying.context.getPipeline.get(classOf[org.jboss.netty.handler.ssl.SslHandler]) match {
59 case sslh: SslHandler => {
60 sslh.setEnableRenegotiation(true)
61 sslh.getEngine.setWantClientAuth(true)
62 val future = sslh.handshake()
63 future.await(5000)
64 val res = if (future.isDone) {
65 var r ="We are in login & we have an https handler! "
66 if (future.isSuccess)
67 r += "\r\n"+"SSL handchake Successful. Did we get the certificate? \r\n\r\n"+certAvailable(sslh)
68 else {
69 r += "\r\n handshake failed. Cause \r\n" +future.getCause
70 }
71 r
72 } else {
73 "Still waiting for requested certificate"
74 }
75 ResponseString(res)
76 }
77 case _ =>ResponseString("We are in login but no https handler!")
78 }
On Saturday, October 22, 2011 3:10:29 PM UTC-4, Henry Story wrote:As I wrote up in a post yesterday, I found that TLS renegotiation is easy to do with netty, and probably impossible with jetty as it stands now - and furthermore the netty code is also elegant. So I want to transition from using jetty to netty, and if possible be able to develop for both simultaneously. So I set out to do this today, and it worked, but I am wondering if it could be done better.
This is very interesting to the project and something I think we would be very happy to include when it's finished.
First we have a very simple intent that is jetty/netty independent (the line numbers point to the source in the rich version, otherwise see [1])
[...]
But in fact hidden behind the X509Claim(xclaim) on line 48 there is a request to a Certs class that does require access to the underlying components. I could not write overloaded functions on the parameterized types due to type erasure: scala and java just see them as the same. So I had to use the Manifest technique:
In this case I think we do not want to work around erasure even though we can. The intent is typed as if it can work with any server binding, but as you say there is hidden internal code that does depend on a known binding. It would be better to have two versions of this intent typed for each server binding, so that later when a mina or grizzly binding becomes available it is clear to the programmer and the compiler that the intent will not be compatible. It should still be possible to share code between the subtypes of the intent.
PS. On IRC I had a conversation on unfiltered. Perhaps this will be helpful to someone here. I am not exactly sure what dobblego was driving at.
The interface uses iterators for parameters because they are iterators in the servlet spec and accessing them has side effects. We have kept the binding interfaces fairly close to what they are wrapping, and use the request extractors to supply preferred data structures.
Nathan
It would require different objects but it should be possible to share
most of the code between them. When you are finished with the
implementation I'll take a crack at that, unless someone else will.
> As it stands currently I can run the same tests on the same intents.
> (btw. why are these called intents? ).
The thinking is that an "intent" is the precursor to a "plan".
Nathan
On 10/24/2011 10:22 AM, Henry Story wrote:
>
> yes, but then I'd have to write intents twice, which is ugly and waste
> of code. I know the current solution is a bit of a hack, but it is
> less of one than writing intents twice.It would require different objects but it should be possible to share
most of the code between them. When you are finished with the
implementation I'll take a crack at that, unless someone else will.
> As it stands currently I can run the same tests on the same intents.
> (btw. why are these called intents? ).The thinking is that an "intent" is the precursor to a "plan".
Nathan