Commit a6317a0d authored by Matija Obreza's avatar Matija Obreza

Updated FTP server tests for ACL support in repository

parent 1b554517
Pipeline #6669 passed with stage
in 1 minute and 49 seconds
......@@ -57,6 +57,13 @@
<version>${spring.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<version>${spring.security.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-net</groupId>
......@@ -80,6 +87,13 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
......
......@@ -16,6 +16,7 @@
package org.genesys.filerepository.service.ftp;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.apache.ftpserver.ftplet.Authentication;
......@@ -29,8 +30,11 @@ import org.apache.ftpserver.usermanager.UsernamePasswordAuthentication;
import org.apache.ftpserver.usermanager.impl.AbstractUserManager;
import org.apache.ftpserver.usermanager.impl.ConcurrentLoginPermission;
import org.apache.ftpserver.usermanager.impl.WritePermission;
import org.genesys.blocks.security.model.BasicUser;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
/**
* The Class ApplicationConfig.
......@@ -128,10 +132,10 @@ public class ApplicationConfig {
if (authentication instanceof UsernamePasswordAuthentication) {
final UsernamePasswordAuthentication upauth = (UsernamePasswordAuthentication) authentication;
final String user = upauth.getUsername();
final String username = upauth.getUsername();
String password = upauth.getPassword();
if (user == null) {
if (username == null) {
throw new AuthenticationFailedException("Authentication failed");
}
......@@ -139,7 +143,7 @@ public class ApplicationConfig {
password = "";
}
final String storedPassword = user.concat("1!");
final String storedPassword = username.concat("1!");
if (!password.equals(storedPassword)) {
// user does not exist
......@@ -148,11 +152,25 @@ public class ApplicationConfig {
// if (getPasswordEncryptor().matches(password, storedPassword)) {
if (password.equals(storedPassword)) {
try {
return getUserByName(user);
} catch (final FtpException e) {
throw new AuthenticationFailedException("Authentication failed", e);
}
// using this to grant us ADMIN role
BasicUser<GrantedAuthority> user=new BasicUser<GrantedAuthority>() {
@Override
public Collection<? extends GrantedAuthority> getAuthorities() {
List<GrantedAuthority> roles=new ArrayList<>();
roles.add(new SimpleGrantedAuthority("ROLE_ADMINISTRATOR"));
return roles;
}
};
FtpUser ftpUser = new FtpUser(user);
ftpUser.setName(username);
final List<Authority> authorities = new ArrayList<>();
authorities.add(new ConcurrentLoginPermission(10, 0));
authorities.add(new WritePermission());
ftpUser.setAuthorities(authorities);
ftpUser.setHomeDirectory("/");
return ftpUser;
} else {
throw new AuthenticationFailedException("Authentication failed");
}
......
......@@ -15,11 +15,7 @@
*/
package org.genesys.filerepository.service.ftp;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.hasItems;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertThat;
import java.io.ByteArrayInputStream;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment