Search in sources :

Example 6 with CredentialType

use of com.microsoft.identity.common.internal.dto.CredentialType in project microsoft-authentication-library-common-for-android by AzureAD.

the class SharedPreferencesAccountCredentialCache method credentialClassForType.

private Class<? extends Credential> credentialClassForType(@NonNull final String cacheKey) {
    Logger.verbose(TAG, "Resolving class for key/CredentialType...");
    Logger.verbosePII(TAG, "Supplied key: [" + cacheKey + "]");
    final CredentialType targetType = getCredentialTypeForCredentialCacheKey(cacheKey);
    Logger.verbose(TAG, "CredentialType matched: [" + targetType + "]");
    return getTargetClassForCredentialType(cacheKey, targetType);
}
Also used : CredentialType(com.microsoft.identity.common.internal.dto.CredentialType)

Example 7 with CredentialType

use of com.microsoft.identity.common.internal.dto.CredentialType in project microsoft-authentication-library-common-for-android by AzureAD.

the class SharedPreferencesAccountCredentialCache method getCredentialTypeForCredentialCacheKey.

/**
 * Inspects the supplied cache key to determine the target CredentialType.
 *
 * @param cacheKey The cache key to inspect.
 * @return The CredentialType or null if a proper type cannot be resolved.
 */
@Nullable
public static CredentialType getCredentialTypeForCredentialCacheKey(@NonNull final String cacheKey) {
    if (StringExtensions.isNullOrBlank(cacheKey)) {
        throw new IllegalArgumentException("Param [cacheKey] cannot be null.");
    }
    Logger.verbosePII(TAG, "Evaluating cache key for CredentialType [" + cacheKey + "]");
    final Set<String> credentialTypesLowerCase = new HashSet<>();
    for (final String credentialTypeStr : CredentialType.valueSet()) {
        credentialTypesLowerCase.add(credentialTypeStr.toLowerCase(Locale.US));
    }
    CredentialType type = null;
    for (final String credentialTypeStr : credentialTypesLowerCase) {
        if (cacheKey.contains(CACHE_VALUE_SEPARATOR + credentialTypeStr + CACHE_VALUE_SEPARATOR)) {
            Logger.verbose(TAG, "Cache key is a Credential type...");
            if (CredentialType.AccessToken.name().equalsIgnoreCase(credentialTypeStr)) {
                type = CredentialType.AccessToken;
                break;
            } else if (CredentialType.AccessToken_With_AuthScheme.name().equalsIgnoreCase(credentialTypeStr)) {
                type = CredentialType.AccessToken_With_AuthScheme;
                break;
            } else if (CredentialType.RefreshToken.name().equalsIgnoreCase(credentialTypeStr)) {
                type = CredentialType.RefreshToken;
                break;
            } else if (CredentialType.IdToken.name().equalsIgnoreCase(credentialTypeStr)) {
                type = CredentialType.IdToken;
                break;
            } else if (CredentialType.V1IdToken.name().equalsIgnoreCase(credentialTypeStr)) {
                type = CredentialType.V1IdToken;
                break;
            } else if (CredentialType.PrimaryRefreshToken.name().equalsIgnoreCase(credentialTypeStr)) {
                type = CredentialType.PrimaryRefreshToken;
                break;
            } else {
                // TODO Log a warning and skip this value?
                Logger.warn(TAG, "Unexpected credential type.");
            }
        }
    }
    Logger.verbose(TAG, "Cache key was type: [" + type + "]");
    return type;
}
Also used : CredentialType(com.microsoft.identity.common.internal.dto.CredentialType) HashSet(java.util.HashSet) Nullable(androidx.annotation.Nullable)

Aggregations

CredentialType (com.microsoft.identity.common.internal.dto.CredentialType)7 Credential (com.microsoft.identity.common.internal.dto.Credential)3 ArrayList (java.util.ArrayList)3 Nullable (androidx.annotation.Nullable)2 AccountRecord (com.microsoft.identity.common.internal.dto.AccountRecord)2 HashSet (java.util.HashSet)2 AccessTokenRecord (com.microsoft.identity.common.internal.dto.AccessTokenRecord)1 RefreshTokenRecord (com.microsoft.identity.common.internal.dto.RefreshTokenRecord)1