use of com.microsoft.identity.common.internal.broker.ipc.BrokerOperationBundle 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.BrokerOperationBundle 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.BrokerOperationBundle in project microsoft-authentication-library-common-for-android by AzureAD.
the class MicrosoftAuthClient method performOperationInternal.
@Override
@Nullable
Bundle performOperationInternal(@NonNull final BrokerOperationBundle brokerOperationBundle, @NonNull final IMicrosoftAuthService microsoftAuthService) throws RemoteException, BrokerCommunicationException {
final Bundle inputBundle = brokerOperationBundle.getBundle();
switch(brokerOperationBundle.getOperation()) {
case MSAL_HELLO:
return microsoftAuthService.hello(inputBundle);
case MSAL_GET_INTENT_FOR_INTERACTIVE_REQUEST:
final Intent intent = microsoftAuthService.getIntentForInteractiveRequest();
final Bundle bundle = intent.getExtras();
// older brokers (pre-ContentProvider) are ONLY sending these values in the intent itself.
if (intent.getComponent() != null && !TextUtils.isEmpty(intent.getPackage()) && !TextUtils.isEmpty(intent.getComponent().getClassName())) {
bundle.putString(BROKER_PACKAGE_NAME, intent.getPackage());
bundle.putString(BROKER_ACTIVITY_NAME, intent.getComponent().getClassName());
}
return bundle;
case MSAL_ACQUIRE_TOKEN_SILENT:
return microsoftAuthService.acquireTokenSilently(inputBundle);
case MSAL_GET_ACCOUNTS:
return microsoftAuthService.getAccounts(inputBundle);
case MSAL_REMOVE_ACCOUNT:
return microsoftAuthService.removeAccount(inputBundle);
case MSAL_GET_DEVICE_MODE:
return microsoftAuthService.getDeviceMode();
case MSAL_GET_CURRENT_ACCOUNT_IN_SHARED_DEVICE:
return microsoftAuthService.getCurrentAccount(inputBundle);
case MSAL_SIGN_OUT_FROM_SHARED_DEVICE:
return microsoftAuthService.removeAccountFromSharedDevice(inputBundle);
case MSAL_GENERATE_SHR:
return microsoftAuthService.generateSignedHttpRequest(inputBundle);
default:
final String errorMessage = "Operation " + brokerOperationBundle.getOperation().name() + " is not supported by MicrosoftAuthClient.";
throw new BrokerCommunicationException(OPERATION_NOT_SUPPORTED_ON_CLIENT_SIDE, BOUND_SERVICE, errorMessage, null);
}
}
use of com.microsoft.identity.common.internal.broker.ipc.BrokerOperationBundle in project microsoft-authentication-library-common-for-android by AzureAD.
the class BrokerMsalController method hello.
/**
* MSAL-Broker handshake operation.
*
* @param strategy an {@link IIpcStrategy}
* @param minRequestedVersion the minimum allowed broker protocol version, may be null.
* @return a protocol version negotiated by MSAL and Broker.
*/
@VisibleForTesting
@NonNull
public String hello(@NonNull final IIpcStrategy strategy, @Nullable final String minRequestedVersion) throws BaseException {
final String cachedProtocolVersion = mHelloCache.tryGetNegotiatedProtocolVersion(minRequestedVersion, MSAL_TO_BROKER_PROTOCOL_VERSION_CODE);
if (!StringUtil.isEmpty(cachedProtocolVersion)) {
return cachedProtocolVersion;
}
final Bundle bundle = new Bundle();
bundle.putString(CLIENT_ADVERTISED_MAXIMUM_BP_VERSION_KEY, MSAL_TO_BROKER_PROTOCOL_VERSION_CODE);
if (!StringUtil.isEmpty(minRequestedVersion)) {
bundle.putString(CLIENT_CONFIGURED_MINIMUM_BP_VERSION_KEY, minRequestedVersion);
}
final BrokerOperationBundle helloBundle = new BrokerOperationBundle(BrokerOperationBundle.Operation.MSAL_HELLO, mActiveBrokerPackageName, bundle);
final String negotiatedProtocolVersion = mResultAdapter.verifyHelloFromResultBundle(strategy.communicateToBroker(helloBundle));
mHelloCache.saveNegotiatedProtocolVersion(minRequestedVersion, MSAL_TO_BROKER_PROTOCOL_VERSION_CODE, negotiatedProtocolVersion);
return negotiatedProtocolVersion;
}
use of com.microsoft.identity.common.internal.broker.ipc.BrokerOperationBundle in project microsoft-authentication-library-common-for-android by AzureAD.
the class BrokerOperationExecutor method performStrategy.
/**
* Execute the given operation with a given IIpcStrategy.
*/
private <T> T performStrategy(@NonNull final IIpcStrategy strategy, @NonNull final BrokerOperation<T> operation) throws BaseException {
com.microsoft.identity.common.internal.logging.Logger.info(TAG + operation.getMethodName(), "Executing with IIpcStrategy: " + strategy.getClass().getSimpleName());
operation.performPrerequisites(strategy);
final BrokerOperationBundle brokerOperationBundle = operation.getBundle();
final Bundle resultBundle = strategy.communicateToBroker(brokerOperationBundle);
return operation.extractResultBundle(resultBundle);
// TODO: Emit success rate and performance of each strategy to eSTS in a finally block.
}
Aggregations