Skip to content

Commit 7e43d80

Browse files
author
sgonzalezMSFT
committed
Make Account internal. Add ClientCrendential interfaces
1 parent 0078e1a commit 7e43d80

File tree

9 files changed

+79
-80
lines changed

9 files changed

+79
-80
lines changed

src/main/java/com/microsoft/aad/msal4j/Account.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
@Getter
1717
@Setter
1818
@AllArgsConstructor
19-
public class Account implements IAccount {
19+
class Account implements IAccount {
2020

2121
String homeAccountId;
2222

src/main/java/com/microsoft/aad/msal4j/AsymmetricKeyCredential.java

Lines changed: 1 addition & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -24,33 +24,16 @@
2424
import lombok.experimental.Accessors;
2525
import org.apache.commons.codec.binary.Base64;
2626

27-
/**
28-
* Credential type containing X509 public certificate and RSA private key.
29-
*/
30-
public final class AsymmetricKeyCredential implements IClientCredential{
27+
final class AsymmetricKeyCredential implements IAsymmetricKeyCredential {
3128

3229
private final static int MIN_KEY_SIZE_IN_BITS = 2048;
3330

34-
/**
35-
* Returns private key of the credential.
36-
*
37-
* @return private key.
38-
*/
3931
@Accessors(fluent = true)
4032
@Getter
4133
private final PrivateKey key;
4234

4335
private final X509Certificate publicCertificate;
4436

45-
/**
46-
* Constructor to create credential with client id, private key and public
47-
* certificate.
48-
*
49-
* @param key
50-
* RSA private key to sign the assertion.
51-
* @param publicCertificate
52-
* Public certificate used for thumb print.
53-
*/
5437
private AsymmetricKeyCredential(final PrivateKey key, final X509Certificate publicCertificate) {
5538
if (key == null) {
5639
throw new NullPointerException("PrivateKey is null or empty");
@@ -86,45 +69,16 @@ else if("sun.security.mscapi.RSAPrivateKey".equals(key.getClass().getName())){
8669
this.publicCertificate = publicCertificate;
8770
}
8871

89-
/**
90-
* Base64 encoded hash of the the public certificate.
91-
*
92-
* @return base64 encoded string
93-
* @throws CertificateEncodingException if an encoding error occurs
94-
* @throws NoSuchAlgorithmException if requested algorithm is not available in the environment
95-
*/
9672
public String publicCertificateHash()
9773
throws CertificateEncodingException, NoSuchAlgorithmException {
9874
return Base64.encodeBase64String(AsymmetricKeyCredential
9975
.getHash(this.publicCertificate.getEncoded()));
10076
}
10177

102-
/**
103-
* Base64 encoded public certificate.
104-
*
105-
* @return base64 encoded string
106-
* @throws CertificateEncodingException if an encoding error occurs
107-
*/
10878
public String publicCertificate() throws CertificateEncodingException {
10979
return Base64.encodeBase64String(this.publicCertificate.getEncoded());
11080
}
11181

112-
/**
113-
* Static method to create KeyCredential instance.
114-
*
115-
* @param pkcs12Certificate
116-
* PKCS12 certificate stream containing public and private key.
117-
* Caller is responsible for handling the input stream.
118-
* @param password
119-
* certificate password
120-
* @return KeyCredential instance
121-
* @throws KeyStoreException {@link KeyStoreException}
122-
* @throws NoSuchProviderException {@link NoSuchProviderException}
123-
* @throws NoSuchAlgorithmException {@link NoSuchAlgorithmException}
124-
* @throws CertificateException {@link CertificateException}
125-
* @throws IOException {@link IOException}
126-
* @throws UnrecoverableKeyException {@link UnrecoverableKeyException}
127-
*/
12882
static AsymmetricKeyCredential create(final InputStream pkcs12Certificate, final String password)
12983
throws KeyStoreException, NoSuchProviderException,
13084
NoSuchAlgorithmException, CertificateException, IOException, UnrecoverableKeyException {
@@ -139,15 +93,6 @@ static AsymmetricKeyCredential create(final InputStream pkcs12Certificate, final
13993
return create(key, publicCertificate);
14094
}
14195

142-
/**
143-
* Static method to create KeyCredential instance.
144-
*
145-
* @param key
146-
* RSA private key to sign the assertion.
147-
* @param publicCertificate
148-
* Public certificate used for thumb print.
149-
* @return KeyCredential instance
150-
*/
15196
static AsymmetricKeyCredential create(final PrivateKey key, final X509Certificate publicCertificate) {
15297
return new AsymmetricKeyCredential(key, publicCertificate);
15398
}

src/main/java/com/microsoft/aad/msal4j/ClientAssertion.java

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,14 @@
88
import lombok.Getter;
99
import lombok.experimental.Accessors;
1010

11-
/**
12-
* Credential type containing an assertion of type
13-
* "urn:ietf:params:oauth:token-type:jwt".
14-
*/
1511
@Accessors(fluent = true)
1612
@Getter
1713
@EqualsAndHashCode
18-
public final class ClientAssertion implements IClientCredential{
14+
final class ClientAssertion implements IClientAssertion {
1915

20-
public static final String assertionType = JWTAuthentication.CLIENT_ASSERTION_TYPE;
16+
static final String assertionType = JWTAuthentication.CLIENT_ASSERTION_TYPE;
2117
private final String assertion;
2218

23-
/**
24-
* Constructor to create credential with a jwt token encoded as a base64 url
25-
* encoded string.
26-
*
27-
* @param assertion The jwt used as credential.
28-
*/
2919
ClientAssertion(final String assertion) {
3020
if (StringHelper.isBlank(assertion)) {
3121
throw new NullPointerException("assertion");

src/main/java/com/microsoft/aad/msal4j/ClientCredentialFactory.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class ClientCredentialFactory {
1919
* @param secret secret of application requesting a token
2020
* @return {@link ClientSecret}
2121
*/
22-
public static IClientCredential createFromSecret(String secret){
22+
public static IClientSecret createFromSecret(String secret){
2323
return new ClientSecret(secret);
2424
}
2525

@@ -35,7 +35,7 @@ public static IClientCredential createFromSecret(String secret){
3535
* @throws NoSuchProviderException
3636
* @throws IOException
3737
*/
38-
public static IClientCredential createFromCertificate(final InputStream pkcs12Certificate, final String password)
38+
public static IAsymmetricKeyCredential createFromCertificate(final InputStream pkcs12Certificate, final String password)
3939
throws CertificateException, UnrecoverableKeyException, NoSuchAlgorithmException,
4040
KeyStoreException, NoSuchProviderException, IOException {
4141
return AsymmetricKeyCredential.create(pkcs12Certificate, password);
@@ -47,7 +47,7 @@ public static IClientCredential createFromCertificate(final InputStream pkcs12Ce
4747
* @param publicCertificate x509 public certificate used for thumbprint
4848
* @return {@link AsymmetricKeyCredential}
4949
*/
50-
public static IClientCredential createFromCertificate(final PrivateKey key, final X509Certificate publicCertificate) {
50+
public static IAsymmetricKeyCredential createFromCertificate(final PrivateKey key, final X509Certificate publicCertificate) {
5151
return AsymmetricKeyCredential.create(key, publicCertificate);
5252
}
5353

@@ -56,7 +56,7 @@ public static IClientCredential createFromCertificate(final PrivateKey key, fina
5656
* @param clientAssertion Jwt token encoded as a base64 URL encoded string
5757
* @return {@link ClientAssertion}
5858
*/
59-
public static IClientCredential createFromClientAssertion(String clientAssertion){
59+
public static IClientAssertion createFromClientAssertion(String clientAssertion){
6060
return new ClientAssertion(clientAssertion);
6161
}
6262
}

src/main/java/com/microsoft/aad/msal4j/ClientSecret.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,8 @@
77
import lombok.Getter;
88
import lombok.experimental.Accessors;
99

10-
11-
/**
12-
* Representation of client credential containing a secret in string format
13-
*/
1410
@EqualsAndHashCode
15-
public final class ClientSecret implements IClientCredential {
16-
11+
final class ClientSecret implements IClientSecret {
1712

1813
@Accessors(fluent = true)
1914
@Getter
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package com.microsoft.aad.msal4j;
5+
6+
import java.security.NoSuchAlgorithmException;
7+
import java.security.PrivateKey;
8+
import java.security.cert.CertificateEncodingException;
9+
10+
/**
11+
* Credential type containing X509 public certificate and RSA private key.
12+
*/
13+
public interface IAsymmetricKeyCredential extends IClientCredential{
14+
15+
/**
16+
* Returns private key of the credential.
17+
*
18+
* @return private key.
19+
*/
20+
PrivateKey key();
21+
22+
/**
23+
* Base64 encoded hash of the the public certificate.
24+
*
25+
* @return base64 encoded string
26+
* @throws CertificateEncodingException if an encoding error occurs
27+
* @throws NoSuchAlgorithmException if requested algorithm is not available in the environment
28+
*/
29+
String publicCertificateHash() throws CertificateEncodingException, NoSuchAlgorithmException;
30+
31+
/**
32+
* Base64 encoded public certificate.
33+
*
34+
* @return base64 encoded string
35+
* @throws CertificateEncodingException if an encoding error occurs
36+
*/
37+
String publicCertificate() throws CertificateEncodingException;
38+
}

src/main/java/com/microsoft/aad/msal4j/IClientApplicationBase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
/**
1414
* Interface representing an application for which tokens can be acquired.
1515
*/
16-
public interface IClientApplicationBase {
16+
interface IClientApplicationBase {
1717

1818
String DEFAULT_AUTHORITY = "https://login.microsoftonline.com/common/";
1919

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package com.microsoft.aad.msal4j;
5+
6+
/**
7+
* Credential type containing an assertion of type
8+
* "urn:ietf:params:oauth:token-type:jwt".
9+
*/
10+
public interface IClientAssertion extends IClientCredential{
11+
12+
/**
13+
* @return Jwt token encoded as a base64 URL encoded string
14+
*/
15+
String assertion();
16+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package com.microsoft.aad.msal4j;
5+
6+
/**
7+
* Representation of client credential containing a secret in string format
8+
*/
9+
public interface IClientSecret extends IClientCredential{
10+
11+
/**
12+
* @return secret secret of application requesting a token
13+
*/
14+
String clientSecret();
15+
}

0 commit comments

Comments
 (0)