[jboss-svn-commits] JBoss Portal SVN: r5678 - in trunk: identity/src/main/org/jboss/portal/identity2 identity/src/main/org/jboss/portal/identity2/db identity/src/main/org/jboss/portal/identity2/ldap identity/src/main/org/jboss/portal/identity2/service identity/src/main/org/jboss/portal/test/identity identity/src/main/org/jboss/portal/test/identity/ldap test/src/etc test/src/etc/identityconfig
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Mon Nov 20 06:10:12 EST 2006
Author: bdaw
Date: 2006-11-20 06:09:53 -0500 (Mon, 20 Nov 2006)
New Revision: 5678
Added:
trunk/identity/src/main/org/jboss/portal/identity2/db/DBRoleImpl.java
trunk/identity/src/main/org/jboss/portal/identity2/db/DBUserImpl.java
trunk/identity/src/main/org/jboss/portal/identity2/db/HibernateMembershipModuleImpl.java
trunk/identity/src/main/org/jboss/portal/identity2/db/HibernateRoleModuleImpl.java
trunk/identity/src/main/org/jboss/portal/identity2/db/HibernateUserModuleImpl.java
trunk/identity/src/main/org/jboss/portal/identity2/db/ProfileMapImpl.java
trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPUserProfileModule.java
trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPUserProfileModuleImpl.java
trunk/identity/src/main/org/jboss/portal/identity2/service/
trunk/identity/src/main/org/jboss/portal/identity2/service/MembershipModuleService.java
trunk/identity/src/main/org/jboss/portal/identity2/service/RoleModuleService.java
trunk/identity/src/main/org/jboss/portal/identity2/service/UserModuleService.java
trunk/identity/src/main/org/jboss/portal/identity2/service/UserProfileModuleService.java
Removed:
trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPUserProfileModuleImpl.java
Modified:
trunk/identity/src/main/org/jboss/portal/identity2/IdentityConfiguration.java
trunk/identity/src/main/org/jboss/portal/identity2/IdentityContextImpl.java
trunk/identity/src/main/org/jboss/portal/identity2/MembershipModule.java
trunk/identity/src/main/org/jboss/portal/identity2/ProfileMap.java
trunk/identity/src/main/org/jboss/portal/identity2/Role.java
trunk/identity/src/main/org/jboss/portal/identity2/RoleModule.java
trunk/identity/src/main/org/jboss/portal/identity2/User.java
trunk/identity/src/main/org/jboss/portal/identity2/UserModule.java
trunk/identity/src/main/org/jboss/portal/identity2/UserProfileModule.java
trunk/identity/src/main/org/jboss/portal/identity2/db/HibernateUserProfileModuleImpl.java
trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPExtRoleModuleImpl.java
trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPExtUserModuleImpl.java
trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPMembershipModule.java
trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPRoleImpl.java
trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPRoleModule.java
trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPRoleModuleImpl.java
trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPStaticGroupMembershipModuleImpl.java
trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPStaticRoleMembershipModuleImpl.java
trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPUserImpl.java
trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPUserModule.java
trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPUserModuleImpl.java
trunk/identity/src/main/org/jboss/portal/test/identity/MembershipStrategyTest.java
trunk/identity/src/main/org/jboss/portal/test/identity/ldap/LDAPSimpleRoleModuleTestCase.java
trunk/identity/src/main/org/jboss/portal/test/identity/ldap/LDAPSimpleUserModuleTestCase.java
trunk/identity/src/main/org/jboss/portal/test/identity/ldap/LDAPStaticGroupMembershipModuleTestCase.java
trunk/identity/src/main/org/jboss/portal/test/identity/ldap/LDAPStaticRoleMembershipModuleTestCase.java
trunk/identity/src/main/org/jboss/portal/test/identity/ldap/LDAPUserTestCase.java
trunk/test/src/etc/directories.xml
trunk/test/src/etc/identityconfig/opends-config.xml
trunk/test/src/etc/identityconfig/rhds-config.xml
Log:
identity module refactorings and interfaces updates
Modified: trunk/identity/src/main/org/jboss/portal/identity2/IdentityConfiguration.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/IdentityConfiguration.java 2006-11-19 23:34:25 UTC (rev 5677)
+++ trunk/identity/src/main/org/jboss/portal/identity2/IdentityConfiguration.java 2006-11-20 11:09:53 UTC (rev 5678)
@@ -44,6 +44,8 @@
public static final String GROUP_ROLE_CREATE_ATTRIBUTES = "roleCreateAttibutes";
+ public static final String GROUP_USER_PROFILE_MAPPINGS = "userProfileMappings";
+
public static final String CONNECTION_NAME = "connection-name";
public static final String CONNECTION_CONTEXT_FACTORY = "context-factory";
Modified: trunk/identity/src/main/org/jboss/portal/identity2/IdentityContextImpl.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/IdentityContextImpl.java 2006-11-19 23:34:25 UTC (rev 5677)
+++ trunk/identity/src/main/org/jboss/portal/identity2/IdentityContextImpl.java 2006-11-20 11:09:53 UTC (rev 5678)
@@ -94,7 +94,7 @@
}
else
{
- throw new IdentityException("No such mapping");
+ throw new IdentityException("No such mapping in IdentityContext: " + name);
}
}
}
Modified: trunk/identity/src/main/org/jboss/portal/identity2/MembershipModule.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/MembershipModule.java 2006-11-19 23:34:25 UTC (rev 5677)
+++ trunk/identity/src/main/org/jboss/portal/identity2/MembershipModule.java 2006-11-20 11:09:53 UTC (rev 5678)
@@ -24,8 +24,8 @@
import org.jboss.portal.identity.IdentityException;
-import org.jboss.portal.identity.User;
-import org.jboss.portal.identity.Role;
+import org.jboss.portal.identity2.User;
+import org.jboss.portal.identity2.Role;
import java.util.Set;
@@ -42,9 +42,9 @@
* @param user the user
* @return the set of roles of the specified user
*/
- Set getRoles(User user) throws IdentityException;
+ Set getRoles(User user) throws IdentityException, IllegalArgumentException;
- Set getUsers(Role role) throws IdentityException;
+ Set getUsers(Role role) throws IdentityException, IllegalArgumentException;
/**
@@ -55,7 +55,7 @@
* @param users
* @throws IdentityException
*/
- void assignUsers(Role role, Set users) throws IdentityException;
+ void assignUsers(Role role, Set users) throws IdentityException, IllegalArgumentException;
/**
* Creates a relationship beetween a user and set of roles. This operation will erase any other assotientions
@@ -65,7 +65,7 @@
* @param roles
* @throws IdentityException
*/
- void assignRoles(User user, Set roles) throws IdentityException;
+ void assignRoles(User user, Set roles) throws IdentityException, IllegalArgumentException;
/**
* Returns role members based on rolename - depreciated method ethod here only for compatibility with
@@ -76,5 +76,5 @@
* @param limit
* @deprecated
*/
- Set findRoleMembers(String roleName, int offset, int limit, String userNameFilter) throws IdentityException;
+ Set findRoleMembers(String roleName, int offset, int limit, String userNameFilter) throws IdentityException, IllegalArgumentException;
}
Modified: trunk/identity/src/main/org/jboss/portal/identity2/ProfileMap.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/ProfileMap.java 2006-11-19 23:34:25 UTC (rev 5677)
+++ trunk/identity/src/main/org/jboss/portal/identity2/ProfileMap.java 2006-11-20 11:09:53 UTC (rev 5678)
@@ -25,7 +25,7 @@
import java.util.Map;
/**
- * Extends <code>java.util.Map</code> to provide meta information about user profile.
+ * Extends <code>java.util.Map</code>le to provide meta information about user profile.
*
* @author <a href="mailto:julien at jboss.org">Julien Viet</a>
* @version $Revision: 5218 $
Modified: trunk/identity/src/main/org/jboss/portal/identity2/Role.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/Role.java 2006-11-19 23:34:25 UTC (rev 5677)
+++ trunk/identity/src/main/org/jboss/portal/identity2/Role.java 2006-11-20 11:09:53 UTC (rev 5678)
@@ -40,9 +40,6 @@
/** The role display name used on screens. This name can be modified */
String getDisplayName();
- /**
- *
- */
+ /** */
void setDisplayName(String name);
-
}
Modified: trunk/identity/src/main/org/jboss/portal/identity2/RoleModule.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/RoleModule.java 2006-11-19 23:34:25 UTC (rev 5677)
+++ trunk/identity/src/main/org/jboss/portal/identity2/RoleModule.java 2006-11-20 11:09:53 UTC (rev 5678)
@@ -23,7 +23,7 @@
package org.jboss.portal.identity2;
import org.jboss.portal.identity.IdentityException;
-import org.jboss.portal.identity.Role;
+import org.jboss.portal.identity2.Role;
import java.util.Set;
Modified: trunk/identity/src/main/org/jboss/portal/identity2/User.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/User.java 2006-11-19 23:34:25 UTC (rev 5677)
+++ trunk/identity/src/main/org/jboss/portal/identity2/User.java 2006-11-20 11:09:53 UTC (rev 5678)
@@ -37,11 +37,8 @@
*/
public interface User
{
-
- String INFO_USER_REGISTRATION_DATE = "portal.user.registration-date";
- String INFO_USER_HOMEPAGE = "portal.user.homepage";
- String INFO_USER_TIME_ZONE_OFFSET = "portal.user.time-zone-offset";
- String INFO_USER_THEME = "portal.user.theme";
+ String INFO_USER_NAME_GIVEN = "portal.user.name.given";
+ String INFO_USER_NAME_FAMILY = "portal.user.name.family";
String INFO_USER_LOCATION = "portal.user.location";
String INFO_USER_OCCUPATION = "portal.user.occupation";
String INFO_USER_EXTRA = "portal.user.extra";
@@ -53,111 +50,28 @@
String INFO_USER_IM_MSNM = "portal.user.im.msnm";
String INFO_USER_IM_YIM = "portal.user.im.yim";
String INFO_USER_IM_SKYPE = "portal.user.im.skype";
+ String INFO_USER_HOMEPAGE = "portal.user.homepage";
+ String INFO_USER_TIME_ZONE_OFFSET = "portal.user.time-zone-offset";
+ String INFO_USER_THEME = "portal.user.theme";
String INFO_USER_SECURITY_QUESTION = "portal.user.security.question";
String INFO_USER_SECURITY_ANSWER = "portal.user.security.answer";
String INFO_USER_EMAIL_FAKE = "portal.user.email.fake";
String INFO_USER_VIEW_EMAIL_VIEW_REAL = "portal.user.email.view-real";
String INFO_USER_LAST_LOGIN_DATE = "portal.user.last-login-date";
+ String INFO_USER_REGISTRATION_DATE = "portal.user.registration-date";
- /** The user identifier. */
- Object getId();
- // User management **************************************************************************************************
- /** Disable the user. */
- boolean getEnabled();
- /** Enable the user. */
- void setEnabled(boolean enable);
+ /** The user identifier. */
+ Object getId();
+ /** The user name. */
+ String getUserName();
+
/** Set the password. */
void updatePassword(String password);
/** Return true if the password is valid. */
boolean validatePassword(String password);
-
- // Detyped access to properties *************************************************************************************
-
- /** Returns the user properties. */
- ProfileMap getProfile();
-
- // Properties declared in this interface for convenient access ******************************************************
-
- /** The user name. */
- String getUserName();
-
- /** The given name (firstname). */
- String getGivenName();
-
- /**
- *
- */
- void setGivenName(String givenName);
-
- /** The family name. */
- String getFamilyName();
-
- /**
- *
- */
- void setFamilyName(String familyName);
-
- /**
- *
- */
- String getRealEmail();
-
- /**
- *
- */
- void setRealEmail(String realEmail);
-
- /**
- *
- */
- String getFakeEmail();
-
- /**
- *
- */
- void setFakeEmail(String fakeEmail);
-
- /**
- *
- */
- Date getRegistrationDate();
-
- /**
- *
- */
- boolean getViewRealEmail();
-
- /**
- *
- */
- void setViewRealEmail(boolean viewRealEmail);
-
- /** Return the user preferred locale. */
- Locale getPreferredLocale();
-
- /** Set the user preferred locale. */
- void setPreferredLocale(Locale locale);
-
- /** Returns the signature. */
- String getSignature();
-
- /** Set the signature. */
- void setSignature(String signature);
-
- /** Return the last time the user logged in or null if this date is not known. */
- Date getLastVisitDate();
-
- /** Set the last visit date on this user. */
- void setLastVisitDate(Date date);
-
- /** Return the theme set for this user as the app id of the Theme. */
- String getTheme();
-
- /** Set the theme for this user. */
- void setTheme(String themeId);
}
Modified: trunk/identity/src/main/org/jboss/portal/identity2/UserModule.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/UserModule.java 2006-11-19 23:34:25 UTC (rev 5677)
+++ trunk/identity/src/main/org/jboss/portal/identity2/UserModule.java 2006-11-20 11:09:53 UTC (rev 5678)
@@ -24,7 +24,7 @@
import org.jboss.portal.identity.IdentityException;
import org.jboss.portal.identity.NoSuchUserException;
-import org.jboss.portal.identity.User;
+import org.jboss.portal.identity2.User;
import java.util.Set;
@@ -66,6 +66,7 @@
* @param userName
* @return the user
*/
+ //TODO: remove realEmail from the signature
User createUser(String userName, String password, String realEmail) throws IdentityException, IllegalArgumentException;
/**
Modified: trunk/identity/src/main/org/jboss/portal/identity2/UserProfileModule.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/UserProfileModule.java 2006-11-19 23:34:25 UTC (rev 5677)
+++ trunk/identity/src/main/org/jboss/portal/identity2/UserProfileModule.java 2006-11-20 11:09:53 UTC (rev 5678)
@@ -22,8 +22,10 @@
******************************************************************************/
package org.jboss.portal.identity2;
-import java.util.Set;
+import org.jboss.portal.identity.IdentityException;
+import java.util.Map;
+
/**
* @author <a href="mailto:boleslaw.dawidowicz at jboss.org">Boleslaw Dawidowicz</a>
* @version $Revision: 1.1 $
@@ -31,10 +33,10 @@
public interface UserProfileModule
{
- public String getProperty(User user, String propertyName);
+ public Object getProperty(User user, String propertyName) throws IdentityException, IllegalArgumentException;
- public void setProperty(User user, String name, Object property);
+ public void setProperty(User user, String name, Object property) throws IdentityException, IllegalArgumentException;
- public Set getProperties(User user);
+ public Map getProperties(User user) throws IdentityException, IllegalArgumentException;
}
Added: trunk/identity/src/main/org/jboss/portal/identity2/db/DBRoleImpl.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/db/DBRoleImpl.java 2006-11-19 23:34:25 UTC (rev 5677)
+++ trunk/identity/src/main/org/jboss/portal/identity2/db/DBRoleImpl.java 2006-11-20 11:09:53 UTC (rev 5678)
@@ -0,0 +1,146 @@
+/*
+* 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.
+*/
+package org.jboss.portal.identity2.db;
+
+import org.jboss.portal.identity2.Role;
+
+import java.util.Set;
+import java.util.HashSet;
+
+/**
+ * @author <a href="mailto:julien at jboss.org">Julien Viet </a>
+ * @author <a href="mailto:theute at jboss.org">Thomas Heute </a>
+ * @author Roy Russo : roy at jboss dot org
+ * @version $Revision: 5448 $
+ */
+public class DBRoleImpl
+ implements Role
+{
+
+ private Long key;
+ private String name;
+ private Set users;
+ private String displayName;
+
+ /**
+ *
+ */
+ public DBRoleImpl()
+ {
+ this.key = null;
+ this.name = null;
+ this.displayName = null;
+ this.users = new HashSet();
+ }
+
+ /**
+ *
+ */
+ public DBRoleImpl(String name)
+ {
+ this.key = null;
+ this.name = name;
+ this.displayName = name;
+ this.users = new HashSet();
+ }
+
+ /**
+ *
+ */
+ public DBRoleImpl(String name, String displayName)
+ {
+ this.key = null;
+ this.name = name;
+ this.displayName = displayName;
+ this.users = new HashSet();
+ }
+
+ /**
+ * Called by hibernate.
+ */
+ protected Long getKey()
+ {
+ return key;
+ }
+
+ /** Called by hibernate. */
+ protected void setKey(Long key)
+ {
+ this.key = key;
+ }
+
+ /** Called by hibernate. */
+ protected void setName(String name)
+ {
+ this.name = name;
+ }
+
+ /** Called by hibernate. */
+ protected void setUsers(Set users)
+ {
+ this.users = users;
+ }
+
+ // ******************************************************************************************************************
+
+ public Object getId()
+ {
+ return key;
+ }
+
+ /**
+ *
+ */
+ public String getName()
+ {
+ return name;
+ }
+
+ /**
+ *
+ */
+ public String getDisplayName()
+ {
+ return displayName;
+ }
+
+ /**
+ *
+ */
+ public void setDisplayName(String displayName)
+ {
+ this.displayName = displayName;
+ }
+
+ /**
+ *
+ */
+ public Set getUsers()
+ {
+ return users;
+ }
+
+ public String toString()
+ {
+ return "Role[" + key + "," + name + "]";
+ }
+}
Added: trunk/identity/src/main/org/jboss/portal/identity2/db/DBUserImpl.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/db/DBUserImpl.java 2006-11-19 23:34:25 UTC (rev 5677)
+++ trunk/identity/src/main/org/jboss/portal/identity2/db/DBUserImpl.java 2006-11-20 11:09:53 UTC (rev 5678)
@@ -0,0 +1,660 @@
+/*
+* 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.
+*/
+package org.jboss.portal.identity2.db;
+
+import org.jboss.portal.identity2.User;
+import org.jboss.portal.identity2.ProfileMap;
+import org.jboss.portal.identity2.Role;
+import org.jboss.portal.identity2.db.ProfileMapImpl;
+import org.jboss.portal.common.p3p.P3PConstants;
+import org.jboss.portal.common.util.Tools;
+import org.jboss.portal.common.util.LocaleInfo;
+
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Collections;
+import java.util.Set;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.Locale;
+import java.util.Iterator;
+import java.lang.reflect.Field;
+import java.text.SimpleDateFormat;
+import java.text.DateFormat;
+import java.text.ParseException;
+
+/**
+ * User interface implementation.
+ *
+ * @author <a href="mailto:julien at jboss.org">Julien Viet </a>
+ * @author <a href="mailto:theute at jboss.org">Thomas Heute </a>
+ * @author <a href="mailto:mageshbk at jboss.com">Magesh Kumar Bojan </a>
+ * @version $Revision: 5448 $
+ */
+public class DBUserImpl
+ implements User
+{
+
+ private static final org.jboss.logging.Logger log = org.jboss.logging.Logger.getLogger(DBUserImpl.class);
+
+ static final Map ACCESSORS = buildAccessors();
+
+ private static Map buildAccessors()
+ {
+ Map map = new HashMap();
+
+ // Map attributes defined by the JSR 168 spec P3P.
+ map.put(P3PConstants.INFO_USER_NAME_NICKNAME, new DBUserImpl.StringPropertyAccessor(P3PConstants.INFO_USER_NAME_NICKNAME, "userName", false, false));
+ map.put(P3PConstants.INFO_USER_BUSINESS_INFO_ONLINE_EMAIL, new DBUserImpl.StringPropertyAccessor(P3PConstants.INFO_USER_BUSINESS_INFO_ONLINE_EMAIL, "realEmail", true, true));
+ map.put(P3PConstants.INFO_USER_NAME_GIVEN, new DBUserImpl.StringPropertyAccessor(P3PConstants.INFO_USER_NAME_GIVEN, "givenName", true, true));
+ map.put(P3PConstants.INFO_USER_NAME_FAMILY, new DBUserImpl.StringPropertyAccessor(P3PConstants.INFO_USER_NAME_FAMILY, "familyName", true, true));
+
+ // Map attributes specific to JBoss Portal
+ map.put(User.INFO_USER_EMAIL_FAKE, new DBUserImpl.StringPropertyAccessor(User.INFO_USER_EMAIL_FAKE, "fakeEmail", true, true));
+ map.put(User.INFO_USER_REGISTRATION_DATE, new DBUserImpl.DatePropertyAccessor(User.INFO_USER_REGISTRATION_DATE, "registrationDate", false, false));
+ map.put(User.INFO_USER_VIEW_EMAIL_VIEW_REAL, new DBUserImpl.BooleanPropertyAccessor(User.INFO_USER_VIEW_EMAIL_VIEW_REAL, "viewRealEmail", true, false));
+
+ //
+ return Collections.unmodifiableMap(map);
+ }
+
+ /*
+ * Transient fields.
+ */
+
+ protected ProfileMap profile;
+ protected Set roleNames;
+
+ /*
+ * P3P mapped persistent fields.
+ */
+
+ protected String userName;
+ protected String givenName;
+ protected String familyName;
+ protected String realEmail;
+
+ /*
+ * Non mapped persistent fields.
+ */
+
+ protected Long key;
+ protected boolean enabled;
+ protected String password;
+
+ /*
+ * Extension mapped persistent fields.
+ */
+
+ protected String fakeEmail;
+ protected boolean viewRealEmail;
+ protected Date registrationDate;
+
+ /*
+ * Persistent associations
+ */
+
+ protected Map dynamic;
+ protected Set roles;
+
+ /**
+ *
+ */
+ public DBUserImpl()
+ {
+ this.key = null;
+ this.userName = null;
+ this.dynamic = null;
+ this.profile = new ProfileMapImpl(this);
+ this.roles = null;
+ this.registrationDate = null;
+ this.enabled = false;
+ }
+
+ /**
+ *
+ */
+ public DBUserImpl(String userName)
+ {
+ this.key = null;
+ this.userName = userName;
+ this.dynamic = new HashMap();
+ this.profile = new ProfileMapImpl(this);
+ this.roles = new HashSet();
+ this.registrationDate = new Date();
+ this.enabled = false;
+ }
+
+ /** Called by hibernate. */
+ public Long getKey()
+ {
+ return key;
+ }
+
+ /** Called by hibernate. */
+ protected void setKey(Long key)
+ {
+ this.key = key;
+ }
+
+ /** Called by hibernate. */
+ protected void setUserName(String userName)
+ {
+ this.userName = userName;
+ }
+
+ /** Called by Hibernate. */
+ protected Map getDynamic()
+ {
+ return dynamic;
+ }
+
+ /** Called by Hibernate. */
+ protected void setDynamic(Map dynamic)
+ {
+ this.dynamic = dynamic;
+ }
+
+ // User implementation **********************************************************************************************
+
+ /**
+ *
+ */
+ public Object getId()
+ {
+ return key;
+ }
+
+ /**
+ *
+ */
+ public String getUserName()
+ {
+ return userName;
+ }
+
+ /**
+ *
+ */
+ public String getGivenName()
+ {
+ return givenName;
+ }
+
+ public void setGivenName(String givenName)
+ {
+ this.givenName = givenName;
+ }
+
+ /**
+ *
+ */
+ public String getFamilyName()
+ {
+ return familyName;
+ }
+
+ public void setFamilyName(String familyName)
+ {
+ this.familyName = familyName;
+ }
+
+ public void updatePassword(String password)
+ {
+ this.password = Tools.md5AsHexString(password);
+ }
+
+ /**
+ *
+ */
+ public String getRealEmail()
+ {
+ return realEmail;
+ }
+
+ /**
+ *
+ */
+ public void setRealEmail(String realEmail)
+ {
+ this.realEmail = realEmail;
+ }
+
+ /**
+ *
+ */
+ public String getFakeEmail()
+ {
+ return fakeEmail;
+ }
+
+ /**
+ *
+ */
+ public void setFakeEmail(String fakeEmail)
+ {
+ this.fakeEmail = fakeEmail;
+ }
+
+ /**
+ *
+ */
+ public Date getRegistrationDate()
+ {
+ return registrationDate;
+ }
+
+ /**
+ *
+ */
+ public void setRegistrationDate(Date registrationDate)
+ {
+ this.registrationDate = registrationDate;
+ }
+
+ /**
+ *
+ */
+ public boolean getViewRealEmail()
+ {
+ return viewRealEmail;
+ }
+
+ /**
+ *
+ */
+ public void setViewRealEmail(boolean viewRealEmail)
+ {
+ this.viewRealEmail = viewRealEmail;
+ }
+
+ /**
+ *
+ */
+ public boolean getEnabled()
+ {
+ return enabled;
+ }
+
+ /**
+ *
+ */
+ public void setEnabled(boolean enable)
+ {
+ this.enabled = enable;
+ }
+
+ /**
+ *
+ */
+ public ProfileMap getProfile()
+ {
+ return profile;
+ }
+
+ public String getPassword()
+ {
+ return password;
+ }
+
+ public void setPassword(String password)
+ {
+ this.password = password;
+ }
+
+ /** Returns the roles related to this user. */
+ public Set getRoles()
+ {
+ return roles;
+ }
+
+ /** Update the roles. */
+ public void setRoles(Set roles)
+ {
+ this.roles = roles;
+ this.roleNames = null;
+ }
+
+ // Dynamic attributes
+
+ /** Implemented as a dynamic attribute (see #INFO_USER_LAST_LOGIN_DATE). */
+ public Date getLastVisitDate()
+ {
+ Date date = null;
+ String dateAsString = (String)getDynamic().get(User.INFO_USER_LAST_LOGIN_DATE);
+ if (dateAsString != null)
+ {
+ try
+ {
+ long dateAsLong = Long.parseLong(dateAsString);
+ date = new Date(dateAsLong);
+ }
+ catch (NumberFormatException e)
+ {
+ log.error("Bad date format " + dateAsString + " try to remove it", e);
+ getDynamic().remove(User.INFO_USER_LAST_LOGIN_DATE);
+ }
+ }
+ return date;
+ }
+
+ public void setLastVisitDate(Date date)
+ {
+ if (date == null)
+ {
+ getDynamic().remove(User.INFO_USER_LAST_LOGIN_DATE);
+ }
+ else
+ {
+ long dateAsLong = date.getTime();
+ String dateAsString = Long.toString(dateAsLong);
+ getDynamic().put(User.INFO_USER_LAST_LOGIN_DATE, dateAsString);
+ }
+ }
+
+ /** Implemented as a dynamic attribute (see #INFO_USER_SIGNATURE). */
+ public String getSignature()
+ {
+ return (String)getDynamic().get(User.INFO_USER_SIGNATURE);
+ }
+
+ public void setSignature(String signature)
+ {
+ getDynamic().put(User.INFO_USER_SIGNATURE, signature);
+ }
+
+ /** Implemented as a dynamic attribute (see #INFO_USER_LOCALE). */
+ public Locale getPreferredLocale()
+ {
+ Locale locale = null;
+ String localeAsString = (String)getDynamic().get(User.INFO_USER_LOCALE);
+ if (localeAsString != null)
+ {
+ LocaleInfo info = LocaleInfo.decodeLocaleInfo(localeAsString);
+ if (info != null)
+ {
+ locale = info.getLocale();
+ }
+ }
+ return locale;
+ }
+
+ public void setPreferredLocale(Locale locale)
+ {
+ if (locale == null)
+ {
+ getDynamic().remove(User.INFO_USER_LOCALE);
+ }
+ else
+ {
+ String localeAsString = locale.toString();
+ getDynamic().put(User.INFO_USER_LOCALE, localeAsString);
+ }
+ }
+
+ public String getTheme()
+ {
+ return (String)getDynamic().get(User.INFO_USER_THEME);
+ }
+
+ public void setTheme(String themeId)
+ {
+ if ((themeId == null) || (themeId.equals("")))
+ {
+ getDynamic().remove(User.INFO_USER_THEME);
+ }
+ else
+ {
+ getDynamic().put(User.INFO_USER_THEME, themeId);
+ }
+ }
+
+ public boolean validatePassword(String password)
+ {
+ if (password != null)
+ {
+ String hashedPassword = Tools.md5AsHexString(password);
+ return hashedPassword.equals(this.password);
+ }
+ return false;
+ }
+
+ /** Return all the role names of the user. */
+ public Set getRoleNames()
+ {
+ if (roleNames == null)
+ {
+ Iterator it = roles.iterator();
+ roleNames = new HashSet();
+ while (it.hasNext())
+ {
+ roleNames.add(((Role)it.next()).getName());
+ }
+ }
+ return roleNames;
+ }
+
+ /**
+ *
+ */
+ public String toString()
+ {
+ return "User[" + key + "," + userName + "]";
+ }
+
+ /** An accessor that maps a user field to a property name. */
+ static abstract class PropertyAccessor
+ {
+
+ protected final String propertyName;
+ protected final Field field;
+ protected final boolean writable;
+ protected final boolean nullable;
+
+ public PropertyAccessor(String propertyName, String fieldName, boolean writable, boolean nullable)
+ {
+ try
+ {
+ this.propertyName = propertyName;
+ this.writable = writable;
+ this.field = DBUserImpl.class.getDeclaredField(fieldName);
+ this.nullable = nullable;
+ }
+ catch (NoSuchFieldException e)
+ {
+ throw new Error(e);
+ }
+ }
+
+ public String getPropertyName()
+ {
+ return propertyName;
+ }
+
+ public boolean isNullable()
+ {
+ return nullable;
+ }
+
+ public boolean isWritable()
+ {
+ return writable;
+ }
+
+ /**
+ * @param instance the user instance
+ * @param string the value
+ * @throws IllegalArgumentException if the string cannot be converted to an object
+ */
+ public void set(Object instance, String string) throws IllegalArgumentException
+ {
+ try
+ {
+ if (string == null)
+ {
+ field.set(instance, null);
+ }
+ else
+ {
+ Object object = toObject(string);
+ field.set(instance, object);
+ }
+ }
+ catch (IllegalAccessException e)
+ {
+ throw new Error(e);
+ }
+ }
+
+ /**
+ * @param instance the user instance
+ * @return the converted value
+ * @throws IllegalArgumentException if the object cannot be converted to a string
+ */
+ public String get(Object instance) throws IllegalArgumentException
+ {
+ try
+ {
+ Object object = field.get(instance);
+ if (object == null)
+ {
+ return null;
+ }
+ else
+ {
+ return toString(object);
+ }
+ }
+ catch (IllegalAccessException e)
+ {
+ throw new Error(e);
+ }
+ }
+
+ /**
+ * Perform the to object conversion.
+ *
+ * @param value the value to convert
+ * @return the converted value
+ * @throws IllegalArgumentException if the string cannot be converted to an object
+ */
+ protected abstract Object toObject(String value) throws IllegalArgumentException;
+
+ /**
+ * Perform the to strong conversion.
+ *
+ * @param value the value to convert
+ * @return the converted value
+ * @throws IllegalArgumentException if the object cannot be converted to a string
+ */
+ protected abstract String toString(Object value);
+
+ public String toString()
+ {
+ return "PropertyAccessor[" + propertyName + "," + field + "]";
+ }
+ }
+
+ static class StringPropertyAccessor extends DBUserImpl.PropertyAccessor
+ {
+ public StringPropertyAccessor(String propertyName, String fieldName, boolean writable, boolean nullable)
+ {
+ super(propertyName, fieldName, writable, nullable);
+ }
+
+ protected Object toObject(String value)
+ {
+ return value;
+ }
+
+ protected String toString(Object value)
+ {
+ return (String)value;
+ }
+ }
+
+ static class BooleanPropertyAccessor extends DBUserImpl.PropertyAccessor
+ {
+ public BooleanPropertyAccessor(String propertyName, String fieldName, boolean writable, boolean nullable)
+ {
+ super(propertyName, fieldName, writable, nullable);
+ }
+
+ protected Object toObject(String value) throws IllegalArgumentException
+ {
+ if ("true".equalsIgnoreCase(value))
+ {
+ return Boolean.TRUE;
+ }
+ else if ("false".equalsIgnoreCase(value))
+ {
+ return Boolean.FALSE;
+ }
+ else
+ {
+ throw new IllegalArgumentException("The value " + value + " cannot be converted to boolean for accessor " + toString());
+ }
+ }
+
+ protected String toString(Object value)
+ {
+ return value.toString();
+ }
+ }
+
+ static class DatePropertyAccessor extends DBUserImpl.PropertyAccessor
+ {
+ private static final ThreadLocal formatLocal = new ThreadLocal()
+ {
+ protected Object initialValue()
+ {
+ return new SimpleDateFormat();
+ }
+ };
+
+ public DatePropertyAccessor(String propertyName, String fieldName, boolean writable, boolean nullable)
+ {
+ super(propertyName, fieldName, writable, nullable);
+ }
+
+ protected Object toObject(String value) throws IllegalArgumentException
+ {
+ try
+ {
+ DateFormat format = (DateFormat)formatLocal.get();
+ Date date = format.parse(value);
+ return date;
+ }
+ catch (ParseException e)
+ {
+ throw new IllegalArgumentException();
+ }
+ }
+
+ protected String toString(Object value)
+ {
+ Date date = (Date)value;
+ DateFormat format = (DateFormat)formatLocal.get();
+ return format.format(date);
+ }
+ }
+}
Added: trunk/identity/src/main/org/jboss/portal/identity2/db/HibernateMembershipModuleImpl.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/db/HibernateMembershipModuleImpl.java 2006-11-19 23:34:25 UTC (rev 5677)
+++ trunk/identity/src/main/org/jboss/portal/identity2/db/HibernateMembershipModuleImpl.java 2006-11-20 11:09:53 UTC (rev 5678)
@@ -0,0 +1,61 @@
+/*
+* 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.
+*/
+package org.jboss.portal.identity2.db;
+
+import org.jboss.portal.identity2.service.MembershipModuleService;
+import org.jboss.portal.identity2.User;
+import org.jboss.portal.identity2.Role;
+import org.jboss.portal.identity.IdentityException;
+
+import java.util.Set;
+
+/**
+ * @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw Dawidowicz</a>
+ * @version $Revision: 1.1 $
+ */
+public class HibernateMembershipModuleImpl extends MembershipModuleService
+{
+ public Set getRoles(User user) throws IdentityException
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public Set getUsers(Role role) throws IdentityException
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void assignUsers(Role role, Set users) throws IdentityException
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void assignRoles(User user, Set roles) throws IdentityException
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public Set findRoleMembers(String roleName, int offset, int limit, String userNameFilter) throws IdentityException
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+}
Added: trunk/identity/src/main/org/jboss/portal/identity2/db/HibernateRoleModuleImpl.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/db/HibernateRoleModuleImpl.java 2006-11-19 23:34:25 UTC (rev 5677)
+++ trunk/identity/src/main/org/jboss/portal/identity2/db/HibernateRoleModuleImpl.java 2006-11-20 11:09:53 UTC (rev 5678)
@@ -0,0 +1,388 @@
+/*
+* 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.
+*/
+package org.jboss.portal.identity2.db;
+
+import org.jboss.portal.identity2.Role;
+import org.jboss.portal.identity.IdentityException;
+import org.jboss.portal.identity2.User;
+import org.jboss.portal.common.util.Tools;
+import org.jboss.portal.identity2.service.RoleModuleService;
+import org.hibernate.SessionFactory;
+import org.hibernate.Session;
+import org.hibernate.Criteria;
+import org.hibernate.HibernateException;
+import org.hibernate.Query;
+import org.hibernate.criterion.Restrictions;
+
+import javax.naming.InitialContext;
+import java.util.Set;
+import java.util.Iterator;
+import java.util.HashSet;
+import java.util.Collections;
+
+/**
+ * @author <a href="mailto:julien at jboss.org">Julien Viet </a>
+ * @author <a href="mailto:theute at jboss.org">Thomas Heute </a>
+ * @author Roy Russo : roy at jboss dot org
+ * @version $Revision: 5448 $
+ * @portal.core
+ */
+public class HibernateRoleModuleImpl extends RoleModuleService
+{
+ private static final org.jboss.logging.Logger log = org.jboss.logging.Logger.getLogger(HibernateUserModuleImpl.class);
+
+ /** . */
+ protected String sessionFactoryJNDIName;
+
+ /** . */
+ protected SessionFactory sessionFactory;
+
+ public String getSessionFactoryJNDIName()
+ {
+ return sessionFactoryJNDIName;
+ }
+
+ public void setSessionFactoryJNDIName(String sessionFactoryJNDIName)
+ {
+ this.sessionFactoryJNDIName = sessionFactoryJNDIName;
+ }
+
+ public SessionFactory getSessionFactory()
+ {
+ return sessionFactory;
+ }
+
+ protected void startService() throws Exception
+ {
+ //
+ sessionFactory = (SessionFactory)new InitialContext().lookup(sessionFactoryJNDIName);
+
+ super.startService();
+ }
+
+ protected void stopService() throws Exception
+ {
+ sessionFactory = null;
+
+ super.stopService();
+
+ //
+
+ }
+
+ public Role findRoleByName(String name) throws IdentityException
+ {
+ if (name != null)
+ {
+ try
+ {
+ Session session = getCurrentSession();
+ Criteria criteria = session.createCriteria(DBRoleImpl.class);
+ criteria.add(Restrictions.naturalId().set("name", name));
+ criteria.setCacheable(true);
+ DBRoleImpl role = (DBRoleImpl)criteria.uniqueResult();
+ if (role == null)
+ {
+ throw new IdentityException("No such role " + name);
+ }
+ return role;
+ }
+ catch (HibernateException e)
+ {
+ String message = "Cannot find role by name " + name;
+ log.error(message, e);
+ throw new IdentityException(message, e);
+ }
+ }
+ else
+ {
+ throw new IllegalArgumentException("name cannot be null");
+ }
+ }
+
+ public Set findRolesByNames(String[] names) throws IdentityException
+ {
+ if (names != null)
+ {
+ try
+ {
+ Session session = getCurrentSession();
+ StringBuffer queryString = new StringBuffer("from DBRoleImpl as g where g.name=?");
+ for (int i = 1; i < names.length; i++)
+ {
+ queryString.append(" or g.name=?");
+ }
+ Query query = session.createQuery(queryString.toString());
+ for (int i = 0; i < names.length; i++)
+ {
+ query.setString(i, names[i]);
+ }
+ Iterator iterator = query.iterate();
+ return Tools.toSet(iterator);
+ }
+ catch (HibernateException e)
+ {
+ String message = "Cannot find roles";
+ log.error(message, e);
+ throw new IdentityException(message, e);
+ }
+ }
+ else
+ {
+ throw new IllegalArgumentException("name cannot be null");
+ }
+ }
+
+ public Role findRoleById(String id) throws IllegalArgumentException, IdentityException
+ {
+ if (id == null)
+ {
+ throw new IllegalArgumentException("The id is null");
+ }
+ try
+ {
+ return findRoleById(new Long(id));
+ }
+ catch (NumberFormatException e)
+ {
+ throw new IllegalArgumentException("Cannot parse id into an long " + id);
+ }
+ }
+
+ public Role findRoleById(Object id) throws IdentityException
+ {
+ if (id instanceof Long)
+ {
+ try
+ {
+ Session session = getCurrentSession();
+ DBRoleImpl role = (DBRoleImpl)session.get(DBRoleImpl.class, (Long)id);
+ if (role == null)
+ {
+ throw new IdentityException("No role found for " + id);
+ }
+ return role;
+ }
+ catch (HibernateException e)
+ {
+ String message = "Cannot find role by id " + id;
+ log.error(message, e);
+ throw new IdentityException(message, e);
+ }
+ }
+ else
+ {
+ throw new IllegalArgumentException("The id is not an long : " + id);
+ }
+ }
+
+ public Role createRole(String name, String displayName) throws IdentityException
+ {
+ if (name != null)
+ {
+ try
+ {
+ DBRoleImpl role = new DBRoleImpl(name, displayName);
+ Session session = getCurrentSession();
+ session.save(role);
+ return role;
+ }
+ catch (HibernateException e)
+ {
+ String message = "Cannot create role " + name;
+ log.error(message, e);
+ throw new IdentityException(message, e);
+ }
+ }
+ else
+ {
+ throw new IllegalArgumentException("name cannot be null");
+ }
+ }
+
+ public void removeRole(Object id) throws IdentityException
+ {
+ if (id instanceof Long)
+ {
+ try
+ {
+ Session session = getCurrentSession();
+ DBRoleImpl role = (DBRoleImpl)session.load(DBRoleImpl.class, (Long)id);
+ Iterator users = role.getUsers().iterator();
+ while (users.hasNext())
+ {
+ DBUserImpl user = (DBUserImpl)users.next();
+ user.getRoles().remove(role);
+ }
+ session.delete(role);
+ session.flush();
+ }
+ catch (HibernateException e)
+ {
+ String message = "Cannot remove role " + id;
+ log.error(message, e);
+ throw new IdentityException(message, e);
+ }
+ }
+ else
+ {
+ throw new IllegalArgumentException("The id is not an long : " + id);
+ }
+ }
+
+ public int getRolesCount() throws IdentityException
+ {
+ try
+ {
+ Session session = getCurrentSession();
+ Query query = session.createQuery("select count(g.id) from DBRoleImpl as g");
+ return ((Number)query.uniqueResult()).intValue();
+ }
+ catch (HibernateException e)
+ {
+ String message = "Cannot count roles";
+ log.error(message, e);
+ throw new IdentityException(message, e);
+ }
+ }
+
+ public Set findRoles() throws IdentityException
+ {
+ try
+ {
+ Session session = getCurrentSession();
+ Query query = session.createQuery("from DBRoleImpl");
+ Iterator iterator = query.iterate();
+ return Tools.toSet(iterator);
+ }
+ catch (HibernateException e)
+ {
+ String message = "Cannot find roles";
+ log.error(message, e);
+ throw new IdentityException(message, e);
+ }
+ }
+
+ public Set findRoleMembers(String roleName, int offset, int limit, String userNameFilter) throws IdentityException
+ {
+ if (roleName != null)
+ {
+ try
+ {
+ Session session = getCurrentSession();
+
+ DBUserImpl userimpl = new DBUserImpl();
+ userimpl.setEnabled(true);
+
+ Query query;
+ if (userNameFilter.trim().length() != 0)
+ {
+ //
+ userNameFilter = "%" + userNameFilter.replaceAll("%", "") + "%";
+
+ //
+ query = session.createQuery("from DBUserImpl as user left join user.roles role where role.name=:name" + " AND user.userName LIKE :filter");
+ query.setString("filter", userNameFilter);
+ }
+ else
+ {
+ query = session.createQuery("from DBUserImpl as user left join user.roles role where role.name=:name");
+ }
+ query.setString("name", roleName);
+ query.setFirstResult(offset);
+ query.setMaxResults(limit);
+
+ Iterator iterator = query.iterate();
+ Set result = Tools.toSet(iterator);
+
+ Set newResult = new HashSet();
+ Iterator cleaner = result.iterator();
+ while (cleaner.hasNext())
+ {
+ Object[] oArr = (Object[])cleaner.next();
+ newResult.add(oArr[0]);
+ }
+
+ return newResult;
+ }
+ catch (HibernateException e)
+ {
+ String message = "Cannot find role " + roleName;
+ log.error(message, e);
+ throw new IdentityException(message, e);
+ }
+ }
+ else
+ {
+ throw new IllegalArgumentException("id cannot be null");
+ }
+ }
+
+ public void setRoles(User user, Set roles) throws IdentityException
+ {
+ if (!(user instanceof DBUserImpl))
+ {
+ throw new IllegalArgumentException("User is not a db user");
+ }
+
+ // We make a defensive copy and update with a new set
+ Set copy = new HashSet();
+ for (Iterator i = roles.iterator(); i.hasNext();)
+ {
+ Object o = i.next();
+ if (o instanceof DBRoleImpl)
+ {
+ copy.add(o);
+ }
+ else
+ {
+ throw new IllegalArgumentException("Only db roles can be accepted");
+ }
+ }
+
+ // Assign new roles
+ DBUserImpl ui = (DBUserImpl)user;
+ ui.setRoles(copy);
+ }
+
+ public Set getRoles(User user) throws IdentityException
+ {
+ if (!(user instanceof DBUserImpl))
+ {
+ throw new IllegalArgumentException("User is not a db user");
+ }
+
+ // We return an immutable set to avoid modifications
+ DBUserImpl ui = (DBUserImpl)user;
+ return Collections.unmodifiableSet(ui.getRoles());
+ }
+
+ /** Can be subclasses to provide testing in a non JTA environement. */
+ protected Session getCurrentSession()
+ {
+ if (sessionFactory == null)
+ {
+ throw new IllegalStateException("No session factory");
+ }
+ return sessionFactory.getCurrentSession();
+ }
+}
Added: trunk/identity/src/main/org/jboss/portal/identity2/db/HibernateUserModuleImpl.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/db/HibernateUserModuleImpl.java 2006-11-19 23:34:25 UTC (rev 5677)
+++ trunk/identity/src/main/org/jboss/portal/identity2/db/HibernateUserModuleImpl.java 2006-11-20 11:09:53 UTC (rev 5678)
@@ -0,0 +1,315 @@
+/*
+* 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.
+*/
+package org.jboss.portal.identity2.db;
+
+import org.jboss.portal.identity2.User;
+import org.jboss.portal.identity2.service.UserModuleService;
+import org.jboss.portal.identity.IdentityException;
+import org.jboss.portal.identity.NoSuchUserException;
+import org.jboss.portal.common.util.JNDI;
+import org.jboss.portal.common.util.Tools;
+import org.hibernate.SessionFactory;
+import org.hibernate.Session;
+import org.hibernate.Query;
+import org.hibernate.HibernateException;
+
+import javax.naming.InitialContext;
+import java.io.Serializable;
+import java.util.Set;
+import java.util.Iterator;
+
+/**
+ * @author <a href="mailto:julien at jboss.org">Julien Viet </a>
+ * @version $Revision: 5448 $
+ * @portal.core
+ */
+public class HibernateUserModuleImpl extends UserModuleService
+{
+
+ /** . */
+ private static final org.jboss.logging.Logger log = org.jboss.logging.Logger.getLogger(HibernateUserModuleImpl.class);
+ /** . */
+ protected SessionFactory sessionFactory;
+
+ /** . */
+ protected String sessionFactoryJNDIName;
+
+ /** . */
+ protected String jndiName;
+
+ /** . */
+ protected JNDI.Binding jndiBinding;
+
+ public HibernateUserModuleImpl()
+ {
+ }
+
+ protected void startService() throws Exception
+ {
+ //
+ sessionFactory = (SessionFactory)new InitialContext().lookup(sessionFactoryJNDIName);
+
+ //
+ if (jndiName != null)
+ {
+ jndiBinding = new JNDI.Binding(jndiName, this);
+ jndiBinding.bind();
+ }
+ }
+
+ protected void stopService() throws Exception
+ {
+ if (jndiBinding != null)
+ {
+ jndiBinding.unbind();
+ jndiBinding = null;
+ }
+
+ //
+ sessionFactory = null;
+ }
+
+ public SessionFactory getSessionFactory()
+ {
+ return sessionFactory;
+ }
+
+ public String getSessionFactoryJNDIName()
+ {
+ return sessionFactoryJNDIName;
+ }
+
+ public void setSessionFactoryJNDIName(String sessionFactoryJNDIName)
+ {
+ this.sessionFactoryJNDIName = sessionFactoryJNDIName;
+ }
+
+ public String getJNDIName()
+ {
+ return jndiName;
+ }
+
+ public void setJNDIName(String jndiName)
+ {
+ this.jndiName = jndiName;
+ }
+
+ public User findUserByUserName(String userName) throws IdentityException
+ {
+ if (userName != null)
+ {
+ try
+ {
+ Session session = getCurrentSession();
+ Query query = session.createQuery("from DBDBUserImpl where userName=:userName");
+ query.setParameter("userName", userName);
+ query.setCacheable(true);
+ DBUserImpl user = (DBUserImpl)query.uniqueResult();
+ if (user == null)
+ {
+ throw new NoSuchUserException("No such user " + userName);
+ }
+ return user;
+ }
+ catch (HibernateException e)
+ {
+ String message = "Cannot find user by name " + userName;
+ log.error(message, e);
+ throw new IdentityException(message, e);
+ }
+ }
+ else
+ {
+ throw new IllegalArgumentException("user name cannot be null");
+ }
+ }
+
+ public User findUserById(String id) throws IllegalArgumentException, IdentityException, NoSuchUserException
+ {
+ if (id == null)
+ {
+ throw new IllegalArgumentException("The id is null");
+ }
+ try
+ {
+ return findUserById(new Long(id));
+ }
+ catch (NumberFormatException e)
+ {
+ throw new IllegalArgumentException("Cannot parse id into an long " + id);
+ }
+ }
+
+ public User findUserById(Object id) throws IllegalArgumentException, IdentityException, NoSuchUserException
+ {
+ if (id instanceof Long)
+ {
+ try
+ {
+ Session session = getCurrentSession();
+ DBUserImpl user = (DBUserImpl)session.get(DBUserImpl.class, (Long)id);
+ if (user == null)
+ {
+ throw new NoSuchUserException("No user found for " + id);
+ }
+ return user;
+ }
+ catch (HibernateException e)
+ {
+ String message = "Cannot find user by id " + id;
+ log.error(message, e);
+ throw new IdentityException(message, e);
+ }
+ }
+ else
+ {
+ throw new IllegalArgumentException("The id is not an long : " + id);
+ }
+ }
+
+ public User createUser(String userName, String password, String realEmail) throws IdentityException
+ {
+ if (userName != null)
+ {
+ try
+ {
+ DBUserImpl user = new DBUserImpl(userName);
+ user.updatePassword(password);
+ user.setRealEmail(realEmail);
+ Session session = getCurrentSession();
+ session.save(user);
+ return user;
+ }
+ catch (HibernateException e)
+ {
+ String message = "Cannot create user " + userName;
+ log.error(message, e);
+ throw new IdentityException(message, e);
+ }
+ }
+ else
+ {
+ throw new IllegalArgumentException("name cannot be null");
+ }
+ }
+
+ public void removeUser(Object id) throws IdentityException
+ {
+ if (id instanceof Long)
+ {
+ try
+ {
+ Session session = getCurrentSession();
+ DBUserImpl user = (DBUserImpl)session.load(DBUserImpl.class, (Serializable)id);
+ if (user == null)
+ {
+ throw new NoSuchUserException("No such user " + id);
+ }
+ session.delete(user);
+ session.flush();
+ }
+ catch (HibernateException e)
+ {
+ String message = "Cannot remove user " + id;
+ log.error(message, e);
+ throw new IdentityException(message, e);
+ }
+ }
+ else
+ {
+ throw new IllegalArgumentException("The id is not an long : " + id);
+ }
+ }
+
+ public Set findUsers(int offset, int limit) throws IdentityException
+ {
+ try
+ {
+ Session session = getCurrentSession();
+ Query query = session.createQuery("from DBDBUserImpl");
+ query.setFirstResult(offset);
+ query.setMaxResults(limit);
+ Iterator iterator = query.iterate();
+ return Tools.toSet(iterator);
+ }
+ catch (HibernateException e)
+ {
+ String message = "Cannot find user range [" + offset + "," + limit + "]";
+ log.error(message, e);
+ throw new IdentityException(message, e);
+ }
+ }
+
+ public Set findUsersFilteredByUserName(String filter, int offset, int limit) throws IdentityException
+ {
+ try
+ {
+ // Remove all occurences of % and add ours
+ filter = "%" + filter.replaceAll("%", "") + "%";
+
+ //
+ Session session = getCurrentSession();
+ Query query = session.createQuery("from DBDBUserImpl as u where u.userName like :filter");
+ query.setString("filter", filter);
+ query.setFirstResult(offset);
+ query.setMaxResults(limit);
+ Iterator iterator = query.iterate();
+ return Tools.toSet(iterator);
+ }
+ catch (HibernateException e)
+ {
+ String message = "Cannot find user range [" + offset + "," + limit + "]";
+ log.error(message, e);
+ throw new IdentityException(message, e);
+ }
+ }
+
+ public int getUserCount() throws IdentityException
+ {
+ try
+ {
+ Session session = getCurrentSession();
+ Query query = session.createQuery("select count(u.key) from DBDBUserImpl as u");
+ return ((Number)query.uniqueResult()).intValue();
+ }
+ catch (HibernateException e)
+ {
+ String message = "Cannot count users";
+ log.error(message, e);
+ throw new IdentityException(message, e);
+ }
+ }
+
+ /**
+ * Can be subclasses to provide testing in a non JTA environement.
+ *
+ * @throws IllegalStateException if no session factory is present
+ */
+ protected Session getCurrentSession() throws IllegalStateException
+ {
+ if (sessionFactory == null)
+ {
+ throw new IllegalStateException("No session factory");
+ }
+ return sessionFactory.getCurrentSession();
+ }
+}
Modified: trunk/identity/src/main/org/jboss/portal/identity2/db/HibernateUserProfileModuleImpl.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/db/HibernateUserProfileModuleImpl.java 2006-11-19 23:34:25 UTC (rev 5677)
+++ trunk/identity/src/main/org/jboss/portal/identity2/db/HibernateUserProfileModuleImpl.java 2006-11-20 11:09:53 UTC (rev 5678)
@@ -22,19 +22,19 @@
******************************************************************************/
package org.jboss.portal.identity2.db;
-import org.jboss.portal.identity.db.UserImpl;
+import org.jboss.portal.identity2.db.DBUserImpl;
import org.jboss.portal.identity2.User;
-import org.jboss.portal.identity2.UserProfileModule;
+import org.jboss.portal.identity2.service.UserProfileModuleService;
-import java.util.Set;
+import java.util.Map;
/**
* @author <a href="mailto:boleslaw.dawidowicz at jboss.org">Boleslaw Dawidowicz</a>
* @version $Revision: 1.1 $
*/
-public class HibernateUserProfileModuleImpl implements UserProfileModule
+public class HibernateUserProfileModuleImpl extends UserProfileModuleService
{
- public String getProperty(User user, String propertyName)
+ public Object getProperty(User user, String propertyName)
{
if (user == null)
{
@@ -45,15 +45,15 @@
throw new IllegalArgumentException("Property name need to have value");
}
- UserImpl dbUser = null;
+ DBUserImpl dbUser = null;
- if (user instanceof UserImpl)
+ if (user instanceof DBUserImpl)
{
- dbUser = (UserImpl)user;
+ dbUser = (DBUserImpl)user;
}
else
{
- throw new IllegalArgumentException("This UserProfileModule implementation support only DBUserImpl objects");
+ throw new IllegalArgumentException("This UserProfileModule implementation support only DBDBUserImpl objects");
}
throw new UnsupportedOperationException("Not yet implemented");
@@ -70,15 +70,15 @@
throw new IllegalArgumentException("Property name need to have value");
}
- UserImpl dbUser = null;
+ DBUserImpl dbUser = null;
- if (user instanceof UserImpl)
+ if (user instanceof DBUserImpl)
{
- dbUser = (UserImpl)user;
+ dbUser = (DBUserImpl)user;
}
else
{
- throw new IllegalArgumentException("This UserProfileModule implementation support only DBUserImpl objects");
+ throw new IllegalArgumentException("This UserProfileModule implementation support only DBDBUserImpl objects");
}
//if value is null reset property
@@ -86,22 +86,22 @@
throw new UnsupportedOperationException("Not yet implemented");
}
- public Set getProperties(User user)
+ public Map getProperties(User user)
{
if (user == null)
{
throw new IllegalArgumentException("User cannot be null");
}
- UserImpl dbUser = null;
+ DBUserImpl dbUser = null;
- if (user instanceof UserImpl)
+ if (user instanceof DBUserImpl)
{
- dbUser = (UserImpl)user;
+ dbUser = (DBUserImpl)user;
}
else
{
- throw new IllegalArgumentException("This UserProfileModule implementation support only DBUserImpl objects");
+ throw new IllegalArgumentException("This UserProfileModule implementation support only DBDBUserImpl objects");
}
Added: trunk/identity/src/main/org/jboss/portal/identity2/db/ProfileMapImpl.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/db/ProfileMapImpl.java 2006-11-19 23:34:25 UTC (rev 5677)
+++ trunk/identity/src/main/org/jboss/portal/identity2/db/ProfileMapImpl.java 2006-11-20 11:09:53 UTC (rev 5678)
@@ -0,0 +1,275 @@
+/*
+* 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.
+*/
+package org.jboss.portal.identity2.db;
+
+import org.jboss.portal.identity2.ProfileMap;
+import org.jboss.portal.identity2.db.DBUserImpl;
+
+import java.util.Iterator;
+import java.util.Set;
+import java.util.HashSet;
+import java.util.Collection;
+import java.util.ArrayList;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Collections;
+
+/**
+ * A mutable map that expose user properties.
+ *
+ * @author <a href="mailto:julien at jboss.org">Julien Viet</a>
+ * @version $Revision: 5448 $
+ */
+public class ProfileMapImpl implements ProfileMap
+{
+
+ /** . */
+ private DBUserImpl user;
+
+ public ProfileMapImpl(DBUserImpl user)
+ {
+ if (user == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ this.user = user;
+ }
+
+ public boolean isReadOnly(Object key)
+ {
+ if (key == null)
+ {
+ return false;
+ }
+ if (key instanceof String == false)
+ {
+ throw new ClassCastException("Key must be a string");
+ }
+ DBUserImpl.PropertyAccessor accessor = (DBUserImpl.PropertyAccessor)DBUserImpl.ACCESSORS.get(key);
+ return accessor != null && !accessor.isWritable();
+ }
+
+ public int size()
+ {
+ return DBUserImpl.ACCESSORS.size() + user.getDynamic().size();
+ }
+
+ public boolean isEmpty()
+ {
+ return false;
+ }
+
+ /** @throws ClassCastException if the key is not an instance of string */
+ public boolean containsKey(Object key) throws ClassCastException
+ {
+ if (key == null)
+ {
+ return false;
+ }
+ if (key instanceof String == false)
+ {
+ throw new ClassCastException("Key must be a string");
+ }
+ DBUserImpl.PropertyAccessor accessor = (DBUserImpl.PropertyAccessor)DBUserImpl.ACCESSORS.get(key);
+ if (accessor != null)
+ {
+ return true;
+ }
+ return user.getDynamic().containsKey(key);
+ }
+
+ /** @throws ClassCastException if the value is not an instance of string */
+ public boolean containsValue(Object value) throws ClassCastException
+ {
+ if (value == null)
+ {
+ throw new NullPointerException("Key cannot be null");
+ }
+ if (value instanceof String == false)
+ {
+ throw new ClassCastException("Value must be a string");
+ }
+ for (Iterator i = DBUserImpl.ACCESSORS.values().iterator(); i.hasNext();)
+ {
+ DBUserImpl.PropertyAccessor accessor = (DBUserImpl.PropertyAccessor)i.next();
+ Object value2 = accessor.get(user);
+ if (value == value2 || value.equals(value2))
+ {
+ return true;
+ }
+ }
+ return user.getDynamic().containsValue(value);
+ }
+
+ /** @throws ClassCastException if the key is not an instance of string */
+ public Object get(Object key)
+ {
+ if (key == null)
+ {
+ return null;
+ }
+ if (key instanceof String == false)
+ {
+ throw new ClassCastException("Key must be a string");
+ }
+ DBUserImpl.PropertyAccessor accessor = (DBUserImpl.PropertyAccessor)DBUserImpl.ACCESSORS.get(key);
+ if (accessor != null)
+ {
+ return accessor.get(user);
+ }
+ return user.getDynamic().get(key);
+ }
+
+ /**
+ * Put a value in the dynamic map.
+ * <p/>
+ * If the key is not an instance of string then an IllegalArgumentException is thrown. If the value is mapped to an
+ * accessor of a non writable field then an IllegalArgumentException is thrown. If the value is mapped to an accessor
+ * of a non nullable field and the field is null then an IllegalArgumentException is thrown.
+ *
+ * @throws IllegalArgumentException
+ */
+ public Object put(Object key, Object newValue) throws IllegalArgumentException
+ {
+ if (key == null)
+ {
+ return null;
+ }
+ if (key instanceof String == false)
+ {
+ throw new ClassCastException("Key is not a String");
+ }
+ DBUserImpl.PropertyAccessor accessor = (DBUserImpl.PropertyAccessor)DBUserImpl.ACCESSORS.get(key);
+ if (accessor != null)
+ {
+ if (newValue == null && !accessor.isNullable())
+ {
+ throw new NullPointerException("Key " + key + " is not nullable");
+ }
+ if (!accessor.isWritable())
+ {
+ throw new IllegalArgumentException("Key " + key + " is not modifiable");
+ }
+ else
+ {
+ Object oldValue = accessor.get(user);
+ accessor.set(user, (String)newValue);
+ return oldValue;
+ }
+ }
+ if (newValue instanceof String == false)
+ {
+ throw new ClassCastException("Dynamic value must be a string");
+ }
+ return user.getDynamic().put(key, newValue);
+ }
+
+ /**
+ * Only affect dynamic properties, otherwise it throws an IllegalArgumentException.
+ *
+ * @throws IllegalArgumentException if the key is a not a dynamic property
+ */
+ public Object remove(Object key) throws IllegalArgumentException
+ {
+ if (key instanceof String == false)
+ {
+ throw new ClassCastException("Key is not a String");
+ }
+ DBUserImpl.PropertyAccessor accessor = (DBUserImpl.PropertyAccessor)DBUserImpl.ACCESSORS.get(key);
+ if (accessor != null)
+ {
+ throw new IllegalArgumentException("Key " + key + " is not removable");
+ }
+ return user.getDynamic().remove(key);
+ }
+
+ /** Clear only dynamic properties. */
+ public void clear()
+ {
+ user.getDynamic().clear();
+ }
+
+ public Set keySet()
+ {
+ // Get
+ Set set = new HashSet(size());
+
+ //
+ set.addAll(user.getDynamic().keySet());
+ set.addAll(DBUserImpl.ACCESSORS.keySet());
+ return set;
+ }
+
+ public Collection values()
+ {
+ ArrayList collection = new ArrayList(size());
+ for (Iterator i = DBUserImpl.ACCESSORS.values().iterator(); i.hasNext();)
+ {
+ DBUserImpl.PropertyAccessor accessor = (DBUserImpl.PropertyAccessor)i.next();
+ collection.add(accessor.get(user));
+ }
+ collection.addAll(user.getDynamic().values());
+ return collection;
+ }
+
+ /** Returns an immutable collection of entries. */
+ public Set entrySet()
+ {
+ Map copy = new HashMap(user.getDynamic());
+ for (Iterator i = DBUserImpl.ACCESSORS.values().iterator(); i.hasNext();)
+ {
+ DBUserImpl.PropertyAccessor accessor = (DBUserImpl.PropertyAccessor)i.next();
+ copy.put(accessor.getPropertyName(), accessor.get(user));
+ }
+ return Collections.unmodifiableMap(copy).entrySet();
+ }
+
+ public void putAll(Map map)
+ {
+ // todo : check all properties ok with changes before proceeding
+ for (Iterator i = map.entrySet().iterator(); i.hasNext();)
+ {
+ Entry entry = (Entry)i.next();
+ Object key = entry.getKey();
+ if (key instanceof String)
+ {
+ Object value = entry.getValue();
+ DBUserImpl.PropertyAccessor accessor = (DBUserImpl.PropertyAccessor)DBUserImpl.ACCESSORS.get(key);
+ if (accessor != null)
+ {
+ if (accessor.isWritable())
+ {
+ accessor.set(user, (String)value);
+ }
+ else
+ {
+ // julien : Do something better ?
+ }
+ }
+ else
+ {
+ user.getDynamic().put(key, value);
+ }
+ }
+ }
+ }
+}
Modified: trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPExtRoleModuleImpl.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPExtRoleModuleImpl.java 2006-11-19 23:34:25 UTC (rev 5677)
+++ trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPExtRoleModuleImpl.java 2006-11-20 11:09:53 UTC (rev 5678)
@@ -23,7 +23,7 @@
package org.jboss.portal.identity2.ldap;
import org.jboss.portal.identity.IdentityException;
-import org.jboss.portal.identity.Role;
+import org.jboss.portal.identity2.Role;
import org.jboss.portal.jems.as.system.AbstractJBossService;
import java.util.Set;
Modified: trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPExtUserModuleImpl.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPExtUserModuleImpl.java 2006-11-19 23:34:25 UTC (rev 5677)
+++ trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPExtUserModuleImpl.java 2006-11-20 11:09:53 UTC (rev 5678)
@@ -24,7 +24,7 @@
import org.jboss.portal.identity.IdentityException;
import org.jboss.portal.identity.NoSuchUserException;
-import org.jboss.portal.identity.User;
+import org.jboss.portal.identity2.User;
import org.jboss.portal.jems.as.system.AbstractJBossService;
import java.util.Set;
Modified: trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPMembershipModule.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPMembershipModule.java 2006-11-19 23:34:25 UTC (rev 5677)
+++ trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPMembershipModule.java 2006-11-20 11:09:53 UTC (rev 5678)
@@ -21,18 +21,16 @@
*/
package org.jboss.portal.identity2.ldap;
-import org.jboss.portal.jems.as.system.AbstractJBossService;
-import org.jboss.portal.identity2.MembershipModule;
import org.jboss.portal.identity2.IdentityContext;
import org.jboss.portal.identity2.IdentityConfiguration;
-import org.jboss.portal.common.util.JNDI;
+import org.jboss.portal.identity2.service.MembershipModuleService;
import org.jboss.portal.identity.IdentityException;
/**
* @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw Dawidowicz</a>
* @version $Revision: 1.1 $
*/
-public abstract class LDAPMembershipModule extends AbstractJBossService implements MembershipModule
+public abstract class LDAPMembershipModule extends MembershipModuleService
{
private static final org.jboss.logging.Logger log = org.jboss.logging.Logger.getLogger(LDAPMembershipModule.class);
@@ -42,74 +40,8 @@
private LDAPRoleModule roleModule;
- private IdentityContext identityContext;
- private IdentityConfiguration identityConfiguration;
-
- //private LDAPMembershipStrategy membershipStrategy;
-
- private String jndiName;
-
- protected JNDI.Binding jndiBinding;
-
-
- /** DN under which roles should be searched. Used only when obtaining roles having only User DN. */
- /*private String roleCtxDN;*/
-
-
-
- /** Name of attribute in role entry that point to belonging user */
- //private String uidAttributeID;
-
-
- /** If the uidAttributeID in Role entry keeps full DN of a user or just a name */
- //private boolean uidAttributeIsDN;
-
-
- protected void startService() throws Exception
- {
-
- //
- if (jndiName != null)
- {
- jndiBinding = new JNDI.Binding(jndiName, this);
- jndiBinding.bind();
- }
-
- if (identityContext == null)
- {
- throw new IdentityException("Cannot register module in context - missing reference");
- }
- else
- {
- identityContext.register(this, IdentityContext.MEMBERSHIP_MODULE);
- }
-
-
-
- }
-
-
- protected void stopService() throws Exception
- {
- if (jndiBinding != null)
- {
- jndiBinding.unbind();
- jndiBinding = null;
- }
-
- if (identityContext == null)
- {
- log.error("Cannot unregister module in context - missing reference");
- }
- else
- {
- identityContext.unregister(IdentityContext.MEMBERSHIP_MODULE);
- }
-
- }
-
//************************************
//******* Getters and Setters ********
//************************************
@@ -121,7 +53,7 @@
{
try
{
- this.connectionContext = (LDAPConnectionContext)identityContext.getObject(IdentityContext.CONNECTION_CONTEXT);
+ this.connectionContext = (LDAPConnectionContext)getIdentityContext().getObject(IdentityContext.CONNECTION_CONTEXT);
}
catch (ClassCastException e)
{
@@ -131,15 +63,8 @@
return connectionContext;
}
- protected IdentityConfiguration getIdentityConfiguration() throws IdentityException
- {
- if (identityConfiguration == null)
- {
- this.identityConfiguration = (IdentityConfiguration)identityContext.getObject(IdentityContext.IDENTITY_CONFIGURATION);
- }
- return identityConfiguration;
- }
+
protected LDAPUserModule getUserModule() throws IdentityException
{
@@ -147,7 +72,7 @@
{
try
{
- this.userModule = (LDAPUserModule)identityContext.getObject(IdentityContext.USER_MODULE);
+ this.userModule = (LDAPUserModule)getIdentityContext().getObject(IdentityContext.USER_MODULE);
}
catch (ClassCastException e)
{
@@ -164,7 +89,7 @@
{
try
{
- this.roleModule = (LDAPRoleModule)identityContext.getObject(IdentityContext.ROLE_MODULE);
+ this.roleModule = (LDAPRoleModule)getIdentityContext().getObject(IdentityContext.ROLE_MODULE);
}
catch (ClassCastException e)
{
@@ -174,26 +99,6 @@
return roleModule;
}
- public IdentityContext getIdentityContext()
- {
- return identityContext;
- }
-
- public void setIdentityContext(IdentityContext identityContext)
- {
- this.identityContext = identityContext;
- }
-
- public String getJndiName()
- {
- return jndiName;
- }
-
- public void setJndiName(String jndiName)
- {
- this.jndiName = jndiName;
- }
-
protected String getMemberAttributeID() throws IdentityException
{
String uid = getIdentityConfiguration().getValue(IdentityConfiguration.MEMBERSHIP_ATTRIBUTE_ID);
@@ -204,11 +109,6 @@
return uid;
}
- /*public void setUidAttributeID(String uidAttributeID)
- {
- this.uidAttributeID = uidAttributeID;
- }*/
-
protected boolean isUidAttributeIsDN() throws IdentityException
{
if (getIdentityConfiguration().getValue(IdentityConfiguration.MEMBERSHIP_ATTRIBUTE_IS_DN) == null)
@@ -219,8 +119,4 @@
return getIdentityConfiguration().getValue(IdentityConfiguration.MEMBERSHIP_ATTRIBUTE_IS_DN).equals("true");
}
- /*protected String getRoleContainerDN() throws IdentityException
- {
- return getIdentityConfiguration().getValue(IdentityConfiguration.ROLE_CONTAINER_DN);
- }*/
}
Modified: trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPRoleImpl.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPRoleImpl.java 2006-11-19 23:34:25 UTC (rev 5677)
+++ trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPRoleImpl.java 2006-11-20 11:09:53 UTC (rev 5678)
@@ -22,7 +22,7 @@
******************************************************************************/
package org.jboss.portal.identity2.ldap;
-import org.jboss.portal.identity.Role;
+import org.jboss.portal.identity2.Role;
import org.jboss.portal.identity.IdentityException;
import org.jboss.portal.identity2.IdentityContext;
import org.jboss.portal.identity2.MembershipModule;
Modified: trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPRoleModule.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPRoleModule.java 2006-11-19 23:34:25 UTC (rev 5677)
+++ trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPRoleModule.java 2006-11-20 11:09:53 UTC (rev 5678)
@@ -21,13 +21,11 @@
*/
package org.jboss.portal.identity2.ldap;
-import org.jboss.portal.jems.as.system.AbstractJBossService;
-import org.jboss.portal.identity.RoleModule;
import org.jboss.portal.identity.IdentityException;
-import org.jboss.portal.identity.Role;
+import org.jboss.portal.identity2.Role;
import org.jboss.portal.identity2.IdentityContext;
import org.jboss.portal.identity2.IdentityConfiguration;
-import org.jboss.portal.common.util.JNDI;
+import org.jboss.portal.identity2.service.RoleModuleService;
import javax.naming.directory.Attributes;
import javax.naming.directory.Attribute;
@@ -39,63 +37,12 @@
* @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw Dawidowicz</a>
* @version $Revision: 1.1 $
*/
-public abstract class LDAPRoleModule extends AbstractJBossService implements RoleModule
+public abstract class LDAPRoleModule extends RoleModuleService
{
private static final org.jboss.logging.Logger log = org.jboss.logging.Logger.getLogger(LDAPRoleModule.class);
private LDAPConnectionContext connectionContext;
- private String jndiName;
-
- private IdentityContext identityContext;
-
- private IdentityConfiguration identityConfiguration;
-
- private JNDI.Binding jndiBinding;
-
-
- protected void startService() throws Exception
- {
-
- //
- if (jndiName != null)
- {
- jndiBinding = new JNDI.Binding(jndiName, this);
- jndiBinding.bind();
- }
-
- if (identityContext == null)
- {
- throw new IdentityException("Cannot register module in context - missing reference");
- }
- else
- {
- identityContext.register(this, IdentityContext.ROLE_MODULE);
- }
-
-
- }
-
-
- protected void stopService() throws Exception
- {
- if (jndiBinding != null)
- {
- jndiBinding.unbind();
- jndiBinding = null;
- }
-
- if (identityContext == null)
- {
- log.error("Cannot unregister module in context - missing reference");
- }
- else
- {
- identityContext.unregister(IdentityContext.ROLE_MODULE);
- }
-
- }
-
protected LDAPRoleImpl createRoleInstance(Attributes attrs, String dn) throws IdentityException
{
LDAPRoleImpl ldapr = null;
@@ -116,7 +63,7 @@
{
throw new IdentityException("LDAP entry doesn't contain proper attribute:" + getDisplayNameAttributeID());
}
- ldapr = new LDAPRoleImpl(dn, identityContext, uida.get().toString(), display.get().toString());
+ ldapr = new LDAPRoleImpl(dn, getIdentityContext(), uida.get().toString(), display.get().toString());
@@ -196,20 +143,11 @@
{
if (connectionContext == null)
{
- this.connectionContext = (LDAPConnectionContext)identityContext.getObject(IdentityContext.CONNECTION_CONTEXT);
+ this.connectionContext = (LDAPConnectionContext)getIdentityContext().getObject(IdentityContext.CONNECTION_CONTEXT);
}
return connectionContext;
}
- protected IdentityConfiguration getIdentityConfiguration() throws IdentityException
- {
- if (identityConfiguration == null)
- {
- this.identityConfiguration = (IdentityConfiguration)identityContext.getObject(IdentityContext.IDENTITY_CONFIGURATION);
- }
- return identityConfiguration;
- }
-
protected String getContainerDN() throws IdentityException
{
String cont = getIdentityConfiguration().getValue(IdentityConfiguration.ROLE_CONTAINER_DN);
@@ -230,24 +168,6 @@
return display;
}
- public IdentityContext getIdentityContext()
- {
- return identityContext;
- }
+
- public void setIdentityContext(IdentityContext identityContext)
- {
- this.identityContext = identityContext;
- }
-
- protected String getJndiName()
- {
- return jndiName;
- }
-
- protected void setJndiName(String jndiName)
- {
- this.jndiName = jndiName;
- }
-
}
Modified: trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPRoleModuleImpl.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPRoleModuleImpl.java 2006-11-19 23:34:25 UTC (rev 5677)
+++ trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPRoleModuleImpl.java 2006-11-20 11:09:53 UTC (rev 5678)
@@ -23,11 +23,10 @@
package org.jboss.portal.identity2.ldap;
import org.jboss.portal.common.util.Tools;
-import org.jboss.portal.common.util.JNDI;
import org.jboss.portal.identity.IdentityException;
-import org.jboss.portal.identity.Role;
-import org.jboss.portal.identity.RoleModule;
-import org.jboss.portal.identity.User;
+import org.jboss.portal.identity2.Role;
+import org.jboss.portal.identity2.RoleModule;
+import org.jboss.portal.identity2.User;
import org.jboss.portal.identity.NoSuchUserException;
import org.jboss.portal.identity2.IdentityContext;
import org.jboss.portal.identity2.MembershipModule;
@@ -216,6 +215,7 @@
return findRoleByName(name);
}
+ //TODO: remove role assignments before?
public void removeRole(Object id) throws IdentityException, IllegalArgumentException
{
LDAPRoleImpl ldapr = (LDAPRoleImpl)findRoleById(id);
Modified: trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPStaticGroupMembershipModuleImpl.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPStaticGroupMembershipModuleImpl.java 2006-11-19 23:34:25 UTC (rev 5677)
+++ trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPStaticGroupMembershipModuleImpl.java 2006-11-20 11:09:53 UTC (rev 5678)
@@ -23,9 +23,9 @@
package org.jboss.portal.identity2.ldap;
import org.jboss.portal.identity.IdentityException;
-import org.jboss.portal.identity.User;
+import org.jboss.portal.identity2.User;
import org.jboss.portal.identity2.MembershipModule;
-import org.jboss.portal.identity.Role;
+import org.jboss.portal.identity2.Role;
import org.jboss.portal.identity2.IdentityContext;
import org.jboss.portal.identity2.IdentityConfiguration;
import org.jboss.portal.identity2.ldap.helper.LDAPTools;
Modified: trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPStaticRoleMembershipModuleImpl.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPStaticRoleMembershipModuleImpl.java 2006-11-19 23:34:25 UTC (rev 5677)
+++ trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPStaticRoleMembershipModuleImpl.java 2006-11-20 11:09:53 UTC (rev 5678)
@@ -29,8 +29,8 @@
import org.jboss.portal.common.util.JNDI;
import org.jboss.portal.common.util.Tools;
import org.jboss.portal.identity.IdentityException;
-import org.jboss.portal.identity.User;
-import org.jboss.portal.identity.Role;
+import org.jboss.portal.identity2.User;
+import org.jboss.portal.identity2.Role;
import javax.naming.directory.SearchControls;
import javax.naming.directory.SearchResult;
Modified: trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPUserImpl.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPUserImpl.java 2006-11-19 23:34:25 UTC (rev 5677)
+++ trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPUserImpl.java 2006-11-20 11:09:53 UTC (rev 5678)
@@ -24,7 +24,7 @@
import org.jboss.portal.identity.IdentityException;
import org.jboss.portal.identity.ProfileMap;
-import org.jboss.portal.identity.User;
+import org.jboss.portal.identity2.User;
import org.jboss.portal.identity2.UserProfileModule;
import org.jboss.portal.identity2.IdentityContext;
import org.jboss.portal.identity2.IdentityConfiguration;
@@ -41,22 +41,20 @@
public class LDAPUserImpl implements User
{
private static final org.jboss.logging.Logger log = org.jboss.logging.Logger.getLogger(LDAPUserImpl.class);
-
+
//TODO:this is to enable user act like a fasade to identity modules calls
IdentityContext identityContext;
- //TODO:validatePassowrd method to handle different enc.
-
private UserProfileModule userProfileModule;
private String dn;
- //In ldap implementation
+ //In ldap implementation it acts as a userName
private String id;
private String password;
- private String realEmail;
+ //private String realEmail;
private LDAPUserImpl()
{
@@ -71,7 +69,7 @@
* @param password - should contain already encrypted password from ldap
* @throws IdentityException
*/
- public LDAPUserImpl(String dn, IdentityContext context, String id, String password, String email) throws IdentityException
+ public LDAPUserImpl(String dn, IdentityContext context, String id, String password) throws IdentityException
{
if (dn == null)
{
@@ -89,11 +87,6 @@
throw new IllegalArgumentException("Password can't be null");
}
- if (email == null)
- {
- throw new IllegalArgumentException("Email can't be null");
- }
-
if (id == null)
{
throw new IllegalArgumentException("Id can't be null");
@@ -101,21 +94,11 @@
this.identityContext = context;
this.password = password;
- this.realEmail = email;
+ //this.realEmail = email;
this.id = id;
}
- public boolean getEnabled()
- {
- throw new UnsupportedOperationException("Not yet implemented");
- }
-
- public void setEnabled(boolean enable)
- {
- throw new UnsupportedOperationException("Not yet implemented");
- }
-
public void updatePassword(String password)
{
//TODO: somehow update the password to ldap?
@@ -165,101 +148,6 @@
}
- public String getGivenName()
- {
- throw new UnsupportedOperationException("Not yet implemented");
- }
-
- public void setGivenName(String givenName)
- {
- throw new UnsupportedOperationException("Not yet implemented");
- }
-
- public String getFamilyName()
- {
- throw new UnsupportedOperationException("Not yet implemented");
- }
-
- public void setFamilyName(String familyName)
- {
- throw new UnsupportedOperationException("Not yet implemented");
- }
-
- public String getRealEmail()
- {
- throw new UnsupportedOperationException("Not yet implemented");
- }
-
- public void setRealEmail(String realEmail)
- {
- throw new UnsupportedOperationException("Not yet implemented");
- }
-
- public String getFakeEmail()
- {
- throw new UnsupportedOperationException("Not yet implemented");
- }
-
- public void setFakeEmail(String fakeEmail)
- {
- throw new UnsupportedOperationException("Not yet implemented");
- }
-
- public Date getRegistrationDate()
- {
- throw new UnsupportedOperationException("Not yet implemented");
- }
-
- public boolean getViewRealEmail()
- {
- throw new UnsupportedOperationException("Not yet implemented");
- }
-
- public void setViewRealEmail(boolean viewRealEmail)
- {
- throw new UnsupportedOperationException("Not yet implemented");
- }
-
- public Locale getPreferredLocale()
- {
- throw new UnsupportedOperationException("Not yet implemented");
- }
-
- public void setPreferredLocale(Locale locale)
- {
- throw new UnsupportedOperationException("Not yet implemented");
- }
-
- public String getSignature()
- {
- throw new UnsupportedOperationException("Not yet implemented");
- }
-
- public void setSignature(String signature)
- {
- throw new UnsupportedOperationException("Not yet implemented");
- }
-
- public Date getLastVisitDate()
- {
- throw new UnsupportedOperationException("Not yet implemented");
- }
-
- public void setLastVisitDate(Date date)
- {
- throw new UnsupportedOperationException("Not yet implemented");
- }
-
- public String getTheme()
- {
- throw new UnsupportedOperationException("Not yet implemented");
- }
-
- public void setTheme(String themeId)
- {
- throw new UnsupportedOperationException("Not yet implemented");
- }
-
//**************************
//*** Getter and Setters
//**************************
Modified: trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPUserModule.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPUserModule.java 2006-11-19 23:34:25 UTC (rev 5677)
+++ trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPUserModule.java 2006-11-20 11:09:53 UTC (rev 5678)
@@ -21,14 +21,12 @@
*/
package org.jboss.portal.identity2.ldap;
-import org.jboss.portal.jems.as.system.AbstractJBossService;
import org.jboss.portal.identity2.IdentityConfiguration;
import org.jboss.portal.identity2.IdentityContext;
import org.jboss.portal.identity2.UserProfileModule;
-import org.jboss.portal.common.util.JNDI;
import org.jboss.portal.identity.IdentityException;
-import org.jboss.portal.identity.UserModule;
-import org.jboss.portal.identity.User;
+import org.jboss.portal.identity2.User;
+import org.jboss.portal.identity2.service.UserModuleService;
import org.jboss.portal.identity.NoSuchUserException;
import javax.naming.directory.Attributes;
@@ -44,63 +42,16 @@
* @author <a href="mailto:boleslaw dot dawidowicz at jboss.com">Boleslaw Dawidowicz</a>
* @version $Revision: 1.1 $
*/
-public abstract class LDAPUserModule extends AbstractJBossService implements UserModule
+public abstract class LDAPUserModule extends UserModuleService
{
private static final org.jboss.logging.Logger log = org.jboss.logging.Logger.getLogger(LDAPUserModule.class);
private LDAPConnectionContext connectionContext;
- private IdentityConfiguration identityConfiguration;
+ private UserProfileModule userProfileModule;
- private String jndiName;
-
- private IdentityContext identityContext;
-
- private UserProfileModule userProfileModule;
-
- private JNDI.Binding jndiBinding;
-
- protected void startService() throws Exception
- {
-
- //
- if (jndiName != null)
- {
- jndiBinding = new JNDI.Binding(jndiName, this);
- jndiBinding.bind();
- }
-
- if (identityContext == null)
- {
- throw new IdentityException("Cannot register module in context - missing reference");
- }
- else
- {
- identityContext.register(this, IdentityContext.USER_MODULE);
- }
-
-
- }
-
-
- protected void stopService() throws Exception
- {
- if (jndiBinding != null)
- {
- jndiBinding.unbind();
- jndiBinding = null;
- }
-
- if (identityContext == null)
- {
- log.error("Cannot unregister module in context - missing reference");
- }
- else
- {
- identityContext.unregister(IdentityContext.USER_MODULE);
- }
- }
-
+
+ //TODO: add enabled
public LDAPUserImpl createUserInstance(Attributes attrs, String dn) throws IdentityException
{
LDAPUserImpl ldapu = null;
@@ -121,15 +72,9 @@
throw new IdentityException("LDAP entry doesn't contain proper attribute:" + getPasswordAttributeId());
}
- Attribute email = attrs.get(getEmailAttributeId());
- if (email == null)
- {
- throw new IdentityException("LDAP entry doesn't contain proper attribute:" + getEmailAttributeId());
- }
+ ldapu = new LDAPUserImpl(dn,getIdentityContext(), uida.get().toString(), passwd.get().toString());
- ldapu = new LDAPUserImpl(dn,identityContext, uida.get().toString(), passwd.get().toString(),email.get().toString());
-
log.debug("user uid: " + ldapu.getId());
log.debug("user dn: " + ldapu.getDn());
@@ -158,12 +103,6 @@
throw new IdentityException("User dn canot be null");
}
- /*SearchControls controls = new SearchControls();
- controls.setSearchScope(SearchControls.SUBTREE_SCOPE);
-
- String filter = getUidAttributeID().concat("=").concat(userName);
- log.debug("Search filter: " + filter);*/
- //DirContext ctx = (DirContext)getConnectionContext().createInitialContext().lookup(dn);
Attributes attrs = getConnectionContext().createInitialContext().getAttributes(dn);
if (attrs == null)
@@ -204,7 +143,7 @@
{
if (userProfileModule == null)
{
- this.userProfileModule = (UserProfileModule)identityContext.getObject(IdentityContext.USER_PROFILE_MODULE);
+ this.userProfileModule = (UserProfileModule)getIdentityContext().getObject(IdentityContext.USER_PROFILE_MODULE);
}
return userProfileModule;
}
@@ -245,20 +184,11 @@
{
if (connectionContext == null)
{
- this.connectionContext = (LDAPConnectionContext)identityContext.getObject(IdentityContext.CONNECTION_CONTEXT);
+ this.connectionContext = (LDAPConnectionContext)getIdentityContext().getObject(IdentityContext.CONNECTION_CONTEXT);
}
return connectionContext;
}
- protected IdentityConfiguration getIdentityConfiguration() throws IdentityException
- {
- if (identityConfiguration == null)
- {
- this.identityConfiguration = (IdentityConfiguration)identityContext.getObject(IdentityContext.IDENTITY_CONFIGURATION);
- }
- return identityConfiguration;
- }
-
protected String getContainerDN() throws IdentityException
{
String cont = getIdentityConfiguration().getValue(IdentityConfiguration.USER_CONTAINER_DN);
@@ -282,7 +212,7 @@
}
}
- protected String getEmailAttributeId() throws IdentityException
+ /*protected String getEmailAttributeId() throws IdentityException
{
String email = getIdentityConfiguration().getValue(IdentityConfiguration.USER_EMAIL_ATTRIBUTE_ID);
if (email == null)
@@ -293,9 +223,8 @@
{
return email;
}
- }
+ }*/
-
protected Map getAttributesToAdd() throws IdentityException
{
Map attributesToAdd = getIdentityConfiguration().getOptions(IdentityConfiguration.GROUP_USER_CREATE_ATTRIBUTES);
@@ -306,25 +235,4 @@
return attributesToAdd;
}
-
- public IdentityContext getIdentityContext()
- {
- return identityContext;
- }
-
- public void setIdentityContext(IdentityContext identityContext)
- {
- this.identityContext = identityContext;
- }
-
- public String getJndiName()
- {
- return jndiName;
- }
-
- public void setJndiName(String jndiName)
- {
- this.jndiName = jndiName;
- }
-
}
Modified: trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPUserModuleImpl.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPUserModuleImpl.java 2006-11-19 23:34:25 UTC (rev 5677)
+++ trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPUserModuleImpl.java 2006-11-20 11:09:53 UTC (rev 5678)
@@ -25,7 +25,7 @@
import org.jboss.portal.common.util.Tools;
import org.jboss.portal.identity.IdentityException;
import org.jboss.portal.identity.NoSuchUserException;
-import org.jboss.portal.identity.User;
+import org.jboss.portal.identity2.User;
import org.jboss.portal.identity2.IdentityConfiguration;
import javax.naming.NamingEnumeration;
@@ -183,7 +183,7 @@
//
//email
- attrs.put(getEmailAttributeId(), realEmail);
+ //attrs.put(getEmailAttributeId(), realEmail);
String dn = getUidAttributeID().concat("=").concat(userName);
@@ -202,6 +202,7 @@
return findUserByUserName(userName);
}
+ //TODO: remove user assignments before?
public void removeUser(Object id) throws IdentityException, IllegalArgumentException
{
Copied: trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPUserProfileModule.java (from rev 5663, trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPUserProfileModuleImpl.java)
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPUserProfileModuleImpl.java 2006-11-15 19:20:40 UTC (rev 5663)
+++ trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPUserProfileModule.java 2006-11-20 11:09:53 UTC (rev 5678)
@@ -0,0 +1,45 @@
+/******************************************************************************
+ * 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. *
+ ******************************************************************************/
+package org.jboss.portal.identity2.ldap;
+
+import org.jboss.portal.identity2.service.UserProfileModuleService;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at jboss.org">Boleslaw Dawidowicz</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class LDAPUserProfileModule extends UserProfileModuleService
+{
+ private LDAPConnectionContext connectionContext;
+
+ public LDAPConnectionContext getConnectionContext()
+ {
+ return connectionContext;
+ }
+
+ public void setConnectionContext(LDAPConnectionContext connectionContext)
+ {
+ this.connectionContext = connectionContext;
+ }
+
+}
Deleted: trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPUserProfileModuleImpl.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPUserProfileModuleImpl.java 2006-11-19 23:34:25 UTC (rev 5677)
+++ trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPUserProfileModuleImpl.java 2006-11-20 11:09:53 UTC (rev 5678)
@@ -1,123 +0,0 @@
-/******************************************************************************
- * 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. *
- ******************************************************************************/
-package org.jboss.portal.identity2.ldap;
-
-import org.jboss.portal.identity2.User;
-import org.jboss.portal.identity2.UserProfileModule;
-import org.jboss.portal.jems.as.system.AbstractJBossService;
-
-import java.util.Set;
-
-/**
- * @author <a href="mailto:boleslaw.dawidowicz at jboss.org">Boleslaw Dawidowicz</a>
- * @version $Revision: 1.1 $
- */
-public class LDAPUserProfileModuleImpl extends AbstractJBossService implements UserProfileModule
-{
- private LDAPConnectionContext connectionContext;
-
- public LDAPConnectionContext getConnectionContext()
- {
- return connectionContext;
- }
-
- public void setConnectionContext(LDAPConnectionContext connectionContext)
- {
- this.connectionContext = connectionContext;
- }
-
-
- public String getProperty(User user, String propertyName)
- {
- if (user == null)
- {
- throw new IllegalArgumentException("User cannot be null");
- }
- if (propertyName == null)
- {
- throw new IllegalArgumentException("Property name need to have value");
- }
-
- LDAPUserImpl ldapUser = null;
-
- if (user instanceof LDAPUserImpl)
- {
- ldapUser = (LDAPUserImpl)user;
- }
- else
- {
- throw new IllegalArgumentException("This UserProfileModule implementation supports only LDAPUserImpl objects");
- }
-
- throw new UnsupportedOperationException("Not yet implemented");
- }
-
- public void setProperty(User user, String propertyName, Object property)
- {
- if (user == null)
- {
- throw new IllegalArgumentException("User cannot be null");
- }
- if (propertyName == null)
- {
- throw new IllegalArgumentException("Property name need to have value");
- }
-
- LDAPUserImpl ldapUser = null;
-
- if (user instanceof LDAPUserImpl)
- {
- ldapUser = (LDAPUserImpl)user;
- }
- else
- {
- throw new IllegalArgumentException("This UserProfileModule implementation support only LDAPUserImpl objects");
- }
-
- //if value is null reset property
-
- throw new UnsupportedOperationException("Not yet implemented");
- }
-
- public Set getProperties(User user)
- {
- if (user == null)
- {
- throw new IllegalArgumentException("User cannot be null");
- }
-
- LDAPUserImpl ldapUser = null;
-
- if (user instanceof LDAPUserImpl)
- {
- ldapUser = (LDAPUserImpl)user;
- }
- else
- {
- throw new IllegalArgumentException("This UserProfileModule implementation support only LDAPUserImpl objects");
- }
-
-
- throw new UnsupportedOperationException("Not yet implemented");
- }
-}
Added: trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPUserProfileModuleImpl.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPUserProfileModuleImpl.java 2006-11-19 23:34:25 UTC (rev 5677)
+++ trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPUserProfileModuleImpl.java 2006-11-20 11:09:53 UTC (rev 5678)
@@ -0,0 +1,237 @@
+/*
+* 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.
+*/
+package org.jboss.portal.identity2.ldap;
+
+import org.jboss.portal.identity2.User;
+import org.jboss.portal.identity2.IdentityConfiguration;
+import org.jboss.portal.identity.IdentityException;
+
+import javax.naming.directory.Attributes;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.BasicAttributes;
+import javax.naming.directory.BasicAttribute;
+import javax.naming.directory.DirContext;
+import javax.naming.NamingException;
+import java.util.Set;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Iterator;
+
+/**
+ * @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw Dawidowicz</a>
+ * @version $Revision: 1.1 $
+ */
+public class LDAPUserProfileModuleImpl extends LDAPUserProfileModule
+{
+ private static final org.jboss.logging.Logger log = org.jboss.logging.Logger.getLogger(LDAPUserProfileModuleImpl.class);
+
+ public Object getProperty(User user, String propertyName) throws IdentityException, IllegalArgumentException
+ {
+ if (user == null)
+ {
+ throw new IllegalArgumentException("User cannot be null");
+ }
+ if (propertyName == null)
+ {
+ throw new IllegalArgumentException("Property name need to have value");
+ }
+
+ LDAPUserImpl ldapUser = null;
+
+ if (user instanceof LDAPUserImpl)
+ {
+ ldapUser = (LDAPUserImpl)user;
+ }
+ else
+ {
+ throw new IllegalArgumentException("This UserProfileModule implementation supports only LDAPUserImpl objects");
+ }
+
+ String attributeName = resolveAttributeName(propertyName);
+ String propertyValue = null;
+
+ if (attributeName == null)
+ {
+ log.error("Proper LDAP attribute mapping not found for such property name: " + propertyName);
+ return null;
+ }
+
+ try
+ {
+ Attributes attrs = getConnectionContext().createInitialContext().getAttributes(ldapUser.getDn());
+
+ Attribute attr = attrs.get(attributeName);
+
+ if (attr != null)
+ {
+ propertyValue = (String)attr.get();
+ }
+ else
+ {
+ log.error("No such attribute ('" + attributeName + "') in entry: " + ldapUser.getDn());
+ }
+ }
+ catch (NamingException e)
+ {
+ throw new IdentityException("Cannot get user property value.", e);
+ }
+
+ return propertyValue;
+
+ }
+
+ public void setProperty(User user, String propertyName, Object property) throws IdentityException, IllegalArgumentException
+ {
+ if (user == null)
+ {
+ throw new IllegalArgumentException("User cannot be null");
+ }
+ if (propertyName == null)
+ {
+ throw new IllegalArgumentException("Property name need to have value");
+ }
+
+ LDAPUserImpl ldapUser = null;
+
+ if (user instanceof LDAPUserImpl)
+ {
+ ldapUser = (LDAPUserImpl)user;
+ }
+ else
+ {
+ throw new IllegalArgumentException("This UserProfileModule implementation support only LDAPUserImpl objects");
+ }
+
+ String attributeName = resolveAttributeName(propertyName);
+
+ String propertyValue = property.toString();
+
+ if (attributeName == null)
+ {
+ log.error("Proper LDAP attribute mapping not found for such property name: " + propertyName);
+ return;
+ }
+
+ try
+ {
+ //TODO: maybe perform a schema check if this attribute is allowed for such entry
+
+ Attributes attrs = new BasicAttributes(true);
+ Attribute attr = new BasicAttribute(attributeName);
+ attr.add(propertyValue);
+ attrs.put(attr);
+
+ getConnectionContext().createInitialContext().modifyAttributes(ldapUser.getDn(), DirContext.REPLACE_ATTRIBUTE,attrs);
+ }
+ catch (NamingException e)
+ {
+ throw new IdentityException("Cannot set user property value.", e);
+ }
+
+ }
+
+ public Map getProperties(User user) throws IdentityException, IllegalArgumentException
+ {
+ if (user == null)
+ {
+ throw new IllegalArgumentException("User cannot be null");
+ }
+
+ LDAPUserImpl ldapUser = null;
+
+ if (user instanceof LDAPUserImpl)
+ {
+ ldapUser = (LDAPUserImpl)user;
+ }
+ else
+ {
+ throw new IllegalArgumentException("This UserProfileModule implementation support only LDAPUserImpl objects");
+ }
+
+ Map propertyMap = new HashMap();
+
+ try
+ {
+ Map mappings = resolveAttributesMappingMap();
+ Set props = mappings.keySet();
+
+ Attributes attrs = getConnectionContext().createInitialContext().getAttributes(ldapUser.getDn());
+
+ for (Iterator iterator = props.iterator(); iterator.hasNext();)
+ {
+ String name = (String)iterator.next();
+ String attrName = (String)mappings.get(name);
+ Attribute attr = attrs.get(attrName);
+
+ if (attr != null)
+ {
+ propertyMap.put(name,(String)attr.get());
+ }
+ else
+ {
+ log.error("No such attribute ('" + attrName + "') in entry: " + ldapUser.getDn());
+ }
+ }
+ }
+ catch (NamingException e)
+ {
+ throw new IdentityException("Cannot get user property value.", e);
+ }
+
+ return propertyMap;
+ }
+
+ private String resolveAttributeName(String propertyName) throws IdentityException
+ {
+ return getIdentityConfiguration().getValue(IdentityConfiguration.GROUP_USER_PROFILE_MAPPINGS, propertyName);
+ }
+
+ /**
+ * Returns a map of mappings - property name/attribute name.
+ * @return
+ * @throws IdentityException
+ */
+ private Map resolveAttributesMappingMap() throws IdentityException
+ {
+ Map group = getIdentityConfiguration().getOptions(IdentityConfiguration.GROUP_USER_PROFILE_MAPPINGS);
+
+ if (group == null)
+ {
+ throw new IdentityException("User profile attributes mappings not found in the configuration");
+ }
+
+ Map mappings = new HashMap();
+ Set options = group.keySet();
+ for (Iterator iterator = options.iterator(); iterator.hasNext();)
+ {
+ String optname = (String)iterator.next();
+ Set values = (Set)group.get(optname);
+ if (values.size() > 0)
+ {
+ mappings.put(optname, values.toArray()[0]);
+ }
+ }
+ return mappings;
+ }
+
+
+}
Added: trunk/identity/src/main/org/jboss/portal/identity2/service/MembershipModuleService.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/service/MembershipModuleService.java 2006-11-19 23:34:25 UTC (rev 5677)
+++ trunk/identity/src/main/org/jboss/portal/identity2/service/MembershipModuleService.java 2006-11-20 11:09:53 UTC (rev 5678)
@@ -0,0 +1,124 @@
+/*
+* 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.
+*/
+package org.jboss.portal.identity2.service;
+
+import org.jboss.portal.jems.as.system.AbstractJBossService;
+import org.jboss.portal.common.util.JNDI;
+import org.jboss.portal.identity.IdentityException;
+import org.jboss.portal.identity2.MembershipModule;
+import org.jboss.portal.identity2.IdentityContext;
+import org.jboss.portal.identity2.IdentityConfiguration;
+
+/**
+ * @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw Dawidowicz</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class MembershipModuleService extends AbstractJBossService implements MembershipModule
+{
+ private static final org.jboss.logging.Logger log = org.jboss.logging.Logger.getLogger(MembershipModuleService.class);
+
+ private IdentityContext identityContext;
+
+ private IdentityConfiguration identityConfiguration;
+
+ private String jndiName;
+
+ protected JNDI.Binding jndiBinding;
+
+
+ protected void startService() throws Exception
+ {
+
+ //
+ if (jndiName != null)
+ {
+ jndiBinding = new JNDI.Binding(jndiName, this);
+ jndiBinding.bind();
+ }
+
+ if (identityContext == null)
+ {
+ throw new IdentityException("Cannot register module in context - missing reference");
+ }
+ else
+ {
+ identityContext.register(this, IdentityContext.MEMBERSHIP_MODULE);
+ }
+
+
+
+
+ }
+
+
+ protected void stopService() throws Exception
+ {
+ if (jndiBinding != null)
+ {
+ jndiBinding.unbind();
+ jndiBinding = null;
+ }
+
+ if (identityContext == null)
+ {
+ log.error("Cannot unregister module in context - missing reference");
+ }
+ else
+ {
+ identityContext.unregister(IdentityContext.MEMBERSHIP_MODULE);
+ }
+
+ }
+
+ //************************************
+ //******* Getters and Setters ********
+ //************************************
+
+ protected IdentityConfiguration getIdentityConfiguration() throws IdentityException
+ {
+ if (identityConfiguration == null)
+ {
+ this.identityConfiguration = (IdentityConfiguration)identityContext.getObject(IdentityContext.IDENTITY_CONFIGURATION);
+ }
+ return identityConfiguration;
+ }
+
+ public IdentityContext getIdentityContext()
+ {
+ return identityContext;
+ }
+
+ public void setIdentityContext(IdentityContext identityContext)
+ {
+ this.identityContext = identityContext;
+ }
+
+ public String getJndiName()
+ {
+ return jndiName;
+ }
+
+ public void setJndiName(String jndiName)
+ {
+ this.jndiName = jndiName;
+ }
+}
Added: trunk/identity/src/main/org/jboss/portal/identity2/service/RoleModuleService.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/service/RoleModuleService.java 2006-11-19 23:34:25 UTC (rev 5677)
+++ trunk/identity/src/main/org/jboss/portal/identity2/service/RoleModuleService.java 2006-11-20 11:09:53 UTC (rev 5678)
@@ -0,0 +1,118 @@
+/*
+* 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.
+*/
+package org.jboss.portal.identity2.service;
+
+import org.jboss.portal.jems.as.system.AbstractJBossService;
+import org.jboss.portal.common.util.JNDI;
+import org.jboss.portal.identity.IdentityException;
+import org.jboss.portal.identity2.RoleModule;
+import org.jboss.portal.identity2.IdentityContext;
+import org.jboss.portal.identity2.IdentityConfiguration;
+
+/**
+ * @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw Dawidowicz</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class RoleModuleService extends AbstractJBossService implements RoleModule
+{
+ private static final org.jboss.logging.Logger log = org.jboss.logging.Logger.getLogger(RoleModuleService.class);
+
+ private String jndiName;
+
+ private IdentityContext identityContext;
+
+ private IdentityConfiguration identityConfiguration;
+
+ private JNDI.Binding jndiBinding;
+
+
+ protected void startService() throws Exception
+ {
+
+ //
+ if (jndiName != null)
+ {
+ jndiBinding = new JNDI.Binding(jndiName, this);
+ jndiBinding.bind();
+ }
+
+ if (identityContext == null)
+ {
+ throw new IdentityException("Cannot register module in context - missing reference");
+ }
+ else
+ {
+ identityContext.register(this, IdentityContext.ROLE_MODULE);
+ }
+
+
+ }
+
+
+ protected void stopService() throws Exception
+ {
+ if (jndiBinding != null)
+ {
+ jndiBinding.unbind();
+ jndiBinding = null;
+ }
+
+ if (identityContext == null)
+ {
+ log.error("Cannot unregister module in context - missing reference");
+ }
+ else
+ {
+ identityContext.unregister(IdentityContext.ROLE_MODULE);
+ }
+
+ }
+
+ protected IdentityConfiguration getIdentityConfiguration() throws IdentityException
+ {
+ if (identityConfiguration == null)
+ {
+ this.identityConfiguration = (IdentityConfiguration)identityContext.getObject(IdentityContext.IDENTITY_CONFIGURATION);
+ }
+ return identityConfiguration;
+ }
+
+ public IdentityContext getIdentityContext()
+ {
+ return identityContext;
+ }
+
+ public void setIdentityContext(IdentityContext identityContext)
+ {
+ this.identityContext = identityContext;
+ }
+
+ protected String getJndiName()
+ {
+ return jndiName;
+ }
+
+ protected void setJndiName(String jndiName)
+ {
+ this.jndiName = jndiName;
+ }
+}
Added: trunk/identity/src/main/org/jboss/portal/identity2/service/UserModuleService.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/service/UserModuleService.java 2006-11-19 23:34:25 UTC (rev 5677)
+++ trunk/identity/src/main/org/jboss/portal/identity2/service/UserModuleService.java 2006-11-20 11:09:53 UTC (rev 5678)
@@ -0,0 +1,116 @@
+/*
+* 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.
+*/
+package org.jboss.portal.identity2.service;
+
+import org.jboss.portal.jems.as.system.AbstractJBossService;
+import org.jboss.portal.common.util.JNDI;
+import org.jboss.portal.identity.IdentityException;
+import org.jboss.portal.identity2.UserModule;
+import org.jboss.portal.identity2.IdentityConfiguration;
+import org.jboss.portal.identity2.IdentityContext;
+
+/**
+ * @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw Dawidowicz</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class UserModuleService extends AbstractJBossService implements UserModule
+{
+ private static final org.jboss.logging.Logger log = org.jboss.logging.Logger.getLogger(UserModuleService.class);
+
+ private IdentityConfiguration identityConfiguration;
+
+ private String jndiName;
+
+ private IdentityContext identityContext;
+
+ private JNDI.Binding jndiBinding;
+
+ protected void startService() throws Exception
+ {
+
+ //
+ if (jndiName != null)
+ {
+ jndiBinding = new JNDI.Binding(jndiName, this);
+ jndiBinding.bind();
+ }
+
+ if (identityContext == null)
+ {
+ throw new IdentityException("Cannot register module in context - missing reference");
+ }
+ else
+ {
+ identityContext.register(this, IdentityContext.USER_MODULE);
+ }
+
+
+ }
+
+
+ protected void stopService() throws Exception
+ {
+ if (jndiBinding != null)
+ {
+ jndiBinding.unbind();
+ jndiBinding = null;
+ }
+
+ if (identityContext == null)
+ {
+ log.error("Cannot unregister module in context - missing reference");
+ }
+ else
+ {
+ identityContext.unregister(IdentityContext.USER_MODULE);
+ }
+ }
+
+ protected IdentityConfiguration getIdentityConfiguration() throws IdentityException
+ {
+ if (identityConfiguration == null)
+ {
+ this.identityConfiguration = (IdentityConfiguration)identityContext.getObject(IdentityContext.IDENTITY_CONFIGURATION);
+ }
+ return identityConfiguration;
+ }
+
+ public IdentityContext getIdentityContext()
+ {
+ return identityContext;
+ }
+
+ public void setIdentityContext(IdentityContext identityContext)
+ {
+ this.identityContext = identityContext;
+ }
+
+ public String getJndiName()
+ {
+ return jndiName;
+ }
+
+ public void setJndiName(String jndiName)
+ {
+ this.jndiName = jndiName;
+ }
+}
Added: trunk/identity/src/main/org/jboss/portal/identity2/service/UserProfileModuleService.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/service/UserProfileModuleService.java 2006-11-19 23:34:25 UTC (rev 5677)
+++ trunk/identity/src/main/org/jboss/portal/identity2/service/UserProfileModuleService.java 2006-11-20 11:09:53 UTC (rev 5678)
@@ -0,0 +1,116 @@
+/*
+* 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.
+*/
+package org.jboss.portal.identity2.service;
+
+import org.jboss.portal.jems.as.system.AbstractJBossService;
+import org.jboss.portal.common.util.JNDI;
+import org.jboss.portal.identity.IdentityException;
+import org.jboss.portal.identity2.UserProfileModule;
+import org.jboss.portal.identity2.IdentityConfiguration;
+import org.jboss.portal.identity2.IdentityContext;
+
+/**
+ * @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw Dawidowicz</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class UserProfileModuleService extends AbstractJBossService implements UserProfileModule
+{
+ private static final org.jboss.logging.Logger log = org.jboss.logging.Logger.getLogger(UserProfileModuleService.class);
+
+ private IdentityConfiguration identityConfiguration;
+
+ private String jndiName;
+
+ private IdentityContext identityContext;
+
+ private JNDI.Binding jndiBinding;
+
+ protected void startService() throws Exception
+ {
+
+ //
+ if (jndiName != null)
+ {
+ jndiBinding = new JNDI.Binding(jndiName, this);
+ jndiBinding.bind();
+ }
+
+ if (identityContext == null)
+ {
+ throw new IdentityException("Cannot register module in context - missing reference");
+ }
+ else
+ {
+ identityContext.register(this, IdentityContext.USER_PROFILE_MODULE);
+ }
+
+
+ }
+
+
+ protected void stopService() throws Exception
+ {
+ if (jndiBinding != null)
+ {
+ jndiBinding.unbind();
+ jndiBinding = null;
+ }
+
+ if (identityContext == null)
+ {
+ log.error("Cannot unregister module in context - missing reference");
+ }
+ else
+ {
+ identityContext.unregister(IdentityContext.USER_PROFILE_MODULE);
+ }
+ }
+
+ protected IdentityConfiguration getIdentityConfiguration() throws IdentityException
+ {
+ if (identityConfiguration == null)
+ {
+ this.identityConfiguration = (IdentityConfiguration)identityContext.getObject(IdentityContext.IDENTITY_CONFIGURATION);
+ }
+ return identityConfiguration;
+ }
+
+ public IdentityContext getIdentityContext()
+ {
+ return identityContext;
+ }
+
+ public void setIdentityContext(IdentityContext identityContext)
+ {
+ this.identityContext = identityContext;
+ }
+
+ public String getJndiName()
+ {
+ return jndiName;
+ }
+
+ public void setJndiName(String jndiName)
+ {
+ this.jndiName = jndiName;
+ }
+}
Modified: trunk/identity/src/main/org/jboss/portal/test/identity/MembershipStrategyTest.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/test/identity/MembershipStrategyTest.java 2006-11-19 23:34:25 UTC (rev 5677)
+++ trunk/identity/src/main/org/jboss/portal/test/identity/MembershipStrategyTest.java 2006-11-20 11:09:53 UTC (rev 5678)
@@ -24,8 +24,8 @@
import junit.framework.Assert;
import org.jboss.portal.identity2.MembershipModule;
-import org.jboss.portal.identity.RoleModule;
-import org.jboss.portal.identity.UserModule;
+import org.jboss.portal.identity2.RoleModule;
+import org.jboss.portal.identity2.UserModule;
/**
* @author <a href="mailto:boleslaw dot dawidowicz at jboss dot com">Boleslaw Dawidowicz</a>
Modified: trunk/identity/src/main/org/jboss/portal/test/identity/ldap/LDAPSimpleRoleModuleTestCase.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/test/identity/ldap/LDAPSimpleRoleModuleTestCase.java 2006-11-19 23:34:25 UTC (rev 5677)
+++ trunk/identity/src/main/org/jboss/portal/test/identity/ldap/LDAPSimpleRoleModuleTestCase.java 2006-11-20 11:09:53 UTC (rev 5678)
@@ -23,7 +23,7 @@
package org.jboss.portal.test.identity.ldap;
import junit.framework.TestSuite;
-import org.jboss.portal.identity.RoleModule;
+import org.jboss.portal.identity2.RoleModule;
import org.jboss.portal.identity2.ldap.LDAPRoleImpl;
import org.jboss.portal.identity2.ldap.LDAPRoleModuleImpl;
import org.jboss.portal.identity2.ldap.LDAPConnectionContext;
Modified: trunk/identity/src/main/org/jboss/portal/test/identity/ldap/LDAPSimpleUserModuleTestCase.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/test/identity/ldap/LDAPSimpleUserModuleTestCase.java 2006-11-19 23:34:25 UTC (rev 5677)
+++ trunk/identity/src/main/org/jboss/portal/test/identity/ldap/LDAPSimpleUserModuleTestCase.java 2006-11-20 11:09:53 UTC (rev 5678)
@@ -23,7 +23,7 @@
package org.jboss.portal.test.identity.ldap;
import junit.framework.TestSuite;
-import org.jboss.portal.identity.UserModule;
+import org.jboss.portal.identity2.UserModule;
import org.jboss.portal.identity2.ldap.LDAPUserImpl;
import org.jboss.portal.identity2.ldap.LDAPUserModuleImpl;
import org.jboss.portal.identity2.ldap.LDAPConnectionContext;
Modified: trunk/identity/src/main/org/jboss/portal/test/identity/ldap/LDAPStaticGroupMembershipModuleTestCase.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/test/identity/ldap/LDAPStaticGroupMembershipModuleTestCase.java 2006-11-19 23:34:25 UTC (rev 5677)
+++ trunk/identity/src/main/org/jboss/portal/test/identity/ldap/LDAPStaticGroupMembershipModuleTestCase.java 2006-11-20 11:09:53 UTC (rev 5678)
@@ -35,10 +35,10 @@
import org.jboss.portal.identity2.ldap.LDAPStaticGroupMembershipModuleImpl;
import org.jboss.portal.identity2.ldap.LDAPRoleImpl;
import org.jboss.portal.identity2.ldap.LDAPUserImpl;
-import org.jboss.portal.identity.UserModule;
-import org.jboss.portal.identity.RoleModule;
-import org.jboss.portal.identity.User;
-import org.jboss.portal.identity.Role;
+import org.jboss.portal.identity2.UserModule;
+import org.jboss.portal.identity2.RoleModule;
+import org.jboss.portal.identity2.User;
+import org.jboss.portal.identity2.Role;
import org.jboss.portal.common.util.Tools;
Modified: trunk/identity/src/main/org/jboss/portal/test/identity/ldap/LDAPStaticRoleMembershipModuleTestCase.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/test/identity/ldap/LDAPStaticRoleMembershipModuleTestCase.java 2006-11-19 23:34:25 UTC (rev 5677)
+++ trunk/identity/src/main/org/jboss/portal/test/identity/ldap/LDAPStaticRoleMembershipModuleTestCase.java 2006-11-20 11:09:53 UTC (rev 5678)
@@ -22,8 +22,8 @@
package org.jboss.portal.test.identity.ldap;
import junit.framework.TestSuite;
-import org.jboss.portal.identity.UserModule;
-import org.jboss.portal.identity.RoleModule;
+import org.jboss.portal.identity2.UserModule;
+import org.jboss.portal.identity2.RoleModule;
import org.jboss.portal.identity2.MembershipModule;
import org.jboss.portal.identity2.IdentityContextImpl;
import org.jboss.portal.identity2.IdentityConfiguration;
Modified: trunk/identity/src/main/org/jboss/portal/test/identity/ldap/LDAPUserTestCase.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/test/identity/ldap/LDAPUserTestCase.java 2006-11-19 23:34:25 UTC (rev 5677)
+++ trunk/identity/src/main/org/jboss/portal/test/identity/ldap/LDAPUserTestCase.java 2006-11-20 11:09:53 UTC (rev 5678)
@@ -84,7 +84,7 @@
private UserTest utc;
/** . */
- //private DBUserModuleImpl userModule;
+ //private HibernateUserModuleImpl userModule;
public DSConfig getDirectoryServerConfigParameter()
{
@@ -97,7 +97,7 @@
}
/** . */
- //private DBRoleModuleImpl roleModule;
+ //private HibernateRoleModuleImpl roleModule;
@@ -115,12 +115,12 @@
//
utc = new UserTest();
/*
- userModule = new DBUserModuleImpl();
+ userModule = new HibernateUserModuleImpl();
userModule.setSessionFactoryJNDIName("java:/SessionFactory");
userModule.start();
//
- roleModule = new DBRoleModuleImpl();
+ roleModule = new HibernateRoleModuleImpl();
roleModule.setSessionFactoryJNDIName("java:/SessionFactory");
roleModule.start();
Modified: trunk/test/src/etc/directories.xml
===================================================================
--- trunk/test/src/etc/directories.xml 2006-11-19 23:34:25 UTC (rev 5677)
+++ trunk/test/src/etc/directories.xml 2006-11-20 11:09:53 UTC (rev 5678)
@@ -37,7 +37,7 @@
<!--DN that will be removed to perform cleanup after each test-->
<cleanup-dn>dc=testsuite,dc=portal,dc=qa,dc=atl,dc=jboss,dc=com</cleanup-dn>
</directory>
- <directory>
+ <!--<directory> in
<name>RedHatDS</name>
<description>RedHat Directory in QA Labs (need vpn access)</description>
@@ -49,7 +49,7 @@
<admin-password>qpq123qpq</admin-password>
<populate-ldif>ldap/ldif/initial-tests-qa.ldif</populate-ldif>
-
+
<cleanup-dn>dc=testsuite,dc=portal,dc=qa,dc=atl,dc=jboss,dc=com</cleanup-dn>
- </directory>
+ </directory>-->
</directories>
Modified: trunk/test/src/etc/identityconfig/opends-config.xml
===================================================================
--- trunk/test/src/etc/identityconfig/opends-config.xml 2006-11-19 23:34:25 UTC (rev 5677)
+++ trunk/test/src/etc/identityconfig/opends-config.xml 2006-11-20 11:09:53 UTC (rev 5678)
@@ -68,10 +68,6 @@
<value>hex</value>
</option>
<option>
- <name>emailAttributeID</name>
- <value>mail</value>
- </option>
- <option>
<name>roleContainerDN</name>
<value>ou=Roles,dc=testsuite,dc=portal,dc=qa,dc=atl,dc=jboss,dc=com</value>
</option>
@@ -129,4 +125,101 @@
<value>uid=dummynonexistinguser,ou=People,dc=testsuite,dc=portal,dc=qa,dc=atl,dc=jboss,dc=com</value>
</option>
</option-group>
+ <option-group>
+ <group-name>userProfileMappings</group-name>
+ <option>
+ <name>portal.user.name.given</name>
+ <!--inetOrgPerson-->
+ <value>givenName</value>
+ </option>
+ <!--<option>
+ <name>portal.user.name.family</name>
+ <value></value>
+ </option>
+ <option>
+ <name>portal.user.location</name>
+ <value></value>
+ </option>-->
+ <option>
+ <name>portal.user.occupation</name>
+ <!--inetOrgPerson-->
+ <value>title</value>
+ </option>
+ <!--<option>
+ <name>portal.user.extra</name>
+ <value></value>
+ </option>-->
+ <option>
+ <name>portal.user.signature</name>
+ <!--newPilotPerson-->
+ <value>personalSignature</value>
+ </option>
+ <!--<option>
+ <name>portal.user.interests</name>
+ <value></value>
+ </option>-->
+ <option>
+ <name>portal.user.locale</name>
+ <!--inetOrgPerson-->
+ <value>localityName</value><!--or prefferedLanguage-->
+ </option>
+ <!--<option>
+ <name>portal.user.im.icq</name>
+ <value></value>
+ </option>
+ <option>
+ <name>portal.user.im.aim</name>
+ <value></value>
+ </option>
+ <option>
+ <name>portal.user.im.msnm</name>
+ <value></value>
+ </option>
+ <option>
+ <name>portal.user.im.yim</name>
+ <value></value>
+ </option>
+ <option>
+ <name>portal.user.im.skype</name>
+ <value></value>
+ </option>-->
+ <option>
+ <name>portal.user.homepage</name>
+ <!--inetOrgPerson-->
+ <value>seeAlso</value>
+ </option>
+ <!--<option>
+ <name>portal.user.time-zone-offset</name>
+ <value></value>
+ </option>
+ <option>
+ <name>portal.user.theme</name>
+ <value></value>
+ </option>
+ <option>
+ <name>portal.user.security.question</name>
+ <value></value>
+ </option>
+ <option>
+ <name>portal.user.security.answer</name>
+ <value></value>
+ </option>
+ <option>
+ <name>portal.user.email.fake</name>
+ <value></value>
+ </option>
+ <option>
+ <name>portal.user.email.view-real</name>
+ <value></value>
+ </option>
+ <option>
+ <name>portal.user.last-login-date</name>
+ <value></value>
+ </option>
+ <option>
+ <name>portal.user.registration-date</name>
+ <value></value>
+ </option>-->
+ </option-group>
+
</identity-configuration>
\ No newline at end of file
Modified: trunk/test/src/etc/identityconfig/rhds-config.xml
===================================================================
--- trunk/test/src/etc/identityconfig/rhds-config.xml 2006-11-19 23:34:25 UTC (rev 5677)
+++ trunk/test/src/etc/identityconfig/rhds-config.xml 2006-11-20 11:09:53 UTC (rev 5678)
@@ -68,10 +68,6 @@
<value>hex</value>
</option>
<option>
- <name>emailAttributeID</name>
- <value>mail</value>
- </option>
- <option>
<name>roleContainerDN</name>
<value>ou=Roles,dc=testsuite,dc=portal,dc=qa,dc=atl,dc=jboss,dc=com</value>
</option>
More information about the jboss-svn-commits
mailing list