Author: bdaw
Date: 2007-07-11 09:40:02 -0400 (Wed, 11 Jul 2007)
New Revision: 7717
Modified:
branches/JBoss_Portal_Branch_2_6/identity/src/main/org/jboss/portal/identity/db/HibernateMembershipModuleImpl.java
branches/JBoss_Portal_Branch_2_6/identity/src/main/org/jboss/portal/identity/db/HibernateUserProfileModuleImpl.java
branches/JBoss_Portal_Branch_2_6/identity/src/main/org/jboss/portal/identity/ldap/LDAPStaticGroupMembershipModuleImpl.java
branches/JBoss_Portal_Branch_2_6/identity/src/main/org/jboss/portal/identity/ldap/LDAPStaticRoleMembershipModuleImpl.java
branches/JBoss_Portal_Branch_2_6/identity/src/main/org/jboss/portal/identity/ldap/LDAPUserProfileModuleImpl.java
branches/JBoss_Portal_Branch_2_6/identity/src/main/org/jboss/portal/test/identity/IdentityTest.java
Log:
JBPORTAL-1570 - make identity modules implementation handle CachedUserImpl properly
Modified:
branches/JBoss_Portal_Branch_2_6/identity/src/main/org/jboss/portal/identity/db/HibernateMembershipModuleImpl.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/identity/src/main/org/jboss/portal/identity/db/HibernateMembershipModuleImpl.java 2007-07-11
06:54:15 UTC (rev 7716)
+++
branches/JBoss_Portal_Branch_2_6/identity/src/main/org/jboss/portal/identity/db/HibernateMembershipModuleImpl.java 2007-07-11
13:40:02 UTC (rev 7717)
@@ -27,6 +27,9 @@
import org.jboss.portal.identity.db.HibernateUserImpl;
import org.jboss.portal.identity.db.HibernateRoleImpl;
import org.jboss.portal.identity.IdentityException;
+import org.jboss.portal.identity.CachedUserImpl;
+import org.jboss.portal.identity.IdentityContext;
+import org.jboss.portal.identity.NoSuchUserException;
import org.jboss.portal.common.util.Tools;
import org.hibernate.SessionFactory;
import org.hibernate.Session;
@@ -53,6 +56,8 @@
/** . */
protected String sessionFactoryJNDIName;
+ private HibernateUserModuleImpl userModule;
+
protected void startService() throws Exception
{
//
@@ -87,7 +92,23 @@
public Set getRoles(User user) throws IdentityException
{
- //throw new UnsupportedOperationException("Not yet implemented");
+ if (user == null)
+ {
+ throw new IllegalArgumentException("User cannot be null");
+ }
+
+ if (user instanceof CachedUserImpl)
+ {
+ try
+ {
+ user = getUserModule().findUserById(user.getId());
+ }
+ catch(NoSuchUserException e)
+ {
+ throw new IdentityException("Illegal state - cached user doesn't
exist in identity store: ", e);
+ }
+ }
+
if (!(user instanceof HibernateUserImpl))
{
throw new IllegalArgumentException("User is not a HibernateUserImpl
user");
@@ -137,6 +158,19 @@
for (Iterator i = users.iterator(); i.hasNext();)
{
Object o = i.next();
+
+ if (o instanceof CachedUserImpl)
+ {
+ try
+ {
+ o = getUserModule().findUserById(((User)o).getId());
+ }
+ catch(NoSuchUserException e)
+ {
+ log.error("Illegal state - cached user doesn't exist in identity
store: ", e);
+ }
+ }
+
if (o instanceof HibernateUserImpl)
{
HibernateUserImpl user = (HibernateUserImpl)o;
@@ -152,7 +186,24 @@
public void assignRoles(User user, Set roles) throws IdentityException
{
- //throw new UnsupportedOperationException("Not yet implemented");
+
+ if (user == null)
+ {
+ throw new IllegalArgumentException("User cannot be null");
+ }
+
+ if (user instanceof CachedUserImpl)
+ {
+ try
+ {
+ user = getUserModule().findUserById(user.getId());
+ }
+ catch(NoSuchUserException e)
+ {
+ throw new IdentityException("Illegal state - cached user doesn't
exist in identity store: ", e);
+ }
+ }
+
if (!(user instanceof HibernateUserImpl))
{
throw new IllegalArgumentException("User is not a HibernateUserImpl
user");
@@ -231,13 +282,23 @@
}
}
- /**
- * Process Set of Map objects and returns a Set of HibernateRoleImpl objects
- * @param maps
- * @return
- * @throws Exception
- */
+ protected HibernateUserModuleImpl getUserModule() throws IdentityException
+ {
+ if (userModule == null)
+ {
+ try
+ {
+ this.userModule =
(HibernateUserModuleImpl)getIdentityContext().getObject(IdentityContext.TYPE_USER_MODULE);
+ }
+ catch (ClassCastException e)
+ {
+ throw new IdentityException("Not supported object as part of the context
- must be HibernateUserModuleImpl", e);
+ }
+ }
+ return userModule;
+ }
+
/** Can be subclasses to provide testing in a non JTA environement. */
protected Session getCurrentSession()
{
Modified:
branches/JBoss_Portal_Branch_2_6/identity/src/main/org/jboss/portal/identity/db/HibernateUserProfileModuleImpl.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/identity/src/main/org/jboss/portal/identity/db/HibernateUserProfileModuleImpl.java 2007-07-11
06:54:15 UTC (rev 7716)
+++
branches/JBoss_Portal_Branch_2_6/identity/src/main/org/jboss/portal/identity/db/HibernateUserProfileModuleImpl.java 2007-07-11
13:40:02 UTC (rev 7717)
@@ -35,6 +35,9 @@
import javax.naming.InitialContext;
import org.jboss.portal.identity.service.UserProfileModuleService;
import org.jboss.portal.identity.IdentityException;
+import org.jboss.portal.identity.NoSuchUserException;
+import org.jboss.portal.identity.UserModule;
+import org.jboss.portal.identity.CachedUserImpl;
import java.util.Map;
import java.util.Set;
@@ -55,6 +58,8 @@
/** . */
protected SessionFactory sessionFactory;
+ protected UserModule userModule;
+
/** . */
protected String sessionFactoryJNDIName;
@@ -196,6 +201,18 @@
protected HibernateUserImpl processUser(User user) throws IdentityException
{
+ if (user instanceof CachedUserImpl)
+ {
+ try
+ {
+ user = getUserModule().findUserById(user.getId());
+ }
+ catch(NoSuchUserException e)
+ {
+ throw new IdentityException("Illegal state - cached user doesn't
exist in identity store: ", e);
+ }
+ }
+
if (user instanceof HibernateUserImpl)
{
return (HibernateUserImpl)user;
@@ -341,5 +358,21 @@
{
this.randomSynchronizePassword = randomSynchronizePassword;
}
+
+ protected UserModule getUserModule() throws IdentityException
+ {
+ if (userModule == null)
+ {
+ try
+ {
+ this.userModule =
(UserModule)getIdentityContext().getObject(IdentityContext.TYPE_USER_MODULE);
+ }
+ catch (ClassCastException e)
+ {
+ throw new IdentityException("Not supported object as part of the context
- must be UserModule", e);
+ }
+ }
+ return userModule;
+ }
}
Modified:
branches/JBoss_Portal_Branch_2_6/identity/src/main/org/jboss/portal/identity/ldap/LDAPStaticGroupMembershipModuleImpl.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/identity/src/main/org/jboss/portal/identity/ldap/LDAPStaticGroupMembershipModuleImpl.java 2007-07-11
06:54:15 UTC (rev 7716)
+++
branches/JBoss_Portal_Branch_2_6/identity/src/main/org/jboss/portal/identity/ldap/LDAPStaticGroupMembershipModuleImpl.java 2007-07-11
13:40:02 UTC (rev 7717)
@@ -25,6 +25,8 @@
import org.jboss.portal.identity.IdentityException;
import org.jboss.portal.identity.User;
import org.jboss.portal.identity.Role;
+import org.jboss.portal.identity.CachedUserImpl;
+import org.jboss.portal.identity.NoSuchUserException;
import org.jboss.portal.identity.ldap.helper.LDAPTools;
import org.jboss.portal.common.util.Tools;
@@ -60,6 +62,18 @@
throw new IllegalArgumentException("User cannot be null");
}
+ if (user instanceof CachedUserImpl)
+ {
+ try
+ {
+ user = getUserModule().findUserById(user.getId());
+ }
+ catch(NoSuchUserException e)
+ {
+ throw new IdentityException("Illegal state - cached user doesn't
exist in identity store: ", e);
+ }
+ }
+
LDAPUserImpl ldapUser = null;
if (user instanceof LDAPUserImpl)
@@ -242,15 +256,31 @@
{
try
{
- LDAPUserImpl user = (LDAPUserImpl)iterator.next();
+
+ User user = (User)iterator.next();
+
+ if (user instanceof CachedUserImpl)
+ {
+ try
+ {
+ user = getUserModule().findUserById(user.getId());
+ }
+ catch(NoSuchUserException e)
+ {
+ throw new IdentityException("Illegal state - cached user
doesn't exist in identity store: ", e);
+ }
+ }
+
+ LDAPUserImpl ldapUser = (LDAPUserImpl)user;
+
if (isUidAttributeIsDN())
{
- member.add(user.getDn());
+ member.add(ldapUser.getDn());
}
else
{
//member.add(user.getId().toString());
- member.add(user.getUserName());
+ member.add(ldapUser.getUserName());
}
}
catch (ClassCastException e)
@@ -283,6 +313,18 @@
throw new IllegalArgumentException("User cannot be null");
}
+ if (user instanceof CachedUserImpl)
+ {
+ try
+ {
+ user = getUserModule().findUserById(user.getId());
+ }
+ catch(NoSuchUserException e)
+ {
+ throw new IdentityException("Illegal state - cached user doesn't
exist in identity store: ", e);
+ }
+ }
+
LDAPUserImpl ldapUser = null;
if (user instanceof LDAPUserImpl)
Modified:
branches/JBoss_Portal_Branch_2_6/identity/src/main/org/jboss/portal/identity/ldap/LDAPStaticRoleMembershipModuleImpl.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/identity/src/main/org/jboss/portal/identity/ldap/LDAPStaticRoleMembershipModuleImpl.java 2007-07-11
06:54:15 UTC (rev 7716)
+++
branches/JBoss_Portal_Branch_2_6/identity/src/main/org/jboss/portal/identity/ldap/LDAPStaticRoleMembershipModuleImpl.java 2007-07-11
13:40:02 UTC (rev 7717)
@@ -26,6 +26,8 @@
import org.jboss.portal.identity.IdentityException;
import org.jboss.portal.identity.User;
import org.jboss.portal.identity.Role;
+import org.jboss.portal.identity.CachedUserImpl;
+import org.jboss.portal.identity.NoSuchUserException;
import javax.naming.directory.SearchResult;
import javax.naming.directory.DirContext;
@@ -60,6 +62,18 @@
throw new IllegalArgumentException("User cannot be null");
}
+ if (user instanceof CachedUserImpl)
+ {
+ try
+ {
+ user = getUserModule().findUserById(user.getId());
+ }
+ catch(NoSuchUserException e)
+ {
+ throw new IdentityException("Illegal state - cached user doesn't
exist in identity store: ", e);
+ }
+ }
+
LDAPUserImpl ldapUser = null;
if (user instanceof LDAPUserImpl)
@@ -236,8 +250,23 @@
{
try
{
- LDAPUserImpl user = (LDAPUserImpl)iterator.next();
- userDNsToAdd.add(user.getDn());
+ User user = (User)iterator.next();
+
+ if (user instanceof CachedUserImpl)
+ {
+ try
+ {
+ user = getUserModule().findUserById(user.getId());
+ }
+ catch(NoSuchUserException e)
+ {
+ throw new IdentityException("Illegal state - cached user
doesn't exist in identity store: ", e);
+ }
+ }
+
+ LDAPUserImpl ldapUser = (LDAPUserImpl)user;
+
+ userDNsToAdd.add(ldapUser.getDn());
}
catch(ClassCastException e)
{
@@ -324,6 +353,18 @@
throw new IllegalArgumentException("User cannot be null");
}
+ if (user instanceof CachedUserImpl)
+ {
+ try
+ {
+ user = getUserModule().findUserById(user.getId());
+ }
+ catch(NoSuchUserException e)
+ {
+ throw new IdentityException("Illegal state - cached user doesn't
exist in identity store: ", e);
+ }
+ }
+
LDAPUserImpl ldapUser = null;
if (user instanceof LDAPUserImpl)
Modified:
branches/JBoss_Portal_Branch_2_6/identity/src/main/org/jboss/portal/identity/ldap/LDAPUserProfileModuleImpl.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/identity/src/main/org/jboss/portal/identity/ldap/LDAPUserProfileModuleImpl.java 2007-07-11
06:54:15 UTC (rev 7716)
+++
branches/JBoss_Portal_Branch_2_6/identity/src/main/org/jboss/portal/identity/ldap/LDAPUserProfileModuleImpl.java 2007-07-11
13:40:02 UTC (rev 7717)
@@ -27,6 +27,9 @@
import org.jboss.portal.identity.info.ProfileInfo;
import org.jboss.portal.identity.info.PropertyInfo;
import org.jboss.portal.identity.IdentityException;
+import org.jboss.portal.identity.CachedUserImpl;
+import org.jboss.portal.identity.NoSuchUserException;
+import org.jboss.portal.identity.UserModule;
import javax.naming.directory.Attributes;
import javax.naming.directory.Attribute;
@@ -49,6 +52,8 @@
{
private static final org.jboss.logging.Logger log =
org.jboss.logging.Logger.getLogger(LDAPUserProfileModuleImpl.class);
+ private UserModule userModule;
+
public Object getProperty(User user, String propertyName) throws IdentityException,
IllegalArgumentException
{
if (user == null)
@@ -60,6 +65,18 @@
throw new IllegalArgumentException("Property name need to have
value");
}
+ if (user instanceof CachedUserImpl)
+ {
+ try
+ {
+ user = getUserModule().findUserById(user.getId());
+ }
+ catch(NoSuchUserException e)
+ {
+ throw new IdentityException("Illegal state - cached user doesn't
exist in identity store: ", e);
+ }
+ }
+
LDAPUserImpl ldapUser = null;
if (user instanceof LDAPUserImpl)
@@ -124,6 +141,18 @@
throw new IllegalArgumentException("Property name need to have
value");
}
+ if (user instanceof CachedUserImpl)
+ {
+ try
+ {
+ user = getUserModule().findUserById(user.getId());
+ }
+ catch(NoSuchUserException e)
+ {
+ throw new IdentityException("Illegal state - cached user doesn't
exist in identity store: ", e);
+ }
+ }
+
LDAPUserImpl ldapUser = null;
if (user instanceof LDAPUserImpl)
@@ -184,6 +213,18 @@
throw new IllegalArgumentException("User cannot be null");
}
+ if (user instanceof CachedUserImpl)
+ {
+ try
+ {
+ user = getUserModule().findUserById(user.getId());
+ }
+ catch(NoSuchUserException e)
+ {
+ throw new IdentityException("Illegal state - cached user doesn't
exist in identity store: ", e);
+ }
+ }
+
LDAPUserImpl ldapUser = null;
if (user instanceof LDAPUserImpl)
@@ -306,6 +347,21 @@
return profileInfo;
}
+ protected UserModule getUserModule() throws IdentityException
+ {
+ if (userModule == null)
+ {
+ try
+ {
+ this.userModule =
(UserModule)getIdentityContext().getObject(IdentityContext.TYPE_USER_MODULE);
+ }
+ catch (ClassCastException e)
+ {
+ throw new IdentityException("Not supported object as part of the context
- must be UserModule", e);
+ }
+ }
+ return userModule;
+ }
}
Modified:
branches/JBoss_Portal_Branch_2_6/identity/src/main/org/jboss/portal/test/identity/IdentityTest.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/identity/src/main/org/jboss/portal/test/identity/IdentityTest.java 2007-07-11
06:54:15 UTC (rev 7716)
+++
branches/JBoss_Portal_Branch_2_6/identity/src/main/org/jboss/portal/test/identity/IdentityTest.java 2007-07-11
13:40:02 UTC (rev 7717)
@@ -10,6 +10,7 @@
import org.jboss.portal.identity.IdentityException;
import org.jboss.portal.identity.ProfileMap;
import org.jboss.portal.identity.NoSuchUserException;
+import org.jboss.portal.identity.CachedUserImpl;
import org.jboss.portal.common.util.CollectionBuilder;
import org.jboss.portal.common.p3p.P3PConstants;
@@ -188,6 +189,10 @@
u3 = userModule.findUserByUserName("user3");
assertNotNull(u3);
Assert.assertEquals("user3", u3.getUserName());
+
+ //test if CachedUserImpl will be handled properly
+ u3 = new CachedUserImpl(u3.getId(), u3.getUserName());
+
assertNotNull(membershipModule.getRoles(u3));
Assert.assertEquals(1, membershipModule.getRoles(u3).size());
Assert.assertEquals("role1",
((Role)membershipModule.getRoles(u3).iterator().next()).getName());
@@ -418,6 +423,10 @@
//
User user = userModule.createUser("testname", "testpassword");
+
+ //test if CachedUserImpl is handled properly
+ user = new CachedUserImpl(user.getId(), user.getUserName());
+
Map map = userProfileModule.getProperties(user);
//assertEquals("testname",
map.get(P3PConstants.INFO_USER_NAME_NICKNAME));
@@ -539,6 +548,14 @@
}
+ public void testFindUserRoles() throws Exception
+ {
+ ctx.begin();
+
+
+ ctx.commit();
+ }
+
public void testGetProperties() throws Exception
{
ctx.begin();