2

I am new to file server implementation. Alfresco jlan seems a good start as it's a pure Java implementation of most server protocols - CIFS, NFS and FTP. There are lot of threads devoted to alfresco, but not specific to jlan. How to setup jlan as a standalone java package in NetBeans?

Thanks in advance.

Lily Elite
  • 21
  • 1
  • 2
  • I think you'd want JLan on its own for this case, rather than the full Alfresco repository (which is much much more than just jlan). Did you try [downloading the JLan source](http://sourceforge.net/projects/alfresco/files/JLAN/Alfresco%20JLAN%205.0/) and adding that to your project? – Gagravarr Oct 30 '14 at 10:22
  • @Gagravarr 12 Thanks. Yeah I have tried that, but I am getting file not found error - missing jlanserver.xml – Lily Elite Oct 30 '14 at 23:23
  • I think you need to provide one of those giving ports, bindings etc. Ought to be a `.xml.sample` or similar in the source package, any luck finding one and filling it in? – Gagravarr Oct 31 '14 at 00:22

1 Answers1

5

Have a look at https://web.archive.org/web/20110925093759/https://svn.alfresco.com/repos/alfresco-open-mirror/alfresco/HEAD/root/projects/alfresco-jlan/

Here you will find a runsrv.bat (and runsrv.sh) script to bootstrap a JLANServer using the provided XML config: jlanConfig.xml

Since the provided files (jlanConfig.xml and JLANServer) are not part of the provided binaries (e.g. not part of alfresco-jlan-embed v5.0.b), you need to provide a similar setup yourself.

For example:

    ServerConfiguration cfg = new JLANFileServerConfiguration();

    NetBIOSNameServer netBIOSNameServer = new NetBIOSNameServer(cfg);
    cfg.addServer(netBIOSNameServer);
    SMBServer smbServer = new SMBServer(cfg);
    cfg.addServer(smbServer);

    // start servers
    for (int i = 0; i < cfg.numberOfServers(); i++) {
        NetworkServer server = cfg.getServer(i);
        server.startServer();
    }

The ServerConfiguration can be read from XML file, or constructed using Java code:

private static final String HOSTNAME = "JLANHOST";

private static final int DefaultThreadPoolInit  = 25;
private static final int DefaultThreadPoolMax   = 50;

private static final int[] DefaultMemoryPoolBufSizes  = { 256, 4096, 16384, 66000 };
private static final int[] DefaultMemoryPoolInitAlloc = {  20,   20,     5,     5 };
private static final int[] DefaultMemoryPoolMaxAlloc  = { 100,   50,    50,    50 };

public JLANFileServerConfiguration() throws InvalidConfigurationException, DeviceContextException {
    super(HOSTNAME);
    setServerName(HOSTNAME);

    // DEBUG
    DebugConfigSection debugConfig = new DebugConfigSection(this);
    final GenericConfigElement debugConfigElement = new GenericConfigElement("output");
    final GenericConfigElement logLevelConfigElement = new GenericConfigElement("logLevel");
    logLevelConfigElement.setValue("Debug");
    debugConfig.setDebug("org.alfresco.jlan.debug.ConsoleDebug", debugConfigElement);

    // CORE
    CoreServerConfigSection coreConfig = new CoreServerConfigSection(this);
    coreConfig.setMemoryPool( DefaultMemoryPoolBufSizes, DefaultMemoryPoolInitAlloc, DefaultMemoryPoolMaxAlloc);
    coreConfig.setThreadPool(DefaultThreadPoolInit, DefaultThreadPoolMax);
    coreConfig.getThreadPool().setDebug(true);

    // GLOBAL
    GlobalConfigSection globalConfig = new GlobalConfigSection(this);

    // SECURITY
    SecurityConfigSection secConfig = new SecurityConfigSection(this);
    DefaultAccessControlManager accessControlManager = new DefaultAccessControlManager();
    accessControlManager.setDebug(true);
    accessControlManager.initialize(this, new GenericConfigElement("aclManager"));
    secConfig.setAccessControlManager(accessControlManager);
    secConfig.setJCEProvider("cryptix.jce.provider.CryptixCrypto");
    final UserAccountList userAccounts = new UserAccountList();
    secConfig.setUserAccounts(userAccounts);

    // SHARES
    FilesystemsConfigSection filesysConfig = new FilesystemsConfigSection(this);
    DiskInterface diskInterface = new org.alfresco.jlan.smb.server.disk.JavaFileDiskDriver();
    final GenericConfigElement driverConfig = new GenericConfigElement("driver");
    final GenericConfigElement localPathConfig = new GenericConfigElement("LocalPath");
    localPathConfig.setValue(".");
    driverConfig.addChild(localPathConfig);
    DiskDeviceContext diskDeviceContext = (DiskDeviceContext) diskInterface.createContext("JLANSHARE", driverConfig);
    diskDeviceContext.setShareName("JLANSHARE");
    diskDeviceContext.setConfigurationParameters(driverConfig);
    diskDeviceContext.enableChangeHandler(false);
    diskDeviceContext.setDiskInformation(new SrvDiskInfo(2560000, 64, 512, 2304000));// Default to a 80Gb sized disk with 90% free space
    DiskSharedDevice diskDev = new DiskSharedDevice("JLANSHARE", diskInterface, diskDeviceContext);
    diskDev.setConfiguration(this);
    diskDev.setAccessControlList(secConfig.getGlobalAccessControls());
    diskDeviceContext.startFilesystem(diskDev);
    filesysConfig.addShare(diskDev);

    // SMB
    CIFSConfigSection cifsConfig = new CIFSConfigSection(this);
    cifsConfig.setServerName(HOSTNAME);
    cifsConfig.setDomainName("MYDOMAIN");
    cifsConfig.setHostAnnounceInterval(5);
    cifsConfig.setHostAnnouncer(true);
    final CifsAuthenticator authenticator = new LocalAuthenticator() {
        @Override
        public int authenticateUser(ClientInfo client, SrvSession sess, int alg) {
            return AUTH_ALLOW;
        }
    };
    authenticator.setDebug(true);
    authenticator.setAllowGuest(true);
    authenticator.setAccessMode(CifsAuthenticator.USER_MODE);
    final GenericConfigElement authenticatorConfigElement = new GenericConfigElement("authenticator");
    authenticator.initialize(this, authenticatorConfigElement);
    cifsConfig.setAuthenticator(authenticator);
    cifsConfig.setHostAnnounceDebug(true);
    cifsConfig.setNetBIOSDebug(true);
    cifsConfig.setSessionDebugFlags(-1);
    cifsConfig.setTcpipSMB(true);
}

Please be aware that in order to use JLAN on a Windows box, you need to disable the built-in file-sharing on port 445.

mhvelplund
  • 2,099
  • 3
  • 22
  • 38
blagerweij
  • 3,154
  • 1
  • 15
  • 20
  • Hi, I wanted to try your code, but it look like there is an error near CifsAuthenticator. Can you post an updated version or just explain what to do ? Thank you. – Filimindji Nov 26 '14 at 14:16
  • Sorry, I've removed the duplicate authenticator (the example above grants any user access). Updated. – blagerweij Nov 26 '14 at 14:34
  • Thank you for the update. Now authenticatorConfigElement is missing :-) – Filimindji Nov 26 '14 at 14:35
  • Again apologies, I had to remove our specific server configuration in the authentication section, which is why the snippet above was broken. I added this missing config-element line, should work now. – blagerweij Nov 26 '14 at 18:23