Skip to content

Commit b17c880

Browse files
author
sgonzalezMSFT
committed
Make AsymetricKeyCredential, ClientSecret, ClientAssertion Constructors
private
1 parent 8fd83a8 commit b17c880

File tree

5 files changed

+15
-16
lines changed

5 files changed

+15
-16
lines changed

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
*/
3030
public final class AsymmetricKeyCredential implements IClientCredential{
3131

32-
public final static int MIN_KEY_SIZE_IN_BITS = 2048;
32+
private final static int MIN_KEY_SIZE_IN_BITS = 2048;
3333

3434
/**
3535
* Returns private key of the credential.
@@ -93,23 +93,22 @@ else if("sun.security.mscapi.RSAPrivateKey".equals(key.getClass().getName())){
9393
* @throws CertificateEncodingException if an encoding error occurs
9494
* @throws NoSuchAlgorithmException if requested algorithm is not available in the environment
9595
*/
96-
public String getPublicCertificateHash()
96+
public String publicCertificateHash()
9797
throws CertificateEncodingException, NoSuchAlgorithmException {
9898
return Base64.encodeBase64String(AsymmetricKeyCredential
9999
.getHash(this.publicCertificate.getEncoded()));
100100
}
101101

102102
/**
103103
* Base64 encoded public certificate.
104-
*
104+
*
105105
* @return base64 encoded string
106106
* @throws CertificateEncodingException if an encoding error occurs
107107
*/
108108
public String publicCertificate() throws CertificateEncodingException {
109109
return Base64.encodeBase64String(this.publicCertificate.getEncoded());
110110
}
111111

112-
113112
/**
114113
* Static method to create KeyCredential instance.
115114
*
@@ -126,7 +125,7 @@ public String publicCertificate() throws CertificateEncodingException {
126125
* @throws IOException {@link IOException}
127126
* @throws UnrecoverableKeyException {@link UnrecoverableKeyException}
128127
*/
129-
public static AsymmetricKeyCredential create(final InputStream pkcs12Certificate, final String password)
128+
static AsymmetricKeyCredential create(final InputStream pkcs12Certificate, final String password)
130129
throws KeyStoreException, NoSuchProviderException,
131130
NoSuchAlgorithmException, CertificateException, IOException, UnrecoverableKeyException {
132131
final KeyStore keystore = KeyStore.getInstance("PKCS12", "SunJSSE");
@@ -149,7 +148,7 @@ public static AsymmetricKeyCredential create(final InputStream pkcs12Certificate
149148
* Public certificate used for thumb print.
150149
* @return KeyCredential instance
151150
*/
152-
public static AsymmetricKeyCredential create(final PrivateKey key, final X509Certificate publicCertificate) {
151+
static AsymmetricKeyCredential create(final PrivateKey key, final X509Certificate publicCertificate) {
153152
return new AsymmetricKeyCredential(key, publicCertificate);
154153
}
155154

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
@Accessors(fluent = true)
1616
@Getter
1717
@EqualsAndHashCode
18-
final class ClientAssertion implements IClientCredential{
18+
public final class ClientAssertion implements IClientCredential{
1919

2020
public static final String assertionType = JWTAuthentication.CLIENT_ASSERTION_TYPE;
2121
private final String assertion;

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
public class ClientCredentialFactory {
1616

1717
/**
18-
*
18+
* Static method to create a {@link ClientSecret} instance from a client secret
1919
* @param secret secret of application requesting a token
2020
* @return {@link ClientSecret}
2121
*/
@@ -24,10 +24,10 @@ public static IClientCredential createFromSecret(String secret){
2424
}
2525

2626
/**
27-
*
27+
* Static method to create a {@link AsymmetricKeyCredential} instance from a certificate
2828
* @param pkcs12Certificate InputStream containing PCKS12 formatted certificate
2929
* @param password certificate password
30-
* @return {@link IClientCredential}
30+
* @return {@link AsymmetricKeyCredential}
3131
* @throws CertificateException
3232
* @throws UnrecoverableKeyException
3333
* @throws NoSuchAlgorithmException
@@ -42,19 +42,19 @@ public static IClientCredential createFromCertificate(final InputStream pkcs12Ce
4242
}
4343

4444
/**
45-
*
45+
* Static method to create a {@link AsymmetricKeyCredential} instance.
4646
* @param key RSA private key to sign the assertion.
4747
* @param publicCertificate x509 public certificate used for thumbprint
48-
* @return {@link IClientCredential}
48+
* @return {@link AsymmetricKeyCredential}
4949
*/
5050
public static IClientCredential createFromCertificate(final PrivateKey key, final X509Certificate publicCertificate) {
5151
return AsymmetricKeyCredential.create(key, publicCertificate);
5252
}
5353

5454
/**
55-
*
55+
* Static method to create a {@link ClientAssertion} instance.
5656
* @param clientAssertion Jwt token encoded as a base64 URL encoded string
57-
* @return {@link IClientCredential}
57+
* @return {@link ClientAssertion}
5858
*/
5959
public static IClientCredential createFromClientAssertion(String clientAssertion){
6060
return new ClientAssertion(clientAssertion);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public final class ClientSecret implements IClientCredential {
2525
* @param clientSecret
2626
* Secret of the client requesting the token.
2727
*/
28-
public ClientSecret(final String clientSecret) {
28+
ClientSecret(final String clientSecret) {
2929
if (StringHelper.isBlank(clientSecret)) {
3030
throw new IllegalArgumentException("clientSecret is null or empty");
3131
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ static ClientAssertion buildJwt(String clientId, final AsymmetricKeyCredential c
5050

5151
JWSHeader.Builder builder = new Builder(JWSAlgorithm.RS256);
5252
builder.x509CertChain(certs);
53-
builder.x509CertThumbprint(new Base64URL(credential.getPublicCertificateHash()));
53+
builder.x509CertThumbprint(new Base64URL(credential.publicCertificateHash()));
5454

5555
jwt = new SignedJWT(builder.build(), claimsSet);
5656
final RSASSASigner signer = new RSASSASigner(credential.key());

0 commit comments

Comments
 (0)