Exemplo n.º 1
0
  public DefaultAuthenticator(@NotNull ErrorReceiver receiver, @NotNull File authfile)
      throws BadCommandLineException {
    this.errReceiver = receiver;
    this.proxyUser = System.getProperty("http.proxyUser");
    this.proxyPasswd = System.getProperty("http.proxyPassword");

    if (authfile != null) {
      this.authFile = authfile;
      this.giveError = true;
    }

    if (!authFile.exists()) {
      try {
        error(
            new SAXParseException(
                WscompileMessages.WSIMPORT_AUTH_FILE_NOT_FOUND(
                    authFile.getCanonicalPath(), defaultAuthfile),
                null));
      } catch (IOException e) {
        error(
            new SAXParseException(
                WscompileMessages.WSIMPORT_FAILED_TO_PARSE(authFile, e.getMessage()), null));
      }
      return;
    }

    if (!authFile.canRead()) {
      error(
          new SAXParseException(
              "Authorization file: " + authFile + " does not have read permission!", null));
      return;
    }
    parseAuth();
  }
Exemplo n.º 2
0
  private void parseAuth() {
    errReceiver.info(
        new SAXParseException(WscompileMessages.WSIMPORT_READING_AUTH_FILE(authFile), null));

    BufferedReader in;
    try {
      in = new BufferedReader(new InputStreamReader(new FileInputStream(authFile), "UTF-8"));
    } catch (UnsupportedEncodingException e) {
      error(new SAXParseException(e.getMessage(), null));
      return;
    } catch (FileNotFoundException e) {
      error(
          new SAXParseException(
              WscompileMessages.WSIMPORT_AUTH_FILE_NOT_FOUND(authFile, defaultAuthfile), null, e));
      return;
    }
    String text;
    LocatorImpl locator = new LocatorImpl();
    try {
      int lineno = 1;

      locator.setSystemId(authFile.getCanonicalPath());

      while ((text = in.readLine()) != null) {
        locator.setLineNumber(lineno++);
        try {
          URL url = new URL(text);
          String authinfo = url.getUserInfo();

          if (authinfo != null) {
            int i = authinfo.indexOf(':');

            if (i >= 0) {
              String user = authinfo.substring(0, i);
              String password = authinfo.substring(i + 1);
              authInfo.add(new AuthInfo(new URL(text), user, password));
            } else {
              error(
                  new SAXParseException(
                      WscompileMessages.WSIMPORT_ILLEGAL_AUTH_INFO(url), locator));
            }
          } else {
            error(
                new SAXParseException(WscompileMessages.WSIMPORT_ILLEGAL_AUTH_INFO(url), locator));
          }

        } catch (NumberFormatException e) {
          error(new SAXParseException(WscompileMessages.WSIMPORT_ILLEGAL_AUTH_INFO(text), locator));
        }
      }
      in.close();
    } catch (IOException e) {
      error(
          new SAXParseException(
              WscompileMessages.WSIMPORT_FAILED_TO_PARSE(authFile, e.getMessage()), locator));
    }
  }