Commit 0b9757c6 authored by Matija Obreza's avatar Matija Obreza

Reorganized packages for better Spring auto-configuration

parent bdf9cd88
/*
* Copyright 2018 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.rest.model;
/**
* The Class PermissionJson.
*/
public class PermissionJson {
private Long sid;
private String authority;
private long oid;
private String clazz;
private boolean create;
private boolean read;
private boolean write;
private boolean delete;
private boolean manage;
@Override
public String toString() {
return "PJ oid=" + oid + " class=" + clazz + " (sid=" + sid + " OR authority=" + authority + ")";
}
/**
* Sets the sid.
*
* @param sid the new sid
*/
public void setSid(final Long sid) {
this.sid = sid;
}
/**
* Gets the sid.
*
* @return the sid
*/
public Long getSid() {
return sid;
}
/**
* Sets the authority.
*
* @param authority the new authority
*/
public void setAuthority(final String authority) {
this.authority = authority;
}
/**
* Gets the authority.
*
* @return the authority
*/
public String getAuthority() {
return authority;
}
/**
* Gets the oid.
*
* @return the oid
*/
public long getOid() {
return oid;
}
/**
* Sets the oid.
*
* @param oid the new oid
*/
public void setOid(final long oid) {
this.oid = oid;
}
/**
* Gets the clazz.
*
* @return the clazz
*/
public String getClazz() {
return clazz;
}
/**
* Sets the clazz.
*
* @param clazz the new clazz
*/
public void setClazz(final String clazz) {
this.clazz = clazz;
}
/**
* Checks if is creates the.
*
* @return true, if is creates the
*/
public boolean isCreate() {
return create;
}
/**
* Sets the creates the.
*
* @param create the new creates the
*/
public void setCreate(final boolean create) {
this.create = create;
}
/**
* Checks if is read.
*
* @return true, if is read
*/
public boolean isRead() {
return read;
}
/**
* Sets the read.
*
* @param read the new read
*/
public void setRead(final boolean read) {
this.read = read;
}
/**
* Checks if is write.
*
* @return true, if is write
*/
public boolean isWrite() {
return write;
}
/**
* Sets the write.
*
* @param write the new write
*/
public void setWrite(final boolean write) {
this.write = write;
}
/**
* Checks if is delete.
*
* @return true, if is delete
*/
public boolean isDelete() {
return delete;
}
/**
* Sets the delete.
*
* @param delete the new delete
*/
public void setDelete(final boolean delete) {
this.delete = delete;
}
/**
* Checks if is manage.
*
* @return true, if is manage
*/
public boolean isManage() {
return manage;
}
/**
* Sets the manage.
*
* @param manage the new manage
*/
public void setManage(final boolean manage) {
this.manage = manage;
}
}
......@@ -62,6 +62,8 @@ import org.genesys.filerepository.InvalidRepositoryPathException;
import org.genesys.filerepository.NoSuchRepositoryFileException;
import org.genesys.filerepository.model.RepositoryFile;
import org.genesys.filerepository.service.RepositoryService;
import org.genesys2.server.component.security.AsAdminInvoker;
import org.genesys2.server.component.security.SecurityUtils;
import org.genesys2.server.exception.InvalidApiUsageException;
import org.genesys2.server.exception.NotFoundElement;
import org.genesys2.server.model.PublishState;
......@@ -69,8 +71,6 @@ import org.genesys2.server.model.UserRole;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.genesys.AccessionRef;
import org.genesys2.server.persistence.AccessionRepository;
import org.genesys2.server.security.AsAdminInvoker;
import org.genesys2.server.security.SecurityUtils;
import org.genesys2.server.service.DownloadService;
import org.genesys2.util.JPAUtils;
import org.springframework.beans.factory.annotation.Autowired;
......
......@@ -35,11 +35,11 @@ import org.genesys.catalog.model.traits.DescriptorList;
import org.genesys.catalog.persistence.traits.DescriptorListRepository;
import org.genesys.catalog.service.DescriptorListService;
import org.genesys.catalog.service.DescriptorService;
import org.genesys2.server.component.security.SecurityUtils;
import org.genesys2.server.exception.InvalidApiUsageException;
import org.genesys2.server.exception.NotFoundElement;
import org.genesys2.server.model.PublishState;
import org.genesys2.server.model.UserRole;
import org.genesys2.server.security.SecurityUtils;
import org.genesys2.util.JPAUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......
......@@ -38,11 +38,11 @@ import org.genesys.catalog.persistence.traits.DescriptorRepository;
import org.genesys.catalog.persistence.vocab.VocabularyTermRepository;
import org.genesys.catalog.service.DescriptorService;
import org.genesys.catalog.service.VersionManager;
import org.genesys2.server.component.security.SecurityUtils;
import org.genesys2.server.exception.InvalidApiUsageException;
import org.genesys2.server.exception.NotFoundElement;
import org.genesys2.server.model.PublishState;
import org.genesys2.server.model.UserRole;
import org.genesys2.server.security.SecurityUtils;
import org.genesys2.server.service.DownloadService;
import org.genesys2.util.JPAUtils;
import org.slf4j.Logger;
......
......@@ -28,12 +28,12 @@ import org.genesys.catalog.model.Partner;
import org.genesys.catalog.model.filters.PartnerFilter;
import org.genesys.catalog.persistence.PartnerRepository;
import org.genesys.catalog.service.PartnerService;
import org.genesys2.server.component.security.SecurityUtils;
import org.genesys2.server.exception.NotFoundElement;
import org.genesys2.server.model.UserRole;
import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.model.impl.QFaoInstitute;
import org.genesys2.server.persistence.FaoInstituteRepository;
import org.genesys2.server.security.SecurityUtils;
import org.genesys2.server.service.filter.InstituteFilter;
import org.genesys2.util.JPAUtils;
import org.slf4j.Logger;
......
......@@ -14,7 +14,7 @@
* limitations under the License.
**/
package org.genesys2.server.aspect;
package org.genesys2.server.component.aspect;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
......
......@@ -14,7 +14,7 @@
* limitations under the License.
**/
package org.genesys2.server.aspect;
package org.genesys2.server.component.aspect;
import java.util.Arrays;
......@@ -45,7 +45,7 @@ public class AsAdminAspect {
// Our copy of the SYS_ADMIN account
private static Authentication SYS_ADMIN = null;
@Around("org.genesys2.server.aspect.SystemArchitecture.allServices()" + " && @annotation(org.genesys2.server.aspect.AsAdmin)")
@Around("org.genesys2.server.component.aspect.SystemArchitecture.allServices()" + " && @annotation(org.genesys2.server.component.aspect.AsAdmin)")
public Object authenticateAsAdmin(ProceedingJoinPoint pjp) throws Throwable {
Authentication adminAuthorization = getSystemAdminAccount();
......
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.genesys2.server.aspect;
package org.genesys2.server.component.aspect;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
......
......@@ -14,7 +14,7 @@
* limitations under the License.
**/
package org.genesys2.server.aspect;
package org.genesys2.server.component.aspect;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
......@@ -34,11 +34,11 @@ public class SystemArchitecture {
public void businessServices() {
}
@Pointcut("execution(* org.genesys2.server.listener.sample.*.*(..))")
@Pointcut("execution(* org.genesys2.server.component.listener.*.*(..))")
public void sampleServices() {
}
@Pointcut("execution(* org.genesys2.server.security.*.*(..))")
@Pointcut("execution(* org.genesys2.server.component.security.*.*(..))")
public void securityServices() {
}
......
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.genesys2.server.listener.sample;
package org.genesys2.server.component.listener;
import java.io.IOException;
import java.io.InputStream;
......@@ -27,7 +27,6 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.genesys2.server.listener.RunAsAdminListener;
import org.genesys2.server.model.impl.Article;
import org.genesys2.server.service.CRMException;
import org.genesys2.server.service.ContentService;
......
......@@ -14,13 +14,12 @@
* limitations under the License.
*/
package org.genesys2.server.listener.sample;
package org.genesys2.server.component.listener;
import java.io.IOException;
import java.io.InputStream;
import org.apache.commons.lang3.StringUtils;
import org.genesys2.server.listener.RunAsAdminListener;
import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.service.CropService;
import org.genesys2.server.service.GenesysService;
......
......@@ -14,11 +14,11 @@
* limitations under the License.
**/
package org.genesys2.server.listener;
package org.genesys2.server.component.listener;
import java.util.concurrent.Callable;
import org.genesys2.server.security.AsAdminInvoker;
import org.genesys2.server.component.security.AsAdminInvoker;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
......
......@@ -14,11 +14,11 @@
* limitations under the License.
**/
package org.genesys2.server.security;
package org.genesys2.server.component.security;
import java.util.concurrent.Callable;
import org.genesys2.server.aspect.AsAdmin;
import org.genesys2.server.component.aspect.AsAdmin;
import org.springframework.stereotype.Service;
@Service
......
......@@ -14,7 +14,7 @@
* limitations under the License.
**/
package org.genesys2.server.servlet.util;
package org.genesys2.server.component.security;
import java.io.BufferedReader;
import java.io.IOException;
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.genesys2.server.security;
package org.genesys2.server.component.security;
import org.genesys.blocks.security.SecurityContextUtil;
import org.genesys.blocks.security.model.AclAwareModel;
......
......@@ -14,7 +14,7 @@
* limitations under the License.
**/
package org.genesys2.spring;
package org.genesys2.server.mvc;
import java.time.LocalDate;
......
......@@ -28,8 +28,8 @@ import javax.servlet.http.HttpServletResponse;
import org.genesys.blocks.security.NotUniqueUserException;
import org.genesys.blocks.security.UserException;
import org.genesys.blocks.security.service.PasswordPolicy.PasswordPolicyException;
import org.genesys2.server.component.security.GoogleOAuthUtil;
import org.genesys2.server.model.impl.User;
import org.genesys2.server.servlet.util.GoogleOAuthUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
......
......@@ -21,7 +21,7 @@ import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.genesys2.server.aspect.AsAdmin;
import org.genesys2.server.component.aspect.AsAdmin;
import org.genesys2.server.model.impl.Article;
import org.genesys2.server.mvc.BaseController;
import org.genesys2.server.service.ContentService;
......
......@@ -40,6 +40,7 @@ import javax.validation.Valid;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.genesys2.server.component.security.SecurityUtils;
import org.genesys2.server.model.UserRole;
import org.genesys2.server.model.kpi.Dimension;
import org.genesys2.server.model.kpi.DimensionKey;
......@@ -55,7 +56,6 @@ import org.genesys2.server.persistence.kpi.ExecutionRepository;
import org.genesys2.server.persistence.kpi.ExecutionRunRepository;
import org.genesys2.server.persistence.kpi.KPIParameterRepository;
import org.genesys2.server.persistence.kpi.ObservationRepository;
import org.genesys2.server.security.SecurityUtils;
import org.genesys2.server.service.KPIService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......
......@@ -32,6 +32,7 @@ import javax.validation.Valid;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.StopWatch;
import org.genesys2.server.component.security.SecurityUtils;
import org.genesys2.server.exception.InvalidApiUsageException;
import org.genesys2.server.exception.NotFoundElement;
import org.genesys2.server.model.PublishState;
......@@ -48,7 +49,6 @@ import org.genesys2.server.persistence.FaoInstituteRepository;
import org.genesys2.server.persistence.SubsetAccessionRefRepository;
import org.genesys2.server.persistence.SubsetCreatorRepository;
import org.genesys2.server.persistence.SubsetRepository;
import org.genesys2.server.security.SecurityUtils;
import org.genesys2.server.service.SubsetService;
import org.genesys2.server.service.filter.SubsetFilter;
import org.genesys2.util.JPAUtils;
......
......@@ -19,8 +19,8 @@ package org.genesys2.server.service.worker;
import net.javacrumbs.shedlock.core.SchedulerLock;
import org.apache.commons.lang3.time.StopWatch;
import org.genesys2.server.component.security.AsAdminInvoker;
import org.genesys2.server.model.kpi.Execution;
import org.genesys2.server.security.AsAdminInvoker;
import org.genesys2.server.service.KPIService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......
......@@ -42,7 +42,7 @@ import org.genesys.worldclim.WorldClimUtil;
import org.genesys.worldclim.grid.generic.GenericGridFile;
import org.genesys.worldclim.grid.generic.GenericGridZipFile;
import org.genesys.worldclim.grid.generic.Header;
import org.genesys2.server.aspect.AsAdmin;
import org.genesys2.server.component.aspect.AsAdmin;
import org.genesys2.server.model.dataset.DS;
import org.genesys2.server.model.dataset.DSColumn;
import org.genesys2.server.model.dataset.DSDescriptor;
......
......@@ -32,6 +32,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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;
......@@ -45,6 +46,10 @@ import org.springframework.security.config.annotation.web.configuration.EnableWe
import org.springframework.validation.beanvalidation.MethodValidationPostProcessor;
@Configuration
// Scan for services, components and aspects
@ComponentScan(basePackages= { "org.genesys2.server.security", "org.genesys2.server.service", "org.genesys2.server.component", "org.genesys2.brapi.service", "org.genesys.catalog.service" })
@Import({ HazelcastConfig.class, CommonConfig.class, SchedulerConfig.class, DatabaseConfig.class, TemplatingConfig.class, MailConfig.class, OAuth2ServerConfig.class, SecurityConfig.class, CacheConfig.class,
ElasticsearchConfig.class, FileRepositoryConfig.class, WebSecurityConfig.class, WebConfiguration.class, AuditConfig.class, GLISConfig.class, SwaggerConfig.class, AccessionListenersConfig.class })
......
......@@ -15,14 +15,8 @@
*/
package org.genesys2.spring.config;
import java.nio.file.Paths;
import org.genesys.blocks.security.service.CustomAclService;
import org.genesys.filerepository.InvalidRepositoryPathException;
import org.genesys.filerepository.migration.RepositoryUpgrade20180920;
import org.genesys.filerepository.model.RepositoryFolder;
import org.genesys.filerepository.service.RepositoryService;
import org.genesys2.server.security.AsAdminInvoker;
import org.genesys2.server.component.security.AsAdminInvoker;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
......@@ -43,14 +37,6 @@ public class ApplicationUpgrades implements InitializingBean {
/** The Constant LOG. */
private static final Logger LOG = LoggerFactory.getLogger(ApplicationUpgrades.class);
/** The repository service. */
@Autowired
private RepositoryService repositoryService;
/** The acl service. */
@Autowired
private CustomAclService aclService;
@Autowired
protected AsAdminInvoker asAdminInvoker;
......@@ -81,27 +67,7 @@ public class ApplicationUpgrades implements InitializingBean {
protected RepositoryUpgrade20180920 afterRepositoryUpgrade20180920(RepositoryUpgrade20180920 repositoryUpgrade20180920) throws Exception {
asAdminInvoker.invoke(() -> {
// repositoryUpgrade20180920.doUpgrade();
//
// LOG.warn("Updating permissions on public folders");
//
// for (RepositoryFolder repositoryFolder : repositoryService.getFolders(Paths.get("/"))) {
// LOG.warn("Making {} publicly readable", repositoryFolder.getPath());
// aclService.createOrUpdatePermissions(repositoryFolder);
// aclService.makePubliclyReadable(repositoryFolder, true);
//
// repositoryService.listPaths(repositoryFolder.getFolderPath()).forEach(subFolder -> {
// aclService.createOrUpdatePermissions(subFolder);
// try {
// repositoryService.getFiles(subFolder.getFolderPath()).forEach(file -> {
// aclService.createOrUpdatePermissions(file);
// });
// } catch (InvalidRepositoryPathException e) {
// LOG.error("Error updating permissions: {}", e.getMessage());
// }
//
// });
// }
LOG.warn("Running afterRepositoryUpgrade20180920");
return true;
});
......
......@@ -16,25 +16,18 @@
package org.genesys2.spring.config;
import javax.persistence.Entity;
import org.genesys2.spring.validation.oval.spring.SpringOvalValidator;
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.FilterType;
import org.springframework.context.annotation.Scope;
import org.springframework.http.converter.json.Jackson2ObjectMapperFactoryBean;
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.Filter(value = Configuration.class, type = FilterType.ANNOTATION) }, includeFilters = @ComponentScan.Filter(value = Entity.class, type = FilterType.ANNOTATION))
@Configuration
public class CommonConfig {
......
......@@ -25,10 +25,10 @@ import javax.persistence.EntityManagerFactory;
import org.apache.tomcat.jdbc.pool.DataSource;
import org.genesys.blocks.auditlog.component.AuditTrailInterceptor;
import org.genesys.catalog.persistence.dataset.DatasetAccessionRefRepository;
import org.genesys.catalog.persistence.dataset.DatasetAccessionRefRepositoryCustomImpl;
import org.genesys2.server.persistence.SubsetAccessionRefRepository;
import org.genesys2.server.persistence.SubsetAccessionRefRepositoryCustomImpl;
import org.genesys.catalog.persistence.dataset.DatasetAccessionRefRepository;
import org.hibernate.CallbackException;
import org.hibernate.EmptyInterceptor;
import org.hibernate.Interceptor;
......@@ -52,7 +52,7 @@ import com.querydsl.jpa.impl.JPAQueryFactory;
import liquibase.integration.spring.SpringLiquibase;
@EnableJpaRepositories(basePackages = { "org.genesys.blocks.persistence", "org.genesys.blocks.security.persistence", "org.genesys.blocks.oauth.persistence",
"org.genesys.blocks.auditlog.persistence", "org.genesys2.server.persistence", "org.genesys2.server.persistence.acl", "org.genesys.filerepository.persistence",
"org.genesys.blocks.auditlog.persistence", "org.genesys2.server.persistence", "org.genesys.filerepository.persistence",
"org.genesys.catalog.persistence" }, entityManagerFactoryRef = "entityManagerFactory", transactionManagerRef = "transactionManager", repositoryImplementationPostfix = "CustomImpl")
@EnableJpaAuditing(auditorAwareRef = "auditorAware")
@EnableTransactionManagement
......@@ -131,9 +131,15 @@ public class DatabaseConfig {
return new JPAQueryFactory(entityManager);
}