diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 33aa0479..35757637 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -3,14 +3,16 @@ on: push: branches: - master + - 1.x.x name: release jobs: release: permissions: write-all - uses: mxenabled/path-tools/.github/workflows/release_manifest.yml@master + uses: mxenabled/path-tools/.github/workflows/release_semantic.yml@master secrets: + SEMANTIC_TOKEN: ${{ secrets.SEMANTIC_TOKEN }} OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }} OSSRH_TOKEN: ${{ secrets.OSSRH_TOKEN }} GPG_SIGNING_KEY_BASE64: ${{ secrets.GPG_SIGNING_KEY_BASE64 }} diff --git a/.release-please-manifest.json b/.release-please-manifest.json deleted file mode 100644 index caf14871..00000000 --- a/.release-please-manifest.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - ".": "1.11.0" -} \ No newline at end of file diff --git a/.releaserc b/.releaserc new file mode 100644 index 00000000..b61ffafe --- /dev/null +++ b/.releaserc @@ -0,0 +1,47 @@ +{ + "branches": [ + { name: "master" }, + { name: "rc", prerelease: "rc" }, + { name: "+([0-9])?(.{+([0-9]),x}).x" } + ], + "plugins": [ + [ + "@google/semantic-release-replace-plugin", + { + "replacements": [ + { + "files": ["./README.md", "build.gradle"], + "from": "(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?(?.+x-release-version.?)", + "to": "${nextRelease.version}$" + } + ] + } + ], + [ + '@semantic-release/commit-analyzer', + { + preset: 'conventionalcommits', + }, + ], + [ + '@semantic-release/release-notes-generator', + { + preset: 'conventionalcommits', + } + ], + [ + "@semantic-release/changelog", + { + "changelogFile": "CHANGELOG.md" + } + ], + [ + "@semantic-release/git", + { + "assets": ["./README.md", "CHANGELOG.md", "./build.gradle"], + "message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}" + } + ], + "@semantic-release/github" + ] +} diff --git a/CHANGELOG.md b/CHANGELOG.md index 3bd4eb4b..cd519160 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## [1.11.1](https://github.com/mxenabled/path-core/compare/v1.11.0...1.11.1) (2023-06-07) + + +### Bug Fixes + +* patch mutual auth provider memory leak ([f9a43b7](https://github.com/mxenabled/path-core/commit/f9a43b7bb0bd88aac651e13e89b5f683aa06215a)) + # Changelog ## [1.11.0](https://github.com/mxenabled/path-core/compare/v1.10.0...v1.11.0) (2023-04-26) diff --git a/README.md b/README.md index c443c8e2..7a3db313 100644 --- a/README.md +++ b/README.md @@ -20,10 +20,9 @@ ### Using platform (preferred) _Gradle_ - ```groovy dependencies { - api platform("com.mx.path-core:platform:1.11.0") + api platform("com.mx.path-core:platform:1.11.1") // x-release-version implementation "com.mx.path-core:common" implementation "com.mx.path-core:context" @@ -37,27 +36,6 @@ dependencies { testImplementation "com.mx.path-core:testing" } ``` - - -### Using without platform - -_Gradle_ - -```groovy -dependencies { - implementation "com.mx.path-core:common:1.11.0" - implementation "com.mx.path-core:context:1.11.0" - implementation "com.mx.path-core:gateway:1.11.0" - implementation "com.mx.path-core:http:1.11.0" - implementation "com.mx.path-core:messaging:1.11.0" - implementation "com.mx.path-core:utilities:1.11.0" - - annotationProcessor "com.mx.path-core:gateway-generator:1.11.0" - - testImplementation "com.mx.path-core:testing:1.11.0" -} -``` - ## Releases diff --git a/build.gradle b/build.gradle index 06e92eb6..8bdf71d2 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ plugins { id "io.github.gradle-nexus.publish-plugin" version "1.1.0" } -version "1.11.0" // x-release-please-version +version "1.11.1" // x-release-version def platformProject = "platform" def publishedProjects = [ diff --git a/common/src/main/java/com/mx/common/connect/ConnectionSettings.java b/common/src/main/java/com/mx/common/connect/ConnectionSettings.java index f039ca1b..3084474b 100644 --- a/common/src/main/java/com/mx/common/connect/ConnectionSettings.java +++ b/common/src/main/java/com/mx/common/connect/ConnectionSettings.java @@ -38,4 +38,26 @@ public interface ConnectionSettings { default void describe(ObjectMap description) { } + + /** + * Used to represent this connection's uniqueness for mutual auth + * + *

Only override if your class needs more uniqueness. (rare) + * @return Hash of baseUrl, certificateAlias, and keystorePath. + */ + @SuppressWarnings("MagicNumber") + default int mutualAuthProviderHashcode() { + int result = 1; + + Object thisBaseUrl = this.getBaseUrl(); + result = result * 59 + (thisBaseUrl == null ? 43 : thisBaseUrl.hashCode()); + + Object thisCertificateAlias = this.getCertificateAlias(); + result = result * 59 + (thisCertificateAlias == null ? 43 : thisCertificateAlias.hashCode()); + + Object thisKeystorePath = this.getKeystorePath(); + result = result * 59 + (thisKeystorePath == null ? 43 : thisKeystorePath.hashCode()); + + return result; + } } diff --git a/common/src/test/groovy/com/mx/common/connect/AccessorConnectionSettingsTest.groovy b/common/src/test/groovy/com/mx/common/connect/AccessorConnectionSettingsTest.groovy new file mode 100644 index 00000000..af2bd9b8 --- /dev/null +++ b/common/src/test/groovy/com/mx/common/connect/AccessorConnectionSettingsTest.groovy @@ -0,0 +1,63 @@ +package com.mx.common.connect + +import com.mx.common.collections.ObjectMap + +import spock.lang.Specification + +class AccessorConnectionSettingsTest extends Specification { + AccessorConnectionSettings settings + + def setup() { + settings = new AccessorConnectionSettings() + } + + def "test mutualAuthProviderHashcode"() { + given: + settings.setBaseUrl("http://localhost:3001") + settings.setCertificateAlias("certificate1") + settings.setKeystorePath("./src/test/resources/keystore.jks") + + when: + def first = settings.mutualAuthProviderHashcode() + + then: + first == settings.mutualAuthProviderHashcode() + + when: + settings.setBaseUrl("http://localhost:3002") + settings.setCertificateAlias("certificate1") + settings.setKeystorePath("./src/test/resources/keystore.jks") + + then: + first != settings.mutualAuthProviderHashcode() + + when: + settings.setBaseUrl("http://localhost:3001") + settings.setCertificateAlias("certificate2") + settings.setKeystorePath("./src/test/resources/keystore.jks") + + then: + first != settings.mutualAuthProviderHashcode() + + when: + settings.setBaseUrl("http://localhost:3001") + settings.setCertificateAlias("certificate1") + settings.setKeystorePath("./src/test/resources/another_keystore.jks") + + then: + first != settings.mutualAuthProviderHashcode() + + when: + settings.setBaseUrl("http://localhost:3001") + settings.setCertificateAlias("certificate1") + settings.setKeystorePath("./src/test/resources/keystore.jks") + + // Does not care about these properties + settings.setKeystorePassword("bobIsYourUncle".toCharArray()) + settings.setSkipHostNameVerify(true) + settings.setConfigurations(new ObjectMap().tap { put("uncle", "bob") }) + + then: + first == settings.mutualAuthProviderHashcode() + } +} diff --git a/gateway/src/main/java/com/mx/path/gateway/security/MutualAuthProviderFactory.java b/gateway/src/main/java/com/mx/path/gateway/security/MutualAuthProviderFactory.java index f0749836..a1be0454 100644 --- a/gateway/src/main/java/com/mx/path/gateway/security/MutualAuthProviderFactory.java +++ b/gateway/src/main/java/com/mx/path/gateway/security/MutualAuthProviderFactory.java @@ -12,22 +12,22 @@ */ @Deprecated public class MutualAuthProviderFactory { - private static Map mutualAuthProviderInstances = new HashMap<>(); + private static Map mutualAuthProviderInstances = new HashMap<>(); public static MutualAuthProvider build(ConnectionSettings settings) { if (settings == null || !isMutualAuthEnabled(settings)) { return null; } - if (!mutualAuthProviderInstances.containsKey(settings)) { + if (!mutualAuthProviderInstances.containsKey(settings.mutualAuthProviderHashcode())) { synchronized (MutualAuthProviderFactory.class) { - if (!mutualAuthProviderInstances.containsKey(settings)) { - mutualAuthProviderInstances.put(settings, buildProvider(settings)); + if (!mutualAuthProviderInstances.containsKey(settings.mutualAuthProviderHashcode())) { + mutualAuthProviderInstances.put(settings.mutualAuthProviderHashcode(), buildProvider(settings)); } } } - return mutualAuthProviderInstances.get(settings); + return mutualAuthProviderInstances.get(settings.mutualAuthProviderHashcode()); } public static void validateSettings(ConnectionSettings settings) throws FieldSettingsValidationError { diff --git a/http/src/main/java/com/mx/path/api/connect/http/certificates/MutualAuthProviderFactory.java b/http/src/main/java/com/mx/path/api/connect/http/certificates/MutualAuthProviderFactory.java index 45ae9dce..faebd957 100644 --- a/http/src/main/java/com/mx/path/api/connect/http/certificates/MutualAuthProviderFactory.java +++ b/http/src/main/java/com/mx/path/api/connect/http/certificates/MutualAuthProviderFactory.java @@ -8,22 +8,22 @@ import com.mx.common.lang.Strings; public class MutualAuthProviderFactory { - private static Map mutualAuthProviderInstances = new HashMap<>(); + private static Map mutualAuthProviderInstances = new HashMap<>(); public static MutualAuthProvider build(ConnectionSettings settings) { if (settings == null || !isMutualAuthEnabled(settings)) { return null; } - if (!mutualAuthProviderInstances.containsKey(settings)) { + if (!mutualAuthProviderInstances.containsKey(settings.mutualAuthProviderHashcode())) { synchronized (MutualAuthProviderFactory.class) { - if (!mutualAuthProviderInstances.containsKey(settings)) { - mutualAuthProviderInstances.put(settings, buildProvider(settings)); + if (!mutualAuthProviderInstances.containsKey(settings.mutualAuthProviderHashcode())) { + mutualAuthProviderInstances.put(settings.mutualAuthProviderHashcode(), buildProvider(settings)); } } } - return mutualAuthProviderInstances.get(settings); + return mutualAuthProviderInstances.get(settings.mutualAuthProviderHashcode()); } public static void validateSettings(ConnectionSettings settings) throws FieldSettingsValidationError { diff --git a/release-please-config.json b/release-please-config.json deleted file mode 100644 index 69fef29d..00000000 --- a/release-please-config.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "bootstrap-sha": "f57a50214ba81064f04a1aee0d8add71d9b01fbb", - "release-type": "simple", - "prerelease": false, - "packages": { - ".": { - "extra-files": [ - "build.gradle", - "README.md" - ] - } - } -}