Пример #1
0
 @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;
   }
 }
Пример #2
0
 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);
   }
 }
Пример #3
0
  @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;
  }
  public static NuxeoOAuthConsumer createFromDirectoryEntry(DocumentModel entry, String keyType)
      throws ClientException {
    String callbackURL = (String) entry.getProperty(SCHEMA, "callbackURL");
    String consumerKey = (String) entry.getProperty(SCHEMA, "consumerKey");
    String consumerSecret = (String) entry.getProperty(SCHEMA, "consumerSecret");
    String rsaKey = (String) entry.getProperty(SCHEMA, "publicKey");

    NuxeoOAuthConsumer consumer =
        new NuxeoOAuthConsumer(callbackURL, consumerKey, consumerSecret, null);

    if (OAuth.RSA_SHA1.equals(keyType)) {
      if (rsaKey != null) {
        if (rsaKey.contains(PEMReader.PUBLIC_X509_MARKER)) {
          consumer.setProperty(RSA_SHA1.PUBLIC_KEY, rsaKey);
        } else {
          consumer.setProperty(RSA_SHA1.X509_CERTIFICATE, rsaKey);
        }
      }
    }
    consumer.publicKey = rsaKey;
    consumer.description = (String) entry.getProperty(SCHEMA, "description");
    consumer.signedFetchSupport = (String) entry.getProperty(SCHEMA, "signedFetchSupport");
    consumer.dedicatedLogin = (String) entry.getProperty(SCHEMA, "dedicatedLogin");

    Boolean enabledFlag = (Boolean) entry.getProperty(SCHEMA, "enabled");
    if (Boolean.FALSE.equals(enabledFlag)) {
      consumer.enabled = false;
    }

    Boolean allowBypassVerifierFlag = (Boolean) entry.getProperty(SCHEMA, "allowBypassVerifier");
    if (Boolean.TRUE.equals(allowBypassVerifierFlag)) {
      consumer.allowBypassVerifier = true;
    }

    return consumer;
  }