Skip to content

Commit 79a9adf

Browse files
Fix #1039
Make client certificate mapper support Jakarta EE; using a single library that can support SB2, SB3, JEE and JakartaEE apps
1 parent 3bf69dd commit 79a9adf

File tree

4 files changed

+4
-59
lines changed

4 files changed

+4
-59
lines changed

config/client_certificate_mapper.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515

1616
# Container security provider configuration
1717
---
18-
version: 1.+
18+
version: 2.+
1919
version_lines:
20+
- 1.+
2021
- 2.+
21-
repository_root: "https://anthonydahanne.github.io/java-buildpack-client-certificate-mapper"
22-
javax_forced: false
22+
repository_root: "{default.repository.root}/client-certificate-mapper"

docs/framework-client_certificate_mapper.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
# Client Certificate Mapper
22
The Client Certificate Mapper Framework adds a Servlet Filter to applications that will that maps the `X-Forwarded-Client-Cert` to the `javax|jakarta.servlet.request.X509Certificate` Servlet attribute.
33

4-
The Client Certificate Mapper Framework will download a helper library, [java-buildpack-client-certificate-mapper][library repository], that will enrich Spring Boot applications classpath.
4+
The Client Certificate Mapper Framework will download a helper library, [java-buildpack-client-certificate-mapper][library repository], that will enrich Spring Boot (2 and 3), as well as JEE / JakartaEE applications classpath with a servlet filter.
55

6-
If the app you're deploying is using Spring Boot 2 or earlier, the latest 1.x version (`javax` support) from [the listing][this listing] will be downloaded.
7-
8-
If the app you're deploying is using Spring Boot 3, the latest 2.x version (`jakarta` support) from [the listing][this listing] will be downloaded.
96
<table>
107
<tr>
118
<td><strong>Detection Criterion</strong></td>
@@ -27,7 +24,6 @@ The framework can be configured by modifying the [`config/client_certificate_map
2724
|-------------------| -----------
2825
| `repository_root` | The URL of the Container Customizer repository index ([details][repositories]).
2926
| `version` | The version of Container Customizer to use. Candidate versions can be found in [this listing][].
30-
| `javax_forced` | You can force the download of the v1.x version of the [library][library repository] which is based on `javax` naming.
3127

3228
## Servlet Filter
3329
The [Servlet Filter][] added by this framework maps the `X-Forwarded-Client-Cert` to the `javax.servlet.request.X509Certificate` Servlet attribute for each request. The `X-Forwarded-Client-Cert` header is contributed by the Cloud Foundry Router and contains the any TLS certificate presented by a client for mututal TLS authentication. This certificate can then be used by any standard Java security framework to establish authentication and authorization for a request.

lib/java_buildpack/framework/client_certificate_mapper.rb

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,15 @@
1717

1818
require 'java_buildpack/component/versioned_dependency_component'
1919
require 'java_buildpack/framework'
20-
require 'java_buildpack/util/spring_boot_utils'
2120

2221
module JavaBuildpack
2322
module Framework
2423

2524
# Encapsulates the functionality for contributing an mTLS client certificate mapper to the application.
2625
class ClientCertificateMapper < JavaBuildpack::Component::VersionedDependencyComponent
27-
include JavaBuildpack::Util
28-
29-
def initialize(context)
30-
@spring_boot_utils = JavaBuildpack::Util::SpringBootUtils.new
31-
@configuration = context[:configuration]
32-
super(context)
33-
end
3426

3527
# (see JavaBuildpack::Component::BaseComponent#compile)
3628
def compile
37-
if spring_boot_3? && !@configuration['javax_forced']
38-
spring_boot_3_configuration = @configuration
39-
spring_boot_3_configuration['version'] = '2.+'
40-
@version, @uri = JavaBuildpack::Repository::ConfiguredItem.find_item(@component_name, spring_boot_3_configuration)
41-
end
4229
download_jar
4330
@droplet.additional_libraries << (@droplet.sandbox + jar_name)
4431
end
@@ -55,14 +42,6 @@ def supports?
5542
true
5643
end
5744

58-
private
59-
60-
def spring_boot_3?
61-
# print '@application.details: ' + @application.details.to_s
62-
@spring_boot_utils.is?(@application) && Gem::Version.new((@spring_boot_utils.version @application)).release >=
63-
Gem::Version.new('3.0.0')
64-
end
65-
6645
end
6746

6847
end

spec/java_buildpack/framework/client_certificate_mapper_spec.rb

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -33,36 +33,6 @@
3333

3434
expect(sandbox + "client_certificate_mapper-#{version}.jar").to exist
3535
expect(additional_libraries).to include(sandbox + "client_certificate_mapper-#{version}.jar")
36-
# version was not patched by the compile step
37-
expect(configuration).to eq({})
38-
end
39-
40-
41-
it 'configures client certificate mapper to download version 2.+ during compile of spring boot 3 app',
42-
app_fixture: 'framework_java_cf_boot_3',
43-
cache_fixture: 'stub-client-certificate-mapper.jar' do
44-
45-
component.compile
46-
47-
expect(sandbox + "client_certificate_mapper-#{version}.jar").to exist
48-
expect(additional_libraries).to include(sandbox + "client_certificate_mapper-#{version}.jar")
49-
# version of the dep. was forced to 2.+ by the compile step, because Spring Boot 3 was found
50-
expect(configuration).to eq({ 'version' => '2.+' })
51-
end
52-
53-
context 'user forced javax to be used' do
54-
let(:configuration) { { 'javax_forced' => true } }
55-
it 'configures client certificate mapper to download version 1 during compile of spring boot 3 app ',
56-
app_fixture: 'framework_java_cf_boot_3',
57-
cache_fixture: 'stub-client-certificate-mapper.jar' do
58-
59-
component.compile
60-
61-
expect(sandbox + "client_certificate_mapper-#{version}.jar").to exist
62-
expect(additional_libraries).to include(sandbox + "client_certificate_mapper-#{version}.jar")
63-
# user prevented version 2.+, forcing javax
64-
expect(configuration).to eq({ 'javax_forced' => true })
65-
end
6636
end
6737

6838
it 'adds the jar to the additional libraries during release',

0 commit comments

Comments
 (0)