Ich habe eine Restlet (2.2.3) Anwendung (Ich bin neu in Restlet), die aufzubauen ist als:Befestigung von Bauteilen an Restlet
component = new Component();
component.getServers().add(Protocol.HTTP, port);
Context childContext = component.getContext().createChildContext();
JaxRsApplication application = new JaxRsApplication(childContext);
application.add(this);
application.setStatusService(new ErrorStatusService());
childContext.getAttributes().put(MY_SERVER, this);
component.getDefaultHost().attach(application);
Es läuft als eigenständige Java-Anwendung. Ich möchte Sicherheit hinzufügen. Hier ist der grundlegende Authentifizierungscode von restlet authentication documentation:
// Guard the restlet with BASIC authentication.
ChallengeAuthenticator guard = new ChallengeAuthenticator(null, ChallengeScheme.HTTP_BASIC, "testRealm");
// Instantiates a Verifier of identifier/secret couples based on a simple Map.
MapVerifier mapVerifier = new MapVerifier();
// Load a single static login/secret pair.
mapVerifier.getLocalSecrets().put("login", "secret".toCharArray());
guard.setVerifier(mapVerifier);
guard.setNext(restlet);
Component component = new Component();
component.getServers().add(Protocol.HTTP, 8182);
component.getDefaultHost().attachDefault(guard);
Wie kann ich integrieren, dass Sicherheitsmechanismus in meinen aktuellen Code?