taylor 2004/10/07 23:49:38
Modified: src/sql populate-db-default.sql
src/schema phase2-schema.xml
jetspeed-api/src/java/org/apache/jetspeed/profiler
ProfileLocator.java Profiler.java
applications/pam/src/java/org/apache/jetspeed/portlets/security
UserDetailsPortlet.java
components/profiler/src/test/org/apache/jetspeed/profiler
TestProfiler.java
components/profiler/src/java/META-INF ojb_repository.xml
portal/src/java/org/apache/jetspeed/profiler/impl
ProfilerValveImpl.java
components/profiler/src/java/org/apache/jetspeed/profiler/impl
JetspeedProfiler.java
jetspeed-api/src/java/org/apache/jetspeed/profiler/rules
PrincipalRule.java
components/profiler/src/java/org/apache/jetspeed/profiler/rules/impl
PrincipalRuleImpl.java
Log:
added locatorName parameter to several Profiler APIs
before this change, the profiler only looked up pages
now it has the capability to lookup other resources such as docsets
note: this commit requires changing your db schema
Revision Changes Path
1.5 +2 -2 jakarta-jetspeed-2/src/sql/populate-db-default.sql
Index: populate-db-default.sql
===================================================================
RCS file: /home/cvs/jakarta-jetspeed-2/src/sql/populate-db-default.sql,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- populate-db-default.sql 23 Sep 2004 22:46:45 -0000 1.4
+++ populate-db-default.sql 8 Oct 2004 06:49:37 -0000 1.5
@@ -305,8 +305,8 @@
insert into RULE_CRITERION values (12, 'role-group', 1, 'group', 'group', null, 2);
insert into RULE_CRITERION values (13, 'role-group', 1, 'request.session', 'page',
'default-page', 0);
-insert into PRINCIPAL_RULE_ASSOC values ( 'guest', 'j1' );
-insert into PRINCIPAL_RULE_ASSOC values ( 'jetspeed', 'role-fallback' );
+insert into PRINCIPAL_RULE_ASSOC values ( 'guest', 'page', 'j1' );
+insert into PRINCIPAL_RULE_ASSOC values ( 'jetspeed', 'page', 'role-fallback' );
1.5 +2 -1 jakarta-jetspeed-2/src/schema/phase2-schema.xml
Index: phase2-schema.xml
===================================================================
RCS file: /home/cvs/jakarta-jetspeed-2/src/schema/phase2-schema.xml,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- phase2-schema.xml 23 Sep 2004 22:30:21 -0000 1.4
+++ phase2-schema.xml 8 Oct 2004 06:49:37 -0000 1.5
@@ -131,9 +131,10 @@
<table name="PRINCIPAL_RULE_ASSOC">
<column name="PRINCIPAL_NAME" primaryKey="true" required="true" size="80"
type="VARCHAR"/>
+ <column name="LOCATOR_NAME" primaryKey="true" required="true" size="80"
type="VARCHAR"/>
<column name="RULE_ID" required="true" size="80" type="VARCHAR"/>
</table>
-
+
<table name="PROFILE_PAGE_ASSOC">
<column name="LOCATOR_HASH" required="true" size="40" type="VARCHAR"/>
<column name="PAGE_ID" required="true" size="80" type="VARCHAR"/>
1.4 +5 -2
jakarta-jetspeed-2/jetspeed-api/src/java/org/apache/jetspeed/profiler/ProfileLocator.java
Index: ProfileLocator.java
===================================================================
RCS file:
/home/cvs/jakarta-jetspeed-2/jetspeed-api/src/java/org/apache/jetspeed/profiler/ProfileLocator.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ProfileLocator.java 23 Sep 2004 22:30:03 -0000 1.3
+++ ProfileLocator.java 8 Oct 2004 06:49:37 -0000 1.4
@@ -40,8 +40,11 @@
*/
public interface ProfileLocator
{
+ public final static String PAGE_LOCATOR = "page";
+ public final static String DOCSET_LOCATOR = "docset";
+
public final static String PATH_SEPARATOR = ":";
-
+
/**
* Initialize this page context.
*
1.7 +8 -5
jakarta-jetspeed-2/jetspeed-api/src/java/org/apache/jetspeed/profiler/Profiler.java
Index: Profiler.java
===================================================================
RCS file:
/home/cvs/jakarta-jetspeed-2/jetspeed-api/src/java/org/apache/jetspeed/profiler/Profiler.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- Profiler.java 23 Sep 2004 22:30:03 -0000 1.6
+++ Profiler.java 8 Oct 2004 06:49:37 -0000 1.7
@@ -45,9 +45,10 @@
* Get the Profile object using the request parameters.
*
* @param context The request context
+ * @param locatorName The name of the profile locator to find i.e. "page",
"docset", ...
* @return a new Profile Locator object or null if failed to find a appropriate
locator.
*/
- ProfileLocator getProfile(RequestContext context) throws ProfilerException;
+ ProfileLocator getProfile(RequestContext context, String locatorName) throws
ProfilerException;
/**
* Get the Profile object using the request parameters and the rule.
@@ -80,18 +81,20 @@
* For a given principal, lookup the associated profiling rule to that
principal name.
*
* @param principal Lookup the profiling rule based on this principal.
+ * @param locatorName the unique name of a locator for this
principal/rule/locator
* @return The rule found or null if not found
*/
- ProfilingRule getRuleForPrincipal(Principal principal);
+ ProfilingRule getRuleForPrincipal(Principal principal, String locatorName);
/**
* For a given principal, associate a profiling rule to that principal name.
* TODO: this API should be secured and require admin role
*
- * @param principal Lookup the profiling rule based on this principal.
+ * @param principal Lookup the profiling rule based on this principal.
+ * @param locatorName the unique name of a locator for this
principal/rule/locator
* @param The rule used to find profiles for this user
*/
- void setRuleForPrincipal(Principal principal, ProfilingRule rule);
+ void setRuleForPrincipal(Principal principal, ProfilingRule rule, String
locatorName);
/**
* Lookup the portal's default profiling rule.
1.9 +11 -4
jakarta-jetspeed-2/applications/pam/src/java/org/apache/jetspeed/portlets/security/UserDetailsPortlet.java
Index: UserDetailsPortlet.java
===================================================================
RCS file:
/home/cvs/jakarta-jetspeed-2/applications/pam/src/java/org/apache/jetspeed/portlets/security/UserDetailsPortlet.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- UserDetailsPortlet.java 6 Oct 2004 23:45:05 -0000 1.8
+++ UserDetailsPortlet.java 8 Oct 2004 06:49:37 -0000 1.9
@@ -37,6 +37,7 @@
import org.apache.jetspeed.portlets.pam.beans.TabBean;
import org.apache.jetspeed.portlets.security.users.JetspeedUserBean;
import org.apache.jetspeed.portlets.security.users.JetspeedUserBean.StringAttribute;
+import org.apache.jetspeed.profiler.ProfileLocator;
import org.apache.jetspeed.profiler.Profiler;
import org.apache.jetspeed.profiler.rules.ProfilingRule;
import org.apache.jetspeed.security.GroupManager;
@@ -161,7 +162,8 @@
else if (selectedTab.getId().equals(TAB_PROFILE))
{
Principal userPrincipal = createPrincipal(user.getSubject(),
UserPrincipal.class);
- ProfilingRule rule = profiler.getRuleForPrincipal(userPrincipal);
+ // TODO: incorporate locator_name
+ ProfilingRule rule = profiler.getRuleForPrincipal(userPrincipal,
ProfileLocator.PAGE_LOCATOR);
if (rule != null)
{
request.setAttribute(VIEW_SELECTED_RULE, rule.getId());
@@ -514,11 +516,16 @@
{
if (rule == null)
{
- profiler.setRuleForPrincipal(userPrincipal,
profiler.getDefaultRule());
+ profiler.setRuleForPrincipal(userPrincipal,
+ profiler.getDefaultRule(),
+
ProfileLocator.PAGE_LOCATOR);
}
else
{
- profiler.setRuleForPrincipal(userPrincipal, rule);
+ // TODO: only support the page locator for now
+ profiler.setRuleForPrincipal(userPrincipal,
+ rule,
+
ProfileLocator.PAGE_LOCATOR);
}
}
}
1.4 +4 -4
jakarta-jetspeed-2/components/profiler/src/test/org/apache/jetspeed/profiler/TestProfiler.java
Index: TestProfiler.java
===================================================================
RCS file:
/home/cvs/jakarta-jetspeed-2/components/profiler/src/test/org/apache/jetspeed/profiler/TestProfiler.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- TestProfiler.java 23 Sep 2004 19:47:29 -0000 1.3
+++ TestProfiler.java 8 Oct 2004 06:49:37 -0000 1.4
@@ -117,7 +117,7 @@
assertTrue("default rule class not mapped", rule instanceof
StandardProfilingRule);
// Test anonymous principal-rule
- ProfilingRule anonRule = profiler.getRuleForPrincipal(new
UserPrincipalImpl("anon"));
+ ProfilingRule anonRule = profiler.getRuleForPrincipal(new
UserPrincipalImpl("anon"), ProfileLocator.PAGE_LOCATOR);
assertNotNull("anonymous rule is null", anonRule);
assertTrue("anonymous rule is j1", anonRule.getId().equals(DEFAULT_RULE));
@@ -255,7 +255,7 @@
params.put("page", "default-other");
params.put("path", "/sports/football/nfl/chiefs");
- ProfileLocator locator = profiler.getProfile(request);
+ ProfileLocator locator = profiler.getProfile(request,
ProfileLocator.PAGE_LOCATOR);
assertNotNull("rule test on getProfile returned null", locator);
String path = locator.getLocatorPath();
System.out.println("locator = " + path);
@@ -344,7 +344,7 @@
Map params = request.getParameterMap();
// params.put("page", "default");
- ProfileLocator locator = profiler.getProfile(request);
+ ProfileLocator locator = profiler.getProfile(request,
ProfileLocator.PAGE_LOCATOR);
assertNotNull("rule test on getProfile returned null", locator);
System.out.println("page = " + locator.getValue("page"));
}
1.3 +7 -0
jakarta-jetspeed-2/components/profiler/src/java/META-INF/ojb_repository.xml
Index: ojb_repository.xml
===================================================================
RCS file:
/home/cvs/jakarta-jetspeed-2/components/profiler/src/java/META-INF/ojb_repository.xml,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ojb_repository.xml 17 Sep 2004 20:03:23 -0000 1.2
+++ ojb_repository.xml 8 Oct 2004 06:49:37 -0000 1.3
@@ -147,6 +147,13 @@
autoincrement="false"
/>
<field-descriptor
+ name="locatorName"
+ column="LOCATOR_NAME"
+ jdbc-type="VARCHAR"
+ primarykey="true"
+ autoincrement="false"
+ />
+ <field-descriptor
name="ruleId"
column="RULE_ID"
jdbc-type="VARCHAR"
1.15 +2 -2
jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/profiler/impl/ProfilerValveImpl.java
Index: ProfilerValveImpl.java
===================================================================
RCS file:
/home/cvs/jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/profiler/impl/ProfilerValveImpl.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- ProfilerValveImpl.java 23 Sep 2004 22:35:11 -0000 1.14
+++ ProfilerValveImpl.java 8 Oct 2004 06:49:37 -0000 1.15
@@ -65,7 +65,7 @@
{
// perform profiling to get profiled page context using
// the profiler and page manager
- ProfileLocator locator = profiler.getProfile(request);
+ ProfileLocator locator = profiler.getProfile(request,
ProfileLocator.PAGE_LOCATOR);
ProfiledPageContext profiledPageContext =
pageManager.getProfiledPageContext(locator);
if ((profiledPageContext == null) || (profiledPageContext.getPage() ==
null) || (profiledPageContext.getLocator() == null))
throw new NodeNotFoundException("Unable to profile request: " +
request.getPath());
1.5 +12 -18
jakarta-jetspeed-2/components/profiler/src/java/org/apache/jetspeed/profiler/impl/JetspeedProfiler.java
Index: JetspeedProfiler.java
===================================================================
RCS file:
/home/cvs/jakarta-jetspeed-2/components/profiler/src/java/org/apache/jetspeed/profiler/impl/JetspeedProfiler.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- JetspeedProfiler.java 23 Sep 2004 22:34:21 -0000 1.4
+++ JetspeedProfiler.java 8 Oct 2004 06:49:38 -0000 1.5
@@ -125,12 +125,8 @@
}
- /*
- * (non-Javadoc)
- *
- * @see
org.apache.jetspeed.profiler.ProfilerService#getProfile(org.apache.jetspeed.request.RequestContext)
- */
- public ProfileLocator getProfile( RequestContext context ) throws
ProfilerException
+ public ProfileLocator getProfile(RequestContext context, String locatorName)
+ throws ProfilerException
{
// get the principal representing the currently logged on user
Subject subject = context.getSubject();
@@ -151,7 +147,7 @@
}
// find a profiling rule for this principal
- ProfilingRule rule = getRuleForPrincipal(principal);
+ ProfilingRule rule = getRuleForPrincipal(principal, locatorName);
if (null == rule)
{
log.warn("Could not find profiling rule for principal: " + principal);
@@ -190,15 +186,10 @@
return lookupProfilingRule(this.defaultRule);
}
- /*
- * (non-Javadoc)
- *
- * @see
org.apache.jetspeed.profiler.ProfilerService#getRuleForPrincipal(java.security.Principal)
- */
- public ProfilingRule getRuleForPrincipal( Principal principal )
+ public ProfilingRule getRuleForPrincipal(Principal principal, String
locatorName)
{
// lookup the rule for the given principal in our user/rule table
- PrincipalRule pr = lookupPrincipalRule(principal.getName());
+ PrincipalRule pr = lookupPrincipalRule(principal.getName(), locatorName);
// if not found, fallback to the system wide rule
if (pr == null)
@@ -211,19 +202,21 @@
}
- public void setRuleForPrincipal(Principal principal, ProfilingRule rule)
+ public void setRuleForPrincipal(Principal principal, ProfilingRule rule, String
locatorName)
{
Transaction tx = persistentStore.getTransaction();
tx.begin();
Filter filter = persistentStore.newFilter();
filter.addEqualTo("principalName", principal);
+ filter.addEqualTo("locatorName", locatorName);
Object query = persistentStore.newQuery(principalRuleClass, filter);
PrincipalRule pr = (PrincipalRule) persistentStore.getObjectByQuery(query);
if (pr == null)
{
pr = new PrincipalRuleImpl(); // TODO: factory
pr.setPrincipalName(principal.getName());
+ pr.setLocatorName(locatorName);
pr.setProfilingRule(rule);
}
try
@@ -249,15 +242,16 @@
* @return The found PrincipalRule associated with the principal key or null
* if not found.
*/
- private PrincipalRule lookupPrincipalRule( String principal )
+ private PrincipalRule lookupPrincipalRule(String principal, String locatorName)
{
PrincipalRule pr = (PrincipalRule) principalRules.get(principal);
if (pr != null)
{
return pr;
}
- Filter filter = persistentStore.newFilter();
+ Filter filter = persistentStore.newFilter();
filter.addEqualTo("principalName", principal);
+ filter.addEqualTo("locatorName", locatorName);
Object query = persistentStore.newQuery(principalRuleClass, filter);
pr = (PrincipalRule) persistentStore.getObjectByQuery(query);
principalRules.put(principal, pr);
1.2 +23 -3
jakarta-jetspeed-2/jetspeed-api/src/java/org/apache/jetspeed/profiler/rules/PrincipalRule.java
Index: PrincipalRule.java
===================================================================
RCS file:
/home/cvs/jakarta-jetspeed-2/jetspeed-api/src/java/org/apache/jetspeed/profiler/rules/PrincipalRule.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- PrincipalRule.java 28 May 2004 18:51:56 -0000 1.1
+++ PrincipalRule.java 8 Oct 2004 06:49:38 -0000 1.2
@@ -27,7 +27,7 @@
public interface PrincipalRule
{
/**
- * Gets the name of the principal in this principal/rule pair association.
+ * Gets the name of the principal in this principal/rule/locator pair
association.
* The principal name identifies the uniqueness of the relationship.
* It is used for keyed lookups to find the rule associated with this
principal.
*
@@ -36,13 +36,33 @@
String getPrincipalName();
/**
- * Sets the name of the principal in this principal/rule pair association.
+ * Sets the name of the principal in this principal/rule/locator pair
association.
* The principal name identifies the uniqueness of the relationship.
* It is used for keyed lookups to find the rule associated with this
principal.
*
* @param name The name of the principal in this association.
*/
void setPrincipalName(String name);
+
+ /**
+ * Gets the name of the locator in this principal/rule/locator pair association.
+ * The principal + locator name identifies the uniqueness of the relationship.
+ * It is used for keyed lookups to find the rule associated with this principal
+ * for a given locator
+ *
+ * @return The name of the locator in this association.
+ */
+ String getLocatorName();
+
+ /**
+ * Sets the name of the locator in this principal/locator/rule pair association.
+ * The principal name + locator name identifies the uniqueness of the
relationship.
+ * It is used for keyed lookups to find the rule associated with this principal
+ * for a given locator
+ *
+ * @param name The name of the locator in this association.
+ */
+ void setLocatorName(String name);
/**
1.4 +16 -1
jakarta-jetspeed-2/components/profiler/src/java/org/apache/jetspeed/profiler/rules/impl/PrincipalRuleImpl.java
Index: PrincipalRuleImpl.java
===================================================================
RCS file:
/home/cvs/jakarta-jetspeed-2/components/profiler/src/java/org/apache/jetspeed/profiler/rules/impl/PrincipalRuleImpl.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- PrincipalRuleImpl.java 20 Sep 2004 17:17:03 -0000 1.3
+++ PrincipalRuleImpl.java 8 Oct 2004 06:49:38 -0000 1.4
@@ -29,6 +29,7 @@
private String principalName;
private String ruleId;
private ProfilingRule profilingRule;
+ private String locatorName;
/* (non-Javadoc)
* @see org.apache.jetspeed.profiler.rules.PrincipalRule#getPrincipalName()
@@ -64,4 +65,18 @@
this.ruleId = rule.getId();
}
+ /**
+ * @return Returns the locatorName.
+ */
+ public String getLocatorName()
+ {
+ return locatorName;
+ }
+ /**
+ * @param locatorName The locatorName to set.
+ */
+ public void setLocatorName(String locatorName)
+ {
+ this.locatorName = locatorName;
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]