windows authentication using java
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Monday, February 25, 2008 12:30 AM

Windows Authentication using java had some problem? Hi folks, I use NTML windows authentication for java its working fine but when other user hit the url then they are prompted for user name and password , but what i preferred is once other user user log in to system and hit the URL he should be log in automatically this should be applicable for all users. How can i do this can any one let me know to solve this problem. This is my code as follows: try { String auth = request.getHeader("Authorization") System.out.println("********"+auth) if (auth == null) { response.setStatus(response.SC_UNAUTHORIZED) response   More>>

Windows Authentication using java had some problem?


Hi folks,
I use NTML windows authentication for java its working fine but when other user hit the url then they are prompted for user name and password , but what i preferred is once other user user log in to system and hit the URL he should be log in automatically this should be applicable for all users.
How can i do this can any one let me know to solve this problem.

This is my code as follows:
try
{
String auth = request.getHeader("Authorization")


System.out.println("********"+auth)


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("USER NAME :"+username+"
")


out.println("Remote Host:"+remoteHost+"
")


out.println("Domain:"+domain+"
")


}
}
}catch(Exception e){
e.printStackTrace()


}


Regards,
Rajeshwar.

   <<Less
About | Sitemap | Contact