use of com.microsoft.identity.common.exception.ClientException in project microsoft-authentication-library-common-for-android by AzureAD.
the class MsalBrokerResultAdapter method authenticationResultFromBundle.
@Override
@NonNull
public ILocalAuthenticationResult authenticationResultFromBundle(@NonNull final Bundle resultBundle) throws ClientException {
final BrokerResult brokerResult = brokerResultFromBundle(resultBundle);
Logger.info(TAG, "Broker Result returned from Bundle, constructing authentication result");
final List<ICacheRecord> tenantProfileCacheRecords = brokerResult.getTenantProfileData();
if (tenantProfileCacheRecords == null) {
Logger.error(TAG, "getTenantProfileData is null", null);
throw new ClientException(INVALID_BROKER_BUNDLE, "getTenantProfileData is null.");
}
return new LocalAuthenticationResult(tenantProfileCacheRecords.get(0), tenantProfileCacheRecords, SdkType.MSAL, brokerResult.isServicedFromCache());
}
use of com.microsoft.identity.common.exception.ClientException in project microsoft-authentication-library-common-for-android by AzureAD.
the class MsalBrokerResultAdapter method verifyHelloFromResultBundle.
@NonNull
public String verifyHelloFromResultBundle(@Nullable final Bundle bundle) throws ClientException {
final String methodName = ":verifyHelloFromResultBundle";
// This means that the Broker doesn't support hello().
if (bundle == null) {
Logger.warn(TAG + methodName, "The hello result bundle is null.");
throw new ClientException(ErrorStrings.UNSUPPORTED_BROKER_VERSION_ERROR_CODE, ErrorStrings.UNSUPPORTED_BROKER_VERSION_ERROR_MESSAGE);
}
final String negotiatedBrokerProtocolVersion = bundle.getString(AuthenticationConstants.Broker.NEGOTIATED_BP_VERSION_KEY);
if (!StringUtil.isEmpty(negotiatedBrokerProtocolVersion)) {
Logger.info(TAG + methodName, "Able to establish the connect, " + "the broker protocol version in common is [" + negotiatedBrokerProtocolVersion + "]");
return negotiatedBrokerProtocolVersion;
}
if (!StringUtil.isEmpty(bundle.getString(AuthenticationConstants.OAuth2.ERROR)) && !StringUtil.isEmpty(bundle.getString(AuthenticationConstants.OAuth2.ERROR_DESCRIPTION))) {
final String errorCode = bundle.getString(AuthenticationConstants.OAuth2.ERROR);
final String errorMessage = bundle.getString(AuthenticationConstants.OAuth2.ERROR_DESCRIPTION);
throw new ClientException(errorCode, errorMessage);
}
final Object resultObject = bundle.get(AuthenticationConstants.Broker.BROKER_RESULT_V2);
if (resultObject instanceof BrokerResult) {
// for the back compatibility purpose to version 3.0.4 and 3.0.6.
final BrokerResult brokerResult = (BrokerResult) resultObject;
throw new ClientException(brokerResult.getErrorCode(), brokerResult.getErrorMessage());
}
// This means that the Broker doesn't support hello().
Logger.warn(TAG + methodName, "The result bundle is not in a recognizable format.");
throw new ClientException(ErrorStrings.UNSUPPORTED_BROKER_VERSION_ERROR_CODE, ErrorStrings.UNSUPPORTED_BROKER_VERSION_ERROR_MESSAGE);
}
use of com.microsoft.identity.common.exception.ClientException in project microsoft-authentication-library-common-for-android by AzureAD.
the class MsalBrokerResultAdapter method getAccountsFromResultBundle.
@NonNull
public List<ICacheRecord> getAccountsFromResultBundle(@NonNull final Bundle bundle) throws BaseException {
String accountJson;
final byte[] compressedData = bundle.getByteArray(BROKER_ACCOUNTS_COMPRESSED);
if (compressedData != null) {
try {
accountJson = GzipUtil.decompressBytesToString(compressedData);
} catch (IOException e) {
Logger.error(TAG, " Failed to decompress account list to bytes", e);
throw new ClientException(INVALID_BROKER_BUNDLE, " Failed to decompress account list to bytes.");
}
} else {
accountJson = bundle.getString(BROKER_ACCOUNTS);
}
if (StringUtil.isEmpty(accountJson)) {
throw new MsalBrokerResultAdapter().getBaseExceptionFromBundle(bundle);
}
return JsonExtensions.getICacheRecordListFromJsonString(accountJson);
}
use of com.microsoft.identity.common.exception.ClientException in project microsoft-authentication-library-common-for-android by AzureAD.
the class MsalBrokerResultAdapter method getIntentForInteractiveRequestFromResultBundle.
@NonNull
public Intent getIntentForInteractiveRequestFromResultBundle(@NonNull final Bundle resultBundle, @NonNull final String negotiatedBrokerProtocolVersion) throws ClientException {
final Bundle interactiveRequestBundle = extractInteractiveRequestBundleFromResultBundle(resultBundle);
final String packageName = interactiveRequestBundle.getString(BROKER_PACKAGE_NAME);
final String className = interactiveRequestBundle.getString(BROKER_ACTIVITY_NAME);
if (StringUtil.isEmpty(packageName) || StringUtil.isEmpty(className)) {
throw new ClientException(INVALID_BROKER_BUNDLE, "Content of Authorization Intent's package and class name should not be null.");
}
final Intent intent = new Intent();
intent.setPackage(packageName);
intent.setClassName(packageName, className);
intent.putExtras(interactiveRequestBundle);
intent.putExtra(NEGOTIATED_BP_VERSION_KEY, negotiatedBrokerProtocolVersion);
return intent;
}
use of com.microsoft.identity.common.exception.ClientException in project microsoft-authentication-library-common-for-android by AzureAD.
the class JWSBuilder method sign.
/**
* Signs the input with the private key.
*
* @param privateKey the key to sign input with
* @param input the data that needs to be signed
* @return String signed string
*/
private static String sign(RSAPrivateKey privateKey, final byte[] input) throws ClientException {
final Signature signer;
try {
signer = Signature.getInstance(JWS_ALGORITHM);
signer.initSign(privateKey);
signer.update(input);
return StringExtensions.encodeBase64URLSafeString(signer.sign());
} catch (InvalidKeyException e) {
throw new ClientException(ErrorStrings.KEY_CHAIN_PRIVATE_KEY_EXCEPTION, "Invalid private RSA key: " + e.getMessage(), e);
} catch (SignatureException e) {
throw new ClientException(ErrorStrings.SIGNATURE_EXCEPTION, "RSA signature exception: " + e.getMessage(), e);
} catch (UnsupportedEncodingException e) {
throw new ClientException(ErrorStrings.UNSUPPORTED_ENCODING, "Unsupported encoding", e);
} catch (NoSuchAlgorithmException e) {
throw new ClientException(ErrorStrings.NO_SUCH_ALGORITHM, "Unsupported RSA algorithm: " + e.getMessage(), e);
}
}
Aggregations