Q:

How to access credentials passed in the authentication popup for a 401 response

I need to implement ActiveDirectory based authentication on my site I am developin gusing Play framework.  As a demo, I created a sample app
public static Result index() 
{
    boolean IsLoggedIn = false;
    String authorization = request().getHeader(AUTHORIZATION);

    if(!IsLoggedIn)
    {
        String usrnm = request().username();
        response().setHeader(WWW_AUTHENTICATE, "Basic realm=\"Enter Your ID and password\"");    
        return unauthorized("You Need to Login first");
    }
    return ok("Welcome to nowhere");
}

This opens a authentication popup on the client.  Now, how do I access these credentials? 

A:

OK, I found the answer
 String authorization = request().getHeader(AUTHORIZATION);

The authorization header contains the username:password in a base64 encoded form. 
AUTHORIZATION = "Basic oa76dfexvdd3=="

here, if you decode oa76dfexvdd3==, you will get something like "myusr:mypwd", which you can then use for the authentication.