Commit 7f295600 authored by Matija Obreza's avatar Matija Obreza
Browse files

Renamed classes in org.genesys2.spring.config

parent de2322f5
/**
* Copyright 2014 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.
* 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.genesys2.spring.config;
......@@ -39,8 +39,8 @@ import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;
@Configuration
@Import({ SpringCommonConfig.class, SpringSchedulerConfig.class, SpringDataBaseConfig.class,
SpringMailConfig.class, OAuth2ServerConfig.class, SecurityConfig.class, SpringCacheConfig.class, ElasticsearchConfig.class, FileRepositoryConfig.class, WebConfiguration.class })
@Import({ CommonConfig.class, SchedulerConfig.class, DatabaseConfig.class, MailConfig.class, OAuth2ServerConfig.class, SecurityConfig.class, CacheConfig.class,
ElasticsearchConfig.class, FileRepositoryConfig.class, WebConfiguration.class })
public class ApplicationConfig {
public static final Log LOG = LogFactory.getLog(ApplicationConfig.class);
......@@ -53,7 +53,6 @@ public class ApplicationConfig {
public BrAPIService brapiService() {
return new BrAPIServiceImpl();
}
@Bean
public static PropertyPlaceholderConfigurer propertyPlaceholderConfigurer() {
......@@ -80,7 +79,6 @@ public class ApplicationConfig {
propertyPlaceholderConfigurer.setLocations(locations.toArray(new Resource[] {}));
return propertyPlaceholderConfigurer;
}
@Bean
public ResourceBundleMessageSource messageSource() {
......@@ -90,14 +88,13 @@ public class ApplicationConfig {
source.setUseCodeAsDefaultMessage(true);
return source;
}
/**
* localeURLFilter in web.xml: en es de fr fa ar ru zh pt
*/
@Bean
public static Set<String> supportedLocales() {
final Set<String> supportedLocales = new HashSet<String>();
final Set<String> supportedLocales = new HashSet<>();
supportedLocales.add("en");
supportedLocales.add("es");
supportedLocales.add("de");
......
/**
* Copyright 2014 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.
* 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.genesys2.spring.config;
......@@ -38,7 +38,7 @@ import org.springframework.security.core.session.SessionRegistryImpl;
@Configuration
@EnableCaching
@Import({ HazelcastConfig.class })
public class SpringCacheConfig {
public class CacheConfig {
@Value("${hazelcast.instanceName}")
protected String instanceName = "genesys";
......@@ -52,36 +52,36 @@ public class SpringCacheConfig {
private String cookieHttpOnly;
@Bean
public HazelcastCacheManager cacheManager(HazelcastInstance hazelcastInstance) {
HazelcastCacheManager cm = new HazelcastCacheManager(hazelcastInstance);
public HazelcastCacheManager cacheManager(final HazelcastInstance hazelcastInstance) {
final HazelcastCacheManager cm = new HazelcastCacheManager(hazelcastInstance);
return cm;
}
@Bean
public IMap<Object, Object> tileserverMap(HazelcastInstance hazelcast) {
IMap<Object, Object> x = hazelcast.getMap("tileserver");
public IMap<Object, Object> tileserverMap(final HazelcastInstance hazelcast) {
final IMap<Object, Object> x = hazelcast.getMap("tileserver");
return x;
}
@Bean
public IQueue<Object> elasticRemoveQueue(HazelcastInstance hazelcast) {
public IQueue<Object> elasticRemoveQueue(final HazelcastInstance hazelcast) {
return hazelcast.getQueue("es-remove");
}
@Bean
public IQueue<Object> elasticUpdateQueue(HazelcastInstance hazelcast) {
public IQueue<Object> elasticUpdateQueue(final HazelcastInstance hazelcast) {
return hazelcast.getQueue("es-update");
}
@Bean
public IExecutorService distributedExecutor(HazelcastInstance hazelcast) {
IExecutorService executorService = hazelcast.getExecutorService("hazel-exec");
public IExecutorService distributedExecutor(final HazelcastInstance hazelcast) {
final IExecutorService executorService = hazelcast.getExecutorService("hazel-exec");
return executorService;
}
@Bean
public IMap<String, AttemptStatistics> accountLockoutMap(HazelcastInstance hazelcast) {
IMap<String, AttemptStatistics> x = hazelcast.getMap("accountLocks");
public IMap<String, AttemptStatistics> accountLockoutMap(final HazelcastInstance hazelcast) {
final IMap<String, AttemptStatistics> x = hazelcast.getMap("accountLocks");
return x;
}
......@@ -89,7 +89,7 @@ public class SpringCacheConfig {
public WebFilter hazelcastWebFilter() {
return new SpringAwareWebFilter(filterProps());
}
@Bean
public SessionRegistry SessionRegistry() {
return new SessionRegistryImpl();
......
/**
* Copyright 2014 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.
......@@ -18,6 +18,9 @@ package org.genesys2.spring.config;
import javax.persistence.Entity;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.SerializationFeature;
import org.genesys2.spring.validation.oval.spring.SpringOvalValidator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
......@@ -32,15 +35,11 @@ import org.springframework.security.web.access.expression.DefaultWebSecurityExpr
import org.springframework.stereotype.Controller;
import org.springframework.validation.Validator;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.SerializationFeature;
@EnableAspectJAutoProxy
@ComponentScan(basePackages = { "org.genesys2.spring", "org.genesys2.server" }, excludeFilters = {
@ComponentScan.Filter(value = Controller.class, type = FilterType.ANNOTATION),
@ComponentScan(basePackages = { "org.genesys2.spring", "org.genesys2.server" }, excludeFilters = { @ComponentScan.Filter(value = Controller.class, type = FilterType.ANNOTATION),
@ComponentScan.Filter(value = Configuration.class, type = FilterType.ANNOTATION) }, includeFilters = @ComponentScan.Filter(value = Entity.class, type = FilterType.ANNOTATION))
@Configuration
public class SpringCommonConfig {
public class CommonConfig {
@Autowired
private AclPermissionEvaluator aclPermissionEvaluator;
......
/**
* Copyright 2014 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.
* 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.genesys2.spring.config;
......@@ -43,7 +43,7 @@ import liquibase.integration.spring.SpringLiquibase;
@EnableJpaAuditing(auditorAwareRef = "auditorAware")
@EnableTransactionManagement
@Configuration
public class SpringDataBaseConfig {
public class DatabaseConfig {
@Value("${db.url}")
private String dbUrl;
......@@ -80,7 +80,7 @@ public class SpringDataBaseConfig {
private int maxActive;
// max allowed age for any connection
private long maxAgeSeconds = 60 * 5;
private final long maxAgeSeconds = 60 * 5;
@Value("${db.pool.maxIdleSeconds}")
private int maxIdleSeconds;
......@@ -108,13 +108,13 @@ public class SpringDataBaseConfig {
}
@Bean
public JdbcTemplate jdbcTemplate(DataSource dataSource) {
public JdbcTemplate jdbcTemplate(final DataSource dataSource) {
return new JdbcTemplate(dataSource);
}
@Bean(name = "databaseMigration")
public SpringLiquibase databaseMigration() {
SpringLiquibase liquibase = new SpringLiquibase();
final SpringLiquibase liquibase = new SpringLiquibase();
// Run controlled database migration only when not generating schema
// automatically
liquibase.setShouldRun(!dbGenerateDdl);
......@@ -125,14 +125,14 @@ public class SpringDataBaseConfig {
@Bean(name = "entityManagerFactory")
@DependsOn("databaseMigration")
public LocalContainerEntityManagerFactoryBean entityManagerFactory(HazelcastCacheRegionFactoryWrapper wrp) throws Exception {
public LocalContainerEntityManagerFactoryBean entityManagerFactory(final HazelcastCacheRegionFactoryWrapper wrp) throws Exception {
final LocalContainerEntityManagerFactoryBean entityManager = new LocalContainerEntityManagerFactoryBean();
entityManager.setDataSource(dataSource());
entityManager.setPersistenceUnitName("spring-jpa");
entityManager.setJpaVendorAdapter(jpaVendorAdapter());
entityManager.setPersistenceProvider(new HibernatePersistenceProvider());
Properties jpaProperties = jpaProperties();
for (Object key : jpaProperties.keySet()) {
final Properties jpaProperties = jpaProperties();
for (final Object key : jpaProperties.keySet()) {
System.err.println("JPA: " + key + " = " + jpaProperties.get(key));
}
entityManager.setJpaProperties(jpaProperties);
......@@ -143,7 +143,7 @@ public class SpringDataBaseConfig {
}
@Bean
public JpaTransactionManager transactionManager(DataSource dataSource, EntityManagerFactory emf) {
public JpaTransactionManager transactionManager(final DataSource dataSource, final EntityManagerFactory emf) {
final JpaTransactionManager transactionManager = new JpaTransactionManager();
transactionManager.setDataSource(dataSource);
transactionManager.setEntityManagerFactory(emf);
......@@ -151,7 +151,7 @@ public class SpringDataBaseConfig {
}
private Properties jpaProperties() throws Exception {
Properties jpaProp = new Properties();
final Properties jpaProp = new Properties();
jpaProp.load(getClass().getResourceAsStream("/hibernate.properties"));
jpaProp.put("hibernate.dialect", hibernateDialect);
return jpaProp;
......
/**
* Copyright 2014 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.
* 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.genesys2.spring.config;
......@@ -37,8 +37,8 @@ import org.springframework.data.elasticsearch.repository.config.EnableElasticsea
public class ElasticsearchConfig {
@Bean
public ElasticsearchTemplate elasticsearchTemplate(Client client, EntityMapper entityMapper) {
ElasticsearchTemplate t = new ElasticsearchTemplate(client, entityMapper);
public ElasticsearchTemplate elasticsearchTemplate(final Client client, final EntityMapper entityMapper) {
final ElasticsearchTemplate t = new ElasticsearchTemplate(client, entityMapper);
return t;
}
......@@ -49,7 +49,7 @@ public class ElasticsearchConfig {
public class GenesysEntityMapper implements EntityMapper {
private ObjectMapper objectMapper;
private final ObjectMapper objectMapper;
public GenesysEntityMapper() {
objectMapper = new ObjectMapper();
......@@ -60,12 +60,12 @@ public class ElasticsearchConfig {
}
@Override
public String mapToString(Object object) throws IOException {
public String mapToString(final Object object) throws IOException {
return objectMapper.writeValueAsString(object);
}
@Override
public <T> T mapToObject(String source, Class<T> clazz) throws IOException {
public <T> T mapToObject(final String source, final Class<T> clazz) throws IOException {
return objectMapper.readValue(source, clazz);
}
}
......
/**
* Copyright 2014 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.
* 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.genesys2.spring.config;
......@@ -35,7 +35,7 @@ public class ElasticsearchConfigAWS {
@Bean
public TransportClientFactoryBean tcfb() {
System.out.println("Setting up external ES cluster.name=" + clusterName + " and nodes=" + clusterNodes);
TransportClientFactoryBean tcfb = new TransportClientFactoryBean();
final TransportClientFactoryBean tcfb = new TransportClientFactoryBean();
tcfb.setClusterName(clusterName);
tcfb.setClusterNodes(clusterNodes);
tcfb.setClientPingTimeout("10s");
......
/**
* Copyright 2014 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.
* 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.genesys2.spring.config;
import static org.elasticsearch.node.NodeBuilder.*;
import static org.elasticsearch.node.NodeBuilder.nodeBuilder;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.settings.ImmutableSettings;
......@@ -43,10 +43,8 @@ public class ElasticsearchConfigDev {
@Bean
public NodeClient nodeClient() {
ImmutableSettings.Builder settings = ImmutableSettings.settingsBuilder().put("http.enabled",
String.valueOf(this.enableHttp)).put("path.home", this.dataPath);
final ImmutableSettings.Builder settings = ImmutableSettings.settingsBuilder().put("http.enabled", String.valueOf(this.enableHttp)).put("path.home", this.dataPath);
return (NodeClient) nodeBuilder().settings(settings).clusterName(this.clusterName).local(true).node()
.client();
return (NodeClient) nodeBuilder().settings(settings).clusterName(this.clusterName).local(true).node().client();
}
}
......@@ -114,7 +114,7 @@ public class FileRepositoryConfig implements InitializingBean {
}
private BytesStorageService fileSystemStorage() {
FilesystemStorageServiceImpl storageService = new FilesystemStorageServiceImpl();
final FilesystemStorageServiceImpl storageService = new FilesystemStorageServiceImpl();
File repoDir;
if (StringUtils.isNotBlank(fileRepositoryDir)) {
......@@ -131,7 +131,7 @@ public class FileRepositoryConfig implements InitializingBean {
@Bean
public CommonsMultipartResolver multipartResolver() {
CommonsMultipartResolver resolver = new CommonsMultipartResolver();
final CommonsMultipartResolver resolver = new CommonsMultipartResolver();
resolver.setDefaultEncoding("utf-8");
return resolver;
}
......@@ -178,7 +178,7 @@ public class FileRepositoryConfig implements InitializingBean {
@Bean
public RepositoryFtpServer ftpServer() {
RepositoryFtpServer ftpServer = new RepositoryFtpServer();
final RepositoryFtpServer ftpServer = new RepositoryFtpServer();
ftpServer.setFtpPort(ftpServerPort);
ftpServer.setUserManager(ftpUserManager());
......@@ -202,16 +202,16 @@ public class FileRepositoryConfig implements InitializingBean {
private UserService userService;
@Override
public void save(User user) throws FtpException {
public void save(final User user) throws FtpException {
// Noop
}
@Override
public User getUserByName(String username) throws FtpException {
FtpUser user = new FtpUser(username);
public User getUserByName(final String username) throws FtpException {
final FtpUser user = new FtpUser(username);
// user.setPassword(username + "1!");
user.setEnabled(true);
List<Authority> authorities = new ArrayList<>();
final List<Authority> authorities = new ArrayList<>();
authorities.add(new ConcurrentLoginPermission(10, 0));
authorities.add(new WritePermission());
user.setAuthorities(authorities);
......@@ -225,26 +225,26 @@ public class FileRepositoryConfig implements InitializingBean {
}
@Override
public boolean doesExist(String username) throws FtpException {
public boolean doesExist(final String username) throws FtpException {
return userService.getUserByEmail(username) != null;
}
@Override
public void delete(String username) throws FtpException {
public void delete(final String username) throws FtpException {
// Noop
}
@Override
public User authenticate(Authentication authentication) throws AuthenticationFailedException {
public User authenticate(final Authentication authentication) throws AuthenticationFailedException {
if (authentication instanceof UsernamePasswordAuthentication) {
UsernamePasswordAuthentication upauth = (UsernamePasswordAuthentication) authentication;
final UsernamePasswordAuthentication upauth = (UsernamePasswordAuthentication) authentication;
String username = upauth.getUsername();
final String username = upauth.getUsername();
String password = upauth.getPassword();
org.genesys2.server.model.impl.User user = userService.getUserByEmail(upauth.getUsername());
final org.genesys2.server.model.impl.User user = userService.getUserByEmail(upauth.getUsername());
if (user == null || !user.isActive() || user.isAccountLocked() || user.isAccountExpired() || !user.isEnabled() || user.isPasswordExpired()) {
if ((user == null) || !user.isActive() || user.isAccountLocked() || user.isAccountExpired() || !user.isEnabled() || user.isPasswordExpired()) {
// user not found
throw new AuthenticationFailedException("Authentication failed");
}
......@@ -262,7 +262,7 @@ public class FileRepositoryConfig implements InitializingBean {
LOG.info("FTP login successful for {}", username);
try {
return getUserByName(username);
} catch (FtpException e) {
} catch (final FtpException e) {
LOG.warn("FTP login failed", e);
throw new AuthenticationFailedException(e.getMessage(), e);
}
......
/*
* 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.
......@@ -51,7 +51,7 @@ import org.springframework.context.annotation.Configuration;
@Configuration
@EnableCaching
public abstract class HazelcastConfig {
protected final Logger LOG = LoggerFactory.getLogger(HazelcastConfig.class);
/// Interfaces on which HZ should bind
......@@ -75,13 +75,13 @@ public abstract class HazelcastConfig {
@Value("${cache.defaultCacheSize}")
protected int defaultCacheSize;
@Value("${cache.time-to-live-seconds}")
private int cacheTimeToLiveSeconds;
@Value("${cache.max-idle-seconds}")
private int cacheMaxIdleSeconds;
@Value("${cache.eviction-policy}")
protected EvictionPolicy cacheEvictionPolicy;
......@@ -89,18 +89,17 @@ public abstract class HazelcastConfig {
public ManagedContext managedContext() {
return new SpringManagedContext();
}
@Value("${hazelcast.members}")
private List<String> hazelcastMembers;
@Bean
public HazelcastInstance hazelcast(ManagedContext managedContext) {
Config cfg = new Config();
public HazelcastInstance hazelcast(final ManagedContext managedContext) {
final Config cfg = new Config();
cfg.setManagedContext(managedContext);
cfg.setInstanceName(instanceName);
GroupConfig groupConfig = cfg.getGroupConfig();
final GroupConfig groupConfig = cfg.getGroupConfig();
groupConfig.setName(name);
groupConfig.setPassword(password);
......@@ -109,32 +108,32 @@ public abstract class HazelcastConfig {
cfg.setProperty("hazelcast.logging.type", "log4j");
cfg.setProperty("hazelcast.icmp.enabled", "true");
NetworkConfig network = cfg.getNetworkConfig();
final NetworkConfig network = cfg.getNetworkConfig();
network.setPort(hazelPort);
network.setPortAutoIncrement(true);
if (StringUtils.isNotBlank(hazelPublicAddress)) {