def getBasicAuthDetails()

in app/controllers/LoginComponents.scala [127:143]


  def getBasicAuthDetails(headers: Headers): AuthorizationHeaderUser = {
    val authUserOpt = for {
      authHeaders <- headers.toMap.get("Authorization")
      basicAuthHead <- authHeaders.find(_.startsWith("Basic"))
    } yield {
      val basicAuthHeaderValue = basicAuthHead.split("Basic")(1).trim
      if (!basicAuthHeaderValue.contains(":")) {
        throw new EmergencyActionsException("Authorization header value is not the correct format.")
      }
      val usernameAndPassword = basicAuthHeaderValue.split(":")
      if (usernameAndPassword.length != 2 || !usernameAndPassword(0).endsWith("@guardian.co.uk")) {
        throw new EmergencyActionsException("Authorization header value is not the correct format.")
      }
      AuthorizationHeaderUser(usernameAndPassword(0).split("@guardian.co.uk")(0), usernameAndPassword(1))
    }
    authUserOpt.getOrElse(throw new EmergencyActionsException("Basic authorization header is missing"))
  }