INTSAMPLES-78 - Don't use hard-coded FTP port
For reference see: https://jira.springsource.org/browse/INTSAMPLES-78
This commit is contained in:
@@ -23,6 +23,12 @@
|
||||
<artifactId>spring-integration-ftp</artifactId>
|
||||
<version>${spring.integration.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.integration</groupId>
|
||||
<artifactId>spring-integration-test</artifactId>
|
||||
<version>${spring.integration.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -24,6 +24,7 @@ import org.apache.ftpserver.FtpServer;
|
||||
import org.apache.ftpserver.FtpServerFactory;
|
||||
import org.apache.ftpserver.ftplet.FtpException;
|
||||
import org.apache.ftpserver.listener.ListenerFactory;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.ClassRule;
|
||||
@@ -31,6 +32,7 @@ import org.junit.rules.TemporaryFolder;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Suite;
|
||||
import org.springframework.integration.samples.ftp.support.TestUserManager;
|
||||
import org.springframework.integration.test.util.SocketUtils;
|
||||
|
||||
/**
|
||||
* Test Suite that will bootstrap an embedded Apache FTP Server. Additionally some
|
||||
@@ -48,8 +50,11 @@ import org.springframework.integration.samples.ftp.support.TestUserManager;
|
||||
})
|
||||
public class TestSuite {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(TestSuite.class);
|
||||
|
||||
public static final String FTP_ROOT_DIR = "target" + File.separator + "ftproot";
|
||||
public static final String LOCAL_FTP_TEMP_DIR = "target" + File.separator + "local-ftp-temp";
|
||||
public static final String SERVER_PORT_SYSTEM_PROPERTY = "availableServerPort";
|
||||
|
||||
@ClassRule
|
||||
public static final TemporaryFolder temporaryFolder = new TemporaryFolder();
|
||||
@@ -59,6 +64,17 @@ public class TestSuite {
|
||||
@BeforeClass
|
||||
public static void setupFtpServer() throws FtpException, SocketException, IOException {
|
||||
|
||||
final int availableServerSocket;
|
||||
|
||||
if (System.getProperty(SERVER_PORT_SYSTEM_PROPERTY) == null) {
|
||||
availableServerSocket = SocketUtils.findAvailableServerSocket(4444);
|
||||
System.setProperty(SERVER_PORT_SYSTEM_PROPERTY, Integer.valueOf(availableServerSocket).toString());
|
||||
} else {
|
||||
availableServerSocket = Integer.valueOf(System.getProperty(SERVER_PORT_SYSTEM_PROPERTY));
|
||||
}
|
||||
|
||||
LOGGER.info("Using open server port..." + availableServerSocket);
|
||||
|
||||
File ftpRoot = new File (FTP_ROOT_DIR);
|
||||
ftpRoot.mkdirs();
|
||||
|
||||
@@ -68,7 +84,7 @@ public class TestSuite {
|
||||
serverFactory.setUserManager(userManager);
|
||||
ListenerFactory factory = new ListenerFactory();
|
||||
|
||||
factory.setPort(3333);
|
||||
factory.setPort(availableServerSocket);
|
||||
|
||||
serverFactory.addListener("default", factory.createListener());
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -31,73 +31,73 @@ import org.apache.ftpserver.usermanager.impl.ConcurrentLoginPermission;
|
||||
import org.apache.ftpserver.usermanager.impl.WritePermission;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Gunnar Hillert
|
||||
*
|
||||
*/
|
||||
public class TestUserManager extends AbstractUserManager {
|
||||
private BaseUser testUser;
|
||||
private BaseUser anonUser;
|
||||
private BaseUser testUser;
|
||||
private BaseUser anonUser;
|
||||
|
||||
private static final String TEST_USERNAME = "demo";
|
||||
private static final String TEST_PASSWORD = "demo";
|
||||
private static final String TEST_USERNAME = "demo";
|
||||
private static final String TEST_PASSWORD = "demo";
|
||||
|
||||
public TestUserManager(String homeDirectory) {
|
||||
super("admin", new ClearTextPasswordEncryptor());
|
||||
super("admin", new ClearTextPasswordEncryptor());
|
||||
|
||||
testUser = new BaseUser();
|
||||
testUser.setAuthorities(Arrays.asList(new Authority[] {new ConcurrentLoginPermission(1, 1), new WritePermission()}));
|
||||
testUser.setEnabled(true);
|
||||
testUser.setHomeDirectory(homeDirectory);
|
||||
testUser.setMaxIdleTime(10000);
|
||||
testUser.setName(TEST_USERNAME);
|
||||
testUser.setPassword(TEST_PASSWORD);
|
||||
testUser = new BaseUser();
|
||||
testUser.setAuthorities(Arrays.asList(new Authority[] {new ConcurrentLoginPermission(1, 1), new WritePermission()}));
|
||||
testUser.setEnabled(true);
|
||||
testUser.setHomeDirectory(homeDirectory);
|
||||
testUser.setMaxIdleTime(10000);
|
||||
testUser.setName(TEST_USERNAME);
|
||||
testUser.setPassword(TEST_PASSWORD);
|
||||
|
||||
anonUser = new BaseUser(testUser);
|
||||
anonUser.setName("anonymous");
|
||||
}
|
||||
anonUser = new BaseUser(testUser);
|
||||
anonUser.setName("anonymous");
|
||||
}
|
||||
|
||||
public User getUserByName(String username) throws FtpException {
|
||||
if(TEST_USERNAME.equals(username)) {
|
||||
return testUser;
|
||||
} else if(anonUser.getName().equals(username)) {
|
||||
return anonUser;
|
||||
}
|
||||
public User getUserByName(String username) throws FtpException {
|
||||
if(TEST_USERNAME.equals(username)) {
|
||||
return testUser;
|
||||
} else if(anonUser.getName().equals(username)) {
|
||||
return anonUser;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String[] getAllUserNames() throws FtpException {
|
||||
return new String[] {TEST_USERNAME, anonUser.getName()};
|
||||
}
|
||||
public String[] getAllUserNames() throws FtpException {
|
||||
return new String[] {TEST_USERNAME, anonUser.getName()};
|
||||
}
|
||||
|
||||
public void delete(String username) throws FtpException {
|
||||
throw new UnsupportedOperationException("Deleting of FTP Users is not supported.");
|
||||
}
|
||||
public void delete(String username) throws FtpException {
|
||||
throw new UnsupportedOperationException("Deleting of FTP Users is not supported.");
|
||||
}
|
||||
|
||||
public void save(User user) throws FtpException {
|
||||
throw new UnsupportedOperationException("Saving of FTP Users is not supported.");
|
||||
}
|
||||
public void save(User user) throws FtpException {
|
||||
throw new UnsupportedOperationException("Saving of FTP Users is not supported.");
|
||||
}
|
||||
|
||||
public boolean doesExist(String username) throws FtpException {
|
||||
return (TEST_USERNAME.equals(username) || anonUser.getName().equals(username)) ? true : false;
|
||||
}
|
||||
public boolean doesExist(String username) throws FtpException {
|
||||
return (TEST_USERNAME.equals(username) || anonUser.getName().equals(username)) ? true : false;
|
||||
}
|
||||
|
||||
public User authenticate(Authentication authentication) throws AuthenticationFailedException {
|
||||
if(UsernamePasswordAuthentication.class.isAssignableFrom(authentication.getClass())) {
|
||||
UsernamePasswordAuthentication upAuth = (UsernamePasswordAuthentication) authentication;
|
||||
public User authenticate(Authentication authentication) throws AuthenticationFailedException {
|
||||
if(UsernamePasswordAuthentication.class.isAssignableFrom(authentication.getClass())) {
|
||||
UsernamePasswordAuthentication upAuth = (UsernamePasswordAuthentication) authentication;
|
||||
|
||||
if(TEST_USERNAME.equals(upAuth.getUsername()) && TEST_PASSWORD.equals(upAuth.getPassword())) {
|
||||
return testUser;
|
||||
}
|
||||
if(TEST_USERNAME.equals(upAuth.getUsername()) && TEST_PASSWORD.equals(upAuth.getPassword())) {
|
||||
return testUser;
|
||||
}
|
||||
|
||||
if(anonUser.getName().equals(upAuth.getUsername())) {
|
||||
return anonUser;
|
||||
}
|
||||
} else if(AnonymousAuthentication.class.isAssignableFrom(authentication.getClass())) {
|
||||
return anonUser;
|
||||
}
|
||||
if(anonUser.getName().equals(upAuth.getUsername())) {
|
||||
return anonUser;
|
||||
}
|
||||
} else if(AnonymousAuthentication.class.isAssignableFrom(authentication.getClass())) {
|
||||
return anonUser;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,25 +10,25 @@
|
||||
http://www.springframework.org/schema/integration/ftp http://www.springframework.org/schema/integration/ftp/spring-integration-ftp.xsd">
|
||||
|
||||
<context:property-placeholder location="classpath:user.properties"/>
|
||||
|
||||
|
||||
<bean id="ftpClientFactory" class="org.springframework.integration.ftp.session.DefaultFtpSessionFactory">
|
||||
<property name="host" value="${host}"/>
|
||||
<property name="port" value="${port}"/>
|
||||
<property name="port" value="${availableServerPort}"/>
|
||||
<property name="username" value="${userid}"/>
|
||||
<property name="password" value="${password}"/>
|
||||
</bean>
|
||||
|
||||
|
||||
<int-ftp:inbound-channel-adapter id="ftpInbound" cache-sessions="false"
|
||||
channel="ftpChannel"
|
||||
channel="ftpChannel"
|
||||
session-factory="ftpClientFactory"
|
||||
filename-pattern="*.txt"
|
||||
filename-pattern="*.txt"
|
||||
auto-create-local-directory="true"
|
||||
delete-remote-files="false"
|
||||
remote-directory="/"
|
||||
local-directory="#{ T(org.springframework.integration.samples.ftp.TestSuite).LOCAL_FTP_TEMP_DIR}/ftpInbound">
|
||||
<int:poller fixed-rate="1000"/>
|
||||
</int-ftp:inbound-channel-adapter>
|
||||
|
||||
|
||||
<int:channel id="ftpChannel">
|
||||
<int:queue/>
|
||||
</int:channel>
|
||||
|
||||
@@ -13,16 +13,16 @@
|
||||
|
||||
<bean id="ftpClientFactory" class="org.springframework.integration.ftp.session.DefaultFtpSessionFactory">
|
||||
<property name="host" value="${host}"/>
|
||||
<property name="port" value="${port}"/>
|
||||
<property name="port" value="${availableServerPort}"/>
|
||||
<property name="username" value="${userid}"/>
|
||||
<property name="password" value="${password}"/>
|
||||
</bean>
|
||||
|
||||
|
||||
<int:channel id="ftpChannel"/>
|
||||
|
||||
<int-ftp:outbound-channel-adapter id="ftpOutbound" cache-sessions="false"
|
||||
channel="ftpChannel"
|
||||
channel="ftpChannel"
|
||||
remote-directory="/"
|
||||
session-factory="ftpClientFactory" />
|
||||
|
||||
|
||||
</beans>
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
<bean id="ftpSessionFactory"
|
||||
class="org.springframework.integration.ftp.session.DefaultFtpSessionFactory">
|
||||
<property name="host" value="${host}"/>
|
||||
<property name="port" value="${port}"/>
|
||||
<property name="port" value="${availableServerPort}"/>
|
||||
<property name="username" value="${userid}"/>
|
||||
<property name="password" value="${password}"/>
|
||||
</bean>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
userid=demo
|
||||
password=demo
|
||||
port=3333
|
||||
availableServerPort=3333
|
||||
host=localhost
|
||||
Reference in New Issue
Block a user