Skip to content

Commit

Permalink
Bump supported Java version and several libraries (#153)
Browse files Browse the repository at this point in the history
* Bump spring-boot-starter-parent from 1.4.4 ->2.7.8 (with Spring 5.3.31 and Solr 8.5.2).
* Bump Java 8 -> Java 17
* Keep Java 8 for klass-forvaltning
* Fix incorrect sql syntax
* Upgrade jaxb2-maven-plugin
* Removed solr-dataimporthandler as it conflicted with ANTLR version (and is hopefully not used)
* Fix boolean comparison operator in JPA queries
* Fix issues with H2 and reserved keywords
* Fix JPQL boolean comparison
* Fixed antlr conflicts
* Specify Converter for fields of type Translatable
* Implement no-args constructor for entity classes
* Fixed native sqls for the user table and fixed an improper test.
* Bump rest-assured version
* Tables should be nullable
* Fix changes in Spring HATEOAS
* Fix tests due to changes in Spring HATEOAS
* Fix CodeQL Analysis
* Share maven cache
* Make all classes Java 1.8 compatible in order to build klass-forvaltning.
* Since klass-forvaltning uses Vaadin7 we must remove dependency to klass-root and continue using Spring Boot 1.4.4.
* Use spring-data-solr 2.1.0.RELEASE
* Turn off hibernate ddl validation since it appears buggy
* Add http examples
* Solr Core name must be part of the baseURL for some reason
* Fix search links to include the base path
* Add separate profiles for nexus and github
* Add github packages repo
* Add auth to github packages repo
* Fix monitoring and ping paths to be less strict. Also fix links where basePath was missing.
* Fix ordering of json structure
* Use application/hal+json by default
* Keep suffix pattern matching which Spring has disabled by default 
* Bump apacheds-server-jndi-version and set CORS header for klass-web
* Expand self links so that klass-web can use the links directly
* Ensure that links inherit https when running behind a LB/reverse proxy
* Enforce https in API docs

---------

Co-authored-by: mmwinther <[email protected]>
  • Loading branch information
bjornandre and mmwinther authored Jan 24, 2024
1 parent 8f5e787 commit 0f5b413
Show file tree
Hide file tree
Showing 166 changed files with 2,129 additions and 1,658 deletions.
30 changes: 27 additions & 3 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,12 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up JDK 1.8
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: '8'
java-version: '17'
cache: maven

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
Expand All @@ -68,8 +69,31 @@ jobs:
#- run: |
# make bootstrap
# make release
# Build all modules except klass-forvaltning since it is not compatible with JDK 17
- name: Build with Maven
run: mvn -B clean install --settings=.maven.settings.xml --file pom.xml
run: mvn -B clean install --settings=.maven.settings.xml -pl '!:klass-forvaltning'

- name: Set up JDK 1.8
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: '8'
cache: maven

# Need to downgrade Maven in order to allow HTTP (not HTTPS) packages to be downloaded.
# This is necessary as HTTP repositories were blocked in Maven 3.8.1
# HTTP repositories are used in some outdated dependenciesns
# This step can be removed once KLASS packages have been updated to more recent versions
- name: Set up Maven
uses: stCarolas/[email protected]
with:
maven-version: 3.6.3

# Build only klass-forvaltning with JDK 1.8
- name: Build, test and package with Maven
run: mvn --batch-mode --update-snapshots package -Djava.version=1.8 -pl :klass-forvaltning -am -P github
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
23 changes: 19 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@ jobs:
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: '17'
cache: maven

# Build all modules except klass-forvaltning since it is not compatible with JDK 17
- name: Build, test and package with Maven
run: mvn --batch-mode --update-snapshots package -pl '!:klass-forvaltning' -P nexus

- uses: actions/checkout@v3
- name: Set up JDK 1.8
uses: actions/setup-java@v3
Expand All @@ -34,8 +46,11 @@ jobs:
with:
maven-version: 3.6.3

# Build only klass-forvaltning with JDK 1.8
- name: Build, test and package with Maven
run: mvn --batch-mode --update-snapshots package -P nexus
run: mvn --batch-mode --update-snapshots package -Djava.version=1.8 -pl :klass-forvaltning -am -P github
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

deploy:
runs-on: ubuntu-latest
Expand All @@ -46,14 +61,14 @@ jobs:
packages: write
steps:
- uses: actions/checkout@v3
- name: Set up JDK 1.8
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: '8'
java-version: '17'
cache: maven

- name: Publish to GitHub Packages
run: mvn --batch-mode deploy -P github -DskipTests
run: mvn --batch-mode deploy -pl '!:klass-forvaltning' -P github -DskipTests
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ build-all:

.PHONY: run-klass-forvaltning-local
run-klass-forvaltning-local:
pushd klass-forvaltning && mvn spring-boot\:run -P nexus && popd
pushd klass-forvaltning && mvn spring-boot\:run --settings=../.maven.settings.xml -P nexus && popd

.PHONY: run-klass-forvaltning-local-mariadb
# Requires that a MariaDB instance is already running with a database called klass and a user called klass.
Expand Down
21 changes: 21 additions & 0 deletions klass-api/doc/requests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# HTTP Client tests

This folder contains files for Jetbrains'
[HTTP Client plugin](https://www.jetbrains.com/help/idea/2023.1/http-client-in-product-code-editor.html). With these
you can create, edit, and execute HTTP requests directly in the IntelliJ IDEA code editor.

To be able to run these requests you should have an environment file called `http-client.env.json`
inside this folder. The file should have
the following structure:

```
{
"local": {
"base_url": "http://localhost:8080/api/klass/v1",
"other": "..."
},
"prod": {
"base_url": "https://data.ssb.no/api/klass/v1",
"other": "..."
}
```
54 changes: 54 additions & 0 deletions klass-api/doc/requests/examples-classifications.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
### Get all classificationfamilies
GET {{base_url}}/classificationfamilies
Accept: application/json

### Get single classificationfamily
GET {{base_url}}/classificationfamilies/15
Accept: application/json

### Get all classifications
GET {{base_url}}/classifications
Accept: application/json

### Get a single classification
GET {{base_url}}/classifications/1
Accept: application/json

### Get classification codes
GET {{base_url}}/classifications/1/codes?from=2020-01-01&to=2021-01-01&includeFuture=true
Accept: application/json

### Get classification codes
GET {{base_url}}/classifications/1/codes?from=2020-01-01&includeFuture=true
Accept: application/json

### Get classification codes
GET {{base_url}}/classifications/1/codesAt?date=2020-06-01
Accept: application/json

### Get classification changes
GET {{base_url}}/classifications/1/changes
Accept: application/json

### Search for classifications
GET {{base_url}}/classifications/search?query=kommune
Accept: application/json

### Search for classifications within a ssb section
GET {{base_url}}/classifications/search?query=kommune&includeCodelists=true&ssbSection=320
Accept: application/json

### Get all classifications with size
GET {{base_url}}/classifications?size=2
Accept: application/json

### Get all classifications with size and page
GET {{base_url}}/classifications?size=2&page=2
Accept: application/json

### Get a single correspondencetable
GET {{base_url}}/correspondencetables/1
Accept: application/json

### Get a single correspondencetable with suffix pattern matching
GET {{base_url}}/correspondencetables/1.csv
8 changes: 8 additions & 0 deletions klass-api/doc/requests/http-client.env.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"local": {
"base_url": "http://localhost:8080/api/klass/v1"
},
"prod": {
"base_url": "https://data.ssb.no/api/klass/v1"
}
}
59 changes: 52 additions & 7 deletions klass-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
<parent>
<groupId>no.ssb.klass</groupId>
<artifactId>klass-root</artifactId>
<version>2.1.8-SNAPSHOT</version>
<!-- <relativePath>../</relativePath>-->
<version>3.0.0-SNAPSHOT</version>
</parent>

<properties>
Expand All @@ -30,8 +29,19 @@
<groupId>no.ssb.klass</groupId>
<artifactId>klass-solr</artifactId>
<version>${project.parent.version}</version>
<exclusions>
<exclusion>
<groupId>org.antlr</groupId>
<artifactId>antlr4-runtime</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>

<!--Spring-->
<dependency>
<groupId>org.springframework.boot</groupId>
Expand All @@ -58,7 +68,12 @@
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-solr</artifactId>
</dependency>

<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>${jaxb-api-version}</version>
<scope>provided</scope>
</dependency>

<!--TOMCAT-->
<dependency>
Expand All @@ -79,7 +94,6 @@
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>

<dependency>
<groupId>javax.el</groupId>
<artifactId>javax.el-api</artifactId>
Expand Down Expand Up @@ -107,6 +121,11 @@
<scope>test</scope>
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>jakarta.ws.rs</groupId>
<artifactId>jakarta.ws.rs-api</artifactId>
<version>${jakarta-rs-api-version}</version>
</dependency>

<!--Spring TEST-->
<dependency>
Expand All @@ -122,17 +141,43 @@
<dependency>
<groupId>org.springframework.restdocs</groupId>
<artifactId>spring-restdocs-mockmvc</artifactId>
<version>${spring-restdocs-version}</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.springframework.restdocs</groupId>
<artifactId>spring-restdocs-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.restdocs</groupId>
<artifactId>spring-restdocs-core</artifactId>
<version>${spring-restdocs-version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.jayway.restassured</groupId>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<scope>test</scope>
<exclusions>
<!-- remove conflicting dependency because declared in 2 differents versions (3 & 4)
See: https://github.com/rest-assured/rest-assured/issues/1612 -->
<exclusion>
<groupId>org.apache.groovy</groupId>
<artifactId>groovy-xml</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<!-- add this dep which bring back the groovy-xml in a single and last version (4) -->
<groupId>io.rest-assured</groupId>
<artifactId>xml-path</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<profiles>
Expand Down
2 changes: 1 addition & 1 deletion klass-api/src/main/asciidoc/api-guide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ include::{snippets}/error-example/http-response.adoc[]

=== Output formats
Default output format is XML. JSON is optional, and in many cases CSV. It is possible to get output in the supported output formats without using Curl `-H` (`--header`). Add the dot-prefix `.json`, `.csv` or `.xml` in the URL before the request parameters,
e.g. json: http://data.ssb.no/api/klass/v1/classifications/104/codesAt.json?date=2020-01-01[http://data.ssb.no/api/klass/v1/classifications/104/codesAt.json?date=2020-01-01]. When adding this in the URL you only get the default character sets.
e.g. json: https://data.ssb.no/api/klass/v1/classifications/104/codesAt.json?date=2020-01-01[https://data.ssb.no/api/klass/v1/classifications/104/codesAt.json?date=2020-01-01]. When adding this in the URL you only get the default character sets.

=== Character sets
Charset for the formats XML and JSON are UTF-8. Default charset for CSV is ISO 8859-1. This can be changed in Accept header to UTF-8.
Expand Down
8 changes: 3 additions & 5 deletions klass-api/src/main/java/no/ssb/klass/KlassApiApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration;
import org.springframework.boot.autoconfigure.web.servlet.TomcatServletWebServerFactoryCustomizer;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Import;

// CHECKSTYLE:OFF
@SpringBootApplication
@Import(EmbeddedServletContainerAutoConfiguration.EmbeddedTomcat.class)
@Import(TomcatServletWebServerFactoryCustomizer.class)
public class KlassApiApplication extends SpringBootServletInitializer {
// TODO kmgv if using embedded container (e.g. Tomcat) remove below method and extends SpringBootServletInitializer
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,21 @@
import no.ssb.klass.api.controllers.MonitorController;
import no.ssb.klass.api.controllers.PingController;
import no.ssb.klass.api.util.RestConstants;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.web.SecurityFilterChain;

/**
* @author Mads Lundemo, SSB.
*/
@Configuration
@Profile(value = { ConfigurationProfiles.API_ONLY }) // makes config disabled for tests
public class KlassApiConfiguration extends WebSecurityConfigurerAdapter {
public class KlassApiConfiguration {

@Override
protected void configure(HttpSecurity http) throws Exception {
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http.authorizeRequests()
// block sensitive endpoints (actuator)
.antMatchers("/manage**").denyAll() // alt. hasIpAddress("127.0.0.1")
Expand All @@ -35,7 +36,7 @@ protected void configure(HttpSecurity http) throws Exception {
.csrf().disable()
.headers()
.addHeaderWriter((request, response) -> {
if (request.getServletPath().startsWith(RestConstants.API_VERSION_V1)) {
if (request.getServletPath().startsWith(RestConstants.PREFIX_AND_API_VERSION_V1)) {
// Workaround to Force CORS header all the time for API
response.addHeader("Access-Control-Allow-Origin", "*");
// Header telling cache server what is varying in our responses
Expand All @@ -44,6 +45,6 @@ protected void configure(HttpSecurity http) throws Exception {
}
})
.frameOptions().disable();

return http.build();
}
}
Loading

0 comments on commit 0f5b413

Please sign in to comment.