Search in sources :

Example 1 with FileSystemResourceFactory

use of io.milton.http.fs.FileSystemResourceFactory in project lobcder by skoulouzis.

the class HttpManagerBuilder method init.

/**
 * This method creates instances of required objects which have not been set
 * on the builder.
 *
 * These are subsequently wired together immutably in HttpManager when
 * buildHttpManager is called.
 *
 * You can call this before calling buildHttpManager if you would like to
 * modify property values on the created objects before HttpManager is
 * instantiated. Otherwise, you can call buildHttpManager directly and it
 * will call init if it has not been called
 */
public final void init() {
    if (listeners != null) {
        for (InitListener l : listeners) {
            l.beforeInit(this);
        }
    }
    if (mainResourceFactory == null) {
        if (fsHomeDir == null) {
            fsHomeDir = System.getProperty("user.home");
        }
        rootDir = new File(fsHomeDir);
        if (!rootDir.exists() || !rootDir.isDirectory()) {
            throw new RuntimeException("Root directory is not valid: " + rootDir.getAbsolutePath());
        }
        FileSystemResourceFactory fsResourceFactory = new FileSystemResourceFactory(rootDir, securityManager(), fsContextPath);
        fsResourceFactory.setContentService(fileContentService);
        mainResourceFactory = fsResourceFactory;
        log.info("Using file system with root directory: " + rootDir.getAbsolutePath());
    }
    log.info("Using mainResourceFactory: " + mainResourceFactory.getClass());
    if (authenticationService == null) {
        if (authenticationHandlers == null) {
            authenticationHandlers = new ArrayList<AuthenticationHandler>();
            if (basicHandler == null) {
                if (enableBasicAuth) {
                    basicHandler = new BasicAuthHandler();
                }
            }
            if (basicHandler != null) {
                authenticationHandlers.add(basicHandler);
            }
            if (digestHandler == null) {
                if (enableDigestAuth) {
                    if (nonceProvider == null) {
                        if (expiredNonceRemover == null) {
                            expiredNonceRemover = new ExpiredNonceRemover(nonces, nonceValiditySeconds);
                            showLog("expiredNonceRemover", expiredNonceRemover);
                        }
                        nonceProvider = new SimpleMemoryNonceProvider(nonceValiditySeconds, expiredNonceRemover, nonces);
                        showLog("nonceProvider", nonceProvider);
                    }
                    digestHandler = new DigestAuthenticationHandler(nonceProvider);
                }
            }
            if (digestHandler != null) {
                authenticationHandlers.add(digestHandler);
            }
            if (formAuthenticationHandler == null) {
                if (enableFormAuth) {
                    formAuthenticationHandler = new FormAuthenticationHandler();
                }
            }
            if (formAuthenticationHandler != null) {
                authenticationHandlers.add(formAuthenticationHandler);
            }
            if (extraAuthenticationHandlers != null && !extraAuthenticationHandlers.isEmpty()) {
                log.info("Adding extra auth handlers: " + extraAuthenticationHandlers.size());
                authenticationHandlers.addAll(extraAuthenticationHandlers);
            }
            if (cookieAuthenticationHandler == null) {
                if (enableCookieAuth) {
                    if (cookieDelegateHandlers == null) {
                        // Don't add digest!
                        // why not???
                        cookieDelegateHandlers = new ArrayList<AuthenticationHandler>();
                        if (basicHandler != null) {
                            cookieDelegateHandlers.add(basicHandler);
                            authenticationHandlers.remove(basicHandler);
                        }
                        if (digestHandler != null) {
                            cookieDelegateHandlers.add(digestHandler);
                            authenticationHandlers.remove(digestHandler);
                        }
                        if (formAuthenticationHandler != null) {
                            cookieDelegateHandlers.add(formAuthenticationHandler);
                            authenticationHandlers.remove(formAuthenticationHandler);
                        }
                    }
                    cookieAuthenticationHandler = new CookieAuthenticationHandler(cookieDelegateHandlers, mainResourceFactory);
                    authenticationHandlers.add(cookieAuthenticationHandler);
                }
            }
        }
        authenticationService = new AuthenticationService(authenticationHandlers);
        showLog("authenticationService", authenticationService);
    }
    init(authenticationService);
}
Also used : FileSystemResourceFactory(io.milton.http.fs.FileSystemResourceFactory) File(java.io.File)

Example 2 with FileSystemResourceFactory

use of io.milton.http.fs.FileSystemResourceFactory in project lobcder by skoulouzis.

the class FileSystemResourceFactoryTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    root = new File(System.getProperty("java.home"));
    SecurityManager sm = null;
    factory = new FileSystemResourceFactory(root, sm);
    System.out.println("testing with root: " + root.getAbsolutePath());
}
Also used : SecurityManager(io.milton.http.SecurityManager) FileSystemResourceFactory(io.milton.http.fs.FileSystemResourceFactory) File(java.io.File)

Example 3 with FileSystemResourceFactory

use of io.milton.http.fs.FileSystemResourceFactory in project lobcder by skoulouzis.

the class RestletFileserver method main.

public static void main(String[] args) throws Exception {
    Component component = new Component();
    component.getServers().add(Protocol.HTTP, 8080);
    // Restlet logs requests by default
    // component.getLogService().setEnabled(false);
    component.getDefaultHost().attach(new Application() {

        @Override
        public Restlet createInboundRoot() {
            FileSystemResourceFactory factory = new FileSystemResourceFactory(new File(System.getProperty("user.home")), new NullSecurityManager());
            factory.setContentService(new SimpleFileContentService());
            factory.setLockManager(new FsMemoryLockManager());
            return new WebDavRestlet(factory);
        }
    });
    component.start();
    System.out.println("Restlet demo fileserver started, open http://localhost:8080 in your browser or WebDAV client...");
}
Also used : Restlet(org.restlet.Restlet) WebDavRestlet(io.milton.restlet.WebDavRestlet) NullSecurityManager(io.milton.http.fs.NullSecurityManager) FileSystemResourceFactory(io.milton.http.fs.FileSystemResourceFactory) FsMemoryLockManager(io.milton.http.fs.FsMemoryLockManager) WebDavRestlet(io.milton.restlet.WebDavRestlet) Component(org.restlet.Component) SimpleFileContentService(io.milton.http.fs.SimpleFileContentService) Application(org.restlet.Application) File(java.io.File)

Aggregations

FileSystemResourceFactory (io.milton.http.fs.FileSystemResourceFactory)3 File (java.io.File)3 SecurityManager (io.milton.http.SecurityManager)1 FsMemoryLockManager (io.milton.http.fs.FsMemoryLockManager)1 NullSecurityManager (io.milton.http.fs.NullSecurityManager)1 SimpleFileContentService (io.milton.http.fs.SimpleFileContentService)1 WebDavRestlet (io.milton.restlet.WebDavRestlet)1 Application (org.restlet.Application)1 Component (org.restlet.Component)1 Restlet (org.restlet.Restlet)1