Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 103 additions & 0 deletions client/src/com/mirth/connect/client/ui/CommandLineOptions.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
// SPDX-License-Identifier: MPL-2.0
// SPDX-FileCopyrightText: Mirth Corporation

package com.mirth.connect.client.ui;

import org.apache.commons.lang3.StringUtils;

/**
* Immutable holder for command line options used by the Mirth client.
*/
public class CommandLineOptions {
private final String server;
private final String version;
private final String username;
private final String password;
private final String protocols;
private final String cipherSuites;

/**
* Parse command line arguments for Mirth client.
*/
public CommandLineOptions(String[] args) {
String server = "https://localhost:8443";
String version = "";
String username = "";
String password = "";
String protocols = "";
String cipherSuites = "";

if (args == null) {
args = new String[0];
}

if (args.length > 0) {
server = args[0];
}
if (args.length > 1) {
version = args[1];
}
if (args.length > 2) {
if (StringUtils.equalsIgnoreCase(args[2], "-ssl")) {
// <server> <version> -ssl [<protocols> [<ciphersuites> [<username> [<password>]]]]
if (args.length > 3) {
protocols = args[3];
}
if (args.length > 4) {
cipherSuites = args[4];
}
if (args.length > 5) {
username = args[5];
}
if (args.length > 6) {
password = args[6];
}
} else {
// <server> <version> <username> [<password> [-ssl [<protocols> [<ciphersuites>]]]]
username = args[2];
if (args.length > 3) {
password = args[3];
}
if (args.length > 4 && StringUtils.equalsIgnoreCase(args[4], "-ssl")) {
if (args.length > 5) {
protocols = args[5];
}
if (args.length > 6) {
cipherSuites = args[6];
}
}
}
}

this.server = server;
this.version = version;
this.username = username;
this.password = password;
this.protocols = protocols;
this.cipherSuites = cipherSuites;
}

public String getServer() {
return server;
}

public String getVersion() {
return version;
}

public String getUsername() {
return username;
}

public String getPassword() {
return password;
}

public String getProtocols() {
return protocols;
}

public String getCipherSuites() {
return cipherSuites;
}
}
15 changes: 5 additions & 10 deletions client/src/com/mirth/connect/client/ui/LoginPanel.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
/*
* Copyright (c) Mirth Corporation. All rights reserved.
*
* http://www.mirthcorp.com
*
* The software in this package is published under the terms of the MPL license a copy of which has
* been included with this distribution in the LICENSE.txt file.
*/
// SPDX-License-Identifier: MPL-2.0
// SPDX-FileCopyrightText: Mirth Corporation
// SPDX-FileCopyrightText: 2025 Mitch Gaffigan and Tony Germano

package com.mirth.connect.client.ui;

Expand Down Expand Up @@ -451,7 +446,7 @@ public Void doInBackground() {
}

// If SUCCESS or SUCCESS_GRACE_PERIOD
if ((loginStatus != null) && ((loginStatus.getStatus() == LoginStatus.Status.SUCCESS) || (loginStatus.getStatus() == LoginStatus.Status.SUCCESS_GRACE_PERIOD))) {
if (loginStatus != null && loginStatus.isSuccess()) {
if (!handleSuccess(loginStatus)) {
LoginPanel.getInstance().setVisible(false);
LoginPanel.getInstance().initialize(PlatformUI.SERVER_URL, PlatformUI.CLIENT_VERSION, "", "");
Expand All @@ -469,7 +464,7 @@ public Void doInBackground() {

loginStatus = plugin.authenticate(LoginPanel.this, client, updatedUsername, loginStatus);

if ((loginStatus != null) && ((loginStatus.getStatus() == LoginStatus.Status.SUCCESS) || (loginStatus.getStatus() == LoginStatus.Status.SUCCESS_GRACE_PERIOD))) {
if (loginStatus != null && loginStatus.isSuccess()) {
errorOccurred = false;
if (!handleSuccess(loginStatus)) {
LoginPanel.getInstance().setVisible(false);
Expand Down
67 changes: 10 additions & 57 deletions client/src/com/mirth/connect/client/ui/Mirth.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
/*
* Copyright (c) Mirth Corporation. All rights reserved.
*
* http://www.mirthcorp.com
*
* The software in this package is published under the terms of the MPL license a copy of which has
* been included with this distribution in the LICENSE.txt file.
*/
// SPDX-License-Identifier: MPL-2.0
// SPDX-FileCopyrightText: Mirth Corporation

package com.mirth.connect.client.ui;

Expand Down Expand Up @@ -259,59 +253,18 @@ public static void initUIManager() {
* String[]
*/
public static void main(String[] args) {
String server = "https://localhost:8443";
String version = "";
String username = "";
String password = "";
String protocols = "";
String cipherSuites = "";

if (args.length > 0) {
server = args[0];
}
if (args.length > 1) {
version = args[1];
}
if (args.length > 2) {
if (StringUtils.equalsIgnoreCase(args[2], "-ssl")) {
// <server> <version> -ssl [<protocols> [<ciphersuites> [<username> [<password>]]]]
if (args.length > 3) {
protocols = args[3];
}
if (args.length > 4) {
cipherSuites = args[4];
}
if (args.length > 5) {
username = args[5];
}
if (args.length > 6) {
password = args[6];
}
} else {
// <server> <version> <username> [<password> [-ssl [<protocols> [<ciphersuites>]]]]
username = args[2];
if (args.length > 3) {
password = args[3];
}
if (args.length > 4 && StringUtils.equalsIgnoreCase(args[4], "-ssl")) {
if (args.length > 5) {
protocols = args[5];
}
if (args.length > 6) {
cipherSuites = args[6];
}
}
}
}
CommandLineOptions opts = new CommandLineOptions(args);

if (StringUtils.isNotBlank(protocols)) {
PlatformUI.HTTPS_PROTOCOLS = StringUtils.split(protocols, ',');
if (StringUtils.isNotBlank(opts.getProtocols())) {
PlatformUI.HTTPS_PROTOCOLS = StringUtils.split(opts.getProtocols(), ',');
}
if (StringUtils.isNotBlank(cipherSuites)) {
PlatformUI.HTTPS_CIPHER_SUITES = StringUtils.split(cipherSuites, ',');
if (StringUtils.isNotBlank(opts.getCipherSuites())) {
PlatformUI.HTTPS_CIPHER_SUITES = StringUtils.split(opts.getCipherSuites(), ',');
}
PlatformUI.SERVER_URL = opts.getServer();
PlatformUI.CLIENT_VERSION = opts.getVersion();

start(server, version, username, password);
start(opts.getServer(), opts.getVersion(), opts.getUsername(), opts.getPassword());
}

private static void start(final String server, final String version, final String username, final String password) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// SPDX-License-Identifier: MPL-2.0
// SPDX-FileCopyrightText: 2025 Mitch Gaffigan

package com.mirth.connect.client.ui;

import static org.junit.Assert.assertEquals;

import org.junit.Test;

public class CommandLineOptionsTest {

@Test
public void testParseSslForm() {
String[] args = new String[] { "https://example:8443", "1.0", "-ssl", "TLSv1.2,TLSv1.3", "TLS_RSA_WITH_AES_128_GCM_SHA256", "alice", "secret" };
CommandLineOptions opts = new CommandLineOptions(args);

assertEquals("https://example:8443", opts.getServer());
assertEquals("1.0", opts.getVersion());
assertEquals("alice", opts.getUsername());
assertEquals("secret", opts.getPassword());
assertEquals("TLSv1.2,TLSv1.3", opts.getProtocols());
assertEquals("TLS_RSA_WITH_AES_128_GCM_SHA256", opts.getCipherSuites());
}

@Test
public void testParseUsernameFormWithSsl() {
String[] args = new String[] { "https://example:8443", "1.0", "bob", "pw", "-ssl", "TLSv1.2", "CIPHER" };
CommandLineOptions opts = new CommandLineOptions(args);

assertEquals("https://example:8443", opts.getServer());
assertEquals("1.0", opts.getVersion());
assertEquals("bob", opts.getUsername());
assertEquals("pw", opts.getPassword());
assertEquals("TLSv1.2", opts.getProtocols());
assertEquals("CIPHER", opts.getCipherSuites());
}

@Test
public void testNullArgsUsesDefaults() {
CommandLineOptions opts = new CommandLineOptions((String[]) null);

assertEquals("https://localhost:8443", opts.getServer());
assertEquals("", opts.getVersion());
assertEquals("", opts.getUsername());
assertEquals("", opts.getPassword());
assertEquals("", opts.getProtocols());
assertEquals("", opts.getCipherSuites());
}

@Test
public void testNormal() {
String[] args = new String[] { "https://example:8443", "1.0" };
CommandLineOptions opts = new CommandLineOptions(args);

assertEquals("https://example:8443", opts.getServer());
assertEquals("1.0", opts.getVersion());
assertEquals("", opts.getUsername());
assertEquals("", opts.getPassword());
assertEquals("", opts.getProtocols());
assertEquals("", opts.getCipherSuites());
}
}
14 changes: 6 additions & 8 deletions server/src/com/mirth/connect/model/LoginStatus.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
/*
* Copyright (c) Mirth Corporation. All rights reserved.
*
* http://www.mirthcorp.com
*
* The software in this package is published under the terms of the MPL license a copy of which has
* been included with this distribution in the LICENSE.txt file.
*/
// SPDX-License-Identifier: MPL-2.0
// SPDX-FileCopyrightText: Mirth Corporation

package com.mirth.connect.model;

Expand Down Expand Up @@ -43,4 +37,8 @@ public String getMessage() {
public String getUpdatedUsername() {
return updatedUsername;
}

public boolean isSuccess() {
return status == Status.SUCCESS || status == Status.SUCCESS_GRACE_PERIOD;
}
}