[jcifs] how to cache NtlmPasswordAuthentication

snowc chsnow123 at gmail.com
Tue Sep 8 01:17:05 MDT 2009

I have an web application that accesses images on a samba server.  The
application always connects to the samba server with the same user name and
password.  A typical scenario is that the application retrieves 10 to 20
images from the samba server  This process repeats, serving up different
batches of images to the web app users.

There is a delay of a few seconds retrieving the first image in the batch,
presumably for the authentication to take place.  The next images in the
batch are loaded quickly.

I can't see how I can decrease the delay retrieving the first image in the
batch.  I have tried tweaking the jcifs properties but I'm not getting
anywhere (code below).

Any pointers would be greatly appreciated!

Many thanks in advance,



public class SmbUtil {

	private static NtlmPasswordAuthentication auth;

	static {
		String wins = UtilProperties.getPropertyValue("Config.properties",
		String smbdc = UtilProperties.getPropertyValue("Config.properties",
		String domain = UtilProperties.getPropertyValue("Config.properties",
		String userName = UtilProperties.getPropertyValue("Config.properties",
		String password = UtilProperties.getPropertyValue("Config.properties",
		try {
			jcifs.Config.setProperty( "jcifs.netbios.wins", wins );
			jcifs.Config.setProperty( "jcifs.netbios.cachePolicy", "-1" );
			jcifs.Config.setProperty( "jcifs.smb.client.soTimeout", "100000");
			jcifs.Config.setProperty( "jcifs.netbios.soTimeout", "100000");
			UniAddress dc = UniAddress.getByName( smbdc );
			auth = new NtlmPasswordAuthentication( domain, userName, password );
			SmbSession.logon( dc, auth );
		} catch (...) {
	public static NtlmPasswordAuthentication getSmbAuth() throws Exception {
		return auth;

The code for serving the images is:

	// doGet() - runs once for each image in the batch
	auth = SmbUtil.getSmbAuth();
	SmbFile file = new SmbFile(filename, auth);
	in = new SmbFileInputStream(file);
	bytes = IOUtils.toByteArray(in);
	// return bytes;

View this message in context: http://www.nabble.com/how-to-cache-NtlmPasswordAuthentication-tp25340981p25340981.html
Sent from the Samba - jcifs mailing list archive at Nabble.com.

More information about the jCIFS mailing list