portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tay...@apache.org
Subject svn commit: r1685182 - in /portals/jetspeed-2/portal/trunk: components/jetspeed-portal/src/main/java/org/apache/jetspeed/engine/ components/jetspeed-registry/src/main/java/org/apache/jetspeed/components/portletpreferences/ components/jetspeed-security/...
Date Fri, 12 Jun 2015 22:30:04 GMT
Author: taylor
Date: Fri Jun 12 22:30:03 2015
New Revision: 1685182

URL: http://svn.apache.org/r1685182
Log:
S2-1325: portlet preferences caching improvements

Modified:
    portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/engine/JetspeedServlet.java
    portals/jetspeed-2/portal/trunk/components/jetspeed-registry/src/main/java/org/apache/jetspeed/components/portletpreferences/PortletPreferencesServiceImpl.java
    portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/UserManagerImpl.java
    portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/stubs/StubPortletPreferences.java
    portals/jetspeed-2/portal/trunk/components/jetspeed-sso/src/test/java/org/apache/jetspeed/sso/StubPortletPreferences.java
    portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/components/portletpreferences/PortletPreferencesProvider.java
    portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/security-managers.xml

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/engine/JetspeedServlet.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/engine/JetspeedServlet.java?rev=1685182&r1=1685181&r2=1685182&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/engine/JetspeedServlet.java
(original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/engine/JetspeedServlet.java
Fri Jun 12 22:30:03 2015
@@ -27,6 +27,7 @@ import org.apache.jetspeed.components.Co
 import org.apache.jetspeed.components.JetspeedBeanDefinitionFilter;
 import org.apache.jetspeed.components.SpringComponentManager;
 import org.apache.jetspeed.components.factorybeans.ServletConfigFactoryBean;
+import org.apache.jetspeed.components.portletpreferences.PortletPreferencesProvider;
 import org.apache.jetspeed.container.session.PortalSessionsManager;
 import org.apache.jetspeed.engine.servlet.ServletHelper;
 import org.apache.jetspeed.exception.JetspeedException;
@@ -389,6 +390,10 @@ public class JetspeedServlet extends Htt
                 psm.portalSessionCreated(se.getSession());
             }
         }
+        PortletPreferencesProvider preferencesProvider = engine.getComponentManager().lookupComponent("portletPreferencesProvider");
+        if (preferencesProvider != null) {
+            preferencesProvider.sessionCreatedEvent(se.getSession());
+        }
     }
     
     public void sessionDestroyed(HttpSessionEvent se)
@@ -410,6 +415,11 @@ public class JetspeedServlet extends Htt
         statistics.logUserLogout(ipAddress, subjectUserPrincipal.getName(), sessionLength);
   
         UserContentCacheManager userContentCacheManager = engine.getComponentManager().lookupComponent("userContentCacheManager");
         userContentCacheManager.evictUserContentCache(subjectUserPrincipal.getName(), se.getSession().getId());
+        // clear preferences cache
+        PortletPreferencesProvider preferencesProvider = engine.getComponentManager().lookupComponent("portletPreferencesProvider");
+        if (preferencesProvider != null) {
+            preferencesProvider.sessionDestroyedEvent(se.getSession());
+        }
     }
            
     /**

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-registry/src/main/java/org/apache/jetspeed/components/portletpreferences/PortletPreferencesServiceImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-registry/src/main/java/org/apache/jetspeed/components/portletpreferences/PortletPreferencesServiceImpl.java?rev=1685182&r1=1685181&r2=1685182&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-registry/src/main/java/org/apache/jetspeed/components/portletpreferences/PortletPreferencesServiceImpl.java
(original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-registry/src/main/java/org/apache/jetspeed/components/portletpreferences/PortletPreferencesServiceImpl.java
Fri Jun 12 22:30:03 2015
@@ -45,6 +45,7 @@ import org.springframework.orm.ojb.suppo
 import javax.portlet.PortletRequest;
 import javax.portlet.PreferencesValidator;
 import javax.portlet.ValidatorException;
+import javax.servlet.http.HttpSession;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.Iterator;
@@ -459,6 +460,10 @@ public class PortletPreferencesServiceIm
      */    
     public void preloadUserPreferences()
     {
+        if (enableSessionCache) {
+            return;
+        }
+
         JetspeedPreferencesMap map = new JetspeedPreferencesMap();
         Criteria c = new Criteria();
         c.addEqualTo(DTYPE, DISCRIMINATOR_USER);
@@ -751,31 +756,33 @@ public class PortletPreferencesServiceIm
     public Map<String, PortletPreference> getUserPreferences(org.apache.jetspeed.om.portlet.PortletDefinition
portletdefinition, String windowId,
                                                              String userName)
     {
-        JetspeedPreferencesMap userPreferences = new JetspeedPreferencesMap();
         String appName = portletdefinition.getApplication().getName();
         String portletName = portletdefinition.getPortletName();
-        
-        String userCacheKey = getUserPreferenceKey(appName, portletName,windowId, userName);
-        CacheElement cachedDefaults = preferenceCache.get(userCacheKey);
-        if (cachedDefaults != null)
-        {
-            userPreferences = (JetspeedPreferencesMap) cachedDefaults.getContent();
+        String userCacheKey = getUserPreferenceKey(appName, portletName, windowId, userName);
+
+        if (!enableSessionCache) {
+            JetspeedPreferencesMap userPreferences = null;
+            CacheElement cachedDefaults = preferenceCache.get(userCacheKey);
+            if (cachedDefaults != null) {
+                userPreferences = (JetspeedPreferencesMap) cachedDefaults.getContent();
+                return userPreferences;
+            }
         }
-        else
+        JetspeedPreferencesMap userPreferences = new JetspeedPreferencesMap();
+        Criteria c = new Criteria();
+        c.addEqualTo(DTYPE, DISCRIMINATOR_USER);
+        c.addEqualTo(APPLICATION_NAME, appName);
+        c.addEqualTo(PORTLET_NAME, portletName);
+        c.addEqualTo(USER_NAME, userName);
+        c.addEqualTo(ENTITY_ID, windowId);
+        QueryByCriteria query = QueryFactory.newQuery(DatabasePreference.class, c);
+        Iterator<DatabasePreference> preferences = getPersistenceBrokerTemplate().getIteratorByQuery(query);
+        while (preferences.hasNext())
         {
-            Criteria c = new Criteria();
-            c.addEqualTo(DTYPE, DISCRIMINATOR_USER);
-            c.addEqualTo(APPLICATION_NAME, appName);
-            c.addEqualTo(PORTLET_NAME, portletName);
-            c.addEqualTo(USER_NAME, userName);
-            c.addEqualTo(ENTITY_ID, windowId);
-            QueryByCriteria query = QueryFactory.newQuery(DatabasePreference.class, c);
-            Iterator<DatabasePreference> preferences = getPersistenceBrokerTemplate().getIteratorByQuery(query);
-            while (preferences.hasNext())
-            {
-                DatabasePreference preference = preferences.next();
-                userPreferences.put(preference.getName(), new JetspeedPreferenceImpl(preference.getName(),
preference.getValues(), preference.isReadOnly()));
-            }
+            DatabasePreference preference = preferences.next();
+            userPreferences.put(preference.getName(), new JetspeedPreferenceImpl(preference.getName(),
preference.getValues(), preference.isReadOnly()));
+        }
+        if (!enableSessionCache) {
             preferenceCache.put(preferenceCache.createElement(userCacheKey, userPreferences));
         }
         return userPreferences;
@@ -961,7 +968,25 @@ public class PortletPreferencesServiceIm
         if (result == null) {
             result = sessionPreferences.createWindowPreferences(window.getPortletEntityId());
         }
-        return result;
+        return clonePreferences(result);
+    }
+
+    protected Map<String,PortletPreference> clonePreferences(Map<String,PortletPreference>
original) {
+        Map<String,PortletPreference> clone = new HashMap<>();
+        for (Map.Entry<String,PortletPreference> entry : original.entrySet()) {
+            clone.put(entry.getKey(), entry.getValue().clone());
+        }
+        return clone;
+    }
+
+    protected void removeUserPreferencesFromSession() {
+        RequestContextComponent rcc = getRequestContextComponent();
+        if (rcc != null) {
+            RequestContext rc = rcc.getRequestContext();
+            if (rc != null) {
+                rc.getRequest().getSession(true).removeAttribute(SESSION_CACHE_KEY);
+            }
+        }
     }
 
     protected UserSessionPreferences getUserSessionPreferences() {
@@ -988,4 +1013,14 @@ public class PortletPreferencesServiceIm
         return requestContextComponent;
     }
 
+    @Override
+    public void sessionCreatedEvent(HttpSession session) {
+    }
+
+    @Override
+    public void sessionDestroyedEvent(HttpSession session) {
+        if (enableSessionCache && session != null) {
+            session.removeAttribute(SESSION_CACHE_KEY);
+        }
+    }
 }

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/UserManagerImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/UserManagerImpl.java?rev=1685182&r1=1685181&r2=1685182&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/UserManagerImpl.java
(original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/UserManagerImpl.java
Fri Jun 12 22:30:03 2015
@@ -16,6 +16,7 @@
  */
 package org.apache.jetspeed.security.impl;
 
+import org.apache.jetspeed.Jetspeed;
 import org.apache.jetspeed.components.portletpreferences.PortletPreferencesProvider;
 import org.apache.jetspeed.security.AuthenticatedUser;
 import org.apache.jetspeed.security.AuthenticatedUserImpl;
@@ -72,7 +73,6 @@ public class UserManagerImpl extends Bas
 	private RoleManager roleManager;
 	private GroupManager groupManager;
 	private Map<String, UserSubjectPrincipalsResolver> usprMap = new HashMap<String,
UserSubjectPrincipalsResolver>();
-	private PortletPreferencesProvider preferencesProvider = null;
 
 	public UserManagerImpl(JetspeedPrincipalType principalType, JetspeedPrincipalType roleType,
JetspeedPrincipalType groupType,
 			JetspeedPrincipalAccessManager jpam, JetspeedPrincipalStorageManager jpsm, UserPasswordCredentialManager
credentialManager)
@@ -83,17 +83,6 @@ public class UserManagerImpl extends Bas
 		this.groupType = groupType;
 	}
 
-	public UserManagerImpl(JetspeedPrincipalType principalType, JetspeedPrincipalType roleType,
JetspeedPrincipalType groupType,
-						   JetspeedPrincipalAccessManager jpam, JetspeedPrincipalStorageManager jpsm, UserPasswordCredentialManager
credentialManager,
-						   PortletPreferencesProvider preferencesProvider)
-	{
-		super(principalType, jpam, jpsm);
-		this.credentialManager = credentialManager;
-		this.roleType = roleType;
-		this.groupType = groupType;
-		this.preferencesProvider = preferencesProvider;
-	}
-
 	public void checkInitialized()
 	{
 		if (groupManager == null)
@@ -260,12 +249,22 @@ public class UserManagerImpl extends Bas
 		super.removePrincipal(user);
 
 		// Since 2.3.0
-		if (preferencesProvider != null) {
-			preferencesProvider.removeUserPreferences(username);
+		PortletPreferencesProvider provider = getPreferencesProvider();
+        if (provider != null) {
+			provider.removeUserPreferences(username);
 		}
 	}
-	
-	public void removePrincipal(String principalName) throws SecurityException
+
+    protected PortletPreferencesProvider getPreferencesProvider() {
+        try {
+            return Jetspeed.getComponentManager().lookupComponent("org.apache.jetspeed.components.portletpreferences.PortletPreferencesProvider");
+        }
+        catch (Exception e) {
+            return null;
+        }
+    }
+
+    public void removePrincipal(String principalName) throws SecurityException
 	{
 	    removeUser(principalName);
 	}

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/stubs/StubPortletPreferences.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/stubs/StubPortletPreferences.java?rev=1685182&r1=1685181&r2=1685182&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/stubs/StubPortletPreferences.java
(original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-security/src/test/java/org/apache/jetspeed/security/stubs/StubPortletPreferences.java
Fri Jun 12 22:30:03 2015
@@ -29,6 +29,7 @@ import org.apache.pluto.container.Portle
 import javax.portlet.PortletRequest;
 import javax.portlet.PreferencesValidator;
 import javax.portlet.ValidatorException;
+import javax.servlet.http.HttpSession;
 import java.util.Map;
 import java.util.Set;
 
@@ -152,4 +153,14 @@ public class StubPortletPreferences impl
     public PreferencesValidator getPreferencesValidator(org.apache.pluto.container.om.portlet.PortletDefinition
portletDefinition) throws ValidatorException {
         return null;
     }
+
+    @Override
+    public void sessionDestroyedEvent(HttpSession session) {
+
+    }
+
+    @Override
+    public void sessionCreatedEvent(HttpSession session) {
+
+    }
 }

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-sso/src/test/java/org/apache/jetspeed/sso/StubPortletPreferences.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-sso/src/test/java/org/apache/jetspeed/sso/StubPortletPreferences.java?rev=1685182&r1=1685181&r2=1685182&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-sso/src/test/java/org/apache/jetspeed/sso/StubPortletPreferences.java
(original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-sso/src/test/java/org/apache/jetspeed/sso/StubPortletPreferences.java
Fri Jun 12 22:30:03 2015
@@ -29,6 +29,7 @@ import org.apache.pluto.container.Portle
 import javax.portlet.PortletRequest;
 import javax.portlet.PreferencesValidator;
 import javax.portlet.ValidatorException;
+import javax.servlet.http.HttpSession;
 import java.util.Map;
 import java.util.Set;
 
@@ -152,4 +153,14 @@ public class StubPortletPreferences impl
     public PreferencesValidator getPreferencesValidator(org.apache.pluto.container.om.portlet.PortletDefinition
portletDefinition) throws ValidatorException {
         return null;
     }
+
+    @Override
+    public void sessionCreatedEvent(HttpSession session) {
+
+    }
+
+    @Override
+    public void sessionDestroyedEvent(HttpSession session) {
+
+    }
 }

Modified: portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/components/portletpreferences/PortletPreferencesProvider.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/components/portletpreferences/PortletPreferencesProvider.java?rev=1685182&r1=1685181&r2=1685182&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/components/portletpreferences/PortletPreferencesProvider.java
(original)
+++ portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/components/portletpreferences/PortletPreferencesProvider.java
Fri Jun 12 22:30:03 2015
@@ -24,6 +24,7 @@ import org.apache.jetspeed.om.portlet.Pr
 import org.apache.pluto.container.PortletPreference;
 import org.apache.pluto.container.PortletPreferencesService;
 
+import javax.servlet.http.HttpSession;
 import java.util.Map;
 import java.util.Set;
 
@@ -186,4 +187,7 @@ public interface PortletPreferencesProvi
      */
     public void removeUserPreferences(String user);
 
+    public void sessionCreatedEvent(HttpSession session);
+    public void sessionDestroyedEvent(HttpSession session);
+
 }

Modified: portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/security-managers.xml
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/security-managers.xml?rev=1685182&r1=1685181&r2=1685182&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/security-managers.xml
(original)
+++ portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/security-managers.xml
Fri Jun 12 22:30:03 2015
@@ -142,7 +142,6 @@
     <constructor-arg index="3" ref="org.apache.jetspeed.security.spi.JetspeedSecurityPersistenceManager"
/>
     <constructor-arg index="4" ref="org.apache.jetspeed.security.spi.JetspeedPrincipalStorageManager"
/>
     <constructor-arg index="5" ref="org.apache.jetspeed.security.spi.UserPasswordCredentialManager"
/>
-    <constructor-arg index="6" ref="org.apache.jetspeed.components.portletpreferences.PortletPreferencesProvider"/>
   </bean>
 
   <bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">



---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org


Mime
View raw message