コード例 #1
0
 static void decodeAuth(String auth, AuthConfig config) throws IOException {
   String str = new String(Base64.decodeBase64(auth), Charset.forName("UTF-8"));
   String[] parts = str.split(":", 2);
   if (parts.length != 2) {
     throw new IOException("Invalid auth configuration file");
   }
   config.setUsername(parts[0]);
   config.setPassword(parts[1]);
 }
コード例 #2
0
  public static AuthConfigFile loadConfig(File confFile) throws IOException {
    AuthConfigFile configFile = new AuthConfigFile();
    if (!confFile.exists()) {
      return new AuthConfigFile();
    }
    Map<String, AuthConfig> configMap = null;
    try {
      configMap = MAPPER.readValue(confFile, CONFIG_MAP_TYPE);
    } catch (IOException e) {
      // pass
    }
    if (configMap != null) {
      for (Map.Entry<String, AuthConfig> entry : configMap.entrySet()) {
        AuthConfig authConfig = entry.getValue();
        decodeAuth(authConfig.getAuth(), authConfig);
        authConfig.setAuth(null);
        authConfig.setServerAddress(entry.getKey());
        configFile.addConfig(authConfig);
      }
    } else {
      List<String> authFileContent = FileUtils.readLines(confFile);
      if (authFileContent.size() < 2) {
        throw new IOException("The Auth Config file is empty");
      }
      AuthConfig config = new AuthConfig();
      String[] origAuth = authFileContent.get(0).split(" = ");
      if (origAuth.length != 2) {
        throw new IOException("Invalid Auth config file");
      }
      decodeAuth(origAuth[1], config);

      String[] origEmail = authFileContent.get(1).split(" = ");
      if (origEmail.length != 2) {
        throw new IOException("Invalid Auth config file");
      }
      config.setEmail(origEmail[1]);
      configFile.addConfig(config);
    }
    return configFile;
  }
コード例 #3
0
 void addConfig(AuthConfig config) {
   authConfigMap.put(config.getServerAddress(), config);
 }