/** * Creates a user credential object for authenticating over an ssh tunnel. * * @param userName the name of a user to authenticate * @param agentProxy SSH agent proxy * @param portNumber the number of a port to establish an ssh tunnel over * @param url url these credentials are applied to * * @since 1.8.9 */ public static SVNSSHAuthentication newInstance(String userName, AgentProxy agentProxy, int portNumber, SVNURL url, boolean isPartial) { return new SVNSSHAuthentication(userName, null, null, null, null, agentProxy, portNumber, false, url, isPartial); }
/** * Creates a user credential object for authenticating over an ssh tunnel. * * @param userName the name of a user to authenticate * @param privateKey the user's ssh private key * @param passphrase a password to the ssh private key * @param portNumber the number of a port to establish an ssh tunnel over * @param storageAllowed if <span class="javakeyword">true</span> then * this credential is allowed to be stored in the * global auth cache, otherwise not * @param url url these credentials are applied to * * @since 1.8.9 */ public static SVNSSHAuthentication newInstance(String userName, char[] keyValue, char[] passphrase, int portNumber, boolean storageAllowed, SVNURL url, boolean isPartial) { return new SVNSSHAuthentication(userName, null, null, keyValue, passphrase, null, portNumber, storageAllowed, url, isPartial); }
/** * Creates a user credential object for authenticating over an ssh tunnel. * * @param userName the name of a user to authenticate * @param password the user's password * @param portNumber the number of a port to establish an ssh tunnel over * @param storageAllowed if <span class="javakeyword">true</span> then * this credential is allowed to be stored in the * global auth cache, otherwise not * @param url url these credentials are applied to * * @since 1.8.9 */ public static SVNSSHAuthentication newInstance(String userName, char[] password, int portNumber, boolean storageAllowed, SVNURL url, boolean isPartial) { return new SVNSSHAuthentication(userName, password, null, null, null, null, portNumber, storageAllowed, url, isPartial); }
/** * Creates a user credential object for authenticating over an ssh tunnel. * * @param userName the name of a user to authenticate * @param keyFile the user's ssh private key file * @param passphrase a password to the ssh private key * @param portNumber the number of a port to establish an ssh tunnel over * @param storageAllowed if <span class="javakeyword">true</span> then * this credential is allowed to be stored in the * global auth cache, otherwise not * @param url url these credentials are applied to * * @since 1.8.9 */ public static SVNSSHAuthentication newInstance(String userName, File keyFile, char[] passphrase, int portNumber, boolean storageAllowed, SVNURL url, boolean isPartial) { return new SVNSSHAuthentication(userName, null, keyFile, null, passphrase, null, portNumber, storageAllowed, url, isPartial); }
public List<SVNAuthentication> build(String kind, SVNURL url) { List<SVNAuthentication> result = new ArrayList<SVNAuthentication>(); if (ISVNAuthenticationManager.SSH.equals(kind)) { for (String privateKey : privateKeys) { result.add(new SVNSSHAuthentication(username, privateKey.toCharArray(), Scrambler.descramble(passphrase), -1, false, url, false)); } } return result; } }
public List<SVNAuthentication> build(String kind, SVNURL url) { if (ISVNAuthenticationManager.PASSWORD.equals(kind)) { return Collections.<SVNAuthentication>singletonList( new SVNPasswordAuthentication(username, Scrambler.descramble(password), false, url, false)); } if (ISVNAuthenticationManager.SSH.equals(kind)) { return Collections.<SVNAuthentication>singletonList( new SVNSSHAuthentication(username, Scrambler.descramble(password), -1, false, url, false)); } return Collections.emptyList(); } }
@Override public SVNAuthentication createSVNAuthentication(String kind) { if (kind.equals(ISVNAuthenticationManager.SSH)) { return new SVNSSHAuthentication(userName, Scrambler.descramble(password), -1, false, null, false); } return new SVNPasswordAuthentication(userName, Scrambler.descramble(password), false, null, false); }
/** * Creates an auth manager given a user credential - a username and * an ssh private key. * * @param userName a username * @param keyFile a private key file * @param passphrase a password to the private key * @param portNumber a port number over which an ssh tunnel is established */ public BasicAuthenticationManager(String userName, File keyFile, String passphrase, int portNumber) { setAuthentications(new SVNAuthentication[] { new SVNSSHAuthentication(userName, keyFile, passphrase, portNumber, false, null, false), new SVNUserNameAuthentication(userName, false, null, false), }); }
@Override public SVNAuthentication createSVNAuthentication(String kind) { if (kind.equals(ISVNAuthenticationManager.SSH)) { return new SVNSSHAuthentication(userName, Scrambler.descramble(password), -1, false); } else { return new SVNPasswordAuthentication(userName, Scrambler.descramble(password), false); } }
/** * Creates an auth manager given a user credential - a username and * an ssh private key. * * @param userName a username * @param keyFile a private key file * @param passphrase a password to the private key * @param portNumber a port number over which an ssh tunnel is established */ public BasicAuthenticationManager(String userName, File keyFile, String passphrase, int portNumber) { setAuthentications(new SVNAuthentication[] { new SVNSSHAuthentication(userName, keyFile, passphrase, portNumber, false, null, false), new SVNUserNameAuthentication(userName, false, null, false), }); }
@Override public SVNAuthentication createSVNAuthentication(String kind) { if(kind.equals(ISVNAuthenticationManager.SSH)) return new SVNSSHAuthentication(userName, getPassword(),-1,false); else return new SVNPasswordAuthentication(userName, getPassword(),false); }
/** * Creates an auth manager given a user credential - a username and * an ssh private key. * * @param userName a username * @param keyFile a private key file * @param passphrase a password to the private key * @param portNumber a port number over which an ssh tunnel is established */ public BasicAuthenticationManager(String userName, File keyFile, String passphrase, int portNumber) { setAuthentications(new SVNAuthentication[] { new SVNSSHAuthentication(userName, keyFile, passphrase, portNumber, false), new SVNUserNameAuthentication(userName, false), }); }
public SVNAuthentication requestClientAuthentication(String kind, SVNURL url, String realm, SVNErrorMessage errorMessage, SVNAuthentication previousAuth, boolean authMayBeStored) { if (previousAuth == null) { if (ISVNAuthenticationManager.SSH.equals(kind)) { SVNSSHAuthentication sshAuth = getDefaultSSHAuthentication(); if (myUserName == null || "".equals(myUserName.trim())) { return sshAuth; } if (myPrivateKey != null) { return new SVNSSHAuthentication(myUserName, myPrivateKey, myPassphrase, sshAuth != null ? sshAuth.getPortNumber() : -1, myIsStore); } return new SVNSSHAuthentication(myUserName, myPassword, sshAuth != null ? sshAuth.getPortNumber() : -1, myIsStore); } else if (ISVNAuthenticationManager.PASSWORD.equals(kind)) { if (myUserName == null || "".equals(myUserName.trim())) { return null; } return new SVNPasswordAuthentication(myUserName, myPassword, myIsStore); } else if (ISVNAuthenticationManager.USERNAME.equals(kind)) { if (myUserName == null || "".equals(myUserName)) { return null; } return new SVNUserNameAuthentication(myUserName, myIsStore); } } return null; } public int acceptServerAuthentication(SVNURL url, String r, Object serverAuth, boolean resultMayBeStored) {
/** * Creates an auth manager given a user credential - a username * and password. * * @param userName a username * @param password a password */ public BasicAuthenticationManager(String userName, String password) { setAuthentications(new SVNAuthentication[] { new SVNPasswordAuthentication(userName, password, false, null, false), new SVNSSHAuthentication(userName, password, -1, false, null, false), new SVNUserNameAuthentication(userName, false, null, false), }); }
/** * Creates an auth manager given a user credential - a username * and password. * * @param userName a username * @param password a password */ public BasicAuthenticationManager(String userName, String password) { setAuthentications(new SVNAuthentication[] { new SVNPasswordAuthentication(userName, password, false, null, false), new SVNSSHAuthentication(userName, password, -1, false, null, false), new SVNUserNameAuthentication(userName, false, null, false), }); }
/** * Creates an auth manager given a user credential - a username * and password. * * @param userName a username * @param password a password */ public BasicAuthenticationManager(String userName, String password) { setAuthentications(new SVNAuthentication[] { new SVNPasswordAuthentication(userName, password, false), new SVNSSHAuthentication(userName, password, -1, false), new SVNUserNameAuthentication(userName, false), }); }
@Test public void compareSVNAuthentications() throws Exception { assertFalse(SubversionSCM.compareSVNAuthentications(new SVNUserNameAuthentication("me",true),new SVNSSHAuthentication("me","me",22,true))); // same object should compare equal _idem(new SVNUserNameAuthentication("me",true)); _idem(new SVNSSHAuthentication("me","pass",22,true)); _idem(new SVNSSHAuthentication("me",new File("./some.key"),null,23,false)); _idem(new SVNSSHAuthentication("me","key".toCharArray(),"phrase",0,false)); _idem(new SVNPasswordAuthentication("me","pass",true)); _idem(new SVNSSLAuthentication(new File("./some.key"), "", true)); // make sure two Files and char[]s compare the same assertTrue(SubversionSCM.compareSVNAuthentications( new SVNSSHAuthentication("me",new File("./some.key"),null,23,false), new SVNSSHAuthentication("me",new File("./some.key"),null,23,false))); assertTrue(SubversionSCM.compareSVNAuthentications( new SVNSSHAuthentication("me","key".toCharArray(),"phrase",0,false), new SVNSSHAuthentication("me","key".toCharArray(),"phrase",0,false))); // negative cases assertFalse(SubversionSCM.compareSVNAuthentications( new SVNSSHAuthentication("me",new File("./some1.key"),null,23,false), new SVNSSHAuthentication("me",new File("./some2.key"),null,23,false))); assertFalse(SubversionSCM.compareSVNAuthentications( new SVNSSHAuthentication("me","key".toCharArray(),"phrase",0,false), new SVNSSHAuthentication("yo","key".toCharArray(),"phrase",0,false))); }
@Override public SVNSSHAuthentication createSVNAuthentication(String kind) throws SVNException { if(kind.equals(ISVNAuthenticationManager.SSH)) { try { Channel channel = Channel.current(); String privateKey; if(channel!=null) { // remote // Unsafe in general, but we should have already converted $JENKINS_HOME/subversion-credentials anyway. privateKey = channel.call(new SlaveToMasterCallable<String,IOException>() { /** * */ private static final long serialVersionUID = -3088632649290496373L; public String call() throws IOException { return FileUtils.readFileToString(getKeyFile(),"iso-8859-1"); } }); } else { privateKey = FileUtils.readFileToString(getKeyFile(),"iso-8859-1"); } return new SVNSSHAuthentication(userName, privateKey.toCharArray(), Scrambler.descramble(Secret.toString(passphrase)),-1,false); } catch (IOException | InterruptedException e) { throw new SVNException( new RemotableSVNErrorMessage(SVNErrorCode.AUTHN_CREDS_UNAVAILABLE, "Unable to load private key"), e); } } else return null; // unknown }
@Override public SVNAuthentication copy() { return new SVNSSHAuthentication(getUserName(), copyOf(myPassword), myPrivateKeyFile, copyOf(myPrivateKeyValue), copyOf(myPassphrase), myAgentProxy, myPortNumber, isStorageAllowed(), getURL(), isPartial()); }
private ISVNAuthenticationManager getAuthManager() { if ( getPrivateKey() != null ) { SVNSSHAuthentication[] auth = new SVNSSHAuthentication[1]; auth[0] = new SVNSSHAuthentication( getUser(), getPrivateKey().toCharArray(), getPassphrase(), -1, false ); return new BasicAuthenticationManager( auth ); } else if ( getUser() != null ) { return new BasicAuthenticationManager( getUser(), getPassword() ); } else { String configDirectory = SvnUtil.getSettings().getConfigDirectory(); return SVNWCUtil.createDefaultAuthenticationManager( configDirectory == null ? null : new File( configDirectory ), getUser(), getPassword(), SvnUtil.getSettings().isUseAuthCache() ); } } }