Restlet - 在Authenticator中使用URI模板变量

时间:2013-10-06 19:50:29

标签: java authentication uri restlet

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

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

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;
    }
}

1 个答案:

答案 0 :(得分: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;
    }
}
相关问题