2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.netconf.ssh.authentication;
10 import ch.ethz.ssh2.signature.RSAPrivateKey;
11 import java.io.IOException;
12 import java.io.InputStream;
13 import java.util.ArrayList;
14 import java.util.List;
15 import org.apache.commons.io.IOUtils;
16 import org.opendaylight.controller.sal.authorization.AuthResultEnum;
17 import org.opendaylight.controller.sal.authorization.UserLevel;
18 import org.opendaylight.controller.usermanager.IUserManager;
19 import org.opendaylight.controller.usermanager.UserConfig;
21 public class AuthProvider implements AuthProviderInterface {
23 private static RSAPrivateKey hostkey = null;
24 private static IUserManager um;
25 private static final String DEAFULT_USER = "netconf";
26 private static final String DEAFULT_PASSWORD = "netconf";
29 public AuthProvider(IUserManager ium) throws Exception {
34 throw new Exception("No usermanager service available.");
37 List<String> roles = new ArrayList<String>(1);
38 roles.add(UserLevel.SYSTEMADMIN.toString());
39 this.um.addLocalUser(new UserConfig(DEAFULT_USER, DEAFULT_PASSWORD, roles));
42 public boolean authenticated(String username, String password) throws Exception {
44 throw new Exception("No usermanager service available.");
46 AuthResultEnum authResult = this.um.authenticate(username,password);
47 if (authResult.equals(AuthResultEnum.AUTH_ACCEPT) || authResult.equals(AuthResultEnum.AUTH_ACCEPT_LOC)){
54 public char[] getPEMAsCharArray() {
56 InputStream is = getClass().getResourceAsStream("/RSA.pk");
58 return IOUtils.toCharArray(is);
59 } catch (IOException e) {
66 public void removeUserManagerService() {
71 public void addUserManagerService(IUserManager userManagerService) {
72 this.um = userManagerService;