gatein SVN: r1312 - portal/trunk/component/wsrp/src/main/java/org/gatein/portal/wsrp.
by do-not-reply@jboss.org
Author: chris.laprun(a)jboss.com
Date: 2010-01-15 06:42:30 -0500 (Fri, 15 Jan 2010)
New Revision: 1312
Added:
portal/trunk/component/wsrp/src/main/java/org/gatein/portal/wsrp/ActivatingFederatingPortletInvoker.java
Modified:
portal/trunk/component/wsrp/src/main/java/org/gatein/portal/wsrp/ExoKernelIntegration.java
Log:
- Added ActivatingFederatingPortletInvoker to have a second-level federation for remote invokers so that we can activate them on
demand instead of requiring ConsumerRegistry to push them to the top-level federating invoker (which would was currently done
manually).
Added: portal/trunk/component/wsrp/src/main/java/org/gatein/portal/wsrp/ActivatingFederatingPortletInvoker.java
===================================================================
--- portal/trunk/component/wsrp/src/main/java/org/gatein/portal/wsrp/ActivatingFederatingPortletInvoker.java (rev 0)
+++ portal/trunk/component/wsrp/src/main/java/org/gatein/portal/wsrp/ActivatingFederatingPortletInvoker.java 2010-01-15 11:42:30 UTC (rev 1312)
@@ -0,0 +1,294 @@
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2010, Red Hat Middleware, LLC, and individual
+ * contributors as indicated by the @authors tag. See the
+ * copyright.txt in the distribution for a full listing of
+ * individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.gatein.portal.wsrp;
+
+import org.gatein.pc.api.InvokerUnavailableException;
+import org.gatein.pc.api.NoSuchPortletException;
+import org.gatein.pc.api.Portlet;
+import org.gatein.pc.api.PortletContext;
+import org.gatein.pc.api.PortletInvoker;
+import org.gatein.pc.api.PortletInvokerException;
+import org.gatein.pc.api.PortletStateType;
+import org.gatein.pc.api.invocation.PortletInvocation;
+import org.gatein.pc.api.invocation.response.PortletInvocationResponse;
+import org.gatein.pc.api.state.DestroyCloneFailure;
+import org.gatein.pc.api.state.PropertyChange;
+import org.gatein.pc.api.state.PropertyMap;
+import org.gatein.pc.federation.FederatedPortletInvoker;
+import org.gatein.pc.federation.FederatingPortletInvoker;
+import org.gatein.pc.federation.impl.FederatedPortletInvokerService;
+import org.gatein.wsrp.WSRPConsumer;
+import org.gatein.wsrp.consumer.registry.ConsumerRegistry;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * TODO: This is a fork of the FederatingPortletInvokerService in the PC module to avoid having to create a new release.
+ * Once PC 2.1.0.CR03 or above is release, revisit and clean up. The only thing that is really needed here is a
+ * different implementation of {@link #getFederatedPortletInvokerFor(org.gatein.pc.api.PortletContext)}.
+ *
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris Laprun</a>
+ * @version $Revision$
+ */
+public class ActivatingFederatingPortletInvoker implements FederatingPortletInvoker /*extends FederatingPortletInvokerService*/
+{
+
+ /** The separator used in the id to route to the correct invoker. */
+ static final String SEPARATOR = ".";
+
+ /** The registred FederatedPortletInvokers. */
+ private volatile Map<String, FederatedPortletInvoker> registry = new HashMap<String, FederatedPortletInvoker>();
+ private transient ConsumerRegistry consumerRegistry;
+
+ public synchronized FederatedPortletInvoker registerInvoker(String federatedId, PortletInvoker federatedInvoker)
+ {
+ if (federatedId == null)
+ {
+ throw new IllegalArgumentException("No null id");
+ }
+ if (federatedInvoker == null)
+ {
+ throw new IllegalArgumentException("No null invoker");
+ }
+ if (registry.containsKey(federatedId))
+ {
+ throw new IllegalArgumentException("Attempting dual registration of " + federatedId);
+ }
+ Map<String, FederatedPortletInvoker> copy = new HashMap<String, FederatedPortletInvoker>(registry);
+ FederatedPortletInvokerService invoker = new FederatedPortletInvokerService(this, federatedId, federatedInvoker);
+ copy.put(federatedId, invoker);
+ registry = copy;
+ return invoker;
+ }
+
+ public synchronized void unregisterInvoker(String federatedId)
+ {
+ if (federatedId == null)
+ {
+ throw new IllegalArgumentException("No null id accepted");
+ }
+ if (!registry.containsKey(federatedId))
+ {
+ throw new IllegalArgumentException("Attempting to unregister unknown invoker " + federatedId);
+ }
+ Map<String, FederatedPortletInvoker> copy = new HashMap<String, FederatedPortletInvoker>(registry);
+ copy.remove(federatedId);
+ registry = copy;
+ }
+
+ public FederatedPortletInvoker getFederatedInvoker(String federatedId) throws IllegalArgumentException
+ {
+ if (federatedId == null)
+ {
+ throw new IllegalArgumentException("No null id provided");
+ }
+ return registry.get(federatedId);
+ }
+
+ public Collection<FederatedPortletInvoker> getFederatedInvokers()
+ {
+ return registry.values();
+ }
+
+ // PortletInvoker implementation ************************************************************************************
+
+ public Set<Portlet> getPortlets() throws PortletInvokerException
+ {
+ return getPortlets(false);
+ }
+
+ private Set<Portlet> getPortlets(boolean remoteOnly) throws PortletInvokerException
+ {
+ LinkedHashSet<Portlet> portlets = new LinkedHashSet<Portlet>();
+ for (FederatedPortletInvoker federated : registry.values())
+ {
+ // if we're only interested in remote portlets, skip the local invoker.
+ if (remoteOnly && LOCAL_PORTLET_INVOKER_ID.equals(federated.getId()))
+ {
+ continue;
+ }
+
+ try
+ {
+ Set<Portlet> offeredPortlets = federated.getPortlets();
+ portlets.addAll(offeredPortlets);
+ }
+ catch (InvokerUnavailableException e)
+ {
+ e.printStackTrace();
+ }
+ }
+ return portlets;
+ }
+
+ public Set<Portlet> getLocalPortlets() throws PortletInvokerException
+ {
+ PortletInvoker local = registry.get(PortletInvoker.LOCAL_PORTLET_INVOKER_ID);
+
+ return local.getPortlets();
+ }
+
+ public Set<Portlet> getRemotePortlets() throws PortletInvokerException
+ {
+ return getPortlets(true);
+ }
+
+ public Portlet getPortlet(PortletContext compoundPortletContext) throws IllegalArgumentException, PortletInvokerException
+ {
+ FederatedPortletInvoker federated = getFederatedPortletInvokerFor(compoundPortletContext);
+ return federated.getPortlet(compoundPortletContext);
+ }
+
+ public PortletInvocationResponse invoke(PortletInvocation invocation) throws PortletInvokerException
+ {
+ PortletContext compoundPortletContext = invocation.getTarget();
+ FederatedPortletInvoker federated = getFederatedPortletInvokerFor(compoundPortletContext);
+ return federated.invoke(invocation);
+ }
+
+ public PortletContext createClone(PortletStateType stateType, PortletContext compoundPortletContext) throws PortletInvokerException
+ {
+ FederatedPortletInvoker federated = getFederatedPortletInvokerFor(compoundPortletContext);
+ return federated.createClone(stateType, compoundPortletContext);
+ }
+
+ public List<DestroyCloneFailure> destroyClones(List<PortletContext> portletContexts) throws IllegalArgumentException, PortletInvokerException, UnsupportedOperationException
+ {
+ if (portletContexts == null)
+ {
+ throw new IllegalArgumentException("No null list accepted");
+ }
+ if (portletContexts.size() == 0)
+ {
+ return Collections.emptyList();
+ }
+
+ // Get the invoker and check that we address only one invoker (for now)
+ FederatedPortletInvoker invoker = null;
+ for (PortletContext compoundPortletContext : portletContexts)
+ {
+ FederatedPortletInvoker federated = getFederatedPortletInvokerFor(compoundPortletContext);
+ if (invoker == null)
+ {
+ invoker = federated;
+ }
+ else if (!invoker.equals(federated))
+ {
+ throw new PortletInvokerException("Cannot destroy portlet lists that requires more than one federated invoker");
+ }
+ }
+
+ //
+ return invoker.destroyClones(portletContexts);
+ }
+
+ public PropertyMap getProperties(PortletContext compoundPortletContext, Set<String> keys) throws PortletInvokerException
+ {
+ FederatedPortletInvoker federated = getFederatedPortletInvokerFor(compoundPortletContext);
+ return federated.getProperties(compoundPortletContext, keys);
+ }
+
+ public PropertyMap getProperties(PortletContext compoundPortletContext) throws PortletInvokerException
+ {
+ FederatedPortletInvoker federated = getFederatedPortletInvokerFor(compoundPortletContext);
+ return federated.getProperties(compoundPortletContext);
+ }
+
+ public PortletContext setProperties(PortletContext compoundPortletContext, PropertyChange[] changes) throws IllegalArgumentException, PortletInvokerException, UnsupportedOperationException
+ {
+ FederatedPortletInvoker federated = getFederatedPortletInvokerFor(compoundPortletContext);
+ return federated.setProperties(compoundPortletContext, changes);
+ }
+
+ // Support methods **************************************************************************************************
+
+ /**
+ * Retrieves the portlet invoker associated with the specified compound portlet id or null if it is not found.
+ *
+ * @param compoundPortletContext the portlet context for which the invoker is to be retrieved
+ * @return the portlet invoker associated with the specified compound portlet id
+ * @throws IllegalArgumentException if the compound portlet id is not well formed or null
+ * @throws org.gatein.pc.api.NoSuchPortletException
+ * if not such portlet exist
+ */
+ private FederatedPortletInvoker getFederatedPortletInvokerFor(PortletContext compoundPortletContext) throws IllegalArgumentException, NoSuchPortletException
+ {
+ if (compoundPortletContext == null)
+ {
+ throw new IllegalArgumentException("No null portlet id accepted");
+ }
+
+ //
+ String compoundPortletId = compoundPortletContext.getId();
+
+ //
+ int pos = compoundPortletId.indexOf(SEPARATOR);
+ if (pos == -1)
+ {
+ throw new IllegalArgumentException("Bad portlet id format " + compoundPortletId);
+ }
+
+ //
+ String invokerId = compoundPortletId.substring(0, pos);
+ FederatedPortletInvoker federated = registry.get(invokerId);
+
+ // if we didn't find the invoker, ask the ConsumerRegistry�
+ if (federated == null)
+ {
+ WSRPConsumer consumer = consumerRegistry.getConsumer(invokerId);
+
+ // if there's no consumer with that invoker id, then there's nothing much we can do
+ if (consumer == null)
+ {
+ throw new NoSuchPortletException(compoundPortletId);
+ }
+ else
+ {
+ // activate the consumer which should register it with this FederatingPortletInvoker
+ consumerRegistry.activateConsumerWith(invokerId);
+
+ federated = getFederatedInvoker(invokerId);
+ }
+ }
+
+ //
+ return federated;
+ }
+
+ public void setConsumerRegistry(ConsumerRegistry consumerRegistry)
+ {
+ if (consumerRegistry.getFederatingPortletInvoker() != this)
+ {
+ throw new IllegalArgumentException("Trying to use a ConsumerRegistry already linked to another FederatingPortletInvoker");
+ }
+
+ this.consumerRegistry = consumerRegistry;
+ }
+}
Modified: portal/trunk/component/wsrp/src/main/java/org/gatein/portal/wsrp/ExoKernelIntegration.java
===================================================================
--- portal/trunk/component/wsrp/src/main/java/org/gatein/portal/wsrp/ExoKernelIntegration.java 2010-01-15 10:55:37 UTC (rev 1311)
+++ portal/trunk/component/wsrp/src/main/java/org/gatein/portal/wsrp/ExoKernelIntegration.java 2010-01-15 11:42:30 UTC (rev 1312)
@@ -1,6 +1,6 @@
/*
* JBoss, a division of Red Hat
- * Copyright 2009, Red Hat Middleware, LLC, and individual
+ * Copyright 2010, Red Hat Middleware, LLC, and individual
* contributors as indicated by the @authors tag. See the
* copyright.txt in the distribution for a full listing of
* individual contributors.
@@ -74,6 +74,7 @@
private final String consumersConfigLocation;
private ConsumerRegistry consumerRegistry;
+ private static final String REMOTE_INVOKERS_INVOKER_ID = "remote";
public ExoKernelIntegration(InitParams params, ConfigurationManager configurationManager,
org.exoplatform.portal.pc.ExoKernelIntegration pc) throws Exception
@@ -118,11 +119,10 @@
}
container.registerComponentInstance(ProducerConfigurationService.class, producerConfigurationService);
- RegistrationPersistenceManager registrationPersistenceManager = null;
+ RegistrationPersistenceManager registrationPersistenceManager;
try
{
registrationPersistenceManager = new JCRRegistrationPersistenceManager(container);
-// registrationPersistenceManager = new RegistrationPersistenceManagerImpl();
}
catch (Exception e)
{
@@ -173,12 +173,19 @@
FederatingPortletInvoker federatingPortletInvoker =
(FederatingPortletInvoker)container.getComponentInstanceOfType(PortletInvoker.class);
+ // set up a second level federating portlet invoker so that when a remote producer is queried, we can start it if needed
+ ActivatingFederatingPortletInvoker remoteInvokers = new ActivatingFederatingPortletInvoker();
+ federatingPortletInvoker.registerInvoker(REMOTE_INVOKERS_INVOKER_ID, remoteInvokers);
+
try
{
consumerRegistry = new JCRConsumerRegistry(container);
- consumerRegistry.setFederatingPortletInvoker(federatingPortletInvoker);
+ consumerRegistry.setFederatingPortletInvoker(remoteInvokers);
consumerRegistry.setSessionEventBroadcaster(new SimpleSessionEventBroadcaster());
consumerRegistry.start();
+
+ // set the consumer registry on the second level federating invoker
+ remoteInvokers.setConsumerRegistry(consumerRegistry);
}
catch (Exception e)
{
14 years, 11 months
gatein SVN: r1311 - portal/trunk/component/portal/src/main/java/org/exoplatform/portal/config.
by do-not-reply@jboss.org
Author: chris.laprun(a)jboss.com
Date: 2010-01-15 05:55:37 -0500 (Fri, 15 Jan 2010)
New Revision: 1311
Modified:
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/config/UserPortalConfigService.java
Log:
- Remove System.out output.
Modified: portal/trunk/component/portal/src/main/java/org/exoplatform/portal/config/UserPortalConfigService.java
===================================================================
--- portal/trunk/component/portal/src/main/java/org/exoplatform/portal/config/UserPortalConfigService.java 2010-01-15 10:45:53 UTC (rev 1310)
+++ portal/trunk/component/portal/src/main/java/org/exoplatform/portal/config/UserPortalConfigService.java 2010-01-15 10:55:37 UTC (rev 1311)
@@ -1,16 +1,16 @@
/**
* Copyright (C) 2009 eXo Platform SAS.
- *
+ *
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
- *
+ *
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
@@ -26,13 +26,13 @@
import org.exoplatform.container.component.RequestLifeCycle;
import org.exoplatform.portal.config.model.Application;
import org.exoplatform.portal.config.model.Container;
-import org.exoplatform.portal.pom.data.ModelChange;
import org.exoplatform.portal.config.model.ModelObject;
import org.exoplatform.portal.config.model.Page;
import org.exoplatform.portal.config.model.PageNavigation;
import org.exoplatform.portal.config.model.PageNode;
import org.exoplatform.portal.config.model.PortalConfig;
import org.exoplatform.portal.config.model.TransientApplicationState;
+import org.exoplatform.portal.pom.data.ModelChange;
import org.exoplatform.services.listener.ListenerService;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
@@ -49,8 +49,8 @@
import java.util.Set;
/**
- * Created by The eXo Platform SAS Apr 19, 2007 This service is used to load the
- * PortalConfig, Page config and Navigation config for a given user.
+ * Created by The eXo Platform SAS Apr 19, 2007 This service is used to load the PortalConfig, Page config and
+ * Navigation config for a given user.
*/
public class UserPortalConfigService implements Startable
{
@@ -93,32 +93,22 @@
}
/**
- * <p>
- * Build and returns an instance of <tt>UserPortalConfig</tt>.
- * </p>
- *
- * <p>
- * To return a valid config, the current thread must be associated with an
- * identity that will grant him access to the portal as returned by the
- * {@link UserACL#hasPermission(org.exoplatform.portal.config.model.PortalConfig)}
- * method.
- * </p>
- *
- * <p>
- * The navigation loaded on the
- * <tt>UserPortalConfig<tt> object are obtained according to the specified user
+ * <p> Build and returns an instance of <tt>UserPortalConfig</tt>. </p>
+ * <p/>
+ * <p> To return a valid config, the current thread must be associated with an identity that will grant him access to
+ * the portal as returned by the {@link UserACL#hasPermission(org.exoplatform.portal.config.model.PortalConfig)}
+ * method. </p>
+ * <p/>
+ * <p> The navigation loaded on the <tt>UserPortalConfig<tt> object are obtained according to the specified user
* argument. The portal navigation is always loaded. If the specified user is null then the navigation of the guest
* group as configured by {@link org.exoplatform.portal.config.UserACL#getGuestsGroup()} is also loaded, otherwise
* the navigations are loaded according to the following rules:
- *
- * <ul>
- * <li>The navigation corresponding to the user is loaded.</li>
- * <li>When the user is root according to the value returned by {@link org.exoplatform.portal.config.UserACL#getSuperUser()}
- * then the navigation of all groups are loaded.</li>
- * <li>When the user is not root, then all its groups are added except the guest group as configued per
- * {@link org.exoplatform.portal.config.UserACL#getGuestsGroup()}.</li>
- * </ul>
- *
+ * <p/>
+ * <ul> <li>The navigation corresponding to the user is loaded.</li> <li>When the user is root according to the value
+ * returned by {@link org.exoplatform.portal.config.UserACL#getSuperUser()} then the navigation of all groups are
+ * loaded.</li> <li>When the user is not root, then all its groups are added except the guest group as configued per
+ * {@link org.exoplatform.portal.config.UserACL#getGuestsGroup()}.</li> </ul>
+ * <p/>
* All the navigations are sorted using the value returned by {@link org.exoplatform.portal.config.model.PageNavigation#getPriority()}.
* </p>
*
@@ -131,7 +121,9 @@
{
PortalConfig portal = storage_.getPortalConfig(portalName);
if (portal == null || !userACL_.hasPermission(portal))
+ {
return null;
+ }
List<PageNavigation> navigations = new ArrayList<PageNavigation>();
PageNavigation navigation = getPageNavigation(PortalConfig.PORTAL_TYPE, portalName);
@@ -159,18 +151,26 @@
Collection<?> groups = null;
if (userACL_.getSuperUser().equals(accessUser))
+ {
groups = orgService_.getGroupHandler().getAllGroups();
+ }
else
+ {
groups = orgService_.getGroupHandler().findGroupsOfUser(accessUser);
+ }
for (Object group : groups)
{
Group m = (Group)group;
String groupId = m.getId().trim();
if (groupId.equals(userACL_.getGuestsGroup()))
+ {
continue;
+ }
navigation = getPageNavigation(PortalConfig.GROUP_TYPE, groupId);
if (navigation == null)
+ {
continue;
+ }
navigation.setModifiable(userACL_.hasEditPermission(navigation));
navigations.add(navigation);
}
@@ -187,26 +187,26 @@
}
/**
- * Compute and returns the list that the specified user can manage. If the
- * user is root then all existing groups are returned otherwise the list is
- * computed from the groups in which the user has a configured membership.
- * The membership is configured from the value returned by
- * {@link org.exoplatform.portal.config.UserACL#getMakableMT()}
- *
- * @param remoteUser
- * the user to get the makable navigations
+ * Compute and returns the list that the specified user can manage. If the user is root then all existing groups are
+ * returned otherwise the list is computed from the groups in which the user has a configured membership. The
+ * membership is configured from the value returned by {@link org.exoplatform.portal.config.UserACL#getMakableMT()}
+ *
+ * @param remoteUser the user to get the makable navigations
* @return the list of groups
- * @throws Exception
- * any exception
+ * @throws Exception any exception
*/
public List<String> getMakableNavigations(String remoteUser) throws Exception
{
List<String> list = new ArrayList<String>();
Collection<?> groups = null;
if (remoteUser.equals(userACL_.getSuperUser()))
+ {
groups = orgService_.getGroupHandler().getAllGroups();
+ }
else
+ {
groups = orgService_.getGroupHandler().findGroupByMembership(remoteUser, userACL_.getMakableMT());
+ }
if (groups != null)
{
for (Object group : groups)
@@ -220,15 +220,11 @@
}
/**
- * This method should create a the portal config, pages and navigation
- * according to the template name.
- *
- * @param portalName
- * the portal name
- * @param template
- * the template to use
- * @throws Exception
- * any exception
+ * This method should create a the portal config, pages and navigation according to the template name.
+ *
+ * @param portalName the portal name
+ * @param template the template to use
+ * @throws Exception any exception
*/
public void createUserPortalConfig(String ownerType, String portalName, String template) throws Exception
{
@@ -247,13 +243,10 @@
}
/**
- * This method removes the PortalConfig, Page and PageNavigation that belong
- * to the portal in the database.
- *
- * @param portalName
- * the portal name
- * @throws Exception
- * any exception
+ * This method removes the PortalConfig, Page and PageNavigation that belong to the portal in the database.
+ *
+ * @param portalName the portal name
+ * @throws Exception any exception
*/
public void removeUserPortalConfig(String portalName) throws Exception
{
@@ -261,15 +254,11 @@
}
/**
- * This method removes the PortalConfig, Page and PageNavigation that belong
- * to the portal in the database.
- *
- * @param ownerType
- * the owner type
- * @param ownerId
- * the portal name
- * @throws Exception
- * any exception
+ * This method removes the PortalConfig, Page and PageNavigation that belong to the portal in the database.
+ *
+ * @param ownerType the owner type
+ * @param ownerId the portal name
+ * @throws Exception any exception
*/
public void removeUserPortalConfig(String ownerType, String ownerId) throws Exception
{
@@ -282,7 +271,7 @@
/**
* This method should update the PortalConfig object
- *
+ *
* @param portal
* @throws Exception
*/
@@ -293,34 +282,29 @@
/**
* This method load the page according to the pageId and returns.
- *
- * @param pageId
- * the page id
+ *
+ * @param pageId the page id
* @return the page
- * @throws Exception
- * any exception
+ * @throws Exception any exception
*/
public Page getPage(String pageId) throws Exception
{
if (pageId == null)
+ {
return null;
+ }
return storage_.getPage(pageId); // TODO: pageConfigCache_ needs to be
}
/**
- * This method load the page according to the pageId and returns it if the
- * current thread is associated with an identity that allows to view the page
- * according to the
- * {@link UserACL#hasPermission(org.exoplatform.portal.config.model.Page)}
+ * This method load the page according to the pageId and returns it if the current thread is associated with an
+ * identity that allows to view the page according to the {@link UserACL#hasPermission(org.exoplatform.portal.config.model.Page)}
* method.
- *
- * @param pageId
- * the page id
- * @param accessUser
- * never used
+ *
+ * @param pageId the page id
+ * @param accessUser never used
* @return the page
- * @throws Exception
- * any exception
+ * @throws Exception any exception
*/
public Page getPage(String pageId, String accessUser) throws Exception
{
@@ -333,14 +317,11 @@
}
/**
- * Removes a page and broadcast an event labelled as
- * {@link org.exoplatform.portal.config.UserPortalConfigService#REMOVE_PAGE_EVENT}
+ * Removes a page and broadcast an event labelled as {@link org.exoplatform.portal.config.UserPortalConfigService#REMOVE_PAGE_EVENT}
* when the removal is successful.
- *
- * @param page
- * the page to remove
- * @throws Exception
- * any exception
+ *
+ * @param page the page to remove
+ * @throws Exception any exception
*/
public void remove(Page page) throws Exception
{
@@ -349,14 +330,11 @@
}
/**
- * Creates a page and broadcast an event labelled as
- * {@link org.exoplatform.portal.config.UserPortalConfigService#CREATE_PAGE_EVENT}
+ * Creates a page and broadcast an event labelled as {@link org.exoplatform.portal.config.UserPortalConfigService#CREATE_PAGE_EVENT}
* when the creation is successful.
- *
- * @param page
- * the page to create
- * @throws Exception
- * any exception
+ *
+ * @param page the page to create
+ * @throws Exception any exception
*/
public void create(Page page) throws Exception
{
@@ -367,19 +345,15 @@
}
/**
- * Updates a page and broadcast an event labelled as
- * {@link org.exoplatform.portal.config.UserPortalConfigService#UPDATE_PAGE_EVENT}
+ * Updates a page and broadcast an event labelled as {@link org.exoplatform.portal.config.UserPortalConfigService#UPDATE_PAGE_EVENT}
* when the creation is successful.
- *
- * @param page
- * the page to update
+ *
+ * @param page the page to update
* @return the list of model changes that occured
- * @throws Exception
- * any exception
+ * @throws Exception any exception
*/
public List<ModelChange> update(Page page) throws Exception
{
- System.out.println("\n\n\n show max window : " + page.isShowMaxWindow() + "\n\n");
List<ModelChange> changes = storage_.save(page);
//
@@ -388,14 +362,11 @@
}
/**
- * Creates a navigation and broadcast an event labelled as
- * {@link org.exoplatform.portal.config.UserPortalConfigService#CREATE_NAVIGATION_EVENT}
+ * Creates a navigation and broadcast an event labelled as {@link org.exoplatform.portal.config.UserPortalConfigService#CREATE_NAVIGATION_EVENT}
* when the creation is successful.
- *
- * @param navigation
- * the navigation to create
- * @throws Exception
- * any exception
+ *
+ * @param navigation the navigation to create
+ * @throws Exception any exception
*/
public void create(PageNavigation navigation) throws Exception
{
@@ -404,14 +375,11 @@
}
/**
- * Updates a page navigation broadcast an event labelled as
- * {@link org.exoplatform.portal.config.UserPortalConfigService#UPDATE_NAVIGATION_EVENT}
+ * Updates a page navigation broadcast an event labelled as {@link org.exoplatform.portal.config.UserPortalConfigService#UPDATE_NAVIGATION_EVENT}
* when the creation is successful.
- *
- * @param navigation
- * the navigation to update
- * @throws Exception
- * any exception
+ *
+ * @param navigation the navigation to update
+ * @throws Exception any exception
*/
public void update(PageNavigation navigation) throws Exception
{
@@ -420,14 +388,11 @@
}
/**
- * Removes a navigation and broadcast an event labelled as
- * {@link org.exoplatform.portal.config.UserPortalConfigService#REMOVE_NAVIGATION_EVENT}
+ * Removes a navigation and broadcast an event labelled as {@link org.exoplatform.portal.config.UserPortalConfigService#REMOVE_NAVIGATION_EVENT}
* when the removal is successful.
- *
- * @param navigation
- * the navigation to remove
- * @throws Exception
- * any exception
+ *
+ * @param navigation the navigation to remove
+ * @throws Exception any exception
*/
public void remove(PageNavigation navigation) throws Exception
{
@@ -442,9 +407,8 @@
}
/**
- * This method creates new page from an existing page and links new page to a
- * PageNode.
- *
+ * This method creates new page from an existing page and links new page to a PageNode.
+ *
* @param nodeName
* @param nodeLabel
* @param pageId
@@ -454,12 +418,14 @@
* @throws Exception
*/
public PageNode createNodeFromPageTemplate(String nodeName, String nodeLabel, String pageId, String ownerType,
- String ownerId) throws Exception
+ String ownerId) throws Exception
{
Page page = renewPage(pageId, nodeName, ownerType, ownerId);
PageNode pageNode = new PageNode();
if (nodeLabel == null || nodeLabel.trim().length() < 1)
+ {
nodeLabel = nodeName;
+ }
pageNode.setName(nodeName);
pageNode.setLabel(nodeLabel);
pageNode.setPageReference(page.getPageId());
@@ -468,18 +434,13 @@
/**
* Clones a page.
- *
- * @param pageId
- * the id of the page to clone
- * @param pageName
- * the new page name
- * @param ownerType
- * the new page owner type
- * @param ownerId
- * the new page owner id
+ *
+ * @param pageId the id of the page to clone
+ * @param pageName the new page name
+ * @param ownerType the new page owner type
+ * @param ownerId the new page owner id
* @return the newly created page
- * @throws Exception
- * any exception
+ * @throws Exception any exception
*/
public Page renewPage(String pageId, String pageName, String ownerType, String ownerId) throws Exception
{
@@ -488,16 +449,12 @@
/**
* Creates a page from an existing template.
- *
- * @param temp
- * the template name
- * @param ownerType
- * the new owner type
- * @param ownerId
- * the new owner id
+ *
+ * @param temp the template name
+ * @param ownerType the new owner type
+ * @param ownerId the new owner id
* @return the page
- * @throws Exception
- * any exception
+ * @throws Exception any exception
*/
public Page createPageTemplate(String temp, String ownerType, String ownerId) throws Exception
{
@@ -508,10 +465,9 @@
/**
* Load all navigation that user has edit permission.
- *
+ *
* @return the navigation the user can edit
- * @throws Exception
- * any exception
+ * @throws Exception any exception
*/
public List<PageNavigation> loadEditableNavigations() throws Exception
{
@@ -538,10 +494,9 @@
/**
* Returns the list of group ids having navigation.
- *
+ *
* @return the group id having navigation
- * @throws Exception
- * any exception
+ * @throws Exception any exception
*/
public Set<String> findGroupHavingNavigation() throws Exception
{
@@ -557,10 +512,9 @@
/**
* Returns the list of all portal names.
- *
+ *
* @return the list of all portal names
- * @throws Exception
- * any exception
+ * @throws Exception any exception
*/
public List<String> getAllPortalNames() throws Exception
{
@@ -580,13 +534,10 @@
/**
* Update the ownership recursively on the model graph.
- *
- * @param object
- * the model object graph root
- * @param ownerType
- * the new owner type
- * @param ownerId
- * the new owner id
+ *
+ * @param object the model object graph root
+ * @param ownerType the new owner type
+ * @param ownerId the new owner id
*/
private void updateOwnership(ModelObject object, String ownerType, String ownerId)
{
@@ -640,7 +591,9 @@
try
{
if (newPortalConfigListener_ == null)
+ {
return;
+ }
//
RequestLifeCycle.begin(PortalContainer.getInstance());
14 years, 11 months
gatein SVN: r1310 - in portal/trunk/webui/core/src: main/java/org/exoplatform/webui/application/replication/model and 2 other directories.
by do-not-reply@jboss.org
Author: julien_viet
Date: 2010-01-15 05:45:53 -0500 (Fri, 15 Jan 2010)
New Revision: 1310
Added:
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/model/ReplicatableTypeModel.java
Removed:
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/model/ClassTypeModel.java
Modified:
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/SerializationContext.java
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/model/TypeDomain.java
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/serial/ObjectReader.java
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/serial/ObjectWriter.java
portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/D.java
portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/TestSerialization.java
portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/TestTypeModel.java
Log:
- do not serialize static fields
Modified: portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/SerializationContext.java
===================================================================
--- portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/SerializationContext.java 2010-01-15 10:13:34 UTC (rev 1309)
+++ portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/SerializationContext.java 2010-01-15 10:45:53 UTC (rev 1310)
@@ -100,4 +100,20 @@
ObjectReader in = new ObjectReader(this, bais);
return (O)in.readObject();
}
+
+ public byte[] write(Object o) throws IOException
+ {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectWriter writer = new ObjectWriter(this, baos);
+ writer.writeObject(o);
+ writer.close();
+ return baos.toByteArray();
+ }
+
+ public Object read(byte[] bytes) throws IOException, ClassNotFoundException
+ {
+ ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
+ ObjectReader in = new ObjectReader(this, bais);
+ return in.readObject();
+ }
}
Deleted: portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/model/ClassTypeModel.java
===================================================================
--- portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/model/ClassTypeModel.java 2010-01-15 10:13:34 UTC (rev 1309)
+++ portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/model/ClassTypeModel.java 2010-01-15 10:45:53 UTC (rev 1310)
@@ -1,78 +0,0 @@
-/*
- * Copyright (C) 2009 eXo Platform SAS.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.exoplatform.webui.application.replication.model;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Map;
-
-/**
- * @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a>
- * @version $Revision$
- */
-public final class ClassTypeModel<O> extends TypeModel
-{
-
- /** . */
- private final Class<O> objectType;
-
- /** . */
- private final TypeModel superType;
-
- /** . */
- private final Map<String, FieldModel> fields;
-
- /** . */
- private final Map<String, FieldModel> immutableFields;
-
- ClassTypeModel(
- Class<O> javaType,
- TypeModel superType,
- Map<String, FieldModel> fields)
- {
- super(javaType);
-
- //
- this.objectType = javaType;
- this.superType = superType;
- this.fields = fields;
- this.immutableFields = Collections.unmodifiableMap(fields);
- }
-
- public Class<O> getObjectType()
- {
- return objectType;
- }
-
- public TypeModel getSuperType()
- {
- return superType;
- }
-
- public Collection<FieldModel> getFields()
- {
- return immutableFields.values();
- }
-
- public Map<String, FieldModel> getFieldMap()
- {
- return immutableFields;
- }
-}
Copied: portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/model/ReplicatableTypeModel.java (from rev 1303, portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/model/ClassTypeModel.java)
===================================================================
--- portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/model/ReplicatableTypeModel.java (rev 0)
+++ portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/model/ReplicatableTypeModel.java 2010-01-15 10:45:53 UTC (rev 1310)
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.exoplatform.webui.application.replication.model;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+public final class ReplicatableTypeModel<O> extends TypeModel
+{
+
+ /** . */
+ private final Class<O> objectType;
+
+ /** . */
+ private final TypeModel superType;
+
+ /** . */
+ private final Map<String, FieldModel> fields;
+
+ /** . */
+ private final Map<String, FieldModel> immutableFields;
+
+ ReplicatableTypeModel(
+ Class<O> javaType,
+ TypeModel superType,
+ Map<String, FieldModel> fields)
+ {
+ super(javaType);
+
+ //
+ this.objectType = javaType;
+ this.superType = superType;
+ this.fields = fields;
+ this.immutableFields = Collections.unmodifiableMap(fields);
+ }
+
+ public Class<O> getObjectType()
+ {
+ return objectType;
+ }
+
+ public TypeModel getSuperType()
+ {
+ return superType;
+ }
+
+ public Collection<FieldModel> getFields()
+ {
+ return immutableFields.values();
+ }
+
+ public Map<String, FieldModel> getFieldMap()
+ {
+ return immutableFields;
+ }
+}
Modified: portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/model/TypeDomain.java
===================================================================
--- portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/model/TypeDomain.java 2010-01-15 10:13:34 UTC (rev 1309)
+++ portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/model/TypeDomain.java 2010-01-15 10:45:53 UTC (rev 1310)
@@ -23,6 +23,7 @@
import java.io.Serializable;
import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
import java.util.*;
/**
@@ -119,12 +120,15 @@
{
return buildSerializable(javaType, addedTypeModels);
}
- return null;
+ else
+ {
+ return null;
+ }
}
- private <O> ClassTypeModel<O> buildClassTypeModel(Class<O> javaType, Map<String, TypeModel> addedTypeModels)
+ private <O> ReplicatableTypeModel<O> buildClassTypeModel(Class<O> javaType, Map<String, TypeModel> addedTypeModels)
{
- ClassTypeModel typeModel = (ClassTypeModel) get(javaType, addedTypeModels);
+ ReplicatableTypeModel typeModel = (ReplicatableTypeModel) get(javaType, addedTypeModels);
if (typeModel == null)
{
TypeModel superTypeModel = null;
@@ -141,7 +145,7 @@
TreeMap<String, FieldModel> fieldModels = new TreeMap<String, FieldModel>();
//
- typeModel = new ClassTypeModel<O>(javaType, superTypeModel, fieldModels);
+ typeModel = new ReplicatableTypeModel<O>(javaType, superTypeModel, fieldModels);
//
addedTypeModels.put(javaType.getName(), typeModel);
@@ -149,18 +153,21 @@
// Now build fields
for (Field field : javaType.getDeclaredFields())
{
- field.setAccessible(true);
- Class<?> fieldJavaType = field.getType();
- TypeModel fieldTypeModel = build(fieldJavaType, addedTypeModels);
- if (fieldTypeModel != null)
+ if (!Modifier.isStatic(field.getModifiers()))
{
- fieldModels.put(field.getName(), new FieldModel(field, fieldTypeModel));
+ field.setAccessible(true);
+ Class<?> fieldJavaType = field.getType();
+ TypeModel fieldTypeModel = build(fieldJavaType, addedTypeModels);
+ if (fieldTypeModel != null)
+ {
+ fieldModels.put(field.getName(), new FieldModel(field, fieldTypeModel));
+ }
}
}
}
// It must be good
- return (ClassTypeModel<O>)typeModel;
+ return (ReplicatableTypeModel<O>)typeModel;
}
private SerializableTypeModel buildSerializable(Class<?> javaType, Map<String, TypeModel> addedTypeModels)
Modified: portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/serial/ObjectReader.java
===================================================================
--- portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/serial/ObjectReader.java 2010-01-15 10:13:34 UTC (rev 1309)
+++ portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/serial/ObjectReader.java 2010-01-15 10:45:53 UTC (rev 1310)
@@ -21,7 +21,7 @@
import org.exoplatform.webui.application.replication.SerializationContext;
import org.exoplatform.webui.application.replication.factory.ObjectFactory;
-import org.exoplatform.webui.application.replication.model.ClassTypeModel;
+import org.exoplatform.webui.application.replication.model.ReplicatableTypeModel;
import org.exoplatform.webui.application.replication.model.FieldModel;
import org.exoplatform.webui.application.replication.model.TypeModel;
@@ -57,7 +57,7 @@
this.idToResolutions = new HashMap<Integer, List<Resolution>>();
}
- private <O> O instantiate(ClassTypeModel<O> typeModel, Map<FieldModel, ?> state) throws InvalidClassException
+ private <O> O instantiate(ReplicatableTypeModel<O> typeModel, Map<FieldModel, ?> state) throws InvalidClassException
{
try
{
@@ -97,11 +97,11 @@
id = container.readInt();
Class clazz = (Class) container.readObject();
- ClassTypeModel<?> typeModel = (ClassTypeModel)context.getTypeDomain().getTypeModel(clazz);
+ ReplicatableTypeModel<?> typeModel = (ReplicatableTypeModel)context.getTypeDomain().getTypeModel(clazz);
//
Map<FieldModel, Object> state = new HashMap<FieldModel, Object>();
- ClassTypeModel<?> currentTypeModel = typeModel;
+ ReplicatableTypeModel<?> currentTypeModel = typeModel;
List<Bilto> biltos = new ArrayList<Bilto>();
while (true)
{
@@ -136,9 +136,9 @@
{
break;
}
- if (currentSuperTypeModel instanceof ClassTypeModel)
+ if (currentSuperTypeModel instanceof ReplicatableTypeModel)
{
- currentTypeModel = (ClassTypeModel)currentSuperTypeModel;
+ currentTypeModel = (ReplicatableTypeModel)currentSuperTypeModel;
}
else
{
Modified: portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/serial/ObjectWriter.java
===================================================================
--- portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/serial/ObjectWriter.java 2010-01-15 10:13:34 UTC (rev 1309)
+++ portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/serial/ObjectWriter.java 2010-01-15 10:45:53 UTC (rev 1310)
@@ -20,7 +20,7 @@
package org.exoplatform.webui.application.replication.serial;
import org.exoplatform.webui.application.replication.SerializationContext;
-import org.exoplatform.webui.application.replication.model.ClassTypeModel;
+import org.exoplatform.webui.application.replication.model.ReplicatableTypeModel;
import org.exoplatform.webui.application.replication.model.FieldModel;
import org.exoplatform.webui.application.replication.model.TypeModel;
@@ -79,7 +79,7 @@
}
else
{
- ClassTypeModel<?> typeModel = (ClassTypeModel<?>)context.getTypeDomain().getTypeModel(obj.getClass());
+ ReplicatableTypeModel<?> typeModel = (ReplicatableTypeModel<?>)context.getTypeDomain().getTypeModel(obj.getClass());
//
if (typeModel == null)
@@ -93,7 +93,7 @@
output.writeObject(obj.getClass());
//
- ClassTypeModel<?> currentTypeModel = typeModel;
+ ReplicatableTypeModel<?> currentTypeModel = typeModel;
while (true)
{
for (FieldModel fieldModel : (currentTypeModel).getFields())
@@ -127,9 +127,9 @@
}
//
- if (currentSuperTypeModel instanceof ClassTypeModel)
+ if (currentSuperTypeModel instanceof ReplicatableTypeModel)
{
- currentTypeModel = (ClassTypeModel)currentSuperTypeModel;
+ currentTypeModel = (ReplicatableTypeModel)currentSuperTypeModel;
}
else
{
Modified: portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/D.java
===================================================================
--- portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/D.java 2010-01-15 10:13:34 UTC (rev 1309)
+++ portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/D.java 2010-01-15 10:45:53 UTC (rev 1310)
@@ -21,16 +21,15 @@
import org.exoplatform.webui.application.replication.annotations.ReplicatedType;
-import java.util.ArrayList;
-
/**
* @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a>
* @version $Revision$
*/
@ReplicatedType
-public class D extends ArrayList
+public class D
{
- String a = "a";
+ static String a = "a";
+ String b = "b";
}
Modified: portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/TestSerialization.java
===================================================================
--- portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/TestSerialization.java 2010-01-15 10:13:34 UTC (rev 1309)
+++ portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/TestSerialization.java 2010-01-15 10:45:53 UTC (rev 1310)
@@ -57,6 +57,20 @@
assertSame(b, b.ref.ref);
}
+ public void testStaticField() throws Exception
+ {
+ TypeDomain domain = new TypeDomain();
+ domain.add(D.class);
+ D d = new D();
+ d.b = "bar";
+ SerializationContext context = new SerializationContext(domain);
+ byte[] bytes = context.write(d);
+ D.a = "foo";
+ d = (D)context.read(bytes);
+ assertEquals("foo", D.a);
+ assertEquals("bar", d.b);
+ }
+
public void testAAA() throws Exception
{
TypeDomain domain = new TypeDomain();
@@ -73,4 +87,26 @@
assertSame(((E2)e.left).left, ((E2)e.right).left);
assertSame(((E2)e.left).right, ((E2)e.right).right);
}
+
+/*
+ public void testListOfReplicatable() throws Exception
+ {
+ TypeDomain domain = new TypeDomain();
+ domain.add(F1.class);
+ domain.add(F2.class);
+
+ //
+ F1 f1 = new F1();
+ F2 f2 = new F2();
+ f1.values.add(f2);
+
+ //
+ SerializationContext context = new SerializationContext(domain);
+ f1 = context.clone(f1);
+
+ //
+ assertNotNull(f1.values);
+ assertEquals(1, f1.values.size());
+ }
+*/
}
Modified: portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/TestTypeModel.java
===================================================================
--- portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/TestTypeModel.java 2010-01-15 10:13:34 UTC (rev 1309)
+++ portal/trunk/webui/core/src/test/java/org/exoplatform/webui/replication/TestTypeModel.java 2010-01-15 10:45:53 UTC (rev 1310)
@@ -50,7 +50,7 @@
public void testJuu()
{
TypeDomain domain = new TypeDomain();
- ClassTypeModel aTM = (ClassTypeModel) domain.add(A.class);
+ ReplicatableTypeModel aTM = (ReplicatableTypeModel) domain.add(A.class);
assertEquals(4, domain.getSize());
assertEquals(A.class.getName(), aTM.getName());
assertEquals(SetBuilder.create(domain.getTypeModel(int.class)).with(aTM).with(domain.getTypeModel(boolean.class)).build(domain.getTypeModel(String.class)), domain.getTypeModels());
14 years, 11 months
gatein SVN: r1309 - in portal/trunk: component/portal/src/main/java/org/exoplatform/portal/resource and 7 other directories.
by do-not-reply@jboss.org
Author: trong.tran
Date: 2010-01-15 05:13:34 -0500 (Fri, 15 Jan 2010)
New Revision: 1309
Added:
portal/trunk/component/web/src/main/java/org/exoplatform/web/security/GateInToken.java
portal/trunk/gadgets/core/src/main/java/conf/configuration.xml
portal/trunk/gadgets/core/src/main/java/conf/gadgettoken-nodetypes.xml
portal/trunk/gadgets/core/src/main/java/org/exoplatform/portal/gadget/core/ExoOAuthStore.java
portal/trunk/gadgets/core/src/main/java/org/exoplatform/portal/gadget/core/GadgetToken.java
portal/trunk/gadgets/core/src/main/java/org/exoplatform/portal/gadget/core/GadgetTokenContainer.java
portal/trunk/gadgets/core/src/main/java/org/exoplatform/portal/gadget/core/GadgetTokenEntry.java
portal/trunk/gadgets/core/src/main/java/org/exoplatform/portal/gadget/core/GadgetTokenInfoService.java
Removed:
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/SkinConfigDeployer.java
Modified:
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/config/UserPortalConfigService.java
portal/trunk/component/portal/src/test/java/org/exoplatform/portal/config/TestDataStorage.java
portal/trunk/component/portal/src/test/java/org/exoplatform/portal/config/TestUserPortalConfigService.java
portal/trunk/component/web/src/main/java/org/exoplatform/web/security/Token.java
portal/trunk/component/web/src/main/java/org/exoplatform/web/security/security/AbstractTokenService.java
portal/trunk/component/web/src/main/java/org/exoplatform/web/security/security/CookieTokenService.java
portal/trunk/component/web/src/main/java/org/exoplatform/web/security/security/TokenContainer.java
portal/trunk/component/web/src/main/java/org/exoplatform/web/security/security/TokenEntry.java
portal/trunk/component/web/src/main/java/org/exoplatform/web/security/security/TransientTokenService.java
portal/trunk/gadgets/core/pom.xml
portal/trunk/gadgets/core/src/main/java/conf/portal/configuration.xml
portal/trunk/gadgets/core/src/main/java/org/exoplatform/portal/gadget/core/ExoOAuthModule.java
Log:
GTNPORTAL-314 Fixing oAuth in gadgets
Modified: portal/trunk/component/portal/src/main/java/org/exoplatform/portal/config/UserPortalConfigService.java
===================================================================
--- portal/trunk/component/portal/src/main/java/org/exoplatform/portal/config/UserPortalConfigService.java 2010-01-15 08:36:46 UTC (rev 1308)
+++ portal/trunk/component/portal/src/main/java/org/exoplatform/portal/config/UserPortalConfigService.java 2010-01-15 10:13:34 UTC (rev 1309)
@@ -379,6 +379,7 @@
*/
public List<ModelChange> update(Page page) throws Exception
{
+ System.out.println("\n\n\n show max window : " + page.isShowMaxWindow() + "\n\n");
List<ModelChange> changes = storage_.save(page);
//
Deleted: portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/SkinConfigDeployer.java
===================================================================
--- portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/SkinConfigDeployer.java 2010-01-15 08:36:46 UTC (rev 1308)
+++ portal/trunk/component/portal/src/main/java/org/exoplatform/portal/resource/SkinConfigDeployer.java 2010-01-15 10:13:34 UTC (rev 1309)
@@ -1,135 +0,0 @@
-/**
- * Copyright (C) 2009 eXo Platform SAS.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.exoplatform.portal.resource;
-
-import groovy.lang.Binding;
-import groovy.lang.GroovyShell;
-
-import org.exoplatform.commons.utils.Safe;
-import org.exoplatform.container.PortalContainer;
-import org.exoplatform.container.RootContainer.PortalContainerPostInitTask;
-import org.exoplatform.services.log.ExoLogger;
-import org.exoplatform.services.log.Log;
-import org.gatein.wci.WebAppEvent;
-import org.gatein.wci.WebAppLifeCycleEvent;
-
-import java.io.IOException;
-import java.io.InputStream;
-
-import javax.servlet.ServletContext;
-
-/**
- * Created by The eXo Platform SAS
- * Jan 19, 2007
- */
-
-public class SkinConfigDeployer extends AbstractResourceHandler
-{
-
- /**
- * Logger
- */
- private static final Log LOG = ExoLogger.getLogger(SkinConfigDeployer.class);
-
- /** . */
- private final SkinService skinService;
-
- /**
- * The name of the portal container
- */
- private final String portalContainerName;
-
- public SkinConfigDeployer(String portalContainerName, SkinService skinService)
- {
- this.skinService = skinService;
- this.portalContainerName = portalContainerName;
- }
-
- public void onEvent(WebAppEvent event)
- {
- if (event instanceof WebAppLifeCycleEvent)
- {
- WebAppLifeCycleEvent waEvent = (WebAppLifeCycleEvent)event;
- if (waEvent.getType() == WebAppLifeCycleEvent.ADDED)
- {
- ServletContext scontext = null;
- InputStream is = null;
- try
- {
- scontext = event.getWebApp().getServletContext();
- is = scontext.getResourceAsStream("/WEB-INF/conf/script/groovy/SkinConfigScript.groovy");
- final PortalContainerPostInitTask task = new PortalContainerPostInitTask()
- {
-
- public void execute(ServletContext scontext, PortalContainer portalContainer)
- {
- register(scontext, portalContainer);
- }
- };
- PortalContainer.addInitTask(scontext, task, portalContainerName);
- }
- catch (Exception ex)
- {
- LOG.error("An error occurs while registering 'SkinConfigScript.groovy' from the context '"
- + (scontext == null ? "unknown" : scontext.getServletContextName()) + "'", ex);
- }
- finally
- {
- Safe.close(is);
- }
- }
- }
- }
-
- private void register(ServletContext scontext, PortalContainer container)
- {
- InputStream is = null;
- try
- {
- is = scontext.getResourceAsStream("/WEB-INF/conf/script/groovy/SkinConfigScript.groovy");
- Binding binding = new Binding();
- binding.setVariable("SkinService", skinService);
- binding.setVariable("ServletContext", scontext);
- binding.setVariable("ServletContextName", scontext.getServletContextName());
- binding.setVariable("PortalContainerName", container.getName());
- GroovyShell shell = new GroovyShell(binding);
- shell.evaluate(is);
- }
- catch (Exception ex)
- {
- LOG.error("An error occurs while processing 'SkinConfigScript.groovy' from the context '"
- + scontext.getServletContextName() + "'", ex);
- }
- finally
- {
- if (is != null)
- {
- try
- {
- is.close();
- }
- catch (IOException e)
- {
- // ignore me
- }
- }
- }
- }
-}
\ No newline at end of file
Modified: portal/trunk/component/portal/src/test/java/org/exoplatform/portal/config/TestDataStorage.java
===================================================================
--- portal/trunk/component/portal/src/test/java/org/exoplatform/portal/config/TestDataStorage.java 2010-01-15 08:36:46 UTC (rev 1308)
+++ portal/trunk/component/portal/src/test/java/org/exoplatform/portal/config/TestDataStorage.java 2010-01-15 10:13:34 UTC (rev 1309)
@@ -165,6 +165,7 @@
page.setOwnerType(PortalConfig.PORTAL_TYPE);
page.setOwnerId("test");
page.setName("foo");
+ page.setShowMaxWindow(false);
//
storage_.create(page);
@@ -172,9 +173,10 @@
//
Page page2 = storage_.getPage(page.getPageId());
page2.setTitle("MyTitle2");
+ page2.setShowMaxWindow(true);
storage_.save(page2);
- //
+ page2 = storage_.getPage(page.getPageId());
assertNotNull(page2);
assertEquals("portal::test::foo", page2.getPageId());
assertEquals("portal", page2.getOwnerType());
@@ -182,6 +184,7 @@
assertEquals("foo", page2.getName());
assertEquals("MyTitle2", page2.getTitle());
assertEquals(0, page2.getChildren().size());
+ assertEquals(true, page2.isShowMaxWindow());
}
public void testPageRemove() throws Exception
Modified: portal/trunk/component/portal/src/test/java/org/exoplatform/portal/config/TestUserPortalConfigService.java
===================================================================
--- portal/trunk/component/portal/src/test/java/org/exoplatform/portal/config/TestUserPortalConfigService.java 2010-01-15 08:36:46 UTC (rev 1308)
+++ portal/trunk/component/portal/src/test/java/org/exoplatform/portal/config/TestUserPortalConfigService.java 2010-01-15 10:13:34 UTC (rev 1309)
@@ -150,6 +150,29 @@
return map;
}
+ public void testUpdatePortalConfig() {
+ new UnitTest()
+ {
+ public void execute() throws Exception
+ {
+ UserPortalConfig userPortalCfg = userPortalConfigSer_.getUserPortalConfig("classic", "root");
+ assertNotNull(userPortalCfg);
+ PortalConfig portalCfg = userPortalCfg.getPortalConfig();
+ assertNotNull(portalCfg);
+ assertEquals(PortalConfig.PORTAL_TYPE, portalCfg.getType());
+ assertEquals("classic", portalCfg.getName());
+ assertEquals("en", portalCfg.getLocale());
+ portalCfg.setLocale("fr");
+
+ userPortalConfigSer_.update(portalCfg);
+
+ userPortalCfg = userPortalConfigSer_.getUserPortalConfig("classic", "root");
+ portalCfg = userPortalCfg.getPortalConfig();
+ assertEquals("fr", portalCfg.getLocale());
+ }
+ }.execute("root");
+ }
+
public void testRootGetUserPortalConfig()
{
new UnitTest()
@@ -497,6 +520,8 @@
page.setOwnerId("/platform/administrators");
page.setName("newAccount");
page.setCreator("someone");
+ page.setShowMaxWindow(true);
+ page.setTitle("newAccount title");
assertTrue(events.isEmpty());
userPortalConfigSer_.create(page);
assertEquals(1, events.size());
@@ -507,11 +532,41 @@
assertEquals("/platform/administrators", p.getOwnerId());
assertEquals("newAccount", p.getName());
assertEquals("someone", p.getCreator());
+ assertEquals("newAccount title", p.getTitle());
+ assertTrue(p.isShowMaxWindow());
+
+ p.setShowMaxWindow(false);
+ userPortalConfigSer_.update(p);
+ p = userPortalConfigSer_.getPage("group::/platform/administrators::newAccount");
+ assertFalse(p.isShowMaxWindow());
+ p.setShowMaxWindow(true);
+ userPortalConfigSer_.update(p);
+ p = userPortalConfigSer_.getPage("group::/platform/administrators::newAccount");
+ assertTrue(p.isShowMaxWindow());
+ p.setShowMaxWindow(false);
+ userPortalConfigSer_.update(p);
+ p = userPortalConfigSer_.getPage("group::/platform/administrators::newAccount");
+ assertFalse(p.isShowMaxWindow());
+ p.setShowMaxWindow(true);
+ userPortalConfigSer_.update(p);
+ p = userPortalConfigSer_.getPage("group::/platform/administrators::newAccount");
+ assertTrue(p.isShowMaxWindow());
+
Page p2 = userPortalConfigSer_.getPage("group::/platform/administrators::newAccount");
assertEquals("group", p2.getOwnerType());
assertEquals("/platform/administrators", p2.getOwnerId());
assertEquals("newAccount", p2.getName());
assertEquals("someone", p2.getCreator());
+// assertFalse(p2.isShowMaxWindow());
+ p2.setTitle("newAccount title 1");
+ p2.setShowMaxWindow(true);
+ userPortalConfigSer_.update(p2);
+
+ Page p3 = userPortalConfigSer_.getPage("group::/platform/administrators::newAccount");
+ assertEquals("newAccount title 1", p3.getTitle());
+// assertTrue(p3.isShowMaxWindow());
+
+
}
}.execute(null);
}
Copied: portal/trunk/component/web/src/main/java/org/exoplatform/web/security/GateInToken.java (from rev 1306, portal/trunk/component/web/src/main/java/org/exoplatform/web/security/Token.java)
===================================================================
--- portal/trunk/component/web/src/main/java/org/exoplatform/web/security/GateInToken.java (rev 0)
+++ portal/trunk/component/web/src/main/java/org/exoplatform/web/security/GateInToken.java 2010-01-15 10:13:34 UTC (rev 1309)
@@ -0,0 +1,64 @@
+/**
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.exoplatform.web.security;
+
+
+/**
+ * Created by The eXo Platform SAS
+ * Author : Tan Pham Dinh
+ * tan.pham(a)exoplatform.com
+ * May 6, 2009
+ */
+public class GateInToken implements Token
+{
+
+ public static String EXPIRE_MILI = "expirationMilis";
+
+ public static String USERNAME = "userName";
+
+ public static String PASSWORD = "password";
+
+ /** . */
+ private final long expirationTimeMillis;
+
+ /** . */
+ private final Credentials payload;
+
+ public GateInToken(long expirationTimeMillis, Credentials payload)
+ {
+ this.expirationTimeMillis = expirationTimeMillis;
+ this.payload = payload;
+ }
+
+ public long getExpirationTimeMillis()
+ {
+ return expirationTimeMillis;
+ }
+
+ public Credentials getPayload()
+ {
+ return payload;
+ }
+
+ public boolean isExpired()
+ {
+ return System.currentTimeMillis() > expirationTimeMillis;
+ }
+}
Modified: portal/trunk/component/web/src/main/java/org/exoplatform/web/security/Token.java
===================================================================
--- portal/trunk/component/web/src/main/java/org/exoplatform/web/security/Token.java 2010-01-15 08:36:46 UTC (rev 1308)
+++ portal/trunk/component/web/src/main/java/org/exoplatform/web/security/Token.java 2010-01-15 10:13:34 UTC (rev 1309)
@@ -1,64 +1,6 @@
-/**
- * Copyright (C) 2009 eXo Platform SAS.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
package org.exoplatform.web.security;
-
-/**
- * Created by The eXo Platform SAS
- * Author : Tan Pham Dinh
- * tan.pham(a)exoplatform.com
- * May 6, 2009
- */
-public class Token
+public interface Token
{
-
- public static String EXPIRE_MILI = "expirationMilis";
-
- public static String USERNAME = "userName";
-
- public static String PASSWORD = "password";
-
- /** . */
- private final long expirationTimeMillis;
-
- /** . */
- private final Credentials payload;
-
- public Token(long expirationTimeMillis, Credentials payload)
- {
- this.expirationTimeMillis = expirationTimeMillis;
- this.payload = payload;
- }
-
- public long getExpirationTimeMillis()
- {
- return expirationTimeMillis;
- }
-
- public Credentials getPayload()
- {
- return payload;
- }
-
- public boolean isExpired()
- {
- return System.currentTimeMillis() > expirationTimeMillis;
- }
+ public boolean isExpired();
}
Modified: portal/trunk/component/web/src/main/java/org/exoplatform/web/security/security/AbstractTokenService.java
===================================================================
--- portal/trunk/component/web/src/main/java/org/exoplatform/web/security/security/AbstractTokenService.java 2010-01-15 08:36:46 UTC (rev 1308)
+++ portal/trunk/component/web/src/main/java/org/exoplatform/web/security/security/AbstractTokenService.java 2010-01-15 10:13:34 UTC (rev 1309)
@@ -28,6 +28,7 @@
import org.exoplatform.management.jmx.annotations.Property;
import org.exoplatform.web.login.InitiateLoginServlet;
import org.exoplatform.web.security.Credentials;
+import org.exoplatform.web.security.GateInToken;
import org.exoplatform.web.security.Token;
import org.exoplatform.web.security.TokenStore;
import org.picocontainer.Startable;
@@ -100,7 +101,7 @@
throw new NullPointerException();
}
- Token token;
+ GateInToken token;
try
{
if (remove)
@@ -139,7 +140,7 @@
String[] ids = getAllTokens();
for (String s : ids)
{
- Token token = getToken(s);
+ GateInToken token = getToken(s);
if (token.isExpired())
{
deleteToken(s);
@@ -164,15 +165,15 @@
@Managed
@ManagedDescription("get a token by id")
- public abstract Token getToken(String id);
+ public abstract <T extends Token> T getToken(Object id);
@Managed
@ManagedDescription("Delete a token by id")
- public abstract Token deleteToken(String id);
+ public abstract <T extends Token> T deleteToken(Object id);
@Managed
@ManagedDescription("The list of all tokens")
- public abstract String[] getAllTokens();
+ public abstract <T extends Object> T[] getAllTokens();
@Managed
@ManagedDescription("The number of tokens")
Modified: portal/trunk/component/web/src/main/java/org/exoplatform/web/security/security/CookieTokenService.java
===================================================================
--- portal/trunk/component/web/src/main/java/org/exoplatform/web/security/security/CookieTokenService.java 2010-01-15 08:36:46 UTC (rev 1308)
+++ portal/trunk/component/web/src/main/java/org/exoplatform/web/security/security/CookieTokenService.java 2010-01-15 10:13:34 UTC (rev 1309)
@@ -26,7 +26,7 @@
import org.exoplatform.commons.chromattic.SessionContext;
import org.exoplatform.container.xml.InitParams;
import org.exoplatform.web.security.Credentials;
-import org.exoplatform.web.security.Token;
+import org.exoplatform.web.security.GateInToken;
import java.util.Collection;
import java.util.Date;
@@ -69,7 +69,7 @@
{
String tokenId = nextTokenId();
long expirationTimeMillis = System.currentTimeMillis() + validityMillis;
- Token token = new Token(expirationTimeMillis, credentials);
+ GateInToken token = new GateInToken(expirationTimeMillis, credentials);
TokenContainer container = getTokenContainer();
container.saveToken(tokenId, token.getPayload(), new Date(token.getExpirationTimeMillis()));
return tokenId;
@@ -78,25 +78,25 @@
}
@Override
- public Token getToken(final String id)
+ public GateInToken getToken(final Object id)
{
- return new TokenTask<Token>() {
+ return new TokenTask<GateInToken>() {
@Override
- protected Token execute()
+ protected GateInToken execute()
{
- return getTokenContainer().getToken(id);
+ return getTokenContainer().getToken((String)id);
}
}.executeWith(chromatticLifeCycle);
}
@Override
- public Token deleteToken(final String id)
+ public GateInToken deleteToken(final Object id)
{
- return new TokenTask<Token>() {
+ return new TokenTask<GateInToken>() {
@Override
- protected Token execute()
+ protected GateInToken execute()
{
- return getTokenContainer().removeToken(id);
+ return getTokenContainer().removeToken((String)id);
}
}.executeWith(chromatticLifeCycle);
}
Modified: portal/trunk/component/web/src/main/java/org/exoplatform/web/security/security/TokenContainer.java
===================================================================
--- portal/trunk/component/web/src/main/java/org/exoplatform/web/security/security/TokenContainer.java 2010-01-15 08:36:46 UTC (rev 1308)
+++ portal/trunk/component/web/src/main/java/org/exoplatform/web/security/security/TokenContainer.java 2010-01-15 10:13:34 UTC (rev 1309)
@@ -22,7 +22,7 @@
import org.chromattic.api.annotations.PrimaryType;
import org.chromattic.api.annotations.OneToMany;
import org.exoplatform.web.security.Credentials;
-import org.exoplatform.web.security.Token;
+import org.exoplatform.web.security.GateInToken;
import java.util.Collection;
import java.util.Date;
@@ -47,20 +47,20 @@
return getTokens().values();
}
- public Token getToken(String tokenId)
+ public GateInToken getToken(String tokenId)
{
Map<String, TokenEntry> tokens = getTokens();
TokenEntry entry = tokens.get(tokenId);
return entry != null ? entry.getToken() : null;
}
- public Token removeToken(String tokenId)
+ public GateInToken removeToken(String tokenId)
{
Map<String, TokenEntry> tokens = getTokens();
TokenEntry entry = tokens.get(tokenId);
if (entry != null)
{
- Token token = entry.getToken();
+ GateInToken token = entry.getToken();
entry.remove();
return token;
}
@@ -70,7 +70,7 @@
}
}
- public Token saveToken(String tokenId, Credentials credentials, Date expirationTime)
+ public GateInToken saveToken(String tokenId, Credentials credentials, Date expirationTime)
{
Map<String, TokenEntry> tokens = getTokens();
TokenEntry entry = tokens.get(tokenId);
Modified: portal/trunk/component/web/src/main/java/org/exoplatform/web/security/security/TokenEntry.java
===================================================================
--- portal/trunk/component/web/src/main/java/org/exoplatform/web/security/security/TokenEntry.java 2010-01-15 08:36:46 UTC (rev 1308)
+++ portal/trunk/component/web/src/main/java/org/exoplatform/web/security/security/TokenEntry.java 2010-01-15 10:13:34 UTC (rev 1309)
@@ -23,7 +23,7 @@
import org.chromattic.api.annotations.PrimaryType;
import org.chromattic.api.annotations.Property;
import org.exoplatform.web.security.Credentials;
-import org.exoplatform.web.security.Token;
+import org.exoplatform.web.security.GateInToken;
import java.util.Date;
@@ -56,9 +56,9 @@
@Destroy
public abstract void remove();
- public Token getToken()
+ public GateInToken getToken()
{
- return new Token(
+ return new GateInToken(
getExpirationTime().getTime(),
new Credentials(getUserName(), getPassword()));
}
Modified: portal/trunk/component/web/src/main/java/org/exoplatform/web/security/security/TransientTokenService.java
===================================================================
--- portal/trunk/component/web/src/main/java/org/exoplatform/web/security/security/TransientTokenService.java 2010-01-15 08:36:46 UTC (rev 1308)
+++ portal/trunk/component/web/src/main/java/org/exoplatform/web/security/security/TransientTokenService.java 2010-01-15 10:13:34 UTC (rev 1309)
@@ -21,7 +21,7 @@
import org.exoplatform.container.xml.InitParams;
import org.exoplatform.web.security.Credentials;
-import org.exoplatform.web.security.Token;
+import org.exoplatform.web.security.GateInToken;
import java.util.concurrent.ConcurrentHashMap;
@@ -32,7 +32,7 @@
public class TransientTokenService extends AbstractTokenService
{
- protected final ConcurrentHashMap<String, Token> tokens = new ConcurrentHashMap<String, Token>();
+ protected final ConcurrentHashMap<String, GateInToken> tokens = new ConcurrentHashMap<String, GateInToken>();
public TransientTokenService(InitParams initParams)
{
@@ -51,20 +51,20 @@
}
String tokenId = nextTokenId();
long expirationTimeMillis = System.currentTimeMillis() + validityMillis;
- tokens.put(tokenId, new Token(expirationTimeMillis, credentials));
+ tokens.put(tokenId, new GateInToken(expirationTimeMillis, credentials));
return tokenId;
}
@Override
- public Token getToken(String id)
+ public GateInToken getToken(Object id)
{
return tokens.get(id);
}
@Override
- public Token deleteToken(String id)
+ public GateInToken deleteToken(Object id)
{
- Token token = tokens.get(id);
+ GateInToken token = tokens.get(id);
tokens.remove(id);
return token;
}
Modified: portal/trunk/gadgets/core/pom.xml
===================================================================
--- portal/trunk/gadgets/core/pom.xml 2010-01-15 08:36:46 UTC (rev 1308)
+++ portal/trunk/gadgets/core/pom.xml 2010-01-15 10:13:34 UTC (rev 1309)
@@ -1,93 +1,90 @@
<?xml version="1.0" encoding="UTF-8"?>
-<!--
+ <!--
- Copyright (C) 2009 eXo Platform SAS.
-
- This is free software; you can redistribute it and/or modify it
- under the terms of the GNU Lesser General Public License as
- published by the Free Software Foundation; either version 2.1 of
- the License, or (at your option) any later version.
-
- This software is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with this software; if not, write to the Free
- Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ Copyright (C) 2009 eXo Platform SAS. This is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This software is
+ distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with
+ this software; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF site:
+ http://www.fsf.org.
+ -->
--->
-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.exoplatform.portal</groupId>
- <artifactId>exo.portal.gadgets</artifactId>
- <version>3.0.0-Beta05-SNAPSHOT</version>
- </parent>
-
- <artifactId>exo.portal.gadgets-core</artifactId>
- <packaging>jar</packaging>
- <name>GateIn Portal eXo Gadgets Core</name>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-dependency-plugin</artifactId>
- <executions>
- <execution>
- <id>unpack</id>
- <phase>compile</phase>
- <goals>
- <goal>unpack</goal>
- </goals>
- <configuration>
- <artifactItems>
- <artifactItem>
- <groupId>org.apache.shindig</groupId>
- <artifactId>shindig-gadgets</artifactId>
- <version>${org.shindig.version}</version>
- <type>jar</type>
- <overWrite>false</overWrite>
- <outputDirectory>${project.build.directory}/classes</outputDirectory>
- <excludes>config/oauth.json,containers/default/container.js</excludes>
- </artifactItem>
- </artifactItems>
- </configuration>
- </execution>
- </executions>
- </plugin>
-
- </plugins>
- <resources>
- <resource>
- <directory>src/main/java</directory>
- <includes>
- <include>**/container.js</include>
- <include>**/oauth.json</include>
- <include>**/*.xml</include>
- </includes>
- </resource>
- </resources>
- </build>
- <dependencies>
- <dependency>
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
<groupId>org.exoplatform.portal</groupId>
- <artifactId>exo.portal.component.web</artifactId>
+ <artifactId>exo.portal.gadgets</artifactId>
<version>3.0.0-Beta05-SNAPSHOT</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.shindig</groupId>
- <artifactId>shindig-common</artifactId>
- <type>jar</type>
- </dependency>
- <dependency>
- <groupId>org.apache.shindig</groupId>
- <artifactId>shindig-features</artifactId>
- <type>jar</type>
- </dependency>
- </dependencies>
+ </parent>
+
+ <artifactId>exo.portal.gadgets-core</artifactId>
+ <packaging>jar</packaging>
+ <name>GateIn Portal eXo Gadgets Core</name>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>unpack</id>
+ <phase>compile</phase>
+ <goals>
+ <goal>unpack</goal>
+ </goals>
+ <configuration>
+ <artifactItems>
+ <artifactItem>
+ <groupId>org.apache.shindig</groupId>
+ <artifactId>shindig-gadgets</artifactId>
+ <version>${org.shindig.version}</version>
+ <type>jar</type>
+ <overWrite>false</overWrite>
+ <outputDirectory>${project.build.directory}/classes</outputDirectory>
+ <excludes>config/oauth.json,containers/default/container.js</excludes>
+ </artifactItem>
+ </artifactItems>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+
+ </plugins>
+ <resources>
+ <resource>
+ <directory>src/main/java</directory>
+ <includes>
+ <include>**/container.js</include>
+ <include>**/oauth.json</include>
+ <include>**/*.xml</include>
+ </includes>
+ </resource>
+ </resources>
+ </build>
+ <dependencies>
+ <dependency>
+ <groupId>org.exoplatform.portal</groupId>
+ <artifactId>exo.portal.component.web</artifactId>
+ <version>3.0.0-Beta05-SNAPSHOT</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.shindig</groupId>
+ <artifactId>shindig-common</artifactId>
+ <type>jar</type>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.shindig</groupId>
+ <artifactId>shindig-features</artifactId>
+ <type>jar</type>
+ </dependency>
+ <dependency>
+ <groupId>org.chromattic</groupId>
+ <artifactId>chromattic.api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.chromattic</groupId>
+ <artifactId>chromattic.spi</artifactId>
+ </dependency>
+ </dependencies>
</project>
Added: portal/trunk/gadgets/core/src/main/java/conf/configuration.xml
===================================================================
--- portal/trunk/gadgets/core/src/main/java/conf/configuration.xml (rev 0)
+++ portal/trunk/gadgets/core/src/main/java/conf/configuration.xml 2010-01-15 10:13:34 UTC (rev 1309)
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+
+ Copyright (C) 2009 eXo Platform SAS.
+
+ This is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of
+ the License, or (at your option) any later version.
+
+ This software is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this software; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+
+-->
+
+<configuration
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.exoplaform.org/xml/ns/kernel_1_0.xsd http://www.exoplaform.org/xml/ns/kernel_1_0.xsd"
+ xmlns="http://www.exoplaform.org/xml/ns/kernel_1_0.xsd">
+</configuration>
\ No newline at end of file
Added: portal/trunk/gadgets/core/src/main/java/conf/gadgettoken-nodetypes.xml
===================================================================
--- portal/trunk/gadgets/core/src/main/java/conf/gadgettoken-nodetypes.xml (rev 0)
+++ portal/trunk/gadgets/core/src/main/java/conf/gadgettoken-nodetypes.xml 2010-01-15 10:13:34 UTC (rev 1309)
@@ -0,0 +1,75 @@
+<!--
+
+ Copyright (C) 2009 eXo Platform SAS.
+
+ This is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of
+ the License, or (at your option) any later version.
+
+ This software is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this software; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+
+-->
+<nodeTypes xmlns:nt="http://www.jcp.org/jcr/nt/1.0" xmlns:mix="http://www.jcp.org/jcr/mix/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0">
+
+ <nodeType name="lgn:gadgettokencontainer" isMixin="false" hasOrderableChildNodes="false" primaryItemName="">
+ <supertypes>
+ <supertype>nt:base</supertype>
+ <supertype>mix:referenceable</supertype>
+ </supertypes>
+ <childNodeDefinitions>
+ <childNodeDefinition name="*" defaultPrimaryType="lgn:gadgettoken" autoCreated="false" mandatory="false"
+ onParentVersion="COPY" protected="false" sameNameSiblings="false">
+ <requiredPrimaryTypes>
+ <requiredPrimaryType>lgn:gadgettoken</requiredPrimaryType>
+ </requiredPrimaryTypes>
+ </childNodeDefinition>
+ </childNodeDefinitions>
+ </nodeType>
+
+ <nodeType name="lgn:gadgettoken" isMixin="false" hasOrderableChildNodes="false" primaryItemName="">
+ <supertypes>
+ <supertype>nt:base</supertype>
+ <supertype>mix:referenceable</supertype>
+ </supertypes>
+ <propertyDefinitions>
+ <propertyDefinition name="userId" requiredType="String" autoCreated="false" mandatory="false" onParentVersion="COPY" protected="false" multiple="false">
+ <valueConstraints/>
+ </propertyDefinition>
+ <propertyDefinition name="gadgetUri" requiredType="String" autoCreated="false" mandatory="false" onParentVersion="COPY" protected="false" multiple="false">
+ <valueConstraints/>
+ </propertyDefinition>
+ <propertyDefinition name="moduleId" requiredType="Long" autoCreated="false" mandatory="false" onParentVersion="COPY" protected="false" multiple="false">
+ <valueConstraints/>
+ </propertyDefinition>
+ <propertyDefinition name="tokenName" requiredType="String" autoCreated="false" mandatory="false" onParentVersion="COPY" protected="false" multiple="false">
+ <valueConstraints/>
+ </propertyDefinition>
+ <propertyDefinition name="serviceName" requiredType="String" autoCreated="false" mandatory="false" onParentVersion="COPY" protected="false" multiple="false">
+ <valueConstraints/>
+ </propertyDefinition>
+
+ <propertyDefinition name="accessToken" requiredType="String" autoCreated="false" mandatory="false" onParentVersion="COPY" protected="false" multiple="false">
+ <valueConstraints/>
+ </propertyDefinition>
+ <propertyDefinition name="tokenSecret" requiredType="String" autoCreated="false" mandatory="false" onParentVersion="COPY" protected="false" multiple="false">
+ <valueConstraints/>
+ </propertyDefinition>
+ <propertyDefinition name="sessionHandle" requiredType="String" autoCreated="false" mandatory="false" onParentVersion="COPY" protected="false" multiple="false">
+ <valueConstraints/>
+ </propertyDefinition>
+ <propertyDefinition name="tokenExpireMillis" requiredType="Long" autoCreated="false" mandatory="false" onParentVersion="COPY" protected="false" multiple="false">
+ <valueConstraints/>
+ </propertyDefinition>
+ </propertyDefinitions>
+ </nodeType>
+
+</nodeTypes>
Modified: portal/trunk/gadgets/core/src/main/java/conf/portal/configuration.xml
===================================================================
--- portal/trunk/gadgets/core/src/main/java/conf/portal/configuration.xml 2010-01-15 08:36:46 UTC (rev 1308)
+++ portal/trunk/gadgets/core/src/main/java/conf/portal/configuration.xml 2010-01-15 10:13:34 UTC (rev 1309)
@@ -24,8 +24,59 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.exoplaform.org/xml/ns/kernel_1_0.xsd http://www.exoplaform.org/xml/ns/kernel_1_0.xsd"
xmlns="http://www.exoplaform.org/xml/ns/kernel_1_0.xsd">
+<component>
+ <key>org.exoplatform.portal.gadget.core.SecurityTokenGenerator</key>
+ <type>org.exoplatform.portal.gadget.core.ExoDefaultSecurityTokenGenerator</type>
+ </component>
<component>
- <key>org.exoplatform.portal.gadget.core.SecurityTokenGenerator</key>
- <type>org.exoplatform.portal.gadget.core.ExoDefaultSecurityTokenGenerator</type>
+ <type>org.exoplatform.portal.gadget.core.GadgetTokenInfoService</type>
+ <init-params>
+ <values-param>
+ <name>service.configuration</name>
+ <value>gadget-token</value>
+ <value>7</value>
+ <value>DAY</value>
+ </values-param>
+ </init-params>
</component>
+
+ <external-component-plugins>
+ <target-component>org.exoplatform.commons.chromattic.ChromatticManager</target-component>
+ <component-plugin>
+ <name>chromattic</name>
+ <set-method>addLifeCycle</set-method>
+ <type>org.exoplatform.commons.chromattic.ChromatticLifeCycle</type>
+ <init-params>
+ <value-param>
+ <name>domain-name</name>
+ <value>gadgettokens</value>
+ </value-param>
+ <value-param>
+ <name>workspace-name</name>
+ <value>portal-work</value>
+ </value-param>
+ <values-param>
+ <name>entities</name>
+ <value>org.exoplatform.portal.gadget.core.GadgetTokenContainer</value>
+ <value>org.exoplatform.portal.gadget.core.GadgetTokenEntry</value>
+ </values-param>
+ </init-params>
+ </component-plugin>
+ </external-component-plugins>
+
+ <external-component-plugins>
+ <target-component>org.exoplatform.services.jcr.RepositoryService</target-component>
+ <component-plugin>
+ <name>add.nodeType</name>
+ <set-method>addPlugin</set-method>
+ <type>org.exoplatform.services.jcr.impl.AddNodeTypePlugin</type>
+ <init-params>
+ <values-param>
+ <name>autoCreatedInNewRepository</name>
+ <description>Node types configuration file</description>
+ <value>jar:/conf/gadgettoken-nodetypes.xml</value>
+ </values-param>
+ </init-params>
+ </component-plugin>
+ </external-component-plugins>
</configuration>
\ No newline at end of file
Modified: portal/trunk/gadgets/core/src/main/java/org/exoplatform/portal/gadget/core/ExoOAuthModule.java
===================================================================
--- portal/trunk/gadgets/core/src/main/java/org/exoplatform/portal/gadget/core/ExoOAuthModule.java 2010-01-15 08:36:46 UTC (rev 1308)
+++ portal/trunk/gadgets/core/src/main/java/org/exoplatform/portal/gadget/core/ExoOAuthModule.java 2010-01-15 10:13:34 UTC (rev 1309)
@@ -19,18 +19,28 @@
package org.exoplatform.portal.gadget.core;
-import com.google.inject.Inject;
-import com.google.inject.name.Names;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang.StringUtils;
import org.apache.shindig.auth.AnonymousAuthenticationHandler;
import org.apache.shindig.common.crypto.BlobCrypter;
+import org.apache.shindig.common.util.ResourceLoader;
import org.apache.shindig.config.ContainerConfig;
import org.apache.shindig.gadgets.http.HttpFetcher;
+import org.apache.shindig.gadgets.oauth.BasicOAuthStore;
+import org.apache.shindig.gadgets.oauth.BasicOAuthStoreConsumerKeyAndSecret;
import org.apache.shindig.gadgets.oauth.OAuthFetcherConfig;
import org.apache.shindig.gadgets.oauth.OAuthModule;
import org.apache.shindig.gadgets.oauth.OAuthRequest;
import org.apache.shindig.gadgets.oauth.OAuthStore;
+import org.apache.shindig.gadgets.oauth.BasicOAuthStoreConsumerKeyAndSecret.KeyType;
+import com.google.inject.Inject;
+import com.google.inject.Provider;
+import com.google.inject.name.Names;
+
/**
* Created by IntelliJ IDEA.
* User: jeremi
@@ -45,6 +55,14 @@
private static final String SIGNING_KEY_NAME = "gadgets.signingKeyName";
private static final String CALLBACK_URL = "gadgets.signing.global-callback-url";
+
+ private static final String OAUTH_CONFIG = "config/oauth.json";
+ private static final String OAUTH_SIGNING_KEY_FILE = "shindig.signing.key-file";
+ private static final String OAUTH_SIGNING_KEY_NAME = "shindig.signing.key-name";
+ private static final String OAUTH_CALLBACK_URL = "shindig.signing.global-callback-url";
+
+
+ private static final Logger logger = Logger.getLogger(OAuthModule.class.getName());
@Override
protected void configure()
@@ -62,18 +80,73 @@
Boolean.TRUE);
}
- public static class ExoOAuthStoreProvider extends OAuthStoreProvider
+ public static class ExoOAuthStoreProvider implements Provider<OAuthStore>
{
- @Inject
+
+ private final ExoOAuthStore store;
+
+ @Inject
public ExoOAuthStoreProvider(ContainerConfig config)
{
//super(config.getString(ContainerConfig.DEFAULT_CONTAINER, SIGNING_KEY_FILE), config.getString(ContainerConfig.DEFAULT_CONTAINER, SIGNING_KEY_NAME));
- super(config.getString(ContainerConfig.DEFAULT_CONTAINER, SIGNING_KEY_FILE), config.getString(
- ContainerConfig.DEFAULT_CONTAINER, SIGNING_KEY_NAME), config.getString(ContainerConfig.DEFAULT_CONTAINER,
- CALLBACK_URL));
+// super(config.getString(ContainerConfig.DEFAULT_CONTAINER, SIGNING_KEY_FILE), config.getString(
+// ContainerConfig.DEFAULT_CONTAINER, SIGNING_KEY_NAME), config.getString(ContainerConfig.DEFAULT_CONTAINER,
+// CALLBACK_URL));
+
+ store = new ExoOAuthStore();
+
+ String signingKeyFile = config.getString(ContainerConfig.DEFAULT_CONTAINER, SIGNING_KEY_FILE);
+ String signingKeyName = config.getString(ContainerConfig.DEFAULT_CONTAINER, SIGNING_KEY_NAME);
+ String defaultCallbackUrl = config.getString(ContainerConfig.DEFAULT_CONTAINER,CALLBACK_URL);
+
+ loadDefaultKey(signingKeyFile, signingKeyName);
+ store.setDefaultCallbackUrl(defaultCallbackUrl);
+ loadConsumers();
}
- }
+
+
+ private void loadDefaultKey(String signingKeyFile, String signingKeyName) {
+ BasicOAuthStoreConsumerKeyAndSecret key = null;
+ if (!StringUtils.isBlank(signingKeyFile)) {
+ try {
+ logger.info("Loading OAuth signing key from " + signingKeyFile);
+ String privateKey = IOUtils.toString(ResourceLoader.open(signingKeyFile), "UTF-8");
+ privateKey = BasicOAuthStore.convertFromOpenSsl(privateKey);
+ key = new BasicOAuthStoreConsumerKeyAndSecret(null, privateKey, KeyType.RSA_PRIVATE,
+ signingKeyName, null);
+ } catch (Throwable t) {
+ logger.log(Level.WARNING, "Couldn't load key file " + signingKeyFile, t);
+ }
+ }
+ if (key != null) {
+ store.setDefaultKey(key);
+ } else {
+ logger.log(Level.WARNING, "Couldn't load OAuth signing key. To create a key, run:\n" +
+ " openssl req -newkey rsa:1024 -days 365 -nodes -x509 -keyout testkey.pem \\\n" +
+ " -out testkey.pem -subj '/CN=mytestkey'\n" +
+ " openssl pkcs8 -in testkey.pem -out oauthkey.pem -topk8 -nocrypt -outform PEM\n" +
+ '\n' +
+ "Then edit gadgets.properties and add these lines:\n" +
+ OAUTH_SIGNING_KEY_FILE + "=<path-to-oauthkey.pem>\n" +
+ OAUTH_SIGNING_KEY_NAME + "=mykey\n");
+ }
+ }
+
+ private void loadConsumers() {
+ try {
+ String oauthConfigString = ResourceLoader.getContent(OAUTH_CONFIG);
+ store.initFromConfigString(oauthConfigString);
+ } catch (Throwable t) {
+ logger.log(Level.WARNING, "Failed to initialize OAuth consumers from " + OAUTH_CONFIG, t);
+ }
+ }
+
+ public OAuthStore get() {
+ return store;
+ }
+ }
+
public static class ExoOAuthRequestProvider extends OAuthRequestProvider
{
private final HttpFetcher fetcher;
Added: portal/trunk/gadgets/core/src/main/java/org/exoplatform/portal/gadget/core/ExoOAuthStore.java
===================================================================
--- portal/trunk/gadgets/core/src/main/java/org/exoplatform/portal/gadget/core/ExoOAuthStore.java (rev 0)
+++ portal/trunk/gadgets/core/src/main/java/org/exoplatform/portal/gadget/core/ExoOAuthStore.java 2010-01-15 10:13:34 UTC (rev 1309)
@@ -0,0 +1,250 @@
+package org.exoplatform.portal.gadget.core;
+
+import com.google.common.collect.Maps;
+import net.oauth.OAuth;
+import net.oauth.OAuthConsumer;
+import net.oauth.OAuthServiceProvider;
+import net.oauth.signature.RSA_SHA1;
+
+import org.apache.shindig.auth.SecurityToken;
+import org.apache.shindig.gadgets.GadgetException;
+import org.apache.shindig.gadgets.oauth.BasicOAuthStoreConsumerIndex;
+import org.apache.shindig.gadgets.oauth.BasicOAuthStoreConsumerKeyAndSecret;
+import org.apache.shindig.gadgets.oauth.BasicOAuthStoreTokenIndex;
+import org.apache.shindig.gadgets.oauth.OAuthStore;
+import org.apache.shindig.gadgets.oauth.BasicOAuthStoreConsumerKeyAndSecret.KeyType;
+import org.exoplatform.container.ExoContainer;
+import org.exoplatform.container.PortalContainer;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Iterator;
+import java.util.Map;
+
+/*
+* Created by The eXo Platform SAS
+* Author : tung.dang
+* tungcnw(a)gmail.com
+* Dec 10, 2009
+*
+*/
+
+/**
+ * Simple implementation of the {@link OAuthStore} interface. We use a
+ * in-memory hash map. If initialized with a private key, then the store will
+ * return an OAuthAccessor in {@code getOAuthAccessor} that uses that private
+ * key if no consumer key and secret could be found.
+ */
+
+public class ExoOAuthStore implements OAuthStore {
+
+ private static final String CONSUMER_SECRET_KEY = "consumer_secret";
+ private static final String CONSUMER_KEY_KEY = "consumer_key";
+ private static final String KEY_TYPE_KEY = "key_type";
+ private static final String CALLBACK_URL = "callback_url";
+
+ /**
+ * HashMap of provider and consumer information. Maps BasicOAuthStoreConsumerIndexs (i.e.
+ * nickname of a service provider and the gadget that uses that nickname) to
+ * {@link BasicOAuthStoreConsumerKeyAndSecret}s.
+ */
+ private final Map<BasicOAuthStoreConsumerIndex, BasicOAuthStoreConsumerKeyAndSecret> consumerInfos;
+
+ /**
+ * HashMap of token information. Maps BasicOAuthStoreTokenIndexs (i.e. gadget id, token
+ * nickname, module id, etc.) to TokenInfos (i.e. access token and token
+ * secrets).
+ */
+ // TODO: tung.dang don't need it, we store token in our memory.
+ //private Map<BasicOAuthStoreTokenIndex, TokenInfo> tokens = Maps.newHashMap();
+
+
+ /**
+ * Key to use when no other key is found.
+ */
+ private BasicOAuthStoreConsumerKeyAndSecret defaultKey;
+
+ /**
+ * Callback to use when no per-key callback URL is found.
+ */
+ private String defaultCallbackUrl;
+
+ /** Number of times we looked up a consumer key */
+ private int consumerKeyLookupCount = 0;
+
+ /** Number of times we looked up an access token */
+ private int accessTokenLookupCount = 0;
+
+ /** Number of times we added an access token */
+ private int accessTokenAddCount = 0;
+
+ /** Number of times we removed an access token */
+ private int accessTokenRemoveCount = 0;
+
+ public ExoOAuthStore() {
+ consumerInfos = Maps.newHashMap();
+ }
+
+ public void initFromConfigString(String oauthConfigStr) throws GadgetException {
+ try {
+ JSONObject oauthConfigs = new JSONObject(oauthConfigStr);
+ for (Iterator<?> i = oauthConfigs.keys(); i.hasNext();) {
+ String url = (String) i.next();
+ URI gadgetUri = new URI(url);
+ JSONObject oauthConfig = oauthConfigs.getJSONObject(url);
+ storeConsumerInfos(gadgetUri, oauthConfig);
+ }
+ } catch (JSONException e) {
+ throw new GadgetException(GadgetException.Code.OAUTH_STORAGE_ERROR, e);
+ } catch (URISyntaxException e) {
+ throw new GadgetException(GadgetException.Code.OAUTH_STORAGE_ERROR, e);
+ }
+ }
+
+ private void storeConsumerInfos(URI gadgetUri, JSONObject oauthConfig)
+ throws JSONException, GadgetException {
+ for (String serviceName : JSONObject.getNames(oauthConfig)) {
+ JSONObject consumerInfo = oauthConfig.getJSONObject(serviceName);
+ storeConsumerInfo(gadgetUri, serviceName, consumerInfo);
+ }
+ }
+
+ private void storeConsumerInfo(URI gadgetUri, String serviceName, JSONObject consumerInfo)
+ throws JSONException, GadgetException {
+ realStoreConsumerInfo(gadgetUri, serviceName, consumerInfo);
+ }
+
+ private void realStoreConsumerInfo(URI gadgetUri, String serviceName, JSONObject consumerInfo)
+ throws JSONException {
+ String callbackUrl = consumerInfo.optString(CALLBACK_URL, null);
+ String consumerSecret = consumerInfo.getString(CONSUMER_SECRET_KEY);
+ String consumerKey = consumerInfo.getString(CONSUMER_KEY_KEY);
+ String keyTypeStr = consumerInfo.getString(KEY_TYPE_KEY);
+ KeyType keyType = KeyType.HMAC_SYMMETRIC;
+
+ if (keyTypeStr.equals("RSA_PRIVATE")) {
+ keyType = KeyType.RSA_PRIVATE;
+ consumerSecret = convertFromOpenSsl(consumerSecret);
+ }
+
+ BasicOAuthStoreConsumerKeyAndSecret kas = new BasicOAuthStoreConsumerKeyAndSecret(
+ consumerKey, consumerSecret, keyType, null, callbackUrl);
+
+ BasicOAuthStoreConsumerIndex index = new BasicOAuthStoreConsumerIndex();
+ index.setGadgetUri(gadgetUri.toASCIIString());
+ index.setServiceName(serviceName);
+ setConsumerKeyAndSecret(index, kas);
+ }
+
+ // Support standard openssl keys by stripping out the headers and blank lines
+ public static String convertFromOpenSsl(String privateKey) {
+ return privateKey.replaceAll("-----[A-Z ]*-----", "").replace("\n", "");
+ }
+
+ public void setDefaultKey(BasicOAuthStoreConsumerKeyAndSecret defaultKey) {
+ this.defaultKey = defaultKey;
+ }
+
+ public void setDefaultCallbackUrl(String defaultCallbackUrl) {
+ this.defaultCallbackUrl = defaultCallbackUrl;
+ }
+
+ public void setConsumerKeyAndSecret(
+ BasicOAuthStoreConsumerIndex providerKey, BasicOAuthStoreConsumerKeyAndSecret keyAndSecret) {
+ consumerInfos.put(providerKey, keyAndSecret);
+ }
+
+ public ConsumerInfo getConsumerKeyAndSecret(
+ SecurityToken securityToken, String serviceName, OAuthServiceProvider provider)
+ throws GadgetException {
+ ++consumerKeyLookupCount;
+ BasicOAuthStoreConsumerIndex pk = new BasicOAuthStoreConsumerIndex();
+ pk.setGadgetUri(securityToken.getAppUrl());
+ pk.setServiceName(serviceName);
+ BasicOAuthStoreConsumerKeyAndSecret cks = consumerInfos.get(pk);
+ if (cks == null) {
+ cks = defaultKey;
+ }
+ if (cks == null) {
+ throw new GadgetException(GadgetException.Code.INTERNAL_SERVER_ERROR,
+ "No key for gadget " + securityToken.getAppUrl() + " and service " + serviceName);
+ }
+ OAuthConsumer consumer = null;
+ if (cks.getKeyType() == KeyType.RSA_PRIVATE) {
+ consumer = new OAuthConsumer(null, cks.getConsumerKey(), null, provider);
+ // The oauth.net java code has lots of magic. By setting this property here, code thousands
+ // of lines away knows that the consumerSecret value in the consumer should be treated as
+ // an RSA private key and not an HMAC key.
+ consumer.setProperty(OAuth.OAUTH_SIGNATURE_METHOD, OAuth.RSA_SHA1);
+ consumer.setProperty(RSA_SHA1.PRIVATE_KEY, cks.getConsumerSecret());
+ } else {
+ consumer = new OAuthConsumer(null, cks.getConsumerKey(), cks.getConsumerSecret(), provider);
+ consumer.setProperty(OAuth.OAUTH_SIGNATURE_METHOD, OAuth.HMAC_SHA1);
+ }
+ String callback = (cks.getCallbackUrl() != null ? cks.getCallbackUrl() : defaultCallbackUrl);
+ return new ConsumerInfo(consumer, cks.getKeyName(), callback);
+ }
+
+ private BasicOAuthStoreTokenIndex makeBasicOAuthStoreTokenIndex(
+ SecurityToken securityToken, String serviceName, String tokenName) {
+ BasicOAuthStoreTokenIndex tokenKey = new BasicOAuthStoreTokenIndex();
+ tokenKey.setGadgetUri(securityToken.getAppUrl());
+
+ // TODO: tung.dang need to improve, why moduleId different each time?.
+ //tokenKey.setModuleId(securityToken.getModuleId());
+
+ tokenKey.setServiceName(serviceName);
+ tokenKey.setTokenName(tokenName);
+ tokenKey.setUserId(securityToken.getViewerId());
+ return tokenKey;
+ }
+
+ public TokenInfo getTokenInfo(SecurityToken securityToken, ConsumerInfo consumerInfo,
+ String serviceName, String tokenName) {
+ ++accessTokenLookupCount;
+ BasicOAuthStoreTokenIndex tokenKey =
+ makeBasicOAuthStoreTokenIndex(securityToken, serviceName, tokenName);
+
+ ExoContainer container = PortalContainer.getInstance();
+ GadgetTokenInfoService tokenSer = (GadgetTokenInfoService)container.getComponentInstanceOfType(GadgetTokenInfoService.class);
+ return tokenSer.getToken(tokenKey);
+ }
+
+ public void setTokenInfo(SecurityToken securityToken, ConsumerInfo consumerInfo,
+ String serviceName, String tokenName, TokenInfo tokenInfo) {
+ ++accessTokenAddCount;
+ BasicOAuthStoreTokenIndex tokenKey =
+ makeBasicOAuthStoreTokenIndex(securityToken, serviceName, tokenName);
+ ExoContainer container = PortalContainer.getInstance();
+ GadgetTokenInfoService tokenSer = (GadgetTokenInfoService)container.getComponentInstanceOfType(GadgetTokenInfoService.class);
+ tokenSer.createToken(tokenKey, tokenInfo);
+ }
+
+ public void removeToken(SecurityToken securityToken, ConsumerInfo consumerInfo,
+ String serviceName, String tokenName) {
+ ++accessTokenRemoveCount;
+ BasicOAuthStoreTokenIndex tokenKey =
+ makeBasicOAuthStoreTokenIndex(securityToken, serviceName, tokenName);
+ ExoContainer container = PortalContainer.getInstance();
+ GadgetTokenInfoService tokenSer = (GadgetTokenInfoService)container.getComponentInstanceOfType(GadgetTokenInfoService.class);
+ tokenSer.deleteToken(tokenKey);
+ }
+
+ public int getConsumerKeyLookupCount() {
+ return consumerKeyLookupCount;
+ }
+
+ public int getAccessTokenLookupCount() {
+ return accessTokenLookupCount;
+ }
+
+ public int getAccessTokenAddCount() {
+ return accessTokenAddCount;
+ }
+
+ public int getAccessTokenRemoveCount() {
+ return accessTokenRemoveCount;
+ }
+}
Added: portal/trunk/gadgets/core/src/main/java/org/exoplatform/portal/gadget/core/GadgetToken.java
===================================================================
--- portal/trunk/gadgets/core/src/main/java/org/exoplatform/portal/gadget/core/GadgetToken.java (rev 0)
+++ portal/trunk/gadgets/core/src/main/java/org/exoplatform/portal/gadget/core/GadgetToken.java 2010-01-15 10:13:34 UTC (rev 1309)
@@ -0,0 +1,19 @@
+package org.exoplatform.portal.gadget.core;
+
+import org.apache.shindig.gadgets.oauth.OAuthStore.TokenInfo;
+import org.exoplatform.web.security.Token;
+
+
+public class GadgetToken extends TokenInfo implements Token
+{
+ public GadgetToken(String accessToken, String tokenSecret, String sessionHandle,
+ long tokenExpireMillis)
+ {
+ super(accessToken, tokenSecret, sessionHandle, tokenExpireMillis);
+ }
+
+ public boolean isExpired()
+ {
+ return false;
+ }
+}
Added: portal/trunk/gadgets/core/src/main/java/org/exoplatform/portal/gadget/core/GadgetTokenContainer.java
===================================================================
--- portal/trunk/gadgets/core/src/main/java/org/exoplatform/portal/gadget/core/GadgetTokenContainer.java (rev 0)
+++ portal/trunk/gadgets/core/src/main/java/org/exoplatform/portal/gadget/core/GadgetTokenContainer.java 2010-01-15 10:13:34 UTC (rev 1309)
@@ -0,0 +1,94 @@
+package org.exoplatform.portal.gadget.core;
+
+import org.apache.shindig.gadgets.oauth.BasicOAuthStoreTokenIndex;
+import org.apache.shindig.gadgets.oauth.OAuthStore.TokenInfo;
+import org.chromattic.api.annotations.Create;
+import org.chromattic.api.annotations.OneToMany;
+import org.chromattic.api.annotations.PrimaryType;
+
+import java.util.Map;
+
+@PrimaryType(name = "lgn:gadgettokencontainer")
+public abstract class GadgetTokenContainer
+{
+ @Create
+ protected abstract GadgetTokenEntry createGadgetToken();
+
+ @OneToMany
+ protected abstract Map<String, GadgetTokenEntry> getGadgetTokens();
+
+ public GadgetToken getToken(BasicOAuthStoreTokenIndex tokenKey)
+ {
+ Map<String, GadgetTokenEntry> tokens = getGadgetTokens();
+
+ for (GadgetTokenEntry tokenEntry : tokens.values())
+ {
+ {
+ BasicOAuthStoreTokenIndex key = new BasicOAuthStoreTokenIndex();
+ key.setGadgetUri(tokenEntry.getGadgetUri());
+ key.setModuleId(tokenEntry.getModuleId());
+ key.setServiceName(tokenEntry.getServiceName());
+ key.setTokenName(tokenEntry.getTokenName());
+ key.setUserId(tokenEntry.getUserId());
+ if (tokenKey.equals(key)) return tokenEntry.getToken();
+ }
+ }
+ return null;
+ }
+
+ public GadgetToken removeToken(BasicOAuthStoreTokenIndex tokenKey)
+ {
+ Map<String, GadgetTokenEntry> tokens = getGadgetTokens();
+
+ for (GadgetTokenEntry tokenEntry : tokens.values())
+ {
+ {
+ BasicOAuthStoreTokenIndex key = new BasicOAuthStoreTokenIndex();
+ key.setGadgetUri(tokenEntry.getGadgetUri());
+ key.setModuleId(tokenEntry.getModuleId());
+ key.setServiceName(tokenEntry.getServiceName());
+ key.setTokenName(tokenEntry.getTokenName());
+ key.setUserId(tokenEntry.getUserId());
+ if (tokenKey.equals(key)) tokenEntry.remove();
+ return tokenEntry.getToken();
+ }
+ }
+ return null;
+ }
+
+ public GadgetToken saveToken(BasicOAuthStoreTokenIndex tokenKey, TokenInfo tokenInfo)
+ {
+ Map<String, GadgetTokenEntry> tokens = getGadgetTokens();
+ GadgetTokenEntry entry = null;
+ for (GadgetTokenEntry item : tokens.values())
+ {
+ {
+ BasicOAuthStoreTokenIndex key = new BasicOAuthStoreTokenIndex();
+ key.setGadgetUri(item.getGadgetUri());
+ key.setModuleId(item.getModuleId());
+ key.setServiceName(item.getServiceName());
+ key.setTokenName(item.getTokenName());
+ key.setUserId(item.getUserId());
+ if (tokenKey.equals(key))
+ entry = item;
+ }
+
+ }
+ if (entry == null)
+ {
+ entry = createGadgetToken();
+ tokens.put("gadgettoken" + System.currentTimeMillis(), entry);
+ }
+ entry.setGadgetUri(tokenKey.getGadgetUri());
+ entry.setModuleId(tokenKey.getModuleId());
+ entry.setServiceName(tokenKey.getServiceName());
+ entry.setTokenName(tokenKey.getTokenName());
+ entry.setUserId(tokenKey.getUserId());
+
+ entry.setAccessToken(tokenInfo.getAccessToken());
+ entry.setTokenSecret(tokenInfo.getTokenSecret());
+ entry.setSessionHandle(tokenInfo.getSessionHandle() == null ? "" : tokenInfo.getSessionHandle());
+ entry.setTokenExpireMillis(tokenInfo.getTokenExpireMillis());
+ return entry.getToken();
+ }
+}
\ No newline at end of file
Added: portal/trunk/gadgets/core/src/main/java/org/exoplatform/portal/gadget/core/GadgetTokenEntry.java
===================================================================
--- portal/trunk/gadgets/core/src/main/java/org/exoplatform/portal/gadget/core/GadgetTokenEntry.java (rev 0)
+++ portal/trunk/gadgets/core/src/main/java/org/exoplatform/portal/gadget/core/GadgetTokenEntry.java 2010-01-15 10:13:34 UTC (rev 1309)
@@ -0,0 +1,63 @@
+package org.exoplatform.portal.gadget.core;
+
+import org.chromattic.api.annotations.Destroy;
+import org.chromattic.api.annotations.PrimaryType;
+import org.chromattic.api.annotations.Property;
+
+@PrimaryType(name = "lgn:gadgettoken")
+public abstract class GadgetTokenEntry
+{
+
+ @Property(name = "userId")
+ public abstract String getUserId();
+
+ public abstract void setUserId(String userId);
+
+ @Property(name = "gadgetUri")
+ public abstract String getGadgetUri();
+
+ public abstract void setGadgetUri(String gadgetUri);
+
+ @Property(name = "moduleId")
+ public abstract long getModuleId();
+
+ public abstract void setModuleId(long moduleId);
+
+ @Property(name = "tokenName")
+ public abstract String getTokenName();
+
+ public abstract void setTokenName(String tokenName);
+
+ @Property(name = "serviceName")
+ public abstract String getServiceName();
+
+ public abstract void setServiceName(String serviceName);
+
+ @Property(name = "accessToken")
+ public abstract String getAccessToken();
+
+ public abstract void setAccessToken(String accessToken);
+
+ @Property(name = "tokenSecret")
+ public abstract String getTokenSecret();
+
+ public abstract void setTokenSecret(String tokenSecret);
+
+ @Property(name = "sessionHandle")
+ public abstract String getSessionHandle();
+
+ public abstract void setSessionHandle(String sessionHandle);
+
+ @Property(name = "tokenExpireMillis")
+ public abstract long getTokenExpireMillis();
+
+ public abstract void setTokenExpireMillis(long tokenExpireMillis);
+
+ @Destroy
+ public abstract void remove();
+
+ public GadgetToken getToken()
+ {
+ return new GadgetToken(getAccessToken(), getTokenSecret(), getServiceName(), getTokenExpireMillis());
+ }
+}
Added: portal/trunk/gadgets/core/src/main/java/org/exoplatform/portal/gadget/core/GadgetTokenInfoService.java
===================================================================
--- portal/trunk/gadgets/core/src/main/java/org/exoplatform/portal/gadget/core/GadgetTokenInfoService.java (rev 0)
+++ portal/trunk/gadgets/core/src/main/java/org/exoplatform/portal/gadget/core/GadgetTokenInfoService.java 2010-01-15 10:13:34 UTC (rev 1309)
@@ -0,0 +1,168 @@
+/**
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.exoplatform.portal.gadget.core;
+
+import org.apache.shindig.gadgets.oauth.BasicOAuthStoreTokenIndex;
+import org.apache.shindig.gadgets.oauth.OAuthStore.TokenInfo;
+import org.chromattic.api.ChromatticSession;
+import org.exoplatform.commons.chromattic.ChromatticLifeCycle;
+import org.exoplatform.commons.chromattic.ChromatticManager;
+import org.exoplatform.commons.chromattic.ContextualTask;
+import org.exoplatform.commons.chromattic.SessionContext;
+import org.exoplatform.container.xml.InitParams;
+import org.exoplatform.web.security.Credentials;
+import org.exoplatform.web.security.security.AbstractTokenService;
+
+import java.util.Collection;
+
+public class GadgetTokenInfoService extends AbstractTokenService
+{
+
+ private ChromatticLifeCycle chromatticLifeCycle;
+
+ public GadgetTokenInfoService(InitParams initParams, ChromatticManager chromatticManager)
+ {
+ super(initParams);
+ chromatticLifeCycle = chromatticManager.getLifeCycle("gadgettokens");
+ }
+
+ public GadgetToken createToken(final BasicOAuthStoreTokenIndex key, final TokenInfo tokenInfo)
+ {
+ return new TokenTask<GadgetToken>()
+ {
+ @Override
+ protected GadgetToken execute()
+ {
+ GadgetTokenContainer container = getGadgetTokenContainer();
+ return container.saveToken(key, tokenInfo);
+ }
+ }.executeWith(chromatticLifeCycle);
+ }
+
+ @Override
+ public GadgetToken getToken(final Object key)
+ {
+ return new TokenTask<GadgetToken>()
+ {
+ @Override
+ protected GadgetToken execute()
+ {
+ return getGadgetTokenContainer().getToken((BasicOAuthStoreTokenIndex)key);
+ }
+ }.executeWith(chromatticLifeCycle);
+ }
+
+ @Override
+ public GadgetToken deleteToken(final Object key)
+ {
+ return new TokenTask<GadgetToken>()
+ {
+ @Override
+ protected GadgetToken execute()
+ {
+ return getGadgetTokenContainer().removeToken((BasicOAuthStoreTokenIndex)key);
+ }
+ }.executeWith(chromatticLifeCycle);
+ }
+
+ @Override
+ public GadgetToken[] getAllTokens()
+ {
+ return new TokenTask<GadgetToken[]>()
+ {
+ @Override
+ protected GadgetToken[] execute()
+ {
+ GadgetTokenContainer container = getGadgetTokenContainer();
+ Collection<GadgetTokenEntry> tokens = container.getGadgetTokens().values();
+ GadgetToken[] gadgetTokens = new GadgetToken[9];
+ int count = 0;
+ for(GadgetTokenEntry tokenEntry : tokens) {
+ gadgetTokens[count++] = tokenEntry.getToken();
+ }
+ return gadgetTokens;
+ }
+ }.executeWith(chromatticLifeCycle);
+ }
+
+ @Override
+ public long getNumberTokens() throws Exception
+ {
+ return new TokenTask<Long>()
+ {
+ @Override
+ protected Long execute()
+ {
+ GadgetTokenContainer container = getGadgetTokenContainer();
+ Collection<GadgetTokenEntry> tokens = container.getGadgetTokens().values();
+ return (long)tokens.size();
+ }
+ }.executeWith(chromatticLifeCycle);
+ }
+
+ public String createToken(Credentials credentials) throws IllegalArgumentException, NullPointerException
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+
+ /**
+ * Wraps token store logic conveniently.
+ *
+ * @param <V> the return type
+ */
+ private abstract class TokenTask<V> extends ContextualTask<V>
+ {
+
+ /** . */
+ private SessionContext context;
+
+ protected final GadgetTokenContainer getGadgetTokenContainer()
+ {
+ ChromatticSession session = context.getSession();
+ GadgetTokenContainer container = session.findByPath(GadgetTokenContainer.class, "gadgettokens");
+ if (container == null)
+ {
+ container = session.insert(GadgetTokenContainer.class, "gadgettokens");
+ }
+ return container;
+ }
+
+ @Override
+ protected V execute(SessionContext context)
+ {
+ this.context = context;
+
+ //
+ try
+ {
+ return execute();
+ }
+ finally
+ {
+ this.context = null;
+ }
+ }
+
+ protected abstract V execute();
+
+ }
+}
14 years, 11 months
gatein SVN: r1308 - in portal/trunk: examples/portlets/jsfhellouser and 1 other directories.
by do-not-reply@jboss.org
Author: thomas.heute(a)jboss.com
Date: 2010-01-15 03:36:46 -0500 (Fri, 15 Jan 2010)
New Revision: 1308
Modified:
portal/trunk/examples/portlets/jsfhellouser/pom.xml
portal/trunk/examples/portlets/jsfhellouser/src/main/webapp/WEB-INF/web.xml
portal/trunk/pom.xml
Log:
Update JBoss Portlet Bridge to 1.0.0-CR01
Modified: portal/trunk/examples/portlets/jsfhellouser/pom.xml
===================================================================
--- portal/trunk/examples/portlets/jsfhellouser/pom.xml 2010-01-15 03:41:05 UTC (rev 1307)
+++ portal/trunk/examples/portlets/jsfhellouser/pom.xml 2010-01-15 08:36:46 UTC (rev 1308)
@@ -37,14 +37,17 @@
<scope>provided</scope>
</dependency>
+ <!-- Portlet bridge -->
<dependency>
<groupId>org.jboss.portletbridge</groupId>
<artifactId>portletbridge-api</artifactId>
+ <version>2.0.0.CR1</version>
</dependency>
<dependency>
<groupId>org.jboss.portletbridge</groupId>
<artifactId>portletbridge-impl</artifactId>
+ <version>2.0.0.CR1</version>
</dependency>
</dependencies>
Modified: portal/trunk/examples/portlets/jsfhellouser/src/main/webapp/WEB-INF/web.xml
===================================================================
--- portal/trunk/examples/portlets/jsfhellouser/src/main/webapp/WEB-INF/web.xml 2010-01-15 03:41:05 UTC (rev 1307)
+++ portal/trunk/examples/portlets/jsfhellouser/src/main/webapp/WEB-INF/web.xml 2010-01-15 08:36:46 UTC (rev 1308)
@@ -14,7 +14,7 @@
</context-param>
<context-param>
- <param-name>javax.portlet.faces.renderPolicy</param-name>
+ <param-name>javax.portlet.faces.RENDER_POLICY</param-name>
<param-value>NEVER_DELEGATE</param-value>
</context-param>
Modified: portal/trunk/pom.xml
===================================================================
--- portal/trunk/pom.xml 2010-01-15 03:41:05 UTC (rev 1307)
+++ portal/trunk/pom.xml 2010-01-15 08:36:46 UTC (rev 1308)
@@ -305,19 +305,7 @@
<version>2.0</version>
</dependency>
- <!-- Portlet bridge -->
<dependency>
- <groupId>org.jboss.portletbridge</groupId>
- <artifactId>portletbridge-api</artifactId>
- <version>2.0.0.BETA</version>
- </dependency>
- <dependency>
- <groupId>org.jboss.portletbridge</groupId>
- <artifactId>portletbridge-impl</artifactId>
- <version>2.0.0.BETA</version>
- </dependency>
-
- <dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.2.2</version>
14 years, 11 months
gatein SVN: r1307 - portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/account.
by do-not-reply@jboss.org
Author: truong.le
Date: 2010-01-14 22:41:05 -0500 (Thu, 14 Jan 2010)
New Revision: 1307
Modified:
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/account/UIAccountProfiles.java
Log:
GTNPORTAL-246: Error occur when changing an existing email
Fixed in account setting as well.
Modified: portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/account/UIAccountProfiles.java
===================================================================
--- portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/account/UIAccountProfiles.java 2010-01-15 01:49:36 UTC (rev 1306)
+++ portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/account/UIAccountProfiles.java 2010-01-15 03:41:05 UTC (rev 1307)
@@ -22,6 +22,7 @@
import org.exoplatform.portal.pom.config.Utils;
import org.exoplatform.portal.webui.util.Util;
import org.exoplatform.services.organization.OrganizationService;
+import org.exoplatform.services.organization.Query;
import org.exoplatform.services.organization.User;
import org.exoplatform.web.application.ApplicationMessage;
import org.exoplatform.webui.application.WebuiRequestContext;
@@ -101,9 +102,23 @@
String userName = uiForm.getUIStringInput("userName").getValue();
User user = service.getUserHandler().findUserByName(userName);
+ String oldEmail = user.getEmail();
+ String newEmail = uiForm.getUIStringInput("email").getValue();
+
+ // Check if mail address is already used
+ Query query = new Query();
+ query.setEmail(newEmail);
+ if (service.getUserHandler().findUsers(query).getAll().size() > 0 && !oldEmail.equals(newEmail))
+ {
+ //Be sure it keep old value
+ user.setEmail(oldEmail);
+ Object[] args = {userName};
+ uiApp.addMessage(new ApplicationMessage("UIAccountInputSet.msg.email-exist", args));
+ return;
+ }
user.setFirstName(uiForm.getUIStringInput("firstName").getValue());
user.setLastName(uiForm.getUIStringInput("lastName").getValue());
- user.setEmail(uiForm.getUIStringInput("email").getValue());
+ user.setEmail(newEmail);
uiApp.addMessage(new ApplicationMessage("UIAccountProfiles.msg.update.success", null));
service.getUserHandler().saveUser(user, true);
return;
14 years, 11 months
gatein SVN: r1306 - portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/portal.
by do-not-reply@jboss.org
Author: truong.le
Date: 2010-01-14 20:49:36 -0500 (Thu, 14 Jan 2010)
New Revision: 1306
Modified:
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/portal/UIPortalForm.java
Log:
GTNPORTAL-419: Always show language of old portal when create new portal
Modified: portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/portal/UIPortalForm.java
===================================================================
--- portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/portal/UIPortalForm.java 2010-01-14 21:34:16 UTC (rev 1305)
+++ portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/portal/UIPortalForm.java 2010-01-15 01:49:36 UTC (rev 1306)
@@ -161,6 +161,11 @@
invokeGetBindingBean(editPortal);
((UIFormStringInput)getChild(UIFormInputSet.class).getChildById(FIELD_NAME)).setValue(getPortalOwner());
+
+
+ LocaleConfigService localeConfigService = getApplicationComponent(LocaleConfigService.class);
+ LocaleConfig localeConfig = localeConfigService.getLocaleConfig(editPortal.getLocale());
+ this.<UIFormInputSet> getChildById("PortalSetting").<UIFormSelectBox>getChildById(FIELD_LOCALE).setValue(localeConfig.getLanguage());
setActions(new String[]{"Save", "Close"});
}
@@ -178,16 +183,17 @@
UIPortal uiPortal = Util.getUIPortal();
LocaleConfigService localeConfigService = getApplicationComponent(LocaleConfigService.class);
Collection<?> listLocaleConfig = localeConfigService.getLocalConfigs();
+ LocaleConfig defaultLocale = localeConfigService.getDefaultLocaleConfig();
+ String defaultLanguage = defaultLocale.getLanguage();
Locale currentLocate = Util.getPortalRequestContext().getLocale();
Iterator<?> iterator = listLocaleConfig.iterator();
while (iterator.hasNext())
{
LocaleConfig localeConfig = (LocaleConfig)iterator.next();
- Locale locale = localeConfig.getLocale();
SelectItemOption<String> option =
new SelectItemOption<String>(localeConfig.getLocale().getDisplayName(currentLocate), localeConfig
.getLanguage());
- if (locale.getLanguage().equalsIgnoreCase(uiPortal.getLocale()))
+ if(defaultLanguage.equals(localeConfig.getLanguage()))
{
option.setSelected(true);
}
14 years, 11 months
gatein SVN: r1305 - components/pc/trunk/federation/src/main/java/org/gatein/pc/federation/impl.
by do-not-reply@jboss.org
Author: chris.laprun(a)jboss.com
Date: 2010-01-14 16:34:16 -0500 (Thu, 14 Jan 2010)
New Revision: 1305
Modified:
components/pc/trunk/federation/src/main/java/org/gatein/pc/federation/impl/FederatingPortletInvokerService.java
Log:
- Made getFederatedPortletInvokerFor method protected so that subclasses can override the resolution behavior if needed.
Modified: components/pc/trunk/federation/src/main/java/org/gatein/pc/federation/impl/FederatingPortletInvokerService.java
===================================================================
--- components/pc/trunk/federation/src/main/java/org/gatein/pc/federation/impl/FederatingPortletInvokerService.java 2010-01-14 21:06:50 UTC (rev 1304)
+++ components/pc/trunk/federation/src/main/java/org/gatein/pc/federation/impl/FederatingPortletInvokerService.java 2010-01-14 21:34:16 UTC (rev 1305)
@@ -1,25 +1,25 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
- * contributors as indicated by the @authors tag. See the *
- * copyright.txt in the distribution for a full listing of *
- * individual contributors. *
- * *
- * This is free software; you can redistribute it and/or modify it *
- * under the terms of the GNU Lesser General Public License as *
- * published by the Free Software Foundation; either version 2.1 of *
- * the License, or (at your option) any later version. *
- * *
- * This software is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this software; if not, write to the Free *
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
- ******************************************************************************/
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2010, Red Hat Middleware, LLC, and individual
+ * contributors as indicated by the @authors tag. See the
+ * copyright.txt in the distribution for a full listing of
+ * individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
package org.gatein.pc.federation.impl;
import org.apache.log4j.Logger;
@@ -237,7 +237,7 @@
* @throws IllegalArgumentException if the compound portlet id is not well formed or null
* @throws NoSuchPortletException if not such portlet exist
*/
- private FederatedPortletInvoker getFederatedPortletInvokerFor(PortletContext compoundPortletContext) throws IllegalArgumentException, NoSuchPortletException
+ protected FederatedPortletInvoker getFederatedPortletInvokerFor(PortletContext compoundPortletContext) throws IllegalArgumentException, NoSuchPortletException
{
if (compoundPortletContext == null)
{
14 years, 11 months
gatein SVN: r1304 - portal/trunk/component/application-registry/src/main/java/org/exoplatform/application/registry/impl.
by do-not-reply@jboss.org
Author: thomas.heute(a)jboss.com
Date: 2010-01-14 16:06:50 -0500 (Thu, 14 Jan 2010)
New Revision: 1304
Modified:
portal/trunk/component/application-registry/src/main/java/org/exoplatform/application/registry/impl/CategoryDefinition.java
Log:
Using MOPFormatter to get rid of potentially harmful characters such as ':'
Modified: portal/trunk/component/application-registry/src/main/java/org/exoplatform/application/registry/impl/CategoryDefinition.java
===================================================================
--- portal/trunk/component/application-registry/src/main/java/org/exoplatform/application/registry/impl/CategoryDefinition.java 2010-01-14 20:13:20 UTC (rev 1303)
+++ portal/trunk/component/application-registry/src/main/java/org/exoplatform/application/registry/impl/CategoryDefinition.java 2010-01-14 21:06:50 UTC (rev 1304)
@@ -19,6 +19,7 @@
package org.exoplatform.application.registry.impl;
import org.chromattic.api.annotations.Create;
+import org.chromattic.api.annotations.FormattedBy;
import org.chromattic.api.annotations.Name;
import org.chromattic.api.annotations.PrimaryType;
import org.chromattic.api.annotations.OneToMany;
@@ -27,6 +28,7 @@
import org.gatein.mop.api.content.ContentType;
import org.gatein.mop.api.content.Customization;
import org.gatein.mop.api.workspace.Workspace;
+import org.gatein.mop.core.api.MOPFormatter;
import java.util.Date;
import java.util.List;
@@ -37,6 +39,7 @@
* @version $Revision$
*/
@PrimaryType(name = "app:contentcategory")
+(a)FormattedBy(MOPFormatter.class)
public abstract class CategoryDefinition
{
14 years, 11 months
gatein SVN: r1303 - portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/model.
by do-not-reply@jboss.org
Author: julien_viet
Date: 2010-01-14 15:13:20 -0500 (Thu, 14 Jan 2010)
New Revision: 1303
Modified:
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/model/ClassTypeModel.java
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/model/FieldModel.java
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/model/SerializableTypeModel.java
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/model/TypeDomain.java
Log:
minor
Modified: portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/model/ClassTypeModel.java
===================================================================
--- portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/model/ClassTypeModel.java 2010-01-14 19:52:25 UTC (rev 1302)
+++ portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/model/ClassTypeModel.java 2010-01-14 20:13:20 UTC (rev 1303)
@@ -27,7 +27,7 @@
* @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a>
* @version $Revision$
*/
-public class ClassTypeModel<O> extends TypeModel
+public final class ClassTypeModel<O> extends TypeModel
{
/** . */
Modified: portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/model/FieldModel.java
===================================================================
--- portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/model/FieldModel.java 2010-01-14 19:52:25 UTC (rev 1302)
+++ portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/model/FieldModel.java 2010-01-14 20:13:20 UTC (rev 1303)
@@ -25,7 +25,7 @@
* @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a>
* @version $Revision$
*/
-public class FieldModel
+public final class FieldModel
{
/** . */
@@ -34,7 +34,7 @@
/** . */
private final TypeModel type;
- public FieldModel(Field field, TypeModel type)
+ FieldModel(Field field, TypeModel type)
{
this.field = field;
this.type = type;
Modified: portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/model/SerializableTypeModel.java
===================================================================
--- portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/model/SerializableTypeModel.java 2010-01-14 19:52:25 UTC (rev 1302)
+++ portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/model/SerializableTypeModel.java 2010-01-14 20:13:20 UTC (rev 1303)
@@ -25,7 +25,7 @@
* @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a>
* @version $Revision$
*/
-public class SerializableTypeModel extends TypeModel
+public final class SerializableTypeModel extends TypeModel
{
SerializableTypeModel(Class<? extends Serializable> serializable)
{
Modified: portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/model/TypeDomain.java
===================================================================
--- portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/model/TypeDomain.java 2010-01-14 19:52:25 UTC (rev 1302)
+++ portal/trunk/webui/core/src/main/java/org/exoplatform/webui/application/replication/model/TypeDomain.java 2010-01-14 20:13:20 UTC (rev 1303)
@@ -29,7 +29,7 @@
* @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a>
* @version $Revision$
*/
-public class TypeDomain
+public final class TypeDomain
{
/** . */
14 years, 11 months