@Override
  public List<MenuEntry> getEntries() {
    if (cfg == null || cfgSnapshot.isModified(cfgFile)) {
      cfgSnapshot = FileSnapshot.save(cfgFile);
      cfg = new FileBasedConfig(cfgFile, FS.DETECTED);
      try {
        cfg.load();
      } catch (ConfigInvalidException | IOException e) {
        return Collections.emptyList();
      }
    }

    List<MenuEntry> menuEntries = new ArrayList<>();
    for (String url : cfg.getSubsections(SECTION_MENU_ITEM)) {
      String name = cfg.getString(SECTION_MENU_ITEM, url, KEY_NAME);
      if (Strings.isNullOrEmpty(name)) {
        continue;
      }

      String topMenu = cfg.getString(SECTION_MENU_ITEM, url, KEY_TOP_MENU);
      if (topMenu == null) {
        topMenu = DEFAULT_TOP_MENU;
      }

      String target = cfg.getString(SECTION_MENU_ITEM, url, KEY_TARGET);
      String id = cfg.getString(SECTION_MENU_ITEM, url, KEY_ID);

      menuEntries.add(
          new MenuEntry(topMenu, Collections.singletonList(new MenuItem(name, url, target, id))));
    }
    return menuEntries;
  }
  @Override
  public boolean load(Properties baseProperties) {
    initialize();
    LOGGER.info("Loading {} ...", propertiesFile);
    if (!Files.exists(propertiesFile)) {
      LOGGER.warn("No {}", propertiesFile);
      return false;
    }

    FileBasedConfig cfg = new FileBasedConfig(propertiesFile.toFile(), FS.DETECTED);
    try {
      cfg.load();
    } catch (ConfigInvalidException e) {
      LOGGER.info("{} has invalid format: {}", propertiesFile, e.getMessage());
      return false;
    } catch (IOException e) {
      LOGGER.info("Cannot read {}: {}", propertiesFile, e.getMessage());
      return false;
    }
    for (Section section : getSections()) {
      if (baseProperties != null) {
        Sections.fromConfig(section, baseProperties.toConfig(), cfg);
      } else {
        Sections.fromConfig(section, cfg);
      }
      Sections.normalize(section);
    }
    return true;
  }
 private void updateGerritConfig(SitePaths sitePaths, String newSecureStore)
     throws IOException, ConfigInvalidException {
   log.info("Set gerrit.secureStoreClass property of gerrit.config to {}", newSecureStore);
   FileBasedConfig config = new FileBasedConfig(sitePaths.gerrit_config.toFile(), FS.DETECTED);
   config.load();
   config.setString("gerrit", null, "secureStoreClass", newSecureStore);
   config.save();
 }
Exemplo n.º 4
0
 protected void setPluginConfigString(String name, String value)
     throws IOException, ConfigInvalidException {
   SitePaths sitePath = new SitePaths(testSite);
   FileBasedConfig cfg = getGerritConfigFile(sitePath);
   cfg.load();
   cfg.setString("plugin", pluginName, name, value);
   cfg.save();
 }
 private static String getSecureStoreClassFromGerritConfig(SitePaths sitePaths) {
   FileBasedConfig cfg = new FileBasedConfig(sitePaths.gerrit_config.toFile(), FS.DETECTED);
   try {
     cfg.load();
   } catch (IOException | ConfigInvalidException e) {
     throw new RuntimeException("Cannot read gerrit.config file", e);
   }
   return cfg.getString("gerrit", null, "secureStoreClass");
 }
Exemplo n.º 6
0
 private void updateAuthorityConfig(UserCertificateModel ucm) {
   File certificatesConfigFile = new File(folder, X509Utils.CA_CONFIG);
   FileBasedConfig config = new FileBasedConfig(certificatesConfigFile, FS.detect());
   if (certificatesConfigFile.exists()) {
     try {
       config.load();
     } catch (Exception e) {
       Utils.showException(GitblitAuthority.this, e);
     }
   }
   ucm.update(config);
   try {
     config.save();
   } catch (Exception e) {
     Utils.showException(GitblitAuthority.this, e);
   }
 }
Exemplo n.º 7
0
  private void setMetadataDefaults(X509Metadata metadata) {
    metadata.serverHostname = gitblitSettings.getString(Keys.web.siteName, Constants.NAME);
    if (StringUtils.isEmpty(metadata.serverHostname)) {
      metadata.serverHostname = Constants.NAME;
    }

    // set default values from config file
    File certificatesConfigFile = new File(folder, X509Utils.CA_CONFIG);
    FileBasedConfig config = new FileBasedConfig(certificatesConfigFile, FS.detect());
    if (certificatesConfigFile.exists()) {
      try {
        config.load();
      } catch (Exception e) {
        Utils.showException(GitblitAuthority.this, e);
      }
      NewCertificateConfig certificateConfig = NewCertificateConfig.KEY.parse(config);
      certificateConfig.update(metadata);
    }
  }
  public IPropertyDescriptor[] getPropertyDescriptors() {
    try {
      systemConfig.load();
      userHomeConfig.load();
      repositoryConfig.load();
      effectiveConfig.load();
    } catch (IOException e) {
      showExceptionMessage(e);
    } catch (ConfigInvalidException e) {
      showExceptionMessage(e);
    }

    List<IPropertyDescriptor> resultList = new ArrayList<IPropertyDescriptor>();

    StoredConfig config;
    String category;
    String prefix;
    switch (getCurrentMode()) {
      case EFFECTIVE:
        prefix = EFFECTIVE_ID_PREFIX;
        category = UIText.RepositoryPropertySource_EffectiveConfigurationCategory;
        config = effectiveConfig;
        break;
      case REPO:
        {
          prefix = REPO_ID_PREFIX;
          String location = ""; // $NON-NLS-1$
          if (repositoryConfig instanceof FileBasedConfig) {
            location = ((FileBasedConfig) repositoryConfig).getFile().getAbsolutePath();
          }
          category =
              NLS.bind(UIText.RepositoryPropertySource_RepositoryConfigurationCategory, location);
          config = repositoryConfig;
          break;
        }
      case USER:
        {
          prefix = USER_ID_PREFIX;
          String location = userHomeConfig.getFile().getAbsolutePath();
          category =
              NLS.bind(UIText.RepositoryPropertySource_GlobalConfigurationCategory, location);
          config = userHomeConfig;
          break;
        }
      case SYSTEM:
        {
          prefix = SYSTEM_ID_PREFIX;
          String location = systemConfig.getFile().getAbsolutePath();
          category =
              NLS.bind(UIText.RepositoryPropertySource_GlobalConfigurationCategory, location);
          config = systemConfig;
          break;
        }
      default:
        return new IPropertyDescriptor[0];
    }
    for (String key : config.getSections()) {
      for (String sectionItem : config.getNames(key)) {
        String sectionId = key + "." + sectionItem; // $NON-NLS-1$
        PropertyDescriptor desc = new PropertyDescriptor(prefix + sectionId, sectionId);
        desc.setCategory(category);
        resultList.add(desc);
      }
      for (String sub : config.getSubsections(key)) {
        for (String sectionItem : config.getNames(key, sub)) {
          String sectionId = key + "." + sub + "." + sectionItem; // $NON-NLS-1$ //$NON-NLS-2$
          PropertyDescriptor desc = new PropertyDescriptor(prefix + sectionId, sectionId);
          desc.setCategory(category);
          resultList.add(desc);
        }
      }
    }

    return resultList.toArray(new IPropertyDescriptor[0]);
  }
Exemplo n.º 9
0
  private void load(File folder) {
    this.folder = folder;
    this.userService = loadUsers(folder);
    System.out.println(Constants.baseFolder$ + " set to " + folder);
    if (userService == null) {
      JOptionPane.showMessageDialog(
          this,
          MessageFormat.format("Sorry, {0} doesn't look like a Gitblit GO installation.", folder));
    } else {
      // build empty certificate model for all users
      Map<String, UserCertificateModel> map = new HashMap<String, UserCertificateModel>();
      for (String user : userService.getAllUsernames()) {
        UserModel model = userService.getUserModel(user);
        UserCertificateModel ucm = new UserCertificateModel(model);
        map.put(user, ucm);
      }
      File certificatesConfigFile = new File(folder, X509Utils.CA_CONFIG);
      FileBasedConfig config = new FileBasedConfig(certificatesConfigFile, FS.detect());
      if (certificatesConfigFile.exists()) {
        try {
          config.load();
          // replace user certificate model with actual data
          List<UserCertificateModel> list = UserCertificateConfig.KEY.parse(config).list;
          for (UserCertificateModel ucm : list) {
            ucm.user = userService.getUserModel(ucm.user.username);
            map.put(ucm.user.username, ucm);
          }
        } catch (IOException e) {
          e.printStackTrace();
        } catch (ConfigInvalidException e) {
          e.printStackTrace();
        }
      }

      tableModel.list = new ArrayList<UserCertificateModel>(map.values());
      Collections.sort(tableModel.list);
      tableModel.fireTableDataChanged();
      Utils.packColumns(table, Utils.MARGIN);

      File caKeystore = new File(folder, X509Utils.CA_KEY_STORE);
      if (!caKeystore.exists()) {

        if (!X509Utils.unlimitedStrength) {
          // prompt to confirm user understands JCE Standard Strength encryption
          int res =
              JOptionPane.showConfirmDialog(
                  GitblitAuthority.this,
                  Translation.get("gb.jceWarning"),
                  Translation.get("gb.warning"),
                  JOptionPane.YES_NO_OPTION,
                  JOptionPane.WARNING_MESSAGE);
          if (res != JOptionPane.YES_OPTION) {
            if (Desktop.isDesktopSupported()) {
              if (Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) {
                try {
                  Desktop.getDesktop()
                      .browse(
                          URI.create(
                              "http://www.oracle.com/technetwork/java/javase/downloads/index.html"));
                } catch (IOException e) {
                }
              }
            }
            System.exit(1);
          }
        }

        // show certificate defaults dialog
        certificateDefaultsButton.doClick();

        // create "localhost" ssl certificate
        prepareX509Infrastructure();
      }
    }
  }
Exemplo n.º 10
0
 private StoredConfig getConfig() throws IOException, ConfigInvalidException {
   File configFile = new File(folder, X509Utils.CA_CONFIG);
   FileBasedConfig config = new FileBasedConfig(configFile, FS.detect());
   config.load();
   return config;
 }