Skip to content

Commit bcf5d5d

Browse files
authored
adding interfaces for public api (#39)
* adding interfaces for public api
1 parent dfa7f8d commit bcf5d5d

Some content is hidden

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

49 files changed

+844
-540
lines changed

pom.xml

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,24 @@
155155

156156
<build>
157157
<plugins>
158+
<plugin>
159+
<groupId>org.projectlombok</groupId>
160+
<artifactId>lombok-maven-plugin</artifactId>
161+
<version>1.18.2.0</version>
162+
<executions>
163+
<execution>
164+
<goals>
165+
<goal>delombok</goal>
166+
</goals>
167+
</execution>
168+
</executions>
169+
<configuration>
170+
<sourceDirectory>src/main/java</sourceDirectory>
171+
<outputDirectory>${project.build.directory}/delombok</outputDirectory>
172+
<addOutputDirectory>false</addOutputDirectory>
173+
</configuration>
174+
</plugin>
175+
158176
<plugin>
159177
<groupId>org.apache.maven.plugins</groupId>
160178
<artifactId>maven-jar-plugin</artifactId>
@@ -176,10 +194,14 @@
176194
<argLine>-noverify</argLine>
177195
</configuration>
178196
</plugin>
197+
179198
<plugin>
180199
<groupId>org.apache.maven.plugins</groupId>
181200
<artifactId>maven-javadoc-plugin</artifactId>
182-
<version>2.9.1</version>
201+
<version>3.1.0</version>
202+
<configuration>
203+
<sourcepath>${project.build.directory}/delombok</sourcepath>
204+
</configuration>
183205
<executions>
184206
<execution>
185207
<id>attach-javadocs</id>
@@ -224,6 +246,7 @@
224246
<plugin>
225247
<groupId>org.apache.maven.plugins</groupId>
226248
<artifactId>maven-compiler-plugin</artifactId>
249+
<version>3.7.0</version>
227250
<configuration>
228251
<source>8</source>
229252
<target>8</target>

src/integrationtest/java/com.microsoft.aad.msal4j/AuthorizationCodeIT.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -220,33 +220,31 @@ public void acquireTokenWithAuthorizationCode_B2C_Google(){
220220

221221
private void assertAcquireTokenAAD(LabResponse labResponse){
222222
String authCode = acquireAuthorizationCodeAutomated(labResponse, AuthorityType.AAD);
223-
AuthenticationResult result = acquireTokenInteractiveAAD(labResponse, authCode);
223+
IAuthenticationResult result = acquireTokenInteractiveAAD(labResponse, authCode);
224224

225225
Assert.assertNotNull(result);
226226
Assert.assertNotNull(result.accessToken());
227-
Assert.assertNotNull(result.refreshToken());
228227
Assert.assertNotNull(result.idToken());
229228
// TODO AuthenticationResult should have an getAccountInfo API
230229
// Assert.assertEquals(labResponse.getUser().getUpn(), result.getAccountInfo().getUsername());
231230
}
232231

233232
private void assertAcquireTokenB2C(LabResponse labResponse){
234233
String authCode = acquireAuthorizationCodeAutomated(labResponse, AuthorityType.B2C);
235-
AuthenticationResult result = acquireTokenInteractiveB2C(labResponse, authCode);
234+
IAuthenticationResult result = acquireTokenInteractiveB2C(labResponse, authCode);
236235

237236
Assert.assertNotNull(result);
238237
Assert.assertNotNull(result.accessToken());
239-
Assert.assertNotNull(result.refreshToken());
240238
Assert.assertNotNull(result.idToken());
241239
// TODO AuthenticationResult should have an getAccountInfo API
242240
// Assert.assertEquals(labResponse.getUser().getUpn(), result.getAccountInfo().getUsername());
243241
}
244242

245-
private AuthenticationResult acquireTokenInteractiveAAD(
243+
private IAuthenticationResult acquireTokenInteractiveAAD(
246244
LabResponse labResponse,
247245
String authCode){
248246

249-
AuthenticationResult result;
247+
IAuthenticationResult result;
250248
try {
251249
PublicClientApplication pca = PublicClientApplication.builder(
252250
labResponse.getAppId()).
@@ -267,9 +265,9 @@ private AuthenticationResult acquireTokenInteractiveAAD(
267265
return result;
268266
}
269267

270-
private AuthenticationResult acquireTokenInteractiveB2C(LabResponse labResponse,
268+
private IAuthenticationResult acquireTokenInteractiveB2C(LabResponse labResponse,
271269
String authCode) {
272-
AuthenticationResult result;
270+
IAuthenticationResult result;
273271
try{
274272
IClientCredential credential = ClientCredentialFactory.create("=]Y)_A7LX`]6\"]_PoD!)Lo24");
275273
ConfidentialClientApplication cca = ConfidentialClientApplication.builder(

src/integrationtest/java/com.microsoft.aad.msal4j/ClientCredentialsIT.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,13 @@ private void assertAcquireTokenCommon(String clientId, IClientCredential credent
6565
authority(TestConstants.AUTHORITY_MICROSOFT).
6666
build();
6767

68-
AuthenticationResult result = cca.acquireToken(ClientCredentialParameters
68+
IAuthenticationResult result = cca.acquireToken(ClientCredentialParameters
6969
.builder(Collections.singleton(KEYVAULT_DEFAULT_SCOPE))
7070
.build())
7171
.get();
7272

7373
Assert.assertNotNull(result);
7474
Assert.assertNotNull(result.accessToken());
75-
Assert.assertNull(result.refreshToken());
7675
// TODO AuthenticationResult should have an getAccountInfo API
7776
// Assert.assertEquals(labResponse.getUser().getUpn(), result.getAccountInfo().getUsername());
7877
}

src/integrationtest/java/com.microsoft.aad.msal4j/DeviceCodeIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public void DeviceCodeFlowTest() throws Exception {
7272
};
7373

7474

75-
AuthenticationResult result = pca.acquireToken(DeviceCodeFlowParameters
75+
IAuthenticationResult result = pca.acquireToken(DeviceCodeFlowParameters
7676
.builder(Collections.singleton(TestConstants.GRAPH_DEFAULT_SCOPE),
7777
deviceCodeConsumer)
7878
.build())

src/integrationtest/java/com.microsoft.aad.msal4j/NationalCloudIT.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ private void assertAcquireTokenCommon(NationalCloud cloud) throws Exception{
6666
authority(TestConstants.AUTHORITY_ORGANIZATIONS).
6767
build();
6868

69-
AuthenticationResult result = pca.acquireToken(UserNamePasswordParameters
69+
IAuthenticationResult result = pca.acquireToken(UserNamePasswordParameters
7070
.builder(Collections.singleton(TestConstants.GRAPH_DEFAULT_SCOPE),
7171
labResponse.getUser().getUpn(),
7272
password.toCharArray())
@@ -75,7 +75,6 @@ private void assertAcquireTokenCommon(NationalCloud cloud) throws Exception{
7575

7676
Assert.assertNotNull(result);
7777
Assert.assertNotNull(result.accessToken());
78-
Assert.assertNotNull(result.refreshToken());
7978
Assert.assertNotNull(result.idToken());
8079
// TODO AuthenticationResult should have an getAccountInfo API
8180
// Assert.assertEquals(labResponse.getUser().getUpn(), result.getAccountInfo().getUsername());

src/integrationtest/java/com.microsoft.aad.msal4j/OnBehalfOfIT.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public void setUp() throws Exception{
3232
authority(msidlab4Authority).
3333
build();
3434

35-
AuthenticationResult result = pca.acquireToken(
35+
IAuthenticationResult result = pca.acquireToken(
3636
UserNamePasswordParameters.builder(Collections.singleton(apiReadScope),
3737
labResponse.getUser().getUpn(),
3838
labResponse.getUser().getPassword().toCharArray()).build()).get();
@@ -51,15 +51,14 @@ public void acquireTokenWithOBO_Managed() throws Exception {
5151
authority(msidlab4Authority).
5252
build();
5353

54-
AuthenticationResult result =
54+
IAuthenticationResult result =
5555
cca.acquireToken(OnBehalfOfParameters.builder(
5656
Collections.singleton(TestConstants.GRAPH_DEFAULT_SCOPE),
5757
new UserAssertion(accessToken)).build()).
5858
get();
5959

6060
Assert.assertNotNull(result);
6161
Assert.assertNotNull(result.accessToken());
62-
Assert.assertNotNull(result.refreshToken());
6362
Assert.assertNotNull(result.idToken());
6463
// TODO AuthenticationResult should have an getAccountInfo API
6564
// Assert.assertEquals(labResponse.getUser().getUpn(), result.getAccountInfo().getUsername());

src/integrationtest/java/com.microsoft.aad.msal4j/RefreshTokenIT.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public void setUp() throws Exception {
5050
authority(TestConstants.AUTHORITY_ORGANIZATIONS).
5151
build();
5252

53-
AuthenticationResult result = pca.acquireToken(UserNamePasswordParameters
53+
AuthenticationResult result = (AuthenticationResult)pca.acquireToken(UserNamePasswordParameters
5454
.builder(Collections.singleton(TestConstants.GRAPH_DEFAULT_SCOPE),
5555
labResponse.getUser().getUpn(),
5656
password.toCharArray())
@@ -63,7 +63,7 @@ public void setUp() throws Exception {
6363
@Test
6464
public void acquireTokenWithRefreshToken() throws Exception{
6565

66-
AuthenticationResult result = pca.acquireToken(RefreshTokenParameters
66+
IAuthenticationResult result = pca.acquireToken(RefreshTokenParameters
6767
.builder(
6868
Collections.singleton(TestConstants.GRAPH_DEFAULT_SCOPE),
6969
refreshToken)
@@ -72,13 +72,12 @@ public void acquireTokenWithRefreshToken() throws Exception{
7272

7373
Assert.assertNotNull(result);
7474
Assert.assertNotNull(result.accessToken());
75-
Assert.assertNotNull(result.refreshToken());
7675
Assert.assertNotNull(result.idToken());
7776
}
7877

7978
@Test(expectedExceptions = ExecutionException.class)
8079
public void acquireTokenWithRefreshToken_WrongScopes() throws Exception{
81-
AuthenticationResult result = pca.acquireToken(RefreshTokenParameters
80+
IAuthenticationResult result = pca.acquireToken(RefreshTokenParameters
8281
.builder(
8382
Collections.singleton(TestConstants.KEYVAULT_DEFAULT_SCOPE),
8483
refreshToken)

src/integrationtest/java/com.microsoft.aad.msal4j/UsernamePasswordIT.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public void assertAcquireTokenCommon(LabResponse labResponse, String password)
100100
authority(TestConstants.AUTHORITY_ORGANIZATIONS).
101101
build();
102102

103-
AuthenticationResult result = pca.acquireToken(UserNamePasswordParameters.
103+
IAuthenticationResult result = pca.acquireToken(UserNamePasswordParameters.
104104
builder(Collections.singleton(TestConstants.GRAPH_DEFAULT_SCOPE),
105105
labResponse.getUser().getUpn(),
106106
password.toCharArray())
@@ -109,7 +109,6 @@ public void assertAcquireTokenCommon(LabResponse labResponse, String password)
109109

110110
Assert.assertNotNull(result);
111111
Assert.assertNotNull(result.accessToken());
112-
Assert.assertNotNull(result.refreshToken());
113112
Assert.assertNotNull(result.idToken());
114113
// TODO AuthenticationResult should have an getAccountInfo API
115114
// Assert.assertEquals(labResponse.getUser().getUpn(), result.getAccountInfo().getUsername());
@@ -129,7 +128,7 @@ public void acquireTokenWithUsernamePassword_B2C_CustomAuthority() throws Except
129128
b2cAuthority(TestConstants.B2C_AUTHORITY_ROPC).
130129
build();
131130

132-
AuthenticationResult result = pca.acquireToken(UserNamePasswordParameters.
131+
IAuthenticationResult result = pca.acquireToken(UserNamePasswordParameters.
133132
builder(Collections.singleton(TestConstants.B2C_READ_SCOPE),
134133
labResponse.getUser().getUpn(),
135134
password.toCharArray())
@@ -138,7 +137,6 @@ public void acquireTokenWithUsernamePassword_B2C_CustomAuthority() throws Except
138137

139138
Assert.assertNotNull(result);
140139
Assert.assertNotNull(result.accessToken());
141-
Assert.assertNotNull(result.refreshToken());
142140
// TODO uncomment once service fixes this for ROPC flow
143141
// Assert.assertNotNull(result.idToken());
144142
}
@@ -157,7 +155,7 @@ public void acquireTokenWithUsernamePassword_B2C_LoginMicrosoftOnline() throws E
157155
b2cAuthority(TestConstants.B2C_MICROSOFTLOGIN_ROPC).
158156
build();
159157

160-
AuthenticationResult result = pca.acquireToken(UserNamePasswordParameters.
158+
IAuthenticationResult result = pca.acquireToken(UserNamePasswordParameters.
161159
builder(Collections.singleton(TestConstants.B2C_READ_SCOPE),
162160
labResponse.getUser().getUpn(),
163161
password.toCharArray())
@@ -166,7 +164,6 @@ public void acquireTokenWithUsernamePassword_B2C_LoginMicrosoftOnline() throws E
166164

167165
Assert.assertNotNull(result);
168166
Assert.assertNotNull(result.accessToken());
169-
Assert.assertNotNull(result.refreshToken());
170167
// TODO uncomment once service fixes this for ROPC flow
171168
// Assert.assertNotNull(result.idToken());
172169
}

src/integrationtest/java/labapi/KeyVaultSecretsProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public String doAuthenticate(String authorization, String resource, String scope
6363
}
6464

6565
private String requestAccessTokenForAutomation() {
66-
AuthenticationResult result;
66+
IAuthenticationResult result;
6767
try{
6868
ConfidentialClientApplication cca = ConfidentialClientApplication.builder(
6969
CLIENT_ID, getClientCredentialFromKeyStore()).

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

Lines changed: 8 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -23,85 +23,20 @@
2323

2424
package com.microsoft.aad.msal4j;
2525

26-
import com.google.gson.annotations.SerializedName;
27-
import lombok.*;
26+
import lombok.AllArgsConstructor;
27+
import lombok.Getter;
28+
import lombok.Setter;
2829
import lombok.experimental.Accessors;
2930

30-
import java.util.ArrayList;
31-
import java.util.List;
32-
3331
@Accessors(fluent = true)
3432
@Getter
3533
@Setter
36-
@EqualsAndHashCode
37-
@NoArgsConstructor(access = AccessLevel.PROTECTED)
38-
public class Account {
39-
40-
public static final String MSSTS_ACCOUNT_TYPE = "MSSTS";
41-
42-
@SerializedName("home_account_id")
43-
protected String homeAccountId;
44-
45-
@SerializedName("environment")
46-
protected String environment;
47-
48-
@EqualsAndHashCode.Exclude
49-
@SerializedName("realm")
50-
protected String realm;
51-
52-
@SerializedName("local_account_id")
53-
protected String localAccountId;
54-
55-
@SerializedName("username")
56-
protected String username;
57-
58-
@SerializedName("name")
59-
protected String name;
60-
61-
@SerializedName("client_info")
62-
protected String clientInfoStr;
63-
64-
ClientInfo clientInfo() {
65-
return ClientInfo.createFromJson(clientInfoStr);
66-
}
67-
68-
@SerializedName("authority_type")
69-
protected String authorityType;
70-
71-
String getKey() {
72-
73-
List<String> keyParts = new ArrayList<>();
74-
75-
keyParts.add(homeAccountId);
76-
keyParts.add(environment);
77-
keyParts.add(StringHelper.isBlank(realm) ? "" : realm);
78-
79-
return String.join(Constants.CACHE_KEY_SEPARATOR, keyParts).toLowerCase();
80-
}
81-
82-
static Account create(String clientInfoStr, String environment, IdToken idToken, String policy) {
83-
84-
Account account = new Account();
85-
account.authorityType(MSSTS_ACCOUNT_TYPE);
86-
account.clientInfoStr = clientInfoStr;
87-
account.homeAccountId(policy != null ?
88-
account.clientInfo().toAccountIdentifier() + Constants.CACHE_KEY_SEPARATOR + policy :
89-
account.clientInfo().toAccountIdentifier());
90-
account.environment(environment);
34+
@AllArgsConstructor
35+
public class Account implements IAccount {
9136

92-
if (idToken != null) {
93-
account.realm(idToken.tenantIdentifier);
94-
String localAccountId = !StringHelper.isBlank(idToken.objectIdentifier)
95-
? idToken.objectIdentifier : idToken.subject;
96-
account.localAccountId(localAccountId);
97-
account.username(idToken.preferredUsername);
98-
account.name(idToken.name);
99-
}
37+
String homeAccountId;
10038

101-
return account;
102-
}
39+
String environment;
10340

104-
static Account create(String clientInfoStr, String environment, IdToken idToken){
105-
return create(clientInfoStr, environment, idToken, null);
106-
}
41+
String username;
10742
}

0 commit comments

Comments
 (0)