Skip to content

Commit fa32189

Browse files
committed
PR feedback
1 parent 09ea0f5 commit fa32189

5 files changed

Lines changed: 101 additions & 109 deletions

File tree

msal4j-sdk/src/integrationtest/java/com/microsoft/aad/msal4j/AgenticIT.java

Lines changed: 33 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@
2828
*
2929
* <p>Test configuration:
3030
* <ul>
31-
* <li>RMA app: {@link #RMA_CLIENT_ID}</li>
32-
* <li>Agent app: {@link #AGENT_APP_ID}</li>
33-
* <li>Tenant: {@link #TENANT_ID}</li>
31+
* <li>RMA app: see {@link TestConstants#AGENTIC_RMA_CLIENT_ID}</li>
32+
* <li>Agent app: see {@link TestConstants#AGENTIC_AGENT_APP_ID}</li>
33+
* <li>Tenant: see {@link TestConstants#AGENTIC_TENANT_ID}</li>
3434
* </ul>
3535
*
3636
* <p>Flows tested:
@@ -44,18 +44,7 @@
4444
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
4545
class AgenticIT {
4646

47-
// Lab test configuration
48-
private static final String BLUEPRINT_CLIENT_ID = "aab5089d-e764-47e3-9f28-cc11c2513821";
49-
private static final String RMA_CLIENT_ID = "3bf56293-fbb5-42bd-a407-248ba7431a8c";
50-
private static final String TENANT_ID = "10c419d4-4a50-45b2-aa4e-919fb84df24f";
51-
private static final String AGENT_APP_ID = "ab18ca07-d139-4840-8b3b-4be9610c6ed5";
52-
private static final String USER_UPN = "agentuser1@id4slab1.onmicrosoft.com";
53-
private static final String TOKEN_EXCHANGE_SCOPE = "api://AzureADTokenExchange/.default";
54-
private static final String FMI_EXCHANGE_SCOPE = "api://AzureFMITokenExchange/.default";
55-
private static final String GRAPH_SCOPE = "https://graph.microsoft.com/.default";
56-
private static final String AZURE_REGION = "westus3";
57-
58-
private static final String AUTHORITY = "https://login.microsoftonline.com/" + TENANT_ID + "/";
47+
private static final String AUTHORITY = "https://login.microsoftonline.com/" + TestConstants.AGENTIC_TENANT_ID + "/";
5948

6049
private PrivateKey privateKey;
6150
private X509Certificate certificate;
@@ -88,20 +77,20 @@ void agentGetsAppToken_UsingFmiAssertion() throws Exception {
8877
// it calls the blueprint app to get an FMI credential for the agent
8978
Function<AssertionRequestOptions, String> assertionProvider = options -> {
9079
try {
91-
return acquireFmiCredentialForAgent(AGENT_APP_ID);
80+
return acquireFmiCredentialForAgent(TestConstants.AGENTIC_AGENT_APP_ID);
9281
} catch (Exception e) {
9382
throw new RuntimeException("Failed to acquire FMI credential", e);
9483
}
9584
};
9685

9786
IClientCredential credential = ClientCredentialFactory.createFromCallback(assertionProvider);
9887

99-
ConfidentialClientApplication agentCca = ConfidentialClientApplication.builder(AGENT_APP_ID, credential)
88+
ConfidentialClientApplication agentCca = ConfidentialClientApplication.builder(TestConstants.AGENTIC_AGENT_APP_ID, credential)
10089
.authority(AUTHORITY)
10190
.build();
10291

10392
IAuthenticationResult result = agentCca.acquireToken(ClientCredentialParameters
104-
.builder(Collections.singleton(GRAPH_SCOPE))
93+
.builder(Collections.singleton(TestConstants.AGENTIC_GRAPH_SCOPE))
10594
.build())
10695
.get();
10796

@@ -135,20 +124,20 @@ void assertionCallback_ReceivesFmiPathContext() throws Exception {
135124
ConfidentialClientApplication cca = ConfidentialClientApplication.builder(
136125
"urn:microsoft:identity:fmi", credential)
137126
.authority(AUTHORITY)
138-
.azureRegion(AZURE_REGION)
127+
.azureRegion(TestConstants.AGENTIC_AZURE_REGION)
139128
.build();
140129

141130
ClientCredentialParameters params = ClientCredentialParameters
142-
.builder(Collections.singleton(FMI_EXCHANGE_SCOPE))
143-
.fmiPath(AGENT_APP_ID)
131+
.builder(Collections.singleton(TestConstants.AGENTIC_FMI_EXCHANGE_SCOPE))
132+
.fmiPath(TestConstants.AGENTIC_AGENT_APP_ID)
144133
.skipCache(true)
145134
.build();
146135

147136
IAuthenticationResult result = cca.acquireToken(params).get();
148137

149138
// Verify assertion callback received the correct context
150139
assertNotNull(capturedOptions.get(), "AssertionRequestOptions should have been passed to callback");
151-
assertEquals(AGENT_APP_ID, capturedOptions.get().clientAssertionFmiPath(),
140+
assertEquals(TestConstants.AGENTIC_AGENT_APP_ID, capturedOptions.get().clientAssertionFmiPath(),
152141
"clientAssertionFmiPath in callback should match the one set in parameters");
153142
assertEquals("urn:microsoft:identity:fmi", capturedOptions.get().clientId(),
154143
"clientId in callback should match the CCA client ID");
@@ -178,19 +167,19 @@ void agentFmiToken_CacheIsolation_DifferentFmiPaths() throws Exception {
178167
ConfidentialClientApplication cca = ConfidentialClientApplication.builder(
179168
"urn:microsoft:identity:fmi", credential)
180169
.authority(AUTHORITY)
181-
.azureRegion(AZURE_REGION)
170+
.azureRegion(TestConstants.AGENTIC_AZURE_REGION)
182171
.build();
183172

184173
// Acquire with first fmi_path
185174
ClientCredentialParameters params1 = ClientCredentialParameters
186-
.builder(Collections.singleton(FMI_EXCHANGE_SCOPE))
187-
.fmiPath(AGENT_APP_ID)
175+
.builder(Collections.singleton(TestConstants.AGENTIC_FMI_EXCHANGE_SCOPE))
176+
.fmiPath(TestConstants.AGENTIC_AGENT_APP_ID)
188177
.build();
189178
IAuthenticationResult result1 = cca.acquireToken(params1).get();
190179

191180
// Acquire with different fmi_path
192181
ClientCredentialParameters params2 = ClientCredentialParameters
193-
.builder(Collections.singleton(FMI_EXCHANGE_SCOPE))
182+
.builder(Collections.singleton(TestConstants.AGENTIC_FMI_EXCHANGE_SCOPE))
194183
.fmiPath("SomeFmiPath/DifferentAgent")
195184
.build();
196185
IAuthenticationResult result2 = cca.acquireToken(params2).get();
@@ -212,15 +201,15 @@ void agentUserIdentity_GetsTokenForGraph() throws Exception {
212201
// Build agent CCA with assertion callback that acquires FMI credential
213202
Function<AssertionRequestOptions, String> assertionProvider = options -> {
214203
try {
215-
return acquireFmiCredentialForAgent(AGENT_APP_ID);
204+
return acquireFmiCredentialForAgent(TestConstants.AGENTIC_AGENT_APP_ID);
216205
} catch (Exception e) {
217206
throw new RuntimeException("Failed to acquire FMI credential", e);
218207
}
219208
};
220209

221210
IClientCredential credential = ClientCredentialFactory.createFromCallback(assertionProvider);
222211

223-
ConfidentialClientApplication agentCca = ConfidentialClientApplication.builder(AGENT_APP_ID, credential)
212+
ConfidentialClientApplication agentCca = ConfidentialClientApplication.builder(TestConstants.AGENTIC_AGENT_APP_ID, credential)
224213
.authority(AUTHORITY)
225214
.build();
226215

@@ -229,7 +218,7 @@ void agentUserIdentity_GetsTokenForGraph() throws Exception {
229218

230219
// Exchange T2 for user-scoped token via user_fic grant
231220
UserFederatedIdentityCredentialParameters params = UserFederatedIdentityCredentialParameters
232-
.builder(Collections.singleton(GRAPH_SCOPE), USER_UPN, t2)
221+
.builder(Collections.singleton(TestConstants.AGENTIC_GRAPH_SCOPE), TestConstants.AGENTIC_USER_UPN, t2)
233222
.build();
234223

235224
IAuthenticationResult result = agentCca.acquireToken(params).get();
@@ -245,7 +234,7 @@ void agentUserIdentity_GetsTokenForGraph() throws Exception {
245234

246235
IAccount account = accounts.iterator().next();
247236
IAuthenticationResult silentResult = agentCca.acquireTokenSilently(
248-
SilentParameters.builder(Collections.singleton(GRAPH_SCOPE), account).build()).get();
237+
SilentParameters.builder(Collections.singleton(TestConstants.AGENTIC_GRAPH_SCOPE), account).build()).get();
249238

250239
assertEquals(result.accessToken(), silentResult.accessToken(),
251240
"Silent call should return cached token");
@@ -260,29 +249,29 @@ void agentUserIdentity_GetsTokenForGraph() throws Exception {
260249
void agentCca_AppAndUserTokens_CacheIsolation() throws Exception {
261250
Function<AssertionRequestOptions, String> assertionProvider = options -> {
262251
try {
263-
return acquireFmiCredentialForAgent(AGENT_APP_ID);
252+
return acquireFmiCredentialForAgent(TestConstants.AGENTIC_AGENT_APP_ID);
264253
} catch (Exception e) {
265254
throw new RuntimeException("Failed to acquire FMI credential", e);
266255
}
267256
};
268257

269258
IClientCredential credential = ClientCredentialFactory.createFromCallback(assertionProvider);
270259

271-
ConfidentialClientApplication agentCca = ConfidentialClientApplication.builder(AGENT_APP_ID, credential)
260+
ConfidentialClientApplication agentCca = ConfidentialClientApplication.builder(TestConstants.AGENTIC_AGENT_APP_ID, credential)
272261
.authority(AUTHORITY)
273262
.build();
274263

275264
// Acquire app-only token
276265
IAuthenticationResult appResult = agentCca.acquireToken(ClientCredentialParameters
277-
.builder(Collections.singleton(GRAPH_SCOPE))
266+
.builder(Collections.singleton(TestConstants.AGENTIC_GRAPH_SCOPE))
278267
.build())
279268
.get();
280269
assertNotNull(appResult.accessToken());
281270

282271
// Acquire user token via user_fic (needs T2 = instance token)
283272
String t2 = acquireInstanceTokenForAgent();
284273
UserFederatedIdentityCredentialParameters userParams = UserFederatedIdentityCredentialParameters
285-
.builder(Collections.singleton(GRAPH_SCOPE), USER_UPN, t2)
274+
.builder(Collections.singleton(TestConstants.AGENTIC_GRAPH_SCOPE), TestConstants.AGENTIC_USER_UPN, t2)
286275
.build();
287276

288277
IAuthenticationResult userResult = agentCca.acquireToken(userParams).get();
@@ -300,21 +289,21 @@ void agentCca_AppAndUserTokens_CacheIsolation() throws Exception {
300289

301290
/**
302291
* Helper: acquires an FMI credential from the RMA (Resource Management Application).
303-
* Uses FMI_EXCHANGE_SCOPE, matching FmiIT's Flow3 pattern.
292+
* Uses TestConstants.AGENTIC_FMI_EXCHANGE_SCOPE, matching FmiIT's Flow3 pattern.
304293
* Suitable for use as client_assertion when client_id = "urn:microsoft:identity:fmi".
305294
*/
306295
private String acquireFmiCredentialFromRma() throws Exception {
307296
IClientCertificate clientCert = ClientCredentialFactory.createFromCertificate(privateKey, certificate);
308297

309298
ConfidentialClientApplication rmaCca = ConfidentialClientApplication.builder(
310-
RMA_CLIENT_ID, clientCert)
299+
TestConstants.AGENTIC_RMA_CLIENT_ID, clientCert)
311300
.authority(AUTHORITY)
312301
.sendX5c(true)
313-
.azureRegion(AZURE_REGION)
302+
.azureRegion(TestConstants.AGENTIC_AZURE_REGION)
314303
.build();
315304

316305
ClientCredentialParameters params = ClientCredentialParameters
317-
.builder(Collections.singleton(FMI_EXCHANGE_SCOPE))
306+
.builder(Collections.singleton(TestConstants.AGENTIC_FMI_EXCHANGE_SCOPE))
318307
.fmiPath("SomeFmiPath/FmiCredentialPath")
319308
.build();
320309

@@ -330,14 +319,14 @@ private String acquireFmiCredentialForAgent(String agentAppId) throws Exception
330319
IClientCertificate clientCert = ClientCredentialFactory.createFromCertificate(privateKey, certificate);
331320

332321
ConfidentialClientApplication blueprintCca = ConfidentialClientApplication.builder(
333-
BLUEPRINT_CLIENT_ID, clientCert)
322+
TestConstants.AGENTIC_BLUEPRINT_CLIENT_ID, clientCert)
334323
.authority(AUTHORITY)
335324
.sendX5c(true)
336-
.azureRegion(AZURE_REGION)
325+
.azureRegion(TestConstants.AGENTIC_AZURE_REGION)
337326
.build();
338327

339328
ClientCredentialParameters params = ClientCredentialParameters
340-
.builder(Collections.singleton(TOKEN_EXCHANGE_SCOPE))
329+
.builder(Collections.singleton(TestConstants.AGENTIC_TOKEN_EXCHANGE_SCOPE))
341330
.fmiPath(agentAppId)
342331
.build();
343332

@@ -352,16 +341,16 @@ private String acquireFmiCredentialForAgent(String agentAppId) throws Exception
352341
* T2 is used as the user_federated_identity_credential in Leg 3 (user_fic exchange).
353342
*/
354343
private String acquireInstanceTokenForAgent() throws Exception {
355-
String t1 = acquireFmiCredentialForAgent(AGENT_APP_ID);
344+
String t1 = acquireFmiCredentialForAgent(TestConstants.AGENTIC_AGENT_APP_ID);
356345

357346
IClientCredential agentCredential = ClientCredentialFactory.createFromClientAssertion(t1);
358347

359-
ConfidentialClientApplication agentCca = ConfidentialClientApplication.builder(AGENT_APP_ID, agentCredential)
348+
ConfidentialClientApplication agentCca = ConfidentialClientApplication.builder(TestConstants.AGENTIC_AGENT_APP_ID, agentCredential)
360349
.authority(AUTHORITY)
361350
.build();
362351

363352
ClientCredentialParameters instanceParams = ClientCredentialParameters
364-
.builder(Collections.singleton(TOKEN_EXCHANGE_SCOPE))
353+
.builder(Collections.singleton(TestConstants.AGENTIC_TOKEN_EXCHANGE_SCOPE))
365354
.skipCache(true)
366355
.build();
367356

0 commit comments

Comments
 (0)