Search in sources :

Example 1 with ResultFuture

use of com.microsoft.identity.common.internal.result.ResultFuture in project microsoft-authentication-library-common-for-android by AzureAD.

the class MockStrategyWithMockedHttpResponse method requestAuthorization.

/**
 * Template method for executing an OAuth2 authorization request.
 *
 * @param request               microsoft sts authorization request.
 * @param authorizationStrategy authorization strategy.
 * @return GenericAuthorizationResponse
 */
@Override
public Future<AuthorizationResult> requestAuthorization(final MicrosoftStsAuthorizationRequest request, final AuthorizationStrategy authorizationStrategy) {
    final MockSuccessAuthorizationResultMockedTests authorizationResult = new MockSuccessAuthorizationResultMockedTests();
    final ResultFuture<AuthorizationResult> future = new ResultFuture<>();
    future.setResult(authorizationResult);
    return future;
}
Also used : ResultFuture(com.microsoft.identity.common.internal.result.ResultFuture) MockSuccessAuthorizationResultMockedTests(com.microsoft.identity.internal.testutils.mocks.MockSuccessAuthorizationResultMockedTests) AuthorizationResult(com.microsoft.identity.common.internal.providers.oauth2.AuthorizationResult)

Example 2 with ResultFuture

use of com.microsoft.identity.common.internal.result.ResultFuture in project microsoft-authentication-library-common-for-android by AzureAD.

the class ResourceOwnerPasswordCredentialsTestStrategy method requestAuthorization.

/**
 * Template method for executing an OAuth2 authorization request.
 *
 * @param request               microsoft sts authorization request.
 * @param authorizationStrategy authorization strategy.
 * @return GenericAuthorizationResponse
 */
@Override
public Future<AuthorizationResult> requestAuthorization(final MicrosoftStsAuthorizationRequest request, final AuthorizationStrategy authorizationStrategy) {
    final MockSuccessAuthorizationResultNetworkTests authorizationResult = new MockSuccessAuthorizationResultNetworkTests();
    final ResultFuture<AuthorizationResult> future = new ResultFuture<>();
    future.setResult(authorizationResult);
    return future;
}
Also used : ResultFuture(com.microsoft.identity.common.internal.result.ResultFuture) AuthorizationResult(com.microsoft.identity.common.internal.providers.oauth2.AuthorizationResult) MockSuccessAuthorizationResultNetworkTests(com.microsoft.identity.internal.testutils.mocks.MockSuccessAuthorizationResultNetworkTests)

Example 3 with ResultFuture

use of com.microsoft.identity.common.internal.result.ResultFuture in project microsoft-authentication-library-common-for-android by AzureAD.

the class BoundServiceClient method connect.

/**
 * Binds to the service.
 *
 * @param targetServicePackageName Package name of the app this client will talk to.
 */
@NonNull
protected T connect(@NonNull final String targetServicePackageName) throws BrokerCommunicationException, InterruptedException, TimeoutException, ExecutionException {
    final String methodName = ":connect";
    if (!isBoundServiceSupported(targetServicePackageName)) {
        final String errorMessage = "Bound service is not supported.";
        Logger.info(TAG + methodName, errorMessage);
        throw new BrokerCommunicationException(OPERATION_NOT_SUPPORTED_ON_SERVER_SIDE, BOUND_SERVICE, errorMessage, null);
    }
    final ResultFuture<IBinder> future = new ResultFuture<>();
    mConnection = new BoundServiceConnection(future);
    mHasStartedBinding = mContext.bindService(getIntentForBoundService(targetServicePackageName), mConnection, Context.BIND_AUTO_CREATE);
    if (!mHasStartedBinding) {
        final String errorMessage = "failed to bind. The service is not available.";
        Logger.info(TAG + methodName, errorMessage);
        throw new BrokerCommunicationException(OPERATION_NOT_SUPPORTED_ON_SERVER_SIDE, BOUND_SERVICE, errorMessage, null);
    }
    Logger.info(TAG + "connect", "Android is establishing the bound service connection.");
    final IBinder binder = future.get(mTimeOutInSeconds, TimeUnit.SECONDS);
    return getInterfaceFromIBinder(binder);
}
Also used : IBinder(android.os.IBinder) ResultFuture(com.microsoft.identity.common.internal.result.ResultFuture) BrokerCommunicationException(com.microsoft.identity.common.exception.BrokerCommunicationException) NonNull(androidx.annotation.NonNull)

Example 4 with ResultFuture

use of com.microsoft.identity.common.internal.result.ResultFuture in project microsoft-authentication-library-common-for-android by AzureAD.

the class MockTestStrategy method requestAuthorization.

/**
 * Template method for executing an OAuth2 authorization request.
 *
 * @param request               microsoft sts authorization request.
 * @param authorizationStrategy authorization strategy.
 * @return GenericAuthorizationResponse
 */
@Override
public Future<AuthorizationResult> requestAuthorization(final MicrosoftStsAuthorizationRequest request, final AuthorizationStrategy authorizationStrategy) {
    final MockSuccessAuthorizationResultMockedTests authorizationResult = new MockSuccessAuthorizationResultMockedTests();
    final ResultFuture<AuthorizationResult> future = new ResultFuture<>();
    future.setResult(authorizationResult);
    return future;
}
Also used : ResultFuture(com.microsoft.identity.common.internal.result.ResultFuture) MockSuccessAuthorizationResultMockedTests(com.microsoft.identity.internal.testutils.mocks.MockSuccessAuthorizationResultMockedTests) AuthorizationResult(com.microsoft.identity.common.internal.providers.oauth2.AuthorizationResult)

Aggregations

ResultFuture (com.microsoft.identity.common.internal.result.ResultFuture)4 AuthorizationResult (com.microsoft.identity.common.internal.providers.oauth2.AuthorizationResult)3 MockSuccessAuthorizationResultMockedTests (com.microsoft.identity.internal.testutils.mocks.MockSuccessAuthorizationResultMockedTests)2 IBinder (android.os.IBinder)1 NonNull (androidx.annotation.NonNull)1 BrokerCommunicationException (com.microsoft.identity.common.exception.BrokerCommunicationException)1 MockSuccessAuthorizationResultNetworkTests (com.microsoft.identity.internal.testutils.mocks.MockSuccessAuthorizationResultNetworkTests)1