Skip to content

Commit

Permalink
#25 Add API key authentication type
Browse files Browse the repository at this point in the history
  • Loading branch information
To-om committed Nov 20, 2017
1 parent 62b0668 commit 368dfd2
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 16 deletions.
7 changes: 1 addition & 6 deletions app/org/elastic4play/services/UserSrv.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,10 @@ trait User {

object AuthCapability extends Enumeration {
type Type = Value
val changePassword, setPassword, allowKey = Value
val changePassword, setPassword = Value
}

trait AuthSrv {
protected final def generateKey(): String = {
val bytes = Array.ofDim[Byte](24)
Random.nextBytes(bytes)
Base64.getEncoder.encodeToString(bytes)
}
val name: String
val capabilities = Set.empty[AuthCapability.Type]

Expand Down
11 changes: 1 addition & 10 deletions app/org/elastic4play/services/auth/LdapAuthSrv.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ class LdapAuthSrvFactory @Inject() (
configuration.get[String]("auth.ldap.bindPW"),
configuration.get[String]("auth.ldap.baseDN"),
configuration.get[String]("auth.ldap.filter"),
configuration.getOptional[String]("auth.ldap.keyAttribute"),
configuration.getOptional[String]("auth.ldap.keyFilter"),
configuration.getOptional[String]("auth.ldap.loginAttribute").getOrElse("uid"),
userSrv,
ec)

Expand All @@ -41,18 +38,12 @@ class LdapAuthSrvFactory @Inject() (
bindPW: String,
baseDN: String,
filter: String,
keyAttribute: Option[String],
keyFilter: Option[String],
loginAttribute: String,
userSrv: UserSrv,
implicit val ec: ExecutionContext) extends AuthSrv {

private[LdapAuthSrv] lazy val logger = Logger(getClass)
val name = "ldap"
override val capabilities: Set[AuthCapability.Value] = keyAttribute match {
case Some(_) Set(AuthCapability.changePassword, AuthCapability.allowKey)
case None Set(AuthCapability.changePassword)
}
val capabilities = Set(AuthCapability.changePassword)

private[auth] def connect[A](username: String, password: String)(f: InitialDirContext Try[A]): Try[A] = {
val protocol = if (useSSL) "ldaps://" else "ldap://"
Expand Down

0 comments on commit 368dfd2

Please sign in to comment.