Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Get NT user name  RSS feed

 
John Williamer
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a problem that been bothering me for a while now. Can somone post some code that will show me how to do this. I've looked at many different sites but they all seem to give the theory but no real examples. This would help me greatly.
JavaRanch is my last hope, please help.
 
Rob Ross
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You realize this is a platform-dependant feature right?
On my Windows2000 machine I can get the current user name via the System property "user.name."
String userName = System.getProperty("user.name");
[ May 15, 2002: Message edited by: Rob Ross ]
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You realize this is a platform-dependant feature right?
Sort of. In fact "user.name" is guaranteed to exist as a System property, as specified in teh docs for System.getProperties(). I suppose the meaning of the String returned is platform-dependant. You could have an operating system that does not even use the concept of "user", in which this method might return a blank String I suppose. I don't know if such an OS actually exists, while also supporting Java. It seems theoretically possible, but unlikely.
Anyway though - System.getProperty("user.name") should work on just about any operating system you're running Java on.
 
Rob Ross
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well I think MRJ 1.1.8 (Macintosh Runtime for Java) that runs under OS 9 probably wouldn't have a meaningful value for user.name. As I recall, there's no concept of a "current user". Although, it may just use the name of the machine as the user name.
But yea, other than that, I haven't used an OS that doesn't have a concept of a user log-in.
 
Bhavesh Ravjee
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I have a jsp that is required to get the "user.name" of the person requesting the page. Since the scriplet is executing on the server
it always comes up with the same name. How do I get it to return the
requesting user's "user.name"
 
Joe Ess
Bartender
Posts: 9429
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's no way for a server to know a user name through HTTP. The usual work-around is to have a login screen and use a session to identify the user in subsequent screens. One can also use a client-side cookie to identify the user in later visits after the session expires.
 
Tim Holloway
Bartender
Posts: 18709
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Joe Ess:
There's no way for a server to know a user name through HTTP.


And this is because the Web is a stateless transaction space. Web clients can make requests from a browser under, say, MS-DOS (which very definitely didn't know what a "user id" was). I'm not exaggerating, BTW. The Lynx and links HTTP browsers are text-mode only and will operate under virtually any OS that has support for network connections. I also briefly played around with an MS-DOS GUI browset named Arachne back when the Earth was still young and so was the Internet.

The "User ID" under Windows actually referes to (at least) 2 distinct user identities, which Microsoft has blurred together for convenience. The first User Id is the login to the local machine's resources. This user ID existed in only primitive form - when it existed at all - under Windows 3.1 and the 9x versions of Windows (including Windows ME). The second User Id is the user's identity under Windows Networking. That's their ID in the Doamin or Workgroup.

Since the web is very definitely not one big Windows Network (some of us aren't even using Windows to access it), the Windows User IDs are not accessible or meaningful and each web implementor has to establish a suitable user identity themselves. Most times it's site specific, such as your user name when you log into JavaRanch. MS-Passport, OTOH, was designed to provide a Single-Signon solution for the entire world. The world has been rather cool to the idea of Microsoft being its trusted authenticator.

Within an Intranet, you CAN make the user's WWindows ID available to internal web sites as part of an enterprise SSO. However this uses properietary Microsoft protocols. Also, for a rarity in Microsoft, this security mechanism is blocked by default. You have to explicitly activate each user's browser to support them.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!