use of com.microsoft.identity.common.exception.UserCancelException in project microsoft-authentication-library-common-for-android by AzureAD.
the class BrokerOperationExecutorTests method expectUserCancelledException.
private void expectUserCancelledException(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 UserCancelException);
}
}
use of com.microsoft.identity.common.exception.UserCancelException in project microsoft-authentication-library-common-for-android by AzureAD.
the class ExceptionAdapter method exceptionFromAcquireTokenResult.
@Nullable
public static BaseException exceptionFromAcquireTokenResult(final AcquireTokenResult result, final CommandParameters commandParameters) {
final String methodName = ":exceptionFromAcquireTokenResult";
@SuppressWarnings(WarningType.rawtype_warning) final AuthorizationResult authorizationResult = result.getAuthorizationResult();
if (null != authorizationResult) {
final AuthorizationErrorResponse authorizationErrorResponse = authorizationResult.getAuthorizationErrorResponse();
if (!authorizationResult.getSuccess()) {
// THERE ARE CURRENTLY NO USAGES of INVALID_REQUEST
switch(result.getAuthorizationResult().getAuthorizationStatus()) {
case FAIL:
// Check if the error is to register device and throw DEVICE_REGISTRATION_NEEDED exception
if (authorizationErrorResponse instanceof MicrosoftAuthorizationErrorResponse) {
MicrosoftAuthorizationErrorResponse microsoftAuthorizationErrorResponse = (MicrosoftAuthorizationErrorResponse) authorizationErrorResponse;
if (microsoftAuthorizationErrorResponse.getError().equals(MicrosoftAuthorizationErrorResponse.DEVICE_REGISTRATION_NEEDED)) {
return new DeviceRegistrationRequiredException(microsoftAuthorizationErrorResponse.getError(), microsoftAuthorizationErrorResponse.getErrorDescription(), microsoftAuthorizationErrorResponse.getUserName());
}
}
return new ServiceException(authorizationErrorResponse.getError(), authorizationErrorResponse.getErrorDescription(), ServiceException.DEFAULT_STATUS_CODE, null);
case SDK_CANCEL:
return new ClientException(authorizationErrorResponse.getError(), authorizationErrorResponse.getErrorDescription());
case USER_CANCEL:
return new UserCancelException();
}
}
} else {
Logger.warn(TAG + methodName, "AuthorizationResult was null -- expected for ATS cases.");
}
return exceptionFromTokenResult(result.getTokenResult(), commandParameters);
}
use of com.microsoft.identity.common.exception.UserCancelException in project microsoft-authentication-library-common-for-android by AzureAD.
the class MsalBrokerResultAdapter method getBaseExceptionFromErrorCodes.
/**
* Method to get the right base exception based on error codes.
* Note : In newer versions of Broker, exception type will be sent and is used to determine the right exception.
* <p>
* This method is to support legacy broker versions (3.1.8 or below)
*
* @return {@link BaseException}
*/
@NonNull
private BaseException getBaseExceptionFromErrorCodes(@NonNull final BrokerResult brokerResult) {
final String errorCode = brokerResult.getErrorCode();
final BaseException baseException;
// INTERACTION_REQUIRED is marked as deprecated
if (AuthenticationConstants.OAuth2ErrorCode.INTERACTION_REQUIRED.equalsIgnoreCase(errorCode) || AuthenticationConstants.OAuth2ErrorCode.INVALID_GRANT.equalsIgnoreCase(errorCode) || ErrorStrings.INVALID_BROKER_REFRESH_TOKEN.equalsIgnoreCase(errorCode) || ErrorStrings.NO_TOKENS_FOUND.equalsIgnoreCase(errorCode)) {
Logger.warn(TAG, "Received a UIRequired exception from Broker : " + errorCode);
baseException = new UiRequiredException(errorCode, brokerResult.getErrorMessage());
} else if (AuthenticationConstants.OAuth2ErrorCode.UNAUTHORIZED_CLIENT.equalsIgnoreCase(errorCode) && AuthenticationConstants.OAuth2SubErrorCode.PROTECTION_POLICY_REQUIRED.equalsIgnoreCase(brokerResult.getSubErrorCode())) {
Logger.warn(TAG, "Received a IntuneAppProtectionPolicyRequiredException exception from Broker : " + errorCode);
baseException = getIntuneProtectionRequiredException(brokerResult);
} else if (ErrorStrings.USER_CANCELLED.equalsIgnoreCase(errorCode)) {
Logger.warn(TAG, "Received a User cancelled exception from Broker : " + errorCode);
baseException = new UserCancelException();
} else if (ArgumentException.ILLEGAL_ARGUMENT_ERROR_CODE.equalsIgnoreCase(errorCode)) {
Logger.warn(TAG, "Received a Argument exception from Broker : " + errorCode);
baseException = new ArgumentException(ArgumentException.BROKER_TOKEN_REQUEST_OPERATION_NAME, errorCode, brokerResult.getErrorMessage());
} else if (!StringUtil.isEmpty(brokerResult.getHttpResponseHeaders()) || !StringUtil.isEmpty(brokerResult.getHttpResponseBody())) {
Logger.warn(TAG, "Received a Service exception from Broker : " + errorCode);
baseException = getServiceException(brokerResult);
} else {
Logger.warn(TAG, "Received a Client exception from Broker : " + errorCode);
baseException = new ClientException(brokerResult.getErrorCode(), brokerResult.getErrorMessage());
}
baseException.setCliTelemErrorCode(brokerResult.getCliTelemErrorCode());
baseException.setCliTelemSubErrorCode(brokerResult.getCliTelemSubErrorCode());
baseException.setCorrelationId(brokerResult.getCorrelationId());
baseException.setSpeRing(brokerResult.getSpeRing());
baseException.setRefreshTokenAge(brokerResult.getRefreshTokenAge());
return baseException;
}
use of com.microsoft.identity.common.exception.UserCancelException in project microsoft-authentication-library-common-for-android by AzureAD.
the class MsalBrokerResultAdapter method getBaseExceptionFromExceptionType.
@NonNull
private BaseException getBaseExceptionFromExceptionType(@NonNull final String exceptionType, @NonNull final BrokerResult brokerResult) {
BaseException baseException;
Logger.warn(TAG, "Received a " + exceptionType + " from Broker : " + brokerResult.getErrorCode());
if (exceptionType.equalsIgnoreCase(UiRequiredException.sName)) {
baseException = new UiRequiredException(brokerResult.getErrorCode(), brokerResult.getErrorMessage());
} else if (exceptionType.equalsIgnoreCase(ServiceException.sName)) {
baseException = getServiceException(brokerResult);
} else if (exceptionType.equalsIgnoreCase(IntuneAppProtectionPolicyRequiredException.sName)) {
baseException = getIntuneProtectionRequiredException(brokerResult);
} else if (exceptionType.equalsIgnoreCase(UserCancelException.sName)) {
baseException = new UserCancelException();
} else if (exceptionType.equalsIgnoreCase(ClientException.sName)) {
baseException = new ClientException(brokerResult.getErrorCode(), brokerResult.getErrorMessage());
} else if (exceptionType.equalsIgnoreCase(ArgumentException.sName)) {
baseException = new ArgumentException(ArgumentException.BROKER_TOKEN_REQUEST_OPERATION_NAME, brokerResult.getErrorCode(), brokerResult.getErrorMessage());
} else {
// Default to ClientException if null
Logger.warn(TAG, " Exception type is unknown : " + exceptionType + brokerResult.getErrorCode() + ", defaulting to Client Exception ");
baseException = new ClientException(brokerResult.getErrorCode(), brokerResult.getErrorMessage());
}
baseException.setCliTelemErrorCode(brokerResult.getCliTelemErrorCode());
baseException.setCliTelemSubErrorCode(brokerResult.getCliTelemSubErrorCode());
baseException.setCorrelationId(brokerResult.getCorrelationId());
baseException.setSpeRing(brokerResult.getSpeRing());
baseException.setRefreshTokenAge(brokerResult.getRefreshTokenAge());
return baseException;
}
use of com.microsoft.identity.common.exception.UserCancelException in project microsoft-authentication-library-common-for-android by AzureAD.
the class CommandDispatcher method executeCommand.
/**
* We need to inspect the AcquireTokenResult type to determine whether the request was successful, cancelled or encountered an exception
* <p>
* Execute the command provided to the command dispatcher
*
* @param command
* @return
*/
private static CommandResult executeCommand(@SuppressWarnings(WarningType.rawtype_warning) BaseCommand command) {
Object result = null;
BaseException baseException = null;
CommandResult commandResult;
try {
// Try executing request
result = command.execute();
} catch (final Exception e) {
if (e instanceof BaseException) {
baseException = (BaseException) e;
} else {
baseException = ExceptionAdapter.baseExceptionFromException(e);
}
}
if (baseException != null) {
if (baseException instanceof UserCancelException) {
commandResult = new CommandResult(CommandResult.ResultStatus.CANCEL, null, command.getParameters().getCorrelationId());
} else {
// Post On Error
commandResult = new CommandResult(CommandResult.ResultStatus.ERROR, baseException, command.getParameters().getCorrelationId());
}
} else /* baseException == null */
{
if (result != null && result instanceof AcquireTokenResult) {
// Handler handler, final BaseCommand command, BaseException baseException, AcquireTokenResult result
commandResult = getCommandResultFromTokenResult(baseException, (AcquireTokenResult) result, command.getParameters());
} else {
// For commands that don't return an AcquireTokenResult
commandResult = new CommandResult(CommandResult.ResultStatus.COMPLETED, result, command.getParameters().getCorrelationId());
}
}
return commandResult;
}
Aggregations