2

私は小さなgrailswebappを作成しました。milton.ioを使用して、webdav経由で一部のコンテンツにアクセスしています。したがって、webdavはまだ機能しており、ファイルの配置、取得、削除などを行うことができます。しかし今、私は認証と承認を追加したいと思います。そしてここに問題があります:

リソースインターフェイスには2つの方法があります。

Object authenticate(String user, String password);
boolean authorise(Request request, Request.Method method, Auth auth);

したがって、私のResourceクラスはResource Interfaceを実装しますが、メソッドauthenticateがフレームワークによって呼び出されることはありません。Auth Basicを自分で実装する必要がありますか?

ミルトンについての私の知識は非常に貧弱です。何かを忘れた可能性があります。私のwebdavクライアント(例:cadaver)がユーザー名/パスワードを要求しないためです。

助けてくれてありがとうピーターウェイバー

私のリソースクラスの署名:

class SResource implements GetableResource, PropFindableResource, Resource, DeletableResource, MoveableResource,  ReportableResource, CopyableResource 

class SFileResource extends SResource implements ReplaceableResource

class SFolderResource extends SResource implements PutableResource, MakeCollectionableResource, CollectionResource

そして、これが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);
        }
    }
}
}

そしてここに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
}
}
4

1 に答える 1

1

基本認証が必要な場合は、有効にする必要があります。そのため、次の行を SMiltonConfig クラスの config メソッドに追加します。

builder.setEnableOptionsAuth(true); // enables auth
builder.setEnableBasicAuth(true);   // optional 

Resource authorize メソッドの例を次に示します。

    @Override
    public boolean authorise(Request r, Method m, Auth a) {
       return a != null;
    }

それが役に立てば幸い

フロリアン・プファン

于 2012-10-19T10:49:55.573 に答える