[jcifs] Need help authenicating URL's using jcifs

learning hortonjw at yahoo.com
Tue Sep 4 20:48:59 GMT 2007


I need to verify if certain URL's exists.  I am currently using jcifs to help
me handle the task.  As a test I have slightly modified the NtlmHttpClient
sample file provided by the jcifs.samba.org site as seen below.  Anytime I
run the code on a UNIX server I get the following error:

Exception in thread "main" java.lang.RuntimeException:
java.lang.NullPointerException 
        at
sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:904) 
        at
jcifs.http.NtlmHttpURLConnection.getInputStream(NtlmHttpURLConnection.java:242) 
        at java.net.URL.openStream(URL.java:1007) 
        at NtlmHttpClient.main(NtlmHttpClient.java:43) 
Caused by: java.lang.NullPointerException 
        at
sun.net.www.protocol.http.NTLMAuthentication.init(NTLMAuthentication.java:138) 
        at
sun.net.www.protocol.http.NTLMAuthentication.<init>(NTLMAuthentication.java:133) 
        at
sun.net.www.protocol.http.HttpURLConnection.getServerAuthentication(HttpURLConnection.java:1582) 
        at
sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1035) 
        at
sun.net.www.protocol.http.HttpURLConnection.getHeaderField(HttpURLConnection.java:1941) 
        at
jcifs.http.NtlmHttpURLConnection.parseResponseCode(NtlmHttpURLConnection.java:424) 
        at
jcifs.http.NtlmHttpURLConnection.doHandshake(NtlmHttpURLConnection.java:436) 
        at
jcifs.http.NtlmHttpURLConnection.handshake(NtlmHttpURLConnection.java:103) 
        at
jcifs.http.NtlmHttpURLConnection.getInputStream(NtlmHttpURLConnection.java:240) 
        ... 2 more 


I have been able to determine that the error is generated cause the user
credentials were not passed correctly.  When I run the same code on a PC it
works because my Windows credentials are passed transparently.  The
credentials in the java code are completely over-looked.  I do know the
credentials I am passing are correct because I use the same credentials to
verify some smb:// links as well in a different java program using jcifs.  I
also know the url is correct because if I paste it into firefox a user
authentication window will popup and once I type in the following
credentials :

username: some.domain.com\username
password: P at ssw0rd

The file will prompt to be saved or opened.

Could someone please take a look at the code and tell me if I am missing
something or doing something wrong?

import java.io.*;
import java.net.*;
import jcifs.*;

public class NtlmHttpClient {

    public static void main(String[] args) throws Exception {
        Config.registerSmbURLHandler();

        Config.setProperty("jcifs.smb.client.domain", "some.domain.com");
        Config.setProperty("jcifs.smb.client.username", "username");
        Config.setProperty("jcifs.smb.client.password", "P at ssw0rd");

        try {
            Config.setProperty("jcifs.netbios.hostname",
                    Config.getProperty("jcifs.netbios.hostname",
                            InetAddress.getLocalHost().getHostName()));
        } catch (Exception ex) { }
        URL url = new
URL("http://portal/ISO/Department/test/Metrics/1234_METRIC_Mar07.xls");
	//URL url = new
URL("http://some.domain.com%5Cusername:P%40ssw0rd@portal/ISO/Department/test/Metrics/1234_METRIC_Mar07.xls");
        BufferedReader reader = new BufferedReader(
                new InputStreamReader(url.openStream()));
        String line;
        while ((line = reader.readLine()) != null) {
            System.out.println(line);
        }
    }

}


Jessie
-- 
View this message in context: http://www.nabble.com/Need-help-authenicating-URL%27s-using-jcifs-tf4380217.html#a12486344
Sent from the Samba - jcifs mailing list archive at Nabble.com.



More information about the jcifs mailing list