2011-07-28 11 views
1

我們正在使用Restlet 2.0.8,並且應用程序實例覆蓋org.restlet.Application#createInboundRoot()。在那裏,我們創造的路由器實例和回報(目前)一DigestAuthenticator,像下面的代碼剪斷:Restlet 2.0.8:用於單個restlet應用程序實例的多種身份驗證方法(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(可選:假)。僞代碼:

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

如果我錯了,請糾正我,但這意味着/ echo和/ status至少受基本權限保護? – Christof

+0

我們想要的只是Echo只受基本身份驗證的Digest和Status保護。 (僞碼): forkingRouter.attach(「/ status」,basicAuth,Template.MODE_STARTS_WITH)我們所做的是引入一個'分叉'路由器,並將digest-和basicAuth路由器連接到不同的路徑。 ; forkingRouter.attach(「/ echo」,digestAuth,Template.MODE_STARTS_WITH); – Christof

+0

這就是要走的路! –

0

在類似情況下,我們創建了兩個org.restlet.Application對象,必須驗證一個應用程序,如上面的問題,並沒有在Servlet容器連接這兩個應用程序以不同的路徑。

相關問題