X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fnetconf%2Fnetconf-ssh%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Fssh%2Fauthentication%2FAuthProvider.java;h=3d5318073d8c0e7cc203fd80fa63b6a05ea71e3e;hb=3d4e563bd21a6b7a159eb5b8512b0e7f274cc767;hp=22dda95064c092c286a1046edc90595943485a0d;hpb=515e60d60ac7dd08aa2440468cd8dab42892e7d0;p=controller.git diff --git a/opendaylight/netconf/netconf-ssh/src/main/java/org/opendaylight/controller/netconf/ssh/authentication/AuthProvider.java b/opendaylight/netconf/netconf-ssh/src/main/java/org/opendaylight/controller/netconf/ssh/authentication/AuthProvider.java index 22dda95064..3d5318073d 100644 --- a/opendaylight/netconf/netconf-ssh/src/main/java/org/opendaylight/controller/netconf/ssh/authentication/AuthProvider.java +++ b/opendaylight/netconf/netconf-ssh/src/main/java/org/opendaylight/controller/netconf/ssh/authentication/AuthProvider.java @@ -7,6 +7,7 @@ */ package org.opendaylight.controller.netconf.ssh.authentication; +import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.List; @@ -23,29 +24,34 @@ public class AuthProvider implements AuthProviderInterface { private static IUserManager um; private static final String DEFAULT_USER = "netconf"; private static final String DEFAULT_PASSWORD = "netconf"; - private static InputStream privateKeyFileInputStream; + private String PEM; private static final Logger logger = LoggerFactory.getLogger(AuthProvider.class); public AuthProvider(IUserManager ium,InputStream privateKeyFileInputStream) throws Exception { - this.um = ium; - if (this.um == null){ + AuthProvider.um = ium; + if (AuthProvider.um == null){ throw new Exception("No usermanager service available."); } - this.privateKeyFileInputStream = privateKeyFileInputStream; - List roles = new ArrayList(1); roles.add(UserLevel.SYSTEMADMIN.toString()); - this.um.addLocalUser(new UserConfig(DEFAULT_USER, DEFAULT_PASSWORD, roles)); + AuthProvider.um.addLocalUser(new UserConfig(DEFAULT_USER, DEFAULT_PASSWORD, roles)); + + try { + PEM = IOUtils.toString(privateKeyFileInputStream); + } catch (IOException e) { + logger.error("Error reading RSA key from file."); + throw new IllegalStateException("Error reading RSA key from file."); + } } @Override public boolean authenticated(String username, String password) throws Exception { - if (this.um == null){ + if (AuthProvider.um == null){ throw new Exception("No usermanager service available."); } - AuthResultEnum authResult = this.um.authenticate(username,password); + AuthResultEnum authResult = AuthProvider.um.authenticate(username,password); if (authResult.equals(AuthResultEnum.AUTH_ACCEPT) || authResult.equals(AuthResultEnum.AUTH_ACCEPT_LOC)){ return true; } @@ -54,19 +60,21 @@ public class AuthProvider implements AuthProviderInterface { @Override public char[] getPEMAsCharArray() throws Exception { - char [] PEM = IOUtils.toCharArray(privateKeyFileInputStream); - privateKeyFileInputStream.close(); - return PEM; + if (null == PEM){ + logger.error("Missing RSA key string."); + throw new Exception("Missing RSA key."); + } + return PEM.toCharArray(); } @Override public void removeUserManagerService() { - this.um = null; + AuthProvider.um = null; } @Override public void addUserManagerService(IUserManager userManagerService) { - this.um = userManagerService; + AuthProvider.um = userManagerService; }