Created
February 7, 2021 23:51
-
-
Save deanwampler/ef5587caa4ff8c2ceb3ffdd444a84f32 to your computer and use it in GitHub Desktop.
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
// Adapted from Programming Scala, Third Edition code repo: | |
// https://github.com/deanwampler/programming-scala-book-code-examples/blob/master/src/script/scala/progscala3/basicoop/Exports.scala | |
import java.net.URL | |
case class UserName(value: String): | |
assert(value.length > 0) | |
case class Password(value: String): | |
assert(value.length > 0) | |
trait Authenticate: | |
final def apply( | |
username: UserName, password: Password): Boolean = | |
authenticated = auth(username, password) | |
authenticated | |
def isAuthenticated: Boolean = authenticated | |
private var authenticated = false | |
protected def auth(username: UserName, password: Password): Boolean | |
class DirectoryAuthenticate(location: URL) extends Authenticate: | |
protected def auth(username: UserName, password: Password): Boolean = true | |
object Service: | |
private val dirAuthenticate = | |
DirectoryAuthenticate(URL("https://directory.wtf")) | |
export dirAuthenticate.{apply => authenticate, isAuthenticated} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment