[jcifs] how to cache NtlmPasswordAuthentication

Michael B Allen ioplex at gmail.com
Tue Sep 8 10:13:02 MDT 2009

On Tue, Sep 8, 2009 at 3:17 AM, snowc<chsnow123 at gmail.com> wrote:
> 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,

Sounds like a name service problem. Try setting jcifs.resolveOrder=DNS
and make sure you use a fully qualified DNS hostname in your SMB URL.

> presumably for the authentication to take place.  The next images in the
> batch are loaded quickly.

Authentication should take only a few milliseconds unless the Samba
server is not configured properly in which case it may be the delay.
But if you can connect to it quickly using something other than JCIFS,
this is probably not the issue.

> 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,
> Chris
> ----
> public class SmbUtil {
>        private static NtlmPasswordAuthentication auth;
>        static {
>                String wins = UtilProperties.getPropertyValue("Config.properties",
> "smb.wins");
>                String smbdc = UtilProperties.getPropertyValue("Config.properties",
> "smb.dc");
>                String domain = UtilProperties.getPropertyValue("Config.properties",
> "smb.domain");
>                String userName = UtilProperties.getPropertyValue("Config.properties",
> "smb.userName");
>                String password = UtilProperties.getPropertyValue("Config.properties",
> "smb.password");
>                try {
>                        jcifs.Config.setProperty( "jcifs.netbios.wins", wins );

Do you really use WINS? Does anyone really use WINS anymore? If yes,
you will need to set jcifs.resolveOrder=WINS and make sure your WINS
properties are correct.

>                        jcifs.Config.setProperty( "jcifs.netbios.cachePolicy", "-1" );
>                        jcifs.Config.setProperty( "jcifs.smb.client.soTimeout", "100000");
>                        jcifs.Config.setProperty( "jcifs.netbios.soTimeout", "100000");

I would not set any of the above. You'll cause more harm than good I think.


Michael B Allen
Java Active Directory Integration

More information about the jCIFS mailing list