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=2e9a0b9d8bbd256154ff82689e85e556b60c9e90;hp=2d380482ba456afd4beef97c77d7a86d1bf79f14;hb=31b7a44c89d1057489338492fcf62a64147bea24;hpb=33aa42c3375a40d417fa0612249c8831c8066473 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 2d380482ba..2e9a0b9d8b 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,42 +7,26 @@ */ package org.opendaylight.controller.netconf.ssh.authentication; +import java.io.IOException; 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 java.util.ArrayList; -import java.util.List; - import static com.google.common.base.Preconditions.checkNotNull; public class AuthProvider implements AuthProviderInterface { - 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 IUserManager um; private final String pem; - public AuthProvider(IUserManager ium, String pemCertificate) throws Exception { + public AuthProvider(IUserManager ium, String pemCertificate) throws IllegalArgumentException, IOException { 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()); - AuthProvider.um.addLocalUser(new UserConfig(DEFAULT_USER, DEFAULT_PASSWORD, roles)); //FIXME hardcoded auth + checkNotNull(ium, "No user manager service available."); + this.um = ium; pem = pemCertificate; } @Override - public boolean authenticated(String username, String password) throws Exception { - if (AuthProvider.um == null) { - throw new Exception("No usermanager service available."); - } - AuthResultEnum authResult = AuthProvider.um.authenticate(username, password); + 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); } @@ -53,11 +37,11 @@ public class AuthProvider implements AuthProviderInterface { @Override public void removeUserManagerService() { - AuthProvider.um = null; + this.um = null; } @Override public void addUserManagerService(IUserManager userManagerService) { - AuthProvider.um = userManagerService; + this.um = userManagerService; } }