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 edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
11 import java.util.Objects;
12 import org.apache.karaf.shell.console.OsgiCommandSupport;
13 import org.opendaylight.aaa.api.IIDMStore;
14 import org.opendaylight.aaa.api.model.User;
15 import org.opendaylight.aaa.api.password.service.PasswordHashService;
16 import org.opendaylight.aaa.cli.utils.CliUtils;
17 import org.opendaylight.aaa.cli.utils.DataStoreUtils;
20 * Base class for all CLI commands.
25 @SuppressFBWarnings("ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD")
26 public abstract class AaaCliAbstractCommand extends OsgiCommandSupport {
28 private static volatile String authUser = null;
29 protected IIDMStore identityStore;
30 private final PasswordHashService passwordService;
32 public AaaCliAbstractCommand(final PasswordHashService passwordService) {
33 Objects.requireNonNull(this.passwordService = passwordService);
36 public void setIdentityStore(IIDMStore identityStore) {
37 this.identityStore = identityStore;
41 protected Object doExecute() throws Exception {
42 final User currentUser = SessionsManager.getInstance().getCurrentUser(authUser);
43 if (currentUser == null) {
44 final String userName = CliUtils.readPassword(super.session, "Enter Username:");
45 final String passwd = CliUtils.readPassword(super.session, "Enter Password:");
46 final User usr = DataStoreUtils.isAdminUser(identityStore, passwordService, userName, passwd);
49 SessionsManager.getInstance().addUserSession(userName, usr);