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 java.io.InputStream;
11 import java.util.ArrayList;
12 import java.util.List;
13 import org.apache.commons.io.IOUtils;
14 import org.opendaylight.controller.sal.authorization.AuthResultEnum;
15 import org.opendaylight.controller.sal.authorization.UserLevel;
16 import org.opendaylight.controller.usermanager.IUserManager;
17 import org.opendaylight.controller.usermanager.UserConfig;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
21 public class AuthProvider implements AuthProviderInterface {
23 private static IUserManager um;
24 private static final String DEFAULT_USER = "netconf";
25 private static final String DEFAULT_PASSWORD = "netconf";
26 private static InputStream privateKeyFileInputStream;
28 private static final Logger logger = LoggerFactory.getLogger(AuthProvider.class);
30 public AuthProvider(IUserManager ium,InputStream privateKeyFileInputStream) throws Exception {
34 throw new Exception("No usermanager service available.");
37 this.privateKeyFileInputStream = privateKeyFileInputStream;
39 List<String> roles = new ArrayList<String>(1);
40 roles.add(UserLevel.SYSTEMADMIN.toString());
41 this.um.addLocalUser(new UserConfig(DEFAULT_USER, DEFAULT_PASSWORD, roles));
44 public boolean authenticated(String username, String password) throws Exception {
46 throw new Exception("No usermanager service available.");
48 AuthResultEnum authResult = this.um.authenticate(username,password);
49 if (authResult.equals(AuthResultEnum.AUTH_ACCEPT) || authResult.equals(AuthResultEnum.AUTH_ACCEPT_LOC)){
56 public char[] getPEMAsCharArray() throws Exception {
57 char [] PEM = IOUtils.toCharArray(privateKeyFileInputStream);
58 privateKeyFileInputStream.close();
63 public void removeUserManagerService() {
68 public void addUserManagerService(IUserManager userManagerService) {
69 this.um = userManagerService;