Author: taylor
Date: Tue Aug 22 23:15:26 2006
New Revision: 433927
URL: http://svn.apache.org/viewvc?rev=433927&view=rev
Log:
Implement preferences per user
http://issues.apache.org/jira/browse/JS2-449
Before JS2-449, all preferences were shared.
With JS2-449, preferences are now stored 'per user'.
The username is stored in the preferences FULL_PATH
To turn on mergeSharedPreferences configure this property to true
This will NOT turn off per user prefs, but instead merge with them, where user
prefs override.
New request context function to centralize retrieval of user subject per request
Modified:
portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/request/JetspeedRequestContext.java
portals/jetspeed-2/trunk/components/registry/src/java/org/apache/jetspeed/components/portletentity/PersistenceBrokerPortletEntityAccess.java
portals/jetspeed-2/trunk/components/registry/src/java/org/apache/jetspeed/components/portletentity/PortletEntityImpl.java
Modified:
portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/request/JetspeedRequestContext.java
URL:
http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/request/JetspeedRequestContext.java?rev=433927&r1=433926&r2=433927&view=diff
==============================================================================
---
portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/request/JetspeedRequestContext.java
(original)
+++
portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/request/JetspeedRequestContext.java
Tue Aug 22 23:15:26 2006
@@ -15,6 +15,7 @@
*/
package org.apache.jetspeed.request;
+import java.security.Principal;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
@@ -40,6 +41,8 @@
import org.apache.jetspeed.om.impl.LanguageImpl;
import org.apache.jetspeed.om.page.ContentPage;
import org.apache.jetspeed.pipeline.Pipeline;
+import org.apache.jetspeed.security.SecurityHelper;
+import org.apache.jetspeed.security.UserPrincipal;
import org.apache.jetspeed.userinfo.UserInfoManager;
import org.apache.pluto.om.common.Language;
import org.apache.pluto.om.common.LanguageSet;
@@ -361,6 +364,11 @@
return this.subject;
}
+ public Principal getUserPrincipal()
+ {
+ return SecurityHelper.getBestPrincipal(getSubject(),
UserPrincipal.class);
+ }
+
/**
* @see
org.apache.jetspeed.request.RequestContext#setSubject(javax.security.auth.Subject)
*/
Modified:
portals/jetspeed-2/trunk/components/registry/src/java/org/apache/jetspeed/components/portletentity/PersistenceBrokerPortletEntityAccess.java
URL:
http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/components/registry/src/java/org/apache/jetspeed/components/portletentity/PersistenceBrokerPortletEntityAccess.java?rev=433927&r1=433926&r2=433927&view=diff
==============================================================================
---
portals/jetspeed-2/trunk/components/registry/src/java/org/apache/jetspeed/components/portletentity/PersistenceBrokerPortletEntityAccess.java
(original)
+++
portals/jetspeed-2/trunk/components/registry/src/java/org/apache/jetspeed/components/portletentity/PersistenceBrokerPortletEntityAccess.java
Tue Aug 22 23:15:26 2006
@@ -28,6 +28,7 @@
import org.apache.jetspeed.om.page.ContentFragment;
import org.apache.jetspeed.om.page.Fragment;
import org.apache.jetspeed.om.preference.impl.PrefsPreferenceSetImpl;
+import org.apache.jetspeed.request.RequestContextComponent;
import org.apache.jetspeed.util.JetspeedObjectID;
import org.apache.ojb.broker.query.Criteria;
import org.apache.ojb.broker.query.Query;
@@ -56,7 +57,15 @@
PortletEntityAccessComponent
{
private PortletRegistry registry;
-
+ private RequestContextComponent rcc;
+
+ // 2006-08-22: by default, do not merge preferences from the shared
preferences area
+ // up until this point, all preferences were shared. With JS2-449,
preferences are now
+ // stored 'per user'. The username is stored in the preferences FULL_PATH
+ // To turn on mergeSharedPreferences configure this property to true
+ // in your Spring configuration
+ boolean mergeSharedPreferences = false;
+
/**
*
* @param registry
@@ -68,6 +77,25 @@
PortletEntityImpl.registry = registry;
}
+ public PersistenceBrokerPortletEntityAccess(PortletRegistry registry,
RequestContextComponent rcc)
+ {
+ super();
+ this.registry = registry;
+ this.rcc = rcc;
+ PortletEntityImpl.registry = registry;
+ PortletEntityImpl.rcc = rcc;
+ }
+
+ public PersistenceBrokerPortletEntityAccess(PortletRegistry registry,
RequestContextComponent rcc, boolean mergeSharedPreferences)
+ {
+ super();
+ this.registry = registry;
+ this.rcc = rcc;
+ PortletEntityImpl.registry = registry;
+ PortletEntityImpl.rcc = rcc;
+ this.mergeSharedPreferences = mergeSharedPreferences;
+ }
+
public void setEntityAccessProxy(PortletEntityAccessComponent proxy)
{
PortletEntityImpl.pac = proxy;
@@ -403,4 +431,14 @@
String portletName = pd.getName();
return appName+"::"+portletName+"::"+new UID().toString();
}
+
+ /* (non-Javadoc)
+ * @see
org.apache.jetspeed.components.portletentity.PortletEntityAccessComponent#isMergeSharedPreferences()
+ */
+ public boolean isMergeSharedPreferences()
+ {
+ return this.mergeSharedPreferences;
+ }
+
+
}
Modified:
portals/jetspeed-2/trunk/components/registry/src/java/org/apache/jetspeed/components/portletentity/PortletEntityImpl.java
URL:
http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/components/registry/src/java/org/apache/jetspeed/components/portletentity/PortletEntityImpl.java?rev=433927&r1=433926&r2=433927&view=diff
==============================================================================
---
portals/jetspeed-2/trunk/components/registry/src/java/org/apache/jetspeed/components/portletentity/PortletEntityImpl.java
(original)
+++
portals/jetspeed-2/trunk/components/registry/src/java/org/apache/jetspeed/components/portletentity/PortletEntityImpl.java
Tue Aug 22 23:15:26 2006
@@ -20,9 +20,11 @@
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
+import java.util.Set;
import java.util.prefs.BackingStoreException;
import java.util.prefs.Preferences;
@@ -36,12 +38,13 @@
import org.apache.jetspeed.om.common.portlet.MutablePortletEntity;
import org.apache.jetspeed.om.common.portlet.PortletDefinitionComposite;
import org.apache.jetspeed.om.common.portlet.PrincipalAware;
-import org.apache.jetspeed.om.common.preference.PreferenceSetComposite;
import org.apache.jetspeed.om.page.Fragment;
import org.apache.jetspeed.om.portlet.impl.FragmentPortletDefinition;
import org.apache.jetspeed.om.preference.impl.PrefsPreference;
import org.apache.jetspeed.om.preference.impl.PrefsPreferenceSetImpl;
import org.apache.jetspeed.om.window.impl.PortletWindowListImpl;
+import org.apache.jetspeed.request.RequestContext;
+import org.apache.jetspeed.request.RequestContextComponent;
import org.apache.jetspeed.util.JetspeedObjectID;
import org.apache.pluto.om.common.Description;
import org.apache.pluto.om.common.ObjectID;
@@ -68,13 +71,12 @@
protected static PortletEntityAccessComponent pac;
protected static PortletRegistry registry;
-
+ protected static RequestContextComponent rcc;
+
private static final Log log = LogFactory.getLog(PortletEntityImpl.class);
protected List originalPreferences;
- // protected PrefsPreferenceSetImpl preferenceSet;
- // protected ThreadLocal preferenceSetRef = new ThreadLocal();
protected Map perPrincipalPrefs = new HashMap();
protected Map originalValues;
@@ -105,9 +107,6 @@
super();
}
- // protected Principal principal;
- protected ThreadLocal principalRef = new ThreadLocal();
-
public static final String NO_PRINCIPAL = "no-principal";
public static final String ENTITY_DEFAULT_PRINCIPAL = "entity-default";
@@ -148,21 +147,15 @@
{
if (preferenceSet == null || !dirty)
{
- //TODO: need to be setting this from
PortletEntityAccessComponent until then it will always be null.
String prefNodePath = MutablePortletEntity.PORTLET_ENTITY_ROOT
+ "/" + getId() +"/"+ principal.getName() +"/"
+ PrefsPreference.PORTLET_PREFERENCES_ROOT;
- Preferences prefNode =
Preferences.userRoot().node(prefNodePath);
-
- // NO_PRINCIPAL is actually the defa
- if(principal.getName().equals(ENTITY_DEFAULT_PRINCIPAL))
- {
- preferenceSet = new PrefsPreferenceSetImpl(prefNode);
- }
- else
+ Preferences prefNode =
Preferences.userRoot().node(prefNodePath);
+ preferenceSet = new PrefsPreferenceSetImpl(prefNode);
+ perPrincipalPrefs.put(principal, preferenceSet);
+ if (pac.isMergeSharedPreferences())
{
- preferenceSet = new PrefsPreferenceSetImpl(prefNode,
(PreferenceSetComposite) getPreferenceSet(new
PortletEntityUserPrincipal(ENTITY_DEFAULT_PRINCIPAL)) );
+ mergePreferencesSet(preferenceSet);
}
- perPrincipalPrefs.put(principal, preferenceSet);
backupValues(preferenceSet);
dirty = true;
}
@@ -176,6 +169,33 @@
}
return preferenceSet;
}
+
+ private void mergePreferencesSet(PrefsPreferenceSetImpl userPrefSet)
+ throws BackingStoreException
+ {
+ String sharedNodePath = MutablePortletEntity.PORTLET_ENTITY_ROOT + "/"
+
+ getId() +"/"+ NO_PRINCIPAL +"/" +
+ PrefsPreference.PORTLET_PREFERENCES_ROOT;
+ Preferences sharedNode = Preferences.userRoot().node(sharedNodePath);
+ if (sharedNode == null)
+ return;
+ PrefsPreferenceSetImpl sharedSet = new
PrefsPreferenceSetImpl(sharedNode);
+ if (sharedSet.size() == 0)
+ return;
+ Set names = userPrefSet.getNames();
+ Iterator sharedPrefs = sharedSet.iterator();
+ int index = 0;
+ while (sharedPrefs.hasNext())
+ {
+ PrefsPreference sharedPref = (PrefsPreference) sharedPrefs.next();
+ if (names.contains(sharedPref.getName()))
+ {
+ List prefs = Arrays.asList(sharedPref.getValueArray());
+ userPrefSet.add(sharedPref.getName(), prefs);
+ }
+ index++;
+ }
+ }
/**
* <p>
@@ -401,22 +421,13 @@
*/
public Principal getPrincipal()
{
- Principal principal = (Principal) principalRef.get();
+ RequestContext rc = rcc.getRequestContext();
+ Principal principal = rc.getUserPrincipal();
if (principal == null)
{
principal = new PortletEntityUserPrincipal(NO_PRINCIPAL);
}
-
return principal;
- }
-
- /**
- * @param principal
- * The principal to set.
- */
- protected void setPrincipal( Principal principal )
- {
- principalRef.set(principal);
}
class PortletEntityUserPrincipal implements Principal
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]