3
3
4
4
package com .microsoft .aad .msal4j ;
5
5
6
- import labapi .AppIdentityProvider ;
7
- import labapi .FederationProvider ;
8
- import labapi .LabResponse ;
9
- import labapi .LabUserProvider ;
10
- import labapi .NationalCloud ;
6
+ import labapi .*;
11
7
import org .testng .Assert ;
12
8
import org .testng .annotations .BeforeClass ;
13
9
import org .testng .annotations .Test ;
@@ -50,21 +46,19 @@ public void acquireTokenSilent_OrganizationAuthority_TokenRefreshed() throws Exc
50
46
public void acquireTokenSilent_LabAuthority_TokenNotRefreshed () throws Exception {
51
47
// Access token should be returned from cache, and not using refresh token
52
48
53
- LabResponse labResponse = labUserProvider .getDefaultUser (
54
- NationalCloud .AZURE_CLOUD ,
55
- false );
56
- String password = labUserProvider .getUserPassword (labResponse .getUser ());
57
- String labAuthority = TestConstants .MICROSOFT_AUTHORITY_HOST + labResponse .getUser ().getTenantId ();
49
+ User user = labUserProvider .getDefaultUser ();
50
+
51
+ String labAuthority = TestConstants .ORGANIZATIONS_AUTHORITY ;
58
52
59
53
PublicClientApplication pca = PublicClientApplication .builder (
60
- labResponse .getAppId ()).
54
+ user .getAppId ()).
61
55
authority (labAuthority ).
62
56
build ();
63
57
64
58
IAuthenticationResult result = pca .acquireToken (UserNamePasswordParameters .
65
59
builder (Collections .singleton (TestConstants .GRAPH_DEFAULT_SCOPE ),
66
- labResponse . getUser () .getUpn (),
67
- password .toCharArray ())
60
+ user .getUpn (),
61
+ user . getPassword () .toCharArray ())
68
62
.build ())
69
63
.get ();
70
64
@@ -85,20 +79,17 @@ public void acquireTokenSilent_LabAuthority_TokenNotRefreshed() throws Exception
85
79
@ Test
86
80
public void acquireTokenSilent_ForceRefresh () throws Exception {
87
81
88
- LabResponse labResponse = labUserProvider .getDefaultUser (
89
- NationalCloud .AZURE_CLOUD ,
90
- false );
91
- String password = labUserProvider .getUserPassword (labResponse .getUser ());
82
+ User user = labUserProvider .getDefaultUser ();
92
83
93
84
PublicClientApplication pca = PublicClientApplication .builder (
94
- labResponse .getAppId ()).
85
+ user .getAppId ()).
95
86
authority (TestConstants .ORGANIZATIONS_AUTHORITY ).
96
87
build ();
97
88
98
89
IAuthenticationResult result = pca .acquireToken (UserNamePasswordParameters .
99
90
builder (Collections .singleton (TestConstants .GRAPH_DEFAULT_SCOPE ),
100
- labResponse . getUser () .getUpn (),
101
- password .toCharArray ())
91
+ user .getUpn (),
92
+ user . getPassword () .toCharArray ())
102
93
.build ())
103
94
.get ();
104
95
@@ -124,24 +115,20 @@ public void acquireTokenSilent_MultipleAccountsInCache_UseCorrectAccount() throw
124
115
IPublicClientApplication pca = getPublicClientApplicationWithTokensInCache ();
125
116
126
117
// get lab user for different account
127
- LabResponse labResponse = labUserProvider .getAdfsUser (
128
- FederationProvider .ADFSV4 ,
129
- true ,
130
- false );
131
- String password = labUserProvider .getUserPassword (labResponse .getUser ());
118
+ User user = labUserProvider .getFederatedAdfsUser (FederationProvider .ADFS_4 );
132
119
133
120
// acquire token for different account
134
121
pca .acquireToken (UserNamePasswordParameters .
135
122
builder (Collections .singleton (TestConstants .GRAPH_DEFAULT_SCOPE ),
136
- labResponse . getUser () .getUpn (),
137
- password .toCharArray ())
123
+ user .getUpn (),
124
+ user . getPassword () .toCharArray ())
138
125
.build ())
139
126
.get ();
140
127
141
128
Set <IAccount > accounts = pca .getAccounts ().join ();
142
129
IAccount account = accounts .stream ().filter (
143
130
x -> x .username ().equalsIgnoreCase (
144
- labResponse . getUser () .getUpn ())).findFirst ().orElse (null );
131
+ user .getUpn ())).findFirst ().orElse (null );
145
132
146
133
SilentParameters parameters = SilentParameters .builder (
147
134
Collections .singleton (TestConstants .GRAPH_DEFAULT_SCOPE ), account ).
@@ -153,7 +140,7 @@ public void acquireTokenSilent_MultipleAccountsInCache_UseCorrectAccount() throw
153
140
Assert .assertNotNull (result );
154
141
Assert .assertNotNull (result .accessToken ());
155
142
Assert .assertNotNull (result .idToken ());
156
- Assert .assertEquals (result .account ().username (), labResponse . getUser () .getUpn ());
143
+ Assert .assertEquals (result .account ().username (), user .getUpn ());
157
144
}
158
145
159
146
@ Test
@@ -163,10 +150,8 @@ public void acquireTokenSilent_usingCommonAuthority_returnCachedAt() throws Exce
163
150
164
151
@ Test
165
152
public void acquireTokenSilent_usingTenantSpecificAuthority_returnCachedAt () throws Exception {
166
- LabResponse labResponse = labUserProvider .getDefaultUser (
167
- NationalCloud .AZURE_CLOUD ,
168
- false );
169
- String tenantSpecificAuthority = TestConstants .MICROSOFT_AUTHORITY_HOST + labResponse .getUser ().getTenantId ();
153
+ String tenantSpecificAuthority = TestConstants .ORGANIZATIONS_AUTHORITY ;
154
+
170
155
acquireTokenSilent_returnCachedTokens (tenantSpecificAuthority );
171
156
}
172
157
@@ -229,20 +214,17 @@ private IConfidentialClientApplication getConfidentialClientApplications() throw
229
214
230
215
private void acquireTokenSilent_returnCachedTokens (String authority ) throws Exception {
231
216
232
- LabResponse labResponse = labUserProvider .getDefaultUser (
233
- NationalCloud .AZURE_CLOUD ,
234
- false );
235
- String password = labUserProvider .getUserPassword (labResponse .getUser ());
217
+ User user = labUserProvider .getDefaultUser ();
236
218
237
219
PublicClientApplication pca = PublicClientApplication .builder (
238
- labResponse .getAppId ()).
220
+ user .getAppId ()).
239
221
authority (authority ).
240
222
build ();
241
223
242
224
IAuthenticationResult interactiveAuthResult = pca .acquireToken (UserNamePasswordParameters .
243
225
builder (Collections .singleton (TestConstants .GRAPH_DEFAULT_SCOPE ),
244
- labResponse . getUser () .getUpn (),
245
- password .toCharArray ())
226
+ user .getUpn (),
227
+ user . getPassword () .toCharArray ())
246
228
.build ())
247
229
.get ();
248
230
@@ -260,21 +242,18 @@ private void acquireTokenSilent_returnCachedTokens(String authority) throws Exce
260
242
261
243
private IPublicClientApplication getPublicClientApplicationWithTokensInCache ()
262
244
throws Exception {
263
- LabResponse labResponse = labUserProvider .getDefaultUser (
264
- NationalCloud .AZURE_CLOUD ,
265
- false );
266
- String password = labUserProvider .getUserPassword (labResponse .getUser ());
245
+ User user = labUserProvider .getDefaultUser ();
267
246
268
247
PublicClientApplication pca = PublicClientApplication .builder (
269
- labResponse .getAppId ()).
248
+ user .getAppId ()).
270
249
authority (TestConstants .ORGANIZATIONS_AUTHORITY ).
271
250
build ();
272
251
273
252
pca .acquireToken (
274
253
UserNamePasswordParameters .builder (
275
254
Collections .singleton (TestConstants .GRAPH_DEFAULT_SCOPE ),
276
- labResponse . getUser () .getUpn (),
277
- password .toCharArray ())
255
+ user .getUpn (),
256
+ user . getPassword () .toCharArray ())
278
257
.build ()).get ();
279
258
return pca ;
280
259
}
0 commit comments