[jcifs] NTLM http client

My Chi Doan thi-my-chi.doan at hp.com
Fri Oct 14 10:07:30 GMT 2005


Hi,

I have a simple application running on WebLogic Server 8.1., please see 
the attachments for more detail.

When opening the test.htlm page from Web browser, everything works fine. 
However, when I try to open the page from an ntlm http client, I get 
authentication error as listed below.

Did I miss something when using nltm http client?

Thanks a lot for your help.

Best regards
My Chi Doan

====================================================
Default credentials (jcifs.smb.client.username/password) not specified. 
SMB signing may not work propertly.  Skipping DC interrogation.
session established ok with AMERICAS<1C>/16.155.7.243
New data read: Transport1[AMERICAS<1C>/16.155.7.243:0]
00000: FF 53 4D 42 72 00 00 00 00 98 03 C0 00 00 00 00  |ÿSMBr......À....|
00010: 00 00 00 00 00 00 00 00 00 00 63 EA 00 00 08 00  |..........cê....|

byteCount=46 but readBytesWireFormat returned 24
Default credentials (jcifs.smb.client.username/password) not specified. 
SMB signing may not work propertly.  Skipping DC interrogation.
treeConnect: unc=\\AMERICAS\IPC$,service=?????
sessionSetup: accountName=thimdoan,primaryDomain=EMEA
SmbComSessionSetupAndX[command=SMB_COM_SESSION_SETUP_ANDX,received=false,errorCode=The 
operation completed 
successfully.,flags=0x0018,flags2=0xC003,signSeq=0,tid=0,pid=60003,uid=0,mid=9,wordCount=13,byteCount=101,andxCommand=0x75,andxOffset=162,snd_buf_size=16644,maxMpxCount=10,VC_NUMBER=1,sessionKey=0,passwordLength=24,unicodePasswordLength=24,capabilities=4180,accountName=thimdoan,primaryDomain=EMEA,NATIVE_OS=HP-UX,NATIVE_LANMAN=jCIFS]
SmbComTreeConnectAndX[command=SMB_COM_TREE_CONNECT_ANDX,received=false,errorCode=The 
operation completed 
successfully.,flags=0x0018,flags2=0x0000,signSeq=0,tid=0,pid=60003,uid=0,mid=0,wordCount=4,byteCount=39,andxCommand=0xFF,andxOffset=0,disconnectTid=false,passwordLength=1,password=,path=\\AMERICAS\IPC$,service=?????]
New data read: Transport1[AMERICAS<1C>/16.155.7.243:0]
00000: FF 53 4D 42 73 6D 00 00 C0 98 03 C0 00 00 00 00  |ÿSMBsm..À..À....|
00010: 00 00 00 00 00 00 00 00 00 00 63 EA 00 00 09 00  |..........cê....|

NtlmHttpFilter: EMEA\test_account: 0xC000006D: 
jcifs.smb.SmbAuthException: Logon failure: unknown user name or bad 
password.
Default credentials (jcifs.smb.client.username/password) not specified. 
SMB signing may not work propertly.  Skipping DC interrogation.
Default credentials (jcifs.smb.client.username/password) not specified. 
SMB signing may not work propertly.  Skipping DC interrogation.
treeConnect: unc=\\AMERICAS\IPC$,service=?????
sessionSetup: accountName=thimdoan,primaryDomain=EMEA
SmbComSessionSetupAndX[command=SMB_COM_SESSION_SETUP_ANDX,received=false,errorCode=The 
operation completed 
successfully.,flags=0x0018,flags2=0xC003,signSeq=0,tid=0,pid=60003,uid=0,mid=7,wordCount=13,byteCount=101,andxCommand=0x75,andxOffset=162,snd_buf_size=16644,maxMpxCount=10,VC_NUMBER=1,sessionKey=0,passwordLength=24,unicodePasswordLength=24,capabilities=4180,accountName=thimdoan,primaryDomain=EMEA,NATIVE_OS=HP-UX,NATIVE_LANMAN=jCIFS]
SmbComTreeConnectAndX[command=SMB_COM_TREE_CONNECT_ANDX,received=false,errorCode=The 
operation completed 
successfully.,flags=0x0018,flags2=0x0000,signSeq=0,tid=0,pid=60003,uid=0,mid=0,wordCount=4,byteCount=39,andxCommand=0xFF,andxOffset=0,disconnectTid=false,passwordLength=1,password=,path=\\AMERICAS\IPC$,service=?????]
New data read: Transport3[AMERICAS<1C>/16.112.229.243:0]
00000: FF 53 4D 42 73 6D 00 00 C0 98 03 C0 00 00 00 00  |ÿSMBsm..À..À....|
00010: 00 00 00 00 00 00 00 00 00 00 63 EA 00 00 07 00  |..........cê....|

NtlmHttpFilter: EMEA\test_account: 0xC000006D: 
jcifs.smb.SmbAuthException: Logon failure: unknown user name or bad 
password.

============================================================================

import jcifs.*;

public class NtlmHttpClient {

     public static void main(String[] args)  {

         Config.registerSmbURLHandler();

         if (args == null || args.length < 4) {
             System.out.println("NtlmHttpClient <url> <domain>
		<user> password>");
             System.exit(1);
         }
         String location = args[0];
         String domain = args[1];
         String user = args[2];
         String password = args[3];

         String encodeUserNamePassword = URLEncoder.encode(domain + "\\"
			+ user) + ":" + URLEncoder.encode(password);
	
         location = "http://" + encodeUserNamePassword + "@" + location;

         try {
             URL url = new URL(location);
             HttpURLConnection connection =
		(HttpURLConnection)url.openConnection();
             System.out.println("ResponseCode=" +
			connection.getResponseCode());
             if (connection.getResponseCode() == 401) {            	
               return;
             }
             BufferedReader in = new BufferedReader(
             	    new InputStreamReader(connection.getInputStream()));
             System.out.println("Login7");
             // What size is the document?
             int len = connection.getContentLength();
             System.out.println("Content Length: " + len);
             // Print the document
             String line;
             while ((line = in.readLine()) != null)
             	System.out.println(line);
             in.close();
         } catch (Exception e) {
         	e.printStackTrace();        	
         }
     }
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: weblogic.xml
Type: text/xml
Size: 352 bytes
Desc: not available
Url : http://lists.samba.org/archive/jcifs/attachments/20051014/04604044/weblogic.xml
-------------- next part --------------
HTML attachment scrubbed and removed
-------------- next part --------------
A non-text attachment was scrubbed...
Name: web.xml
Type: text/xml
Size: 1826 bytes
Desc: not available
Url : http://lists.samba.org/archive/jcifs/attachments/20051014/04604044/web.xml
-------------- next part --------------
import java.io.*;
import java.net.*;


import jcifs.*;

public class NtlmHttpClient {

    public static void main(String[] args)  {
        // Normally set this outside application.
        // Note that as a side effect due to the way handlers are located,
        // you can also achieve this by simply doing:
             Config.registerSmbURLHandler();
        // which we already do to register the smb handler.
        //String pkgs = System.getProperty("java.protocol.handler.pkgs");
        //pkgs = (pkgs != null) ? "jcifs|" + pkgs : "jcifs";
        //System.setProperty("java.protocol.handler.pkgs", pkgs);
        //

        if (args == null || args.length < 4) {
            System.out.println("NtlmHttpClient <url> <domain> <user> <password>");
            System.exit(1);
        }
        String location = args[0];
        String domain = args[1];
        String user = args[2];
        String password = args[3];
        String hpsbUsername = args[4];
        String hpsbPassword = args[5];
        String encodeUserNamePassword = URLEncoder.encode(domain + "\\" + user) + ":" + URLEncoder.encode(password);
	    
        //location = "http://" + encodeUserNamePassword + "@" + location+ "?j_username=" + hpsbUsername + "&j_password=" + hpsbPassword;
        location = "http://" + encodeUserNamePassword + "@" + location;
        System.out.println("location=" + location);
        System.out.println(Config.getProperty("jcifs.smb.client.username"));
        System.out.println(Config.getProperty("jcifs.smb.client.password"));
        // can also specify these in the URL, i.e.
        //     http://DOMAIN%5cuser:password@host/dir/file.html
        // which will override these properties
        //Config.setProperty("jcifs.smb.client.domain", domain);
        //Config.setProperty("jcifs.smb.client.username", user);
        //Config.setProperty("jcifs.smb.client.password", password);

        try {
        	URL url = new URL(location);
            HttpURLConnection connection = (HttpURLConnection)url.openConnection();
            System.out.println("ResponseCode=" + connection.getResponseCode());
            //BufferedReader in = new BufferedReader(
            //	    new InputStreamReader(connection.getInputStream()));
            if (connection.getResponseCode() == 401) {            	
              return;
            }
            BufferedReader in = new BufferedReader(
            	    new InputStreamReader(connection.getInputStream()));
            System.out.println("Login7");
            // What size is the document?
            int len = connection.getContentLength();
            System.out.println("Content Length: " + len);
            // Print the document
            String line;
            while ((line = in.readLine()) != null)
            	System.out.println(line);
            in.close();
        /*HttpURLConnection connection = (HttpURLConnection)
		url.openConnection();
        if (connection.getResponseCode() == 403) {
        	System.out.println("Error");
        }*/
        } catch (Exception e) {
        	e.printStackTrace();        	
        }
        
    }

}



More information about the jcifs mailing list