title: Restlet: Using SecretVerifier and Enroler classes forces 2 roundtrips to the database. Is this pattern efficient?
body: <p>In Restlet you have a class called <code>SecretVerifier</code> with an abstract method <code>verify(String identifier, char[] secret)</code> that you are to override in your subclass. The base class will also create a <code>User</code> object initialized with the identifier. So far so good.</p>
  
  <p>Now the <code>Enroler</code> interface needs to be implemented to "add" roles to the aforementioned <code>User</code> object (that is passed to the subclass via the <code>ClientInfo</code> object). Here is where you "add" roles to the User object.</p>
  
  <p>Let's assume that <code>ChallengeAuthenticator</code> is being used for authentication.</p>
  
  <p><em>Question</em>: Both these classes are quite distinct and you don't have access to the corresponding Request/Response objects. The very design sort of forces you to perform 2 round trips to the DB - one to verify the password and one to fetch the roles of the user. Is this an efficient design?</p>
  
  <p>You can fetch everything in a single query, so to speak. And since both classes will invoke the corresponding DAOs separately, there will be 2 calls to the DB.</p>
  
  <p>Of course you can have slightly convoluted code by overriding <code>SecretVerifier.getIdentifier(Request req, Response resp)</code> and then use that to fetch everything and add the roles - but the <code>verify</code> method seems to be a part of the <code>template</code> patter and you can't really control what's happening in the base class, unless you directly implement <code>Verifier</code> and reinvent the wheel and 'tweak' the code ever so slightly...but the question is about the design decision. I don't want to start a debate. I just want to know is something like this (2 trips) one for authentication, the other for roles quite common and is efficient under moderate-high loads?</p>