Merge "Fixed typo in SnapshotBackedWriteTransaction class"
[controller.git] / opendaylight / netconf / netconf-ssh / src / main / java / org / opendaylight / controller / netconf / ssh / authentication / AuthProvider.java
index a73dfdfd49eca56129a5ba0e98efb13fba001556..2e9a0b9d8bbd256154ff82689e85e556b60c9e90 100644 (file)
@@ -7,59 +7,32 @@
  */
 package org.opendaylight.controller.netconf.ssh.authentication;
 
-import ch.ethz.ssh2.signature.RSAPrivateKey;
 import java.io.IOException;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.List;
-import org.apache.commons.io.IOUtils;
 import org.opendaylight.controller.sal.authorization.AuthResultEnum;
-import org.opendaylight.controller.sal.authorization.UserLevel;
 import org.opendaylight.controller.usermanager.IUserManager;
-import org.opendaylight.controller.usermanager.UserConfig;
+import static com.google.common.base.Preconditions.checkNotNull;
 
 public class AuthProvider implements AuthProviderInterface {
 
-    private static RSAPrivateKey hostkey = null;
-    private static IUserManager um;
-    private static final String DEAFULT_USER = "netconf";
-    private static final String DEAFULT_PASSWORD = "netconf";
-
-
-    public AuthProvider(IUserManager ium) throws Exception {
+    private IUserManager um;
+    private final String pem;
 
+    public AuthProvider(IUserManager ium, String pemCertificate) throws IllegalArgumentException, IOException {
+        checkNotNull(pemCertificate, "Parameter 'pemCertificate' is null");
+        checkNotNull(ium, "No user manager service available.");
         this.um = ium;
-
-        if (this.um  == null){
-            throw new Exception("No usermanager service available.");
-        }
-
-        List<String> roles = new ArrayList<String>(1);
-        roles.add(UserLevel.SYSTEMADMIN.toString());
-        this.um.addLocalUser(new UserConfig(DEAFULT_USER, DEAFULT_PASSWORD, roles));
+        pem = pemCertificate;
     }
+
     @Override
-    public boolean authenticated(String username, String password)  throws Exception {
-        if (this.um  == null){
-            throw new Exception("No usermanager service available.");
-        }
-        AuthResultEnum authResult = this.um.authenticate(username,password);
-        if (authResult.equals(AuthResultEnum.AUTH_ACCEPT) || authResult.equals(AuthResultEnum.AUTH_ACCEPT_LOC)){
-            return true;
-        }
-        return false;
+    public boolean authenticated(String username, String password) {
+        AuthResultEnum authResult = this.um.authenticate(username, password);
+        return authResult.equals(AuthResultEnum.AUTH_ACCEPT) || authResult.equals(AuthResultEnum.AUTH_ACCEPT_LOC);
     }
 
     @Override
     public char[] getPEMAsCharArray() {
-
-        InputStream is = getClass().getResourceAsStream("/RSA.pk");
-        try {
-            return IOUtils.toCharArray(is);
-        } catch (IOException e) {
-            e.printStackTrace();
-        }
-        return null;
+        return pem.toCharArray();
     }
 
     @Override
@@ -71,6 +44,4 @@ public class AuthProvider implements AuthProviderInterface {
     public void addUserManagerService(IUserManager userManagerService) {
         this.um = userManagerService;
     }
-
-
 }