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;
}
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;
}
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());
}
}
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();
}
}
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());
}
}
Aggregations