Created
July 29, 2012 09:24
-
-
Save bblfish/3197004 to your computer and use it in GitHub Desktop.
Claim logic
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.w3.play.auth | |
import akka.actor.Actor | |
import org.openrdf.model.URI | |
import java.security.cert.X509Certificate | |
import org.w3.play.rdf.GraphCache | |
import scalaz._ | |
import scala.Some | |
import scalaz.Scalaz._ | |
import org.w3.banana.RDF | |
import java.security.PublicKey | |
/** | |
* | |
*/ | |
class WebIDAuthN[Rdf<:RDF](graphs: GraphCache[Rdf]) extends Actor { | |
protected def receive = { | |
case x509claim : Claim[X509Certificate] => { | |
val webidClaims = for (x509 <- x509claim) yield { | |
Option(x509.getSubjectAlternativeNames()).toList.flatMap { coll => | |
import scala.collection.JavaConverters.iterableAsScalaIterableConverter | |
for { | |
sanPair <- coll.asScala if (sanPair.get(0) == 6) | |
} yield (sanPair.get(1).asInstanceOf[String].trim,x509.getPublicKey) | |
} | |
} | |
for ( webidclaim <- webidClaims.sequence) { | |
// send this webid claim to a webid claim verifier agent. | |
} | |
} | |
} | |
} | |
trait Claim[+S] { | |
protected val statement: S | |
def verify(implicit fn: S=> Boolean ): Option[S] | |
} | |
object Claim { | |
implicit val ClaimMonad: Monad[Claim] with Traverse[Claim] = | |
new Monad[Claim] with Traverse[Claim] { | |
def traverseImpl[G[_] : Applicative, A, B](fa: Claim[A])(f: A => G[B]): G[Claim[B]] = | |
f(fa.statement).map(a => this.point(a)) | |
def point[A](a: => A) = new Claim[A]{ | |
protected val statement : A = a; | |
def verify(implicit fn: A=> Boolean ): Option[A] = fn(statement) match { | |
case true => Some(statement) | |
case false => None | |
} | |
} | |
def bind[A, B](fa: Claim[A])(f: (A) => Claim[B]) = f(fa.statement) | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment