title: HTTP Basic Authentication in Restlet with a JAXRS Application?
body: <p>I'm trying to authenticate access to all resources on my server via HTTP Basic authentication. Currently, my setup looks like this when starting the server:</p>
  
  <pre><code>this.component = new Component();
  this.server = this.component.getServers().add(Protocol.HTTP, 8118);
  
  JaxRsApplication application = new JaxRsApplication(component.getContext()
          .createChildContext());
  application.add(new RestletApplication());
  
  ChallengeAuthenticator authenticator = new ChallengeAuthenticator(
          this.component.getContext(), 
          ChallengeScheme.HTTP_BASIC, "test");        
  authenticator.setVerifier(new ApplicationVerifier());
  
  this.component.getDefaultHost().attachDefault(authenticator);
  this.component.getDefaultHost().attach(application);
  this.component.start();
  </code></pre>
  
  <p>Here's my <code>RestletApplication</code>:</p>
  
  <pre><code>import java.util.HashSet;
  import java.util.Set;
  
  import javax.ws.rs.core.Application;
  
  public class RestletApplication extends Application {
  
      @Override
      public Set&lt;Class&lt;?&gt;&gt; getClasses() {
          Set&lt;Class&lt;?&gt;&gt; classes = new HashSet&lt;Class&lt;?&gt;&gt;();
          classes.add(TestResource.class);
          return classes;
      }
  }
  </code></pre>
  
  <p>Here's my <code>ApplicationVerifier</code>:</p>
  
  <pre><code>import java.util.HashMap;
  import java.util.Map;
  
  import org.restlet.security.LocalVerifier;
  
  public class ApplicationVerifier extends LocalVerifier {
  
      private Map&lt;String, char[]&gt; localSecrets = new HashMap&lt;String, char[]&gt;();
  
      public ApplicationVerifier() {
          this.localSecrets.put("username", "password".toCharArray());
      }
  
      @Override
      public char[] getLocalSecret(String key) {
          if (this.localSecrets.containsKey(key))
              return this.localSecrets.get(key);
  
          return null;
      }
  }
  </code></pre>
  
  <p>Finally, here's my <code>TestResource</code>:</p>
  
  <pre><code>import java.util.*;
  
  import javax.ws.rs.GET;
  import javax.ws.rs.Path;
  
  @Path("test")
  public class TestResource {
  
      @GET
      @Path("list")
      public TestList getTestList() {
          return makeTestList();
      }
  }
  </code></pre>
  
  <p>However, I'm not seeing any prompt or requirement for authentication when I try to access the resource. What am I doing wrong? I'm not having any issues with marshalling and unmarshalling items and I'm sure that my resource is getting hit with requests. What am I not doing right?</p>