2006-01-19 00:34:21 +01:00
|
|
|
/***********************************************************************
|
|
|
|
*
|
2006-01-31 23:01:47 +01:00
|
|
|
* Copyright (C) 2005-2006 Novell, Inc. Inc. All Rights Reserved.
|
2006-01-19 00:34:21 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; version 2.1
|
|
|
|
* of the License.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
2006-01-31 23:01:47 +01:00
|
|
|
* Library Lesser General Public License for more details.
|
2006-01-19 00:34:21 +01:00
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2006-01-31 23:01:47 +01:00
|
|
|
* License along with this library; if not, Novell, Inc.
|
2006-01-19 00:34:21 +01:00
|
|
|
*
|
|
|
|
* To contact Novell about this file by physical or electronic mail,
|
|
|
|
* you may find current contact information at www.novell.com.
|
|
|
|
*
|
|
|
|
***********************************************************************/
|
|
|
|
|
2006-01-31 23:01:47 +01:00
|
|
|
|
2005-10-11 21:51:00 +02:00
|
|
|
using System;
|
|
|
|
using System.Collections;
|
|
|
|
using System.Threading;
|
|
|
|
using sscs.common;
|
|
|
|
|
|
|
|
namespace sscs.cache
|
|
|
|
{
|
|
|
|
|
|
|
|
class KeyChain : IKeychain
|
|
|
|
{
|
|
|
|
//We can have a Arraylist in case we dont need to look up via SecretID
|
|
|
|
// Hashtable has [SecretID(string), Secret(class)]
|
|
|
|
private Hashtable tSecretList = new Hashtable();
|
|
|
|
private Hashtable SecretList; // = Hashtable.Synchronized(tSecretList);
|
|
|
|
|
|
|
|
private string keyChainId;
|
|
|
|
|
|
|
|
private DateTime createdTime;
|
|
|
|
internal DateTime CreatedTime
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return createdTime;
|
|
|
|
}
|
|
|
|
set
|
|
|
|
{
|
|
|
|
createdTime = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private DateTime accessedTime;
|
|
|
|
internal DateTime AccessedTime
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return accessedTime;
|
|
|
|
}
|
|
|
|
set
|
|
|
|
{
|
|
|
|
accessedTime = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private DateTime modifiedTime;
|
|
|
|
internal DateTime ModifiedTime
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return modifiedTime;
|
|
|
|
}
|
|
|
|
set
|
|
|
|
{
|
|
|
|
modifiedTime = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
internal KeyChain()
|
|
|
|
{
|
|
|
|
SecretList = Hashtable.Synchronized(tSecretList);
|
|
|
|
}
|
|
|
|
|
|
|
|
internal KeyChain(string keyChainId)
|
|
|
|
{
|
|
|
|
SecretList = Hashtable.Synchronized(tSecretList);
|
|
|
|
this.keyChainId = keyChainId;
|
|
|
|
}
|
|
|
|
~KeyChain()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SetKey(string value)
|
|
|
|
{
|
|
|
|
keyChainId = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void AddSecret(Secret mySecret)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
mySecret.CreatedTime = DateTime.Now;
|
|
|
|
SecretList.Add((mySecret.GetKey()), mySecret);
|
|
|
|
this.ModifiedTime = DateTime.Now;
|
|
|
|
}
|
|
|
|
catch(Exception e)
|
|
|
|
{
|
|
|
|
CSSSLogger.ExpLog(e.ToString());
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void RemoveSecret(String secretID)
|
|
|
|
{
|
2005-11-24 00:27:29 +01:00
|
|
|
// remove all keyvalues first, as to unlink reverse links
|
|
|
|
try
|
|
|
|
{
|
|
|
|
Secret secret = GetSecret(secretID);
|
|
|
|
secret.RemoveAllKeyValuePairs(this);
|
|
|
|
}
|
|
|
|
catch
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2005-10-11 21:51:00 +02:00
|
|
|
SecretList.Remove(secretID);
|
|
|
|
this.ModifiedTime = DateTime.Now;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void RemoveAllSecrets()
|
|
|
|
{
|
|
|
|
SecretList.Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
public Secret GetSecret(string secretID)
|
|
|
|
{
|
|
|
|
if(SecretList.ContainsKey(secretID))
|
|
|
|
{
|
|
|
|
Secret secret = (Secret)SecretList[secretID];
|
|
|
|
secret.AccessedTime = DateTime.Now;
|
|
|
|
return secret;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
throw new SecretNotFoundException(secretID);
|
|
|
|
}
|
|
|
|
|
|
|
|
internal string GetKey()
|
|
|
|
{
|
|
|
|
return keyChainId;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
internal IEnumerator GetAllSecrets()
|
|
|
|
{
|
|
|
|
return SecretList.GetEnumerator();
|
|
|
|
}
|
|
|
|
internal int GetNumSecrets()
|
|
|
|
{
|
|
|
|
return SecretList.Count;
|
|
|
|
}
|
|
|
|
|
|
|
|
internal bool CheckIfSecretExists(string id)
|
|
|
|
{
|
|
|
|
if( SecretList.ContainsKey(id) )
|
|
|
|
return true;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|