Skip to content

Commit dcab27f

Browse files
committed
feat(mtls): Update Java docs.
1 parent 54108ff commit dcab27f

File tree

5 files changed

+53
-10
lines changed

5 files changed

+53
-10
lines changed

oauth2_http/java/com/google/auth/mtls/ContextAwareMetadataJson.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,14 @@
3535
import com.google.common.collect.ImmutableList;
3636
import java.util.List;
3737

38-
/** Data class representing context_aware_metadata.json file. */
38+
/**
39+
* Data class representing context_aware_metadata.json file. This is meant for internal Google Cloud
40+
* usage and behavior may be changed without warning.
41+
*
42+
* <p>Note: This implementation is duplicated from the existing ContextAwareMetadataJson found in
43+
* the Gax library. The Gax library version of ContextAwareMetadataJson will be marked as deprecated
44+
* in the future.
45+
*/
3946
public class ContextAwareMetadataJson extends GenericJson {
4047
/** Cert provider command */
4148
@Key("cert_provider_command")

oauth2_http/java/com/google/auth/mtls/DefaultMtlsProviderFactory.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ public class DefaultMtlsProviderFactory {
4040
* creating a {@link SecureConnectProvider}. If the secure connect provider also fails, it throws
4141
* the original {@link com.google.auth.mtls.CertificateSourceUnavailableException}.
4242
*
43+
* <p>This is only meant to be used internally by Google Cloud libraries, and the public facing
44+
* methods may be changed without notice, and have no guarantee of backwards compatibility.
45+
*
4346
* @return an instance of {@link MtlsProvider}.
4447
* @throws com.google.auth.mtls.CertificateSourceUnavailableException if neither provider can be
4548
* created.

oauth2_http/java/com/google/auth/mtls/MtlsProvider.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,21 @@
4242
* https://github.com/googleapis/google-auth-library-java/issues/1758
4343
*/
4444
public interface MtlsProvider {
45-
/** Returns the mutual TLS key store. */
46-
KeyStore getKeyStore() throws IOException;
45+
/**
46+
* Returns a mutual TLS key store.
47+
*
48+
* @return KeyStore for configuring mTLS.
49+
* @throws CertificateSourceUnavailableException if the certificate source is unavailable (ex.
50+
* missing configuration file).
51+
* @throws IOException if a general I/O error occurs while creating the KeyStore
52+
*/
53+
KeyStore getKeyStore() throws CertificateSourceUnavailableException, IOException;
4754

48-
/** Returns true if the underlying certificate source is available. */
55+
/**
56+
* Returns true if the underlying certificate source is available.
57+
*
58+
* @throws IOException if a general I/O error occurs while determining certificate source
59+
* availability.
60+
*/
4961
boolean isCertificateSourceAvailable() throws IOException;
5062
}

oauth2_http/java/com/google/auth/mtls/SecureConnectProvider.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
* This class implements {@link MtlsProvider} for the Google Auth library transport layer via {@link
4949
* ContextAwareMetadataJson}. This is only meant to be used internally by Google Cloud libraries,
5050
* and the public facing methods may be changed without notice, and have no guarantee of backwards
51-
* compatability.
51+
* compatibility.
5252
*
5353
* <p>Note: This implementation is derived from the existing "MtlsProvider" found in the Gax
5454
* library, with two notable differences: 1) All logic associated with parsing environment variables
@@ -92,9 +92,16 @@ public SecureConnectProvider() {
9292
this(new DefaultProcessProvider(), DEFAULT_CONTEXT_AWARE_METADATA_PATH);
9393
}
9494

95-
/** The mutual TLS key store created with the default client certificate on device. */
95+
/**
96+
* Returns a mutual TLS key store backed by the certificate provided by the SecureConnect tool.
97+
*
98+
* @return a KeyStore containing the certificate provided by the SecureConnect tool.
99+
* @throws CertificateSourceUnavailableException if the certificate source is unavailable (ex.
100+
* missing configuration file).
101+
* @throws IOException if a general I/O error occurs while creating the KeyStore.
102+
*/
96103
@Override
97-
public KeyStore getKeyStore() throws IOException {
104+
public KeyStore getKeyStore() throws CertificateSourceUnavailableException, IOException {
98105
try (InputStream stream = new FileInputStream(metadataPath)) {
99106
return getKeyStore(stream, processProvider);
100107
} catch (InterruptedException e) {
@@ -109,6 +116,12 @@ public KeyStore getKeyStore() throws IOException {
109116
}
110117
}
111118

119+
/**
120+
* Returns true if the SecureConnect certificate source is available.
121+
*
122+
* @throws IOException if a general I/O error occurs while determining certificate source
123+
* availability
124+
*/
112125
@Override
113126
public boolean isCertificateSourceAvailable() throws IOException {
114127
try {

oauth2_http/java/com/google/auth/mtls/X509Provider.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
* This class implements {@link MtlsProvider} for the Google Auth library transport layer via {@link
4646
* WorkloadCertificateConfiguration}. This is only meant to be used internally by Google Cloud
4747
* libraries, and the public facing methods may be changed without notice, and have no guarantee of
48-
* backwards compatability.
48+
* backwards compatibility.
4949
*/
5050
public class X509Provider implements MtlsProvider {
5151
static final String CERTIFICATE_CONFIGURATION_ENV_VARIABLE = "GOOGLE_API_CERTIFICATE_CONFIG";
@@ -109,10 +109,12 @@ public String getCertificatePath() throws IOException {
109109
* </ul>
110110
*
111111
* @return a KeyStore containing the X.509 certificate specified by the certificate configuration.
112-
* @throws IOException if there is an error retrieving the certificate configuration.
112+
* @throws CertificateSourceUnavailableException if the certificate source is unavailable (ex.
113+
* missing configuration file)
114+
* @throws IOException if a general I/O error occurs while creating the KeyStore
113115
*/
114116
@Override
115-
public KeyStore getKeyStore() throws IOException {
117+
public KeyStore getKeyStore() throws CertificateSourceUnavailableException, IOException {
116118
WorkloadCertificateConfiguration workloadCertConfig = getWorkloadCertificateConfiguration();
117119

118120
// Read the certificate and private key file paths into streams.
@@ -133,6 +135,12 @@ public KeyStore getKeyStore() throws IOException {
133135
}
134136
}
135137

138+
/**
139+
* Returns true if the X509 certificate source is available.
140+
*
141+
* @throws IOException if a general I/O error occurs while determining certificate source
142+
* availability
143+
*/
136144
@Override
137145
public boolean isCertificateSourceAvailable() throws IOException {
138146
try {

0 commit comments

Comments
 (0)