无法从 Restlet Authorizer 获取机密
我正在使用 Restlet 身份验证和授权。但我无法获取自定义注册器中的秘密,它是空的。这是代码:
TestApplication.java
@Override
public Restlet createInboundRoot()
{
Router rootRouter = new Router(getContext());
Router pubRouter = new Router(getContext());
pubRouter.attach("/test", TestResource.class);
RoleAuthorizer ra = new RoleAuthorizer();
ra.getAuthorizedRoles().add(MyEnroler.PUBLISHER);
ra.setNext(pubRouter);
rootRouter.attach("/publish", ra);
ChallengeAuthenticator guard =
new ChallengeAuthenticator(getContext(),ChallengeScheme.HTTP_BASIC, "my realm");
guard.setVerifier(new MyVerifier());
guard.setEnroler(new MyEnroler());
guard.setNext(rootRouter);
return guard;
}
Enroller.java
public class MyEnroler implements Enroler
{
public final static Role PUBLISHER = new Role("publisher", "publisher");
public void enrole(ClientInfo clientInfo)
{
System.out.println(clientInfo.getUser().getIdentifier());
System.out.println(new String(theClientInfo.getUser().getSecret()));
}
}
theClientInfo.getUser().getSecret() 总是返回 null
ClientResource.java
public static void main(String[] args) throws Exception
{
// Create a HTTP Server listening to the port 8182
Component c = new Component();
c.getServers().add(Protocol.HTTP, 8182);
c.getDefaultHost().attach("/myapp", new TestApplication());
c.start();
ClientResource pubResource =
new ClientResource("http://localhost:8182/myapp/publish/test");
ChallengeResponse cr =
new ChallengeResponse(ChallengeScheme.HTTP_BASIC, "scott", "tiger");
pubResource.setChallengeResponse(cr);
pubResource.get()
}
有人知道为什么吗?
谢谢!
I am using Restlet Authentication and Authorization. But I can't get the secrets in my customized enroller, it is null. Here is the code:
TestApplication.java
@Override
public Restlet createInboundRoot()
{
Router rootRouter = new Router(getContext());
Router pubRouter = new Router(getContext());
pubRouter.attach("/test", TestResource.class);
RoleAuthorizer ra = new RoleAuthorizer();
ra.getAuthorizedRoles().add(MyEnroler.PUBLISHER);
ra.setNext(pubRouter);
rootRouter.attach("/publish", ra);
ChallengeAuthenticator guard =
new ChallengeAuthenticator(getContext(),ChallengeScheme.HTTP_BASIC, "my realm");
guard.setVerifier(new MyVerifier());
guard.setEnroler(new MyEnroler());
guard.setNext(rootRouter);
return guard;
}
Enroller.java
public class MyEnroler implements Enroler
{
public final static Role PUBLISHER = new Role("publisher", "publisher");
public void enrole(ClientInfo clientInfo)
{
System.out.println(clientInfo.getUser().getIdentifier());
System.out.println(new String(theClientInfo.getUser().getSecret()));
}
}
theClientInfo.getUser().getSecret() always return null
ClientResource.java
public static void main(String[] args) throws Exception
{
// Create a HTTP Server listening to the port 8182
Component c = new Component();
c.getServers().add(Protocol.HTTP, 8182);
c.getDefaultHost().attach("/myapp", new TestApplication());
c.start();
ClientResource pubResource =
new ClientResource("http://localhost:8182/myapp/publish/test");
ChallengeResponse cr =
new ChallengeResponse(ChallengeScheme.HTTP_BASIC, "scott", "tiger");
pubResource.setChallengeResponse(cr);
pubResource.get()
}
Does anybody know why?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看最新的代码,似乎没有在 User 对象上设置秘密。但是,您可以重写 MyVerifier 类中的 verify(request, response) 方法来设置它,如下所示:
Looking through the latest code, it does not appear that the secret is ever set on the User object. However, you can override the verify(request, response) method in your MyVerifier class to set it, like so: