X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fnetconf%2Fnetconf-ssh%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Fssh%2Fauthentication%2FAuthProvider.java;h=6ddc8ebb55752dca439e63ee3e70dfa260e79783;hp=a73dfdfd49eca56129a5ba0e98efb13fba001556;hb=1ded3b4311dc761d39c132f9f38fcceb761ea997;hpb=12c81a67161098bfc9036bd07b07e9f29d447b14 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 a73dfdfd49..6ddc8ebb55 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,70 +7,57 @@ */ 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; -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"; +import java.util.ArrayList; +import java.util.List; +import static com.google.common.base.Preconditions.checkNotNull; - public AuthProvider(IUserManager ium) throws Exception { +public class AuthProvider implements AuthProviderInterface { - this.um = ium; + private static IUserManager um; //FIXME static mutable state, no locks + private static final String DEFAULT_USER = "netconf"; + private static final String DEFAULT_PASSWORD = "netconf"; + private final String pem; - if (this.um == null){ + public AuthProvider(IUserManager ium, String pemCertificate) throws Exception { + checkNotNull(pemCertificate, "Parameter 'pemCertificate' is null"); + AuthProvider.um = ium; + if (AuthProvider.um == null) { throw new Exception("No usermanager service available."); } List roles = new ArrayList(1); roles.add(UserLevel.SYSTEMADMIN.toString()); - this.um.addLocalUser(new UserConfig(DEAFULT_USER, DEAFULT_PASSWORD, roles)); + AuthProvider.um.addLocalUser(new UserConfig(DEFAULT_USER, DEFAULT_PASSWORD, roles)); //FIXME hardcoded auth + pem = pemCertificate; } + @Override - public boolean authenticated(String username, String password) throws Exception { - if (this.um == null){ - throw new Exception("No usermanager service available."); + public boolean authenticated(String username, String password) { + if (AuthProvider.um == null) { + throw new IllegalStateException("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; + AuthResultEnum authResult = AuthProvider.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 public void removeUserManagerService() { - this.um = null; + AuthProvider.um = null; } @Override public void addUserManagerService(IUserManager userManagerService) { - this.um = userManagerService; + AuthProvider.um = userManagerService; } - - }