Enterprise Library Test Guide - Willy .Net
Enterprise Library Test Guide - Willy .Net
Enterprise Library Test Guide - Willy .Net
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
214<br />
<strong>Enterprise</strong> <strong>Library</strong> <strong>Test</strong> <strong>Guide</strong><br />
Table 24: Security Application Block <strong>Test</strong> Code<br />
ID Scenario <strong>Test</strong> code<br />
1 Save or read the<br />
Identity property.<br />
protected void SQLSaveReadIdentity_Click(object sender,<br />
EventArgs e)<br />
{<br />
ISecurityCacheProvider securityCache = SecurityCacheFactory.GetSecurityCacheProvider("CacheProvidersDB");<br />
IToken token = securityCache.<br />
SaveIdentity(identity);<br />
securityCache.ExpireIdentity(token);<br />
IIdentity cachedIdentity = securityCache.<br />
GetIdentity(token);<br />
}<br />
2 Save or read the<br />
Principal property.<br />
3 Save or read the<br />
Profile property.<br />
4 Authorize the user<br />
with AzMan.<br />
protected void SQLSaveReadPrincipal_Click(object<br />
sender,EventArgs e)<br />
{<br />
WindowsIdentity wi = WindowsIdentity.GetCurrent();<br />
WindowsPrincipal wp = new WindowsPrincipal(wi);<br />
ISecurityCacheProvider securityCache = SecurityCacheFactory.GetSecurityCacheProvider("CacheProvidersDB");<br />
IToken token = securityCache.SavePrincipal(wp);<br />
IPrincipal Principal=securityCache.<br />
GetPrincipal(token);<br />
}<br />
protected void SQLSaveReadProfile_Click(object sender,<br />
EventArgs e)<br />
{<br />
WindowsIdentity wi = WindowsIdentity.GetCurrent();<br />
WindowsPrincipal wp = new WindowsPrincipal(wi);<br />
ISecurityCacheProvider securityCache =<br />
SecurityCacheFactory.GetSecurityCacheProvider<br />
("CacheProvidersDB");<br />
IToken token = securityCache.SaveProfile(new object());<br />
IPrincipal Principal = securityCache.<br />
GetProfile(token);<br />
}<br />
protected void AzmanAuthProvider_Click(object sender,<br />
EventArgs e)<br />
{<br />
IAuthorizationProvider azManProvider = AuthorizationFactory.GetAuthorizationProvider("DefaultAzManProvider");<br />
WindowsIdentity identity = WindowsIdentity.GetAnonymous();<br />
bool isAuthorized = azManProvider.Authorize(new<br />
WindowsPrincipal(identity), "Authorize Purchase");<br />
}