Restlet中的HTTP身份验证,验证子URL
我在服务器端使用HTTP摘要身份验证机制,客户端是firefox 这是服务器端代码Restlet中的HTTP身份验证,验证子URL,restlet,Restlet,我在服务器端使用HTTP摘要身份验证机制,客户端是firefox 这是服务器端代码 Application application = new Vehicle(); component.getDefaultHost().attachDefault(application); component.getDefaultHost().attach("/home",new Home()); DigestAuthenticator guard = new DigestAuthenticator(nul
Application application = new Vehicle();
component.getDefaultHost().attachDefault(application);
component.getDefaultHost().attach("/home",new Home());
DigestAuthenticator guard = new DigestAuthenticator(null, "TestRealm","mySecretServerKey");
Instantiates a Verifier of identifier/secret couples based on a simple Map.
MapVerifier mapVerifier = new MapVerifier();
加载单个静态登录/密码对
mapVerifier.getLocalSecrets().put("login", "secret".toCharArray());
guard.setWrappedVerifier(mapVerifier);
守饭桌
guard.setNext(application);
component.getDefaultHost().attachDefault(guard);
component.start();
家庭课
Router router = new Router(getContext());
router.attach("/People", People.class);
router.attach("/categories/",Categories.class);
return router;
如果我要求http://localhost:8182/ Http身份验证正在工作,但是http://localhost:8182/home/categories/ 如果我们首先尝试使用/home/categories/而不是http://localhost:8182/ 它将在没有任何身份验证机制的情况下给出结果。如何解决这个问题 您只将防护装置附加到默认路由,因此不匹配任何其他路由的路由。有关attachDefault,请参见javadoc:
* Attaches a Resource class to this router as the default target to invoke
* when no route matches. It actually sets a default route that scores all
* calls to 1.0.
您的其他路由不是默认路由,因此它们不受保护
router.attach("/People", People.class);
router.attach("/categories/",Categories.class);
必须在要保护的每条路线之间连接防护装置,如下所示:
DigestAuthenticator peopleGuard = new DigestAuthenticator(null, "TestRealm","mySecretServerKey");
peopleGuard.setNext(People.class);
router.attach("/People", peopleGuard);
谢谢你的回复,我会试试你的建议。