Skip to content

Add a WinRM CLI and standalone executable JAR #112

Description

@bertysentry

Goal

Add a command-line interface for running WQL queries and remote commands, and update pom.xml so every build also produces a self-contained executable JAR.

The existing regular library JAR must remain unchanged/available. The executable should be an additional artifact, for example:

winrm-java-<version>-standalone.jar

invoked with:

java -jar winrm-java-<version>-standalone.jar [options] wql <query>
java -jar winrm-java-<version>-standalone.jar [options] command <command line...>

cmd, exec, and run must be aliases for command.

CLI syntax

winrm-java [connection/authentication options] wql <query>
winrm-java [connection/authentication options] command|cmd|exec|run <command line...>

Required connection options

  • --hostname, -h — target hostname or IP address.
  • --username, -u — username, including forms such as DOMAIN\user or HOST\localuser.

Credential options

  • --password, -p — password supplied directly.
  • --password-file, -pf — read the password from a file.

--password and --password-file must be mutually exclusive. Passwords must never be printed in diagnostics, usage errors, or logs. The password-file behavior must be documented, including treatment of its final CR/LF. Clear mutable password buffers when practical.

Direct --password use should carry a documentation warning that command-line arguments can be visible to other local processes; --password-file is preferred for automation.

Authentication options

  • --ntlm — use NTLM authentication.
  • --kerberos — use Kerberos authentication.

Document the default when neither is supplied (currently NTLM). If both flags are accepted for fallback, define and test their ordering; otherwise report a clear mutual-exclusion error.

Transport and timeout options

  • --https — use HTTPS instead of HTTP.
  • --https-permissive, — allow self-signed certificates (you can modify the option name if you find something more accurate and descriptive)
  • --port, -P — target port.
  • --timeout, -t — operation timeout in milliseconds.

-p was requested for both password and port, which is ambiguous. Reserve lowercase -p for password and use uppercase -P for port. The default port should follow the transport: 5985 for HTTP and 5986 for HTTPS.

Command behavior

WQL

java -jar winrm-java-<version>-standalone.jar \
  -h server.example.net -u 'DOMAIN\user' -pf password.txt --ntlm \
  wql 'SELECT Name,State FROM Win32_Service'

Command execution

java -jar winrm-java-<version>-standalone.jar \
  --hostname server.example.net --username Administrator --password-file password.txt --https \
  exec ipconfig /all
  • Treat every remaining argument after command|cmd|exec|run as part of the remote command line, preserving spaces and quoting as predictably as possible.
  • Forward remote stdout to local stdout and remote stderr to local stderr.
  • Stream output as it arrives using Streaming APIs (phase 2): stream()/start() terminal methods on the fluent WinRMClient #111 when available.
  • Propagate the remote command exit status when it can be represented as a process exit code.

Executable JAR

Update pom.xml to produce an attached standalone executable artifact, preferably with maven-shade-plugin:

  • keep the normal library JAR;
  • attach a standalone classifier rather than replacing the main artifact;
  • include all runtime dependencies;
  • set the manifest Main-Class to the CLI entry point;
  • merge any required service resources correctly;
  • avoid publishing dependency-reduced POM changes that break consumers;
  • retain reproducible-build behavior.

No CXF-specific packaging is required; the CLI targets the lightweight client only.

Exit codes

Define and document stable exit behavior, including at least:

  • 0: successful WQL query or remote command with exit code 0;
  • remote command exit code: propagated where possible;
  • distinct non-zero handling for CLI usage errors versus connection, authentication, timeout, and WinRM protocol failures.

Acceptance criteria

  • mvn package produces both the normal library JAR and an executable standalone JAR.
  • java -jar ...-standalone.jar --help prints usage and exits successfully.
  • --version prints the project version.
  • All long and short options listed above are supported, with -p for password and -P for port.
  • wql executes WQL and emits results to stdout.
  • command, cmd, exec, and run execute remote commands and forward stdout/stderr appropriately.
  • HTTP/HTTPS default ports and explicit port overrides work.
  • NTLM and Kerberos selection works according to documented defaults and conflict/fallback rules.
  • Password-file input works without leaking secrets.
  • Invalid/missing/conflicting options produce concise errors and a non-zero usage exit code.
  • Unit tests cover argument parsing, aliases, defaults, conflicts, password files, exit-code mapping, and command-line reconstruction.
  • An end-to-end test verifies the manifest and launches the built JAR in a separate JVM.
  • README/Javadocs document installation, examples, authentication, certificate trust for HTTPS, password security, output formats, and exit codes.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions