i have written a small grails webapp. I am using milton.io to access some content via webdav. So webdav is still working and i am able to put, get, delete files - and so on. But now i want to add authentication and authorization. And here is the problem:
The Resource Interface gives me 2 methods:
Object authenticate(String user, String password);
boolean authorise(Request request, Request.Method method, Auth auth);
So my Resource classes implements the Resource Interface, but the method authenticate is never called by the framework. Do i have to implement Auth Basic by my self?
My knowledge about milton is very poor. May be i forgot something, cause my webdav client (e.g. cadaver) never asks for a username / password.
Thanks for any help Peter Waver
Signature of my Resource Classes:
class SResource implements GetableResource, PropFindableResource, Resource, DeletableResource, MoveableResource, ReportableResource, CopyableResource
class SFileResource extends SResource implements ReplaceableResource
class SFolderResource extends SResource implements PutableResource, MakeCollectionableResource, CollectionResource
And here is the builder to get the HttpManager
class SMiltonConfig implements MiltonConfigurator {
protected HttpManagerBuilder builder;
protected List<Initable> initables;
protected HttpManager httpManager;
public SMiltonConfig(){
try {
// Attempt to use Enterprise edition build if available
Class builderClass = Class.forName("io.milton.ent.config.HttpManagerBuilderEnt");
builder = (HttpManagerBuilder) builderClass.newInstance();
println ("load Ent. HTTP Manager")
} catch (InstantiationException ex) {
builder = new HttpManagerBuilder();
println ("load Std. HTTP Manager")
} catch (IllegalAccessException ex) {
println ("load Std. HTTP Manager")
builder = new HttpManagerBuilder();
} catch (ClassNotFoundException ex) {
println ("load Std. HTTP Manager")
builder = new HttpManagerBuilder();
}
}
@Override
public HttpManager configure(Config arg0) throws ServletException {
ResourceFactory rf = new SResourceFactory();
builder.setMainResourceFactory(rf);
checkAddInitable(initables, builder.getMainResourceFactory());
httpManager = builder.buildHttpManager();
for( Initable i : initables ) {
i.init(config, httpManager);
}
return httpManager;
}
@Override
public void shutdown() {
httpManager.shutdown()
for( Initable i : initables ) {
i.destroy(httpManager);
}
}
private void checkAddInitable(List<Initable> initables, Object o) {
if( o instanceof Initable) {
initables.add((Initable)o);
} else if( o instanceof List ) {
for( Object o2 : (List)o) {
checkAddInitable(initables, o2);
}
}
}
}
And here the ResourceFactory
class SResourceFactory implements ResourceFactory {
def fileSystemService
public SResourceFactory(){
println "loading resource Factory"
def ctx = ServletContextHolder.servletContext.getAttribute(GrailsApplicationAttributes.APPLICATION_CONTEXT)
fileSystemService = ctx.fileSystemService
}
@Override
public Resource getResource(String host, String strPath)
throws NotAuthorizedException, BadRequestException {
SResource sfr
sfr = fileSystemService.getFolderByPath(strPath)
return sfr
}
}
If you need Basic Auth - you have to enable it. So add the following line to the config method of the SMiltonConfig Class.
builder.setEnableOptionsAuth(true); // enables auth
builder.setEnableBasicAuth(true); // optional
Here'S an example of the Resource authorise Method
@Override
public boolean authorise(Request r, Method m, Auth a) {
return a != null;
}
Hope it helps
Florian Pfann