diff --git a/src/main/java/com/oneidentity/safeguard/safeguardjava/Safeguard.java b/src/main/java/com/oneidentity/safeguard/safeguardjava/Safeguard.java index 34bae6f..9710915 100644 --- a/src/main/java/com/oneidentity/safeguard/safeguardjava/Safeguard.java +++ b/src/main/java/com/oneidentity/safeguard/safeguardjava/Safeguard.java @@ -1887,6 +1887,8 @@ public static ISafeguardEventListener getPersistentA2AEventListener(List } /** + * NOT SUPPORTED + * * Get a persistent A2A event listener. The handler passed in * will be registered for the AssetAccountPasswordUpdated event, * which is the only one supported in A2A. Uses a client @@ -1913,6 +1915,9 @@ public static ISafeguardEventListener getPersistentA2AEventListener(List HostnameVerifier validationCallback, Integer apiVersion) throws ObjectDisposedException, ArgumentException, SafeguardForJavaException { + throw new SafeguardForJavaException("Not supported. This function is not available for Java."); + + /* int version = DEFAULTAPIVERSION; if (apiVersion != null) { version = apiVersion; @@ -1930,9 +1935,12 @@ public static ISafeguardEventListener getPersistentA2AEventListener(List return new PersistentSafeguardA2AEventListener( new SafeguardA2AContext(networkAddress, version, false, thumbprint, validationCallback), apiKeys, handler); + */ } /** + * NOT SUPPORTED + * * Get a persistent A2A event listener. The handler passed in * will be registered for the AssetAccountPasswordUpdated event, * which is the only one supported in A2A. Uses a client @@ -1959,6 +1967,9 @@ public static ISafeguardEventListener getPersistentA2AEventListener(List Integer apiVersion, Boolean ignoreSsl) throws ObjectDisposedException, ArgumentException, SafeguardForJavaException { + throw new SafeguardForJavaException("Not supported. This function is not available for Java."); + + /* int version = DEFAULTAPIVERSION; if (apiVersion != null) { version = apiVersion; @@ -1981,6 +1992,7 @@ public static ISafeguardEventListener getPersistentA2AEventListener(List return new PersistentSafeguardA2AEventListener( new SafeguardA2AContext(networkAddress, version, ignoreSsl, thumbprint, null), apiKeys, handler); + */ } /** diff --git a/src/main/java/com/oneidentity/safeguard/safeguardjava/data/SafeguardEventListenerState.java b/src/main/java/com/oneidentity/safeguard/safeguardjava/data/SafeguardEventListenerState.java new file mode 100644 index 0000000..ad278a1 --- /dev/null +++ b/src/main/java/com/oneidentity/safeguard/safeguardjava/data/SafeguardEventListenerState.java @@ -0,0 +1,16 @@ +package com.oneidentity.safeguard.safeguardjava.data; + + /** + * Connection state of the Safeguard event listener. + */ + public enum SafeguardEventListenerState + { + /** + * Event listener connected. + */ + Connected, + /** + * Event listener disconnected. + */ + Disconnected + } diff --git a/src/main/java/com/oneidentity/safeguard/safeguardjava/event/ISafeguardEventListener.java b/src/main/java/com/oneidentity/safeguard/safeguardjava/event/ISafeguardEventListener.java index 9097492..9f64766 100644 --- a/src/main/java/com/oneidentity/safeguard/safeguardjava/event/ISafeguardEventListener.java +++ b/src/main/java/com/oneidentity/safeguard/safeguardjava/event/ISafeguardEventListener.java @@ -22,6 +22,14 @@ public interface ISafeguardEventListener */ void registerEventHandler(String eventName, ISafeguardEventHandler handler) throws ObjectDisposedException; + /** + * Set an event listener callback that will be called each time the connection + * state changes of the event listener. + * + * @param eventListenerStateCallback Callback method. + */ + void SetEventListenerStateCallback(ISafeguardEventListenerStateCallback eventListenerStateCallback); + /** * Start listening for Safeguard events in a background thread. * @throws ObjectDisposedException Object has already been disposed diff --git a/src/main/java/com/oneidentity/safeguard/safeguardjava/event/ISafeguardEventListenerStateCallback.java b/src/main/java/com/oneidentity/safeguard/safeguardjava/event/ISafeguardEventListenerStateCallback.java new file mode 100644 index 0000000..e95d39b --- /dev/null +++ b/src/main/java/com/oneidentity/safeguard/safeguardjava/event/ISafeguardEventListenerStateCallback.java @@ -0,0 +1,16 @@ +package com.oneidentity.safeguard.safeguardjava.event; + +import com.oneidentity.safeguard.safeguardjava.data.SafeguardEventListenerState; + +/** + * A callback that will be called whenever the event listener connection state Changes. + */ +public interface ISafeguardEventListenerStateCallback { + /** + * Handles an incoming event listener connection change. + * + * @param eventListenerState New connection state of the event listener. + */ + void onEventListenerStateChange(SafeguardEventListenerState eventListenerState); +} + diff --git a/src/main/java/com/oneidentity/safeguard/safeguardjava/event/PersistentSafeguardEventListenerBase.java b/src/main/java/com/oneidentity/safeguard/safeguardjava/event/PersistentSafeguardEventListenerBase.java index 7cc0e1a..e2cd6e8 100644 --- a/src/main/java/com/oneidentity/safeguard/safeguardjava/event/PersistentSafeguardEventListenerBase.java +++ b/src/main/java/com/oneidentity/safeguard/safeguardjava/event/PersistentSafeguardEventListenerBase.java @@ -12,6 +12,7 @@ public abstract class PersistentSafeguardEventListenerBase implements ISafeguard private SafeguardEventListener eventListener; private final EventHandlerRegistry eventHandlerRegistry = new EventHandlerRegistry(); + private ISafeguardEventListenerStateCallback eventListenerStateCallback; private Thread reconnectThread = null; boolean isCancellationRequested = false; @@ -28,6 +29,12 @@ public void registerEventHandler(String eventName, ISafeguardEventHandler handle this.eventHandlerRegistry.registerEventHandler(eventName, handler); } + @Override + public void SetEventListenerStateCallback(ISafeguardEventListenerStateCallback eventListenerStateCallback) + { + this.eventListenerStateCallback = eventListenerStateCallback; + } + protected abstract SafeguardEventListener reconnectEventListener() throws ObjectDisposedException, SafeguardForJavaException, ArgumentException; class PersistentReconnectAndStartHandler implements IDisconnectHandler { @@ -56,6 +63,7 @@ public void run() { "Attempting to connect and start internal event listener."); eventListener = reconnectEventListener(); eventListener.setEventHandlerRegistry(eventHandlerRegistry); + eventListener.SetEventListenerStateCallback(eventListenerStateCallback); eventListener.start(); eventListener.setDisconnectHandler(new PersistentReconnectAndStartHandler()); break; @@ -67,6 +75,7 @@ public void run() { try { Thread.sleep(5000); } catch (InterruptedException ex1) { + isCancellationRequested = true; } } } @@ -78,11 +87,10 @@ public void run() { this.reconnectThread.start(); this.reconnectThread.join(); } catch (InterruptedException ex1) { + isCancellationRequested = true; } - if (isCancellationRequested) - this.reconnectThread = null; - + this.reconnectThread = null; } @Override diff --git a/src/main/java/com/oneidentity/safeguard/safeguardjava/event/SafeguardEventListener.java b/src/main/java/com/oneidentity/safeguard/safeguardjava/event/SafeguardEventListener.java index 34be5d3..a5f158d 100644 --- a/src/main/java/com/oneidentity/safeguard/safeguardjava/event/SafeguardEventListener.java +++ b/src/main/java/com/oneidentity/safeguard/safeguardjava/event/SafeguardEventListener.java @@ -7,6 +7,7 @@ import com.microsoft.signalr.Action1; import com.microsoft.signalr.OnClosedCallback; import com.oneidentity.safeguard.safeguardjava.data.CertificateContext; +import com.oneidentity.safeguard.safeguardjava.data.SafeguardEventListenerState; import com.oneidentity.safeguard.safeguardjava.exceptions.ArgumentException; import com.oneidentity.safeguard.safeguardjava.exceptions.ObjectDisposedException; import com.oneidentity.safeguard.safeguardjava.exceptions.SafeguardEventListenerDisconnectedException; @@ -14,6 +15,7 @@ import io.reactivex.rxjava3.core.Single; import java.io.ByteArrayInputStream; +import java.io.FileInputStream; import java.io.InputStream; import java.security.KeyManagementException; import java.security.KeyStore; @@ -57,6 +59,7 @@ public class SafeguardEventListener implements ISafeguardEventListener, AutoClos private EventHandlerRegistry eventHandlerRegistry; private IDisconnectHandler disconnectHandler; + private ISafeguardEventListenerStateCallback eventListenerStateCallback; private HubConnection signalrConnection = null; private static final String NOTIFICATION_HUB = "signalr"; @@ -107,8 +110,8 @@ public SafeguardEventListener(String eventUrl, String clientCertificatePath, cha this.clientCertificate = new CertificateContext(certificateAlias, clientCertificatePath, null, certificatePassword); this.apiKeys = new ArrayList<>(); for (char[] key : apiKeys) - apiKeys.add(key.clone()); - if (apiKeys.isEmpty()) + this.apiKeys.add(key.clone()); + if (this.apiKeys.isEmpty()) throw new ArgumentException("The apiKeys parameter must include at least one item"); } @@ -122,8 +125,8 @@ public SafeguardEventListener(String eventUrl, CertificateContext clientCertific this.clientCertificate = clientCertificate.cloneObject(); this.apiKeys = new ArrayList<>(); for (char[] key : apiKeys) - apiKeys.add(key.clone()); - if (apiKeys.isEmpty()) + this.apiKeys.add(key.clone()); + if (this.apiKeys.isEmpty()) throw new ArgumentException("The apiKeys parameter must include at least one item"); } @@ -149,6 +152,12 @@ public void registerEventHandler(String eventName, ISafeguardEventHandler handle } eventHandlerRegistry.registerEventHandler(eventName, handler); } + + @Override + public void SetEventListenerStateCallback(ISafeguardEventListenerStateCallback eventListenerStateCallback) + { + this.eventListenerStateCallback = eventListenerStateCallback; + } @Override public void start() throws ObjectDisposedException, SafeguardForJavaException, SafeguardEventListenerDisconnectedException { @@ -185,6 +194,7 @@ public void invoke(Exception exception){ // Start the connection try{ signalrConnection.start().blockingAwait(); + CallEventListenerStateCallback(SafeguardEventListenerState.Connected); } catch(Exception error) { throw new SafeguardForJavaException(String.format("Failed to start signalr connection: %s", error.getMessage()), error); @@ -252,8 +262,22 @@ private void handleDisconnect() throws SafeguardEventListenerDisconnectedExcepti return; } Logger.getLogger(EventHandlerRegistry.class.getName()).log(Level.WARNING, "SignalR disconnect detected, calling handler..."); + CallEventListenerStateCallback(SafeguardEventListenerState.Disconnected); disconnectHandler.func(); } + + private void CallEventListenerStateCallback(SafeguardEventListenerState newState) + { + if (eventListenerStateCallback != null) { + try { + eventListenerStateCallback.onEventListenerStateChange(newState); + } + catch(Exception e) + { + // Just in case the user's callback function throws an exception. + } + } + } private void cleanupConnection() { try { @@ -306,11 +330,15 @@ private void ConfigureHttpClientBuilder(Builder builder) } KeyManager[] km = null; - if(clientCertificate != null){ + if(clientCertificate != null && + (clientCertificate.getCertificateData() != null || clientCertificate.getCertificatePath() != null)){ + // If we have a client certificate, set it into the KeyStore/KeyManager try{ KeyStore keyStore = KeyStore.getInstance("PKCS12"); - InputStream inputStream = new ByteArrayInputStream(clientCertificate.getCertificateData()); + InputStream inputStream = clientCertificate.getCertificatePath() != null ? new FileInputStream(clientCertificate.getCertificatePath()) + : new ByteArrayInputStream(clientCertificate.getCertificateData()); + keyStore.load(inputStream, clientCertificate.getCertificatePassword()); KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()); diff --git a/tests/safeguardjavaclient/src/main/java/com/oneidentity/safeguard/safeguardclient/SafeguardJavaClient.java b/tests/safeguardjavaclient/src/main/java/com/oneidentity/safeguard/safeguardclient/SafeguardJavaClient.java index 417a199..ac31a92 100644 --- a/tests/safeguardjavaclient/src/main/java/com/oneidentity/safeguard/safeguardclient/SafeguardJavaClient.java +++ b/tests/safeguardjavaclient/src/main/java/com/oneidentity/safeguard/safeguardclient/SafeguardJavaClient.java @@ -23,6 +23,7 @@ public static void main(String[] args) { ISafeguardSessionsConnection sessionConnection = null; ISafeguardA2AContext a2aContext = null; ISafeguardEventListener eventListener = null; + ISafeguardEventListener a2aEventListener = null; boolean done = false; SafeguardTests tests = new SafeguardTests(); @@ -97,39 +98,55 @@ public static void main(String[] args) { tests.safeguardTestEventListener(eventListener); break; case 19: - eventListener = tests.safeguardDisconnectEventListener(eventListener); + a2aEventListener = tests.safeguardA2AEventListenerByCertificate(); break; case 20: - tests.safeguardListBackups(connection); + a2aEventListener = tests.safeguardA2AEventListenerByThumbprint(); break; case 21: - tests.safeguardTestBackupDownload(connection); + tests.safeguardTestA2AEventListener(a2aEventListener); break; case 22: - tests.safeguardTestBackupUpload(connection); + { + if (eventListener != null) { + eventListener = tests.safeguardDisconnectEventListener(eventListener); + } + if (a2aEventListener != null) { + a2aEventListener = tests.safeguardDisconnectEventListener(a2aEventListener); + } + } break; case 23: - sessionConnection = tests.safeguardSessionsConnection(); + tests.safeguardListBackups(connection); break; case 24: - tests.safeguardSessionsApi(sessionConnection); + tests.safeguardTestBackupDownload(connection); break; case 25: - tests.safeguardSessionsFileUpload(sessionConnection); + tests.safeguardTestBackupUpload(connection); break; case 26: - tests.safeguardSessionsStreamUpload(sessionConnection); + sessionConnection = tests.safeguardSessionsConnection(); break; case 27: - tests.safeguardSessionTestRecordingDownload(sessionConnection); + tests.safeguardSessionsApi(sessionConnection); break; case 28: - tests.safeguardTestJoinSps(connection, sessionConnection); + tests.safeguardSessionsFileUpload(sessionConnection); break; case 29: - tests.safeguardTestManagementConnection(connection); + tests.safeguardSessionsStreamUpload(sessionConnection); break; case 30: + tests.safeguardSessionTestRecordingDownload(sessionConnection); + break; + case 31: + tests.safeguardTestJoinSps(connection, sessionConnection); + break; + case 32: + tests.safeguardTestManagementConnection(connection); + break; + case 33: tests.safeguardTestAnonymousConnection(connection); break; default: @@ -168,18 +185,21 @@ private static Integer displayMenu() { System.out.println ("\t16. Event Listener by keystore"); System.out.println ("\t17. Event Listener by thumbprint"); System.out.println ("\t18. Test Event Listener"); - System.out.println ("\t19. Disconnect Event Listener"); - System.out.println ("\t20. Test List Backups"); - System.out.println ("\t21. Test Download Backup File"); - System.out.println ("\t22. Test Upload Backup File"); - System.out.println ("\t23. Test SPS Connection"); - System.out.println ("\t24. Test SPS API"); - System.out.println ("\t25. Test SPS Firmware Upload"); - System.out.println ("\t26. Test Stream Upload"); - System.out.println ("\t27. Test Session Recording Download"); - System.out.println ("\t28. Test Join SPS"); - System.out.println ("\t29. Test Management Interface API"); - System.out.println ("\t30. Test Anonymous Connection"); + System.out.println ("\t19. A2A Event Listener by certificate file"); + System.out.println ("\t20. A2A Event Listener by thumbprint"); + System.out.println ("\t21. Test A2A Event Listener"); + System.out.println ("\t22. Disconnect Event Listener"); + System.out.println ("\t23. Test List Backups"); + System.out.println ("\t24. Test Download Backup File"); + System.out.println ("\t25. Test Upload Backup File"); + System.out.println ("\t26. Test SPS Connection"); + System.out.println ("\t27. Test SPS API"); + System.out.println ("\t28. Test SPS Firmware Upload"); + System.out.println ("\t29. Test Stream Upload"); + System.out.println ("\t30. Test Session Recording Download"); + System.out.println ("\t31. Test Join SPS"); + System.out.println ("\t32. Test Management Interface API"); + System.out.println ("\t33. Test Anonymous Connection"); System.out.println ("\t99. Exit"); diff --git a/tests/safeguardjavaclient/src/main/java/com/oneidentity/safeguard/safeguardclient/SafeguardTests.java b/tests/safeguardjavaclient/src/main/java/com/oneidentity/safeguard/safeguardclient/SafeguardTests.java index 9f5d07b..7acd88d 100644 --- a/tests/safeguardjavaclient/src/main/java/com/oneidentity/safeguard/safeguardclient/SafeguardTests.java +++ b/tests/safeguardjavaclient/src/main/java/com/oneidentity/safeguard/safeguardclient/SafeguardTests.java @@ -24,6 +24,7 @@ import com.oneidentity.safeguard.safeguardjava.data.FullResponse; import com.oneidentity.safeguard.safeguardjava.data.KeyFormat; import com.oneidentity.safeguard.safeguardjava.data.Method; +import com.oneidentity.safeguard.safeguardjava.data.SafeguardEventListenerState; import com.oneidentity.safeguard.safeguardjava.data.Service; import com.oneidentity.safeguard.safeguardjava.event.ISafeguardEventHandler; import com.oneidentity.safeguard.safeguardjava.event.ISafeguardEventListener; @@ -38,9 +39,8 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.ArrayList; import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; import java.util.regex.Pattern; import java.util.stream.Collectors; @@ -260,6 +260,12 @@ public ISafeguardA2AContext safeguardGetA2AContextByCertificate() { boolean withCertValidator = readLine("With Certificate Validator(y/n): ", "n").equalsIgnoreCase("y"); boolean ignoreSsl = readLine("Ignore SSL(y/n): ", "y").equalsIgnoreCase("y"); + return safeguardGetA2AContextByCertificate(address, certificatePath, password, withCertValidator, ignoreSsl); + } + + private ISafeguardA2AContext safeguardGetA2AContextByCertificate(String address, String certificatePath, String password, boolean withCertValidator, boolean ignoreSsl) { + ISafeguardA2AContext a2aContext = null; + try { if (withCertValidator) { a2aContext = Safeguard.A2A.getContext(address, certificatePath, password.toCharArray(), new CertificateValidator(), null); @@ -300,13 +306,18 @@ public ISafeguardA2AContext safeguardGetA2AContextByKeystore() { return a2aContext; } - ISafeguardA2AContext safeguardGetA2AContextByThumbprint() { - ISafeguardA2AContext a2aContext = null; + public ISafeguardA2AContext safeguardGetA2AContextByThumbprint() { String address = readLine("SPP address: ", null); String thumbprint = readLine("Thumbprint:", null); boolean withCertValidator = readLine("With Certificate Validator(y/n): ", "y").equalsIgnoreCase("y"); boolean ignoreSsl = readLine("Ignore SSL(y/n): ", "y").equalsIgnoreCase("y"); + + return safeguardGetA2AContextByThumbprint(address, thumbprint, withCertValidator, ignoreSsl); + } + + private ISafeguardA2AContext safeguardGetA2AContextByThumbprint(String address, String thumbprint, boolean withCertValidator, boolean ignoreSsl) { + ISafeguardA2AContext a2aContext = null; try { if (withCertValidator) { @@ -462,6 +473,95 @@ public ISafeguardA2AContext safeguardDisconnectA2AContext(ISafeguardA2AContext a } return null; } + + private List ReadAllApiKeys(ISafeguardA2AContext context) throws ObjectDisposedException, SafeguardForJavaException + { + List apiKeys = new ArrayList(); + List retrievableAccounts = context.getRetrievableAccounts(); + for (IA2ARetrievableAccount account : retrievableAccounts) + { + System.out.println(account.toString()); + apiKeys.add(account.getApiKey()); + } + + return apiKeys; + } + + public ISafeguardEventListener safeguardA2AEventListenerByCertificate() { + + String address = readLine("SPP address: ", null); + String certificatePath = readLine("Certificate Path:", null); + String password = readLine("Password: ", null); + boolean withCertValidator = readLine("With Certificate Validator(y/n): ", "n").equalsIgnoreCase("y"); + boolean ignoreSsl = readLine("Ignore SSL(y/n): ", "y").equalsIgnoreCase("y"); + + ISafeguardA2AContext a2aContext = safeguardGetA2AContextByCertificate(address, certificatePath, password, withCertValidator, ignoreSsl); + + ISafeguardEventListener eventListener = null; + + try { + List apiKeys = ReadAllApiKeys(a2aContext); + ISafeguardEventHandler a2aHandler = + (String eventName, String eventBody) -> { + System.out.println(String.format("\tEvent body for %s event", eventName)); + System.out.println(String.format("\t\t%s", eventBody)); + }; + + if (withCertValidator) { + eventListener = Safeguard.A2A.Event.getPersistentA2AEventListener(apiKeys, a2aHandler, address, + certificatePath, password.toCharArray(), new CertificateValidator(), null); + } else { + eventListener = Safeguard.A2A.Event.getPersistentA2AEventListener(apiKeys, a2aHandler, address, + certificatePath, password.toCharArray(), null, ignoreSsl); + } + } catch (ObjectDisposedException | SafeguardForJavaException ex) { + System.out.println("\t[ERROR]Event listener failed: " + ex.getMessage()); + } catch (Exception ex) { + System.out.println("\t[ERROR]Event listener failed: " + ex.getMessage()); + } + + if (eventListener != null) + System.out.println("\tSuccessfully create an event listener."); + return eventListener; + } + + public ISafeguardEventListener safeguardA2AEventListenerByThumbprint() { + + String address = readLine("SPP address: ", null); + String thumbprint = readLine("Thumbprint:", null); + boolean withCertValidator = readLine("With Certificate Validator(y/n): ", "n").equalsIgnoreCase("y"); + boolean ignoreSsl = readLine("Ignore SSL(y/n): ", "y").equalsIgnoreCase("y"); + + + ISafeguardA2AContext a2aContext = safeguardGetA2AContextByThumbprint(address, thumbprint, withCertValidator, ignoreSsl); + + ISafeguardEventListener eventListener = null; + + try { + List apiKeys = ReadAllApiKeys(a2aContext); + ISafeguardEventHandler a2aHandler = + (String eventName, String eventBody) -> { + System.out.println(String.format("\tEvent body for %s event", eventName)); + System.out.println(String.format("\t\t%s", eventBody)); + }; + + if (withCertValidator) { + eventListener = Safeguard.A2A.Event.getPersistentA2AEventListener(apiKeys, a2aHandler, address, + thumbprint, new CertificateValidator(), null); + } else { + eventListener = Safeguard.A2A.Event.getPersistentA2AEventListener(apiKeys, a2aHandler, address, + thumbprint, null, ignoreSsl); + } + } catch (ObjectDisposedException | SafeguardForJavaException ex) { + System.out.println("\t[ERROR]Event listener failed: " + ex.getMessage()); + } catch (Exception ex) { + System.out.println("\t[ERROR]Event listener failed: " + ex.getMessage()); + } + + if (eventListener != null) + System.out.println("\tSuccessfully create an event listener."); + return eventListener; + } public ISafeguardEventListener safeguardEventListenerByUserPassword() { @@ -494,7 +594,6 @@ public ISafeguardEventListener safeguardEventListenerByUserPassword() { public ISafeguardEventListener safeguardEventListenerByCertificate() { String address = readLine("SPP address: ", null); - String provider = readLine("Provider:", null); String certificatePath = readLine("Certificate Path:", null); String password = readLine("Password: ", null); boolean withCertValidator = readLine("With Certificate Validator(y/n): ", "n").equalsIgnoreCase("y"); @@ -504,9 +603,9 @@ public ISafeguardEventListener safeguardEventListenerByCertificate() { try { if (withCertValidator) { - eventListener = Safeguard.Event.getPersistentEventListener(address, certificatePath, password.toCharArray(), new CertificateValidator(), provider, null); + eventListener = Safeguard.Event.getPersistentEventListener(address, certificatePath, password.toCharArray(), new CertificateValidator(), null); } else { - eventListener = Safeguard.Event.getPersistentEventListener(address, certificatePath, password.toCharArray(), provider, null, ignoreSsl); + eventListener = Safeguard.Event.getPersistentEventListener(address, certificatePath, password.toCharArray(), null, ignoreSsl); } } catch (ObjectDisposedException | SafeguardForJavaException ex) { System.out.println("\t[ERROR]Event listener failed: " + ex.getMessage()); @@ -610,6 +709,30 @@ public void onEventReceived(String eventName, String eventBody) { System.out.println("\t[ERROR]Test event listener failed: " + ex.getMessage()); } } + + public void safeguardTestA2AEventListener(ISafeguardEventListener eventListener) { + + if (eventListener == null) { + System.out.println(String.format("\t[ERROR]Missing event listener")); + return; + } + + try { + + eventListener.SetEventListenerStateCallback((SafeguardEventListenerState eventListenerState) -> { + System.out.println(String.format("\tGot a SignalR connection state change: %s", eventListenerState.toString())); + }); + + System.out.print("\tStarting the event listener"); + eventListener.start(); + readLine("Press enter to stop...", null); + eventListener.stop(); + } catch (ObjectDisposedException | SafeguardForJavaException ex) { + System.out.println("\t[ERROR]Test event listener failed: " + ex.getMessage()); + } catch (Exception ex) { + System.out.println("\t[ERROR]Test event listener failed: " + ex.getMessage()); + } + } public ISafeguardEventListener safeguardDisconnectEventListener(ISafeguardEventListener eventListener) { if (eventListener != null) {