- File privateKeyFile = new File(path);
- String privateKeyPEMString = null;
- if (privateKeyFile.exists() == false) {
- // generate & save to file
- try {
- privateKeyPEMString = PEMGenerator.generateTo(privateKeyFile);
- } catch (Exception e) {
- logger.error("Exception occured while generating PEM string {}",e);
- }
- } else {
- // read from file
- try (FileInputStream fis = new FileInputStream(path)) {
- privateKeyPEMString = IOUtils.toString(fis);
- } catch (IOException e) {
- logger.error("Error reading RSA key from file '{}'", path);
- throw new IllegalStateException("Error reading RSA key from file " + path);
+ private static class AuthProviderTracker implements ServiceTrackerCustomizer<AuthProvider, AuthProvider> {
+ private final BundleContext bundleContext;
+ private final NetconfSSHServer server;
+
+ private Integer maxPreference;
+ private Thread sshThread;
+ private final ServiceTracker<AuthProvider, AuthProvider> listenerTracker;
+
+ public AuthProviderTracker(final BundleContext bundleContext, final NetconfSSHServer server) {
+ this.bundleContext = bundleContext;
+ this.server = server;
+ listenerTracker = new ServiceTracker<>(bundleContext, AuthProvider.class, this);
+ listenerTracker.open();
+ }
+
+ @Override
+ public AuthProvider addingService(final ServiceReference<AuthProvider> reference) {
+ logger.trace("Service {} added", reference);
+ final AuthProvider authService = bundleContext.getService(reference);
+ final Integer newServicePreference = getPreference(reference);
+ if(isBetter(newServicePreference)) {
+ maxPreference = newServicePreference;
+ server.setAuthProvider(authService);
+ if(sshThread == null) {
+ sshThread = runNetconfSshThread(server);