Search in sources :

Example 1 with BrokerOperationBundle

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;
        }
    };
}
Also used : BrokerOperationBundle(com.microsoft.identity.common.internal.broker.ipc.BrokerOperationBundle) Bundle(android.os.Bundle) BrokerOperationBundle(com.microsoft.identity.common.internal.broker.ipc.BrokerOperationBundle) IIpcStrategy(com.microsoft.identity.common.internal.broker.ipc.IIpcStrategy) NonNull(androidx.annotation.NonNull)

Example 2 with BrokerOperationBundle

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.");
    }
}
Also used : BaseException(com.microsoft.identity.common.exception.BaseException) Bundle(android.os.Bundle) BrokerOperationBundle(com.microsoft.identity.common.internal.broker.ipc.BrokerOperationBundle) BaseBundle(android.os.BaseBundle) IIpcStrategy(com.microsoft.identity.common.internal.broker.ipc.IIpcStrategy)

Example 3 with BrokerOperationBundle

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);
    }
}
Also used : Bundle(android.os.Bundle) BrokerOperationBundle(com.microsoft.identity.common.internal.broker.ipc.BrokerOperationBundle) Intent(android.content.Intent) BrokerCommunicationException(com.microsoft.identity.common.exception.BrokerCommunicationException) Nullable(androidx.annotation.Nullable)

Example 4 with BrokerOperationBundle

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;
}
Also used : BrokerOperationBundle(com.microsoft.identity.common.internal.broker.ipc.BrokerOperationBundle) Bundle(android.os.Bundle) BrokerOperationBundle(com.microsoft.identity.common.internal.broker.ipc.BrokerOperationBundle) VisibleForTesting(androidx.annotation.VisibleForTesting) NonNull(androidx.annotation.NonNull)

Example 5 with BrokerOperationBundle

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.
}
Also used : BrokerOperationBundle(com.microsoft.identity.common.internal.broker.ipc.BrokerOperationBundle) Bundle(android.os.Bundle) BrokerOperationBundle(com.microsoft.identity.common.internal.broker.ipc.BrokerOperationBundle)

Aggregations

Bundle (android.os.Bundle)9 BrokerOperationBundle (com.microsoft.identity.common.internal.broker.ipc.BrokerOperationBundle)9 NonNull (androidx.annotation.NonNull)5 IIpcStrategy (com.microsoft.identity.common.internal.broker.ipc.IIpcStrategy)5 BaseBundle (android.os.BaseBundle)2 BaseException (com.microsoft.identity.common.exception.BaseException)2 Context (android.content.Context)1 Intent (android.content.Intent)1 Nullable (androidx.annotation.Nullable)1 VisibleForTesting (androidx.annotation.VisibleForTesting)1 BrokerCommunicationException (com.microsoft.identity.common.exception.BrokerCommunicationException)1 CommandParameters (com.microsoft.identity.common.internal.commands.parameters.CommandParameters)1 BrokerMsalController (com.microsoft.identity.common.internal.controllers.BrokerMsalController)1 Test (org.junit.Test)1