Subject subject = context.getSubject();
if (subject == null)
{
String msg = "Invalid (null) Subject in request pipeline";
log.error(msg);
throw new ProfilerException(msg);
}
// get the UserPrincipal, finding the first UserPrincipal, or
// find the first principal if no UserPrincipal isn't available
Principal principal = SecurityHelper.getBestPrincipal(subject, UserPrincipal.class);
if (principal == null)
{
String msg = "Could not find a principle for subject in request pipeline";
log.error(msg);
throw new ProfilerException(msg);
}
// find a profiling rule for this principal
ProfilingRule rule = getRuleForPrincipal(principal, locatorName);
if (null == rule)
{
log.warn("Could not find profiling rule for principal: " + principal);
rule = this.getDefaultRule();
}
if (null == rule)
{
String msg = "Couldn't find any profiling rules including default rule for principal " + principal;
log.error(msg);
throw new ProfilerException(msg);
}
// create a profile locator for given rule
return rule.apply(context, this);
}