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=92f3861c05351cacf9b93dd38d6771a58141fb9a;hb=5d83b20301c16b1637c7acaadbc5b2ecc8315214;hp=d904ad7f269a344600aa04bd2279b9590a0f91d7;hpb=5dd78e29d5b7fb6e32ad12d10e83d7941b31f4dd;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 d904ad7f26..92f3861c05 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 @@ -1,81 +1,16 @@ /* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ -package org.opendaylight.controller.netconf.ssh.authentication; - -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 org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class AuthProvider implements AuthProviderInterface { - - private static IUserManager um; - private static final String DEFAULT_USER = "netconf"; - private static final String DEFAULT_PASSWORD = "netconf"; - 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){ - throw new Exception("No usermanager service available."); - } - - List roles = new ArrayList(1); - roles.add(UserLevel.SYSTEMADMIN.toString()); - this.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){ - 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; - } - - @Override - public char[] getPEMAsCharArray() throws Exception { - 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; - } +package org.opendaylight.controller.netconf.ssh.authentication; - @Override - public void addUserManagerService(IUserManager userManagerService) { - this.um = userManagerService; - } +public interface AuthProvider { + boolean authenticated(String username, String password); + char[] getPEMAsCharArray(); }