com.microsoft.azure.keyvault.authentication.ChallengeCache Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of azure-keyvault Show documentation
Show all versions of azure-keyvault Show documentation
This library has been replaced by new Azure SDKs, you can read about them at https://aka.ms/azsdkvalueprop. The latest libraries to interact with the Azure Key Vault service are:
(1) https://search.maven.org/artifact/com.azure/azure-security-keyvault-keys.
(2) https://search.maven.org/artifact/com.azure/azure-security-keyvault-secrets.
(3) https://search.maven.org/artifact/com.azure/azure-security-keyvault-certificates.
It is recommended that you move to the new package.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
package com.microsoft.azure.keyvault.authentication;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import okhttp3.HttpUrl;
/**
* Handles caching of the challenge.
*/
class ChallengeCache {
private final HashMap> cachedChallenges = new HashMap>();
/**
* Uses authority to retrieve the cached values.
*
* @param url
* the url that is used as a cache key.
* @return cached value or null if value is not available.
*/
public Map getCachedChallenge(HttpUrl url) {
if (url == null) {
return null;
}
String authority = getAuthority(url);
authority = authority.toLowerCase(Locale.ENGLISH);
return cachedChallenges.get(authority);
}
/**
* Uses authority to cache challenge.
*
* @param url
* the url that is used as a cache key.
* @param challenge
* the challenge to cache.
*/
public void addCachedChallenge(HttpUrl url, Map challenge) {
if (url == null || challenge == null) {
return;
}
String authority = getAuthority(url);
authority = authority.toLowerCase(Locale.ENGLISH);
cachedChallenges.put(authority, challenge);
}
/**
* Gets authority of a url.
*
* @param url
* the url to get the authority for.
* @return the authority.
*/
public String getAuthority(HttpUrl url) {
String scheme = url.scheme();
String host = url.host();
int port = url.port();
StringBuilder builder = new StringBuilder();
if (scheme != null) {
builder.append(scheme).append("://");
}
builder.append(host);
if (port >= 0) {
builder.append(':').append(port);
}
return builder.toString();
}
}