Skip to content

Commit 2db210a

Browse files
authored
Introduce mTLS support (#1543)
* Introduce mTLS support Please note that this feature is in preview. * Make hasUpdate unnecessary * Fix inspection errors
1 parent 6f0462f commit 2db210a

File tree

58 files changed

+2865
-167
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+2865
-167
lines changed

benchkit-backend/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<artifactId>neo4j-java-driver-parent</artifactId>
99
<groupId>org.neo4j.driver</groupId>
10-
<version>5.18-SNAPSHOT</version>
10+
<version>5.19-SNAPSHOT</version>
1111
</parent>
1212

1313
<artifactId>benchkit-backend</artifactId>

bundle/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>org.neo4j.driver</groupId>
88
<artifactId>neo4j-java-driver-parent</artifactId>
9-
<version>5.18-SNAPSHOT</version>
9+
<version>5.19-SNAPSHOT</version>
1010
<relativePath>..</relativePath>
1111
</parent>
1212

driver/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>org.neo4j.driver</groupId>
88
<artifactId>neo4j-java-driver-parent</artifactId>
9-
<version>5.18-SNAPSHOT</version>
9+
<version>5.19-SNAPSHOT</version>
1010
</parent>
1111

1212
<artifactId>neo4j-java-driver</artifactId>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright (c) "Neo4j"
3+
* Neo4j Sweden AB [https://neo4j.com]
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.neo4j.driver;
18+
19+
import org.neo4j.driver.internal.InternalClientCertificate;
20+
import org.neo4j.driver.util.Preview;
21+
22+
/**
23+
* An opaque container for client certificate used for mTLS.
24+
* <p>
25+
* Use {@link ClientCertificates} to create new instances.
26+
* @since 5.19
27+
*/
28+
@Preview(name = "mTLS")
29+
public sealed interface ClientCertificate permits InternalClientCertificate {}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright (c) "Neo4j"
3+
* Neo4j Sweden AB [https://neo4j.com]
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.neo4j.driver;
18+
19+
import java.util.concurrent.CompletionStage;
20+
import org.neo4j.driver.util.Preview;
21+
22+
/**
23+
* A manager of {@link ClientCertificate} instances used by the driver for mTLS.
24+
* <p>
25+
* The driver uses the {@link ClientCertificate} supplied by the manager for setting up new connections. Therefore,
26+
* a change of the certificate affects subsequent new connections only.
27+
* <p>
28+
* The manager must never return {@literal null}. Exceptions must be emitted via the {@link CompletionStage} only.
29+
* <p>
30+
* All implementations of this interface must be thread-safe and non-blocking for caller threads. For instance, IO
31+
* operations must not done on the calling thread.
32+
* @since 5.19
33+
*/
34+
@Preview(name = "mTLS")
35+
public interface ClientCertificateManager {
36+
/**
37+
* Returns a {@link CompletionStage} of a new {@link ClientCertificate}.
38+
* <p>
39+
* The first {@link CompletionStage} supplied to the driver must not complete with {@literal null} to ensure the
40+
* driver has the initial {@link ClientCertificate}.
41+
* <p>
42+
* Afterwards, the {@link CompletionStage} may complete with {@literal null} to indicate no update. If the
43+
* {@link CompletionStage} completes with {@link ClientCertificate}, the driver loads the supplied
44+
* {@link ClientCertificate}.
45+
* @return the certificate stage, must not be {@literal null}
46+
*/
47+
CompletionStage<ClientCertificate> getClientCertificate();
48+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright (c) "Neo4j"
3+
* Neo4j Sweden AB [https://neo4j.com]
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.neo4j.driver;
18+
19+
import org.neo4j.driver.internal.InternalRotatingClientCertificateManager;
20+
import org.neo4j.driver.util.Preview;
21+
22+
/**
23+
* Implementations of {@link ClientCertificateManager}.
24+
*
25+
* @since 5.19
26+
*/
27+
@Preview(name = "mTLS")
28+
public final class ClientCertificateManagers {
29+
private ClientCertificateManagers() {}
30+
31+
/**
32+
* Returns a {@link RotatingClientCertificateManager} that supports rotating its {@link ClientCertificate} using the
33+
* {@link RotatingClientCertificateManager#rotate(ClientCertificate)} method.
34+
*
35+
* @param clientCertificate an initial certificate, must not be {@literal null}
36+
* @return a new manager
37+
*/
38+
public static RotatingClientCertificateManager rotating(ClientCertificate clientCertificate) {
39+
return new InternalRotatingClientCertificateManager(clientCertificate);
40+
}
41+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright (c) "Neo4j"
3+
* Neo4j Sweden AB [https://neo4j.com]
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.neo4j.driver;
18+
19+
import java.io.File;
20+
import java.util.Objects;
21+
import org.neo4j.driver.internal.InternalClientCertificate;
22+
import org.neo4j.driver.util.Preview;
23+
24+
/**
25+
* Creates new instances of {@link ClientCertificate}.
26+
* @since 5.19
27+
*/
28+
@Preview(name = "mTLS")
29+
public final class ClientCertificates {
30+
private ClientCertificates() {}
31+
32+
/**
33+
* Creates a new instance of {@link ClientCertificate} with certificate {@link File} and private key {@link File}.
34+
* @param certificate the certificate file, must not be {@literal null}
35+
* @param privateKey the key file, must not be {@literal null}
36+
* @return the client certificate
37+
*/
38+
public static ClientCertificate of(File certificate, File privateKey) {
39+
return of(certificate, privateKey, null);
40+
}
41+
42+
/**
43+
* Creates a new instance of {@link ClientCertificate} with certificate {@link File}, private key {@link File} and key password.
44+
* @param certificate the certificate file, must not be {@literal null}
45+
* @param privateKey the key file, must not be {@literal null}
46+
* @param password the key password
47+
* @return the client certificate
48+
*/
49+
public static ClientCertificate of(File certificate, File privateKey, String password) {
50+
Objects.requireNonNull(certificate);
51+
Objects.requireNonNull(privateKey);
52+
return new InternalClientCertificate(certificate, privateKey, password);
53+
}
54+
}

0 commit comments

Comments
 (0)