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

org.opendaylight.netconf.shaded.sshd.client.ClientAuthenticationManager Maven / Gradle / Ivy

There is a newer version: 8.0.3
Show newest version
/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements. See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership. The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

package org.opendaylight.netconf.shaded.sshd.client;

import java.security.KeyPair;
import java.util.Collection;
import java.util.List;

import org.opendaylight.netconf.shaded.sshd.client.auth.AuthenticationIdentitiesProvider;
import org.opendaylight.netconf.shaded.sshd.client.auth.BuiltinUserAuthFactories;
import org.opendaylight.netconf.shaded.sshd.client.auth.UserAuth;
import org.opendaylight.netconf.shaded.sshd.client.auth.UserAuthFactory;
import org.opendaylight.netconf.shaded.sshd.client.auth.hostbased.HostBasedAuthenticationReporter;
import org.opendaylight.netconf.shaded.sshd.client.auth.keyboard.UserInteraction;
import org.opendaylight.netconf.shaded.sshd.client.auth.password.PasswordAuthenticationReporter;
import org.opendaylight.netconf.shaded.sshd.client.auth.password.PasswordIdentityProvider;
import org.opendaylight.netconf.shaded.sshd.client.auth.pubkey.PublicKeyAuthenticationReporter;
import org.opendaylight.netconf.shaded.sshd.client.keyverifier.ServerKeyVerifier;
import org.opendaylight.netconf.shaded.sshd.client.session.ClientSession;
import org.opendaylight.netconf.shaded.sshd.common.auth.UserAuthFactoriesManager;
import org.opendaylight.netconf.shaded.sshd.common.keyprovider.KeyIdentityProviderHolder;
import org.opendaylight.netconf.shaded.sshd.common.util.GenericUtils;
import org.opendaylight.netconf.shaded.sshd.common.util.ValidateUtils;

/**
 * Holds information required for the client to perform authentication with the server
 *
 * @author Apache MINA SSHD Project
 */
public interface ClientAuthenticationManager
        extends UserAuthFactoriesManager,
        KeyIdentityProviderHolder {

    /**
     * @return The {@link AuthenticationIdentitiesProvider} to be used for attempting password or public key
     *         authentication
     */
    AuthenticationIdentitiesProvider getRegisteredIdentities();

    /**
     * Retrieve {@link PasswordIdentityProvider} used to provide password candidates
     *
     * @return The {@link PasswordIdentityProvider} instance - ignored if {@code null} (i.e., no passwords available).
     * @see    #addPasswordIdentity(String)
     */
    PasswordIdentityProvider getPasswordIdentityProvider();

    void setPasswordIdentityProvider(PasswordIdentityProvider provider);

    /**
     * @param password Password to be added - may not be {@code null}/empty. Note: this password is in
     *                 addition to whatever passwords are available via the {@link PasswordIdentityProvider} (if
     *                 any)
     */
    void addPasswordIdentity(String password);

    /**
     * @param  password The password to remove - ignored if {@code null}/empty
     * @return          The removed password - same one that was added via {@link #addPasswordIdentity(String)} - or
     *                  {@code null} if no match found
     */
    String removePasswordIdentity(String password);

    /**
     * @param key The {@link KeyPair} to add - may not be {@code null} Note: this key is in addition to
     *            whatever keys are available via the {@link org.opendaylight.netconf.shaded.sshd.common.keyprovider.KeyIdentityProvider} (if
     *            any)
     */
    void addPublicKeyIdentity(KeyPair key);

    /**
     * @param  kp The {@link KeyPair} to remove - ignored if {@code null}
     * @return    The removed {@link KeyPair} - same one that was added via {@link #addPublicKeyIdentity(KeyPair)} - or
     *            {@code null} if no match found
     */
    KeyPair removePublicKeyIdentity(KeyPair kp);

    /**
     * Retrieve the server key verifier to be used to check the key when connecting to an SSH server.
     *
     * @return the {@link ServerKeyVerifier} to use - never {@code null}
     */
    ServerKeyVerifier getServerKeyVerifier();

    void setServerKeyVerifier(ServerKeyVerifier serverKeyVerifier);

    /**
     * @return A {@link UserInteraction} object to communicate with the user (may be {@code null} to indicate that no
     *         such communication is allowed)
     */
    UserInteraction getUserInteraction();

    void setUserInteraction(UserInteraction userInteraction);

    PasswordAuthenticationReporter getPasswordAuthenticationReporter();

    void setPasswordAuthenticationReporter(PasswordAuthenticationReporter reporter);

    PublicKeyAuthenticationReporter getPublicKeyAuthenticationReporter();

    void setPublicKeyAuthenticationReporter(PublicKeyAuthenticationReporter reporter);

    HostBasedAuthenticationReporter getHostBasedAuthenticationReporter();

    void setHostBasedAuthenticationReporter(HostBasedAuthenticationReporter reporter);

    @Override
    default void setUserAuthFactoriesNames(Collection names) {
        BuiltinUserAuthFactories.ParseResult result = BuiltinUserAuthFactories.parseFactoriesList(names);
        List factories = ValidateUtils.checkNotNullAndNotEmpty(
                result.getParsedFactories(), "No supported user authentication factories: %s", names);
        Collection unsupported = result.getUnsupportedFactories();
        ValidateUtils.checkTrue(
                GenericUtils.isEmpty(unsupported), "Unsupported user authentication factories found: %s", unsupported);
        setUserAuthFactories(factories);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy