Skip to content

Commit ef4c9d5

Browse files
committed
Introduce mTLS support
Please note that this feature is in preview.
1 parent 6f0462f commit ef4c9d5

File tree

54 files changed

+2467
-166
lines changed

Some content is hidden

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

54 files changed

+2467
-166
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: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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.concurrent.CompletionStage;
21+
import org.neo4j.driver.util.Preview;
22+
23+
/**
24+
* A manager of {@link ClientCertificate} instances used by the driver for mTLS.
25+
* <p>
26+
* The driver uses the {@link ClientCertificate} supplied by the manager for setting up new connections. Therefore,
27+
* a change of the certificate affects new connections only.
28+
* <p>
29+
* For efficiency reasons, the driver will only reload the certificate and the key from the files when the
30+
* {@code hasUpdate} flag is set to {@literal true}. See {@link ClientCertificates#of(File, File, boolean)} and
31+
* {@link ClientCertificates#of(File, File, String, boolean)}.
32+
* <p>
33+
* The manager must never return {@literal null} or {@link CompletionStage} completing with {@literal null}.
34+
* <p>
35+
* All implementations of this interface must be thread-safe and non-blocking for caller threads. For instance, IO
36+
* operations must not done on the calling thread.
37+
* @since 5.19
38+
*/
39+
@Preview(name = "mTLS")
40+
public interface ClientCertificateManager {
41+
/**
42+
* Returns a {@link CompletionStage} of the {@link ClientCertificate}.
43+
* @return the certificate stage, must not be {@literal null} or complete with {@literal null}
44+
*/
45+
CompletionStage<ClientCertificate> getClientCertificate();
46+
}
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 updating its {@link ClientCertificate} using the
33+
* {@link RotatingClientCertificateManager#update(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: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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 org.neo4j.driver.internal.InternalClientCertificate;
21+
import org.neo4j.driver.util.Preview;
22+
23+
/**
24+
* Creates new instances of {@link ClientCertificate}.
25+
* @since 5.19
26+
*/
27+
@Preview(name = "mTLS")
28+
public final class ClientCertificates {
29+
private ClientCertificates() {}
30+
31+
/**
32+
* Creates a new instance of {@link ClientCertificate} with certificate {@link File} and private key {@link File}.
33+
* @param certificate the certificate file
34+
* @param privateKey the key file
35+
* @param hasUpdate indicates if the files have changed and must be reloaded
36+
* @return the client certificate
37+
*/
38+
public static ClientCertificate of(File certificate, File privateKey, boolean hasUpdate) {
39+
return new InternalClientCertificate(certificate, privateKey, null, hasUpdate);
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
45+
* @param privateKey the key file
46+
* @param password the key password
47+
* @param hasUpdate indicates if the files have changed and must be reloaded
48+
* @return the client certificate
49+
*/
50+
public static ClientCertificate of(File certificate, File privateKey, String password, boolean hasUpdate) {
51+
return new InternalClientCertificate(certificate, privateKey, password, hasUpdate);
52+
}
53+
}

0 commit comments

Comments
 (0)