Skip to content

Commit

Permalink
small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rpdome committed Jan 30, 2024
1 parent 86ac2b2 commit 2e72dfc
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -193,15 +193,15 @@ class AccountManagerBackupIpcStrategyTargetingSpecificBrokerApp
}
} catch (t: Throwable) {
throw BrokerCommunicationException(
BrokerCommunicationException.Category.OPERATION_NOT_SUPPORTED_ON_SERVER_SIDE,
BrokerCommunicationException.Category.CONNECTION_ERROR,
type,
"$targetPackageName doesn't support account manager backup ipc for Broker Discovery.",
null)
}

if (!brokerValidator.isValidBrokerPackage(targetAppInfo.packageName)) {
throw BrokerCommunicationException(
BrokerCommunicationException.Category.OPERATION_NOT_SUPPORTED_ON_SERVER_SIDE,
BrokerCommunicationException.Category.CONNECTION_ERROR,
type,
"${targetAppInfo.packageName} is not a valid broker app",
null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import static com.microsoft.identity.common.internal.broker.ipc.BrokerOperationBundle.Operation.MSAL_SIGN_OUT_FROM_SHARED_DEVICE;
import static com.microsoft.identity.common.internal.broker.ipc.BrokerOperationBundle.Operation.MSAL_SSO_TOKEN;
import static com.microsoft.identity.common.internal.controllers.BrokerOperationExecutor.BrokerOperation;
import static com.microsoft.identity.common.internal.util.StringUtil.isEmpty;
import static com.microsoft.identity.common.java.AuthenticationConstants.Broker.BROKER_ACCOUNT_TYPE;
import static com.microsoft.identity.common.java.AuthenticationConstants.LocalBroadcasterAliases.RETURN_BROKER_INTERACTIVE_ACQUIRE_TOKEN_RESULT;
import static com.microsoft.identity.common.java.AuthenticationConstants.LocalBroadcasterFields.REQUEST_CODE;
Expand Down Expand Up @@ -115,9 +114,9 @@
import com.microsoft.identity.common.java.util.ported.LocalBroadcaster;
import com.microsoft.identity.common.java.util.ported.PropertyBag;
import com.microsoft.identity.common.logging.Logger;
import com.microsoft.identity.common.sharedwithoneauth.OneAuthSharedFunctions;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.ExecutionException;
Expand Down Expand Up @@ -164,7 +163,7 @@ public BrokerMsalController(@NonNull final Context applicationContext,
this(applicationContext,
components,
activeBrokerPackageName,
getIpcStrategies(applicationContext, activeBrokerPackageName));
OneAuthSharedFunctions.getIpcStrategies(applicationContext, activeBrokerPackageName));
}

@VisibleForTesting
Expand All @@ -178,42 +177,6 @@ public HelloCache getHelloCache() {
);
}

/**
* Gets a list of communication strategies.
* Order of objects in the list will reflects the order of strategies that will be used.
*/
@NonNull
static List<IIpcStrategy> getIpcStrategies(final Context applicationContext,
final String activeBrokerPackageName) {
final String methodTag = TAG + ":getIpcStrategies";
final List<IIpcStrategy> strategies = new ArrayList<>();
final StringBuilder sb = new StringBuilder(100);
sb.append("Broker Strategies added : ");

final ContentProviderStrategy contentProviderStrategy = new ContentProviderStrategy(applicationContext);
if (contentProviderStrategy.isSupportedByTargetedBroker(activeBrokerPackageName)) {
sb.append("ContentProviderStrategy, ");
strategies.add(contentProviderStrategy);
}

final MicrosoftAuthClient client = new MicrosoftAuthClient(applicationContext);
if (client.isBoundServiceSupported(activeBrokerPackageName)) {
sb.append("BoundServiceStrategy, ");
strategies.add(new BoundServiceStrategy<>(client));
}

if (AccountManagerUtil.canUseAccountManagerOperation(applicationContext,
Collections.singleton(BROKER_ACCOUNT_TYPE)))
{
sb.append("AccountManagerStrategy.");
strategies.add(new AccountManagerAddAccountStrategy(applicationContext));
}

Logger.info(methodTag, sb.toString());

return strategies;
}

/**
* MSAL-Broker handshake operation.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// Copyright (c) Microsoft Corporation.
// All rights reserved.
//
// This code is licensed under the MIT License.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files(the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
package com.microsoft.identity.common.sharedwithoneauth

import android.content.Context
import com.microsoft.identity.common.internal.broker.MicrosoftAuthClient
import com.microsoft.identity.common.internal.broker.ipc.AccountManagerAddAccountStrategy
import com.microsoft.identity.common.internal.broker.ipc.BoundServiceStrategy
import com.microsoft.identity.common.internal.broker.ipc.ContentProviderStrategy
import com.microsoft.identity.common.internal.broker.ipc.IIpcStrategy
import com.microsoft.identity.common.internal.util.AccountManagerUtil
import com.microsoft.identity.common.java.AuthenticationConstants
import com.microsoft.identity.common.logging.Logger

// Functions to be invoked by both OneAuth and MSAL Android
// Making a change to any method signature is a breaking change.
class OneAuthSharedFunctions {

companion object {
val TAG = OneAuthSharedFunctions::class.java

/**
* Constructs a list of [IIpcStrategy] to communicate from
* OneAuth/MSAL to Broker process.
*
* @param context [Context]
* @param activeBrokerPackageName name of the app hosting the broker process to communicate to.
**/
@JvmStatic
fun getIpcStrategies(
context: Context,
activeBrokerPackageName: String,
): List<IIpcStrategy> {
val methodTag = "$TAG:getIpcStrategies"
val strategies: MutableList<IIpcStrategy> = ArrayList()

val sb = StringBuilder(100)
sb.append("Broker Strategies added : ")
val contentProviderStrategy = ContentProviderStrategy(context)
if (contentProviderStrategy.isSupportedByTargetedBroker(activeBrokerPackageName)) {
sb.append("ContentProviderStrategy, ")
strategies.add(contentProviderStrategy)
}

val client = MicrosoftAuthClient(context)
if (client.isBoundServiceSupported(activeBrokerPackageName)) {
sb.append("BoundServiceStrategy, ")
strategies.add(BoundServiceStrategy(client))
}

if (AccountManagerUtil.canUseAccountManagerOperation(
context, setOf(AuthenticationConstants.Broker.BROKER_ACCOUNT_TYPE)
)
) {
sb.append("AccountManagerStrategy.")
strategies.add(AccountManagerAddAccountStrategy(context))
}

Logger.info(methodTag, sb.toString())
return strategies
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ class AccountManagerBackupIpcStrategyTargetingSpecificBrokerAppTest {
)
} catch (t: Throwable) {
Assert.assertEquals(
BrokerCommunicationException.Category.OPERATION_NOT_SUPPORTED_ON_SERVER_SIDE,
BrokerCommunicationException.Category.CONNECTION_ERROR,
(t as BrokerCommunicationException).category)
}
}
Expand Down Expand Up @@ -247,7 +247,7 @@ class AccountManagerBackupIpcStrategyTargetingSpecificBrokerAppTest {
)
} catch (t: Throwable) {
Assert.assertEquals(
BrokerCommunicationException.Category.OPERATION_NOT_SUPPORTED_ON_SERVER_SIDE,
BrokerCommunicationException.Category.CONNECTION_ERROR,
(t as BrokerCommunicationException).category)
}
}
Expand Down

0 comments on commit 2e72dfc

Please sign in to comment.