Java 类com.jcraft.jsch.Identity 实例源码

项目:app-runner    文件:SystemInfo.java   
private static List<String> getPublicKeys() throws Exception {
    return new JschConfigSessionFactory() {
        @Override
        protected void configure(OpenSshConfig.Host hc, Session session) {
        }
        List<String> getPublicKeys() throws Exception {
            JSch jSch = createDefaultJSch(FS.DETECTED);
            List<String> keys = new ArrayList<>();
            for (Object o : jSch.getIdentityRepository().getIdentities()) {
                Identity i = (Identity) o;
                KeyPair keyPair = KeyPair.load(jSch, i.getName(), null);
                StringBuilder sb = new StringBuilder();
                try (StringBuilderWriter sbw = new StringBuilderWriter(sb);
                     OutputStream os = new WriterOutputStream(sbw, "UTF-8")) {
                    keyPair.writePublicKey(os, keyPair.getPublicKeyComment());
                } finally {
                    keyPair.dispose();
                }
                keys.add(sb.toString().trim());
            }
            return keys;
        }
    }.getPublicKeys();
}
项目:release-maven-plugin-parent    文件:SshAgentSessionFactoryTest.java   
private Identity getId(final JSch jsch, final String name) {
    final Iterator<?> it = jsch.getIdentityRepository().getIdentities().iterator();

    while (it.hasNext()) {
        final Identity id = (Identity) it.next();
        if (id.getName().contains(name)) {
            return id;
        }
    }

    throw new AssertionFailedError(format("No identity found with name %s", name));
}
项目:release-maven-plugin-parent    文件:SshAgentSessionFactoryTest.java   
/**
 * 
 */
@Test
public void createDefaultJSch() throws Exception {
    final SshAgentSessionFactory factory = new SshAgentSessionFactory(log, null, TESTID, null);
    factory.setIdentityFile(getFile(TESTID));
    final JSch jsch = factory.createDefaultJSch(fs);
    final Identity id = getId(jsch, TESTID);
    assertFalse(id.isEncrypted());
}
项目:release-maven-plugin-parent    文件:SshAgentSessionFactoryTest.java   
/**
 * 
 */
@Test
public void createDefaultJSch_WithPassword() throws Exception {
    final SshAgentSessionFactory factory = new SshAgentSessionFactory(log, null, TESTID_WITH_PASSWORD, null);
    factory.setIdentityFile(getFile(TESTID_WITH_PASSWORD));
    JSch jsch = factory.createDefaultJSch(fs);

    Identity id = getId(jsch, TESTID_WITH_PASSWORD);
    assertTrue(id.isEncrypted());

    factory.setPassphrase("password");
    jsch = factory.createDefaultJSch(fs);
    id = getId(jsch, TESTID_WITH_PASSWORD);
    assertFalse(id.isEncrypted());
}
项目:httpsig-java    文件:JschKey.java   
public static Keychain getIdentities(JSch jSch) {
    ArrayList<JschKey> identities = new ArrayList<JschKey>();
    Vector _identities = jSch.getIdentityRepository().getIdentities();
    if (_identities != null) {
        for (Object obj : _identities) {
            identities.add(new JschKey((Identity) obj));
        }
    }

    return new DefaultKeychain(Collections.unmodifiableList(identities));
}
项目:centraldogma    文件:GitWithAuth.java   
@Override
public Vector<Identity> getIdentities() {
    final Vector<Identity> identities = new Vector<>();
    identities.add(identity);
    return identities;
}
项目:httpsig-java    文件:JschKey.java   
public JschKey(Identity identity) {
    this.fingerprint = Magic.getFingerprint(identity.getPublicKeyBlob());
    this.identity = identity;
    this.algorithm = Algorithm.forName(identity.getAlgName());
}