-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Classes for tenant profile functionality * Implement tenant profile feature * Tests for tenant profile feature * Simplify tenant profile class structure * 1.6.2 release * Classes for tenant profile redesign * Tests for tenant profile redesign * Adjust sample cached ID tokens to have realistic headers * Redesign how Tenant Pofiles are added to Accounts * New error code for JWT parse exceptions * Add claims and tenant profiles fields to Account * Remove annotation excluding realm field from comparisons * Use more generic token * Remove ID token claims field from Account * Minor changes for clarity * Adjust tests for tenant profile design refactor * Refactor tenant profile structure * Minor fixes * Minor fixes * Minor fixes * Simplify tenant profile class Co-authored-by: SomkaPe <pesomka@microsoft.com>
- Loading branch information
1 parent
fce61b2
commit 0b20b14
Showing
13 changed files
with
280 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/main/java/com/microsoft/aad/msal4j/ITenantProfile.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
package com.microsoft.aad.msal4j; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* Interface representing a single tenant profile. ITenantProfiles are made available through the | ||
* {@link IAccount#getTenantProfiles()} method of an Account | ||
* | ||
*/ | ||
public interface ITenantProfile { | ||
|
||
/** | ||
* A map of claims taken from an ID token. Keys and values will follow the structure of a JSON Web Token | ||
* | ||
* @return Map claims in id token | ||
*/ | ||
Map<String, ?> getClaims(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
package com.microsoft.aad.msal4j; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
import lombok.experimental.Accessors; | ||
import java.util.Map; | ||
|
||
/** | ||
* Representation of a single tenant profile | ||
*/ | ||
@Accessors(fluent = true) | ||
@Getter | ||
@Setter | ||
@AllArgsConstructor | ||
class TenantProfile implements ITenantProfile { | ||
|
||
Map<String, ?> idTokenClaims; | ||
|
||
public Map<String, ?> getClaims() { | ||
return idTokenClaims; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
package com.microsoft.aad.msal4j; | ||
|
||
import org.testng.Assert; | ||
import org.testng.annotations.Test; | ||
import java.io.IOException; | ||
import java.net.URISyntaxException; | ||
import java.util.Iterator; | ||
import java.util.Map; | ||
|
||
public class AccountTest { | ||
|
||
@Test | ||
public void testMultiTenantAccount_AccessTenantProfile() throws IOException, URISyntaxException { | ||
|
||
ITokenCacheAccessAspect accountCache = new CachePersistenceIT.TokenPersistence( | ||
TestHelper.readResource(this.getClass(), | ||
"/cache_data/multi-tenant-account-cache.json")); | ||
|
||
PublicClientApplication app = PublicClientApplication.builder("client_id") | ||
.setTokenCacheAccessAspect(accountCache).build(); | ||
|
||
Assert.assertEquals(app.getAccounts().join().size(), 3); | ||
Iterator<IAccount> acctIterator = app.getAccounts().join().iterator(); | ||
|
||
IAccount curAccount; | ||
while (acctIterator.hasNext()) { | ||
curAccount = acctIterator.next(); | ||
|
||
switch (curAccount.username()) { | ||
case "MultiTenantAccount": { | ||
Assert.assertEquals(curAccount.homeAccountId(), "uid1.utid1"); | ||
Map<String, ITenantProfile> tenantProfiles = curAccount.getTenantProfiles(); | ||
Assert.assertNotNull(tenantProfiles); | ||
Assert.assertEquals(tenantProfiles.size(), 3); | ||
Assert.assertNotNull(tenantProfiles.get("utid1")); | ||
Assert.assertNotNull(tenantProfiles.get("utid1").getClaims()); | ||
Assert.assertNotNull(tenantProfiles.get("utid2")); | ||
Assert.assertNotNull(tenantProfiles.get("utid2").getClaims()); | ||
Assert.assertNotNull(tenantProfiles.get("utid3")); | ||
Assert.assertNotNull(tenantProfiles.get("utid3").getClaims()); | ||
break; | ||
} | ||
case "SingleTenantAccount": { | ||
Assert.assertEquals(curAccount.homeAccountId(), "uid6.utid5"); | ||
Map<String, ITenantProfile> tenantProfiles = curAccount.getTenantProfiles(); | ||
Assert.assertNotNull(tenantProfiles); | ||
Assert.assertEquals(tenantProfiles.size(), 1); | ||
Assert.assertNotNull(tenantProfiles.get("utid5")); | ||
Assert.assertNotNull(tenantProfiles.get("utid5").getClaims()); | ||
break; | ||
} | ||
case "TenantProfileNoHome": { | ||
Assert.assertEquals(curAccount.homeAccountId(), "uid5.utid4"); | ||
Map<String, ITenantProfile> tenantProfiles = curAccount.getTenantProfiles(); | ||
Assert.assertNotNull(tenantProfiles); | ||
Assert.assertEquals(tenantProfiles.size(), 1); | ||
Assert.assertNotNull(tenantProfiles.get("utid4")); | ||
Assert.assertNotNull(tenantProfiles.get("utid4").getClaims()); | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
} |
86 changes: 86 additions & 0 deletions
86
src/test/resources/cache_data/multi-tenant-account-cache.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
{ | ||
"Account": { | ||
"uid1.utid1-login.windows.net-utid1": { | ||
"username": "MultiTenantAccount", | ||
"local_account_id": "uid1", | ||
"realm": "utid1", | ||
"environment": "login.windows.net", | ||
"home_account_id": "uid1.utid1", | ||
"authority_type": "MSSTS" | ||
}, | ||
"uid1.utid1-login.windows.net-utid2": { | ||
"username": "TenantProfile1", | ||
"local_account_id": "uid2", | ||
"realm": "utid2", | ||
"environment": "login.windows.net", | ||
"home_account_id": "uid1.utid1", | ||
"authority_type": "MSSTS" | ||
}, | ||
"uid1.utid1-login.windows.net-utid3": { | ||
"username": "TenantProfile2", | ||
"local_account_id": "uid3", | ||
"realm": "utid3", | ||
"environment": "login.windows.net", | ||
"home_account_id": "uid1.utid1", | ||
"authority_type": "MSSTS" | ||
}, | ||
"uid5.utid4-login.windows.net-utid4": { | ||
"username": "TenantProfileNoHome", | ||
"local_account_id": "uid4", | ||
"realm": "utid4", | ||
"environment": "login.windows.net", | ||
"home_account_id": "uid5.utid4", | ||
"authority_type": "MSSTS" | ||
}, | ||
"uid6.utid5-login.windows.net-utid5": { | ||
"username": "SingleTenantAccount", | ||
"local_account_id": "uid6", | ||
"realm": "utid5", | ||
"environment": "login.windows.net", | ||
"home_account_id": "uid6.utid5", | ||
"authority_type": "MSSTS" | ||
} | ||
}, | ||
"IdToken": { | ||
"uid1.utid1-login.windows.net-idtoken-client_id-utid1-": { | ||
"realm": "utid1", | ||
"environment": "login.windows.net", | ||
"credential_type": "IdToken", | ||
"secret": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6Imh1Tjk1SXZQZmVocTM0R3pCRFoxR1hHaXJuTSJ9.eyJvaWQiOiAib2JqZWN0MTIzNCIsICJwcmVmZXJyZWRfdXNlcm5hbWUiOiAiSm9obiBEb2UiLCAic3ViIjogInN1YiJ9.signature", | ||
"client_id": "client_id", | ||
"home_account_id": "uid.utid1" | ||
}, | ||
"uid1.utid1-login.windows.net-idtoken-client_id-utid2-": { | ||
"realm": "utid2", | ||
"environment": "login.windows.net", | ||
"credential_type": "IdToken", | ||
"secret": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6Imh1Tjk1SXZQZmVocTM0R3pCRFoxR1hHaXJuTSJ9.eyJvaWQiOiAib2JqZWN0MTIzNCIsICJwcmVmZXJyZWRfdXNlcm5hbWUiOiAiSm9obiBEb2UiLCAic3ViIjogInN1YiJ9.signature", | ||
"client_id": "client_id", | ||
"home_account_id": "uid.utid1" | ||
}, | ||
"uid1.utid1-login.windows.net-idtoken-client_id-utid3-": { | ||
"realm": "utid3", | ||
"environment": "login.windows.net", | ||
"credential_type": "IdToken", | ||
"secret": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6Imh1Tjk1SXZQZmVocTM0R3pCRFoxR1hHaXJuTSJ9.eyJvaWQiOiAib2JqZWN0MTIzNCIsICJwcmVmZXJyZWRfdXNlcm5hbWUiOiAiSm9obiBEb2UiLCAic3ViIjogInN1YiJ9.signature", | ||
"client_id": "client_id", | ||
"home_account_id": "uid.utid1" | ||
}, | ||
"uid5.utid4-login.windows.net-idtoken-client_id-utid4-": { | ||
"realm": "utid4", | ||
"environment": "login.windows.net", | ||
"credential_type": "IdToken", | ||
"secret": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6Imh1Tjk1SXZQZmVocTM0R3pCRFoxR1hHaXJuTSJ9.eyJvaWQiOiAib2JqZWN0MTIzNCIsICJwcmVmZXJyZWRfdXNlcm5hbWUiOiAiSm9obiBEb2UiLCAic3ViIjogInN1YiJ9.signature", | ||
"client_id": "client_id", | ||
"home_account_id": "uid5.utid4" | ||
}, | ||
"uid6.utid5-login.windows.net-idtoken-client_id-utid5-": { | ||
"realm": "utid5", | ||
"environment": "login.windows.net", | ||
"credential_type": "IdToken", | ||
"secret": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6Imh1Tjk1SXZQZmVocTM0R3pCRFoxR1hHaXJuTSJ9.eyJvaWQiOiAib2JqZWN0MTIzNCIsICJwcmVmZXJyZWRfdXNlcm5hbWUiOiAiSm9obiBEb2UiLCAic3ViIjogInN1YiJ9.signature", | ||
"client_id": "client_id", | ||
"home_account_id": "uid6.utid5" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters