Skip to content

Instantly share code, notes, and snippets.

@imeredith
Created August 23, 2012 07:32
Show Gist options
  • Save imeredith/3433852 to your computer and use it in GitHub Desktop.
Save imeredith/3433852 to your computer and use it in GitHub Desktop.
for{
header <- Option(req.getHeader("Authorization"))
base64 <- Option(header.substring(0,6)) if base64.equals("Basic ")
encoded <- Option(header.substring(6))
auth <- Option(new String(new Base64().decode(encoded.getBytes))) if auth == "%s:%s".format(Config.basicUser, Config.basicPassword)
} yield auth
if(auth.isEmpty) {
resp.setHeader("WWW-Authenticate", "Basic Realm=\"cloudbees\"")
resp.setStatus(HttpServletResponse.SC_UNAUTHORIZED)
resp.flushBuffer
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment