Skip to content
This repository has been archived by the owner on Sep 12, 2021. It is now read-only.

Commit

Permalink
Merge pull request #337 from cemcatik/basic
Browse files Browse the repository at this point in the history
BasicAuthProvider should check the method is Basic
  • Loading branch information
akkie committed May 5, 2015
2 parents 7163750 + 93972d7 commit 0eca774
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,12 @@ class BasicAuthProvider(
*/
def getCredentials(request: RequestHeader): Option[Credentials] = {
request.headers.get(HeaderNames.AUTHORIZATION) match {
case Some(header) => Base64.decode(header.replace("Basic ", "")).split(":") match {
case credentials if credentials.length == 2 => Some(Credentials(credentials(0), credentials(1)))
case _ => None
}
case None => None
case Some(header) if header.startsWith("Basic ") =>
Base64.decode(header.replace("Basic ", "")).split(":") match {
case credentials if credentials.length == 2 => Some(Credentials(credentials(0), credentials(1)))
case _ => None
}
case _ => None
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ class BasicAuthProviderSpec extends PlaySpecification with Mockito {
await(provider.authenticate(request)) must beSome(loginInfo)
there was one(authInfoRepository).update(loginInfo, passwordInfo)
}

"return None if Authorization method is not Basic and Base64 decoded header has ':'" in new WithApplication with Context {
val request = FakeRequest().withHeaders(AUTHORIZATION -> Base64.encode("NotBasic foo:bar"))

await(provider.authenticate(request)) must beNone
}
}

/**
Expand Down

0 comments on commit 0eca774

Please sign in to comment.