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 org.opendaylight.controller.sal.authorization.AuthResultEnum;
11 import org.opendaylight.controller.sal.authorization.UserLevel;
12 import org.opendaylight.controller.usermanager.IUserManager;
13 import org.opendaylight.controller.usermanager.UserConfig;
15 import java.util.ArrayList;
16 import java.util.List;
18 import static com.google.common.base.Preconditions.checkNotNull;
20 public class AuthProvider implements AuthProviderInterface {
22 private static IUserManager um; //FIXME static mutable state, no locks
23 private static final String DEFAULT_USER = "netconf";
24 private static final String DEFAULT_PASSWORD = "netconf";
25 private final String pem;
27 public AuthProvider(IUserManager ium, String pemCertificate) throws Exception {
28 checkNotNull(pemCertificate, "Parameter 'pemCertificate' is null");
29 AuthProvider.um = ium;
30 if (AuthProvider.um == null) {
31 throw new Exception("No usermanager service available.");
34 List<String> roles = new ArrayList<String>(1);
35 roles.add(UserLevel.SYSTEMADMIN.toString());
36 AuthProvider.um.addLocalUser(new UserConfig(DEFAULT_USER, DEFAULT_PASSWORD, roles)); //FIXME hardcoded auth
41 public boolean authenticated(String username, String password) throws Exception {
42 if (AuthProvider.um == null) {
43 throw new Exception("No usermanager service available.");
45 AuthResultEnum authResult = AuthProvider.um.authenticate(username, password);
46 return authResult.equals(AuthResultEnum.AUTH_ACCEPT) || authResult.equals(AuthResultEnum.AUTH_ACCEPT_LOC);
50 public char[] getPEMAsCharArray() {
51 return pem.toCharArray();
55 public void removeUserManagerService() {
56 AuthProvider.um = null;
60 public void addUserManagerService(IUserManager userManagerService) {
61 AuthProvider.um = userManagerService;