Created
May 16, 2012 06:54
-
-
Save casualjim/2708163 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
post("/login") { | |
basicAuth | |
logger.debug("The user %s was successfully logged in.".format(params("userName"))) | |
} | |
error { | |
case ex => logger.error("there was an error requesting %s" format request.path, ex) | |
} | |
protected def basicAuth() = { | |
val req = new BasicAuthStrategy.BasicAuthRequest(request) | |
def notAuthenticated() { | |
response.setHeader("WWW-Authenticate", "Basic realm=\"%s\"" format realm) | |
halt(401, "Unauthenticated") | |
} | |
if(!req.providesAuth) { | |
notAuthenticated | |
} | |
if(!req.isBasicAuth) { | |
halt(400, "Bad Request") | |
} | |
val user = DAO.validateLoginPassword(req.user, req.password) | |
if (user != null) | |
response.headers("REMOTE_USER", user.id) | |
else { | |
notAuthenticated | |
} | |
Option(user) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment