【问题标题】:Restlet - Using URI Template Variables in AuthenticatorRestlet - 在 Authenticator 中使用 URI 模板变量
【发布时间】:2013-10-06 19:50:29
【问题描述】:

我正在尝试在 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;
    }
}

【问题讨论】:

    标签: java authentication uri restlet


    【解决方案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;
        }
    }
    

    【讨论】:

    • 谢谢!在这种情况下,authenticationRouter 中的tenantId 变量会给我“斜线之间”的值吗?还是我需要解析它?
    • "tenantId" 变量将包含 URI 的剩余部分,包括斜杠
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-09-16
    • 2013-11-17
    • 2012-01-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-19
    相关资源
    最近更新 更多