Skip to content

Commit

Permalink
Issue-554 update all dependencies
Browse files Browse the repository at this point in the history
Change Jax-Rs for Spring Rest / Mvc
Add Swagger dependencies
  • Loading branch information
pierrejego committed Jun 21, 2021
1 parent 88cdfe3 commit 04fa580
Show file tree
Hide file tree
Showing 47 changed files with 817 additions and 786 deletions.
6 changes: 6 additions & 0 deletions cadastrapp/.settings/org.eclipse.core.resources.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/main/resources=UTF-8
encoding//src/test/java=UTF-8
encoding//src/test/resources=UTF-8
encoding/<project>=UTF-8
2 changes: 2 additions & 0 deletions cadastrapp/.settings/org.eclipse.jdt.apt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
org.eclipse.jdt.apt.aptEnabled=false
9 changes: 9 additions & 0 deletions cadastrapp/.settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
org.eclipse.jdt.core.compiler.processAnnotations=disabled
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8
4 changes: 4 additions & 0 deletions cadastrapp/.settings/org.eclipse.m2e.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
16 changes: 8 additions & 8 deletions cadastrapp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ This application is made to be installed behind GeOrchestra security proxy. To i
-- As for gerochestra tomcat instance, you will have to create a new instance
(choose a port not already use here we choose 8480 for http endpoint and 8405 to stop
```
sudo tomcat6-instance-create -p 8480 -c 8405 /var/lib/tomcat-cadastrapp
sudo tomcat9-instance-create -p 8480 -c 8405 /var/lib/tomcat-cadastrapp
```
### Init policy and service
sudo mkdir /var/lib/tomcat-cadastrapp/conf/policy.d
sudo touch /var/lib/tomcat-cadastrapp/conf/policy.d/empty.policy
sudo chown -R tomcat6:tomcat6 /var/lib/tomcat-cadastrapp
sudo cp /etc/init.d/tomcat6 /etc/init.d/tomcat-cadastrapp
sudo cp /etc/default/tomcat6 /etc/default/tomcat-cadastrapp
sudo chown -R tomcat:tomcat /var/lib/tomcat-cadastrapp
sudo cp /etc/init.d/tomcat9 /etc/init.d/tomcat-cadastrapp
sudo cp /etc/default/tomcat9 /etc/default/tomcat-cadastrapp

Finally, edit the ```/etc/init.d/tomcat-cadastrapp``` script, find the following line:
```
# Provides: tomcat6
# Provides: tomcat9
```
... and replace it with:
```
Expand All @@ -44,12 +44,12 @@ JAVA_OPTS="-Djava.awt.headless=true -XX:+UseConcMarkSweepGC"
And later add these lines (change the ```STOREPASSWORD``` string):
```
JAVA_OPTS="$JAVA_OPTS \
-Xms1024m \
-Xms256m \
-Xmx1024m \
-XX:MaxPermSize=256m"
JAVA_OPTS="$JAVA_OPTS \
-Djavax.net.ssl.trustStore=/etc/tomcat6/keystore \
-Djavax.net.ssl.trustStore=/etc/georchestra/keystore \
-Djavax.net.ssl.trustStorePassword=STOREPASSWORD"
```
### Configure connectors
Expand Down Expand Up @@ -86,7 +86,7 @@ In ```/var/lib/tomcat-cadastrapp/conf/context.xml```, add a new ResourceLink at
#### Add jar require for this datasource

To be able to connect to postgresql database, tomcat will have to get postgresql client librairie in his classloader.
In tomcat6 instance, you will have to add ```postgresql-9.1-901-1.jdbc4.jar``` to ```/var/lib/tomcat-cadastrapp/lib``` folder (with a symlink)
In tomcat9 instance, you will have to add ```postgresql-42.2.22.jar``` to ```/var/lib/tomcat-cadastrapp/lib``` folder (with a symlink)

### Start the instance

Expand Down
43 changes: 23 additions & 20 deletions cadastrapp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@
<slf4j.version>1.7.30</slf4j.version>
<logback.version>1.2.3</logback.version>
<jcloverslf4j.version>1.7.25</jcloverslf4j.version>
<postgresql.version>9.4-1205-jdbc4</postgresql.version>
<cxf.version>3.4.3</cxf.version>
<spring.version>5.3.5</spring.version>
<postgresql.version>42.2.20.jre7</postgresql.version>
<spring.version>5.3.7</spring.version>
<hibernate-version>6.0.0.Alpha7</hibernate-version>
<hibernate-annotations-version>5.1.2.Final</hibernate-annotations-version>
<geotools.version>24.0</geotools.version>
<pdfbox.version>2.0.23</pdfbox.version>
<pdfbox.version>3.0.0-RC1</pdfbox.version>
<quartz.version>2.3.2</quartz.version>
</properties>
<repositories>
Expand Down Expand Up @@ -51,16 +50,6 @@
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-rs-client</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
Expand Down Expand Up @@ -92,6 +81,11 @@
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- Transaction and context support dependency are required with Quartz integration -->
<dependency>
<groupId>org.springframework</groupId>
Expand Down Expand Up @@ -234,7 +228,7 @@
<dependency>
<groupId>org.apache.xmlgraphics</groupId>
<artifactId>fop</artifactId>
<version>2.3</version>
<version>2.6</version>
</dependency>
<dependency>
<groupId>net.sf.supercsv</groupId>
Expand Down Expand Up @@ -308,9 +302,14 @@
<version>${pdfbox.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-rs-service-description-swagger</artifactId>
<version>3.1.11</version>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>3.0.0</version>
</dependency>
</dependencies>
<pluginRepositories>
Expand Down Expand Up @@ -344,7 +343,7 @@
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.2.11.v20150529</version>
<version>9.4.41.v20210516</version>
<configuration>
<webApp>
<contextPath>/cadastrapp/</contextPath>
Expand Down Expand Up @@ -374,6 +373,10 @@
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.2</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
Expand Down Expand Up @@ -614,7 +617,7 @@
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>19.0</version>
<version>30.1.1-jre</version>
</dependency>
</dependencies>
</plugin>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.georchestra.cadastrapp.configuration;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration;

import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.context.ContextLoaderListener;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.context.support.GenericWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;

public class CadastrappControllerConfig implements WebApplicationInitializer {

@Override
public void onStartup(ServletContext sc) throws ServletException {
AnnotationConfigWebApplicationContext root = new AnnotationConfigWebApplicationContext();

root.refresh();
root.setServletContext(sc);

sc.addListener(new ContextLoaderListener(root));

DispatcherServlet dv = new DispatcherServlet(new GenericWebApplicationContext());

ServletRegistration.Dynamic appServlet = sc.addServlet("cadastrapp", dv);
appServlet.setLoadOnStartup(1);
appServlet.addMapping("/services/*");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;

/**
*
* CadastrappPlaceHolder
*
* @author Pierre Jégo / [email protected]
*
*/
public class CadastrappPlaceHolder extends PropertyPlaceholderConfigurer {

private static Map<String, String> propertiesMap;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package org.georchestra.cadastrapp.configuration;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import io.swagger.annotations.Contact;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;

@Configuration
@EnableSwagger2WebMvc
public class SwaggerConfig {

@Bean
public Docket api(){
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.regex("/api/.*"))
.build()
.apiInfo(apiInfo());
}

private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("TITLE")
.description("DESCRIPTION")
.version("VERSION")
.termsOfServiceUrl("http://terms-of-services.url")
.license("LICENSE")
.licenseUrl("http://url-to-license.com")
.build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*
* Context listener specific for cadastrapp
*
* @author pierrejego
* @author Pierre Jégo / [email protected]
*
*/
public class CadastrappContextListener implements ServletContextListener{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import java.util.List;
import java.util.Map;

import javax.ws.rs.core.HttpHeaders;

import org.georchestra.cadastrapp.service.CadController;

import org.slf4j.Logger;
Expand All @@ -26,7 +24,7 @@ public final class BatimentHelper extends CadController {
*
* @return buildings information on this plot
*/
public List<Map<String, Object>> getBuildings(String parcelle, HttpHeaders headers ){
public List<Map<String, Object>> getBuildings(String parcelle, String rolesList ){

logger.debug("infoOngletBatiment - parcelle : " + parcelle);

Expand All @@ -36,7 +34,7 @@ public List<Map<String, Object>> getBuildings(String parcelle, HttpHeaders heade
queryBuilder.append(databaseSchema);
queryBuilder.append(".proprietebatie pb ");
queryBuilder.append(" where pb.parcelle = ? ");
queryBuilder.append(addAuthorizationFiltering(headers, "pb."));
queryBuilder.append(addAuthorizationFiltering(rolesList, "pb."));
queryBuilder.append(" ORDER BY pb.dnubat");

JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import java.util.List;
import java.util.Map;

import javax.ws.rs.core.HttpHeaders;

import org.georchestra.cadastrapp.service.CadController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -21,16 +19,16 @@ public final class ProprietaireHelper extends CadController {
*
* @param parcelleList plots list
* @param isAddressConcat true to display address in only on field address, false to display each dlign
* @param headers A leaste level CNIL1 form http headers
* @param rolesList A leaste level CNIL1 form http headers
* @return information list of owner whith address field concat in one field (if isAddressConcat is true)
*/
public List<Map<String, Object>> getProprietairesByParcelles(HttpHeaders headers, List<String> parcelleList, boolean isAddressConcat) {
public List<Map<String, Object>> getProprietairesByParcelles(String rolesList, List<String> parcelleList, boolean isAddressConcat) {

// Init list to return response even if nothing in it.
List<Map<String,Object>> proprietaires = new ArrayList<Map<String,Object>>();

// User need to be at least CNIL1 level
if (getUserCNILLevel(headers)>0){
if (getUserCNILLevel(rolesList)>0){

if(parcelleList != null && !parcelleList.isEmpty()){

Expand All @@ -49,7 +47,7 @@ public List<Map<String, Object>> getProprietairesByParcelles(HttpHeaders headers
queryBuilder.append(".proprietaire_parcelle proparc ");
queryBuilder.append(createWhereInQuery(parcelleList.size(), "proparc.parcelle"));
queryBuilder.append(" and prop.comptecommunal = proparc.comptecommunal");
queryBuilder.append(addAuthorizationFiltering(headers, "prop."));
queryBuilder.append(addAuthorizationFiltering(rolesList, "prop."));
queryBuilder.append(" ORDER BY prop.dnulp, prop.app_nom_usage ");

JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package org.georchestra.cadastrapp.providers;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

/**
* Log all request
* @author Pierre Jégo
*
*/
@Component
public class CadastrappInterceptor implements HandlerInterceptor {

final Logger logger = LoggerFactory.getLogger(CadastrappInterceptor.class);

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
throws Exception {

String rolesList = request.getHeader("sec-roles");
String userName = request.getHeader("sec-username");
MDC.put("user", userName);
MDC.put("roles", rolesList);
MDC.put("uri", request.getRequestURI());

logger.info("Incoming request");

if(logger.isDebugEnabled()){
logger.debug("Parameter list : " + StringUtils.join(request.getParameterMap()));
}
return true;
}


@Override
public void postHandle( HttpServletRequest request, HttpServletResponse response,
Object handler, ModelAndView modelAndView) throws Exception {

logger.info("Response");
MDC.remove("user");
MDC.remove("roles");
MDC.remove("uri");
}

}
Loading

0 comments on commit 04fa580

Please sign in to comment.