Commit 92a4715e authored by Matija Obreza's avatar Matija Obreza
Browse files

Merge branch '20-ftp-server' into 'master'

Resolve "FTP server"

Closes #20

See merge request !76
parents 6b5655ec 87da0417
#
# Basic genesys properties
# You should use envirnment variables to override Genesys configuration defaults
# Basic Genesys properties
# You should use environment variables to override Genesys configuration defaults
#
base.host=docker.local
base.hostname=${base.host}:8080
base.url=https://${base.hostname}
base.cookie-secure=true
base.url=http://${base.hostname}
base.cookie-secure=false
base.cookie-http-only=true
robots.allow=false
db.url=jdbc:mysql://some-server/genesys?useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false
db.driverClassName=com.mysql.jdbc.Driver
db.username=genesys
# In-memory database
db.url=jdbc:hsqldb:mem:test;sql.syntax_mys=true
db.driverClassName=org.hsqldb.jdbc.JDBCDriver
db.username=sa
db.password=
db.showSql=false
db.hbm2ddl=true
hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect
hibernate.dialect=org.hibernate.dialect.HSQLDialect
data.dir=/data/genesys/
# Disable FTP
repository.ftp.port=-1
......@@ -496,8 +496,8 @@
</dependency>
<dependency>
<groupId>org.genesys-pgr</groupId>
<artifactId>file-repository</artifactId>
<version>0.8.1</version>
<artifactId>file-repository-ftpserver</artifactId>
<version>0.9-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
......@@ -779,7 +779,7 @@
</attributes>
</configuration>
</plugin>
<plugin>
<!-- <plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>license-maven-plugin</artifactId>
<version>1.9</version>
......@@ -802,13 +802,14 @@
<configuration>
<sortArtifactByName>true</sortArtifactByName>
</configuration>
</plugin>
</plugin> -->
<plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>${liquibase.version}</version>
<configuration>
<propertyFile>src/main/resources/liquibase.properties</propertyFile>
<verbose>true</verbose>
</configuration>
<dependencies>
<dependency>
......
......@@ -19,12 +19,11 @@ package org.genesys2.server.service;
import java.io.IOException;
import java.util.UUID;
import org.genesys2.server.filerepository.InvalidRepositoryFileDataException;
import org.genesys2.server.filerepository.InvalidRepositoryPathException;
import org.genesys2.server.filerepository.NoSuchRepositoryFileException;
import org.genesys2.server.filerepository.model.ImageGallery;
import org.genesys2.server.filerepository.model.RepositoryImage;
import org.genesys2.server.filerepository.model.RepositoryImageData;
import org.genesys.filerepository.InvalidRepositoryFileDataException;
import org.genesys.filerepository.InvalidRepositoryPathException;
import org.genesys.filerepository.NoSuchRepositoryFileException;
import org.genesys.filerepository.model.ImageGallery;
import org.genesys.filerepository.model.RepositoryImage;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.impl.FaoInstitute;
import org.springframework.data.domain.Page;
......@@ -39,9 +38,9 @@ public interface InstituteFilesService {
RepositoryImage getImage(FaoInstitute institute, Accession accession, UUID uuid) throws NoSuchRepositoryFileException;
RepositoryImage updateImageMetadata(FaoInstitute institute, Accession accession, UUID uuid, RepositoryImageData repositoryImage) throws NoSuchRepositoryFileException;
RepositoryImage updateImageMetadata(FaoInstitute institute, Accession accession, UUID uuid, RepositoryImage repositoryImage) throws NoSuchRepositoryFileException;
byte[] getFileBytes(FaoInstitute institute, Accession accession, RepositoryImage repositoryImage) throws NoSuchRepositoryFileException;
byte[] getFileBytes(FaoInstitute institute, Accession accession, RepositoryImage repositoryImage) throws NoSuchRepositoryFileException, IOException;
Page<ImageGallery> listImageGalleries(FaoInstitute institute, Pageable pageable);
......
......@@ -21,15 +21,14 @@ import java.util.UUID;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.genesys2.server.filerepository.InvalidRepositoryFileDataException;
import org.genesys2.server.filerepository.InvalidRepositoryPathException;
import org.genesys2.server.filerepository.NoSuchRepositoryFileException;
import org.genesys2.server.filerepository.model.ImageGallery;
import org.genesys2.server.filerepository.model.RepositoryFile;
import org.genesys2.server.filerepository.model.RepositoryImage;
import org.genesys2.server.filerepository.model.RepositoryImageData;
import org.genesys2.server.filerepository.service.ImageGalleryService;
import org.genesys2.server.filerepository.service.RepositoryService;
import org.genesys.filerepository.InvalidRepositoryFileDataException;
import org.genesys.filerepository.InvalidRepositoryPathException;
import org.genesys.filerepository.NoSuchRepositoryFileException;
import org.genesys.filerepository.model.ImageGallery;
import org.genesys.filerepository.model.RepositoryFile;
import org.genesys.filerepository.model.RepositoryImage;
import org.genesys.filerepository.service.ImageGalleryService;
import org.genesys.filerepository.service.RepositoryService;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.service.InstituteFilesService;
......@@ -61,11 +60,11 @@ public class InstituteFilesServiceImpl implements InstituteFilesService {
private ImageGalleryService imageGalleryService;
private static final String getGalleriesPrefix(final FaoInstitute institute) {
return REPOSITORY_GALLERIES_PREFIX + institute.getCode() + "/acn/";
return REPOSITORY_GALLERIES_PREFIX + institute.getCode() + "/acn";
}
private static final String getGalleryPath(final FaoInstitute institute, final Accession accession) {
return getGalleriesPrefix(institute) + accession.getAccessionName() + "/";
return getGalleriesPrefix(institute) + "/" + accession.getAccessionName();
}
@Override
......@@ -103,7 +102,7 @@ public class InstituteFilesServiceImpl implements InstituteFilesService {
@Override
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#institute, 'WRITE') or hasPermission(#institute, 'CREATE')")
public RepositoryImage updateImageMetadata(final FaoInstitute institute, Accession accession, final UUID uuid, final RepositoryImageData imageData) throws NoSuchRepositoryFileException {
public RepositoryImage updateImageMetadata(final FaoInstitute institute, Accession accession, final UUID uuid, final RepositoryImage imageData) throws NoSuchRepositoryFileException {
final RepositoryFile repositoryFile = this.repositoryService.getFile(uuid);
if (!repositoryFile.getPath().equals(getGalleryPath(institute, accession))) {
LOG.warn(repositoryFile.getPath() + "!=" + getGalleryPath(institute, accession));
......@@ -114,8 +113,8 @@ public class InstituteFilesServiceImpl implements InstituteFilesService {
@Override
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#institute, 'WRITE') or hasPermission(#institute, 'CREATE')")
public byte[] getFileBytes(final FaoInstitute institute, final Accession accession, final RepositoryImage repositoryImage) throws NoSuchRepositoryFileException {
return this.repositoryService.getFileBytes(getGalleryPath(institute, accession), repositoryImage.getFilename());
public byte[] getFileBytes(final FaoInstitute institute, final Accession accession, final RepositoryImage repositoryImage) throws NoSuchRepositoryFileException, IOException {
return this.repositoryService.getFileBytes(repositoryImage);
}
@Override
......
......@@ -25,8 +25,8 @@ import java.util.UUID;
import javax.servlet.http.HttpServletResponse;
import org.genesys2.server.filerepository.model.ImageGallery;
import org.genesys2.server.filerepository.service.ImageGalleryService;
import org.genesys.filerepository.model.ImageGallery;
import org.genesys.filerepository.service.ImageGalleryService;
import org.genesys2.server.model.dataset.DS;
import org.genesys2.server.model.elastic.AccessionDetails;
import org.genesys2.server.model.genesys.Accession;
......
/**
* Copyright 2016 Global Crop Diversity Trust
/*
* Copyright 2017 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -22,13 +22,14 @@ import java.util.UUID;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.velocity.exception.ResourceNotFoundException;
import org.genesys2.server.filerepository.NoSuchRepositoryFileException;
import org.genesys2.server.filerepository.model.RepositoryFile;
import org.genesys2.server.filerepository.service.BytesStorageService;
import org.genesys2.server.filerepository.service.RepositoryService;
import org.genesys.filerepository.NoSuchRepositoryFileException;
import org.genesys.filerepository.model.RepositoryFile;
import org.genesys.filerepository.service.BytesStorageService;
import org.genesys.filerepository.service.ImageGalleryService;
import org.genesys.filerepository.service.RepositoryService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
......@@ -41,7 +42,7 @@ import org.springframework.web.servlet.HandlerMapping;
@Controller
public class RepositoryDownloadController extends BaseController {
public static final Log LOG = LogFactory.getLog(RepositoryDownloadController.class);
public static final Logger LOG = LoggerFactory.getLogger(RepositoryDownloadController.class);
@Autowired
private RepositoryService repositoryService;
......@@ -52,7 +53,7 @@ public class RepositoryDownloadController extends BaseController {
private void downloadFile(final String path, final String uuid, final String ext, final HttpServletResponse response) throws IOException {
byte[] data;
if (path.endsWith("_thumb/") && ext.equals(".png")) {
if (path.startsWith(ImageGalleryService.THUMB_PATH) && ext.equals(ImageGalleryService.THUMB_EXT)) {
final String filename = uuid + ext;
if (LOG.isDebugEnabled()) {
LOG.debug("_thumb path=" + path + " filename=" + filename);
......@@ -68,7 +69,7 @@ public class RepositoryDownloadController extends BaseController {
sanityCheck(path, ext, repositoryFile);
data = this.repositoryService.getFileBytes(repositoryFile.getPath(), repositoryFile.getFilename());
data = this.repositoryService.getFileBytes(repositoryFile.getStoragePath(), repositoryFile.getFilename());
response.setHeader(HttpHeaders.CACHE_CONTROL, "max-age=3600, s-maxage=3600, public, no-transform");
response.setHeader(HttpHeaders.PRAGMA, "");
......@@ -78,10 +79,10 @@ public class RepositoryDownloadController extends BaseController {
} catch (final NumberFormatException e) {
LOG.warn("404 - UUID in wrong format.");
throw new ResourceNotFoundException("No such thing");
throw new ResourceNotFoundException("No such thing", e);
} catch (final NoSuchRepositoryFileException e) {
LOG.warn("404 - No such repository file ", e);
throw new ResourceNotFoundException("No such thing");
throw new ResourceNotFoundException("No such thing", e);
}
}
......@@ -97,8 +98,8 @@ public class RepositoryDownloadController extends BaseController {
throw new ResourceNotFoundException("No such thing");
}
if (!repositoryFile.getPath().equals(path) || !repositoryFile.getExtension().equals(ext)) {
LOG.warn(repositoryFile.getPath() + "!=" + path);
if (!repositoryFile.getStoragePath().equals(path) || !repositoryFile.getExtension().equals(ext)) {
LOG.warn(repositoryFile.getStoragePath() + "!=" + path);
LOG.warn(repositoryFile.getExtension() + "!=" + ext);
throw new ResourceNotFoundException("No such thing");
}
......@@ -116,7 +117,7 @@ public class RepositoryDownloadController extends BaseController {
final String ext = fullpath.substring(fullpath.lastIndexOf("."));
final String uuid = fullpath.substring(fullpath.lastIndexOf("/") + 1, fullpath.lastIndexOf("."));
final String path = fullpath.substring("/repository/d".length(), fullpath.lastIndexOf("/") + 1);
final String path = fullpath.substring("/repository/d".length(), fullpath.lastIndexOf("/"));
if (LOG.isDebugEnabled()) {
LOG.debug(path + " " + uuid + ext);
......@@ -132,9 +133,7 @@ public class RepositoryDownloadController extends BaseController {
public @ResponseBody RepositoryFile getMetadata(final HttpServletRequest request) throws IOException, NoSuchRepositoryFileException {
final String fullpath = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
if (LOG.isTraceEnabled()) {
LOG.trace("Fullname: " + fullpath);
}
LOG.debug("Fullname: {}", fullpath);
String path;
String uuid;
......@@ -142,7 +141,7 @@ public class RepositoryDownloadController extends BaseController {
try {
ext = fullpath.substring(fullpath.lastIndexOf("."));
uuid = fullpath.substring(fullpath.lastIndexOf("/") + 1, fullpath.lastIndexOf("."));
path = fullpath.substring("/repository/d".length(), fullpath.lastIndexOf("/") + 1);
path = fullpath.substring("/repository/d".length(), fullpath.lastIndexOf("/"));
if (LOG.isDebugEnabled()) {
LOG.debug(path + " " + uuid + ext);
}
......
......@@ -27,13 +27,12 @@ import javax.servlet.http.HttpServletRequest;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.genesys2.server.filerepository.InvalidRepositoryFileDataException;
import org.genesys2.server.filerepository.InvalidRepositoryPathException;
import org.genesys2.server.filerepository.NoSuchRepositoryFileException;
import org.genesys2.server.filerepository.model.RepositoryFile;
import org.genesys2.server.filerepository.model.RepositoryFileData;
import org.genesys2.server.filerepository.service.ImageGalleryService;
import org.genesys2.server.filerepository.service.RepositoryService;
import org.genesys.filerepository.InvalidRepositoryFileDataException;
import org.genesys.filerepository.InvalidRepositoryPathException;
import org.genesys.filerepository.NoSuchRepositoryFileException;
import org.genesys.filerepository.model.RepositoryFile;
import org.genesys.filerepository.service.ImageGalleryService;
import org.genesys.filerepository.service.RepositoryService;
import org.genesys2.server.servlet.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
......@@ -67,7 +66,7 @@ public class RepositoryController extends BaseController {
private ImageGalleryService imageGalleryService;
@RequestMapping(value = "/files/**", method = RequestMethod.GET)
public String listAllFiles(HttpServletRequest request, ModelMap model) throws UnsupportedEncodingException {
public String listAllFiles(HttpServletRequest request, ModelMap model) throws UnsupportedEncodingException, InvalidRepositoryPathException {
String fullpath = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
fullpath = fullpath.substring(CONTROLLER_PATH.length() + "/files".length());
......@@ -78,7 +77,7 @@ public class RepositoryController extends BaseController {
}
@RequestMapping(value = "/files", method = RequestMethod.GET)
public String listAllFiles(@RequestParam(defaultValue = "/") String repositoryPath, ModelMap model) {
public String listAllFiles(@RequestParam(defaultValue = "/") String repositoryPath, ModelMap model) throws InvalidRepositoryPathException {
if (LOG.isDebugEnabled()) {
LOG.debug("Listing files for path=" + repositoryPath);
}
......@@ -124,7 +123,7 @@ public class RepositoryController extends BaseController {
}
@RequestMapping(value = "/update", method = RequestMethod.POST)
public String updateMetadata(@ModelAttribute RepositoryFileData fileData, @RequestParam String uuid, RedirectAttributes redirectAttributes)
public String updateMetadata(@ModelAttribute RepositoryFile fileData, @RequestParam String uuid, RedirectAttributes redirectAttributes)
throws NoSuchRepositoryFileException {
RepositoryFile updatedFile = repositoryService.getFile(UUID.fromString(uuid));
......
......@@ -20,9 +20,10 @@ import javax.servlet.http.HttpServletRequest;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.genesys2.server.filerepository.NoSuchRepositoryFileException;
import org.genesys2.server.filerepository.model.ImageGallery;
import org.genesys2.server.filerepository.service.ImageGalleryService;
import org.genesys.filerepository.InvalidRepositoryPathException;
import org.genesys.filerepository.NoSuchRepositoryFileException;
import org.genesys.filerepository.model.ImageGallery;
import org.genesys.filerepository.service.ImageGalleryService;
import org.genesys2.server.servlet.controller.BaseController;
import org.genesys2.spring.ResourceNotFoundException;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -109,7 +110,7 @@ public class RepositoryGalleryController extends BaseController {
}
@RequestMapping(value = "/delete", method = RequestMethod.POST)
public String deleteFile(@RequestParam String galleryPath, RedirectAttributes redirectAttributes) {
public String deleteFile(@RequestParam String galleryPath, RedirectAttributes redirectAttributes) throws InvalidRepositoryPathException {
ImageGallery imageGallery = imageGalleryService.loadImageGallery(galleryPath);
imageGalleryService.removeGallery(imageGallery);
......
......@@ -26,12 +26,11 @@ import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.genesys2.server.filerepository.InvalidRepositoryFileDataException;
import org.genesys2.server.filerepository.InvalidRepositoryPathException;
import org.genesys2.server.filerepository.NoSuchRepositoryFileException;
import org.genesys2.server.filerepository.model.ImageGallery;
import org.genesys2.server.filerepository.model.RepositoryImage;
import org.genesys2.server.filerepository.model.RepositoryImageData;
import org.genesys.filerepository.InvalidRepositoryFileDataException;
import org.genesys.filerepository.InvalidRepositoryPathException;
import org.genesys.filerepository.NoSuchRepositoryFileException;
import org.genesys.filerepository.model.ImageGallery;
import org.genesys.filerepository.model.RepositoryImage;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.service.GenesysService;
......@@ -131,7 +130,7 @@ public class InstituteGalleriesController extends RestController {
*/
@RequestMapping(value = "/{instCode}/acn/{acceNumb:.+}/{uuid}/_metadata", method = { RequestMethod.PUT }, produces = { MediaType.APPLICATION_JSON_VALUE })
public @ResponseBody RepositoryImage updateImageMetadata(final HttpServletRequest request, final HttpServletResponse response, @PathVariable("instCode") final String instCode,
@PathVariable("acceNumb") final String acceNumb, @PathVariable("uuid") final UUID uuid, @RequestBody final RepositoryImageData imageData)
@PathVariable("acceNumb") final String acceNumb, @PathVariable("uuid") final UUID uuid, @RequestBody final RepositoryImage imageData)
throws IOException, NonUniqueAccessionException {
final FaoInstitute institute = this.instituteService.findInstitute(instCode);
......
/**
* Copyright 2016 Global Crop Diversity Trust
/*
* Copyright 2017 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -17,12 +17,41 @@
package org.genesys2.spring.config;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.genesys2.server.filerepository.service.BytesStorageService;
import org.genesys2.server.filerepository.service.aspect.ImageGalleryAspects;
import org.genesys2.server.filerepository.service.impl.FilesystemStorageServiceImpl;
import org.genesys2.server.filerepository.service.impl.S3StorageServiceImpl;
import org.apache.ftpserver.ftplet.Authentication;
import org.apache.ftpserver.ftplet.AuthenticationFailedException;
import org.apache.ftpserver.ftplet.Authority;
import org.apache.ftpserver.ftplet.FtpException;
import org.apache.ftpserver.ftplet.User;
import org.apache.ftpserver.ftplet.UserManager;
import org.apache.ftpserver.usermanager.AnonymousAuthentication;
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.lockout.AccountLockoutManager;
import org.genesys.filerepository.service.BytesStorageService;
import org.genesys.filerepository.service.ImageGalleryService;
import org.genesys.filerepository.service.RepositoryService;
import org.genesys.filerepository.service.ThumbnailGenerator;
import org.genesys.filerepository.service.aspect.ImageGalleryAspects;
import org.genesys.filerepository.service.ftp.FtpUser;
import org.genesys.filerepository.service.ftp.RepositoryFileSystemFactory;
import org.genesys.filerepository.service.ftp.RepositoryFtpServer;
import org.genesys.filerepository.service.ftp.TemporaryBytesManager;
import org.genesys.filerepository.service.impl.FilesystemStorageServiceImpl;
import org.genesys.filerepository.service.impl.ImageGalleryServiceImpl;
import org.genesys.filerepository.service.impl.RepositoryServiceImpl;
import org.genesys.filerepository.service.impl.S3StorageServiceImpl;
import org.genesys.filerepository.service.impl.ThumbnailGenerator1;
import org.genesys2.server.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
......@@ -33,7 +62,10 @@ import org.springframework.web.multipart.commons.CommonsMultipartResolver;
* Instatiates and configures the storage mechanism for the FileRepository.
*/
@Configuration
public class FileRepositoryConfig {
public class FileRepositoryConfig implements InitializingBean {
private static final String DEFAULT_REPOSITORY_KEYSTORE_RESOURCE = "/repository/ftpserver.jks";
private static final String DEFAULT_REPOSITORY_KEYSTORE_PASSWORD = "changeit!";
@Value("${file.repository.dir}")
private String fileRepositoryDir;
......@@ -41,6 +73,31 @@ public class FileRepositoryConfig {
@Value("${s3.accessKey}")
private String s3AccessKey;
@Value("${repository.ftp.keystore.path}")
private String ftpKeystorePath;
@Value("${repository.ftp.keystore.password}")
private String ftpKeystorePwd;
@Value("${repository.ftp.port}")
private int ftpServerPort;
@Value("${repository.ftp.passivePorts}")
private String ftpServerPassivePorts;
@Value("${repository.ftp.externalAddress}")
private String ftpServerExternalAddress;
/**
* File repository service.
*
* @return the repository service
*/
@Bean
public RepositoryService fileRepositoryService() {
return new RepositoryServiceImpl();
}
@Bean(name = "fileSystemStorage")
@Primary
public BytesStorageService bytesStorageService() {
......@@ -74,8 +131,27 @@ public class FileRepositoryConfig {
}
/**
* Register ImageGallery aspects for automatic registration of new images in
* galleries
* ImageGallery service.
*
* @return the thing!
*/
@Bean
public ImageGalleryService imageGalleryService() {
return new ImageGalleryServiceImpl();
}
/**
* One Thumbnail generator.
*
* @return the thumbnail generator
*/
@Bean
public ThumbnailGenerator thumbnailGenerator() {
return new ThumbnailGenerator1();
}
/**
* Register ImageGallery aspects!.
*
* @return the image gallery aspects
*/
......@@ -84,4 +160,130 @@ public class FileRepositoryConfig {
return new ImageGalleryAspects();
}
@Bean
public TemporaryBytesManager temporaryBytesManager() {
return new TemporaryBytesManager();
}
@Bean
public RepositoryFileSystemFactory repositoryFileSystemFactory() {
return new RepositoryFileSystemFactory();
}
@Bean
public RepositoryFtpServer ftpServer() {
RepositoryFtpServer ftpServer = new RepositoryFtpServer();
ftpServer.setFtpPort(ftpServerPort);
ftpServer.setUserManager(ftpUserManager());
ftpServer.setKeystorePath(ftpKeystorePath);
ftpServer.setKeystorePsw(ftpKeystorePwd);
ftpServer.setExternalAddress(ftpServerExternalAddress);
ftpServer.setPassivePorts(ftpServerPassivePorts);
return ftpServer;
}
@Bean
public UserManager ftpUserManager() {
return new AbstractUserManager() {
@Autowired
private AccountLockoutManager lockoutManager;
private final Logger LOG = LoggerFactory.getLogger(this.getClass());
@Autowired
private UserService userService;
@Override
public void save(User user) throws FtpException {
// Noop
}
@Override
public User getUserByName(String username) throws FtpException {
FtpUser user = new FtpUser(username);
// user.setPassword(username + "1!");
user.setEnabled(true);
List<Authority> authorities = new ArrayList<>();
authorities.add(new ConcurrentLoginPermission(10, 0));
authorities.add(new WritePermission());
user.setAuthorities(authorities);
user.setHomeDirectory("/");
return user;
}
@Override
public String[] getAllUserNames() throws FtpException {
return new String[] {};
}
@Override
public boolean doesExist(String username) throws FtpException {
return userService.getUserByEmail(username) != null;
}
@Override
public void delete(String username) throws FtpException {
// Noop
}
@Override
public User authenticate(Authentication authentication) throws AuthenticationFailedException {
if (authentication instanceof UsernamePasswordAuthentication) {
UsernamePasswordAuthentication upauth = (UsernamePasswordAuthentication) authentication;
String username = upauth.getUsername();
String password = upauth.getPassword();
org.genesys2.server.model.impl.User user = userService.getUserByEmail(upauth.getUsername());