///
/// Evaluates the specified authority against the specified context.
///
/// Must be an object.
/// The name of the rule to evaluate.
/// true if the expression evaluates to true,
/// otherwise false.
public override bool Authorize(IPrincipal principal,
string ruleName)
{
if (principal ==
null)
throw new ArgumentNullException(
"principal");
if (ruleName ==
null || ruleName.Length ==
0)
throw new ArgumentNullException(
"ruleName");
//get the rules from the cache
if (m_CacheManager.ContainsKey(CACHEKEY))
{
GetAuthorizationRulesFromCache();
}
else {
GetAuthorizationRules();
}
InstrumentationProvider.FireAuthorizationCheckPerformed(principal.Identity.Name, ruleName);
BooleanExpression booleanExpression = GetParsedExpression(ruleName);
if (booleanExpression ==
null)
{
throw new InvalidOperationException(
string.Format(
"Authorization Rule Not Found", ruleName));
}
bool result = booleanExpression.Evaluate(principal);
if (result ==
false)
{
InstrumentationProvider.FireAuthorizationCheckFailed(principal.Identity.Name, ruleName);
}
return result;
}