001: /*
002: * ====================================================================
003: * Copyright (c) 2004-2008 TMate Software Ltd. All rights reserved.
004: *
005: * This software is licensed as described in the file COPYING, which
006: * you should have received as part of this distribution. The terms
007: * are also available at http://svnkit.com/license.html
008: * If newer versions of this license are posted there, you may use a
009: * newer version instead, at your option.
010: * ====================================================================
011: */
012: package org.tmatesoft.svn.core.auth;
013:
014: import java.io.File;
015:
016: /**
017: * The <b>SVNSSHAuthentication</b> class represents a kind of credentials used
018: * to authenticate a user over an SSH tunnel.
019: *
020: * <p>
021: * To obtain an ssh user credential, specify the {@link ISVNAuthenticationManager#SSH SSH}
022: * kind to credentials getter method of <b>ISVNAuthenticationManager</b>:
023: * {@link ISVNAuthenticationManager#getFirstAuthentication(String, String, SVNURL) getFirstAuthentication()},
024: * {@link ISVNAuthenticationManager#getNextAuthentication(String, String, SVNURL) getNextAuthentication()}.
025: *
026: * @version 1.1.1
027: * @author TMate Software Ltd.
028: * @see ISVNAuthenticationManager
029: */
030: public class SVNSSHAuthentication extends SVNAuthentication {
031:
032: private String myPassword;
033: private String myPassphrase;
034: private File myPrivateKeyFile;
035: private int myPortNumber;
036: private char[] myPrivateKeyValue;
037:
038: /**
039: * Creates a user credential object for authenticating over an ssh tunnel.
040: * This kind of credentials is used when an ssh connection requires
041: * a user password instead of an ssh private key.
042: *
043: * @param userName the name of a user to authenticate
044: * @param password the user's password
045: * @param portNumber the number of a port to establish an ssh tunnel over
046: * @param storageAllowed if <span class="javakeyword">true</span> then
047: * this credential is allowed to be stored in the
048: * global auth cache, otherwise not
049: */
050: public SVNSSHAuthentication(String userName, String password,
051: int portNumber, boolean storageAllowed) {
052: super (ISVNAuthenticationManager.SSH, userName, storageAllowed);
053: myPassword = password;
054: myPortNumber = portNumber;
055: }
056:
057: /**
058: * Creates a user credential object for authenticating over an ssh tunnel.
059: * This kind of credentials is used when an ssh connection requires
060: * an ssh private key.
061: *
062: * @param userName the name of a user to authenticate
063: * @param keyFile the user's ssh private key file
064: * @param passphrase a password to the ssh private key
065: * @param portNumber the number of a port to establish an ssh tunnel over
066: * @param storageAllowed if <span class="javakeyword">true</span> then
067: * this credential is allowed to be stored in the
068: * global auth cache, otherwise not
069: */
070: public SVNSSHAuthentication(String userName, File keyFile,
071: String passphrase, int portNumber, boolean storageAllowed) {
072: super (ISVNAuthenticationManager.SSH, userName, storageAllowed);
073: myPrivateKeyFile = keyFile;
074: myPassphrase = passphrase;
075: myPortNumber = portNumber;
076: }
077:
078: /**
079: * Creates a user credential object for authenticating over an ssh tunnel.
080: * This kind of credentials is used when an ssh connection requires
081: * an ssh private key.
082: *
083: * @param userName the name of a user to authenticate
084: * @param privateKey the user's ssh private key
085: * @param passphrase a password to the ssh private key
086: * @param portNumber the number of a port to establish an ssh tunnel over
087: * @param storageAllowed if <span class="javakeyword">true</span> then
088: * this credential is allowed to be stored in the
089: * global auth cache, otherwise not
090: */
091: public SVNSSHAuthentication(String userName, char[] privateKey,
092: String passphrase, int portNumber, boolean storageAllowed) {
093: super (ISVNAuthenticationManager.SSH, userName, storageAllowed);
094: myPrivateKeyValue = privateKey;
095: myPassphrase = passphrase;
096: myPortNumber = portNumber;
097: }
098:
099: /**
100: * Returns the user account's password. This is used when an
101: * ssh private key is not used.
102: *
103: * @return the user's password
104: */
105: public String getPassword() {
106: return myPassword;
107: }
108:
109: /**
110: * Returns the password to the ssh private key.
111: *
112: * @return the password to the private key
113: * @see #getPrivateKeyFile()
114: */
115: public String getPassphrase() {
116: return myPassphrase;
117: }
118:
119: /**
120: * Returns the File representation referring to the file with the
121: * user's ssh private key. If the private key is encrypted with a
122: * passphrase, it should have been provided to an appropriate constructor.
123: *
124: * @return the user's private key file
125: */
126: public File getPrivateKeyFile() {
127: return myPrivateKeyFile;
128: }
129:
130: /**
131: * Returns ssh private key. If the private key is encrypted with a
132: * passphrase, it should have been provided to an appropriate constructor.
133: *
134: * @return the user's private key file
135: */
136: public char[] getPrivateKey() {
137: return myPrivateKeyValue;
138: }
139:
140: /**
141: * Returns the number of the port across which an ssh tunnel
142: * is established.
143: *
144: * @return the port number to establish an ssh tunnel over
145: */
146: public int getPortNumber() {
147: return myPortNumber;
148: }
149:
150: public boolean hasPrivateKey() {
151: return myPrivateKeyFile != null || myPrivateKeyValue != null;
152: }
153: }
|