All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.opendaylight.aaa.cli.AaaCliAbstractCommand Maven / Gradle / Ivy

There is a newer version: 0.20.3
Show newest version
/*
 * Copyright (c) 2016, 2017 Inocybe Technologies. and others.  All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 */
package org.opendaylight.aaa.cli;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.Collection;
import org.apache.karaf.shell.api.action.Action;
import org.apache.karaf.shell.api.action.Option;
import org.apache.karaf.shell.api.action.lifecycle.Reference;
import org.opendaylight.aaa.api.IIDMStore;
import org.opendaylight.aaa.api.model.User;
import org.opendaylight.aaa.api.password.service.PasswordHashService;
import org.opendaylight.aaa.cli.utils.DataStoreUtils;

/**
 * Base class for all CLI commands.
 *
 * @author mserngawy
 *
 */
@SuppressFBWarnings("ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD")
@SuppressWarnings("checkstyle:RegexpSingleLineJava")
public abstract class AaaCliAbstractCommand implements Action {
    public static final String LOGIN_FAILED_MESS = "User does not exist OR user name and passsword are not correct";

    @Option(name = "-aaaAdmin",
            description = "AAA admin username",
            required = true,
            censor = true,
            multiValued = false)
    private String userName;

    @Option(name = "-aaaAdminPass",
            description = "AAA Admin password",
            required = true,
            censor = true,
            multiValued = false)
    private String passwd;

    @Reference protected IIDMStore identityStore;
    @Reference private PasswordHashService passwordService;

    @Override
    public Object execute() throws Exception {
        final User usr = DataStoreUtils.isAdminUser(identityStore, passwordService, userName, passwd);
        return usr;
    }

    protected void list(String name, Collection items) {
        System.out.println(name);
        items.forEach(i -> System.out.println("  " + i));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy