private IUserManager iUserManager;
private BundleContext context = null;
- ServiceTrackerCustomizer<IUserManager, IUserManager> customizer = new ServiceTrackerCustomizer<IUserManager, IUserManager>(){
+ private ServiceTrackerCustomizer<IUserManager, IUserManager> customizer = new ServiceTrackerCustomizer<IUserManager, IUserManager>(){
@Override
public IUserManager addingService(ServiceReference<IUserManager> reference) {
logger.trace("Service {} added, let there be SSH bridge.", reference);
@Override
- public void start(BundleContext context) throws Exception {
+ public void start(BundleContext context) {
this.context = context;
listenForManagerService();
}
@Override
- public void stop(BundleContext context) throws Exception {
+ public void stop(BundleContext context) throws IOException {
if (server != null){
server.stop();
logger.trace("Netconf SSH bridge is down ...");
}
}
- private void startSSHServer() throws Exception {
+ private void startSSHServer() throws IllegalStateException, IOException {
logger.trace("Starting netconf SSH bridge.");
Optional<InetSocketAddress> sshSocketAddressOptional = NetconfConfigUtil.extractSSHNetconfAddress(context, EXCEPTION_MESSAGE);
InetSocketAddress tcpSocketAddress = NetconfConfigUtil.extractTCPNetconfAddress(context,
String path = NetconfConfigUtil.getPrivateKeyPath(context);
path = path.replace("\\", "/"); // FIXME: shouldn't this convert lines to system dependent path separator?
if (path.equals("")){
- throw new Exception("Missing netconf.ssh.pk.path key in configuration file.");
+ throw new IllegalStateException("Missing netconf.ssh.pk.path key in configuration file.");
}
File privateKeyFile = new File(path);
- String privateKeyPEMString;
+ String privateKeyPEMString = null;
if (privateKeyFile.exists() == false) {
// generate & save to file
- privateKeyPEMString = PEMGenerator.generateTo(privateKeyFile);
+ 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)) {
throw new IllegalStateException("Error reading RSA key from file " + path);
}
}
- AuthProvider authProvider = new AuthProvider(iUserManager, privateKeyPEMString);
+ AuthProvider authProvider = null;
+ try {
+ authProvider = new AuthProvider(iUserManager, privateKeyPEMString);
+ } catch (Exception e) {
+ logger.error("Error instantiating AuthProvider {}",e);
+ }
this.server = NetconfSSHServer.start(sshSocketAddressOptional.get().getPort(),tcpSocketAddress,authProvider);
Thread serverThread = new Thread(server,"netconf SSH server thread");
logger.trace("Netconf SSH bridge up and running.");
} else {
logger.trace("No valid connection configuration for SSH bridge found.");
- throw new Exception("No valid connection configuration for SSH bridge found.");
+ throw new IllegalStateException("No valid connection configuration for SSH bridge found.");
}
}
- private void onUserManagerFound(IUserManager userManager) throws Exception{
+ private void onUserManagerFound(IUserManager userManager) throws IOException {
if (server!=null && server.isUp()){
server.addUserManagerService(userManager);
} else {