[jcifs] filtering the users home share (Was Re: davenport filters)

Mike Manley Mike at technomyth.co.uk
Sat Dec 18 00:33:36 GMT 2004

Michael B Allen wrote:

>On Fri, 17 Dec 2004 23:58:52 +0000
>Mike Manley <Mike at technomyth.co.uk> wrote:
>>I don't think putting the username
>>into an attribute of the [HttpSession] is an option, as I can't see how it
>>would be possible to ensure that the
>>currently set username on the [HttpSession] matched the session currently
>>being filtered when several clients were
>>connecting at the same time.
>HttpSession's are specific to the current http connection and NTLM HTTP
>authentication is specific to the current connection.
That makes sense but I don't have access to the HttpSession from within 
the accept method of the
smbFileFilter or do I?

I've included the code below so you can see how I'm trying to achieve 
this. I've omitted the
initialization code - it simply sets up the variables shares (list of 
allowed shares), allowBrowse
and allowHome from the properties from the XML. The init method is all 
that DavenportFileFilter
adds to jcifs.smb.smbFileFilter.

It maybe there's a better approach than the one I'm trying to use.

public class ShareFilter implements DavenportFileFilter {
    private Set shares;
    private boolean allowBrowse;
    private boolean allowHome;

    public void init(Properties properties) throws Exception {
       // initialization code omitted.

    public boolean accept(SmbFile file) throws SmbException {
        String share = file.getShare();
        if(share == null) {
            // If we're accepting root
            if(file.getServer() == null)
                // At server level - allow connection - server filter 
will stop it if required.
                return true;
            Log.log(Log.DEBUG, "Is server browse (0)", allowBrowse ? 
"accepting" : "rejecting");
            return allowBrowse;

             // TODO - check if share is the users home share and if so 
allow the connection.

        boolean status = shares.contains(share.toUpperCase());
        Log.log(Log.DEBUG, status ? "Share \"{0}\" is listed; accepting" :
                "Share \"{0}\" is not listed; rejecting", share);
        return status;



More information about the jcifs mailing list