Skip to content

Commit 2e3a068

Browse files
authored
Merge pull request #895 from AzureAD/shahzaibj/mergeRelease2.0.7ToMaster
Merge release 2.0.7 to master
2 parents 941927c + c00fe38 commit 2e3a068

68 files changed

Lines changed: 3608 additions & 2633 deletions

File tree

Some content is hidden

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

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,7 @@ provided by the bot. You will only need to do this once across all repos using o
1919
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
2020
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
2121
contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
22+
23+
### Android Studio Build Requirement
24+
Please note that this project uses [Lombok](https://projectlombok.org/) internally and while using Android Studio you will need to install [Lobmok Plugin](https://plugins.jetbrains.com/plugin/6317-lombok) to get the project to build successfully within Android Studio.
25+

changelog.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
Version 2.0.7
2+
------------
3+
- Added throttling
4+
- Added Dual Client Stack support for FoCI apps
5+
- Added support to compress broker payload using GZIP
6+
- Added flag to enable/disable power optimization check
7+
- Removed check for usage stat manager to determine if network is disabled
8+
- Project wide internal code refactoring using Lombok
9+
110
Version 2.0.6
211
------------
312
- Use fixed thread pool for silent requests

common/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ dependencies {
8484
implementation "com.google.code.gson:gson:$rootProject.ext.gsonVersion"
8585
implementation "androidx.browser:browser:$rootProject.ext.browserVersion"
8686
implementation "androidx.constraintlayout:constraintlayout:$rootProject.ext.constraintLayoutVersion"
87+
compileOnly "org.projectlombok:lombok:$rootProject.ext.lombokVersion"
88+
annotationProcessor "org.projectlombok:lombok:$rootProject.ext.lombokVersion"
8789

8890
// Test dependencies
8991
// Needed to resolve JSONObject inside of non-instrumented tests

common/src/androidTest/java/com/microsoft/identity/common/MsalOAuth2TokenCacheTest.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1307,4 +1307,43 @@ public void getAccoutsWithIdTokensEmpty() {
13071307
assertTrue(records.isEmpty());
13081308
}
13091309

1310+
@Test
1311+
public void testFrtFallback() throws ClientException {
1312+
// This test verifies changes in common/#893
1313+
// We will fallback on an FRT in the local cache for the current user if one is avail
1314+
final List<ICacheRecord> result = loadTestBundleIntoCacheWithAggregation(
1315+
defaultTestBundleV2
1316+
);
1317+
1318+
assertEquals(1, result.size());
1319+
1320+
final ICacheRecord entry = result.get(0);
1321+
1322+
assertNotNull(entry.getAccount());
1323+
assertNotNull(entry.getIdToken());
1324+
assertNotNull(entry.getAccessToken());
1325+
assertNotNull(entry.getRefreshToken());
1326+
1327+
// delete the existing RT and insert our FRT
1328+
accountCredentialCache.removeCredential(entry.getRefreshToken());
1329+
1330+
// Modify the existing RT to change the client_id and set a FoCI affiliation
1331+
final String fociRtClientId = UUID.randomUUID().toString();
1332+
final RefreshTokenRecord modifiedRT = entry.getRefreshToken();
1333+
modifiedRT.setFamilyId("1");
1334+
modifiedRT.setClientId(fociRtClientId);
1335+
1336+
accountCredentialCache.saveCredential(modifiedRT);
1337+
1338+
final ICacheRecord secondaryLoad = mOauth2TokenCache.load(
1339+
entry.getAccessToken().getClientId(),
1340+
TARGET,
1341+
entry.getAccount(),
1342+
BEARER_AUTHENTICATION_SCHEME
1343+
);
1344+
1345+
assertNotNull(secondaryLoad.getRefreshToken());
1346+
assertEquals(fociRtClientId, secondaryLoad.getRefreshToken().getClientId());
1347+
}
1348+
13101349
}

common/src/main/java/com/microsoft/identity/common/adal/internal/AuthenticationConstants.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ public static final class Broker {
628628
/**
629629
* The maximum broker protocol version that common supports.
630630
*/
631-
public static final String BROKER_PROTOCOL_VERSION_CODE = "4.0";
631+
public static final String BROKER_PROTOCOL_VERSION_CODE = "5.0";
632632

633633
/**
634634
* The key of maximum broker protocol version that client advertised.
@@ -1070,11 +1070,22 @@ public static final class Broker {
10701070
*/
10711071
public static final String BROKER_REQUEST_V2 = "broker_request_v2";
10721072

1073+
1074+
/**
1075+
* String to send MSAL V2 Request params as gzip compressed byte array.
1076+
*/
1077+
public static final String BROKER_REQUEST_V2_COMPRESSED = "broker_request_v2_compressed";
1078+
10731079
/**
10741080
* String to return Msal V2 response.
10751081
*/
10761082
public static final String BROKER_RESULT_V2 = "broker_result_v2";
10771083

1084+
/**
1085+
* String to return MSA: V2 response as gzip compressed byte array.
1086+
*/
1087+
public static final String BROKER_RESULT_V2_COMPRESSED = "broker_result_v2_compressed";
1088+
10781089
/**
10791090
* Represents the broker device mode boolean (true = shared device mode).
10801091
* This is used to determine what PublicClientApplication MSAL will return to its caller.
@@ -1137,6 +1148,11 @@ public static final class Broker {
11371148
*/
11381149
public static final String BROKER_ACCOUNTS = "broker_accounts";
11391150

1151+
/**
1152+
* String to return account list as compressed json.
1153+
*/
1154+
public static final String BROKER_ACCOUNTS_COMPRESSED = "broker_accounts_compressed";
1155+
11401156
/**
11411157
* String to return current account from broker (only available in shared device mode)
11421158
*/

common/src/main/java/com/microsoft/identity/common/adal/internal/net/DefaultConnectionService.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public boolean isConnectionAvailable() {
6464
.getSystemService(Context.CONNECTIVITY_SERVICE);
6565
NetworkInfo activeNetwork = connectivityManager.getActiveNetworkInfo();
6666
@SuppressWarnings("deprecation")
67-
final boolean isConnectionAvailable = activeNetwork != null && activeNetwork.isConnectedOrConnecting() && !isNetworkDisabledFromOptimizations();
67+
final boolean isConnectionAvailable = activeNetwork != null && activeNetwork.isConnectedOrConnecting();
6868
Telemetry.emit((BaseEvent) new BaseEvent().put(TelemetryEventStrings.Key.NETWORK_CONNECTION, String.valueOf(isConnectionAvailable)));
6969
return isConnectionAvailable;
7070
}
@@ -78,19 +78,12 @@ public boolean isConnectionAvailable() {
7878
@TargetApi(Build.VERSION_CODES.M)
7979
public boolean isNetworkDisabledFromOptimizations() {
8080
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
81-
final UsageStatsManagerWrapper usageStatsManagerWrapper = UsageStatsManagerWrapper.getInstance();
82-
if (usageStatsManagerWrapper.isAppInactive(mConnectionContext)) {
83-
Telemetry.emit((BaseEvent) new BaseEvent().put(TelemetryEventStrings.Key.POWER_OPTIMIZATION, String.valueOf(true)));
84-
return true;
85-
}
86-
8781
final PowerManagerWrapper powerManagerWrapper = PowerManagerWrapper.getInstance();
8882
if (powerManagerWrapper.isDeviceIdleMode(mConnectionContext) && !powerManagerWrapper.isIgnoringBatteryOptimizations(mConnectionContext)) {
8983
Telemetry.emit((BaseEvent) new BaseEvent().put(TelemetryEventStrings.Key.POWER_OPTIMIZATION, String.valueOf(true)));
9084
return true;
9185
}
9286
}
93-
9487
Telemetry.emit((BaseEvent) new BaseEvent().put(TelemetryEventStrings.Key.POWER_OPTIMIZATION, String.valueOf(false)));
9588
return false;
9689
}

common/src/main/java/com/microsoft/identity/common/adal/internal/net/HttpWebRequest.java

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -185,24 +185,28 @@ public HttpWebResponse send() throws IOException {
185185
* when connection is not available to refresh token because power optimization is enabled, or
186186
* throw with error code {@link ErrorStrings#DEVICE_NETWORK_NOT_AVAILABLE} otherwise.
187187
*
188-
* @param context Context
188+
* @param context Context : application context
189+
* @param skipPowerOptimizationCheck : boolean to skip power optimization check
190+
*
189191
* @throws ClientException throw network exception
190192
*/
191-
public static void throwIfNetworkNotAvailable(final Context context) throws ClientException {
193+
public static void throwIfNetworkNotAvailable(final Context context,
194+
final boolean skipPowerOptimizationCheck)
195+
throws ClientException {
196+
192197
final DefaultConnectionService connectionService = new DefaultConnectionService(context);
198+
199+
if (skipPowerOptimizationCheck && connectionService.isNetworkDisabledFromOptimizations()) {
200+
throw new ClientException(
201+
ErrorStrings.NO_NETWORK_CONNECTION_POWER_OPTIMIZATION,
202+
"Connection is not available to refresh token because power optimization is "
203+
+ "enabled. And the device is in doze mode or the app is standby");
204+
}
205+
193206
if (!connectionService.isConnectionAvailable()) {
194-
if (connectionService.isNetworkDisabledFromOptimizations()) {
195-
final ClientException dozeModeException = new ClientException(
196-
ErrorStrings.NO_NETWORK_CONNECTION_POWER_OPTIMIZATION,
197-
"Connection is not available to refresh token because power optimization is "
198-
+ "enabled. And the device is in doze mode or the app is standby");
199-
throw dozeModeException;
200-
} else {
201-
final ClientException generalNetworkException = new ClientException(
202-
ErrorStrings.DEVICE_NETWORK_NOT_AVAILABLE,
203-
"Connection is not available to refresh token");
204-
throw generalNetworkException;
205-
}
207+
throw new ClientException(
208+
ErrorStrings.DEVICE_NETWORK_NOT_AVAILABLE,
209+
"Connection is not available to refresh token");
206210
}
207211
}
208212

common/src/main/java/com/microsoft/identity/common/internal/authscheme/AbstractAuthenticationScheme.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,12 @@
2626

2727
import com.google.gson.annotations.SerializedName;
2828

29+
import lombok.EqualsAndHashCode;
30+
2931
/**
3032
* Abstract base class for AuthenticationSchemes.
3133
*/
34+
@EqualsAndHashCode
3235
public abstract class AbstractAuthenticationScheme implements INameable {
3336

3437
private static final long serialVersionUID = -2437270903389813253L;

common/src/main/java/com/microsoft/identity/common/internal/broker/BrokerRequest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ private class SerializedNames {
5757
final static String MULTIPLE_CLOUDS_SUPPORTED = "multiple_clouds_supported";
5858
final static String AUTHORIZATION_AGENT = "authorization_agent";
5959
final static String AUTHENTICATION_SCHEME = "authentication_scheme";
60+
final static String POWER_OPT_CHECK_ENABLED = "power_opt_check_enabled";
6061
}
6162

6263
/**
@@ -189,6 +190,10 @@ private class SerializedNames {
189190
@SerializedName(SerializedNames.AUTHENTICATION_SCHEME)
190191
private AbstractAuthenticationScheme mAuthenticationScheme;
191192

193+
@Nullable
194+
@SerializedName(SerializedNames.POWER_OPT_CHECK_ENABLED)
195+
private boolean mPowerOptCheckEnabled;
196+
192197
private BrokerRequest(BrokerRequest.Builder builder) {
193198
mAuthority = builder.mAuthority;
194199
mScope = builder.mScope;
@@ -209,6 +214,7 @@ private BrokerRequest(BrokerRequest.Builder builder) {
209214
mMultipleCloudsSupported = builder.mMultipleCloudsSupported;
210215
mAuthorizationAgent = builder.mAuthorizationAgent;
211216
mAuthenticationScheme = builder.mAuthenticationScheme;
217+
mPowerOptCheckEnabled = builder.mPowerOptCheckEnabled;
212218
}
213219

214220
public String getAuthority() {
@@ -287,6 +293,10 @@ public AbstractAuthenticationScheme getAuthenticationScheme() {
287293
return mAuthenticationScheme;
288294
}
289295

296+
public boolean isPowerOptCheckEnabled(){
297+
return mPowerOptCheckEnabled;
298+
}
299+
290300
/**
291301
* Builder class for Broker Request.
292302
*/
@@ -330,6 +340,8 @@ public static class Builder {
330340

331341
private AbstractAuthenticationScheme mAuthenticationScheme;
332342

343+
private boolean mPowerOptCheckEnabled;
344+
333345
/**
334346
* Authority for the request
335347
*/
@@ -476,6 +488,11 @@ public BrokerRequest.Builder authenticationScheme(@NonNull final AbstractAuthent
476488
return this;
477489
}
478490

491+
public BrokerRequest.Builder powerOptCheckEnabled(final boolean powerOptCheckEnabled) {
492+
this.mPowerOptCheckEnabled = powerOptCheckEnabled;
493+
return this;
494+
}
495+
479496
/**
480497
* Builds and returns a BrokerRequest
481498
*/

common/src/main/java/com/microsoft/identity/common/internal/cache/IAccountCredentialCache.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public interface IAccountCredentialCache {
7676
* @param homeAccountId The homeAccountId used to match Account cache keys.
7777
* @param environment The environment used to match Account cache keys.
7878
* @param realm The realm used to match Account cache keys.
79-
* @return A List of Accounts matching the supplied criteria.
79+
* @return A mutable List of Accounts matching the supplied criteria.
8080
*/
8181
List<AccountRecord> getAccountsFilteredBy(
8282
final String homeAccountId,
@@ -87,7 +87,7 @@ List<AccountRecord> getAccountsFilteredBy(
8787
/**
8888
* Returns all of the Credentials saved in the cache.
8989
*
90-
* @return The saved Credentials.
90+
* @return A mutable List of saved Credentials.
9191
*/
9292
List<Credential> getCredentials();
9393

@@ -100,7 +100,7 @@ List<AccountRecord> getAccountsFilteredBy(
100100
* @param clientId The clientId used to match Credential cache keys.
101101
* @param realm The realm used to match Credential cache keys.
102102
* @param target The target used to match Credential cache keys.
103-
* @return A List of Credentials matching the supplied criteria.
103+
* @return A mutable List of Credentials matching the supplied criteria.
104104
*/
105105
List<Credential> getCredentialsFilteredBy(
106106
final String homeAccountId,

0 commit comments

Comments
 (0)