当前位置: 首页>>代码示例>>Java>>正文


Java PasswordAuthenticator类代码示例

本文整理汇总了Java中org.apache.sshd.server.auth.password.PasswordAuthenticator的典型用法代码示例。如果您正苦于以下问题:Java PasswordAuthenticator类的具体用法?Java PasswordAuthenticator怎么用?Java PasswordAuthenticator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


PasswordAuthenticator类属于org.apache.sshd.server.auth.password包,在下文中一共展示了PasswordAuthenticator类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: passwordAuthenticator

import org.apache.sshd.server.auth.password.PasswordAuthenticator; //导入依赖的package包/类
@Bean
PasswordAuthenticator passwordAuthenticator() {
    SshdShellProperties.Shell.Auth props = properties.getShell().getAuth();
    switch (props.getAuthType()) {
        case SIMPLE:
            return new SimpleSshdPasswordAuthenticator(properties);
        case AUTH_PROVIDER:
            try {
                AuthenticationProvider authProvider = Objects.isNull(props.getAuthProviderBeanName())
                        ? appContext.getBean(AuthenticationProvider.class)
                        : appContext.getBean(props.getAuthProviderBeanName(), AuthenticationProvider.class);
                return new AuthProviderSshdPasswordAuthenticator(authProvider);
            } catch (BeansException ex) {
                throw new IllegalArgumentException("Expected a default or valid AuthenticationProvider bean", ex);
            }
        default:
            throw new IllegalArgumentException("Invalid/Unsupported auth type");
    }
}
 
开发者ID:anand1st,项目名称:sshd-shell-spring-boot,代码行数:20,代码来源:SshdServerConfiguration.java

示例2: usePasswordAuthentication

import org.apache.sshd.server.auth.password.PasswordAuthenticator; //导入依赖的package包/类
/**
 * Setup a password authentication.
 *
 * @param login Login for an authentication.
 * @param password Password for an authentication.
 * @return This instance of builder.
 */
public MockSshServerBuilder usePasswordAuthentication(
    final String login, final String password) {
    this.factories.add(new UserAuthPasswordFactory());
    final PasswordAuthenticator auth =
        Mockito.mock(PasswordAuthenticator.class);
    Mockito.when(
        auth.authenticate(
            Mockito.eq(login),
            Mockito.eq(password),
            Mockito.any(ServerSession.class)
        )
    ).thenReturn(true);
    this.pwd = Optional.of(auth);
    return this;
}
 
开发者ID:jcabi,项目名称:jcabi-ssh,代码行数:23,代码来源:MockSshServerBuilder.java

示例3: create

import org.apache.sshd.server.auth.password.PasswordAuthenticator; //导入依赖的package包/类
public static SshServer create() {

        SshServer sshd = SshServer.setUpDefaultServer();
        sshd.setPort(SpashConfig.getInstance().spashListenPort());

        AbstractGeneratorHostKeyProvider keyProvider = new SimpleGeneratorHostKeyProvider(new File(SpashConfig.getInstance().spashKeyFileName()));
        keyProvider.setAlgorithm(SpashConfig.getInstance().spashKeyAlgorithm());
        keyProvider.setKeySize(SpashConfig.getInstance().spashKeyLength());

        sshd.setKeyPairProvider(keyProvider);

        List<NamedFactory<UserAuth>> userAuthFactories = new ArrayList<NamedFactory<UserAuth>>();
        userAuthFactories.add(new UserAuthPasswordFactory());
        sshd.setUserAuthFactories(userAuthFactories);

        sshd.setPasswordAuthenticator(new PasswordAuthenticator() {
            @Override
            public boolean authenticate(String username, String password, ServerSession serverSession) throws PasswordChangeRequiredException {
                return username!=null && username.length()>0 && username.equals(password);
            }
        });

        sshd.setShellFactory(new SpashShellFactory());

        List<NamedFactory<Command>> namedFactoryList = new ArrayList<>();
        namedFactoryList.add(new SftpSubsystemFactory());
        sshd.setSubsystemFactories(namedFactoryList);

        sshd.setCommandFactory(new ScpCommandFactory());

        sshd.setFileSystemFactory(new FileSystemFactory() {
            @Override
            public FileSystem createFileSystem(Session session) throws IOException {
                return SpashFileSystem.get().getFileSystem();
            }
        });

        return sshd;
    }
 
开发者ID:nerdammer,项目名称:spash,代码行数:40,代码来源:SshServerFactory.java

示例4: setup

import org.apache.sshd.server.auth.password.PasswordAuthenticator; //导入依赖的package包/类
@BeforeClass
public static void setup() throws Exception {
    sshdServer.setPort(PORT);
    sshdServer.setKeyPairProvider(new SimpleGeneratorHostKeyProvider());

    sshdServer.setPasswordAuthenticator(new PasswordAuthenticator() {
        public boolean authenticate(String user, String password, ServerSession serverSession) throws PasswordChangeRequiredException {
            return user.equals(USERNAME) && password.equals(USERPWD);
        }
    });

    sshdServer.start();
}
 
开发者ID:ziccardi,项目名称:jnrpe,代码行数:14,代码来源:CheckSSHTest.java

示例5: setPasswordAuthenticator

import org.apache.sshd.server.auth.password.PasswordAuthenticator; //导入依赖的package包/类
public void setPasswordAuthenticator (PasswordAuthenticator passwordAuthenticator) {
	this.passwordAuthenticator = passwordAuthenticator;
}
 
开发者ID:jesse-gallagher,项目名称:xsp-groovy-shell,代码行数:4,代码来源:GroovyShellService.java

示例6: setPasswordAuthenticator

import org.apache.sshd.server.auth.password.PasswordAuthenticator; //导入依赖的package包/类
public NettySshTtyBootstrap setPasswordAuthenticator(PasswordAuthenticator passwordAuthenticator) {
    this.passwordAuthenticator = passwordAuthenticator;
    return this;
}
 
开发者ID:aeshell,项目名称:aesh-readline,代码行数:5,代码来源:NettySshTtyBootstrap.java

示例7: setUp

import org.apache.sshd.server.auth.password.PasswordAuthenticator; //导入依赖的package包/类
@BeforeClass
public static void setUp() throws Exception {
    Security.addProvider(new BouncyCastleProvider());
    int portNumber = TestTools.findAvailablePort(50830);
    sshServerNetconf = SshServer.setUpDefaultServer();
    sshServerNetconf.setPasswordAuthenticator(
            new PasswordAuthenticator() {
                @Override
                public boolean authenticate(
                        String username,
                        String password,
                        ServerSession session) {
                    return TEST_USERNAME.equals(username) && TEST_PASSWORD.equals(password);
                }
            });
    sshServerNetconf.setPort(portNumber);
    SimpleGeneratorHostKeyProvider provider = new SimpleGeneratorHostKeyProvider();
    provider.setFile(new File(TEST_SERFILE));
    sshServerNetconf.setKeyPairProvider(provider);
    sshServerNetconf.setSubsystemFactories(
            Arrays.<NamedFactory<Command>>asList(new NetconfSshdTestSubsystem.Factory()));
    sshServerNetconf.open();
    log.info("SSH Server opened on port {}", portNumber);

    NetconfDeviceInfo deviceInfo = new NetconfDeviceInfo(
            TEST_USERNAME, TEST_PASSWORD, Ip4Address.valueOf(TEST_HOSTNAME), portNumber);
    deviceInfo.setConnectTimeoutSec(OptionalInt.of(30));
    deviceInfo.setReplyTimeoutSec(OptionalInt.of(30));

    session1 = new NetconfSessionMinaImpl(deviceInfo, ImmutableList.of("urn:ietf:params:netconf:base:1.0"));
    log.info("Started NETCONF Session {} with test SSHD server in Unit Test", session1.getSessionId());
    assertTrue("Incorrect sessionId", !session1.getSessionId().equalsIgnoreCase("-1"));
    assertTrue("Incorrect sessionId", !session1.getSessionId().equalsIgnoreCase("0"));
    assertThat(session1.getDeviceCapabilitiesSet(), containsInAnyOrder(DEFAULT_CAPABILITIES.toArray()));

    session2 = new NetconfSessionMinaImpl(deviceInfo, ImmutableList.of("urn:ietf:params:netconf:base:1.0"));
    log.info("Started NETCONF Session {} with test SSHD server in Unit Test", session2.getSessionId());
    assertTrue("Incorrect sessionId", !session2.getSessionId().equalsIgnoreCase("-1"));
    assertTrue("Incorrect sessionId", !session2.getSessionId().equalsIgnoreCase("0"));
    assertThat(session2.getDeviceCapabilitiesSet(), containsInAnyOrder(DEFAULT_CAPABILITIES.toArray()));

    session3 = new NetconfSessionMinaImpl(deviceInfo);
    log.info("Started NETCONF Session {} with test SSHD server in Unit Test", session3.getSessionId());
    assertTrue("Incorrect sessionId", !session3.getSessionId().equalsIgnoreCase("-1"));
    assertTrue("Incorrect sessionId", !session3.getSessionId().equalsIgnoreCase("0"));
    assertThat(session3.getDeviceCapabilitiesSet(), containsInAnyOrder(DEFAULT_CAPABILITIES_1_1.toArray()));

    session4 = new NetconfSessionMinaImpl(deviceInfo);
    log.info("Started NETCONF Session {} with test SSHD server in Unit Test", session4.getSessionId());
    assertTrue("Incorrect sessionId", !session4.getSessionId().equalsIgnoreCase("-1"));
    assertTrue("Incorrect sessionId", !session4.getSessionId().equalsIgnoreCase("0"));
    assertThat(session4.getDeviceCapabilitiesSet(), containsInAnyOrder(DEFAULT_CAPABILITIES_1_1.toArray()));
}
 
开发者ID:opennetworkinglab,项目名称:onos,代码行数:54,代码来源:NetconfSessionMinaImplTest.java

示例8: setUp

import org.apache.sshd.server.auth.password.PasswordAuthenticator; //导入依赖的package包/类
@BeforeClass
public static void setUp() throws Exception {
    int portNumber = TestTools.findAvailablePort(50830);
    sshServerNetconf = SshServer.setUpDefaultServer();
    sshServerNetconf.setPasswordAuthenticator(
            new PasswordAuthenticator() {
                @Override
                public boolean authenticate(
                        String username,
                        String password,
                        ServerSession session) {
                    return TEST_USERNAME.equals(username) && TEST_PASSWORD.equals(password);
                }
            });
    sshServerNetconf.setPort(portNumber);
    SimpleGeneratorHostKeyProvider provider = new SimpleGeneratorHostKeyProvider();
    provider.setFile(new File(TEST_SERFILE));
    sshServerNetconf.setKeyPairProvider(provider);
    sshServerNetconf.setSubsystemFactories(
            Arrays.<NamedFactory<Command>>asList(new NetconfSshdTestSubsystem.Factory()));
    sshServerNetconf.open();
    log.info("SSH Server opened on port {}", portNumber);

    NetconfController netconfCtl = new NetconfControllerImpl();
    NetconfControllerImpl.netconfConnectTimeout = NetconfControllerImpl.DEFAULT_CONNECT_TIMEOUT_SECONDS;
    NetconfControllerImpl.netconfIdleTimeout = NetconfControllerImpl.DEFAULT_IDLE_TIMEOUT_SECONDS;
    NetconfControllerImpl.netconfReplyTimeout = NetconfControllerImpl.DEFAULT_REPLY_TIMEOUT_SECONDS;

    NetconfDeviceInfo deviceInfo1 = new NetconfDeviceInfo(
            TEST_USERNAME, TEST_PASSWORD, Ip4Address.valueOf(TEST_HOSTNAME), portNumber);

    session1 = new NetconfSessionImpl(deviceInfo1, ImmutableList.of("urn:ietf:params:netconf:base:1.0"));
    log.info("Started NETCONF Session {} with test SSHD server in Unit Test", session1.getSessionId());
    assertTrue("Incorrect sessionId", !session1.getSessionId().equalsIgnoreCase("-1"));
    assertTrue("Incorrect sessionId", !session1.getSessionId().equalsIgnoreCase("0"));
    assertThat(session1.getDeviceCapabilitiesSet(), containsInAnyOrder(
            NetconfSessionMinaImplTest.DEFAULT_CAPABILITIES.toArray()));

    NetconfDeviceInfo deviceInfo2 = new NetconfDeviceInfo(
            TEST_USERNAME, TEST_PASSWORD, Ip4Address.valueOf(TEST_HOSTNAME), portNumber);
    deviceInfo2.setConnectTimeoutSec(OptionalInt.of(11));
    deviceInfo2.setReplyTimeoutSec(OptionalInt.of(10));
    deviceInfo2.setIdleTimeoutSec(OptionalInt.of(12));
    session2 = new NetconfSessionMinaImpl(deviceInfo2, ImmutableList.of("urn:ietf:params:netconf:base:1.0"));
    log.info("Started NETCONF Session {} with test SSHD server in Unit Test", session2.getSessionId());
    assertTrue("Incorrect sessionId", !session2.getSessionId().equalsIgnoreCase("-1"));
    assertTrue("Incorrect sessionId", !session2.getSessionId().equalsIgnoreCase("0"));
    assertThat(session2.getDeviceCapabilitiesSet(), containsInAnyOrder(
            NetconfSessionMinaImplTest.DEFAULT_CAPABILITIES.toArray()));
    session3 = new NetconfSessionImpl(deviceInfo1);
    log.info("Started NETCONF Session {} with test SSHD server in Unit Test", session3.getSessionId());
    assertTrue("Incorrect sessionId", !session3.getSessionId().equalsIgnoreCase("-1"));
    assertTrue("Incorrect sessionId", !session3.getSessionId().equalsIgnoreCase("0"));
    assertThat(session3.getDeviceCapabilitiesSet(), containsInAnyOrder(
            NetconfSessionMinaImplTest.DEFAULT_CAPABILITIES_1_1.toArray()));
    session4 = new NetconfSessionImpl(deviceInfo1);
    log.info("Started NETCONF Session {} with test SSHD server in Unit Test", session4.getSessionId());
    assertTrue("Incorrect sessionId", !session4.getSessionId().equalsIgnoreCase("-1"));
    assertTrue("Incorrect sessionId", !session4.getSessionId().equalsIgnoreCase("0"));
    assertThat(session4.getDeviceCapabilitiesSet(), containsInAnyOrder(
            NetconfSessionMinaImplTest.DEFAULT_CAPABILITIES_1_1.toArray()));
}
 
开发者ID:opennetworkinglab,项目名称:onos,代码行数:63,代码来源:NetconfSessionImplTest.java


注:本文中的org.apache.sshd.server.auth.password.PasswordAuthenticator类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。