Search in sources :

Example 1 with ArgumentException

use of com.microsoft.identity.common.exception.ArgumentException 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;
}
Also used : BaseException(com.microsoft.identity.common.exception.BaseException) UiRequiredException(com.microsoft.identity.common.exception.UiRequiredException) UserCancelException(com.microsoft.identity.common.exception.UserCancelException) GzipUtil.compressString(com.microsoft.identity.common.internal.util.GzipUtil.compressString) ArgumentException(com.microsoft.identity.common.exception.ArgumentException) ClientException(com.microsoft.identity.common.exception.ClientException) NonNull(androidx.annotation.NonNull)

Example 2 with ArgumentException

use of com.microsoft.identity.common.exception.ArgumentException 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;
}
Also used : BaseException(com.microsoft.identity.common.exception.BaseException) UiRequiredException(com.microsoft.identity.common.exception.UiRequiredException) UserCancelException(com.microsoft.identity.common.exception.UserCancelException) ClientException(com.microsoft.identity.common.exception.ClientException) ArgumentException(com.microsoft.identity.common.exception.ArgumentException) NonNull(androidx.annotation.NonNull)

Aggregations

NonNull (androidx.annotation.NonNull)2 ArgumentException (com.microsoft.identity.common.exception.ArgumentException)2 BaseException (com.microsoft.identity.common.exception.BaseException)2 ClientException (com.microsoft.identity.common.exception.ClientException)2 UiRequiredException (com.microsoft.identity.common.exception.UiRequiredException)2 UserCancelException (com.microsoft.identity.common.exception.UserCancelException)2 GzipUtil.compressString (com.microsoft.identity.common.internal.util.GzipUtil.compressString)1