Пример #1
0
 // ----------------------------------------------------------
 public void setDefaultConfigValues(final WCConfigurationFile configuration) {
   final String username = configuration.getProperty("AdminUsername");
   final String authDomainName = configuration.getProperty("authenticator.default");
   String className = configuration.getProperty("authenticator." + authDomainName);
   usingDatabaseAuthentication =
       className == null || className.equals(DatabaseAuthenticator.class.getName());
   canSetPassword = usingDatabaseAuthentication;
   if (authDomainName != null && !authDomainName.equals("")) {
     run(
         new ECAction() {
           public void action() {
             AuthenticationDomain domain = AuthenticationDomain.authDomainByName(authDomainName);
             canSetPassword = domain.authenticator().canChangePassword();
             if (username != null && !username.equals("")) {
               NSArray<?> users =
                   EOUtilities.objectsMatchingValues(
                       ec,
                       User.ENTITY_NAME,
                       new NSDictionary<String, Object>(
                           new Object[] {username, domain},
                           new String[] {User.USER_NAME_KEY, User.AUTHENTICATION_DOMAIN_KEY}));
               if (users.count() > 0) {
                 if (users.count() > 1) {
                   error("Multiple accounts with the user name '" + username + "' detected!");
                 }
                 User admin = (User) users.objectAtIndex(0);
                 if (admin.firstName() != null) {
                   setConfigDefault(configuration, "AdminFirstName", admin.firstName());
                 }
                 if (admin.lastName() != null) {
                   setConfigDefault(configuration, "AdminLastName", admin.lastName());
                 }
                 if (admin.email() != null) {
                   setConfigDefault(configuration, "coreAdminEmail", admin.email());
                 }
                 if (canSetPassword && admin.password() != null) {
                   setConfigDefault(configuration, "AdminPassword", admin.password());
                 }
               }
             }
           }
         });
   }
   setConfigDefault(configuration, "adminNotifyAddrs", "*****@*****.**");
 }
Пример #2
0
  // ----------------------------------------------------------
  public void takeFormValues(NSDictionary<?, ?> formValues) {
    WCConfigurationFile configuration = Application.configurationProperties();
    if (log.isDebugEnabled()) {
      log.debug("takeFormValues(): initial config = ");
      log.debug(configuration.configSettingsAsString());
    }
    String email =
        storeFormValueToConfig(
            formValues, "coreAdminEmail", "Please specify the administrator's e-mail address.");
    storeFormValueToConfig(formValues, "adminNotifyAddrs", null);
    String authDomainName = configuration.getProperty("authenticator.default");
    String username =
        storeFormValueToConfig(
            formValues, "AdminUsername", "Please specify the administrator's user name.");
    if (log.isDebugEnabled()) {
      log.debug("takeFormValues(): middle = ");
      log.debug(configuration.configSettingsAsString());
    }
    if (authDomainName == null || authDomainName.equals("")) {
      error("Cannot identify default institution's " + "authentication configuration.");
    } else if (username != null && !hasMessages()) {
      EOEditingContext ec = WCEC.newEditingContext();
      try {
        ec.lock();
        AuthenticationDomain domain = AuthenticationDomain.authDomainByName(authDomainName);
        NSArray<?> users =
            EOUtilities.objectsMatchingValues(
                ec,
                User.ENTITY_NAME,
                new NSDictionary<String, Object>(
                    new Object[] {username, domain},
                    new String[] {User.USER_NAME_KEY, User.AUTHENTICATION_DOMAIN_KEY}));
        User admin;
        if (users.count() > 0) {
          admin = (User) users.objectAtIndex(0);
          admin.setEmail(email);
          String first = extractFormValue(formValues, "AdminFirstName");
          if (first != null && !first.equals("")) {
            admin.setFirstName(first);
          }
          String last = extractFormValue(formValues, "AdminLastName");
          if (last != null && !last.equals("")) {
            admin.setLastName(last);
          }
          ec.saveChanges();
        } else {
          String password =
              storeFormValueToConfig(
                  formValues, "AdminPassword", "An administrator password is required.");
          if (authDomainName.equals(DatabaseAuthenticator.class.getName())
              && (password == null || password.equals(""))) {
            // Don't need this anymore, since the error message is
            // posted by storeFormValuesToConfig() above.

            // errorMessage(
            //     "An administrator password is required." );
          } else {
            admin = User.createUser(username, password, domain, (byte) 100, ec);
            admin.setEmail(email);
            String first = extractFormValue(formValues, "AdminFirstName");
            if (first != null && !first.equals("")) {
              admin.setFirstName(first);
            }
            String last = extractFormValue(formValues, "AdminLastName");
            if (last != null && !last.equals("")) {
              admin.setLastName(last);
            }
            ec.saveChanges();
          }
        }
      } finally {
        ec.unlock();
        ec.dispose();
      }
    }
    if (log.isDebugEnabled()) {
      log.debug("takeFormValues(): near end = ");
      log.debug(configuration.configSettingsAsString());
    }
    if (!hasMessages()) {
      configuration.remove("AdminFirstName");
      configuration.remove("AdminLastName");
    }
    if (log.isDebugEnabled()) {
      log.debug("takeFormValues(): finals = ");
      log.debug(configuration.configSettingsAsString());
    }
  }