protected NuxeoOAuthConsumer getEntry(String consumerKey, String keyType) {
   DirectoryService ds = Framework.getService(DirectoryService.class);
   try (Session session = ds.open(DIRECTORY_NAME)) {
     DocumentModel entry = session.getEntry(consumerKey);
     if (entry == null) {
       return null;
     }
     return NuxeoOAuthConsumer.createFromDirectoryEntry(entry, keyType);
   }
 }
 @Override
 public NuxeoOAuthConsumer storeConsumer(NuxeoOAuthConsumer consumer) {
   DirectoryService ds = Framework.getService(DirectoryService.class);
   try (Session session = ds.open(DIRECTORY_NAME)) {
     Map<String, Object> init = new HashMap<String, Object>();
     init.put("consumerKey", consumer.consumerKey);
     DocumentModel entry = session.createEntry(init);
     consumer.asDocumentModel(entry);
     session.updateEntry(entry);
     if (entry == null) {
       return null;
     }
     consumer = NuxeoOAuthConsumer.createFromDirectoryEntry(entry, null);
     return consumer;
   }
 }
  @Override
  public List<NuxeoOAuthConsumer> listConsumers() {

    List<NuxeoOAuthConsumer> result = new ArrayList<NuxeoOAuthConsumer>();
    try {
      DirectoryService ds = Framework.getService(DirectoryService.class);
      try (Session session = ds.open(DIRECTORY_NAME)) {
        DocumentModelList entries = session.getEntries();
        for (DocumentModel entry : entries) {
          result.add(NuxeoOAuthConsumer.createFromDirectoryEntry(entry, null));
        }
      }
    } catch (ClientException e) {
      log.error("Error while fetching consumer directory", e);
    }
    return result;
  }