diff --git a/README.md b/README.md index ca797b2..bdfd0cc 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,14 @@ Where: • [-m server-ip] (Optional): Management server ip address. Default value is 127.0.0.1. +• [-u username] (Optional): Management administrator user name. + +• [-p password] (Optional): Management administrator password. + +• [--api-key] (Optional): Management administrator API key. + +• [--cloud-mgmt-id] (Optional): Smart-1 Cloud management UID. + • [-d domain-name] (Optional): The name or uid of the Security Management Server domain. When running the command on a Multi domain server the default domain is the "MDS". diff --git a/src/main/java/com/checkpoint/mgmt_api/examples/ShowPackageConfiguration.java b/src/main/java/com/checkpoint/mgmt_api/examples/ShowPackageConfiguration.java index e246bf8..d66a65b 100644 --- a/src/main/java/com/checkpoint/mgmt_api/examples/ShowPackageConfiguration.java +++ b/src/main/java/com/checkpoint/mgmt_api/examples/ShowPackageConfiguration.java @@ -36,6 +36,7 @@ public enum ShowPackageConfiguration { private static final String RULEBASE_FILE = "rulebase.txt"; /*Management server IP address*/ private static String server = ApiClient.LOCAL_SERVER_IP; + private static String cloudMgmtId = null; /*Set the names of the tar and log files*/ private static final String tarName; @@ -51,6 +52,7 @@ public enum ShowPackageConfiguration { /*Login credentials*/ private static String username; private static String password; + private static String apiKey; private static String domain; private static int port; private static boolean userEnteredPort = false; @@ -293,19 +295,23 @@ JSONObject createPayloadForLogin(boolean loginAsRoot){ JSONObject payload = new JSONObject(); String missing_arg; if (!loginAsRoot) { - if (username != null && !username.isEmpty()) { - payload.put("user", username); - } - else{ - String userName = readUserName(); - payload.put("user", userName); - } - if (password != null && !password.isEmpty()) { - payload.put("password", password); - } - else{ - char[] passwordFromConsole = readPassword(); - payload.put("password", new String(passwordFromConsole)); + if(apiKey != null && !apiKey.isEmpty()){ + payload.put("api-key", apiKey); + }else{ + if (username != null && !username.isEmpty()) { + payload.put("user", username); + } + else{ + String userName = readUserName(); + payload.put("user", userName); + } + if (password != null && !password.isEmpty()) { + payload.put("password", password); + } + else{ + char[] passwordFromConsole = readPassword(); + payload.put("password", new String(passwordFromConsole)); + } } } if(domain != null && !domain.isEmpty()){ @@ -546,6 +552,10 @@ public Boolean getDereferenceGroupMembers() public boolean showRuleUidFlag() { return showEachRulesUid; } + public String getApiKey() { return apiKey; } + + public String getCloudMgmtId() { return cloudMgmtId; } + /** * This enum defines the known flags and the actions each of them does. */ @@ -653,6 +663,43 @@ String debugString() return "password:(-p)=*****"; } }, + adminApiKey("--api-key") { + void runCommand(String value) + { + apiKey = value; + } + + void flagToString() + { + System.out.println("\tManagement administrator API key."); + } + + String value(){ + return " API key"; + } + + String debugString() + { + return "API key:(--api-key)=*****"; + } + }, + mgmtCloudId("--cloud-mgmt-id") { + void runCommand(String value) { cloudMgmtId = value; } + + void flagToString() + { + System.out.println("\tSmart-1 Cloud management UID."); + } + + String value(){ + return " Smart-1 Cloud management UID"; + } + + String debugString() + { + return "Smart-1 Cloud management UID:(--cloud-mgmt-id)=" + cloudMgmtId; + } + }, domainName("-d") { void runCommand(String value) { diff --git a/src/main/java/com/checkpoint/mgmt_api/examples/ShowPackageTool.java b/src/main/java/com/checkpoint/mgmt_api/examples/ShowPackageTool.java index 6f4b3e0..6af7e0b 100644 --- a/src/main/java/com/checkpoint/mgmt_api/examples/ShowPackageTool.java +++ b/src/main/java/com/checkpoint/mgmt_api/examples/ShowPackageTool.java @@ -138,7 +138,7 @@ public static void main(String[] args) { /*Login to the Check Point Management server*/ if (!loginAsRoot) { try { - loginResponse = client.login(configuration.getServer(), configuration.createPayloadForLogin(false)); + loginResponse = client.login(configuration.getServer(), configuration.createPayloadForLogin(false), configuration.getCloudMgmtId()); } catch (ApiClientException e) { logoutReportAndExit("An error occurred while logging in to the server. Exception: "+ e.getMessage(), MessageType.SEVERE); @@ -292,7 +292,7 @@ private static void handlePublishedSession(IndexView index) private static boolean isLoginAsRoot(){ /*Check if the user entered use name and password*/ - if (configuration.getUsername() != null && configuration.getPassword() != null){ + if (configuration.getUsername() != null && configuration.getPassword() != null && configuration.getApiKey() != null){ return false; }