0

我正在尝试在 Restlet 中执行身份验证,我正在根据 URI 的一部分查找凭据,即多租户身份验证。

我无法将身份验证器的路由器链接到路由器以进行资源访问。这甚至可能吗?假设我有一个需要tenantId 变量来查找用户的身份验证器。我一直在尝试如下设置以使其无法成功运行。想法?

public class MyApplication extends Application
{
    public Authenticator authenticator;

    @Override
    public Restlet createInboundRoot()
    {
        Router router = new Router(getContext());
        router.attach("/", TraceResource.class);
        router.attach("/{apiVersion}/{tenantId}/pathOne/{someId}",
            ResourceOne.class);
        router.attach("/{apiVersion}/{tenantId}/pathTwo/{someId}",
            ResourceTwo.class);

        authenticator.setNext(router);

        Router authenticationRouter = new Router(getContext());
        authenticationRouter.attach("/{apiVersion}/{tenantId}/{remaining}",
            authenticator).setMatchingMode(Template.MODE_STARTS_WITH);

        return authenticationRouter;
    }
}
4

1 回答 1

1

这几乎是正确的,这是一个修复:

public class MyApplication extends Application
{
    public Authenticator authenticator;

    @Override
    public Restlet createInboundRoot()
    {
        Router router = new Router(getContext());
        router.attach("/", TraceResource.class);
        router.attach("/pathOne/{someId}", ResourceOne.class);
        router.attach("/pathTwo/{someId}", ResourceTwo.class);
        authenticator.setNext(router);

        Router authenticationRouter = new Router(getContext());
        authenticationRouter.attach("/{apiVersion}/{tenantId}",
            authenticator).setMatchingMode(Template.MODE_STARTS_WITH);

        return authenticationRouter;
    }
}
于 2013-10-08T00:14:08.410 回答