Revision 46743
Added by Alessia Bardi about 7 years ago
modules/dnet-data-services/branches/saxonHE/src/test/java/eu/dnetlib/data/collector/plugins/sftp/SftpPubKeyCollectorPluginTest.java | ||
---|---|---|
31 | 31 |
apiDescriptor.setId("testSFTP"); |
32 | 32 |
apiDescriptor.getParams().put("recursive", "false"); |
33 | 33 |
apiDescriptor.getParams().put("extensions", "xml"); |
34 |
apiDescriptor.getParams().put("username", "alessia"); |
|
34 | 35 |
} |
35 | 36 |
|
36 | 37 |
@Test |
37 | 38 |
public void testWithAriadneServerNorecursive() throws CollectorServiceException { |
38 |
apiDescriptor.getParams().put("recursive", "false"); |
|
39 |
|
|
39 | 40 |
Iterable<String> res = plugin.collect(apiDescriptor, null, null); |
40 | 41 |
Assert.assertNotNull(res); |
41 | 42 |
for(String r : res){ |
modules/dnet-data-services/branches/saxonHE/src/test/resources/eu/dnetlib/data/collector/plugins/sftp/SftpPubKeyCollectorPluginTest-context.xml | ||
---|---|---|
10 | 10 |
<property name="params"> |
11 | 11 |
<list> |
12 | 12 |
<bean class="eu.dnetlib.rmi.data.ProtocolParameter" |
13 |
p:name="username" /> |
|
14 |
<bean class="eu.dnetlib.rmi.data.ProtocolParameter" |
|
13 | 15 |
p:name="recursive" p:type="BOOLEAN"/> |
14 | 16 |
<bean class="eu.dnetlib.rmi.data.ProtocolParameter" |
15 | 17 |
p:name="extensions" p:type="LIST"/> |
... | ... | |
26 | 28 |
<property name="properties"> |
27 | 29 |
<props> |
28 | 30 |
<prop key="collector.sftp.auth.prvKeyPath">~/.ssh/id_rsa</prop> |
29 |
<prop key="collector.sftp.auth.passphrase">pippo</prop>
|
|
31 |
<prop key="collector.sftp.auth.passphrase"></prop> |
|
30 | 32 |
<prop key="collector.sftp.auth.knownHostsPath">~/.ssh/known_hosts</prop> |
31 | 33 |
</props> |
32 | 34 |
</property> |
modules/dnet-data-services/branches/saxonHE/src/main/java/eu/dnetlib/data/collector/plugins/sftp/SftpPubKeyCollectorPlugin.java | ||
---|---|---|
4 | 4 |
|
5 | 5 |
import eu.dnetlib.rmi.data.CollectorServiceException; |
6 | 6 |
import eu.dnetlib.rmi.data.InterfaceDescriptor; |
7 |
import org.apache.commons.lang3.StringUtils; |
|
8 |
import org.apache.commons.logging.Log; |
|
9 |
import org.apache.commons.logging.LogFactory; |
|
7 | 10 |
import org.springframework.beans.factory.annotation.Value; |
8 | 11 |
|
9 | 12 |
/** |
... | ... | |
11 | 14 |
*/ |
12 | 15 |
public class SftpPubKeyCollectorPlugin extends AbstractSftpCollectorPlugin { |
13 | 16 |
|
17 |
private static final Log log = LogFactory.getLog(SftpPubKeyCollectorPlugin.class); |
|
14 | 18 |
@Value("${collector.sftp.auth.prvKeyPath}") |
15 | 19 |
private String prvKeyFilePath; |
16 | 20 |
@Value("${collector.sftp.auth.passphrase}") |
... | ... | |
25 | 29 |
final Set<String> extensionSet, |
26 | 30 |
final String fromDate) throws CollectorServiceException { |
27 | 31 |
|
28 |
return () -> getSftpIteratorFactory().newIteratorPubKeyAuth(baseUrl, prvKeyFilePath, passphrase, knownHostsFile, isRecursive, extensionSet, fromDate); |
|
32 |
String username = interfaceDescriptor.getParams().get("username"); |
|
33 |
if(StringUtils.isBlank(username)) { |
|
34 |
log.warn("Param 'username' is null or empty"); |
|
35 |
} |
|
36 |
return () -> getSftpIteratorFactory().newIteratorPubKeyAuth(baseUrl, username, prvKeyFilePath, passphrase, knownHostsFile, isRecursive, extensionSet, fromDate); |
|
29 | 37 |
} |
30 | 38 |
|
31 | 39 |
} |
modules/dnet-data-services/branches/saxonHE/src/main/java/eu/dnetlib/data/collector/plugins/sftp/SftpIterator.java | ||
---|---|---|
81 | 81 |
initializeQueue(); |
82 | 82 |
} |
83 | 83 |
|
84 |
public SftpIterator(final String baseUrl, final String prvKeyFilePath, final String passPhrase, final String knownHostsFile, final boolean isRecursive, final Set<String> extensionsSet, final String fromDate) { |
|
84 |
public SftpIterator(final String baseUrl, final String username, final String prvKeyFilePath, final String passPhrase, final String knownHostsFile, final boolean isRecursive, final Set<String> extensionsSet, final String fromDate) {
|
|
85 | 85 |
init(baseUrl, isRecursive, extensionsSet, fromDate); |
86 |
this.username = username; |
|
86 | 87 |
this.passPhrase = passPhrase; |
87 | 88 |
this.prvKeyFile = prvKeyFilePath; |
88 | 89 |
this.knownHostsFile = knownHostsFile; |
... | ... | |
93 | 94 |
private void connectToSftpServerPubKeyAuth() { |
94 | 95 |
JSch jsch = new JSch(); |
95 | 96 |
log.info("Connecting to "+sftpServerAddress+" with PubKey authentication"); |
97 |
//log.info("Username "+username); |
|
96 | 98 |
log.info("Private key path: "+prvKeyFile); |
97 |
log.info("Pass phrase: "+passPhrase); |
|
99 |
if(StringUtils.isNotBlank(passPhrase)){ |
|
100 |
log.info("with Pass phrase"); |
|
101 |
} |
|
98 | 102 |
log.info("Known host file path: "+knownHostsFile); |
99 | 103 |
try { |
100 | 104 |
jsch.setKnownHosts(this.knownHostsFile); |
101 | 105 |
jsch.addIdentity(this.prvKeyFile, this.passPhrase); |
102 | 106 |
sftpSession = jsch.getSession(sftpServerAddress); |
107 |
//sftpSession = jsch.getSession(username, sftpServerAddress); |
|
103 | 108 |
sftpSession.connect(); |
104 | 109 |
openChannelOnBasePath(); |
105 | 110 |
} catch (JSchException e) { |
modules/dnet-data-services/branches/saxonHE/src/main/java/eu/dnetlib/data/collector/plugins/sftp/SftpIteratorFactory.java | ||
---|---|---|
16 | 16 |
return new SftpIterator(baseUrl, username, password, isRecursive, extensionsSet, fromDate); |
17 | 17 |
} |
18 | 18 |
|
19 |
public Iterator<String> newIteratorPubKeyAuth(final String baseUrl, |
|
19 |
public Iterator<String> newIteratorPubKeyAuth(final String baseUrl, String username,
|
|
20 | 20 |
final String prvKeyFilePath, final String passPhrase, final String knownHostsFile, |
21 | 21 |
final boolean isRecursive, |
22 | 22 |
final Set<String> extensionsSet, final String fromDate) { |
23 |
return new SftpIterator(baseUrl, prvKeyFilePath, passPhrase,knownHostsFile, isRecursive, extensionsSet, fromDate); |
|
23 |
return new SftpIterator(baseUrl, username, prvKeyFilePath, passPhrase,knownHostsFile, isRecursive, extensionsSet, fromDate);
|
|
24 | 24 |
} |
25 | 25 |
} |
modules/dnet-data-services/branches/saxonHE/src/main/resources/eu/dnetlib/data/collector/plugins/applicationContext-dnet-modular-collector-plugins.xml | ||
---|---|---|
153 | 153 |
<property name="params"> |
154 | 154 |
<list> |
155 | 155 |
<bean class="eu.dnetlib.rmi.data.ProtocolParameter" |
156 |
p:name="username"/> |
|
157 |
<bean class="eu.dnetlib.rmi.data.ProtocolParameter" |
|
156 | 158 |
p:name="recursive" p:type="BOOLEAN"/> |
157 | 159 |
<bean class="eu.dnetlib.rmi.data.ProtocolParameter" |
158 | 160 |
p:name="extensions" p:type="LIST"/> |
Also available in: Unified diff
Added username parameter to the SFTP plugin with public key auth