Search in sources :

Example 16 with ClientException

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;
}
Also used : HashMap(java.util.HashMap) ClientException(com.microsoft.identity.common.exception.ClientException)

Example 17 with ClientException

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;
}
Also used : Intent(android.content.Intent) ClientException(com.microsoft.identity.common.exception.ClientException)

Example 18 with ClientException

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);
    }
}
Also used : BrokerOperationExecutor(com.microsoft.identity.common.internal.controllers.BrokerOperationExecutor) BaseException(com.microsoft.identity.common.exception.BaseException) ClientException(com.microsoft.identity.common.exception.ClientException)

Example 19 with ClientException

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;
}
Also used : IDeviceCertificate(com.microsoft.identity.common.adal.internal.IDeviceCertificate) ClientException(com.microsoft.identity.common.exception.ClientException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 20 with ClientException

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));
    }
}
Also used : ArrayList(java.util.ArrayList) BrowserDescriptor(com.microsoft.identity.common.internal.ui.browser.BrowserDescriptor) ClientException(com.microsoft.identity.common.exception.ClientException) Test(org.junit.Test)

Aggregations

ClientException (com.microsoft.identity.common.exception.ClientException)74 IOException (java.io.IOException)23 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)23 InvalidKeyException (java.security.InvalidKeyException)18 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)17 KeyStoreException (java.security.KeyStoreException)17 BadPaddingException (javax.crypto.BadPaddingException)17 IllegalBlockSizeException (javax.crypto.IllegalBlockSizeException)17 NoSuchPaddingException (javax.crypto.NoSuchPaddingException)17 UnrecoverableEntryException (java.security.UnrecoverableEntryException)15 CertificateException (java.security.cert.CertificateException)13 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)12 SignatureException (java.security.SignatureException)11 KeyPermanentlyInvalidatedException (android.security.keystore.KeyPermanentlyInvalidatedException)10 StrongBoxUnavailableException (android.security.keystore.StrongBoxUnavailableException)10 NonNull (androidx.annotation.NonNull)10 JOSEException (com.nimbusds.jose.JOSEException)10 NoSuchProviderException (java.security.NoSuchProviderException)10 ProviderException (java.security.ProviderException)10 JSONException (org.json.JSONException)10