cancel
Showing results for 
Search instead for 
Did you mean: 

how to get windows domain user in jsp

Former Member
0 Kudos

Does anybody know how to get domain user name who opened my jsp page ?

Maybe there is some api (SAP or other )?

I can run my project in portal maybe there is some portal api?

I tried this code in servlet but in my case it always prompt login pop up.

I want to read username without user interaction.

Maybe somebody can check this code in her/his enviroment.


			String auth = request.getHeader("Authorization");
			if (auth == null)
			{
			  response.setStatus(response.SC_UNAUTHORIZED);
			  response.setHeader("WWW-Authenticate", "NTLM");
			  response.flushBuffer();
			  return;
			}
			if (auth.startsWith("NTLM "))
			{
			  byte[] msg = new sun.misc.BASE64Decoder().decodeBuffer(auth.substring(5));
			  int off = 0, length, offset;
			  if (msg[8] == 1)
			  {
				byte z = 0;
				byte[] msg1 = {(byte)'N', (byte)'T', (byte)'L', (byte)'M', (byte)'S', (byte)'S', (byte)'P', 
				  z,(byte)2, z, z, z, z, z, z, z,(byte)40, z, z, z, 
				  (byte)1, (byte)130, z, z,z, (byte)2, (byte)2,
				  (byte)2, z, z, z, z, z, z, z, z, z, z, z, z};
				response.setHeader("WWW-Authenticate", "NTLM " + 
				   new sun.misc.BASE64Encoder().encodeBuffer(msg1));
				response.sendError(response.SC_UNAUTHORIZED);
				return;
			  }
			  else if (msg[8] == 3)
			  {
				off = 30;

				length = msg[off+17]*256 + msg[off+16];
				offset = msg[off+19]*256 + msg[off+18];
				String remoteHost = new String(msg, offset, length);

				length = msg[off+1]*256 + msg[off];
				offset = msg[off+3]*256 + msg[off+2];
				String domain = new String(msg, offset, length);

				length = msg[off+9]*256 + msg[off+8];
				offset = msg[off+11]*256 + msg[off+10];
				String username = new String(msg, offset, length);
				PrintWriter out = response.getWriter();
				out.println("Username:"+username+"<BR>");
				out.println("RemoteHost:"+remoteHost+"<BR>");
				out.println("Domain:"+domain+"<BR>");
			  }

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

(1)You have to access the window domain user values through the browser.

You have to load a java bean or invisible aplet and get the user name on the client machine.

But the user browser should enable running of java.

Some times the user logged in on windows server is different from the user logged on the j2ee server.

(2)If you also need to know the username on the windows server, you would need to develop an activex component and install it on the windows server so that you can get the user name by java native call from j2ee server.

Former Member
0 Kudos

Hi,

Do mean accessing System Properties. Have a look here.

<a href="http://java.sun.com/docs/books/tutorial/essential/environment/sysprop.html">accessing system properties in java</a>

HTH

Vivek Nidhi

Former Member
0 Kudos

Hi,

But the problem is that when I use get "user.name" property in jsp, I will get j2ee user who is logged on server, no user who entered my jsp page. And the second problem is that I cannot access user.name property in applet.

Former Member
0 Kudos

Hi,

In that case try to make use of UME API's

regards

Vivek Nidhi.