Updated to only add non-success authtoken entries to the

cache if the time necessary to process them exceeds 30
seconds. With this change we make sure that non-successful
entries are added to the cache to deal with server
un-available issues.
This commit is contained in:
Juan Carlos Luciani 2007-06-12 16:51:18 +00:00
parent e9551385d0
commit ad7a069507

View File

@ -29,7 +29,9 @@
//===[ Type definitions ]==================================================
#define DEFAULT_RETRY_LIFETIME 300 // seconds
#define DEFAULT_RETRY_LIFETIME 300 // seconds
#define BAD_CACHE_TRIGER_TIME 30 // seconds
#define DEFAULT_ATS_PORT 2645
@ -661,8 +663,8 @@ ObtainAuthTokenInt(
bool setupHostEntries = true;
char *pHostNameAnd443 = NULL;
char *pHostNameAnd2645 = NULL;
ATSHostEntry serviceHostEntry443 = {NULL, NULL, NULL, NULL, 0};
ATSHostEntry serviceHostEntry2645 = {NULL, NULL, NULL, NULL, 0};
ATSHostEntry serviceHostEntry443 = {{NULL, NULL}, NULL, NULL, 0};
ATSHostEntry serviceHostEntry2645 = {{NULL, NULL}, NULL, NULL, 0};
LIST_ENTRY *pListEntry;
ATSHostEntry *pHostEntryInUse;
@ -734,6 +736,7 @@ ObtainAuthTokenInt(
// Initialize to retry in case of failure
int cacheEntryLifetime = DEFAULT_RETRY_LIFETIME;
bool advisedToRetry;
DWORD opStartTime = GetTickCount();
// Cache entry created, now try to obtain auth token from the CASA Server
pToken = NULL;
@ -760,23 +763,31 @@ ObtainAuthTokenInt(
&advisedToRetry);
}
// Add the entry to the cache if we did not fail due to authentication
// failure.
// Try to add the entry to the cache if we did not fail due
// to authentication failure.
if (CasaStatusCode(retStatus) != CASA_STATUS_AUTHENTICATION_FAILURE)
{
pCacheEntry = CreateAuthTokenCacheEntry(pServiceName,
pNormalizedHostName,
pHostEntryInUse,
retStatus,
pToken,
cacheEntryLifetime,
pCredStoreScope);
if (pCacheEntry)
DWORD opEndTime = GetTickCount();
// We only want to cache bad results if the operation took a
// considerable amount of time.
if (CASA_SUCCESS(retStatus)
|| opEndTime >= (opStartTime + (BAD_CACHE_TRIGER_TIME * 1000)))
{
// Release the cache entry if the resulting status is not successful
if (!CASA_SUCCESS(retStatus))
pCacheEntry = CreateAuthTokenCacheEntry(pServiceName,
pNormalizedHostName,
pHostEntryInUse,
retStatus,
pToken,
cacheEntryLifetime,
pCredStoreScope);
if (pCacheEntry)
{
FreeAuthCacheEntry(pCacheEntry);
// Release the cache entry if the resulting status is not successful
if (!CASA_SUCCESS(retStatus))
{
FreeAuthCacheEntry(pCacheEntry);
}
}
}
}