Author: bdaw
Date: 2008-04-17 13:12:32 -0400 (Thu, 17 Apr 2008)
New Revision: 10623
Modified:
branches/JBoss_Portal_Branch_2_6/core-identity/src/main/org/jboss/portal/core/identity/ui/common/IdentityUserBean.java
Log:
- use cached current user instance in IdentityUserPortlet
Modified:
branches/JBoss_Portal_Branch_2_6/core-identity/src/main/org/jboss/portal/core/identity/ui/common/IdentityUserBean.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/core-identity/src/main/org/jboss/portal/core/identity/ui/common/IdentityUserBean.java 2008-04-17
13:51:42 UTC (rev 10622)
+++
branches/JBoss_Portal_Branch_2_6/core-identity/src/main/org/jboss/portal/core/identity/ui/common/IdentityUserBean.java 2008-04-17
17:12:32 UTC (rev 10623)
@@ -37,11 +37,16 @@
import org.jboss.portal.core.identity.services.IdentityConstants;
import org.jboss.portal.core.identity.services.metadata.UIComponentConfiguration;
import org.jboss.portal.core.identity.ui.IdentityUIUser;
+import org.jboss.portal.core.aspects.server.UserInterceptor;
+import org.jboss.portal.core.controller.ControllerContext;
import org.jboss.portal.identity.IdentityException;
import org.jboss.portal.identity.NoSuchUserException;
import org.jboss.portal.identity.User;
import org.jboss.portal.identity.UserModule;
import org.jboss.portal.identity.UserProfileModule;
+import org.jboss.portal.server.ServerInvocation;
+import org.jboss.portlet.JBossRenderRequest;
+import org.jboss.portlet.JBossActionRequest;
/**
* @author <a href="mailto:emuckenh@redhat.com">Emanuel
Muckenhuber</a>
@@ -193,8 +198,86 @@
public Object getUserProperty(String username, String propertyName) throws
IllegalArgumentException, NoSuchUserException, IdentityException
{
- User user = this.findUserByUserName(username);
+
UIComponentConfiguration uiComponent = (UIComponentConfiguration)
this.metaDataService.getValue(propertyName).getObject();
- return this.userProfileModule.getProperty(user, uiComponent.getPropertyRef());
+
+ Map profile = null;
+
+ // Uncomment this to use the cached profile (for now its not invalidated on write)
+ //profile = getCachedUserProfile();
+
+ if (profile == null)
+ {
+ User user = getCurrentUser();
+ if (user == null)
+ {
+ user = this.findUserByUserName(username);
+ }
+
+ return this.userProfileModule.getProperty(user, uiComponent.getPropertyRef());
+ }
+
+ return profile.get(uiComponent.getPropertyRef());
+
}
+
+ public User getCurrentUser()
+ {
+ Object request =
FacesContext.getCurrentInstance().getExternalContext().getRequest();
+
+ ControllerContext context = null;
+
+ if (request instanceof JBossRenderRequest)
+ {
+ JBossRenderRequest renderRequest = (JBossRenderRequest)request;
+ context = renderRequest.getControllerContext();
+ }
+ else if (request instanceof JBossActionRequest)
+ {
+ JBossActionRequest actionRequest = (JBossActionRequest)request;
+ context = actionRequest.getControllerContext();
+ }
+
+ if (context != null)
+ {
+ Object user = context.getAttribute(ServerInvocation.PRINCIPAL_SCOPE,
UserInterceptor.USER_KEY);
+ if (user instanceof User)
+ {
+ return (User)user;
+ }
+ }
+
+ return null;
+
+ }
+
+ public Map getCachedUserProfile()
+ {
+ Object request =
FacesContext.getCurrentInstance().getExternalContext().getRequest();
+
+ ControllerContext context = null;
+
+ if (request instanceof JBossRenderRequest)
+ {
+ JBossRenderRequest renderRequest = (JBossRenderRequest)request;
+ context = renderRequest.getControllerContext();
+ }
+ else if (request instanceof JBossActionRequest)
+ {
+ JBossActionRequest actionRequest = (JBossActionRequest)request;
+ context = actionRequest.getControllerContext();
+ }
+
+ if (context != null)
+ {
+ Object profile = context.getAttribute(ServerInvocation.PRINCIPAL_SCOPE,
UserInterceptor.PROFILE_KEY);
+ if (profile instanceof Map)
+ {
+ return (Map)profile;
+ }
+ }
+
+ return null;
+
+ }
}