C# Class GSF.Security.UserDataCache

Represents a secured inter-process cache for a Dictionary{TKey,TValue} of serialized UserData.
This is a personal user data cache that only contains basic LDAP information for the user. It is used to load the local and Active Directory groups a user is associated with when the user no longer has access to its domain server. This can happen when a laptop that is normally connected to the Active Directory domain gets shutdown then restarted without access to the domain, for example, on an airplane - in this mode the user can successfully still login to the laptop to their using domain account cached by Windows but the groups the user is in will no longer be accessible. If role based security happens to be based on Active Directory groups, this cache will make sure the user can still have needed role based access even when the domain is unavailable. This cache is maintained as a separate user cache from the system level AdoSecurityCache since the user data cache only contains group information and is used by the LdapSecurityProvider which can be used independently of the AdoSecurityProvider.
Inheritance: GSF.IO.InterprocessCache
Exibir arquivo Open project: GridProtectionAlliance/gsf Class Usage Examples

Public Methods

Method Description
GetCurrentCache ( int providerID ) : UserDataCache

Loads the UserDataCache for the current local user.

Save ( ) : void

Initiates inter-process synchronized save of user data cache.

SaveUserData ( string loginID, GSF.Security.UserData userData ) : void

Serializes the userData for the given loginID into the UserDataCache.

This will add an entry into the user data cache for loginID if it doesn't exist; otherwise existing entry will be updated.

Updates are automatically queued up for serialization so user does not need to call Save.

TryGetUserData ( string loginID, GSF.Security.UserData &userData ) : bool

Attempts to retrieve UserData for given loginID.

UserDataCache ( int providerID = LdapSecurityProvider.ProviderID ) : System

Creates a new instance of the UserDataCache.

UserDataCache ( int providerID, int maximumConcurrentLocks ) : System

Creates a new instance of the UserDataCache with the specified number of maximumConcurrentLocks.

this ( string loginID ) : GSF.Security.UserData

Gets or sets UserData for given loginID.

Protected Methods

Method Description
HashLoginID ( string loginID ) : string

Calculates the hash of the loginID used as the key for the user data cache.

For added security, a hash of the loginID is used as the key for UserData in the user data cache instead of the actual loginID. This method allows the consumer to properly calculate this hash when directly using the user data cache.

LoadFileData ( FileStream fileStream ) : byte[]

Handles deserialization of file from disk; virtual method allows customization (e.g., pre-load decryption and/or data merge).

Consumers overriding this method should not directly call InterprocessCache.FileData property to avoid potential dead-locks.

SaveFileData ( FileStream fileStream, byte fileData ) : void

Handles serialization of file to disk; virtual method allows customization (e.g., pre-save encryption and/or data merge).

Consumers overriding this method should not directly call InterprocessCache.FileData property to avoid potential dead-locks.

Private Methods

Method Description
DeserializeCache ( byte data ) : UserData>.Dictionary
SerializeCache ( UserData>.Dictionary cache ) : byte[]
WaitForDataReady ( ) : void

Method Details

GetCurrentCache() public static method

Loads the UserDataCache for the current local user.
public static GetCurrentCache ( int providerID ) : UserDataCache
providerID int Unique security provider ID used to distinguish cached user data that may be different based on provider.
return UserDataCache

HashLoginID() protected method

Calculates the hash of the loginID used as the key for the user data cache.
For added security, a hash of the loginID is used as the key for UserData in the user data cache instead of the actual loginID. This method allows the consumer to properly calculate this hash when directly using the user data cache.
protected HashLoginID ( string loginID ) : string
loginID string Login ID to hash.
return string

LoadFileData() protected method

Handles deserialization of file from disk; virtual method allows customization (e.g., pre-load decryption and/or data merge).
Consumers overriding this method should not directly call InterprocessCache.FileData property to avoid potential dead-locks.
protected LoadFileData ( FileStream fileStream ) : byte[]
fileStream System.IO.FileStream used to deserialize data.
return byte[]

Save() public method

Initiates inter-process synchronized save of user data cache.
public Save ( ) : void
return void

SaveFileData() protected method

Handles serialization of file to disk; virtual method allows customization (e.g., pre-save encryption and/or data merge).
Consumers overriding this method should not directly call InterprocessCache.FileData property to avoid potential dead-locks.
protected SaveFileData ( FileStream fileStream, byte fileData ) : void
fileStream System.IO.FileStream used to serialize data.
fileData byte File data to be serialized.
return void

SaveUserData() public method

Serializes the userData for the given loginID into the UserDataCache.

This will add an entry into the user data cache for loginID if it doesn't exist; otherwise existing entry will be updated.

Updates are automatically queued up for serialization so user does not need to call Save.

public SaveUserData ( string loginID, GSF.Security.UserData userData ) : void
loginID string Login ID of associated to retrieve.
userData GSF.Security.UserData Reference to object to serialize into .
return void

TryGetUserData() public method

Attempts to retrieve UserData for given loginID.
public TryGetUserData ( string loginID, GSF.Security.UserData &userData ) : bool
loginID string Login ID of associated to retrieve.
userData GSF.Security.UserData Reference to object to populate if found.
return bool

UserDataCache() public method

Creates a new instance of the UserDataCache.
public UserDataCache ( int providerID = LdapSecurityProvider.ProviderID ) : System
providerID int Unique provider ID used to distinguish cached user data that may be different based on provider.
return System

UserDataCache() public method

Creates a new instance of the UserDataCache with the specified number of maximumConcurrentLocks.
public UserDataCache ( int providerID, int maximumConcurrentLocks ) : System
providerID int Unique provider ID used to distinguish cached user data that may be different based on provider.
maximumConcurrentLocks int Maximum concurrent reader locks to allow.
return System

this() public method

Gets or sets UserData for given loginID.
public this ( string loginID ) : GSF.Security.UserData
loginID string Login ID of associated to load or save.
return GSF.Security.UserData