Author: ndkhoiits
Date: 2011-01-12 09:26:07 -0500 (Wed, 12 Jan 2011)
New Revision: 5735
Added:
exo/portal/branches/3.1.x/component/identity/src/main/java/org/exoplatform/services/organization/idm/IntegrationCache.java
exo/portal/branches/3.1.x/component/identity/src/main/java/org/exoplatform/services/organization/idm/Tools.java
Modified:
exo/portal/branches/3.1.x/component/identity/src/main/java/org/exoplatform/services/organization/idm/GroupDAOImpl.java
exo/portal/branches/3.1.x/component/identity/src/main/java/org/exoplatform/services/organization/idm/IDMUserListAccess.java
exo/portal/branches/3.1.x/component/identity/src/main/java/org/exoplatform/services/organization/idm/MembershipDAOImpl.java
exo/portal/branches/3.1.x/component/identity/src/main/java/org/exoplatform/services/organization/idm/MembershipImpl.java
exo/portal/branches/3.1.x/component/identity/src/main/java/org/exoplatform/services/organization/idm/MembershipTypeDAOImpl.java
exo/portal/branches/3.1.x/component/identity/src/main/java/org/exoplatform/services/organization/idm/PicketLinkIDMCacheService.java
exo/portal/branches/3.1.x/component/identity/src/main/java/org/exoplatform/services/organization/idm/PicketLinkIDMOrganizationServiceImpl.java
exo/portal/branches/3.1.x/component/identity/src/main/java/org/exoplatform/services/organization/idm/PicketLinkIDMServiceImpl.java
exo/portal/branches/3.1.x/component/identity/src/main/java/org/exoplatform/services/organization/idm/UserDAOImpl.java
exo/portal/branches/3.1.x/pom.xml
Log:
EXOGTN-205 Port lastest IDM changes
Modified:
exo/portal/branches/3.1.x/component/identity/src/main/java/org/exoplatform/services/organization/idm/GroupDAOImpl.java
===================================================================
---
exo/portal/branches/3.1.x/component/identity/src/main/java/org/exoplatform/services/organization/idm/GroupDAOImpl.java 2011-01-12
11:04:03 UTC (rev 5734)
+++
exo/portal/branches/3.1.x/component/identity/src/main/java/org/exoplatform/services/organization/idm/GroupDAOImpl.java 2011-01-12
14:26:07 UTC (rev 5735)
@@ -22,6 +22,9 @@
import org.exoplatform.services.organization.Group;
import org.exoplatform.services.organization.GroupEventListener;
import org.exoplatform.services.organization.GroupHandler;
+import org.gatein.common.logging.LogLevel;
+import org.gatein.common.logging.Logger;
+import org.gatein.common.logging.LoggerFactory;
import org.picketlink.idm.api.Attribute;
import org.picketlink.idm.api.IdentitySession;
import org.picketlink.idm.impl.api.SimpleAttribute;
@@ -35,10 +38,10 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+
+
/*
* @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
*/
@@ -57,6 +60,8 @@
private PicketLinkIDMOrganizationServiceImpl orgService;
+ private static final String CYCLIC_ID =
"org.gatein.portal.identity.LOOPED_GROUP_ID";
+
public GroupDAOImpl(PicketLinkIDMOrganizationServiceImpl orgService,
PicketLinkIDMService service)
{
service_ = service;
@@ -71,16 +76,50 @@
final public Group createGroupInstance()
{
+ if (log.isTraceEnabled())
+ {
+ Tools.logMethodIn(
+ log,
+ LogLevel.TRACE,
+ "createGroupInstance",
+ null
+ );
+ }
return new ExtGroup();
}
public void createGroup(Group group, boolean broadcast) throws Exception
{
+ if (log.isTraceEnabled())
+ {
+ Tools.logMethodIn(
+ log,
+ LogLevel.TRACE,
+ "createGroup",
+ new Object[]{
+ "broadcast", broadcast
+ }
+ );
+ }
addChild(null, group, broadcast);
}
public void addChild(Group parent, Group child, boolean broadcast) throws Exception
{
+ if (log.isTraceEnabled())
+ {
+ Tools.logMethodIn(
+ log,
+ LogLevel.TRACE,
+ "addChild",
+ new Object[]{
+ "parent", parent,
+ "child", child,
+ "broadcast", broadcast
+ }
+ );
+ }
+
org.picketlink.idm.api.Group parentGroup = null;
String childPLGroupName = getPLIDMGroupName(child.getGroupName());
@@ -146,6 +185,19 @@
public void saveGroup(Group group, boolean broadcast) throws Exception
{
+ if (log.isTraceEnabled())
+ {
+ Tools.logMethodIn(
+ log,
+ LogLevel.TRACE,
+ "saveGroup",
+ new Object[]{
+ "group", group,
+ "broadcast", broadcast
+ }
+ );
+ }
+
if (broadcast)
{
preSave(group, false);
@@ -159,6 +211,19 @@
public Group removeGroup(Group group, boolean broadcast) throws Exception
{
+ if (log.isTraceEnabled())
+ {
+ Tools.logMethodIn(
+ log,
+ LogLevel.TRACE,
+ "removeGroup",
+ new Object[]{
+ "group", group,
+ "broadcast", broadcast
+ }
+ );
+ }
+
if (broadcast)
{
preDelete(group);
@@ -210,6 +275,7 @@
try
{
getIdentitySession().getPersistenceManager().removeGroup(jbidGroup, true);
+
}
catch (Exception e)
{
@@ -225,6 +291,19 @@
public Collection findGroupByMembership(String userName, String membershipType) throws
Exception
{
+ if (log.isTraceEnabled())
+ {
+ Tools.logMethodIn(
+ log,
+ LogLevel.TRACE,
+ "findGroupsByMembership",
+ new Object[]{
+ "userName", membershipType
+ }
+ );
+ }
+
+
Collection<org.picketlink.idm.api.Role> allRoles = new HashSet();
try
@@ -269,25 +348,84 @@
}
// UI has hardcoded casts to List
- return new LinkedList<Group>(exoGroups);
+ Collection result = new LinkedList<Group>(exoGroups);
+
+ if (log.isTraceEnabled())
+ {
+ Tools.logMethodOut(
+ log,
+ LogLevel.TRACE,
+ "findGroupByMembership",
+ result
+ );
+ }
+
+ return result;
}
//
public Group findGroupById(String groupId) throws Exception
{
+ if (log.isTraceEnabled())
+ {
+ Tools.logMethodIn(
+ log,
+ LogLevel.TRACE,
+ "findGroupById",
+ new Object[]{
+ "groupId", groupId
+ }
+ );
+ }
+
org.picketlink.idm.api.Group jbidGroup = orgService.getJBIDMGroup(groupId);
if (jbidGroup == null)
{
+ if (log.isTraceEnabled())
+ {
+ Tools.logMethodOut(
+ log,
+ LogLevel.TRACE,
+ "findGroupById",
+ null
+ );
+ }
+
return null;
}
- return convertGroup(jbidGroup);
+ Group result = convertGroup(jbidGroup);
+
+ if (log.isTraceEnabled())
+ {
+ Tools.logMethodOut(
+ log,
+ LogLevel.TRACE,
+ "findGroupById",
+ result
+ );
+ }
+
+ return result;
+
}
public Collection findGroups(Group parent) throws Exception
{
+ if (log.isTraceEnabled())
+ {
+ Tools.logMethodIn(
+ log,
+ LogLevel.TRACE,
+ "findGroups",
+ new Object[]{
+ "parent", parent
+ }
+ );
+ }
+
org.picketlink.idm.api.Group jbidGroup = null;
if (parent == null)
@@ -370,7 +508,8 @@
{
String id = g.getParentId();
if ((parent == null && id == null)
- || (id != null && id.equals(parent.getId())))
+ || (parent != null && id != null &&
id.equals(parent.getId()))
+ || (parent == null && id != null &&
id.equals("/")))
{
exoGroups.add(g);
continue;
@@ -392,6 +531,16 @@
Collections.sort(results);
}
+ if (log.isTraceEnabled())
+ {
+ Tools.logMethodOut(
+ log,
+ LogLevel.TRACE,
+ "findGroups",
+ results
+ );
+ }
+
return results;
}
@@ -399,6 +548,19 @@
public Collection findGroupsOfUser(String user) throws Exception
{
+ if (log.isTraceEnabled())
+ {
+ Tools.logMethodIn(
+ log,
+ LogLevel.TRACE,
+ "findGroupsOfUser",
+ new Object[]{
+ "user", user
+ }
+ );
+ }
+
+
if (user == null)
{
// julien : integration bug
@@ -411,6 +573,17 @@
// at
org.exoplatform.organization.webui.component.GroupManagement.isMemberOfGroup(GroupManagement.java:72)
// at
org.exoplatform.organization.webui.component.GroupManagement.isAdministrator(GroupManagement.java:125)
// at
org.exoplatform.organization.webui.component.UIGroupExplorer.<init>(UIGroupExplorer.java:57)
+
+ if (log.isTraceEnabled())
+ {
+ Tools.logMethodOut(
+ log,
+ LogLevel.TRACE,
+ "findGroupsOfUser",
+ Collections.emptyList()
+ );
+ }
+
return Collections.emptyList();
}
@@ -435,12 +608,32 @@
}
+ if (log.isTraceEnabled())
+ {
+ Tools.logMethodOut(
+ log,
+ LogLevel.TRACE,
+ "findGroupsOfUser",
+ exoGroups
+ );
+ }
+
return exoGroups;
}
public Collection getAllGroups() throws Exception
{
+ if (log.isTraceEnabled())
+ {
+ Tools.logMethodIn(
+ log,
+ LogLevel.TRACE,
+ "getAllGroups",
+ null
+ );
+ }
+
Set<org.picketlink.idm.api.Group> plGroups = new
HashSet<org.picketlink.idm.api.Group>();
try
@@ -486,7 +679,19 @@
}
// UI has hardcoded casts to List
- return new LinkedList<Group>(exoGroups);
+ Collection result = new LinkedList<Group>(exoGroups);
+
+ if (log.isTraceEnabled())
+ {
+ Tools.logMethodOut(
+ log,
+ LogLevel.TRACE,
+ "getAllGroups",
+ result
+ );
+ }
+
+ return result;
}
@@ -525,6 +730,18 @@
protected Group convertGroup(org.picketlink.idm.api.Group jbidGroup) throws Exception
{
+ if (log.isTraceEnabled())
+ {
+ Tools.logMethodIn(
+ log,
+ LogLevel.TRACE,
+ "convertGroup",
+ new Object[]{
+ "jbidGroup", jbidGroup
+ }
+ );
+ }
+
Map<String, Attribute> attrs = new HashMap();
try
@@ -556,8 +773,18 @@
}
// Resolve full ID
- String id = getGroupId(jbidGroup);
+ String id = getGroupId(jbidGroup, null);
+ if (log.isTraceEnabled())
+ {
+ Tools.logMethodOut(
+ log,
+ LogLevel.TRACE,
+ "getGroupId",
+ id
+ );
+ }
+
exoGroup.setId(id);
// child of root
@@ -571,16 +798,71 @@
exoGroup.setParentId(id.substring(0, id.lastIndexOf("/")));
}
+ if (log.isTraceEnabled())
+ {
+ Tools.logMethodOut(
+ log,
+ LogLevel.TRACE,
+ "convertGroup",
+ exoGroup
+ );
+ }
+
return exoGroup;
}
- private String getGroupId(org.picketlink.idm.api.Group jbidGroup) throws Exception
+ /**
+ * Calculates group id by checking all parents up to the root group or group type
mapping from the configuration.
+ *
+ * @param jbidGroup
+ * @param processed
+ * @return
+ * @throws Exception
+ */
+ private String getGroupId(org.picketlink.idm.api.Group jbidGroup,
+ List<org.picketlink.idm.api.Group> processed) throws
Exception
{
+ if (log.isTraceEnabled())
+ {
+ Tools.logMethodIn(
+ log,
+ LogLevel.TRACE,
+ "getGroupId",
+ new Object[]{
+ "jbidGroup", jbidGroup,
+ "processed", processed
+ }
+ );
+ }
+
+
+ // Check in cache
+ if (getIntegrationCache() != null)
+ {
+ String cachedId = getIntegrationCache().getGtnGroupId(getCacheNS(),
jbidGroup.getKey());
+ if (cachedId != null)
+ {
+ return cachedId;
+ }
+ }
+
if (jbidGroup.equals(getRootGroup()))
{
- return "";
+ String calculatedId = "";
+
+ if (getIntegrationCache() != null)
+ {
+ getIntegrationCache().putGtnGroupId(getCacheNS(), jbidGroup.getKey(),
calculatedId);
+ }
+
+ return calculatedId;
}
+ if (processed == null)
+ {
+ processed = new LinkedList<org.picketlink.idm.api.Group>();
+ }
+
Collection<org.picketlink.idm.api.Group> parents = new HashSet();
String gtnGroupName = getGtnGroupName(jbidGroup.getName());
@@ -595,7 +877,17 @@
log.info("Identity operation error: ", e);
}
-
+ // Check if there is cross reference so we ended in a loop and break the process.
+ if (parents.size() > 0 &&
processed.contains(parents.iterator().next()))
+ {
+ if (log.isTraceEnabled())
+ {
+ log.trace("Detected looped relationship between groups!!!");
+ }
+ processed.remove(processed.size() - 1);
+ return CYCLIC_ID;
+ }
+ // If there are no parents or more then one parent
if (parents.size() == 0 || parents.size() > 1)
{
@@ -605,34 +897,86 @@
"defined by type mappings or just place it under root /");
}
+ String calculatedId = obtainMappedId(jbidGroup, gtnGroupName);
- String id =
orgService.getConfiguration().getParentId(jbidGroup.getGroupType());
+ if (getIntegrationCache() != null)
+ {
+ getIntegrationCache().putGtnGroupId(getCacheNS(), jbidGroup.getKey(),
calculatedId);
+ }
+ return calculatedId;
- if (id != null &&
orgService.getConfiguration().isForceMembershipOfMappedTypes())
+ }
+
+ processed.add(jbidGroup);
+ String parentGroupId =
getGroupId(((org.picketlink.idm.api.Group)parents.iterator().next()),processed);
+
+ // Check if loop occured
+ if (parentGroupId.equals(CYCLIC_ID))
+ {
+ // if there are still processed groups in the list we are in nested call so
remove last one and go back
+ if (processed.size() > 0)
{
- if (id.endsWith("/*"))
+ processed.remove(processed.size() - 1);
+ return parentGroupId;
+ }
+ // if we finally reached the first group from the looped ones then just return
id calculated from
+ // mappings or connect it to the root
+ else
+ {
+ String calculatedId = obtainMappedId(jbidGroup, gtnGroupName);
+
+ if (getIntegrationCache() != null)
{
- id = id.substring(0, id.length() - 2);
+ getIntegrationCache().putGtnGroupId(getCacheNS(), jbidGroup.getKey(),
calculatedId);
}
- return id + "/" + gtnGroupName;
+ return calculatedId;
}
+ }
- // All groups not connected to the root should be just below the root
- return "/" + gtnGroupName;
+ String calculatedId = parentGroupId + "/" + gtnGroupName;
- //TODO: make it configurable
- // throw new IllegalStateException("Group present that is not connected to
the root: " + jbidGroup.getName());
+ if (getIntegrationCache() != null)
+ {
+ getIntegrationCache().putGtnGroupId(getCacheNS(), jbidGroup.getKey(),
calculatedId);
+ }
+ return calculatedId;
+
+ }
+
+ /**
+ * Obtain group id based on groupType mapping from configuration or if this fails just
place it under root /
+ *
+ * @param jbidGroup
+ * @param gtnGroupName
+ * @return
+ */
+ private String obtainMappedId(org.picketlink.idm.api.Group jbidGroup, String
gtnGroupName)
+ {
+ String id = orgService.getConfiguration().getParentId(jbidGroup.getGroupType());
+
+
+
+ if (id != null &&
orgService.getConfiguration().isForceMembershipOfMappedTypes())
+ {
+ if (id.endsWith("/*"))
+ {
+ id = id.substring(0, id.length() - 2);
+ }
+
+ return id + "/" + gtnGroupName;
}
- String parentGroupId =
getGroupId(((org.picketlink.idm.api.Group)parents.iterator().next()));
- return parentGroupId + "/" + gtnGroupName;
+ // All groups not connected to the root should be just below the root
+ return "/" + gtnGroupName;
+ //TODO: make it configurable
+ // throw new IllegalStateException("Group present that is not connected to the
root: " + jbidGroup.getName());
}
private org.picketlink.idm.api.Group persistGroup(Group exoGroup) throws Exception
@@ -708,8 +1052,61 @@
return service_.getIdentitySession();
}
- private org.picketlink.idm.api.Group getRootGroup() throws Exception
+ private IntegrationCache getIntegrationCache()
{
+ // TODO: refactor to remove cast. For now to avoid adding new config option and
share existing cache instannce
+ // TODO: it should be there.
+ return ((PicketLinkIDMServiceImpl)service_).getIntegrationCache();
+ }
+
+ /**
+ * Returns namespace to be used with integration cache
+ * @return
+ */
+ private String getCacheNS()
+ {
+ // TODO: refactor to remove cast. For now to avoid adding new config option and
share existing cache instannce
+ // TODO: it should be there.
+ return ((PicketLinkIDMServiceImpl)service_).getRealmName();
+ }
+
+
+ /**
+ * Returns mock of PLIDM group representing "/" group. This method uses
cache and delegates to obtainRootGroup().
+ *
+ * @return
+ * @throws Exception
+ */
+ protected org.picketlink.idm.api.Group getRootGroup() throws Exception
+ {
+ org.picketlink.idm.api.Group rootGroup = null;
+
+ if (getIntegrationCache() != null)
+ {
+ rootGroup = getIntegrationCache().getRootGroup(getCacheNS());
+ }
+
+ if (rootGroup == null)
+ {
+ rootGroup = obtainRootGroup();
+
+ if (getIntegrationCache() != null)
+ {
+ getIntegrationCache().putRootGroup(getCacheNS(), rootGroup);
+ }
+ }
+
+ return rootGroup;
+
+ }
+
+ /**
+ * Obtains PLIDM group representing "/" group. If such group doens't
exist it creates one.
+ * @return
+ * @throws Exception
+ */
+ protected org.picketlink.idm.api.Group obtainRootGroup() throws Exception
+ {
org.picketlink.idm.api.Group rootGroup = null;
try
{
Modified:
exo/portal/branches/3.1.x/component/identity/src/main/java/org/exoplatform/services/organization/idm/IDMUserListAccess.java
===================================================================
---
exo/portal/branches/3.1.x/component/identity/src/main/java/org/exoplatform/services/organization/idm/IDMUserListAccess.java 2011-01-12
11:04:03 UTC (rev 5734)
+++
exo/portal/branches/3.1.x/component/identity/src/main/java/org/exoplatform/services/organization/idm/IDMUserListAccess.java 2011-01-12
14:26:07 UTC (rev 5735)
@@ -21,10 +21,14 @@
import org.exoplatform.commons.utils.ListAccess;
import org.exoplatform.services.organization.User;
+import org.gatein.common.logging.LogLevel;
+import org.gatein.common.logging.Logger;
+import org.gatein.common.logging.LoggerFactory;
import org.picketlink.idm.api.SortOrder;
import org.picketlink.idm.api.query.UserQuery;
import org.picketlink.idm.api.query.UserQueryBuilder;
+
import java.util.List;
/*
@@ -32,6 +36,8 @@
*/
public class IDMUserListAccess implements ListAccess<User>
{
+ private static Logger log = LoggerFactory.getLogger(IDMUserListAccess.class);
+
private final UserDAOImpl userDAO;
private final PicketLinkIDMService idmService;
@@ -54,6 +60,19 @@
public User[] load(int index, int length) throws Exception, IllegalArgumentException
{
+ if (log.isTraceEnabled())
+ {
+ Tools.logMethodIn(
+ log,
+ LogLevel.TRACE,
+ "load",
+ new Object[]{
+ "index", index,
+ "length", length
+ }
+ );
+ }
+
userQueryBuilder.page(index, length);
UserQuery query = userQueryBuilder.sort(SortOrder.ASCENDING).createQuery();
List<org.picketlink.idm.api.User> users =
idmService.getIdentitySession().list(query);
@@ -67,21 +86,55 @@
exoUsers[i] = UserDAOImpl.getPopulatedUser(user.getId(),
idmService.getIdentitySession());
}
+ if (log.isTraceEnabled())
+ {
+ Tools.logMethodOut(
+ log,
+ LogLevel.TRACE,
+ "load",
+ exoUsers
+ );
+ }
+
return exoUsers;
}
public int getSize() throws Exception
{
+ if (log.isTraceEnabled())
+ {
+ Tools.logMethodIn(
+ log,
+ LogLevel.TRACE,
+ "getSize",
+ null
+ );
+ }
+
+ int result;
+
if (countAll)
{
- return idmService.getIdentitySession().getPersistenceManager().getUserCount();
+ result =
idmService.getIdentitySession().getPersistenceManager().getUserCount();
}
else
{
userQueryBuilder.page(0, 0);
UserQuery query = userQueryBuilder.sort(SortOrder.ASCENDING).createQuery();
- return idmService.getIdentitySession().execute(query).size();
+ result = idmService.getIdentitySession().execute(query).size();
}
+ if (log.isTraceEnabled())
+ {
+ Tools.logMethodOut(
+ log,
+ LogLevel.TRACE,
+ "getSize",
+ result
+ );
+ }
+
+ return result;
+
}
}
Copied:
exo/portal/branches/3.1.x/component/identity/src/main/java/org/exoplatform/services/organization/idm/IntegrationCache.java
(from rev 5221,
portal/trunk/component/identity/src/main/java/org/exoplatform/services/organization/idm/IntegrationCache.java)
===================================================================
---
exo/portal/branches/3.1.x/component/identity/src/main/java/org/exoplatform/services/organization/idm/IntegrationCache.java
(rev 0)
+++
exo/portal/branches/3.1.x/component/identity/src/main/java/org/exoplatform/services/organization/idm/IntegrationCache.java 2011-01-12
14:26:07 UTC (rev 5735)
@@ -0,0 +1,245 @@
+package org.exoplatform.services.organization.idm;
+
+import org.jboss.cache.Cache;
+import org.jboss.cache.CacheFactory;
+import org.jboss.cache.CacheStatus;
+import org.jboss.cache.DefaultCacheFactory;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.Node;
+import org.picketlink.idm.api.Group;
+import org.picketlink.idm.api.User;
+
+import java.io.InputStream;
+import java.util.Collection;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/*
+* 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.
+*/
+
+/**
+ * Provides cache for some data used in integration layer between PicketLink IDM and
GateIn
+ */
+public class IntegrationCache
+{
+ private static Logger log = Logger.getLogger(IntegrationCache.class.getName());
+
+ private Cache cache;
+
+ public static final String NODE_GTN_GROUP_ID = "NODE_GTN_GROUP_ID";
+
+ public static final String NODE_PLIDM_ROOT_GROUP = "NODE_PLIDM_ROOT_GROUP";
+
+ public static final String NULL_NS_NODE = "GTN_IC_COMMON_NS";
+
+ public static final String MAIN_ROOT =
"NODE_GTN_ORG_SERVICE_INT_CACHE_MAIN_ROOT";
+
+ public static final String NODE_OBJECT_KEY = "object";
+
+ private Fqn getRootNode()
+ {
+ return Fqn.fromString("/" + MAIN_ROOT);
+ }
+
+ private Fqn getNamespacedFqn(String ns)
+ {
+ String namespace = ns != null ? ns : NULL_NS_NODE;
+ namespace = namespace.replaceAll("/", "_");
+ return Fqn.fromString(getRootNode() + "/" + namespace);
+ }
+
+ private Fqn getFqn(String ns, String node, Object o)
+ {
+ return Fqn.fromString(getNamespacedFqn(ns) + "/" + node + "/" +
o);
+ }
+
+ private Fqn getFqn(String ns, String node)
+ {
+ return Fqn.fromString(getNamespacedFqn(ns) + "/" + node);
+ }
+
+ public void initialize(InputStream jbossCacheConfiguration)
+ {
+ CacheFactory factory = new DefaultCacheFactory();
+
+ if (jbossCacheConfiguration == null)
+ {
+ throw new IllegalArgumentException("JBoss Cache configuration InputStream
is null");
+ }
+
+ this.cache = factory.createCache(jbossCacheConfiguration);
+
+ this.cache.create();
+ this.cache.start();
+
+ }
+
+ public void initialize(Cache cache)
+ {
+ this.cache = cache;
+
+ CacheStatus status = cache.getCacheStatus();
+
+ if (status.createAllowed())
+ {
+ this.cache.create();
+ }
+ if (status.startAllowed())
+ {
+ this.cache.start();
+ }
+
+ }
+
+ Cache getCache()
+ {
+ return cache;
+ }
+
+
+ public void invalidate(String ns)
+ {
+
+ boolean success = cache.getRoot().removeChild(getNamespacedFqn(ns));
+
+ if (log.isLoggable(Level.FINER))
+ {
+ log.finer(this.toString() + "Invalidating namespace:" + ns + ";
success=" + success);
+ }
+ }
+
+ public void invalidateAll()
+ {
+ boolean success = cache.getRoot().removeChild(getRootNode());
+
+ if (log.isLoggable(Level.FINER))
+ {
+ log.finer(this.toString() + "Invalidating whole cache - success=" +
success);
+ }
+ }
+
+ /**
+ * Store gatein group id
+ * @param ns
+ * @param pLIDMId
+ * @param id
+ */
+ void putGtnGroupId(String ns, String pLIDMId, String id)
+ {
+ Fqn nodeFqn = getFqn(ns, NODE_GTN_GROUP_ID, pLIDMId);
+
+ Node ioNode = getCache().getRoot().addChild(nodeFqn);
+
+ if (ioNode != null)
+ {
+ ioNode.put(NODE_OBJECT_KEY, id);
+
+ if (log.isLoggable(Level.FINER))
+ {
+
+ log.finer(this.toString() + "GateIn group id cached. PLIDM group id:
" + pLIDMId +
+ "GateIn group id: " + id + ";namespace=" + ns);
+ }
+ }
+ }
+
+ /**
+ * Retrieve gatein group id
+ * @param ns
+ * @param pLIDMId
+ * @return
+ */
+ String getGtnGroupId(String ns, String pLIDMId)
+ {
+
+ Fqn nodeFqn = getFqn(ns, NODE_GTN_GROUP_ID, pLIDMId);
+
+ Node node = getCache().getRoot().getChild(nodeFqn);
+
+ if (node != null)
+ {
+ String id = (String)node.get(NODE_OBJECT_KEY);
+
+ if (log.isLoggable(Level.FINER) && id != null)
+ {
+ log.finer(this.toString() + "GateIn group id found in cache. PLIDM group
id: " + pLIDMId +
+ "GateIn group id: " + id + ";namespace=" + ns);
+ }
+
+ return id;
+ }
+
+ return null;
+
+ }
+
+ /**
+ * Store PLIDM root group
+ * @param ns
+ * @param rootGroup
+ */
+ void putRootGroup(String ns, Group rootGroup)
+ {
+ Fqn nodeFqn = getFqn(ns, NODE_PLIDM_ROOT_GROUP);
+
+ Node ioNode = getCache().getRoot().addChild(nodeFqn);
+
+ if (ioNode != null)
+ {
+ ioNode.put(NODE_OBJECT_KEY, rootGroup);
+
+ if (log.isLoggable(Level.FINER))
+ {
+
+ log.finer(this.toString() + "GateIn root group stored in cache" +
";namespace=" + ns);
+ }
+ }
+ }
+
+ /**
+ * Retrieve PLIDM root group
+ * @param ns
+ * @return
+ */
+ Group getRootGroup(String ns)
+ {
+ Fqn nodeFqn = getFqn(ns, NODE_PLIDM_ROOT_GROUP);
+
+ Node node = getCache().getRoot().getChild(nodeFqn);
+
+ if (node != null)
+ {
+ Group rootGroup = (Group)node.get(NODE_OBJECT_KEY);
+
+ if (log.isLoggable(Level.FINER) && rootGroup != null)
+ {
+ log.finer(this.toString() + "GateIn root group found in cache" +
";namespace=" + ns);
+ }
+
+ return rootGroup;
+ }
+
+ return null;
+
+ }
+
+}
Modified:
exo/portal/branches/3.1.x/component/identity/src/main/java/org/exoplatform/services/organization/idm/MembershipDAOImpl.java
===================================================================
---
exo/portal/branches/3.1.x/component/identity/src/main/java/org/exoplatform/services/organization/idm/MembershipDAOImpl.java 2011-01-12
11:04:03 UTC (rev 5734)
+++
exo/portal/branches/3.1.x/component/identity/src/main/java/org/exoplatform/services/organization/idm/MembershipDAOImpl.java 2011-01-12
14:26:07 UTC (rev 5735)
@@ -26,12 +26,14 @@
import org.exoplatform.services.organization.MembershipHandler;
import org.exoplatform.services.organization.MembershipType;
import org.exoplatform.services.organization.User;
+import org.gatein.common.logging.LogLevel;
+import org.gatein.common.logging.Logger;
+import org.gatein.common.logging.LoggerFactory;
import org.picketlink.idm.api.IdentitySession;
import org.picketlink.idm.api.Role;
import org.picketlink.idm.api.RoleType;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
@@ -74,6 +76,19 @@
public void createMembership(Membership m, boolean broadcast) throws Exception
{
+ if (log.isTraceEnabled())
+ {
+ Tools.logMethodIn(
+ log,
+ LogLevel.TRACE,
+ "createMembership",
+ new Object[]{
+ "membership", m,
+ "broadcast", broadcast,
+ }
+ );
+ }
+
if (broadcast)
{
preSave(m, true);
@@ -90,6 +105,21 @@
public void linkMembership(User user, Group g, MembershipType mt, boolean broadcast)
throws Exception
{
+ if (log.isTraceEnabled())
+ {
+ Tools.logMethodIn(
+ log,
+ LogLevel.TRACE,
+ "linkMembership",
+ new Object[]{
+ "user", user,
+ "group", g,
+ "membershipType", mt,
+ "broadcast", broadcast
+ }
+ );
+ }
+
if (g == null)
{
throw new InvalidNameException("Can not create membership record for "
+ user.getUserName()
@@ -154,7 +184,20 @@
public void saveMembership(Membership m, boolean broadcast) throws Exception
{
+ if (log.isTraceEnabled())
+ {
+ Tools.logMethodIn(
+ log,
+ LogLevel.TRACE,
+ "saveMembership",
+ new Object[]{
+ "membership", m,
+ "broadcast", broadcast
+ }
+ );
+ }
+
String plGroupName = getPLIDMGroupName(getGroupNameFromId(m.getGroupId()));
String groupId =
@@ -222,7 +265,20 @@
public Membership removeMembership(String id, boolean broadcast) throws Exception
{
+ if (log.isTraceEnabled())
+ {
+ Tools.logMethodIn(
+ log,
+ LogLevel.TRACE,
+ "removeMembership",
+ new Object[]{
+ "id", id,
+ "broadcast", broadcast
+ }
+ );
+ }
+
Membership m = new MembershipImpl(id);
String plGroupName = getPLIDMGroupName(getGroupNameFromId(m.getGroupId()));
@@ -308,6 +364,20 @@
public Collection removeMembershipByUser(String userName, boolean broadcast) throws
Exception
{
+ if (log.isTraceEnabled())
+ {
+ Tools.logMethodIn(
+ log,
+ LogLevel.TRACE,
+ "removeMembershipByUser",
+ new Object[]{
+ "userName", userName,
+ "broadcast", broadcast
+ }
+ );
+ }
+
+
Collection<Role> roles = new HashSet();
try
@@ -388,6 +458,22 @@
public Membership findMembershipByUserGroupAndType(String userName, String groupId,
String type) throws Exception
{
+
+ if (log.isTraceEnabled())
+ {
+ Tools.logMethodIn(
+ log,
+ LogLevel.TRACE,
+ "findMembershipByUserAndType",
+ new Object[]{
+ "userName", userName,
+ "groupId", groupId,
+ "type", type,
+ }
+ );
+ }
+
+
String plGroupName = getPLIDMGroupName(getGroupNameFromId(groupId));
String gid =
@@ -437,6 +523,8 @@
hasMembership = true;
}
+ Membership result = null;
+
if (hasMembership)
{
@@ -446,16 +534,51 @@
m.setUserName(userName);
m.setMembershipType(type);
- return m;
+ result = m;
}
- return null;
+
+ if (log.isTraceEnabled())
+ {
+ Tools.logMethodOut(
+ log,
+ LogLevel.TRACE,
+ "findMembershipByUserGroupAndType",
+ result
+ );
+ }
+
+ return result;
}
public Collection findMembershipsByUserAndGroup(String userName, String groupId)
throws Exception
{
+ if (log.isTraceEnabled())
+ {
+ Tools.logMethodIn(
+ log,
+ LogLevel.TRACE,
+ "findMembershipByUserAndGroup",
+ new Object[]{
+ "userName", userName,
+ "groupId", groupId,
+ }
+ );
+ }
+
if (userName == null)
{
// julien fix : if user name is null, need to check if we do need to return a
special group
+
+ if (log.isTraceEnabled())
+ {
+ Tools.logMethodOut(
+ log,
+ LogLevel.TRACE,
+ "findMembershipByUserAndGroup",
+ Collections.emptyList()
+ );
+ }
+
return Collections.emptyList();
}
@@ -515,11 +638,36 @@
}
//TODO: Exo UI has hardcoded casts to List
- return new LinkedList(memberships);
+ Collection result = new LinkedList(memberships);
+
+ if (log.isTraceEnabled())
+ {
+ Tools.logMethodOut(
+ log,
+ LogLevel.TRACE,
+ "findMembershipByUserAndGroup",
+ result
+ );
+ }
+
+ return result;
}
public Collection findMembershipsByUser(String userName) throws Exception
{
+ if (log.isTraceEnabled())
+ {
+ Tools.logMethodIn(
+ log,
+ LogLevel.TRACE,
+ "findMembershipsByUser",
+ new Object[]{
+ "userName", userName
+ }
+ );
+ }
+
+
Collection<Role> roles = new HashSet();
try
@@ -577,7 +725,19 @@
}
- return new LinkedList(memberships);
+ Collection result = new LinkedList(memberships);
+
+ if (log.isTraceEnabled())
+ {
+ Tools.logMethodOut(
+ log,
+ LogLevel.TRACE,
+ "findMembershipsByUser",
+ result
+ );
+ }
+
+ return result;
}
public Collection findMembershipsByGroup(Group group) throws Exception
@@ -587,6 +747,18 @@
public Collection findMembershipsByGroupId(String groupId) throws Exception
{
+ if (log.isTraceEnabled())
+ {
+ Tools.logMethodIn(
+ log,
+ LogLevel.TRACE,
+ "findMembershipsByGroup",
+ new Object[]{
+ "groupId", groupId
+ }
+ );
+ }
+
String plGroupName = getPLIDMGroupName(getGroupNameFromId(groupId));
String gid =
@@ -656,11 +828,34 @@
Collections.sort(results);
}
+
+ if (log.isTraceEnabled())
+ {
+ Tools.logMethodOut(
+ log,
+ LogLevel.TRACE,
+ "findMembershipsByGroupId",
+ results
+ );
+ }
+
return results;
}
public Membership findMembership(String id) throws Exception
{
+ if (log.isTraceEnabled())
+ {
+ Tools.logMethodIn(
+ log,
+ LogLevel.TRACE,
+ "findMembership",
+ new Object[]{
+ "id", id
+ }
+ );
+ }
+
Membership m = new MembershipImpl(id);
String plGroupName = getPLIDMGroupName(getGroupNameFromId(m.getGroupId()));
@@ -675,6 +870,15 @@
if (isCreateMembership(m.getMembershipType()) &&
getIdentitySession().getRoleManager().hasRole(m.getUserName(), groupId,
m.getMembershipType()))
{
+ if (log.isTraceEnabled())
+ {
+ Tools.logMethodOut(
+ log,
+ LogLevel.TRACE,
+ "findMembership",
+ m
+ );
+ }
return m;
}
}
@@ -690,6 +894,16 @@
if (isAssociationMapped() &&
getAssociationMapping().equals(m.getMembershipType()) &&
getIdentitySession().getRelationshipManager().isAssociatedByKeys(groupId,
m.getUserName()))
{
+ if (log.isTraceEnabled())
+ {
+ Tools.logMethodOut(
+ log,
+ LogLevel.TRACE,
+ "findMembership",
+ m
+ );
+ }
+
return m;
}
}
@@ -700,6 +914,15 @@
}
+ if (log.isTraceEnabled())
+ {
+ Tools.logMethodOut(
+ log,
+ LogLevel.TRACE,
+ "findMembership",
+ null
+ );
+ }
return null;
}
Modified:
exo/portal/branches/3.1.x/component/identity/src/main/java/org/exoplatform/services/organization/idm/MembershipImpl.java
===================================================================
---
exo/portal/branches/3.1.x/component/identity/src/main/java/org/exoplatform/services/organization/idm/MembershipImpl.java 2011-01-12
11:04:03 UTC (rev 5734)
+++
exo/portal/branches/3.1.x/component/identity/src/main/java/org/exoplatform/services/organization/idm/MembershipImpl.java 2011-01-12
14:26:07 UTC (rev 5735)
@@ -157,4 +157,14 @@
return userName.compareTo(m.getUserName());
}
+
+ @Override
+ public String toString()
+ {
+ return "MembershipImpl{" +
+ "membershipType='" + membershipType + '\'' +
+ ", userName='" + userName + '\'' +
+ ", groupId='" + groupId + '\'' +
+ '}';
+ }
}
Modified:
exo/portal/branches/3.1.x/component/identity/src/main/java/org/exoplatform/services/organization/idm/MembershipTypeDAOImpl.java
===================================================================
---
exo/portal/branches/3.1.x/component/identity/src/main/java/org/exoplatform/services/organization/idm/MembershipTypeDAOImpl.java 2011-01-12
11:04:03 UTC (rev 5734)
+++
exo/portal/branches/3.1.x/component/identity/src/main/java/org/exoplatform/services/organization/idm/MembershipTypeDAOImpl.java 2011-01-12
14:26:07 UTC (rev 5735)
@@ -22,6 +22,7 @@
import org.exoplatform.services.organization.MembershipType;
import org.exoplatform.services.organization.MembershipTypeHandler;
import org.exoplatform.services.organization.impl.MembershipTypeImpl;
+import org.gatein.common.logging.LogLevel;
import org.gatein.common.logging.Logger;
import org.gatein.common.logging.LoggerFactory;
import org.picketlink.idm.api.IdentitySession;
@@ -71,6 +72,20 @@
public MembershipType createMembershipType(MembershipType mt, boolean broadcast)
throws Exception
{
+ if (log.isTraceEnabled())
+ {
+ Tools.logMethodIn(
+ log,
+ LogLevel.TRACE,
+ "createMembershipType",
+ new Object[]{
+ "membershipType", mt,
+ "broadcast", broadcast
+ }
+ );
+ }
+
+
Date now = new Date();
mt.setCreatedDate(now);
mt.setModifiedDate(now);
@@ -83,6 +98,18 @@
public MembershipType saveMembershipType(MembershipType mt, boolean broadcast) throws
Exception
{
+ if (log.isTraceEnabled())
+ {
+ Tools.logMethodIn(
+ log,
+ LogLevel.TRACE,
+ "saveMembershipType",
+ new Object[]{
+ "membershipType", mt,
+ "broadcast", broadcast
+ }
+ );
+ }
Date now = new Date();
mt.setModifiedDate(now);
updateMembershipType(mt);
@@ -91,6 +118,18 @@
public MembershipType findMembershipType(String name) throws Exception
{
+ if (log.isTraceEnabled())
+ {
+ Tools.logMethodIn(
+ log,
+ LogLevel.TRACE,
+ "findMembershipType",
+ new Object[]{
+ "name", name
+ }
+ );
+ }
+
RoleType rt = getIdentitySession().getRoleManager().getRoleType(name);
MembershipType mt = null;
@@ -101,11 +140,35 @@
populateMembershipType(mt);
}
+ if (log.isTraceEnabled())
+ {
+ Tools.logMethodOut(
+ log,
+ LogLevel.TRACE,
+ "findMembershipType",
+ mt
+ );
+ }
+
return mt;
}
public MembershipType removeMembershipType(String name, boolean broadcast) throws
Exception
{
+ if (log.isTraceEnabled())
+ {
+ Tools.logMethodIn(
+ log,
+ LogLevel.TRACE,
+ "removeMembershipType",
+ new Object[]{
+ "name", name,
+ "broadcast", broadcast
+ }
+ );
+ }
+
+
MembershipType mt = findMembershipType(name);
if (mt != null)
@@ -119,6 +182,15 @@
public Collection findMembershipTypes() throws Exception
{
+ if (log.isTraceEnabled())
+ {
+ Tools.logMethodIn(
+ log,
+ LogLevel.TRACE,
+ "findMembershipTypes",
+ null
+ );
+ }
Collection<RoleType> rts =
getIdentitySession().getRoleManager().findRoleTypes();
@@ -131,6 +203,16 @@
mts.add(mt);
}
+ if (log.isTraceEnabled())
+ {
+ Tools.logMethodOut(
+ log,
+ LogLevel.TRACE,
+ "findMembershipTypes",
+ mts
+ );
+ }
+
return mts;
}
Modified:
exo/portal/branches/3.1.x/component/identity/src/main/java/org/exoplatform/services/organization/idm/PicketLinkIDMCacheService.java
===================================================================
---
exo/portal/branches/3.1.x/component/identity/src/main/java/org/exoplatform/services/organization/idm/PicketLinkIDMCacheService.java 2011-01-12
11:04:03 UTC (rev 5734)
+++
exo/portal/branches/3.1.x/component/identity/src/main/java/org/exoplatform/services/organization/idm/PicketLinkIDMCacheService.java 2011-01-12
14:26:07 UTC (rev 5735)
@@ -51,6 +51,8 @@
public class PicketLinkIDMCacheService
{
+ private final List<IntegrationCache> integrationCache = new
LinkedList<IntegrationCache>();
+
private final List<APICacheProvider> apiCacheProviders = new
LinkedList<APICacheProvider>();
private final List<IdentityStoreCacheProvider> storeCacheProviders = new
LinkedList<IdentityStoreCacheProvider>();
@@ -59,6 +61,16 @@
{
}
+ public void register(IntegrationCache cacheProvider)
+ {
+
+ if (cacheProvider != null)
+ {
+ integrationCache.add(cacheProvider);
+ }
+
+ }
+
public void register(APICacheProvider cacheProvider)
{
@@ -101,6 +113,11 @@
@Impact(ImpactType.WRITE)
public void invalidateAll()
{
+ for (IntegrationCache cacheProvider : integrationCache)
+ {
+ cacheProvider.invalidateAll();
+ }
+
for (APICacheProvider cacheProvider : apiCacheProviders)
{
cacheProvider.invalidateAll();
Modified:
exo/portal/branches/3.1.x/component/identity/src/main/java/org/exoplatform/services/organization/idm/PicketLinkIDMOrganizationServiceImpl.java
===================================================================
---
exo/portal/branches/3.1.x/component/identity/src/main/java/org/exoplatform/services/organization/idm/PicketLinkIDMOrganizationServiceImpl.java 2011-01-12
11:04:03 UTC (rev 5734)
+++
exo/portal/branches/3.1.x/component/identity/src/main/java/org/exoplatform/services/organization/idm/PicketLinkIDMOrganizationServiceImpl.java 2011-01-12
14:26:07 UTC (rev 5735)
@@ -76,7 +76,7 @@
}
- public final org.picketlink.idm.api.Group getJBIDMGroup(String groupId) throws
Exception
+ public final org.picketlink.idm.api.Group getJBIDMGroup(String groupId) throws
Exception
{
String[] ids = groupId.split("/");
String name = ids[ids.length - 1];
Modified:
exo/portal/branches/3.1.x/component/identity/src/main/java/org/exoplatform/services/organization/idm/PicketLinkIDMServiceImpl.java
===================================================================
---
exo/portal/branches/3.1.x/component/identity/src/main/java/org/exoplatform/services/organization/idm/PicketLinkIDMServiceImpl.java 2011-01-12
11:04:03 UTC (rev 5734)
+++
exo/portal/branches/3.1.x/component/identity/src/main/java/org/exoplatform/services/organization/idm/PicketLinkIDMServiceImpl.java 2011-01-12
14:26:07 UTC (rev 5735)
@@ -26,6 +26,9 @@
import org.exoplatform.services.log.Log;
import org.exoplatform.services.database.HibernateService;
import org.exoplatform.services.naming.InitialContextInitializer;
+import org.jboss.cache.Cache;
+import org.jboss.cache.CacheFactory;
+import org.jboss.cache.DefaultCacheFactory;
import org.picketlink.idm.api.IdentitySession;
import org.picketlink.idm.api.IdentitySessionFactory;
import org.picketlink.idm.api.cfg.IdentityConfiguration;
@@ -75,6 +78,8 @@
private IdentityConfiguration identityConfiguration;
+ private IntegrationCache integrationCache;
+
private PicketLinkIDMServiceImpl()
{
}
@@ -125,13 +130,31 @@
{
InputStream configStream =
confManager.getInputStream(apiCacheConfig.getValue());
+ // Create common JBoss Cache instance
+ CacheFactory factory = new DefaultCacheFactory();
+ if (configStream == null)
+ {
+ throw new IllegalArgumentException("JBoss Cache configuration
InputStream is null");
+ }
+
+ Cache cache = factory.createCache(configStream);
+
+ cache.create();
+ cache.start();
+
+ configStream.close();
+
+ // PLIDM API cache
JBossCacheAPICacheProviderImpl apiCacheProvider = new
JBossCacheAPICacheProviderImpl();
- apiCacheProvider.initialize(configStream);
+ apiCacheProvider.initialize(cache);
picketLinkIDMCache.register(apiCacheProvider);
identityConfiguration.getIdentityConfigurationRegistry().register(apiCacheProvider,
"apiCacheProvider");
- configStream.close();
+ //Integration cache
+ integrationCache = new IntegrationCache();
+ integrationCache.initialize(cache);
+ picketLinkIDMCache.register(apiCacheProvider);
}
if (storeCacheConfig != null)
@@ -192,4 +215,14 @@
}
return getIdentitySessionFactory().getCurrentIdentitySession(realm);
}
+
+ public IntegrationCache getIntegrationCache()
+ {
+ return integrationCache;
+ }
+
+ public String getRealmName()
+ {
+ return realmName;
+ }
}
Copied:
exo/portal/branches/3.1.x/component/identity/src/main/java/org/exoplatform/services/organization/idm/Tools.java
(from rev 5282,
portal/trunk/component/identity/src/main/java/org/exoplatform/services/organization/idm/Tools.java)
===================================================================
---
exo/portal/branches/3.1.x/component/identity/src/main/java/org/exoplatform/services/organization/idm/Tools.java
(rev 0)
+++
exo/portal/branches/3.1.x/component/identity/src/main/java/org/exoplatform/services/organization/idm/Tools.java 2011-01-12
14:26:07 UTC (rev 5735)
@@ -0,0 +1,106 @@
+package org.exoplatform.services.organization.idm;
+
+import org.gatein.common.logging.LogLevel;
+import org.gatein.common.logging.Logger;
+
+import java.util.Arrays;
+import java.util.Collection;
+
+/*
+* 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.
+*/
+
+/**
+ * Some helper methods
+ */
+public class Tools
+{
+ public static void logMethodIn(Logger log, LogLevel level, String methodName, Object[]
args)
+ {
+ try
+ {
+ StringBuilder sb = new StringBuilder();
+ sb.append("Method '")
+ .append(methodName)
+ .append("' called with arguments: ");
+
+ if (args != null)
+ {
+ for (Object arg : args)
+ {
+ if (arg != null && arg instanceof Object[])
+ {
+ sb.append(Arrays.toString((Object[])arg))
+ .append("; ");
+ }
+ else
+ {
+ sb.append(arg)
+ .append("; ");
+ }
+ }
+ }
+ else
+ {
+ sb.append(args);
+ }
+
+ log.log(level, sb.toString());
+ }
+ catch (Throwable t)
+ {
+ log.log(level, "Error in logging code block (not related to application
code): ", t);
+ }
+
+ }
+
+ public static void logMethodOut(Logger log, LogLevel level, String methodName, Object
result)
+ {
+ try
+ {
+ StringBuilder sb = new StringBuilder();
+ sb.append("Method '")
+ .append(methodName)
+ .append("' returning object: ");
+
+ if (result != null && result instanceof Collection)
+ {
+ sb.append("Collection of size:
").append(((Collection)result).size());
+ }
+ else
+ {
+ if (result != null)
+ {
+
sb.append("[").append(result.getClass().getCanonicalName()).append("]");
+ }
+ sb.append(result);
+ }
+
+ log.log(level, sb.toString());
+
+ }
+ catch (Throwable t)
+ {
+ log.log(level, "Error in logging code block (not related to application
code): ", t);
+ }
+ }
+
+}
Modified:
exo/portal/branches/3.1.x/component/identity/src/main/java/org/exoplatform/services/organization/idm/UserDAOImpl.java
===================================================================
---
exo/portal/branches/3.1.x/component/identity/src/main/java/org/exoplatform/services/organization/idm/UserDAOImpl.java 2011-01-12
11:04:03 UTC (rev 5734)
+++
exo/portal/branches/3.1.x/component/identity/src/main/java/org/exoplatform/services/organization/idm/UserDAOImpl.java 2011-01-12
14:26:07 UTC (rev 5735)
@@ -28,6 +28,7 @@
import org.exoplatform.services.organization.UserEventListener;
import org.exoplatform.services.organization.UserHandler;
import org.exoplatform.services.organization.impl.UserImpl;
+import org.gatein.common.logging.LogLevel;
import org.gatein.common.logging.Logger;
import org.gatein.common.logging.LoggerFactory;
import org.picketlink.idm.api.Attribute;
@@ -122,6 +123,20 @@
public void createUser(User user, boolean broadcast) throws Exception
{
+ if (log.isTraceEnabled())
+ {
+ Tools.logMethodIn(
+ log,
+ LogLevel.TRACE,
+ "createUser",
+ new Object[]{
+ "user", user,
+ "broadcast", broadcast
+ }
+ );
+ }
+
+
IdentitySession session = service_.getIdentitySession();
if (broadcast)
{
@@ -149,6 +164,20 @@
public void saveUser(User user, boolean broadcast) throws Exception
{
+
+ if (log.isTraceEnabled())
+ {
+ Tools.logMethodIn(
+ log,
+ LogLevel.TRACE,
+ "saveUser",
+ new Object[]{
+ "user", user,
+ "broadcast", broadcast
+ }
+ );
+ }
+
IdentitySession session = service_.getIdentitySession();
if (broadcast)
{
@@ -165,6 +194,20 @@
public User removeUser(String userName, boolean broadcast) throws Exception
{
+ if (log.isTraceEnabled())
+ {
+ Tools.logMethodIn(
+ log,
+ LogLevel.TRACE,
+ "removeUser",
+ new Object[]{
+ "userName", userName,
+ "broadcast", broadcast
+ }
+ );
+ }
+
+
IdentitySession session = service_.getIdentitySession();
org.picketlink.idm.api.User foundUser = null;
@@ -223,15 +266,49 @@
//
public User findUserByName(String userName) throws Exception
{
+ if (log.isTraceEnabled())
+ {
+ Tools.logMethodIn(
+ log,
+ LogLevel.TRACE,
+ "findUserByName",
+ new Object[]{
+ "userName", userName,
+ }
+ );
+ }
+
IdentitySession session = service_.getIdentitySession();
User user = getPopulatedUser(userName, session);
+ if (log.isTraceEnabled())
+ {
+ Tools.logMethodOut(
+ log,
+ LogLevel.TRACE,
+ "findUserByName",
+ user
+ );
+ }
+
return user;
}
public LazyPageList getUserPageList(int pageSize) throws Exception
{
+ if (log.isTraceEnabled())
+ {
+ Tools.logMethodIn(
+ log,
+ LogLevel.TRACE,
+ "getUserPagetList",
+ new Object[]{
+ "pageSize", pageSize
+ }
+ );
+ }
+
UserQueryBuilder qb = service_.getIdentitySession().createUserQueryBuilder();
return new LazyPageList(new IDMUserListAccess(this, service_, qb, pageSize, true),
pageSize);
@@ -245,9 +322,32 @@
//
public boolean authenticate(String username, String password) throws Exception
{
+ if (log.isTraceEnabled())
+ {
+ Tools.logMethodIn(
+ log,
+ LogLevel.TRACE,
+ "authenticate",
+ new Object[]{
+ "userName", username,
+ "password", "****"
+ }
+ );
+ }
+
User user = findUserByName(username);
if (user == null)
{
+ if (log.isTraceEnabled())
+ {
+ Tools.logMethodOut(
+ log,
+ LogLevel.TRACE,
+ "authenticate",
+ false
+ );
+ }
+
return false;
}
@@ -279,12 +379,35 @@
userImpl.setLastLoginTime(Calendar.getInstance().getTime());
saveUser(userImpl, false);
}
+
+ if (log.isTraceEnabled())
+ {
+ Tools.logMethodOut(
+ log,
+ LogLevel.TRACE,
+ "authenticate",
+ authenticated
+ );
+ }
+
return authenticated;
}
public LazyPageList findUsers(Query q) throws Exception
{
+ if (log.isTraceEnabled())
+ {
+ Tools.logMethodIn(
+ log,
+ LogLevel.TRACE,
+ "findUsers",
+ new Object[]{
+ "q", q
+ }
+ );
+ }
+
UserQueryBuilder qb = service_.getIdentitySession().createUserQueryBuilder();
if (q.getUserName() != null)
@@ -319,6 +442,19 @@
public LazyPageList findUsersByGroup(String groupId) throws Exception
{
+ if (log.isTraceEnabled())
+ {
+ Tools.logMethodIn(
+ log,
+ LogLevel.TRACE,
+ "findUsersByGroup",
+ new Object[]{
+ "groupId", groupId
+ }
+ );
+ }
+
+
UserQueryBuilder qb = service_.getIdentitySession().createUserQueryBuilder();
org.picketlink.idm.api.Group jbidGroup = null;
@@ -339,6 +475,18 @@
public User findUserByEmail(String email) throws Exception
{
+ if (log.isTraceEnabled())
+ {
+ Tools.logMethodIn(
+ log,
+ LogLevel.TRACE,
+ "findUserByEmail",
+ new Object[]{
+ "findUserByEmail", email
+ }
+ );
+ }
+
IdentitySession session = service_.getIdentitySession();
@@ -363,6 +511,16 @@
}
+ if (log.isTraceEnabled())
+ {
+ Tools.logMethodOut(
+ log,
+ LogLevel.TRACE,
+ "findUserByEmail",
+ user
+ );
+ }
+
return user;
}
Modified: exo/portal/branches/3.1.x/pom.xml
===================================================================
--- exo/portal/branches/3.1.x/pom.xml 2011-01-12 11:04:03 UTC (rev 5734)
+++ exo/portal/branches/3.1.x/pom.xml 2011-01-12 14:26:07 UTC (rev 5735)
@@ -47,7 +47,7 @@
<org.gatein.common.version>2.0.2-GA</org.gatein.common.version>
<org.gatein.wci.version>2.0.1-GA</org.gatein.wci.version>
<org.gatein.pc.version>2.1.1-GA</org.gatein.pc.version>
- <org.picketlink.idm>1.1.6.GA</org.picketlink.idm>
+ <org.picketlink.idm>1.1.7.GA</org.picketlink.idm>
<org.gatein.wsrp.version>1.1.1-GA</org.gatein.wsrp.version>
<org.gatein.mop.version>1.0.4-GA</org.gatein.mop.version>
<org.slf4j.version>1.5.6</org.slf4j.version>