07.11.2014 Views

Enterprise Library Test Guide - Willy .Net

Enterprise Library Test Guide - Willy .Net

Enterprise Library Test Guide - Willy .Net

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Test</strong>ing the Security Application Block 109<br />

Code test case Implemented? Feature that is implemented<br />

Verify that<br />

the security<br />

cache provider<br />

encrypts the<br />

data stored in<br />

the cache.<br />

Yes<br />

The CachingStoreProvider class derives from the SecurityCacheProvider<br />

class. This class uses a CacheManager<br />

instance to add, remove, and retrieve an identity from the<br />

cache. In the following example, the CacheManager instance<br />

adds the identity to the caching store. The Caching Application<br />

Block’s database cache encrypts the data stored in the cache.<br />

public class CachingStoreProvider : Security-<br />

CacheProvider<br />

{<br />

private CacheManager securityCacheManager;<br />

public override void SaveIdentity(IIdentity identity,<br />

IToken token)<br />

{<br />

GetSecurityCacheItem(token, true).Identity = identity;<br />

}<br />

private SecurityCacheItem GetSecurityCacheItem(ITok<br />

en token, bool createIfNull)<br />

{<br />

…<br />

securityCacheManager.Add(token.Value, item, CacheItemPriority.Normal,<br />

null, GetCacheExpirations());<br />

…<br />

}<br />

}<br />

The following code demonstrates how the DatabaseBacking-<br />

Store object encrypts the data before adding it to the database.<br />

public class DatabaseBackingStore : BaseBacking-<br />

Store<br />

{<br />

protected override void AddNewItem(int storageKey,<br />

CacheItem newItem)<br />

{<br />

…<br />

this.encryptionProvider.Encrypt(valueBytes);<br />

…<br />

}<br />

}<br />

Similarly, the Caching Application Block’s IsolatedStorage-<br />

CacheProvider class also encrypts the data stored in the<br />

cache.<br />

continued

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!