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


Java PublickeyAuthenticator类代码示例

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


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

示例1: initUserAuth

import org.apache.sshd.server.auth.pubkey.PublickeyAuthenticator; //导入依赖的package包/类
private void initUserAuth(
    final PublickeyAuthenticator pubkey,
    final GSSAuthenticator kerberosAuthenticator,
    String kerberosKeytab,
    String kerberosPrincipal) {
  List<NamedFactory<UserAuth>> authFactories = new ArrayList<>();
  if (kerberosKeytab != null) {
    authFactories.add(UserAuthGSSFactory.INSTANCE);
    log.info("Enabling kerberos with keytab " + kerberosKeytab);
    if (!new File(kerberosKeytab).canRead()) {
      sshDaemonLog.error(
          "Keytab "
              + kerberosKeytab
              + " does not exist or is not readable; further errors are possible");
    }
    kerberosAuthenticator.setKeytabFile(kerberosKeytab);
    if (kerberosPrincipal == null) {
      try {
        kerberosPrincipal = "host/" + InetAddress.getLocalHost().getCanonicalHostName();
      } catch (UnknownHostException e) {
        kerberosPrincipal = "host/localhost";
      }
    }
    sshDaemonLog.info("Using kerberos principal " + kerberosPrincipal);
    if (!kerberosPrincipal.startsWith("host/")) {
      sshDaemonLog.warn(
          "Host principal does not start with host/ "
              + "which most SSH clients will supply automatically");
    }
    kerberosAuthenticator.setServicePrincipalName(kerberosPrincipal);
    setGSSAuthenticator(kerberosAuthenticator);
  }
  authFactories.add(UserAuthPublicKeyFactory.INSTANCE);
  setUserAuthFactories(authFactories);
  setPublickeyAuthenticator(pubkey);
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:37,代码来源:SshDaemon.java

示例2: usePublicKeyAuthentication

import org.apache.sshd.server.auth.pubkey.PublickeyAuthenticator; //导入依赖的package包/类
/**
 * Setup a public key authentication.
 *
 * @return This instance of builder.
 */
public MockSshServerBuilder usePublicKeyAuthentication() {
    this.factories.add(new UserAuthPublicKeyFactory());
    final PublickeyAuthenticator auth =
        Mockito.mock(PublickeyAuthenticator.class);
    Mockito.when(
        auth.authenticate(
            Mockito.anyString(),
            Mockito.any(PublicKey.class),
            Mockito.any(ServerSession.class)
        )
    ).thenReturn(true);
    this.pkey = Optional.of(auth);
    return this;
}
 
开发者ID:jcabi,项目名称:jcabi-ssh,代码行数:20,代码来源:MockSshServerBuilder.java

示例3: setUp

import org.apache.sshd.server.auth.pubkey.PublickeyAuthenticator; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
    sshd = setupTestServer();
    PropertyResolverUtils.updateProperty(sshd, ServerFactoryManager.AUTH_METHODS, UserAuthPublicKeyFactory.NAME);
    sshd.setPublickeyAuthenticator(new PublickeyAuthenticator() {
        @SuppressWarnings("synthetic-access")
        @Override
        public boolean authenticate(String username, PublicKey key, ServerSession session) {
            return delegate.authenticate(username, key, session);
        }
    });
    sshd.start();
    port = sshd.getPort();
}
 
开发者ID:termd,项目名称:termd,代码行数:15,代码来源:SinglePublicKeyAuthTest.java

示例4: testPublicKeyAuthWithCache

import org.apache.sshd.server.auth.pubkey.PublickeyAuthenticator; //导入依赖的package包/类
@Test
public void testPublicKeyAuthWithCache() throws Exception {
    final ConcurrentHashMap<String, AtomicInteger> count = new ConcurrentHashMap<String, AtomicInteger>();
    TestCachingPublicKeyAuthenticator auth = new TestCachingPublicKeyAuthenticator(new PublickeyAuthenticator() {
        @SuppressWarnings("synthetic-access")
        @Override
        public boolean authenticate(String username, PublicKey key, ServerSession session) {
            String fp = KeyUtils.getFingerPrint(key);
            count.putIfAbsent(fp, new AtomicInteger());
            count.get(fp).incrementAndGet();
            return key.equals(pairRsa.getPublic());
        }
    });
    delegate = auth;

    try (SshClient client = setupTestClient()) {
        client.start();

        try (ClientSession session = client.connect(getCurrentTestName(), TEST_LOCALHOST, port).verify(7L, TimeUnit.SECONDS).getSession()) {
            session.addPublicKeyIdentity(pairRsaBad);
            session.addPublicKeyIdentity(pairRsa);
            session.auth().verify(5L, TimeUnit.SECONDS);

            assertEquals("Mismatched authentication invocations count", 2, count.size());

            String fpBad = KeyUtils.getFingerPrint(pairRsaBad.getPublic());
            String fpGood = KeyUtils.getFingerPrint(pairRsa.getPublic());
            assertTrue("Missing bad public key", count.containsKey(fpBad));
            assertTrue("Missing good public key", count.containsKey(fpGood));
            assertEquals("Mismatched bad key authentication attempts", 1, count.get(fpBad).get());
            assertEquals("Mismatched good key authentication attempts", 1, count.get(fpGood).get());
        } finally {
            client.stop();
        }
    }

    Thread.sleep(100L);
    assertTrue("Cache not empty", auth.getCache().isEmpty());
}
 
开发者ID:termd,项目名称:termd,代码行数:40,代码来源:SinglePublicKeyAuthTest.java

示例5: setPublicKeyAuthenticator

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

示例6: configure

import org.apache.sshd.server.auth.pubkey.PublickeyAuthenticator; //导入依赖的package包/类
@Override
protected void configure() {
  bindScope(RequestScoped.class, SshScope.REQUEST);
  bind(RequestScopePropagator.class).to(SshScope.Propagator.class);
  bind(SshScope.class).in(SINGLETON);

  configureRequestScope();
  install(new AsyncReceiveCommits.Module());
  configureAliases();

  bind(SshLog.class);
  bind(SshInfo.class).to(SshDaemon.class).in(SINGLETON);
  factory(DispatchCommand.Factory.class);
  factory(QueryShell.Factory.class);
  factory(PeerDaemonUser.Factory.class);

  bind(DispatchCommandProvider.class)
      .annotatedWith(Commands.CMD_ROOT)
      .toInstance(new DispatchCommandProvider(Commands.CMD_ROOT));
  bind(CommandFactoryProvider.class);
  bind(CommandFactory.class).toProvider(CommandFactoryProvider.class);
  bind(ScheduledThreadPoolExecutor.class)
      .annotatedWith(StreamCommandExecutor.class)
      .toProvider(StreamCommandExecutorProvider.class)
      .in(SINGLETON);
  bind(QueueProvider.class).to(CommandExecutorQueueProvider.class).in(SINGLETON);

  bind(GSSAuthenticator.class).to(GerritGSSAuthenticator.class);
  bind(PublickeyAuthenticator.class).to(CachingPublicKeyAuthenticator.class);

  bind(ModuleGenerator.class).to(SshAutoRegisterModuleGenerator.class);
  bind(SshPluginStarterCallback.class);
  bind(StartPluginListener.class)
      .annotatedWith(UniqueAnnotations.create())
      .to(SshPluginStarterCallback.class);

  bind(ReloadPluginListener.class)
      .annotatedWith(UniqueAnnotations.create())
      .to(SshPluginStarterCallback.class);

  DynamicMap.mapOf(binder(), DynamicOptions.DynamicBean.class);

  listener().toInstance(registerInParentInjectors());
  listener().to(SshLog.class);
  listener().to(SshDaemon.class);
  listener().to(CommandFactoryProvider.class);
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:48,代码来源:SshModule.java

示例7: testPublicKeyAuthWithoutCache

import org.apache.sshd.server.auth.pubkey.PublickeyAuthenticator; //导入依赖的package包/类
@Test
public void testPublicKeyAuthWithoutCache() throws Exception {
    final ConcurrentHashMap<String, AtomicInteger> count = new ConcurrentHashMap<String, AtomicInteger>();
    delegate = new PublickeyAuthenticator() {
        @SuppressWarnings("synthetic-access")
        @Override
        public boolean authenticate(String username, PublicKey key, ServerSession session) {
            String fp = KeyUtils.getFingerPrint(key);
            count.putIfAbsent(fp, new AtomicInteger());
            count.get(fp).incrementAndGet();
            return key.equals(pairRsa.getPublic());
        }
    };

    try (SshClient client = setupTestClient()) {
        client.start();

        try (ClientSession session = client.connect(getCurrentTestName(), TEST_LOCALHOST, port).verify(7L, TimeUnit.SECONDS).getSession()) {
            session.addPublicKeyIdentity(pairRsaBad);
            session.addPublicKeyIdentity(pairRsa);

            AuthFuture auth = session.auth();
            assertTrue("Failed to authenticate on time", auth.await(5L, TimeUnit.SECONDS));
            assertTrue("Authentication failed", auth.isSuccess());
        } finally {
            client.stop();
        }
    }

    assertEquals("Mismatched attempted keys count", 2, count.size());

    String badFingerPrint = KeyUtils.getFingerPrint(pairRsaBad.getPublic());
    Number badIndex = count.get(badFingerPrint);
    assertNotNull("Missing bad RSA key", badIndex);
    assertEquals("Mismatched attempt index for bad key", 1, badIndex.intValue());

    String goodFingerPrint = KeyUtils.getFingerPrint(pairRsa.getPublic());
    Number goodIndex = count.get(goodFingerPrint);
    assertNotNull("Missing good RSA key", goodIndex);
    assertEquals("Mismatched attempt index for good key", 2, goodIndex.intValue());
}
 
开发者ID:termd,项目名称:termd,代码行数:42,代码来源:SinglePublicKeyAuthTest.java

示例8: TestCachingPublicKeyAuthenticator

import org.apache.sshd.server.auth.pubkey.PublickeyAuthenticator; //导入依赖的package包/类
public TestCachingPublicKeyAuthenticator(PublickeyAuthenticator authenticator) {
    super(authenticator);
}
 
开发者ID:termd,项目名称:termd,代码行数:4,代码来源:SinglePublicKeyAuthTest.java


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