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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

120<br />

<strong>Enterprise</strong> <strong>Library</strong> <strong>Test</strong> <strong>Guide</strong><br />

<strong>Test</strong> case Result Automated test<br />

AuthorizationProviderFactory factory = new Authorizati<br />

onProviderFactory(configSource);<br />

Verify that<br />

custom security<br />

cache classes<br />

that derive from<br />

the Security-<br />

CacheProvider<br />

class can be<br />

added to the<br />

application block<br />

and configured<br />

from configuration<br />

source.<br />

Passed<br />

IAuthorizationProvider authRuleProvider = factory.<br />

Create("MyAuthorizationProvider");<br />

bool authorized = authRuleProvider.Authorize(null,"");<br />

Assert.IsTrue(authorized);<br />

}<br />

In this example, the custom authorization class, CustomSecurityCacheProvider,<br />

derives from the SecurityCacheProvider class.<br />

The <strong>Enterprise</strong> <strong>Library</strong> Core uses information in the dictionary<br />

configuration source to add the custom class to the application<br />

block.<br />

The following is the configuration information.<br />

public DictionaryConfigurationSource BuildDictionarySourceSection()<br />

{<br />

DictionaryConfigurationSource section = new Dictionary-<br />

ConfigurationSource();<br />

SecuritySettings secSettings = new SecuritySettings();<br />

CustomSecurityCacheProviderData customData<br />

= new CustomSecurityCacheProviderData("MyCache", Type.<br />

GetType("SecurityCachingFunc<strong>Test</strong>s.CustomSecurityCacheP<br />

rovider,SecurityCachingFunc<strong>Test</strong>s"));<br />

customData.Attributes.Add("key1", "value1");<br />

secSettings.SecurityCacheProviders.<br />

Add(customData);<br />

section.Add("securityConfiguration", secSettings);<br />

}<br />

The following is the custom class.<br />

[ConfigurationElementType(typeof(CustomSecurityCachePro<br />

viderData))]<br />

class CustomSecurityCacheProvider:SecurityCacheProvider<br />

{<br />

public override IToken SaveIdentity(IIdentity identity){…}<br />

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

IToken token)<br />

{…}<br />

public override IToken SavePrincipal(IPrincipal principal)<br />

{…}

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

Saved successfully!

Ooh no, something went wrong!