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);
}
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());
}
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...");
}
Aggregations