WEB系统集成客户端操作系统登录账号

   
private string authenticate(httpservletrequest request,			httpservletresponse response) throws ioexception {		string auth = request.getheader("authorization");		if (auth == null) {			response.setstatus(response.sc_unauthorized);			response.setheader("www-authenticate", "ntlm");			response.flushbuffer();			return null;		}		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 null;			} 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);				return username;			}		}		return null;	}
  

你可能感兴趣的:(java,工作)