use of com.microsoft.identity.common.internal.broker.ipc.IIpcStrategy in project microsoft-authentication-library-common-for-android by AzureAD.
the class BrokerOperationExecutorTests method getStrategyWithUserCanceledResult.
// Gets a bundle back, the bundle contains a user cancelled result.
private IIpcStrategy getStrategyWithUserCanceledResult() {
return new IIpcStrategy() {
@Override
@NonNull
public Bundle communicateToBroker(@NonNull final BrokerOperationBundle bundle) throws BrokerCommunicationException {
final Bundle result = new Bundle();
result.putBoolean(USER_CANCEL_BUNDLE_KEY, true);
return result;
}
@Override
public Type getType() {
return MOCK_TYPE;
}
};
}
use of com.microsoft.identity.common.internal.broker.ipc.IIpcStrategy in project microsoft-authentication-library-common-for-android by AzureAD.
the class IpcStrategyTests method testOperationSucceeds.
protected void testOperationSucceeds(@NonNull final BrokerOperationBundle bundle, @NonNull final Bundle expectedResultBundle) {
final IIpcStrategy strategy = getStrategy();
try {
final Bundle resultBundle = strategy.communicateToBroker(bundle);
Assert.assertNotNull(resultBundle);
Assert.assertTrue(isBundleEqual(resultBundle, expectedResultBundle));
} catch (BaseException e) {
Assert.fail("Exception is not expected.");
}
}
use of com.microsoft.identity.common.internal.broker.ipc.IIpcStrategy in project microsoft-authentication-library-common-for-android by AzureAD.
the class BrokerOperationExecutor method execute.
/**
* A generic method that would initialize and iterate through available strategies.
* It will return a result immediately if any of the strategy succeeds, or throw an exception if all of the strategies fails.
*/
public <T extends CommandParameters, U> U execute(@Nullable final T parameters, @NonNull final BrokerOperation<U> operation) throws BaseException {
final String methodName = ":execute";
emitOperationStartEvent(parameters, operation);
if (mStrategies.size() == 0) {
final ClientException exception = new ClientException(ErrorStrings.BROKER_BIND_SERVICE_FAILED, "No strategies can be used to connect to the broker.");
emitOperationFailureEvent(operation, exception);
throw exception;
}
final List<BrokerCommunicationException> communicationExceptionStack = new ArrayList<>();
for (final IIpcStrategy strategy : mStrategies) {
try {
final U result = performStrategy(strategy, operation);
emitOperationSuccessEvent(operation, result);
return result;
} catch (final BrokerCommunicationException communicationException) {
// Fails to communicate to the . Try next strategy.
communicationExceptionStack.add(communicationException);
} catch (final BaseException exception) {
emitOperationFailureEvent((BrokerOperation<U>) operation, exception);
throw exception;
}
}
final ClientException exception = new ClientException(ErrorStrings.BROKER_BIND_SERVICE_FAILED, "Unable to connect to the broker. Please refer to MSAL/Broker logs " + "or suppressed exception (API 19+) for more details.");
// This means that we've tried every strategies... log everything...
for (final BrokerCommunicationException e : communicationExceptionStack) {
Logger.error(TAG + methodName, e.getMessage(), e);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
exception.addSuppressed(e);
}
}
emitOperationFailureEvent(operation, exception);
throw exception;
}
use of com.microsoft.identity.common.internal.broker.ipc.IIpcStrategy in project microsoft-authentication-library-common-for-android by AzureAD.
the class BrokerMsalController method getIpcStrategies.
/**
* Gets a list of communication strategies.
* Order of objects in the list will reflects the order of strategies that will be used.
*/
@NonNull
private static List<IIpcStrategy> getIpcStrategies(final Context applicationContext, final String activeBrokerPackageName) {
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.isBrokerContentProviderAvailable(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)) {
sb.append("AccountManagerStrategy.");
strategies.add(new AccountManagerAddAccountStrategy(applicationContext));
}
Logger.info(TAG, sb.toString());
return strategies;
}
use of com.microsoft.identity.common.internal.broker.ipc.IIpcStrategy in project microsoft-authentication-library-common-for-android by AzureAD.
the class BrokerOperationExecutorTests method getStrategyWithValidResult.
private IIpcStrategy getStrategyWithValidResult() {
return new IIpcStrategy() {
@Override
@NonNull
public Bundle communicateToBroker(@NonNull BrokerOperationBundle bundle) throws BrokerCommunicationException {
final Bundle result = new Bundle();
result.putBoolean(SUCCESS_BUNDLE_KEY, true);
return result;
}
@Override
public Type getType() {
return MOCK_TYPE;
}
};
}
Aggregations