2 * Copyright (c) 2016, 2017 Inocybe Technologies. 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.aaa.cli;
10 import org.apache.karaf.shell.console.OsgiCommandSupport;
11 import org.opendaylight.aaa.api.IIDMStore;
12 import org.opendaylight.aaa.api.model.User;
13 import org.opendaylight.aaa.cli.utils.CliUtils;
14 import org.opendaylight.aaa.cli.utils.DataStoreUtils;
17 * Base class for all CLI commands.
22 public abstract class AaaCliAbstractCommand extends OsgiCommandSupport {
24 private static volatile String authUser = null;
25 protected final IIDMStore identityStore;
27 public AaaCliAbstractCommand(final IIDMStore identityStore) {
28 this.identityStore = identityStore;
32 protected Object doExecute() throws Exception {
33 final User currentUser = SessionsManager.getInstance().getCurrentUser(authUser);
34 if (currentUser == null) {
35 final String userName = CliUtils.readPassword(super.session, "Enter Username:");
36 final String passwd = CliUtils.readPassword(super.session, "Enter Password:");
37 final User usr = DataStoreUtils.isAdminUser(identityStore, userName, passwd);
40 SessionsManager.getInstance().addUserSession(userName, usr);