VFS JCIFS-NG Provider

A jcifs-ng based file system provider for Apache Commons VFS

License

License

Categories

Categories

Net Auto Application Layer Libs Code Generators
GroupId

GroupId

net.idauto.oss.jcifs
ArtifactId

ArtifactId

vfs-jcifs-ng
Last Version

Last Version

1.0.1
Release Date

Release Date

Type

Type

jar
Description

Description

VFS JCIFS-NG Provider
A jcifs-ng based file system provider for Apache Commons VFS
Project URL

Project URL

https://github.com/IdentityAutomation/vfs-jcifs-ng
Source Code Management

Source Code Management

https://github.com/IdentityAutomation/vfs-jcifs-ng

Download vfs-jcifs-ng

How to add to project

<!-- https://jarcasting.com/artifacts/net.idauto.oss.jcifs/vfs-jcifs-ng/ -->
<dependency>
    <groupId>net.idauto.oss.jcifs</groupId>
    <artifactId>vfs-jcifs-ng</artifactId>
    <version>1.0.1</version>
</dependency>
// https://jarcasting.com/artifacts/net.idauto.oss.jcifs/vfs-jcifs-ng/
implementation 'net.idauto.oss.jcifs:vfs-jcifs-ng:1.0.1'
// https://jarcasting.com/artifacts/net.idauto.oss.jcifs/vfs-jcifs-ng/
implementation ("net.idauto.oss.jcifs:vfs-jcifs-ng:1.0.1")
'net.idauto.oss.jcifs:vfs-jcifs-ng:jar:1.0.1'
<dependency org="net.idauto.oss.jcifs" name="vfs-jcifs-ng" rev="1.0.1">
  <artifact name="vfs-jcifs-ng" type="jar" />
</dependency>
@Grapes(
@Grab(group='net.idauto.oss.jcifs', module='vfs-jcifs-ng', version='1.0.1')
)
libraryDependencies += "net.idauto.oss.jcifs" % "vfs-jcifs-ng" % "1.0.1"
[net.idauto.oss.jcifs/vfs-jcifs-ng "1.0.1"]

Dependencies

provided (3)

Group / Artifact Type Version
org.apache.commons : commons-vfs2 jar 2.2
org.slf4j : jcl-over-slf4j jar 1.7.21
eu.agno3.jcifs : jcifs-ng jar 2.0.4

test (4)

Group / Artifact Type Version
org.apache.commons : commons-vfs2 test-jar 2.2
junit : junit jar 4.12
commons-io : commons-io jar 2.5
org.slf4j : slf4j-log4j12 jar 1.7.24

Project Modules

There are no modules declared in this project.

vfs-jcifs-ng

SMB Provider for Apache commons-vfs (Virtual File System) based on jcifs-ng

This is pretty much the code for the CIFS provider available in the Commons VFS Sandbox changed slightly to account for the API changes between the original JCIFS and JCIFS-NG.

Maven

<dependency>
    <groupId>net.idauto.oss.jcifs</groupId>
    <artifactId>vfs-jcifs-ng</artifactId>
    <version>1.0.1</version>
</dependency>

Notes

  • You must provide the versions of Commons VFS (tested with 2.1 and 2.2), and jcifs-ng (tested with 2.0.4, and 2.1.0-SNAPSHOT) that you wish to use.
<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-vfs2</artifactId>
    <version>2.2</version>
</dependency>
<dependency>
    <groupId>eu.agno3.jcifs</groupId>
    <artifactId>jcifs-ng</artifactId>
    <version>2.1.0-SNAPSHOT</version>
</dependency>
  • Commons VFS uses Apache Commons Logging and JCIFS-NG used SLF4J, so to get full logging you need to account for both.
  • JCIFS-NG apparently needs Unlimited Crypto enabled for the JVM, but that may depend on servers you are connecting to.
  • I didn't implement support for the deprecated practice of putting the credentials in the url. You can provide the credentials in either the CIFSContext or using StaticUserAuthenticator.
  • By default the SingletonContext will be used, but you can provide a customized CIFSContext using SmbFileSystemConfigBuilder.setCIFSContext()
  • An example of using StaticUserAuthenticator for authentication and a custom CIFSContext:
import jcifs.CIFSContext;
import jcifs.CIFSException;
import jcifs.config.PropertyConfiguration;
import jcifs.context.BaseContext;
import org.apache.commons.vfs2.*;
import org.apache.commons.vfs2.auth.StaticUserAuthenticator;
import org.apache.commons.vfs2.impl.DefaultFileSystemConfigBuilder;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.Properties;

public class Example {
    public static void main(String[] args) throws CIFSException, FileSystemException, URISyntaxException {
        if (args.length != 3) {
            System.err.println(" Usage: Example <server> <username> <password>");
            System.exit(-1);
        }

        final String host = args[0];
        final String username = args[1];
        final String password = args[2];

        final URI uri = new URI("smb", host, "/C$", null);

        // authentication
        StaticUserAuthenticator auth = new StaticUserAuthenticator(null, username, password);

        // jcifs configuration
        Properties jcifsProperties = new Properties();

        // these settings are needed for 2.0.x to use anything but SMB1, 2.1.x enables by default and will ignore
        jcifsProperties.setProperty("jcifs.smb.client.enableSMB2", "true");
        jcifsProperties.setProperty("jcifs.smb.client.useSMB2Negotiation", "true");

        CIFSContext jcifsContext = new BaseContext(new PropertyConfiguration(jcifsProperties));

        // pass in both to VFS
        FileSystemOptions options = new FileSystemOptions();
        DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(options, auth);
        SmbFileSystemConfigBuilder.getInstance().setCIFSContext(options, jcifsContext);

        final FileSystemManager fsManager = VFS.getManager();
        try (FileObject file = fsManager.resolveFile(uri.toString(), options)) {
            for (FileObject child : file.getChildren()) {
                System.out.println(child.getName());
            }
        }
    }
}
net.idauto.oss.jcifs

Identity Automation

Versions

Version
1.0.1
1.0.0