我正在尝试在 ReSTLet 中执行身份验证,其中我根据 URI 的一部分查找凭据,即 Multi-Tenancy 身份验证。
我无法将身份 validator 的路由器链接到用于资源访问的路由器。这可能吗?假设我有一个身份 validator ,它需要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;
}
}
最佳答案
这几乎是正确的,这是一个修复:
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;
}
}
关于java - ReSTLet - 在身份 validator 中使用 URI 模板变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19213209/