Commit f47fb68b authored by Matija Obreza's avatar Matija Obreza
Browse files

Application configuration updated with FileRepositoryConfig

- file.repository.dir defaults to **data/file_repository** (for FileSystemBytesStorage)
- Moved passwordEncoder to SecurityConfig
parent 42c9a0be
......@@ -14,7 +14,11 @@
# limitations under the License.
#-------------------------------------------------------------------------------
file.repository.path=/file_repository
# Directory for FileSystemStorageService
file.repository.dir=data/file_repository
# Path to dataset files within the repository
file.repository.datasets.folder=/dataset
#AWS parameter values
s3.accessKey=
s3.secretKey=
......
......@@ -39,7 +39,10 @@ db.updateSchema=true
# Default partner UUID
partner.primary.uuid=a870b3b2-1dfc-459f-abc8-8c10ca8aaab4
file.repository.path=/file_repository
# Directory for FileSystemStorageService
file.repository.dir=data/file_repository
# Path to dataset files within the repository
file.repository.datasets.folder=/dataset
#AWS parameter values
s3.accessKey=
......
......@@ -20,38 +20,25 @@ import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.genesys.blocks.util.CurrentApplicationContext;
import org.genesys.filerepository.service.BytesStorageService;
import org.genesys.filerepository.service.VirusScanner;
import org.genesys.filerepository.service.impl.ClamAVScanner;
import org.genesys.filerepository.service.impl.FilesystemStorageServiceImpl;
import org.genesys.filerepository.service.impl.S3StorageServiceImpl;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.context.annotation.Import;
import org.springframework.core.annotation.Order;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
@Configuration
@ComponentScan({ "org.genesys.filerepository.service", "org.genesys.catalog.service.impl", "org.genesys.catalog.util", "org.genesys.blocks.security.service.*",
@Import({ FileRepositoryConfig.class })
@ComponentScan({ "org.genesys.catalog.service.impl", "org.genesys.catalog.util", "org.genesys.blocks.security.service.*",
"org.genesys.blocks.auditlog.service.impl", "org.genesys.blocks.security.component" })
@EnableAspectJAutoProxy
public class ApplicationConfig {
@Value("${CLAMD_HOSTNAME}")
private String clamdHost;
@Value("${CLAMD_PORT}")
private String clamdPortStr;
@Bean
public static PropertyPlaceholderConfigurer propertyPlaceholderConfigurer() {
final PropertyPlaceholderConfigurer propertyPlaceholderConfigurer = new PropertyPlaceholderConfigurer();
......@@ -80,44 +67,10 @@ public class ApplicationConfig {
return propertyPlaceholderConfigurer;
}
@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
@Bean
@Order(Integer.MIN_VALUE)
public CurrentApplicationContext currentApplicationContext() {
// This provides static access to current application context
return new CurrentApplicationContext();
}
@Bean
public VirusScanner virusScanner() {
if (StringUtils.isNotBlank(clamdHost)) {
System.err.println("Using clamd at " + clamdHost);
final ClamAVScanner clamav = new ClamAVScanner();
clamav.setClamAvHost(clamdHost);
clamav.setClamAvPort(NumberUtils.toInt(clamdPortStr, 3310));
return clamav;
} else {
System.err.println("clamd host not configured.");
return null;
}
}
@Bean(name = "bytesStorageService")
public BytesStorageService bytesStorageService() {
final File repoDir = new File("data");
final FilesystemStorageServiceImpl storageService = new FilesystemStorageServiceImpl();
storageService.setRepositoryBaseDirectory(repoDir);
return storageService;
}
@Bean(name = "S3Storage")
public BytesStorageService S3StorageService() {
return new S3StorageServiceImpl();
}
}
/*
* 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
package org.genesys.catalog.server.config;
import java.io.File;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
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.VirusScanner;
import org.genesys.filerepository.service.aspect.MetadataInStorageAspect;
import org.genesys.filerepository.service.impl.ClamAVScanner;
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.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
/**
* Instantiates and configures the storage mechanism for the FileRepository.
*/
@Configuration
public class FileRepositoryConfig implements InitializingBean {
public static final Logger LOG = LoggerFactory.getLogger(ApplicationConfig.class);
@Value("${CLAMD_HOSTNAME}")
private String clamdHost;
@Value("${CLAMD_PORT}")
private String clamdPortStr;
@Value("${file.repository.dir}")
private String fileRepositoryDir;
@Value("${s3.accessKey}")
private String s3AccessKey;
@Override
public void afterPropertiesSet() throws Exception {
}
/**
* File repository service.
*
* @return the repository service
*/
@Bean
public RepositoryService fileRepositoryService() {
return new RepositoryServiceImpl();
}
@Bean(name = "fileSystemStorage")
@Primary
public BytesStorageService bytesStorageService() {
if (StringUtils.isNotBlank(s3AccessKey)) {
// We have some S3 configuration, let's do that!
LOG.warn("Initializing S3 bytes storage with {}", s3AccessKey);
return new S3StorageServiceImpl();
} else {
// Stick to FS storage
return fileSystemStorage();
}
}
private BytesStorageService fileSystemStorage() {
final FilesystemStorageServiceImpl storageService = new FilesystemStorageServiceImpl();
File repoDir;
if (StringUtils.isNotBlank(fileRepositoryDir)) {
repoDir = new File(fileRepositoryDir);
} else {
repoDir = new File(FileUtils.getTempDirectory(), "repository");
}
LOG.warn("Initializing filesystem bytes storage at base path={}", repoDir.getAbsolutePath());
storageService.setRepositoryBaseDirectory(repoDir);
return storageService;
}
/**
* 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();
}
/**
* Maintain metadata in .json in storage
*
* @return
*/
@Bean
public MetadataInStorageAspect repositoryMetadataAspects() {
return new MetadataInStorageAspect();
}
/**
* Enable virus scanner if configured
*
* @return
*/
@Bean
public VirusScanner virusScanner() {
if (StringUtils.isNotBlank(clamdHost)) {
System.err.println("Using clamd at " + clamdHost);
final ClamAVScanner clamav = new ClamAVScanner();
clamav.setClamAvHost(clamdHost);
clamav.setClamAvPort(NumberUtils.toInt(clamdPortStr, 3310));
return clamav;
} else {
System.err.println("clamd host not configured.");
return null;
}
}
}
......@@ -25,6 +25,7 @@ import org.springframework.security.config.annotation.method.configuration.Enabl
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
......@@ -36,9 +37,11 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private UserService userDetailsService;
@Autowired
private PasswordEncoder passwordEncoder;
@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
// @Bean
// public AuthenticationProvider runAsAuthenticationProvider() {
// RunAsImplAuthenticationProvider authProvider = new RunAsImplAuthenticationProvider();
......@@ -50,7 +53,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
protected void configure(final AuthenticationManagerBuilder auth) throws Exception {
auth
//.authenticationProvider(runAsAuthenticationProvider())
.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder);
.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder());
}
@Override
......
......@@ -47,8 +47,10 @@ build.name=${project.artifactId}-${buildNumber}
build.revision=${buildNumber}
#file repository
file.repository.path=/file_repository
# Directory for FileSystemStorageService
file.repository.dir=data/file_repository
# Path to dataset files within the repository
file.repository.datasets.folder=/dataset
#AWS parameter values
s3.accessKey=
......
......@@ -37,8 +37,10 @@ default.oauth.refreshToken.validity=604800
# MockMvc printing
spring.test.mockmvc.print=none
#file repository
file.repository.path=/file_repository
# Directory for FileSystemStorageService
file.repository.dir=data/file_repository
# Path to dataset files within the repository
file.repository.datasets.folder=/dataset
#AWS parameter values
s3.accessKey=
......
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