2011-07-28 12 views
1

私たちはRestlet 2.0.8を使用しており、アプリケーションインスタンスがorg.restlet.Application#createInboundRoot()を上書きしています。そこでは、我々は(現時点では)DigestAuthenticatorをルータインスタンスとリターンを作成し、以下の切り取らコードのように:Restlet 2.0.8:シングルリセレット用の複数の認証方法(BASIC、DIGEST)アプリケーションインスタンス?

@Override 
public synchronized Restlet createInboundRoot() { 
    log.info("App::createInboundRoot called"); 

    this.authenticator = getAuthenticator(); 

    Router router = new Router(getContext()); 
    router.attach("/echo", EchoResource.class); 
    router.attach("/status", StatusResource.class); 

    authenticator.setNext(router); 
    return authenticator; 
} 

private ChallengeAuthenticator getAuthenticator() { 
    DigestAuthenticator auth = new DigestAuthenticator(getContext(), "Guard", "s3cret"); 
    auth.setWrappedVerifier(new SimpleVerifier("user","pass"); 
    auth.setOptional(false); 
    return auth; 
} 

私は何を達成したいことは次のとおりです。

  • はEchoResourceを使用していダイジェスト認証で、StatusResourceはHTTP基本認証を使用する必要があります

これはRestletsで可能ですか?

ベスト、 クリス

答えて

1

これは、(オプション:真)DigestAuthenticator連結することも可能であるとBasicAuthenticatorは(オプション:false)を。擬似コード:

digestAuth.setNext(basicAuth); 
    basicAuth.setNext(router); 
+0

私が間違っていれば私を訂正しますが、それは/ echoと/ statusの両方が基本的な認証権限によって少なくとも保護されていることを意味しますか? – Christof

+0

私たちが望んでいたのは、基本認証でダイジェストとステータスだけでエコーを保護することです。 私たちが行ったことは、 'フォーク'ルーターを導入し、digest-とbasicAuthルーターを異なるパスに接続することです(擬似コード)。 forkingRouter.attach( "/ status"、basicAuth、Template.MODE_STARTS_WITH) ; forkingRouter.attach( "/ echo"、digestAuth、Template.MODE_STARTS_WITH); – Christof

+0

それは行く方法です! –

0

似たような状況では、我々は、2つのorg.restlet.Applicationオブジェクトを作成した上で問題になっているように、1つのアプリケーションの認証を必要とし、サーブレットコンテナに異なるパスへのアプリケーションの両方を添付しました。

関連する問題