0

I've created a play-java web application, with the default Application controller:

package controllers;

import play.*;
import play.mvc.*;

public class Application extends Controller {

    public Result index() {
        String loggedUser = ""; // Would like to get the request logged in user somehow...
        return ok(loggedUser + ", Hi there!");
    }
}

What i need is to retrieve the user name which is logged in :
I'm visiting "http://localhost:9000" by chrome browser, and i need to retrieve the windows logged-in user which browses my play application, in order to check its premissions with our DB users tables.

In Servlet API - i think it was possible by using:

String name = request.getUserPrincipal().getName();
// Or
String name = request.getRemoteUser();

In ASP. MVC WebApi Controller- the correspond code is:

HttpContext.Current.User.Identity.Name

How can i implement it in play-framework simple java application?

====================
UPDATE:
i believe i need to implmenet windows authentication (NTLM) in play java application in order to get the windows username who browses my play application remotely. can someone please assist me with this?

AmirTNinja
  • 357
  • 3
  • 5
  • 15
  • This seems like it could be easily done from [java](http://stackoverflow.com/questions/473446/java-current-machine-name-and-logged-in-user). Its not necessarily a Play issue if i understand correctly. If your intention is to get the user name of a persons computer who browses your site remotely then that's not possible for (hopefully) obvious security reasons. On the other hand if you wanted to get the user logged in to your web app then you would have to roll your own authentication (or search for play plugins) as play doesnt provide this out of the box. – jsonmurphy Jul 07 '15 at 13:11
  • Tnx. my intention is to get the Windows\ActiveDirerctory username which logged in to my web app (who browses my site remotely). In Asp.net controllers or servlet app it was possible with simple code as the examlpes i mentioned above. I beileve i maybe need to manage WindowsAuthentication, am i right? – AmirTNinja Jul 07 '15 at 13:50
  • I'm affraid this is where my expertise ends, I'm not too familiar with Windows/Active Directory environments but a quick google search brought up the following which might be of interest to you: [one](http://stackoverflow.com/questions/4751157/integrated-windows-authentication-ntlm-in-a-java-weblogic-app) & [two](http://stackoverflow.com/questions/20102113/windows-logged-on-user-sso-in-play-framework-2) – jsonmurphy Jul 07 '15 at 14:03
  • I've encountered with the links that you found, but still couldn't found a simple and clear tutorial that can guide me how to achieve the user context details that called my play action. hope that someone can still assist me on that – AmirTNinja Jul 07 '15 at 15:41
  • Can someone please assist me about adding windows (ntlm) authentication in order that i'll be able to get the windows user name who browses my play java site remotely? it's really urgent!! – AmirTNinja Jul 15 '15 at 13:53

0 Answers0