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?

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top