Skip to content

Commit

Permalink
Kotlin refactor (#118)
Browse files Browse the repository at this point in the history
* Migrate build.gradle to kotlin

* Remove Lombok

* Migrate Integration tests to Kotlin

* Migrate Unit tests to kotlin and rename test dir roots

* Bumped to `6.0.0-SNAPSHOT` and refactored test directories

* Refactor source code to Kotlin

* Tests, config and API refactors/cleanups

* Update .editorconfig and .gitignore

* Refactor code for Javalin 6.0.0-beta.4, removed http3 and minor cleanups

* Update dependencies in build.gradle.kts

* Update workflows

* Update Kotlin and Gradle versions

* Fix tests
  • Loading branch information
zugazagoitia authored Dec 31, 2023
1 parent e679290 commit 4af9952
Show file tree
Hide file tree
Showing 79 changed files with 3,751 additions and 3,684 deletions.
21 changes: 3 additions & 18 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,16 @@ trim_trailing_whitespace = true
insert_final_newline = true

[*.java]
indent_style = space
indent_size = 4
continuation_indent_size = 4

[*.kt]
indent_style = space
indent_size = 4
continuation_indent_size = 8

[*.md]
trim_trailing_whitespace = false

[*.adoc]
trim_trailing_whitespace = false


[*.{js, css, html}]
indent_style = space
indent_size = 4
[*.{js,css,html}]
insert_final_newline = false

[*.{yml, yaml, json}]
indent_style = space
indent_size = 2

[*.xml]
indent_style = space
indent_size = 4
[*.{yml,yaml,json}]
indent_size = 2
59 changes: 32 additions & 27 deletions .github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

# SSL Plugin [![GitHub Workflow Status (branch)](https://img.shields.io/github/actions/workflow/status/javalin/javalin-ssl/main.yaml?branch=main&label=main&logo=githubactions&logoColor=white)](https://github.com/javalin/javalin-ssl/actions?query=branch%3Amain) [![GitHub Workflow Status (branch)](https://img.shields.io/github/actions/workflow/status/javalin/javalin-ssl/main.yaml?branch=dev&label=dev&logo=githubactions&logoColor=white)](https://github.com/javalin/javalin-ssl/actions?query=branch%3Adev) [![Coverage](https://codecov.io/gh/javalin/javalin-ssl/branch/dev/graphs/badge.svg)](https://app.codecov.io/gh/javalin/javalin-ssl) [![javadoc](https://javadoc.io/badge2/io.javalin.community.ssl/ssl-plugin/javadoc.svg)](https://javadoc.io/doc/io.javalin.community.ssl/ssl-plugin)

Straightforward SSL and HTTP/2 Configuration for Javalin!
Straightforward SSL, HTTP/2 and HTTP/3 Configuration for Javalin!

If you're not familiar with the HTTPS protocol we have a great guide at the [Javalin website](https://javalin.io/tutorials/javalin-ssl-tutorial).

Expand Down Expand Up @@ -53,28 +53,34 @@ Javalin.create(config->{
```kotlin
Javalin.create { config ->
... // your Javalin config here
config.plugins.register(SSLPlugin { ssl ->
config.registerPlugin(SSL) {
... // your SSL configuration here
ssl.pemFromPath("/path/to/cert.pem", "/path/to/key.pem")
})
it.pemFromPath("/path/to/cert.pem", "/path/to/key.pem")
}
}
```

### Available config options

```java
```kotlin

// Connection options
host=null; // Host to bind to, by default it will bind to all interfaces
insecure=true; // Toggle the default http (insecure) connector
secure=true; // Toggle the default https (secure) connector
http2=true; // Toggle HTTP/2 Support
http3=false; // Toggle HTTP/3 Support

securePort=443; // Port to use on the SSL (secure) connector
insecurePort=80; // Port to use on the http (insecure) connector
securePort=443; // Port to use on the SSL (secure) connector (TCP)
insecurePort=80; // Port to use on the http (insecure) connector (TCP)
http3Port=443; // Port to use on the http3 connector (UDP)
redirect=false; // Redirect all http requests to https
disableHttp3Upgrade=false; // Disable the HTTP/3 upgrade header



sniHostCheck=true; // Enable SNI hostname verification
tlsConfig=TLSConfig.INTERMEDIATE; // Set the TLS configuration. (by default it uses Mozilla's intermediate configuration)
tlsConfig=TLSConfig.INTERMEDIATE; // Set the TLS configuration. (by default Mozilla's intermediate)

// PEM loading options (mutually exclusive)
pemFromPath("/path/to/cert.pem","/path/to/key.pem"); // load from the given paths
Expand All @@ -92,9 +98,9 @@ keystoreFromClasspath("keyStoreName.p12","keystorePassword"); // load th
keystoreFromInputStream(keystoreInputStream,"keystorePassword"); // load the keystore from the given input stream

// Advanced options
configConnectors(Consumer<ServerConnector>); // Set a Consumer to configure the connectors
configConnectors { con -> con.dump() } // Set a Consumer to configure the connectors
securityProvider = null; // Use a custom security provider
withTrustConfig(Consumer<TrustConfig>); // Set the trust configuration, explained below. (by default all clients are trusted)
withTrustConfig { trust -> trust.pemFromString("cert") } // Set the trust configuration, explained below.
```

#### Trust Configuration
Expand All @@ -114,7 +120,7 @@ config.plugins.register(new SSLPlugin(ssl->{
}));
```

```java
```kotlin
// Certificate loading options (PEM/DER/P7B)
certificateFromPath("path/to/certificate.pem"); // load a PEM/DER/P7B cert from the given path
certificateFromClasspath("certificateName.pem"); // load a PEM/DER/P7B cert from the given path in the classpath
Expand All @@ -132,36 +138,35 @@ trustStoreFromInputStream(inputStream, "password"); // load a trust sto
#### Hot reloading
Certificate reloading is supported, if you want to replace the certificate you can simply call `SSLPlugin.reload()` with the new configuration.

```java
```kotlin
// Create the plugin outside the Javalin config to hold a reference to reload it
SSLPlugin sslPlugin = new SSLPlugin(ssl->{
ssl.loadPemFromPath("/path/to/cert.pem","/path/to/key.pem");
ssl.insecurePort = 8080; // any other config you want to change
});
val sslPlugin = SSLPlugin {
it.loadPemFromPath("/path/to/cert.pem","/path/to/key.pem");
it.insecurePort = 8080; // any other config you want to change
}

Javalin.create(config->{
Javalin.create {
... // your Javalin config here
config.plugins.register(sslPlugin);
});
it.registerPlugin(sslPlugin)
}

// later on, when you want to replace the certificate
sslPlugin.reload(ssl->{
sslPlugin.reload {
// any options other than loading certificates/keys will be ignored.
ssl.loadPemFromPath("/path/to/new/cert.pem","/path/to/new/key.pem");
it.pemFromPath("/path/to/new/cert.pem","/path/to/new/key.pem");

// you can also replace trust configuration
ssl.withTrustConfig(trust->{
trust.certificateFromPath("/path/to/new/cert.pem");
});
});
it.withTrustConfig{ trust ->
trust.certificateFromPath("path/to/new/certificate.pem");
}
}
```



## Notes

- HTTP/2 **can** be used over an insecure connection.
- HTTP/3 is **not** yet supported because of some issues with Jetty's implementation.
- If Jetty responds with an `HTTP ERROR 400 Invalid SNI`, you can disable SNI verification by
setting `sniHostCheck = false`.
- Minimizing your jar can lead to issues, [more info](https://github.com/javalin/javalin-ssl/issues/59).
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/codeql.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ name: "CodeQL"

on:
push:
branches: [ "main" ]
branches: [ "main", "dev" ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ "main" ]
branches: [ "main", "dev" ]
schedule:
- cron: '37 5 * * 4'

Expand Down
63 changes: 37 additions & 26 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
fail-fast: false
matrix:
java_version: [11, 17, 18] # Test all LTS releases and the latest one
java_version: [11, 17, 21] # Test all LTS releases and the latest one
os: [windows-latest, macOS-latest, ubuntu-latest]
steps:
- name: Checkout
Expand All @@ -33,9 +33,6 @@ jobs:
needs:
- test
name: "📄 Codecov Report"
strategy:
matrix:
test-type: [unit, integration]
steps:
- name: Setup Java JDK
uses: actions/[email protected]
Expand All @@ -52,20 +49,20 @@ jobs:
- name: Setup and Run Gradle
uses: gradle/[email protected]
with:
arguments: ${{ matrix.test-type }}TestsCoverageReport
arguments: jacocoTestReport

- name: Upload coverage to Codecov
uses: codecov/[email protected]
with:
files: "${{ github.workspace }}/build/reports/jacoco/${{ matrix.test-type }}TestsCoverageReport/${{ matrix.test-type }}TestsCoverageReport.xml"
flags: "${{ matrix.test-type }}Tests"
files: "${{ github.workspace }}/build/reports/jacoco/test/jacocoTestReport.xml"
verbose: true
token: "${{ secrets.CODECOV_TOKEN }}"
publish:
publish-release:
#TODO Support releases on 5.x
if: github.ref == 'refs/heads/main' && github.event_name != 'pull_request' && github.repository == 'javalin/javalin-ssl'
needs:
- test
name: "🛫 Publish to maven repo"
name: "🛫 Publish to maven central"
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand All @@ -81,8 +78,8 @@ jobs:
uses: HardNorth/[email protected]
with:
version-source: file
version-file: build.gradle
version-file-extraction-pattern: '(?<=version\s*=\s*'')\S+(?='')'
version-file: build.gradle.kts
version-file-extraction-pattern: '(?<=version\s*=\s*"")\S+(?="")'

- name: Validate Wrapper
uses: gradle/wrapper-validation-action@v1
Expand Down Expand Up @@ -110,8 +107,8 @@ jobs:
with:
arguments: publishToSonatype closeAndReleaseStagingRepository

- name: Create Pre-Release
if: contains(env.CURRENT_VERSION, 'SNAPSHOT')
- name: Create Pre-Release for Betas
if: contains(env.CURRENT_VERSION, 'beta')
uses: ncipollo/[email protected]
with:
tag: ${{ env.CURRENT_VERSION }}
Expand All @@ -122,31 +119,19 @@ jobs:
## Download Instructions
### Maven
```xml
<repository>
<id>reposilite-repository-snapshots</id>
<name>Reposilite Repository</name>
<url>https://maven.reposilite.com/snapshots</url>
</repository>
```
```xml
<dependency>
<groupId>io.javalin.community.ssl</groupId>
<artifactId>ssl-plugin</artifactId>
<version>${{ env.CURRENT_VERSION }}</version>
</dependency>
```
### Gradle
```groovy
maven {
url "https://maven.reposilite.com/snapshots"
}
```
```groovy
implementation('io.javalin.community.ssl:ssl-plugin:${{ env.CURRENT_VERSION }}')
```
- name: Create Release
if: "!contains(env.CURRENT_VERSION, 'SNAPSHOT')"
if: "!contains(env.CURRENT_VERSION, 'beta') && !contains(env.CURRENT_VERSION, 'SNAPSHOT')"
uses: ncipollo/[email protected]
with:
tag: ${{ env.CURRENT_VERSION }}
Expand All @@ -166,6 +151,32 @@ jobs:
```groovy
implementation('io.javalin.community.ssl:ssl-plugin:${{ env.CURRENT_VERSION }}')
```
publish-snapshot:
if: github.ref == 'refs/heads/dev' && github.event_name != 'pull_request' && github.repository == 'javalin/javalin-ssl'
needs:
- test
name: "🛫 Publish snapshot to reposilite"
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Set up JDK
uses: actions/[email protected]
with:
distribution: 'zulu'
java-version: '17'

- name: Validate Wrapper
uses: gradle/wrapper-validation-action@v1

- name: Publish to Reposilite
uses: gradle/[email protected]
env:
MAVEN_NAME: '${{ secrets.MAVEN_NAME }}'
MAVEN_TOKEN: '${{ secrets.MAVEN_TOKEN }}'
ORG_GRADLE_PROJECT_signingKey: '${{ secrets.GPG_KEY }}'
ORG_GRADLE_PROJECT_signingPassword: '${{ secrets.GPG_PASSPHRASE }}'
ORG_GRADLE_PROJECT_signingKeyId: '${{ secrets.GPG_KEYID }}'
with:
arguments: publishMavenPublicationToReposiliteRepository
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ buildNumber.properties
.gradle
**/build/
!src/**/build/
bin

# Ignore Gradle GUI config
gradle-app.setting
Expand All @@ -37,3 +38,6 @@ gradle-app.setting
# Eclipse Core
# JDT-specific (Eclipse Java Development Tools)
/.run/

# Vscode
.vscode
Loading

0 comments on commit 4af9952

Please sign in to comment.