bolster.security

Members list

Type members

Classlikes

sealed trait Permission

Defines permission by name.

Defines permission by name.

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any
object Permission

Provides permission factory.

Provides permission factory.

Attributes

Companion
trait
Supertypes
trait Sum
trait Mirror
class Object
trait Matchable
class Any
Self type
Permission.type
object RootContext extends SecurityContext

Defines root context in which all permissions are granted.

Defines root context in which all permissions are granted.

Attributes

See also
Supertypes
class Object
trait Matchable
class Any
Self type
sealed trait SecurityContext

Defines context in which permissions are granted.

Defines context in which permissions are granted.

A SecurityContext establishes a pattern in which a restricted operation is performed only if required permissions are granted; otherwise, a SecurityViolation is raised.

The following demonstrates how read/write access to an in-memory cache could be implemented.

import bolster.security.{ Permission, SecurityContext, UserContext }

import scala.collection.concurrent.TrieMap

object SecureCache:
 // Define permissions to read and write cache entries
 private val getPermission = Permission("cache:get")
 private val putPermission = Permission("cache:put")

 private val cache = TrieMap[String, String](
   "gang starr"      -> "step in the arena",
   "digable planets" -> "blowout comb"
 )

 def get(key: String)(using security: SecurityContext): String =
   // Test for read permission before getting cache entry
   security(getPermission) { cache(key) }

 def put(key: String, value: String)(using security: SecurityContext): Unit =
   // Test for write permission before putting cache entry
   security(putPermission) { cache += key -> value }

// Set security context to include read permission
given SecurityContext = UserContext(Permission("cache:get"))

// Get cache entry
val classic = SecureCache.get("gang starr")

// Throw SecurityViolation because write permission is not granted
SecureCache.put("sucker mc", classic)

Attributes

Supertypes
class Object
trait Matchable
class Any
Known subtypes
object RootContext.type
trait UserContext
case class SecurityViolation(message: String) extends RuntimeException

Indicates security violation.

Indicates security violation.

Value parameters

message

detail message

Attributes

Constructor

Constructs SecurityViolation with supplied detail message.

Supertypes
trait Product
trait Equals
class RuntimeException
class Exception
class Throwable
trait Serializable
class Object
trait Matchable
class Any
Show all
sealed trait UserContext extends SecurityContext

Defines user context in which a set of permissions is granted.

Defines user context in which a set of permissions is granted.

Attributes

See also
Companion
object
Supertypes
class Object
trait Matchable
class Any
object UserContext

Provides user context factory.

Provides user context factory.

Attributes

Companion
trait
Supertypes
trait Sum
trait Mirror
class Object
trait Matchable
class Any
Self type