2012-02-11 12 views
1

私はサーバー側でHTTPダイジェスト認証メカニズムを使用しています。クライアントはfirefoxです。RestletでのHTTP認証、子のURLの認証

これは、単一の静的ログイン/秘密のペアを読み込み、サーバー側のコード

Application application = new Vehicle(); 

component.getDefaultHost().attachDefault(application); 
component.getDefaultHost().attach("/home",new Home()); 

DigestAuthenticator guard = new DigestAuthenticator(null, "TestRealm","mySecretServerKey"); 
Instantiates a Verifier of identifier/secret couples based on a simple Map. 
MapVerifier mapVerifier = new MapVerifier(); 

です。

mapVerifier.getLocalSecrets().put("login", "secret".toCharArray()); 
guard.setWrappedVerifier(mapVerifier); 

ガードホームクラス

Router router = new Router(getContext()); 
router.attach("/People", People.class); 
router.attach("/categories/",Categories.class); 

return router; 

でのRestlet

guard.setNext(application); 
component.getDefaultHost().attachDefault(guard); 
component.start(); 

私が要求した場合http://localhost:8182/ HTTP認証は機能していますが、私たちが代わりに/home/categories/のためにしてみてください最初の場合http://localhost:8182/home/categories/はどのhttp authenticationを求めていませんhttp://localhost:8182/の場合は、認証メカニズムsm。これを解決するには?

答えて

0

デフォルトのルートだけにガードを接続しているため、他のルートと一致しないルートもあります。 attachDefaultのJavadocを参照してください:

* Attaches a Resource class to this router as the default target to invoke 
* when no route matches. It actually sets a default route that scores all 
* calls to 1.0. 

あなたの他のルートは、デフォルトルートではありませんので、彼らは

router.attach("/People", People.class); 
router.attach("/categories/",Categories.class); 

を守っていないあなたは、このように保護したい各ルート間のガードを配線する必要があります:

DigestAuthenticator peopleGuard = new DigestAuthenticator(null, "TestRealm","mySecretServerKey"); 
peopleGuard.setNext(People.class); 
router.attach("/People", peopleGuard); 
+0

返信いただきありがとうございます。ご提案をお試しになります。 – ridy