/** * Sets the modifiable map of local secrets. This method clears the current * map and puts all entries in the parameter map. * * @param localSecrets * A map of local secrets. */ public void setLocalSecrets(Map<String, char[]> localSecrets) { synchronized (getLocalSecrets()) { if (localSecrets != getLocalSecrets()) { getLocalSecrets().clear(); if (localSecrets != null) { getLocalSecrets().putAll(localSecrets); } } } }
@Override public char[] getLocalSecret(String identifier) { return (identifier == null) ? null : getLocalSecrets().get(identifier); }
MapVerifier verifier = new MapVerifier(); NewAwsVerifier newVerifier = new NewAwsVerifier(verifier); // Get passwords from a more secure source (only here for illustration)! verifier.getLocalSecrets().put("accessKey", "secretKey".toCharArray()); auth.setVerifier(newVerifier);
@Override public Restlet createInboundRoot() { // Create a simple password verifier MapVerifier verifier = new MapVerifier(); verifier.getLocalSecrets().put("scott", "tiger".toCharArray()); DigestAuthenticator guard = new DigestAuthenticator(getContext(), "TestRealm", "mySecretServerKey"); MapVerifier mapVerifier = new MapVerifier(); mapVerifier.getLocalSecrets().put("scott", "tiger".toCharArray()); guard.setWrappedVerifier(mapVerifier); // Create a Directory able to return a deep hierarchy of files Directory directory = new Directory(getContext(), "file:///tmp"); directory.setListingAllowed(true); guard.setNext(directory); return guard; }
// 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); // Application JaxRsApplication application = new JaxRsApplication(childContext); application.add(this); application.setStatusService(new ErrorStatusService()); // Set application within guard guard.setNext(application); // <-------- // Create and configure component Component component = new Component(); component.getServers().add(Protocol.HTTP, 8182); component.getDefaultHost().attachDefault(guard);
@Override public Restlet createInboundRoot() { // Create a simple password verifier MapVerifier verifier = new MapVerifier(); verifier.getLocalSecrets().put("scott", "tiger".toCharArray()); // Create a guard ChallengeAuthenticator guard = new ChallengeAuthenticator(getContext(), ChallengeScheme.HTTP_BASIC, "Tutorial"); guard.setVerifier(verifier); // Create a Directory able to return a deep hierarchy of files Directory directory = new Directory(getContext(), "file:///tmp"); directory.setListingAllowed(true); guard.setNext(directory); return guard; }
@Override public Restlet createInboundRoot() { // Create a simple password verifier MapVerifier verifier = new MapVerifier(); verifier.getLocalSecrets().put("scott", "tiger".toCharArray()); // Create a Guard ChallengeAuthenticator authenticator = new ChallengeAuthenticator( getContext(), ChallengeScheme.HTTP_BASIC, "Tutorial"); authenticator.setVerifier(verifier); // Create a Directory able to return a deep hierarchy of files Directory directory = new Directory(getContext(), ROOT_URI); directory.setListingAllowed(true); authenticator.setNext(directory); return authenticator; }
/** * Creates a root Router to dispatch call to server resources. */ @Override public Restlet createInboundRoot() { Router router = new Router(getContext()); router.attach("/accounts/{accountId}/mails/{mailId}", MailServerResource.class); // Create the HTTP Digest authenticator DigestAuthenticator authenticator = new DigestAuthenticator( getContext(), "My Realm", "My Server Key"); // Set the credentials verifier MapVerifier verifier = new MapVerifier(); verifier.getLocalSecrets().put("chunkylover53", "pwd".toCharArray()); authenticator.setWrappedVerifier(verifier); // Chain the authenticator with the router authenticator.setNext(router); return authenticator; } }
/** * Creates a root Router to dispatch call to server resources. */ @Override public Restlet createInboundRoot() { Router router = new Router(getContext()); router.attach("/accounts/{accountId}/mails/{mailId}", MailServerResource.class); MapVerifier verifier = new MapVerifier(); verifier.getLocalSecrets().put("chunkylover53", "pwd".toCharArray()); NaiveCookieAuthenticator authenticator = new NaiveCookieAuthenticator( getContext(), "Cookie Test"); authenticator.setVerifier(verifier); authenticator.setNext(router); return authenticator; } }
/** * Creates a root Router to dispatch call to server resources. */ @Override public Restlet createInboundRoot() { Router router = new Router(getContext()); router.attach("/accounts/{accountId}/mails/{mailId}", MailServerResource.class); // Create the HTTP Basic authenticator ChallengeAuthenticator authenticator = new ChallengeAuthenticator( getContext(), ChallengeScheme.HTTP_BASIC, "My Realm"); // Set the credentials verifier MapVerifier verifier = new MapVerifier(); verifier.getLocalSecrets().put("chunkylover53", "pwd".toCharArray()); authenticator.setVerifier(verifier); // Chain the authenticator with the router authenticator.setNext(router); return authenticator; } }
verifier.getLocalSecrets().put("scott", "tiger".toCharArray());
verifier.getLocalSecrets().put("scott", "tiger".toCharArray());
public static void main( String[] args ) throws Exception { Energy4Java polygene = new Energy4Java( ); Server server = new Server( Protocol.HTTP, 8888 ); Application app = polygene.newApplication( new ForumAssembler(), new MetadataService() ); app.activate(); ContextRestlet restlet = app.findModule( "REST", "Restlet" ).newObject( ContextRestlet.class, new org.restlet.Context() ); ChallengeAuthenticator guard = new ChallengeAuthenticator(null, ChallengeScheme.HTTP_BASIC, "testRealm"); MapVerifier mapVerifier = new MapVerifier(); mapVerifier.getLocalSecrets().put("rickard", "secret".toCharArray()); guard.setVerifier(mapVerifier); guard.setNext(restlet); server.setNext( restlet ); server.start(); } }
mapVerifier.getLocalSecrets().put( "rickard", "secret".toCharArray() ); guard.setVerifier( mapVerifier );
mapVerifier.getLocalSecrets().put("rickard", "secret".toCharArray()); guard.setVerifier(mapVerifier);