use of com.microsoft.identity.common.exception.ClientException in project microsoft-authentication-library-common-for-android by AzureAD.
the class PKeyAuthChallengeFactory method getPKeyAuthHeader.
private Map<String, String> getPKeyAuthHeader(final String headerStr) throws ClientException, UnsupportedEncodingException {
final String authenticateHeader = headerStr.substring(CHALLENGE_RESPONSE_TYPE.length());
final ArrayList<String> queryPairs = StringExtensions.splitWithQuotes(authenticateHeader, ',');
Map<String, String> headerItems = new HashMap<>();
for (String queryPair : queryPairs) {
ArrayList<String> pair = StringExtensions.splitWithQuotes(queryPair, '=');
if (pair.size() == 2 && !StringExtensions.isNullOrBlank(pair.get(0)) && !StringExtensions.isNullOrBlank(pair.get(1))) {
String key = pair.get(0);
String value = pair.get(1);
key = StringExtensions.urlFormDecode(key);
value = StringExtensions.urlFormDecode(value);
key = key.trim();
value = StringExtensions.removeQuoteInHeaderValue(value.trim());
headerItems.put(key, value);
} else if (pair.size() == 1 && !StringExtensions.isNullOrBlank(pair.get(0))) {
// The value list could be null when either no certificate or no permission
// for ADFS service account for the Device container in AD.
headerItems.put(StringExtensions.urlFormDecode(pair.get(0)).trim(), StringExtensions.urlFormDecode(""));
} else {
// invalid format
throw new ClientException(DEVICE_CERTIFICATE_REQUEST_INVALID, authenticateHeader);
}
}
return headerItems;
}
use of com.microsoft.identity.common.exception.ClientException in project microsoft-authentication-library-common-for-android by AzureAD.
the class PKeyAuthChallengeHandler method processChallenge.
@Override
public Void processChallenge(final PKeyAuthChallenge pKeyAuthChallenge) {
mWebView.stopLoading();
mChallengeCallback.setPKeyAuthStatus(true);
try {
// Get no device cert response
final Map<String, String> header = getChallengeHeader(pKeyAuthChallenge);
mWebView.post(new Runnable() {
@Override
public void run() {
String loadUrl = pKeyAuthChallenge.getSubmitUrl();
Logger.info(TAG, "Respond to pkeyAuth challenge");
Logger.infoPII(TAG, "Challenge submit url:" + pKeyAuthChallenge.getSubmitUrl());
mWebView.loadUrl(loadUrl, header);
}
});
} catch (final ClientException e) {
// It should return error code and finish the
// activity, so that onActivityResult implementation
// returns errors to callback.
Intent resultIntent = new Intent();
resultIntent.putExtra(AuthenticationConstants.Browser.RESPONSE_AUTHENTICATION_EXCEPTION, e);
// TODO log the request info
mChallengeCallback.onChallengeResponseReceived(AuthenticationConstants.UIResponse.BROWSER_CODE_AUTHENTICATION_EXCEPTION, resultIntent);
}
return null;
}
use of com.microsoft.identity.common.exception.ClientException in project microsoft-authentication-library-common-for-android by AzureAD.
the class BrokerOperationExecutorTests method expectCorruptedBundleException.
private void expectCorruptedBundleException(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(), CORRUPTED_BUNDLE_ERROR_CODE);
}
}
use of com.microsoft.identity.common.exception.ClientException in project microsoft-authentication-library-common-for-android by AzureAD.
the class PKeyAuthChallengeHandler method getWPJAPIInstance.
private static IDeviceCertificate getWPJAPIInstance(Class<IDeviceCertificate> certClazz) throws ClientException {
final IDeviceCertificate deviceCertProxy;
final Constructor<?> constructor;
try {
constructor = certClazz.getDeclaredConstructor();
deviceCertProxy = (IDeviceCertificate) constructor.newInstance((Object[]) null);
} catch (NoSuchMethodException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
throw new ClientException(ErrorStrings.DEVICE_CERTIFICATE_API_EXCEPTION, "WPJ Api constructor is not defined", e);
}
return deviceCertProxy;
}
use of com.microsoft.identity.common.exception.ClientException in project microsoft-authentication-library-common-for-android by AzureAD.
the class BrowserSelectorTest method testSelect_versionNotSupportedBrowser.
@Test
public void testSelect_versionNotSupportedBrowser() throws NameNotFoundException {
setBrowserList(CHROME, FIREFOX);
when(mContext.getPackageManager().resolveActivity(BROWSER_INTENT, 0)).thenReturn(CHROME.mResolveInfo);
List<BrowserDescriptor> browserSafelist = new ArrayList<>();
browserSafelist.add(new BrowserDescriptor("com.android.chrome", "ChromeSignature", "51", null));
try {
BrowserSelector.select(mContext, browserSafelist);
} catch (final ClientException exception) {
assertNotNull(exception);
assert (exception.getErrorCode().equalsIgnoreCase(ErrorStrings.NO_AVAILABLE_BROWSER_FOUND));
}
}
Aggregations