Skip to content

Commit 3bf69dd

Browse files
Fix #1039: Make client certificate mapper support Spring Boot 3
* let it choose v2 of the jar when SB3 is detected * otherwise, continue as before with default v1
1 parent 9e24737 commit 3bf69dd

File tree

4 files changed

+66
-5
lines changed

4 files changed

+66
-5
lines changed

config/client_certificate_mapper.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,7 @@
1616
# Container security provider configuration
1717
---
1818
version: 1.+
19-
repository_root: "{default.repository.root}/client-certificate-mapper"
19+
version_lines:
20+
- 2.+
21+
repository_root: "https://anthonydahanne.github.io/java-buildpack-client-certificate-mapper"
22+
javax_forced: false

docs/framework-client_certificate_mapper.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# Client Certificate Mapper
2-
The Client Certificate Mapper Framework adds a Servlet Filter to applications that will that maps the `X-Forwarded-Client-Cert` to the `javax.servlet.request.X509Certificate` Servlet attribute.
2+
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.
5+
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.
49
<table>
510
<tr>
611
<td><strong>Detection Criterion</strong></td>
@@ -18,10 +23,11 @@ For general information on configuring the buildpack, including how to specify c
1823

1924
The framework can be configured by modifying the [`config/client_certificate_mapper.yml`][] file in the buildpack fork. The framework uses the [`Repository` utility support][repositories] and so it supports the [version syntax][] defined there.
2025

21-
| Name | Description
22-
| ---- | -----------
26+
| Name | Description
27+
|-------------------| -----------
2328
| `repository_root` | The URL of the Container Customizer repository index ([details][repositories]).
24-
| `version` | The version of Container Customizer to use. Candidate versions can be found in [this listing][].
29+
| `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.
2531

2632
## Servlet Filter
2733
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.
@@ -32,3 +38,4 @@ The [Servlet Filter][] added by this framework maps the `X-Forwarded-Client-Cert
3238
[Servlet Filter]: https://github.com/cloudfoundry/java-buildpack-client-certificate-mapper
3339
[this listing]: http://download.pivotal.io.s3.amazonaws.com/container-security-provider/index.yml
3440
[version syntax]: extending-repositories.md#version-syntax-and-ordering
41+
[library repository]: https://github.com:cloudfoundry/java-buildpack-client-certificate-mapper.git

lib/java_buildpack/framework/client_certificate_mapper.rb

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

1818
require 'java_buildpack/component/versioned_dependency_component'
1919
require 'java_buildpack/framework'
20+
require 'java_buildpack/util/spring_boot_utils'
2021

2122
module JavaBuildpack
2223
module Framework
2324

2425
# Encapsulates the functionality for contributing an mTLS client certificate mapper to the application.
2526
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
2634

2735
# (see JavaBuildpack::Component::BaseComponent#compile)
2836
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
2942
download_jar
3043
@droplet.additional_libraries << (@droplet.sandbox + jar_name)
3144
end
@@ -42,6 +55,14 @@ def supports?
4255
true
4356
end
4457

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+
4566
end
4667

4768
end

spec/java_buildpack/framework/client_certificate_mapper_spec.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,36 @@
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
3666
end
3767

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

0 commit comments

Comments
 (0)