/** * Internal method to ensure we have a valid principalRule class for queries * * @return the class object for the principalRule */ private Class getPrincipalRuleClass() { if (this.prRuleClass == null) { try { PrincipalRule tempRule = createPrincipalRule(); this.prRuleClass = tempRule.getClass(); } catch (Exception e) { e.printStackTrace(); } } return this.prRuleClass; }
public Map<String, ProfileLocator> getDefaultProfileLocators(RequestContext context) throws ProfilerException { // get default profile locators Map<String, ProfileLocator> locators = new HashMap<String, ProfileLocator>(); Collection<PrincipalRule> rules = getRulesForPrincipal(DEFAULT_RULE_PRINCIPAL); for (PrincipalRule pr : rules) { locators.put(pr.getLocatorName(), getDefaultProfile(context, pr.getLocatorName())); } return locators; }
public void storeProfilingRule(ProfilingRule rule) throws ProfilerException { getPersistenceBrokerTemplate().store(rule); }
public Map<String, ProfileLocator> getProfileLocators(RequestContext context, Principal principal) throws ProfilerException { // setup/maintain profiler context for session end notification setupProfilerContext(context); // get profile locators Map<String, ProfileLocator> locators = new HashMap<String, ProfileLocator>(); Collection<PrincipalRule> rules = getRulesForPrincipal(principal); for (PrincipalRule pr : rules) { locators.put(pr.getLocatorName(), getProfile(context, pr.getLocatorName())); } return locators; }
public ProfilingRule getRuleForPrincipal(Principal principal, String locatorName) { ProfilingRule rule = null; // lookup the rule for the given principal in our user/rule table PrincipalRule pr = lookupPrincipalRule(principal.getName(), locatorName); // if not found, fallback to the locator named rule or system wide rule if (pr == null) { // find rule on locator name rule = getRule(locatorName); if (rule == null) { // if not found, fallback to the system wide rule rule = getDefaultRule(); } pr = new PrincipalRuleImpl(); pr.setLocatorName(locatorName); pr.setPrincipalName(principal.getName()); pr.setProfilingRule(rule); principalRules.put(makePrincipalRuleKey(principal.getName(), locatorName), pr); // track cached principal rules trackCachedPrincipalRulesPut(principal.getName(), pr); } else { // Get the associated rule rule = pr.getProfilingRule(); } return rule; }
/** * Helper function to lookup principal rule associations by principal * * @param principal The string representation of the principal name. * @return The found PrincipalRule associated with the principal key or null * if not found. */ private PrincipalRule lookupPrincipalRule(String principal, String locatorName) { PrincipalRule pr = principalRules.get(makePrincipalRuleKey(principal, locatorName)); if (pr != null) { return pr; } Criteria c = new Criteria(); c.addEqualTo("principalName", principal); c.addEqualTo("locatorName", locatorName); pr = (PrincipalRule) getPersistenceBrokerTemplate().getObjectByQuery( QueryFactory.newQuery(getPrincipalRuleClass(), c)); if (pr != null) pr.getProfilingRule().setResolvers(resolvers); principalRules.put(makePrincipalRuleKey(principal, locatorName), pr); // track cached principal rules trackCachedPrincipalRulesPut(principal, pr); return pr; }
public void deletePrincipalRule(PrincipalRule rule) throws ProfilerException { getPersistenceBrokerTemplate().delete(rule); // reset persistent rules per principal rulesPerPrincipal.remove(rule.getPrincipalName()); String key = this.makePrincipalRuleKey(rule.getPrincipalName(), rule.getLocatorName()); // remove individual rule principalRules.remove(key); // track cached principal rules trackCachedPrincipalRulesRemoved(rule.getPrincipalName(), rule); }
setupProfilerContext(context); ProfilingRule rule = getRuleForPrincipal(principal, locatorName); if (null == rule) { log.warn("Could not find profiling rule for principal: " + principal); rule = this.getDefaultRule();
public Collection<PrincipalRule> getRulesForPrincipal(Principal principal) { Collection<PrincipalRule> rules = this.rulesPerPrincipal.get(principal.getName()); if (rules != null) return rules; Criteria c = new Criteria(); c.addEqualTo("principalName", principal.getName()); rules = getPersistenceBrokerTemplate().getCollectionByQuery( QueryFactory.newQuery(getPrincipalRuleClass(), c)); for (PrincipalRule pr : rules) { ProfilingRule rule = pr.getProfilingRule(); if (rule != null) rule.setResolvers(resolvers); } this.rulesPerPrincipal.put(principal.getName(), rules); return rules; }
public ProfileLocator getDefaultProfile(RequestContext context, String locatorName) throws ProfilerException { // find a profiling rule for the default principal ProfilingRule rule = getRuleForPrincipal(DEFAULT_RULE_PRINCIPAL, locatorName); if (null == rule) { log.warn("Could not find profiling rule for principal: " + DEFAULT_RULE_PRINCIPAL); rule = this.getDefaultRule(); } if (null == rule) { String msg = "Couldn't find any profiling rules including default rule for principal " + DEFAULT_RULE_PRINCIPAL; log.error(msg); throw new ProfilerException(msg); } // create a profile locator for given rule return rule.apply(context, this); }
/** * Evict cached profiler rule information for principal. * * @param principalName cached profiler rule key * @param force force eviction of guest and default rules */ private void evictCachedPrincipalRules(String principalName, boolean force) { if (principalName != null) { // do not evict guest and default principal profiler rules by // default since they would be evicted all too frequently if (force || (!principalName.equals(getGuestPrincipalName()) && !principalName.equals(DEFAULT_RULE_PRINCIPAL_NAME))) { // evict cached profiler rules Collection<PrincipalRule> rules = allRulesPerPrincipal.remove(principalName); if (rules != null) { rulesPerPrincipal.remove(principalName); for (PrincipalRule rule : rules) { String key = this.makePrincipalRuleKey(rule.getPrincipalName(), rule.getLocatorName()); principalRules.remove(key); } } } } }
public ProfilingRule getDefaultRule() { return getRule(this.defaultRule); }
public void setRuleForPrincipal(Principal principal, ProfilingRule rule, String locatorName) { Criteria c = new Criteria(); c.addEqualTo("principalName", principal.getName()); c.addEqualTo("locatorName", locatorName); PrincipalRule pr = (PrincipalRule) getPersistenceBrokerTemplate() .getObjectByQuery( QueryFactory.newQuery(getPrincipalRuleClass(), c)); if (pr == null) { pr = new PrincipalRuleImpl(); // TODO: factory pr.setPrincipalName(principal.getName()); pr.setLocatorName(locatorName); pr.setProfilingRule(rule); } rule.setResolvers(resolvers); pr.setProfilingRule(rule); getPersistenceBrokerTemplate().store(pr); principalRules.put(makePrincipalRuleKey(principal.getName(), locatorName), pr); // track cached principal rules trackCachedPrincipalRulesPut(principal.getName(), pr); // reset persistent rules per principal rulesPerPrincipal.remove(principal.getName()); }
public String[] getLocatorNamesForPrincipal(Principal principal) { Criteria c = new Criteria(); c.addEqualTo("principalName", principal.getName()); Collection<PrincipalRule> result = getPersistenceBrokerTemplate() .getCollectionByQuery( QueryFactory.newQuery(getPrincipalRuleClass(), c)); if (result.size() == 0) { return new String[]{}; } String[] names = new String[result.size()]; int ix = 0; for (PrincipalRule pr : result) { names[ix] = pr.getLocatorName(); pr.getProfilingRule().setResolvers(resolvers); ix++; } return names; }
public void deleteProfilingRule(ProfilingRule rule) throws ProfilerException { getPersistenceBrokerTemplate().delete(rule); }
public void storePrincipalRule(PrincipalRule rule) throws ProfilerException { getPersistenceBrokerTemplate().store(rule); }
public Collection<ProfilingRule> getRules() { Collection<ProfilingRule> rules = getPersistenceBrokerTemplate().getCollectionByQuery( QueryFactory.newQuery(profilingRuleClass, new Criteria())); for (ProfilingRule rule : rules) { rule.setResolvers(resolvers); } return rules; }
public ProfilingRule getRule(String id) { Criteria c = new Criteria(); c.addEqualTo("id", id); ProfilingRule rule = (ProfilingRule) getPersistenceBrokerTemplate() .getObjectByQuery(QueryFactory.newQuery(profilingRuleClass, c)); if (rule != null) { rule.setResolvers(resolvers); } return rule; }