Skip to content
This repository has been archived by the owner on Mar 6, 2018. It is now read-only.

Latest commit

 

History

History
29 lines (23 loc) · 1008 Bytes

README.md

File metadata and controls

29 lines (23 loc) · 1008 Bytes

Simple Authorization with Type Classes

This is a simple project showing the use of type classes and implicits to provide an authorization framework.

val users = Set("jeff", "steve", "mutt")

val steveAndJeffsGroup = new Group(Set("jeff", "steve"))
val muttsOrg = new Organization(admin = "mutt")
val stevesOrg = new Organization(admin = "steve")

for (currentUser <- users) {
  implicit val context = new ExampleSecurityContext(currentUser)
    
  println(s"Is $steveAndJeffsGroup readable by $currentUser? ${Readable(steveAndJeffsGroup)}")
  println(s"Is $muttsOrg readable by $currentUser? ${Readable(muttsOrg)}")
  println(s"Is $stevesOrg readable by $currentUser? ${Readable(stevesOrg)}")
     
  try {
    val result: String = steveAndJeffsGroup.readable {
      s"$currentUser can execute readable for $steveAndJeffsGroup!"
    }
    println(result)
  } catch {
    case e:UnauthorizedException =>
      println(s"$currentUser cannot execute readable for $steveAndJeffsGroup!")
  }
}