Search in sources :

Example 11 with BaseException

use of com.microsoft.identity.common.exception.BaseException in project microsoft-authentication-library-common-for-android by AzureAD.

the class EstsTelemetry method isTelemetryLoggedByServer.

private boolean isTelemetryLoggedByServer(@SuppressWarnings(WarningType.rawtype_warning) @NonNull final BaseCommand command, @NonNull final CommandResult commandResult) {
    // This was a local operation - we didn't reach token endpoint and hence telemetry wasn't sent
    if (!(command instanceof TokenCommand)) {
        return false;
    }
    if (commandResult.getStatus() == CommandResult.ResultStatus.ERROR) {
        BaseException baseException = (BaseException) commandResult.getResult();
        if (!(baseException instanceof ServiceException)) {
            // (request did not reach token endpoint)
            return false;
        } else {
            final ServiceException serviceException = (ServiceException) baseException;
            final int statusCode = serviceException.getHttpStatusCode();
            // for these status codes, headers aren't logged by ests
            return !(statusCode == ServiceException.DEFAULT_STATUS_CODE || statusCode == 429 || statusCode >= 500);
        }
    } else if (commandResult.getStatus() == CommandResult.ResultStatus.CANCEL) {
        // we did not go to token endpoint
        return false;
    } else if (commandResult.getStatus() == CommandResult.ResultStatus.COMPLETED) {
        if (commandResult.getResult() instanceof ILocalAuthenticationResult) {
            final ILocalAuthenticationResult localAuthenticationResult = (ILocalAuthenticationResult) commandResult.getResult();
            if (localAuthenticationResult.isServicedFromCache()) {
                // we did not go to token endpoint
                return false;
            }
        } else {
            // command probably wasn't a token command - we should never get here in that case
            return false;
        }
    }
    // if we get here that means we went to token endpoint and headers were logged by sts
    return true;
}
Also used : BaseException(com.microsoft.identity.common.exception.BaseException) ServiceException(com.microsoft.identity.common.exception.ServiceException) TokenCommand(com.microsoft.identity.common.internal.commands.TokenCommand) ILocalAuthenticationResult(com.microsoft.identity.common.internal.result.ILocalAuthenticationResult)

Example 12 with BaseException

use of com.microsoft.identity.common.exception.BaseException in project microsoft-authentication-library-common-for-android by AzureAD.

the class ApiEndEvent method putException.

public ApiEndEvent putException(@NonNull final Exception exception) {
    if (exception == null) {
        return this;
    }
    final BaseException adaptedException = ExceptionAdapter.baseExceptionFromException(exception);
    if (adaptedException instanceof UserCancelException) {
        put(Key.USER_CANCEL, Value.TRUE);
    }
    put(Key.SERVER_ERROR_CODE, adaptedException.getCliTelemErrorCode());
    put(Key.SERVER_SUBERROR_CODE, adaptedException.getCliTelemSubErrorCode());
    put(Key.ERROR_CODE, adaptedException.getErrorCode());
    put(Key.SPE_RING, adaptedException.getSpeRing());
    // oii
    put(Key.ERROR_DESCRIPTION, adaptedException.getMessage());
    put(Key.RT_AGE, adaptedException.getRefreshTokenAge());
    put(Key.IS_SUCCESSFUL, Value.FALSE);
    return this;
}
Also used : BaseException(com.microsoft.identity.common.exception.BaseException) UserCancelException(com.microsoft.identity.common.exception.UserCancelException)

Example 13 with BaseException

use of com.microsoft.identity.common.exception.BaseException in project microsoft-authentication-library-common-for-android by AzureAD.

the class BrokerOperationExecutorTests method expectBindFailureException.

private void expectBindFailureException(final List<IIpcStrategy> strategyList) {
    try {
        final BrokerOperationExecutor executor = new BrokerOperationExecutor(strategyList);
        executor.execute(getMockParameter(), getBrokerOperation());
        Assert.fail("Failure is expected.");
    } catch (final BaseException e) {
        Assert.assertTrue(e instanceof ClientException);
        Assert.assertEquals(e.getErrorCode(), ErrorStrings.BROKER_BIND_SERVICE_FAILED);
        Assert.assertEquals(e.getSuppressed().length, strategyList.size());
    }
}
Also used : BrokerOperationExecutor(com.microsoft.identity.common.internal.controllers.BrokerOperationExecutor) BaseException(com.microsoft.identity.common.exception.BaseException) ClientException(com.microsoft.identity.common.exception.ClientException)

Example 14 with BaseException

use of com.microsoft.identity.common.exception.BaseException in project microsoft-authentication-library-common-for-android by AzureAD.

the class HelloCacheTests method testHelloShouldOnlyTriggerOnce.

@Test
public void testHelloShouldOnlyTriggerOnce() {
    final String minimumVer = "1.0";
    final String negotiatedVer = "2.5";
    class MockStrategy implements IIpcStrategy {

        int triggered = 0;

        @Nullable
        @Override
        public Bundle communicateToBroker(@NonNull BrokerOperationBundle bundle) throws BrokerCommunicationException {
            triggered += 1;
            if (triggered == 2) {
                Assert.fail("Should never be triggered");
            }
            final Bundle resultBundle = new Bundle();
            resultBundle.putString(NEGOTIATED_BP_VERSION_KEY, negotiatedVer);
            return resultBundle;
        }

        @Override
        public Type getType() {
            return Type.CONTENT_PROVIDER;
        }
    }
    class MockController extends BrokerMsalController {

        public MockController(Context applicationContext) {
            super(applicationContext);
        }

        @Override
        public HelloCache getHelloCache() {
            return HelloCacheTests.this.getHelloCache(protocolA);
        }

        @Override
        public String getActiveBrokerPackageName() {
            return brokerAppName;
        }
    }
    final MockController controller = new MockController(ApplicationProvider.getApplicationContext());
    final MockStrategy strategy = new MockStrategy();
    final CommandParameters parameters = CommandParameters.builder().requiredBrokerProtocolVersion(minimumVer).build();
    try {
        final String negotiatedProtocolVersion = controller.hello(strategy, parameters.getRequiredBrokerProtocolVersion());
        final String negotiatedProtocolVersion2 = controller.hello(strategy, parameters.getRequiredBrokerProtocolVersion());
        Assert.assertEquals(negotiatedProtocolVersion, negotiatedProtocolVersion2);
    } catch (BaseException e) {
        Assert.fail();
    }
}
Also used : Context(android.content.Context) BaseException(com.microsoft.identity.common.exception.BaseException) BrokerOperationBundle(com.microsoft.identity.common.internal.broker.ipc.BrokerOperationBundle) Bundle(android.os.Bundle) BrokerOperationBundle(com.microsoft.identity.common.internal.broker.ipc.BrokerOperationBundle) NonNull(androidx.annotation.NonNull) IIpcStrategy(com.microsoft.identity.common.internal.broker.ipc.IIpcStrategy) CommandParameters(com.microsoft.identity.common.internal.commands.parameters.CommandParameters) BrokerMsalController(com.microsoft.identity.common.internal.controllers.BrokerMsalController) Test(org.junit.Test)

Example 15 with BaseException

use of com.microsoft.identity.common.exception.BaseException in project microsoft-authentication-library-common-for-android by AzureAD.

the class IpcStrategyTests method testIpcConnectionFailed.

protected void testIpcConnectionFailed(@NonNull final BrokerOperationBundle bundle) {
    final IIpcStrategy strategy = getStrategy();
    try {
        strategy.communicateToBroker(bundle);
        Assert.fail("Operation should fail.");
    } catch (BaseException e) {
        Assert.assertTrue(e instanceof BrokerCommunicationException);
        Assert.assertSame(((BrokerCommunicationException) e).getCategory(), CONNECTION_ERROR);
        Assert.assertSame(((BrokerCommunicationException) e).getStrategyType(), strategy.getType());
    }
}
Also used : BaseException(com.microsoft.identity.common.exception.BaseException) IIpcStrategy(com.microsoft.identity.common.internal.broker.ipc.IIpcStrategy) BrokerCommunicationException(com.microsoft.identity.common.exception.BrokerCommunicationException)

Aggregations

BaseException (com.microsoft.identity.common.exception.BaseException)16 ClientException (com.microsoft.identity.common.exception.ClientException)6 UserCancelException (com.microsoft.identity.common.exception.UserCancelException)5 IIpcStrategy (com.microsoft.identity.common.internal.broker.ipc.IIpcStrategy)5 BrokerOperationExecutor (com.microsoft.identity.common.internal.controllers.BrokerOperationExecutor)5 BrokerCommunicationException (com.microsoft.identity.common.exception.BrokerCommunicationException)4 Bundle (android.os.Bundle)3 NonNull (androidx.annotation.NonNull)3 BrokerOperationBundle (com.microsoft.identity.common.internal.broker.ipc.BrokerOperationBundle)3 ArgumentException (com.microsoft.identity.common.exception.ArgumentException)2 ServiceException (com.microsoft.identity.common.exception.ServiceException)2 UiRequiredException (com.microsoft.identity.common.exception.UiRequiredException)2 AcquireTokenResult (com.microsoft.identity.common.internal.result.AcquireTokenResult)2 Context (android.content.Context)1 Intent (android.content.Intent)1 BaseBundle (android.os.BaseBundle)1 IntuneAppProtectionPolicyRequiredException (com.microsoft.identity.common.exception.IntuneAppProtectionPolicyRequiredException)1 BrokerResultFuture (com.microsoft.identity.common.internal.broker.BrokerResultFuture)1 TokenCommand (com.microsoft.identity.common.internal.commands.TokenCommand)1 CommandParameters (com.microsoft.identity.common.internal.commands.parameters.CommandParameters)1