Skip to content

Commit 07bdbb7

Browse files
committed
Clean up comments
1 parent 0306432 commit 07bdbb7

3 files changed

Lines changed: 56 additions & 28 deletions

File tree

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

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121

2222
/**
2323
* Integration tests for agentic (agent identity) scenarios using MSAL Java APIs.
24-
* Tests FMI credential acquisition via assertion callbacks and cache isolation,
25-
* plus FIC user_fic flows for the full 3-leg agent identity protocol.
24+
* Corresponds to .NET's Agentic.cs — tests the MSAL-level APIs for the agent identity flow
25+
* (specifically the FMI portions that are available on this branch, plus FIC user_fic flows).
2626
*
2727
* <p>These tests use MSAL token acquisition APIs (unlike AgenticRawHttpIT which uses raw HTTP).
2828
*
@@ -74,6 +74,42 @@ void init() throws KeyStoreException, NoSuchProviderException,
7474
assertNotNull(certificate, "Lab certificate not found. Ensure the lab cert is installed.");
7575
}
7676

77+
/**
78+
* Agent gets an app-only token for Graph using an FMI-sourced client assertion.
79+
* This tests Leg 2 of the agent identity flow:
80+
* 1. Blueprint CCA acquires FMI credential (fmi_path = agentAppId)
81+
* 2. Agent CCA uses that credential as client_assertion to get Graph token
82+
*
83+
* Corresponds to .NET's AgentGetsAppTokenForGraphTest.
84+
*/
85+
@Test
86+
void agentGetsAppToken_UsingFmiAssertion() throws Exception {
87+
// The assertion callback simulates what an SDK or middleware would do:
88+
// it calls the blueprint app to get an FMI credential for the agent
89+
Function<AssertionRequestOptions, String> assertionProvider = options -> {
90+
try {
91+
return acquireFmiCredentialForAgent(AGENT_APP_ID);
92+
} catch (Exception e) {
93+
throw new RuntimeException("Failed to acquire FMI credential", e);
94+
}
95+
};
96+
97+
IClientCredential credential = ClientCredentialFactory.createFromCallback(assertionProvider);
98+
99+
ConfidentialClientApplication agentCca = ConfidentialClientApplication.builder(AGENT_APP_ID, credential)
100+
.authority(AUTHORITY)
101+
.build();
102+
103+
IAuthenticationResult result = agentCca.acquireToken(ClientCredentialParameters
104+
.builder(Collections.singleton(GRAPH_SCOPE))
105+
.build())
106+
.get();
107+
108+
assertNotNull(result, "Auth result should not be null");
109+
assertNotNull(result.accessToken(), "Access token should not be null");
110+
assertFalse(result.accessToken().isEmpty(), "Access token should not be empty");
111+
}
112+
77113
/**
78114
* Verifies that the context-aware assertion callback receives the correct fmiPath
79115
* when the ClientCredentialParameters include an fmiPath.
@@ -263,8 +299,9 @@ void agentCca_AppAndUserTokens_CacheIsolation() throws Exception {
263299
}
264300

265301
/**
266-
* Helper: acquires an FMI credential from the RMA using a certificate.
267-
* Uses the FMI-specific exchange scope (api://AzureFMITokenExchange).
302+
* Helper: acquires an FMI credential from the RMA (Resource Management Application).
303+
* Uses FMI_EXCHANGE_SCOPE, matching FmiIT's Flow3 pattern.
304+
* Suitable for use as client_assertion when client_id = "urn:microsoft:identity:fmi".
268305
*/
269306
private String acquireFmiCredentialFromRma() throws Exception {
270307
IClientCertificate clientCert = ClientCredentialFactory.createFromCertificate(privateKey, certificate);

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

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,11 @@
2121

2222
/**
2323
* Integration tests for FIC (Federated Identity Credential) / user_fic grant support.
24-
* Corresponds to .NET's Agentic.cs UserFIC-related tests.
2524
*
26-
* <p>Tests the low-level UserFIC primitive: acquires an FMI-sourced assertion,
25+
* <p>Tests the user_fic primitive: acquires an FMI-sourced assertion,
2726
* then exchanges it for a user-scoped token using the user_fic grant type.
2827
*
29-
* <p>Test configuration (same as .NET Agentic.cs):
28+
* <p>Test configuration:
3029
* <ul>
3130
* <li>Blueprint app: {@link #BLUEPRINT_CLIENT_ID}</li>
3231
* <li>Agent app: {@link #AGENT_APP_ID}</li>
@@ -37,15 +36,15 @@
3736
* <p>Flows tested:
3837
* <ul>
3938
* <li>Full 3-leg: FMI → assertion → user_fic → user token (UPN-based)</li>
40-
* <li>OID-based user_fic (Guid overload)</li>
39+
* <li>OID-based user_fic (UUID overload)</li>
4140
* <li>Cache hit: second call returns cached user token</li>
4241
* <li>Force refresh: bypasses cache</li>
4342
* </ul>
4443
*/
4544
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
4645
class FicIT {
4746

48-
// Same config as .NET Agentic.cs
47+
// Same config as AgenticIT
4948
private static final String BLUEPRINT_CLIENT_ID = "aab5089d-e764-47e3-9f28-cc11c2513821";
5049
private static final String TENANT_ID = "10c419d4-4a50-45b2-aa4e-919fb84df24f";
5150
private static final String AGENT_APP_ID = "ab18ca07-d139-4840-8b3b-4be9610c6ed5";
@@ -76,7 +75,6 @@ void init() throws KeyStoreException, NoSuchProviderException,
7675
/**
7776
* Full 3-leg flow using UPN: FMI credential → assertion → user_fic → user-scoped Graph token.
7877
* Then verifies the token is cached and can be retrieved silently.
79-
* Corresponds to .NET's AgentUserIdentityGetsTokenForGraphTest.
8078
*/
8179
@Test
8280
void userFic_FullFlow_WithUpn_GetsUserToken() throws Exception {
@@ -114,7 +112,6 @@ void userFic_FullFlow_WithUpn_GetsUserToken() throws Exception {
114112

115113
/**
116114
* OID-based user_fic: discovers user's OID via UPN flow, then uses UUID overload.
117-
* Corresponds to .NET's UserFic_WithGuidObjectId_Test.
118115
*/
119116
@Test
120117
void userFic_WithGuidObjectId_GetsUserToken() throws Exception {
@@ -222,7 +219,6 @@ void userFic_ForceRefresh_BypassesCache() throws Exception {
222219

223220
/**
224221
* Leg 1: Blueprint CCA acquires FMI credential (T1) for the agent app.
225-
* Equivalent to .NET's GetAppCredentialAsync(fmiPath).
226222
* T1 is used as client_assertion to authenticate the agent CCA.
227223
*/
228224
private String acquireFmiCredential(String fmiPath) throws Exception {
@@ -272,8 +268,7 @@ private String acquireInstanceToken() throws Exception {
272268

273269
/**
274270
* Builds an agent CCA whose credential callback produces T1 (FMI credential).
275-
* This matches .NET's pattern: the CCA authenticates with T1 as client_assertion.
276-
* Equivalent to .NET's WithClientAssertion(_ => GetAppCredentialAsync(AgentIdentity)).
271+
* The CCA authenticates with T1 as client_assertion for Leg 2 and Leg 3 requests.
277272
*/
278273
private ConfidentialClientApplication buildAgentCca() throws Exception {
279274
Function<AssertionRequestOptions, String> assertionProvider = options -> {

msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/UserFederatedIdentityCredentialTest.java

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121

2222
/**
2323
* Tests for the User Federated Identity Credential (user_fic) flow.
24-
* Covers §6 (user_fic grant type), §7 (user_federated_identity_credential body param),
25-
* §8 (user_id/username body params), and §11 (primitive API) from AgentIDs_ComponentsReference.
2624
*/
2725
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
2826
class UserFederatedIdentityCredentialTest {
@@ -59,7 +57,7 @@ private HttpResponse createSuccessResponseWithIdToken() {
5957
}
6058

6159
// ========================================================================
62-
// §6: user_fic grant type
60+
// Grant type and body parameters
6361
// ========================================================================
6462

6563
@Test
@@ -86,7 +84,7 @@ void userFic_SendsCorrectGrantType() throws Exception {
8684
}
8785

8886
// ========================================================================
89-
// §7: user_federated_identity_credential body parameter
87+
// user_federated_identity_credential body parameter
9088
// ========================================================================
9189

9290
@Test
@@ -113,7 +111,7 @@ void userFic_SendsAssertionInBody() throws Exception {
113111
}
114112

115113
// ========================================================================
116-
// §8: user_id / username body parameters — mutual exclusion
114+
// user_id / username body parameters — mutual exclusion
117115
// ========================================================================
118116

119117
@Test
@@ -165,7 +163,7 @@ void userFic_WithOid_SendsUserIdNotUsername() throws Exception {
165163
}
166164

167165
// ========================================================================
168-
// §6+§7+§8 combined: all parameters sent together
166+
// All parameters sent together
169167
// ========================================================================
170168

171169
@Test
@@ -224,7 +222,7 @@ void userFic_ScopeIncludesOidcScopes() throws Exception {
224222
}
225223

226224
// ========================================================================
227-
// §11: Token stored in user cache
225+
// Token stored in user cache
228226
// ========================================================================
229227

230228
@Test
@@ -251,7 +249,7 @@ void userFic_TokenStoredInUserCache() throws Exception {
251249
}
252250

253251
// ========================================================================
254-
// §11: Force refresh bypasses cache
252+
// Force refresh bypasses cache
255253
// ========================================================================
256254

257255
@Test
@@ -285,7 +283,7 @@ void userFic_ForceRefresh_BypassesCache() throws Exception {
285283
}
286284

287285
// ========================================================================
288-
// §11: Cache hit when not force-refreshing
286+
// Cache hit when not force-refreshing
289287
// ========================================================================
290288

291289
@Test
@@ -391,7 +389,7 @@ void userFic_Parameters_OidBuilder_SetsFieldsCorrectly() {
391389
}
392390

393391
// ========================================================================
394-
// Multi-user cache isolation (matches .NET TwoUpns/TwoOids tests)
392+
// Multi-user cache isolation
395393
// ========================================================================
396394

397395
/**
@@ -422,9 +420,8 @@ private HttpResponse createUserResponse(String oid, String preferredUsername, St
422420
}
423421

424422
/**
425-
* Verifies that two different users (by UPN) acquire tokens via UserFIC on the same CCA,
423+
* Verifies that two different users (by UPN) acquire tokens via user_fic on the same CCA,
426424
* and AcquireTokenSilent returns the correct cached token for each user.
427-
* Matches .NET's AcquireTokenByUserFic_TwoUpns_SilentReturnsCorrectToken_Async.
428425
*/
429426
@Test
430427
void userFic_TwoUpns_SilentReturnsCorrectToken() throws Exception {
@@ -492,9 +489,8 @@ void userFic_TwoUpns_SilentReturnsCorrectToken() throws Exception {
492489
}
493490

494491
/**
495-
* Verifies that two different users (by OID) acquire tokens via UserFIC on the same CCA,
492+
* Verifies that two different users (by OID) acquire tokens via user_fic on the same CCA,
496493
* and AcquireTokenSilent resolves the correct account by OID.
497-
* Matches .NET's AcquireTokenByUserFic_TwoOids_SilentReturnsCorrectToken_Async.
498494
*/
499495
@Test
500496
void userFic_TwoOids_SilentReturnsCorrectToken() throws Exception {

0 commit comments

Comments
 (0)