Author: bdaw
Date: 2006-12-17 09:52:15 -0500 (Sun, 17 Dec 2006)
New Revision: 5885
Added:
trunk/identity/src/main/org/jboss/portal/identity/AnnonymousRole.java
trunk/identity/src/main/org/jboss/portal/identity/AnnonymousUser.java
trunk/identity/src/main/org/jboss/portal/identity/DelegatingUserProfileModuleImpl.java
trunk/identity/src/main/org/jboss/portal/identity/IdentityConfiguration.java
trunk/identity/src/main/org/jboss/portal/identity/IdentityContext.java
trunk/identity/src/main/org/jboss/portal/identity/IdentityContextImpl.java
trunk/identity/src/main/org/jboss/portal/identity/IdentityServiceController.java
trunk/identity/src/main/org/jboss/portal/identity/IdentityServiceControllerImpl.java
trunk/identity/src/main/org/jboss/portal/identity/MembershipModule.java
trunk/identity/src/main/org/jboss/portal/identity/UserProfileModule.java
trunk/identity/src/main/org/jboss/portal/identity/config/
trunk/identity/src/main/org/jboss/portal/identity/config/SimpleConfigurationImpl.java
trunk/identity/src/main/org/jboss/portal/identity/config/SimpleIdentityConfigurationFactory.java
trunk/identity/src/main/org/jboss/portal/identity/config/info/
trunk/identity/src/main/org/jboss/portal/identity/config/metadata/
trunk/identity/src/main/org/jboss/portal/identity/db/HibernateMembershipModuleImpl.java
trunk/identity/src/main/org/jboss/portal/identity/db/HibernateRoleImpl.java
trunk/identity/src/main/org/jboss/portal/identity/db/HibernateRoleModuleImpl.java
trunk/identity/src/main/org/jboss/portal/identity/db/HibernateUserImpl.java
trunk/identity/src/main/org/jboss/portal/identity/db/HibernateUserModuleImpl.java
trunk/identity/src/main/org/jboss/portal/identity/db/HibernateUserProfileModuleImpl.java
trunk/identity/src/main/org/jboss/portal/identity/experimental/
trunk/identity/src/main/org/jboss/portal/identity/experimental/db/
trunk/identity/src/main/org/jboss/portal/identity/experimental/db/HibernateHelper.java
trunk/identity/src/main/org/jboss/portal/identity/experimental/db/HibernateMembershipModuleImpl.java
trunk/identity/src/main/org/jboss/portal/identity/experimental/db/HibernateRoleImpl.java
trunk/identity/src/main/org/jboss/portal/identity/experimental/db/HibernateRoleModuleImpl.java
trunk/identity/src/main/org/jboss/portal/identity/experimental/db/HibernateUserImpl.java
trunk/identity/src/main/org/jboss/portal/identity/experimental/db/HibernateUserModuleImpl.java
trunk/identity/src/main/org/jboss/portal/identity/experimental/db/HibernateUserProfileModuleImpl.java
trunk/identity/src/main/org/jboss/portal/identity/experimental/db/IdentitySessionFactoryBinder.java
trunk/identity/src/main/org/jboss/portal/identity/info/
trunk/identity/src/main/org/jboss/portal/identity/info/ProfileInfo.java
trunk/identity/src/main/org/jboss/portal/identity/info/PropertyInfo.java
trunk/identity/src/main/org/jboss/portal/identity/ldap/
trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPConnectionContext.java
trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPExtRoleModuleImpl.java
trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPExtUserModuleImpl.java
trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPMembershipModule.java
trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPRoleImpl.java
trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPRoleModule.java
trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPRoleModuleImpl.java
trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPStaticGroupMembershipModuleImpl.java
trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPStaticRoleMembershipModuleImpl.java
trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPUserImpl.java
trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPUserModule.java
trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPUserModuleImpl.java
trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPUserProfileModule.java
trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPUserProfileModuleImpl.java
trunk/identity/src/main/org/jboss/portal/identity/ldap/helper/
trunk/identity/src/main/org/jboss/portal/identity/service/
trunk/identity/src/main/org/jboss/portal/identity/service/IdentityConfigurationService.java
trunk/identity/src/main/org/jboss/portal/identity/service/IdentityModuleService.java
trunk/identity/src/main/org/jboss/portal/identity/service/MembershipModuleService.java
trunk/identity/src/main/org/jboss/portal/identity/service/RoleModuleService.java
trunk/identity/src/main/org/jboss/portal/identity/service/UserModuleService.java
trunk/identity/src/main/org/jboss/portal/identity/service/UserProfileModuleService.java
Removed:
trunk/identity/src/main/org/jboss/portal/identity/config/SimpleConfigurationImpl.java
trunk/identity/src/main/org/jboss/portal/identity/config/SimpleIdentityConfigurationFactory.java
trunk/identity/src/main/org/jboss/portal/identity/config/info/
trunk/identity/src/main/org/jboss/portal/identity/config/metadata/
trunk/identity/src/main/org/jboss/portal/identity/db/DBRoleModuleImpl.java
trunk/identity/src/main/org/jboss/portal/identity/db/DBUserModuleImpl.java
trunk/identity/src/main/org/jboss/portal/identity/db/RoleImpl.java
trunk/identity/src/main/org/jboss/portal/identity/db/UserImpl.java
trunk/identity/src/main/org/jboss/portal/identity/experimental/db/HibernateHelper.java
trunk/identity/src/main/org/jboss/portal/identity/experimental/db/HibernateMembershipModuleImpl.java
trunk/identity/src/main/org/jboss/portal/identity/experimental/db/HibernateRoleImpl.java
trunk/identity/src/main/org/jboss/portal/identity/experimental/db/HibernateRoleModuleImpl.java
trunk/identity/src/main/org/jboss/portal/identity/experimental/db/HibernateUserImpl.java
trunk/identity/src/main/org/jboss/portal/identity/experimental/db/HibernateUserModuleImpl.java
trunk/identity/src/main/org/jboss/portal/identity/experimental/db/HibernateUserProfileModuleImpl.java
trunk/identity/src/main/org/jboss/portal/identity/experimental/db/IdentitySessionFactoryBinder.java
trunk/identity/src/main/org/jboss/portal/identity/info/ProfileInfo.java
trunk/identity/src/main/org/jboss/portal/identity/info/PropertyInfo.java
trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPConnectionContext.java
trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPExtRoleModuleImpl.java
trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPExtUserModuleImpl.java
trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPMembershipModule.java
trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPRoleImpl.java
trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPRoleModule.java
trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPRoleModuleImpl.java
trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPStaticGroupMembershipModuleImpl.java
trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPStaticRoleMembershipModuleImpl.java
trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPUserImpl.java
trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPUserModule.java
trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPUserModuleImpl.java
trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPUserProfileModule.java
trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPUserProfileModuleImpl.java
trunk/identity/src/main/org/jboss/portal/identity/ldap/helper/
trunk/identity/src/main/org/jboss/portal/identity/service/IdentityConfigurationService.java
trunk/identity/src/main/org/jboss/portal/identity/service/IdentityModuleService.java
trunk/identity/src/main/org/jboss/portal/identity/service/MembershipModuleService.java
trunk/identity/src/main/org/jboss/portal/identity/service/RoleModuleService.java
trunk/identity/src/main/org/jboss/portal/identity/service/UserModuleService.java
trunk/identity/src/main/org/jboss/portal/identity/service/UserProfileModuleService.java
trunk/identity/src/main/org/jboss/portal/identity2/DelegatingUserProfileModuleImpl.java
trunk/identity/src/main/org/jboss/portal/identity2/IdentityConfiguration.java
trunk/identity/src/main/org/jboss/portal/identity2/IdentityContext.java
trunk/identity/src/main/org/jboss/portal/identity2/IdentityContextImpl.java
trunk/identity/src/main/org/jboss/portal/identity2/IdentityServiceController.java
trunk/identity/src/main/org/jboss/portal/identity2/IdentityServiceControllerImpl.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/config/
trunk/identity/src/main/org/jboss/portal/identity2/db/HibernateMembershipModuleImpl.java
trunk/identity/src/main/org/jboss/portal/identity2/db/HibernateRoleImpl.java
trunk/identity/src/main/org/jboss/portal/identity2/db/HibernateRoleModuleImpl.java
trunk/identity/src/main/org/jboss/portal/identity2/db/HibernateUserImpl.java
trunk/identity/src/main/org/jboss/portal/identity2/db/HibernateUserModuleImpl.java
trunk/identity/src/main/org/jboss/portal/identity2/db/HibernateUserProfileModuleImpl.java
trunk/identity/src/main/org/jboss/portal/identity2/db/ProfileMapImpl.java
trunk/identity/src/main/org/jboss/portal/identity2/experimental/db/
trunk/identity/src/main/org/jboss/portal/identity2/info/
trunk/identity/src/main/org/jboss/portal/identity2/ldap/
trunk/identity/src/main/org/jboss/portal/identity2/service/
Modified:
trunk/identity/src/main/org/jboss/portal/identity/Role.java
trunk/identity/src/main/org/jboss/portal/identity/RoleModule.java
trunk/identity/src/main/org/jboss/portal/identity/User.java
trunk/identity/src/main/org/jboss/portal/identity/UserModule.java
trunk/identity/src/main/org/jboss/portal/identity/auth/IdentityLoginModule.java
trunk/identity/src/main/org/jboss/portal/identity/config/info/ProfileInfoSupport.java
trunk/identity/src/main/org/jboss/portal/identity/config/info/PropertyInfoSupport.java
trunk/identity/src/main/org/jboss/portal/identity/config/metadata/ConfigMetaData.java
trunk/identity/src/main/org/jboss/portal/identity/config/metadata/ConfigOptionMetaData.java
trunk/identity/src/main/org/jboss/portal/identity/config/metadata/ConfigurationParser.java
trunk/identity/src/main/org/jboss/portal/identity/config/metadata/DatasourceMetaData.java
trunk/identity/src/main/org/jboss/portal/identity/config/metadata/DatasourcesMetaData.java
trunk/identity/src/main/org/jboss/portal/identity/config/metadata/IdentityConfigurationMetaData.java
trunk/identity/src/main/org/jboss/portal/identity/config/metadata/IdentityConfigurationMetaDataFactory.java
trunk/identity/src/main/org/jboss/portal/identity/config/metadata/ModuleMetaData.java
trunk/identity/src/main/org/jboss/portal/identity/config/metadata/ModulesMetaData.java
trunk/identity/src/main/org/jboss/portal/identity/config/metadata/OptionsGroupMetaData.java
trunk/identity/src/main/org/jboss/portal/identity/config/metadata/OptionsGroupOptionMetaData.java
trunk/identity/src/main/org/jboss/portal/identity/config/metadata/OptionsMetaData.java
trunk/identity/src/main/org/jboss/portal/identity/config/metadata/profile/LocalizedStringMetaData.java
trunk/identity/src/main/org/jboss/portal/identity/config/metadata/profile/LocalizedValueMetaData.java
trunk/identity/src/main/org/jboss/portal/identity/config/metadata/profile/ProfileMetaData.java
trunk/identity/src/main/org/jboss/portal/identity/config/metadata/profile/ProfileMetaDataFactory.java
trunk/identity/src/main/org/jboss/portal/identity/config/metadata/profile/PropertyMappingDatabaseMetaData.java
trunk/identity/src/main/org/jboss/portal/identity/config/metadata/profile/PropertyMappingLDAPMetaData.java
trunk/identity/src/main/org/jboss/portal/identity/config/metadata/profile/PropertyMappingMetaData.java
trunk/identity/src/main/org/jboss/portal/identity/config/metadata/profile/PropertyMetaData.java
trunk/identity/src/main/org/jboss/portal/identity/db/ProfileMapImpl.java
trunk/identity/src/main/org/jboss/portal/identity/ldap/helper/LDAPTools.java
trunk/identity/src/main/org/jboss/portal/test/identity/ConfigurationTestCase.java
trunk/identity/src/main/org/jboss/portal/test/identity/MembershipStrategyTest.java
trunk/identity/src/main/org/jboss/portal/test/identity/UserProtoTestCase.java
trunk/identity/src/main/org/jboss/portal/test/identity/UserTest.java
trunk/identity/src/main/org/jboss/portal/test/identity/db/DBIdentityTestCase.java
trunk/identity/src/main/org/jboss/portal/test/identity/db/DBTestCase.java
trunk/identity/src/main/org/jboss/portal/test/identity/db_old/DBUserTestCase.java
trunk/identity/src/main/org/jboss/portal/test/identity/db_old/UserTest.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/LDAPTestCase.java
trunk/identity/src/main/org/jboss/portal/test/identity/ldap/LDAPUserProfileModuleTestCase.java
trunk/identity/src/resources/hibernate/domain-identity.hbm.xml
trunk/identity/src/resources/hibernate/domain.hbm.xml
trunk/identity/src/resources/test/config/standardidentity-config.xml
Log:
- plug in new identity modules
- correct API usages
(Still some stuff not working 100% ok)
Added: trunk/identity/src/main/org/jboss/portal/identity/AnnonymousRole.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity/AnnonymousRole.java 2006-12-17
14:45:10 UTC (rev 5884)
+++ trunk/identity/src/main/org/jboss/portal/identity/AnnonymousRole.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -0,0 +1,50 @@
+/*
+* 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.identity;
+
+/**
+ * @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw
Dawidowicz</a>
+ * @version $Revision: 1.1 $
+ */
+public class AnnonymousRole implements Role
+{
+
+ public Object getId()
+ {
+ return new Long(0);
+ }
+
+ public String getName()
+ {
+ return "StandardAnnonymousPortalRole";
+ }
+
+ public String getDisplayName()
+ {
+ return "Portal Annonymous Role";
+ }
+
+ public void setDisplayName(String name)
+ {
+ //nothing
+ }
+}
Added: trunk/identity/src/main/org/jboss/portal/identity/AnnonymousUser.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity/AnnonymousUser.java 2006-12-17
14:45:10 UTC (rev 5884)
+++ trunk/identity/src/main/org/jboss/portal/identity/AnnonymousUser.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -0,0 +1,52 @@
+/*
+* 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.identity;
+
+import org.jboss.portal.identity.User;
+
+/**
+ * @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw
Dawidowicz</a>
+ * @version $Revision: 1.1 $
+ */
+public class AnnonymousUser implements User
+{
+
+ public Object getId()
+ {
+ return new Long(0);
+ }
+
+ public String getUserName()
+ {
+ return "StandardAnnonymousPortalUser";
+ }
+
+ public void updatePassword(String password)
+ {
+ //nothing
+ }
+
+ public boolean validatePassword(String password)
+ {
+ return false; //To change body of implemented methods use File | Settings | File
Templates.
+ }
+}
Copied:
trunk/identity/src/main/org/jboss/portal/identity/DelegatingUserProfileModuleImpl.java
(from rev 5871,
trunk/identity/src/main/org/jboss/portal/identity2/DelegatingUserProfileModuleImpl.java)
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/DelegatingUserProfileModuleImpl.java 2006-12-15
15:15:26 UTC (rev 5871)
+++
trunk/identity/src/main/org/jboss/portal/identity/DelegatingUserProfileModuleImpl.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -0,0 +1,230 @@
+/*
+* 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.identity;
+
+import org.jboss.portal.identity.service.UserProfileModuleService;
+import org.jboss.portal.identity.info.PropertyInfo;
+import org.jboss.portal.identity.info.ProfileInfo;
+import org.jboss.portal.identity.ldap.LDAPUserImpl;
+import org.jboss.portal.identity.db.HibernateUserImpl;
+import org.jboss.portal.identity.User;
+import org.jboss.portal.identity.IdentityException;
+
+
+import javax.naming.InitialContext;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw
Dawidowicz</a>
+ * @version $Revision: 1.1 $
+ */
+public class DelegatingUserProfileModuleImpl extends UserProfileModuleService
+{
+ private static final org.jboss.logging.Logger log =
org.jboss.logging.Logger.getLogger(DelegatingUserProfileModuleImpl.class);
+
+ private String ldapModuleJNDIName;
+
+ private String dbModuleJNDIName;
+
+ private UserProfileModule LDAPModule;
+
+ private UserProfileModule dbModule;
+
+ protected void startService() throws Exception
+ {
+ super.startService();
+
+ if(getProfileInfo() == null)
+ {
+ throw new IdentityException("No profile information found. Check the
configuration.");
+ }
+
+ //check if we don't delegate to ourselves:
+ if (getJndiName().equals(getDbModuleJNDIName()))
+ {
+ throw new IdentityException("Cannot delegate to itself - correct
dbModuleJNDIName option");
+ }
+ if (getJndiName().equals(getLdapModuleJNDIName()))
+ {
+ throw new IdentityException("Cannot delegate to itself - correct
ldapModuleJNDIName option");
+ }
+ }
+
+ public Object getProperty(User user, String propertyName) throws IdentityException,
IllegalArgumentException
+ {
+ if (log.isDebugEnabled()) log.debug("getProperty: " + propertyName);
+ try
+ {
+ PropertyInfo property = getProfileInfo().getPropertyInfo(propertyName);
+ if (property == null)
+ {
+ throw new IdentityException("Such property name is not
supported");
+ }
+ else if (property.isMappedLDAP() && isLDAPSupported() && user
instanceof LDAPUserImpl)
+ {
+ log.debug("Delegating to LDAP module");
+ return getLDAPModule().getProperty(user, propertyName);
+ }
+ else if (property.isMappedDB())
+ {
+ log.debug("Delegating to DB module");
+ return getDBModule().getProperty(user, propertyName);
+ }
+ throw new IdentityException("Cannot process property - incorrect profile or
module configuration");
+ }
+ catch (Exception e)
+ {
+ throw new IdentityException("Cannot resolve property: ", e);
+ }
+ }
+
+ public void setProperty(User user, String name, Object propertyValue) throws
IdentityException, IllegalArgumentException
+ {
+ if (log.isDebugEnabled()) log.debug("setProperty: " + name +
"/" + propertyValue);
+ try
+ {
+ PropertyInfo property = getProfileInfo().getPropertyInfo(name);
+ if (property == null)
+ {
+ throw new IdentityException("Such property name is not
supported");
+ }
+ else if (property.isMappedLDAP() && isLDAPSupported() && user
instanceof LDAPUserImpl)
+ {
+ log.debug("Delegating to LDAP module");
+ getLDAPModule().setProperty(user, name, propertyValue);
+ return;
+ }
+ else if (property.isMappedDB())
+ {
+ log.debug("Delegating to DB module");
+
+
+ Object val = null;
+ //if property is dynamic convert value to String first
+ if(property.getMappingDBType().equals(PropertyInfo.MAPPING_DB_TYPE_DYNAMIC))
+ {
+ val = propertyValue.toString();
+ }
+ else
+ {
+ val = propertyValue;
+ }
+
+ getDBModule().setProperty(user, name, val);
+ return;
+ }
+ throw new IdentityException("Cannot process property - incorrect profile or
module configuration");
+ }
+ catch (Exception e)
+ {
+ throw new IdentityException("Cannot resolve property: ", e);
+ }
+ }
+
+ public Map getProperties(User user) throws IdentityException,
IllegalArgumentException
+ {
+ if (log.isDebugEnabled()) log.debug("getProperties");//: " + name +
"/" + propertyValue)
+ try
+ {
+ if (user instanceof LDAPUserImpl && isLDAPSupported())
+ {
+ log.debug("Delegating to LDAP module");
+ return getLDAPModule().getProperties(user);
+ }
+ else if (user instanceof HibernateUserImpl && isDBSupported())
+ {
+ log.debug("Delegating to DB module");
+ return getDBModule().getProperties(user);
+ }
+ throw new IdentityException("Cannot process properties - incorrect profile
or module configuration");
+ }
+ catch (Exception e)
+ {
+ throw new IdentityException("Cannot resolve property: ", e);
+ }
+ }
+
+
+ public ProfileInfo getProfileInfo() throws IdentityException
+ {
+ return profileInfo;
+ }
+
+ public String getLdapModuleJNDIName()
+ {
+ return ldapModuleJNDIName;
+ }
+
+ public void setLdapModuleJNDIName(String ldapModuleJNDIName)
+ {
+ this.ldapModuleJNDIName = ldapModuleJNDIName;
+ }
+
+ public String getDbModuleJNDIName()
+ {
+ return dbModuleJNDIName;
+ }
+
+ public void setDbModuleJNDIName(String dbModuleJNDIName)
+ {
+ this.dbModuleJNDIName = dbModuleJNDIName;
+ }
+
+ public boolean isLDAPSupported()
+ {
+ return getLdapModuleJNDIName()!=null;
+ }
+
+ public boolean isDBSupported()
+ {
+ return getDbModuleJNDIName()!=null;
+ }
+
+ protected UserProfileModule getDBModule() throws Exception
+ {
+
+ //TODO: to tired to clean this at the moment
+ if (dbModule == null)
+ {
+ dbModule = (UserProfileModule)new
InitialContext().lookup(getDbModuleJNDIName());
+ if (dbModule == null)
+ {
+ throw new IdentityException("Couldn't obtain DB
UserProfileModule");
+ }
+ }
+ return dbModule;
+ }
+
+ protected UserProfileModule getLDAPModule() throws Exception
+ {
+ if (LDAPModule == null)
+ {
+ LDAPModule = (UserProfileModule)new
InitialContext().lookup(getLdapModuleJNDIName());
+ if (LDAPModule == null)
+ {
+ throw new IdentityException("Couldn't obtain LDAP
UserProfileModule");
+ }
+ }
+ return LDAPModule;
+ }
+
+}
Copied: trunk/identity/src/main/org/jboss/portal/identity/IdentityConfiguration.java (from
rev 5871, trunk/identity/src/main/org/jboss/portal/identity2/IdentityConfiguration.java)
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/IdentityConfiguration.java 2006-12-15
15:15:26 UTC (rev 5871)
+++
trunk/identity/src/main/org/jboss/portal/identity/IdentityConfiguration.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -0,0 +1,105 @@
+/*
+* 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.identity;
+
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw
Dawidowicz</a>
+ * @version $Revision: 1.1 $
+ */
+public interface IdentityConfiguration
+{
+
+ //TODO: isMembershipAttributeRequired
+ //TODO: memebershipAttributeEmptyValue
+ //TODO: options for secured connection to ldap
+ //TODO: let decide if has should be in hex or base64
+
+ public static final String GROUP_COMMON = "common";
+
+ public static final String GROUP_CONNECTION = "connection";
+
+ public static final String GROUP_USER_CREATE_ATTRIBUTES =
"userCreateAttibutes";
+
+ 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";
+
+ public static final String CONNECTION_HOST = "host";
+
+ public static final String CONNECTION_PORT = "port";
+
+ public static final String CONNECTION_ADMIN_DN = "admin-dn";
+
+ public static final String CONNECTION_ADMIN_PASSWORD = "admin-password";
+
+ public static final String CONNECTION_AUTHENTICATION = "authentication";
+
+ public static final String USER_CONTAINER_DN = "userContainerDN";
+
+ public static final String USER_UID_ATTRIBUTE_ID = "uidAttributeID";
+
+ public static final String USER_PASSWORD_ATTRIBUTE_ID =
"passwordAttributeID";
+
+ public static final String USER_EMAIL_ATTRIBUTE_ID = "emailAttributeID";
+
+ public static final String ROLE_CONTAINER_DN = "roleContainerDN";
+
+ public static final String ROLE_RID_ATTRIBUTE_ID = "ridAttributeID";
+
+ public static final String ROLE_DISPLAY_NAME_ATTRIBUTE_ID =
"roleDisplayNameAttributeID";
+
+ public static final String MEMBERSHIP_ATTRIBUTE_ID =
"membershipAttributeID";
+
+ public static final String MEMBERSHIP_ATTRIBUTE_IS_DN =
"membershipAttributeIsDN";
+
+ public static final String HASH_ALGORITHM = "hashAlgorithm";
+
+ public static final String HASH_ENCODING = "hashEncoding";
+
+
+ public Set getValues(String optionGroup, String option);
+
+ public String getValue(String optionGroup, String option);
+
+ public String getValue(String option);
+
+ public void setValues(String optionGroup, String option, Set values);
+
+ public void addValue(String optionGroup, String option, String value);
+
+ public Map getOptions(String optionGroup);
+
+ public void setOptions(String optionGroup, Map options);
+
+ public void remoeOption(String optionGroup, String option);
+
+ public Map getOptionGroups();
+
+
+}
Copied: trunk/identity/src/main/org/jboss/portal/identity/IdentityContext.java (from rev
5871, trunk/identity/src/main/org/jboss/portal/identity2/IdentityContext.java)
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/IdentityContext.java 2006-12-15
15:15:26 UTC (rev 5871)
+++ trunk/identity/src/main/org/jboss/portal/identity/IdentityContext.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -0,0 +1,52 @@
+/*
+* 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.identity;
+
+import org.jboss.portal.identity.IdentityException;
+
+/**
+ * @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw
Dawidowicz</a>
+ * @version $Revision: 1.1 $
+ */
+public interface IdentityContext
+{
+
+ //TODO: move to safe type enum
+ public static final String TYPE_USER_MODULE = "User";
+
+ public static final String TYPE_ROLE_MODULE = "Role";
+
+ public static final String TYPE_MEMBERSHIP_MODULE = "Membership";
+
+ public static final String TYPE_USER_PROFILE_MODULE = "UserProfile";
+
+ public static final String TYPE_CONNECTION_CONTEXT = "ConnectionContext";
+
+ public static final String TYPE_IDENTITY_CONFIGURATION =
"IdentityConfiguration";
+
+
+ public void register(Object object, String name) throws IdentityException;
+
+ public void unregister(String name);
+
+ public Object getObject(String name) throws IdentityException;
+}
Copied: trunk/identity/src/main/org/jboss/portal/identity/IdentityContextImpl.java (from
rev 5871, trunk/identity/src/main/org/jboss/portal/identity2/IdentityContextImpl.java)
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/IdentityContextImpl.java 2006-12-15
15:15:26 UTC (rev 5871)
+++ trunk/identity/src/main/org/jboss/portal/identity/IdentityContextImpl.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -0,0 +1,106 @@
+/*
+* 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.identity;
+
+import org.jboss.portal.jems.as.system.AbstractJBossService;
+import org.jboss.portal.identity.IdentityException;
+import org.jboss.portal.identity.IdentityContext;
+
+import java.util.Map;
+import java.util.HashMap;
+
+/**
+ * Keeps references to all identity related modules to enable them interactions
+ *
+ * @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw
Dawidowicz</a>
+ * @version $Revision: 1.1 $
+ */
+public class IdentityContextImpl extends AbstractJBossService implements IdentityContext
{
+ //private static final org.jboss.logging.Logger log =
org.jboss.logging.Logger.getLogger(IdentityContextImpl.class);
+
+ private Map registry;
+
+ public IdentityContextImpl()
+ {
+ registry = new HashMap();
+ }
+
+ public void register(Object object, String name) throws IdentityException
+ {
+ if (object == null)
+ {
+ throw new IllegalArgumentException("Cannot register null reference");
+ }
+ if (name == null)
+ {
+ throw new IllegalArgumentException("Cannot register object with null
name");
+ }
+
+ synchronized(this)
+ {
+ if (registry.containsKey(name))
+ {
+ throw new IdentityException("Name: " + name + " already
registered.");
+ }
+ if (log.isDebugEnabled()) log.debug("registering object: " + name +
" ; " + object.getClass());
+ registry.put(name, object);
+ }
+ }
+
+ public void unregister(String name)
+ {
+ if (name == null)
+ {
+ throw new IllegalArgumentException("Name cannot be null");
+ }
+ synchronized(this)
+ {
+ if(registry.containsKey(name))
+ {
+ if (log.isDebugEnabled()) log.debug("unregistering object: " +
name);
+
+ registry.remove(name);
+ }
+ }
+ }
+
+ public Object getObject(String name) throws IdentityException
+ {
+ if (name == null)
+ {
+ throw new IllegalArgumentException("Name cannot be null");
+ }
+
+ //TODO:
+ synchronized(this)
+ {
+ if (registry.containsKey(name))
+ {
+ return registry.get(name);
+ }
+ else
+ {
+ throw new IdentityException("No such mapping in IdentityContext: "
+ name);
+ }
+ }
+ }
+}
Copied: trunk/identity/src/main/org/jboss/portal/identity/IdentityServiceController.java
(from rev 5871,
trunk/identity/src/main/org/jboss/portal/identity2/IdentityServiceController.java)
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/IdentityServiceController.java 2006-12-15
15:15:26 UTC (rev 5871)
+++
trunk/identity/src/main/org/jboss/portal/identity/IdentityServiceController.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -0,0 +1,34 @@
+/*
+* 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.identity;
+
+import org.jboss.portal.identity.IdentityContext;
+
+/**
+ *
+ * @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw
Dawidowicz</a>
+ * @version $Revision: 1.1 $
+ */
+public interface IdentityServiceController
+{
+ public IdentityContext getIdentityContext();
+}
Copied:
trunk/identity/src/main/org/jboss/portal/identity/IdentityServiceControllerImpl.java (from
rev 5871,
trunk/identity/src/main/org/jboss/portal/identity2/IdentityServiceControllerImpl.java)
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/IdentityServiceControllerImpl.java 2006-12-15
15:15:26 UTC (rev 5871)
+++
trunk/identity/src/main/org/jboss/portal/identity/IdentityServiceControllerImpl.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -0,0 +1,579 @@
+/*
+* 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.identity;
+
+import org.jboss.portal.jems.as.system.AbstractJBossService;
+import org.jboss.portal.jems.as.system.JBossServiceModelMBean;
+import org.jboss.portal.common.util.JNDI;
+import org.jboss.portal.identity.IdentityException;
+import org.jboss.portal.identity.IdentityContext;
+import org.jboss.portal.identity.IdentityContextImpl;
+import org.jboss.portal.identity.IdentityServiceController;
+import org.jboss.portal.identity.config.metadata.IdentityConfigurationMetaData;
+import org.jboss.portal.identity.config.metadata.ModuleMetaData;
+import org.jboss.portal.identity.config.metadata.ConfigOptionMetaData;
+import org.jboss.portal.identity.config.metadata.OptionsMetaData;
+import org.jboss.portal.identity.config.metadata.OptionsGroupMetaData;
+import org.jboss.portal.identity.config.metadata.OptionsGroupOptionMetaData;
+import org.jboss.portal.identity.config.metadata.DatasourceMetaData;
+import org.jboss.portal.identity.config.metadata.ConfigurationParser;
+import org.jboss.portal.identity.service.IdentityModuleService;
+import org.jboss.portal.identity.service.IdentityConfigurationService;
+import org.jboss.kernel.Kernel;
+import org.jboss.kernel.spi.dependency.KernelControllerContext;
+import org.jboss.kernel.plugins.bootstrap.basic.BasicBootstrap;
+import org.jboss.beans.metadata.plugins.AbstractBeanMetaData;
+import org.jboss.beans.metadata.plugins.AbstractPropertyMetaData;
+
+import javax.management.ObjectName;
+import java.util.Map;
+import java.util.Iterator;
+import java.util.HashMap;
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw
Dawidowicz</a>
+ * @version $Revision: 1.1 $
+ */
+public class IdentityServiceControllerImpl extends AbstractJBossService implements
IdentityServiceController {
+ private static final org.jboss.logging.Logger log =
org.jboss.logging.Logger.getLogger(IdentityServiceControllerImpl.class);
+
+ private String jndiName;
+
+ protected JNDI.Binding jndiBinding;
+
+ private IdentityContext identityContext;
+
+ private boolean registerMBeans = true;
+
+ private String configFile;
+
+ private String defaultConfigFile;
+
+ /**
+ * .
+ */
+ protected Kernel kernel;
+
+ /**
+ * .
+ */
+ protected List beans;
+
+ protected void startService() throws Exception
+ {
+ if (jndiName != null)
+ {
+ jndiBinding = new JNDI.Binding(jndiName, this);
+ jndiBinding.bind();
+ }
+
+ //initialize microcontainer stuff
+ try
+ {
+ BasicBootstrap bootstrap = new BasicBootstrap();
+ bootstrap.run();
+ kernel = bootstrap.getKernel();
+ beans = new ArrayList();
+ }
+ catch (Exception e)
+ {
+ throw new IdentityException(e);
+ }
+
+ ClassLoader tcl = Thread.currentThread().getContextClassLoader();
+
+ //TODO: make a dtd for config files.
+
+ //parse config files
+ IdentityConfigurationMetaData meta =
ConfigurationParser.parseIdentityConfiguration(configFile);
+ IdentityConfigurationMetaData defaultMeta =
ConfigurationParser.parseIdentityConfiguration(defaultConfigFile);
+
+ KernelControllerContext identityKernelContext;
+ try
+ {
+ AbstractBeanMetaData contextBMD = new AbstractBeanMetaData(
+ "portal:identity=IdentityContext",
+ IdentityContextImpl.class.getName());
+ beans.add(contextBMD);
+ identityKernelContext = kernel.getController().install(contextBMD);
+ identityContext = (IdentityContext)identityKernelContext.getTarget();
+
+ }
+ catch (Throwable throwable)
+ {
+ throw new IdentityException(throwable);
+ }
+
+ //TODO:update meta options using defaultMeta options
+
+ //create detault modules set
+
+ //Map[implementation] --> Map[Type] --> ModuleMetaData
+ Map defaultImplementations = new HashMap();
+
+ //update modules data with defaults
+ try
+ {
+ List defaultModules = defaultMeta.getModules().getModules();
+ for (Iterator iterator = defaultModules.iterator(); iterator.hasNext();)
+ {
+ ModuleMetaData module = (ModuleMetaData)iterator.next();
+
+ //check if defaults contains all information
+ if (module.getType() == null ||
+ module.getImplementation() == null ||
+ //module.getJndiName() == null ||
+ module.getServiceName() == null ||
+ module.getConfig() == null)
+ {
+ throw new IdentityException("Default module configuration must be
complete");
+ }
+
+ //store them as maps for different implementations
+ String implType = module.getImplementation();
+ Map implementation;
+ if (defaultImplementations.containsKey(implType))
+ {
+ implementation = (Map)defaultImplementations.get(implType);
+ }
+ else
+ {
+ implementation = new HashMap();
+ }
+
+ //store per implementation
+ implementation.put(module.getType(), module);
+ defaultImplementations.put(implType, implementation);
+ }
+ }
+ catch (Exception e)
+ {
+ throw new IdentityException("Error during processing default configuration
file", e);
+ }
+
+ //map default datasources by name
+ Map defaultDatasources = new HashMap();
+ for (Iterator iterator = defaultMeta.getDatasources().getDatasources().iterator();
iterator.hasNext();)
+ {
+ DatasourceMetaData ds = (DatasourceMetaData)iterator.next();
+ defaultDatasources.put(ds.getName(), ds);
+
+ }
+
+ //process the list of modules, instantiate them, configure them, tide them
+ try
+ {
+ List datasources = meta.getDatasources().getDatasources();
+ List modules = meta.getModules().getModules();
+
+ //inject configuration service
+ IdentityConfigurationService configuration = new
IdentityConfigurationService(meta.getOptions());
+ configuration.setIdentityContext(identityContext);
+
+ //TODO:set proper jndiName and serviceName
+ configuration.start();
+
+ //update options with defaults
+ updateOptionsWithDefaults(configuration, defaultMeta.getOptions());
+
+ //process datasources
+ for (Iterator iterator = datasources.iterator(); iterator.hasNext();)
+ {
+ DatasourceMetaData ds = (DatasourceMetaData)iterator.next();
+ if (log.isDebugEnabled()) log.debug("processing datasource: " +
ds.getName() + "/" + ds.getClassName());
+ log.info("Installing datasourc: " + ds.getName());
+ updateDatasourceWithDefaults(ds, defaultDatasources);
+
+ //generate initial options
+ //TODO:presence of config tag should be forced in dtd
+ Map configOptions = ds.getConfig().getOptions();
+ Map optionMap = new HashMap();
+ for (Iterator iterator1 = configOptions.keySet().iterator();
iterator1.hasNext();)
+ {
+ String optionName = (String)iterator1.next();
+ ConfigOptionMetaData option =
(ConfigOptionMetaData)configOptions.get(optionName);
+ optionMap.put(optionName, option.getValue());
+ }
+
+ //instantiate the module
+ //IdentityModuleService moduleService = null;
+
+
+ if (ds.getClassName() == null)
+ {
+ throw new IdentityException("Class name not found for datasource
type: " + ds.getName() + " wrong configuration");
+ }
+
+ /*try
+ {
+ moduleService =
(IdentityModuleService)tcl.loadClass(module.getClassName()).newInstance();
+ }
+ catch (Exception e)
+ {
+ throw new IdentityException("Unable to instantiate the class: "
+ module.getClassName() );
+ }*/
+
+ //instantiate datasource using MC
+ String entryName = "portal:identity=Datasource,type=" +
ds.getName();
+ AbstractBeanMetaData dsBMD = new AbstractBeanMetaData(entryName,
+ ds.getClassName());
+ //AbstractPropertyMetaData propertyBMD = new
AbstractPropertyMetaData("identityContext", identityContext);
+ //moduleBMD.addProperty(propertyBMD);
+
+ //initiate parameters from <config>
+ for (Iterator iterator1 = optionMap.keySet().iterator();
iterator1.hasNext();)
+ {
+ String propertyKey = (String)iterator1.next();
+ String propertyValue = (String)optionMap.get(propertyKey);
+ if (log.isDebugEnabled()) log.debug("adding parameter: " +
propertyKey + " ; " + propertyValue);
+ AbstractPropertyMetaData propertyBMD = new
AbstractPropertyMetaData(propertyKey, propertyValue);
+ dsBMD.addProperty(propertyBMD);
+ }
+
+ // Installation
+ beans.add(dsBMD);
+ KernelControllerContext controllerContext =
kernel.getController().install(dsBMD);
+ Object datasource = controllerContext.getTarget();
+
+ //make a part of identityContext
+ //moduleService.setIdentityContext(identityContext);
+
+ //register as an mbean
+ if (isRegisterMBeans() && (ds.getServiceName() != null))
+ {
+ getServer().registerMBean(datasource, new
ObjectName(ds.getServiceName()));
+ }
+
+
+ }
+
+
+
+ //process modules for instantiation
+ for (Iterator iterator = modules.iterator(); iterator.hasNext();)
+ {
+
+ ModuleMetaData module = (ModuleMetaData)iterator.next();
+ log.info("Processing module: " + module.getType() + "/" +
module.getImplementation());// + "/" + module.getClassName());
+
+ updateModuleWithDefaults(module, defaultImplementations);
+
+ //generate initial options
+ Map configOptions = module.getConfig().getOptions();
+ Map optionMap = new HashMap();
+ for (Iterator iterator1 = configOptions.keySet().iterator();
iterator1.hasNext();)
+ {
+ String optionName = (String)iterator1.next();
+ ConfigOptionMetaData option =
(ConfigOptionMetaData)configOptions.get(optionName);
+ optionMap.put(optionName, option.getValue());
+ }
+
+ //instantiate the module
+ //IdentityModuleService moduleService = null;
+
+
+ if (module.getClassName() == null)
+ {
+ throw new IdentityException("Class name not found for module type:
" + module.getType() + " wrong configuration");
+ }
+
+ /*try
+ {
+ moduleService =
(IdentityModuleService)tcl.loadClass(module.getClassName()).newInstance();
+ }
+ catch (Exception e)
+ {
+ throw new IdentityException("Unable to instantiate the class: "
+ module.getClassName() );
+ }*/
+
+ //instantiate module using MC
+ String entryName = "portal:identity=Module,type=" +
module.getType();
+ AbstractBeanMetaData moduleBMD = new AbstractBeanMetaData(entryName,
+ module.getClassName());
+ AbstractPropertyMetaData propertyBMD = new
AbstractPropertyMetaData("identityContext", identityContext);
+ moduleBMD.addProperty(propertyBMD);
+
+ //initiate parameters from <config>
+ for (Iterator iterator1 = optionMap.keySet().iterator();
iterator1.hasNext();)
+ {
+ String propertyKey = (String)iterator1.next();
+ String propertyValue = (String)optionMap.get(propertyKey);
+ if (log.isDebugEnabled()) log.debug("adding parameter: " +
propertyKey + " ; " + propertyValue);
+ propertyBMD = new AbstractPropertyMetaData(propertyKey, propertyValue);
+ moduleBMD.addProperty(propertyBMD);
+ }
+
+ //make the type from name
+ propertyBMD = new AbstractPropertyMetaData("moduleType",
module.getType());
+ moduleBMD.addProperty(propertyBMD);
+
+
+ // Installation
+ beans.add(moduleBMD);
+ KernelControllerContext controllerContext =
kernel.getController().install(moduleBMD);
+ Object moduleService = (IdentityModuleService)controllerContext.getTarget();
+
+ //make a part of identityContext
+ //moduleService.setIdentityContext(identityContext);
+
+ //register as an mbean
+ if (isRegisterMBeans() && (module.getServiceName() != null))
+ {
+ //getServer().registerMBean(moduleService, new
ObjectName(module.getServiceName()));
+ JBossServiceModelMBean mbean = new JBossServiceModelMBean(moduleService);
+ //serviceName = new ObjectName("portal:container=WebApp,id=" +
portletAppMD.getId());
+ //mbeanServer.registerMBean(mbean, serviceName);
+ getServer().registerMBean(mbean, new
ObjectName(module.getServiceName()));
+
+ }
+ }
+
+
+ }
+ catch (Throwable e)
+ {
+ throw new IdentityException("Cannot initiate identity modules: ", e);
+ }
+ }
+
+
+ protected void stopService() throws Exception
+ {
+ if (jndiBinding != null)
+ {
+ jndiBinding.unbind();
+ jndiBinding = null;
+ }
+
+ }
+
+
+
+
+ /**
+ * updates module with proper defaults
+ *
+ * @param module
+ * @param defaultModules
+ */
+ private void updateModuleWithDefaults(ModuleMetaData module, Map defaultModules)
+ {
+ if (module.getImplementation() == null)
+ {
+ return;
+ }
+ if (!defaultModules.containsKey(module.getImplementation()))
+ {
+ return;
+ }
+ Map modules = (Map)defaultModules.get(module.getImplementation());
+ if (!modules.containsKey(module.getType()))
+ {
+ return;
+ }
+ ModuleMetaData def = (ModuleMetaData)modules.get(module.getType());
+
+ if (module.getClassName() == null)
+ {
+ module.setClassName(def.getClassName());
+ }
+ if (module.getServiceName() == null)
+ {
+ module.setServiceName(def.getServiceName());
+ }
+
+ //now check if config options are overwritten
+ if (module.getConfig() == null)
+ {
+ module.setConfig(def.getConfig());
+ }
+ else
+ {
+ Map moduleOptions = module.getConfig().getOptions();
+ if (moduleOptions == null)
+ {
+ return;
+ }
+ Map defOptions = def.getConfig().getOptions();
+
+ for (Iterator iterator = defOptions.keySet().iterator(); iterator.hasNext();)
+ {
+ String key = (String)iterator.next();
+ if (!moduleOptions.containsKey(key))
+ {
+ ConfigOptionMetaData o = (ConfigOptionMetaData)defOptions.get(key);
+ module.getConfig().addOption(o);
+ }
+ }
+ }
+ }
+
+ /**
+ * updates module with proper defaults
+ */
+ private void updateDatasourceWithDefaults(DatasourceMetaData ds, Map defaultDS)
+ {
+ if (ds.getName() == null)
+ {
+ return;
+ }
+ if (!defaultDS.containsKey(ds.getName()))
+ {
+ return;
+ }
+ DatasourceMetaData def = (DatasourceMetaData)defaultDS.get(ds.getName());
+ if (ds.getClassName() == null)
+ {
+ ds.setClassName(def.getClassName());
+ }
+ if (ds.getServiceName() == null)
+ {
+ ds.setServiceName(def.getServiceName());
+ }
+
+ //now check if config options are overwritten
+ if (ds.getConfig() == null)
+ {
+ ds.setConfig(def.getConfig());
+ }
+ else
+ {
+ Map dsOptions = ds.getConfig().getOptions();
+ if (dsOptions == null)
+ {
+ return;
+ }
+ Map defOptions = def.getConfig().getOptions();
+
+ for (Iterator iterator = defOptions.keySet().iterator(); iterator.hasNext();)
+ {
+ String key = (String)iterator.next();
+ if (!dsOptions.containsKey(key))
+ {
+ ConfigOptionMetaData o = (ConfigOptionMetaData)defOptions.get(key);
+ ds.getConfig().addOption(o);
+ }
+ }
+ }
+ }
+
+ /**
+ * Check current options and update them with defaults if not exists;
+ *
+ * @param config
+ * @param defaults
+ */
+ public void updateOptionsWithDefaults(IdentityConfigurationService config,
OptionsMetaData defaults)
+ {
+ //Map newGroups = new HashMap();
+ Map groups = defaults.getGroups();
+ for (Iterator iterator = groups.keySet().iterator(); iterator.hasNext();)
+ {
+ String groupKey = (String)iterator.next();
+
+ OptionsGroupMetaData group = (OptionsGroupMetaData)groups.get(groupKey);
+
+ if (config.getOptions(groupKey) == null)
+ {
+ config.setOptions(groupKey, new HashMap());
+ }
+
+ //Map newOptions = new HashMap();
+ Map options = group.getOptions();
+ for (Iterator iterator1 = options.keySet().iterator(); iterator1.hasNext();)
+ {
+ String optionKey = (String)iterator1.next();
+
+ OptionsGroupOptionMetaData option =
(OptionsGroupOptionMetaData)options.get(optionKey);
+
+ if (config.getValues(groupKey, optionKey) == null)
+ {
+
+ //config.setValues(groupKey, optionKey, new HashSet());
+ config.setValues(groupKey, optionKey, option.getValues());
+ }
+
+
+ }
+ }
+
+ }
+
+
+ public IdentityContext getIdentityContext()
+ {
+ return identityContext;
+ }
+
+
+ public String getConfigFile()
+ {
+ return configFile;
+ }
+
+ public void setConfigFile(String configFile)
+ {
+ this.configFile = configFile;
+ }
+
+ public String getDefaultConfigFile()
+ {
+ return defaultConfigFile;
+ }
+
+ public void setDefaultConfigFile(String defaultConfigFile)
+ {
+ this.defaultConfigFile = defaultConfigFile;
+ }
+
+ public String getJndiName()
+ {
+ return jndiName;
+ }
+
+ public void setJndiName(String jndiName)
+ {
+ this.jndiName = jndiName;
+ }
+
+ public JNDI.Binding getJndiBinding()
+ {
+ return jndiBinding;
+ }
+
+ public void setJndiBinding(JNDI.Binding jndiBinding)
+ {
+ this.jndiBinding = jndiBinding;
+ }
+
+ public boolean isRegisterMBeans()
+ {
+ return registerMBeans;
+ }
+
+ public void setRegisterMBeans(boolean registerMBeans)
+ {
+ this.registerMBeans = registerMBeans;
+ }
+}
Copied: trunk/identity/src/main/org/jboss/portal/identity/MembershipModule.java (from rev
5871, trunk/identity/src/main/org/jboss/portal/identity2/MembershipModule.java)
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/MembershipModule.java 2006-12-15
15:15:26 UTC (rev 5871)
+++ trunk/identity/src/main/org/jboss/portal/identity/MembershipModule.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -0,0 +1,82 @@
+/******************************************************************************
+ * 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.identity;
+
+
+import org.jboss.portal.identity.IdentityException;
+import org.jboss.portal.identity.User;
+import org.jboss.portal.identity.Role;
+
+import java.util.Set;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz@jboss.org">Boleslaw
Dawidowicz</a>
+ * @version $Revision: 1.1 $
+ */
+public interface MembershipModule
+{
+
+ //TODO: add isUserInRole method - it could gain better performance
+
+ /**
+ * Return the set of role objects that a given user has.
+ *
+ * @param user the user
+ * @return the set of roles of the specified user
+ */
+ Set getRoles(User user) throws IdentityException, IllegalArgumentException;
+
+ Set getUsers(Role role) throws IdentityException, IllegalArgumentException;
+
+
+ /**
+ * Creates a relationship beetween a role and set of users. Other roles that have
assotiontions with
+ * those users remain unaffected.
+ *
+ * @param role
+ * @param 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
+ * beetween the user and roles not specified in the provided set.
+ *
+ * @param user
+ * @param 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
+ * old RoleModule interface
+ *
+ * @param roleName
+ * @param offset
+ * @param limit
+ * @deprecated
+ */
+ Set findRoleMembers(String roleName, int offset, int limit, String userNameFilter)
throws IdentityException, IllegalArgumentException;
+}
Modified: trunk/identity/src/main/org/jboss/portal/identity/Role.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity/Role.java 2006-12-17 14:45:10 UTC
(rev 5884)
+++ trunk/identity/src/main/org/jboss/portal/identity/Role.java 2006-12-17 14:52:15 UTC
(rev 5885)
@@ -22,8 +22,6 @@
******************************************************************************/
package org.jboss.portal.identity;
-import java.util.Set;
-
/**
* A role of users.
*
@@ -34,19 +32,14 @@
public interface Role
{
/** The role identifier. */
- Object getId();
+ public Object getId();
/** The role name used in security rules. This name can not be modified */
- String getName();
+ public String getName();
/** The role display name used on screens. This name can be modified */
- String getDisplayName();
+ public String getDisplayName();
- /**
- *
- */
- void setDisplayName(String name);
-
- /** The users. */
- Set getUsers();
+ /** */
+ public void setDisplayName(String name);
}
Modified: trunk/identity/src/main/org/jboss/portal/identity/RoleModule.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity/RoleModule.java 2006-12-17 14:45:10
UTC (rev 5884)
+++ trunk/identity/src/main/org/jboss/portal/identity/RoleModule.java 2006-12-17 14:52:15
UTC (rev 5885)
@@ -22,6 +22,9 @@
******************************************************************************/
package org.jboss.portal.identity;
+import org.jboss.portal.identity.IdentityException;
+import org.jboss.portal.identity.Role;
+
import java.util.Set;
/**
@@ -95,28 +98,5 @@
*/
Set findRoles() throws IdentityException;
- /**
- * Returns role members based on rolename
- *
- * @param roleName
- * @param offset
- * @param limit
- */
- Set findRoleMembers(String roleName, int offset, int limit, String userNameFilter)
throws IdentityException;
- /**
- * Assign a set of role objects to a given user.
- *
- * @param user the user
- * @param roles the user roles
- */
- void setRoles(User user, Set roles) throws IdentityException;
-
- /**
- * Return the set of role objects that a given user has.
- *
- * @param user the user
- * @return the set of roles of the specified user
- */
- Set getRoles(User user) throws IdentityException;
}
Modified: trunk/identity/src/main/org/jboss/portal/identity/User.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity/User.java 2006-12-17 14:45:10 UTC
(rev 5884)
+++ trunk/identity/src/main/org/jboss/portal/identity/User.java 2006-12-17 14:52:15 UTC
(rev 5885)
@@ -22,6 +22,8 @@
******************************************************************************/
package org.jboss.portal.identity;
+import org.jboss.portal.identity.ProfileMap;
+
import java.util.Date;
import java.util.Locale;
@@ -35,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";
@@ -51,111 +50,31 @@
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. To safetly cast to String use .toString() method */
- Object getId();
+ String INFO_USER_ENABLED = "portal.user.enabled";
+ String INFO_USER_EMAIL_REAL = "portal.user.email.real";
- // User management
**************************************************************************************************
- /** Disable the user. */
- boolean getEnabled();
- /** Enable the user. */
- void setEnabled(boolean enable);
- /** Set the password. */
- void updatePassword(String password);
+ /** The user identifier. */
+ public Object getId();
- /** 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();
+ public String getUserName();
- /** The given name (firstname). */
- String getGivenName();
+ /** Set the password using proper encoding. */
+ public void updatePassword(String password);
- /**
- *
- */
- 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);
+ /** Return true if the password is valid. */
+ public boolean validatePassword(String password);
}
Modified: trunk/identity/src/main/org/jboss/portal/identity/UserModule.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity/UserModule.java 2006-12-17 14:45:10
UTC (rev 5884)
+++ trunk/identity/src/main/org/jboss/portal/identity/UserModule.java 2006-12-17 14:52:15
UTC (rev 5885)
@@ -22,6 +22,10 @@
******************************************************************************/
package org.jboss.portal.identity;
+import org.jboss.portal.identity.IdentityException;
+import org.jboss.portal.identity.NoSuchUserException;
+import org.jboss.portal.identity.User;
+
import java.util.Set;
/**
@@ -62,7 +66,7 @@
* @param userName
* @return the user
*/
- User createUser(String userName, String password, String realEmail) throws
IdentityException, IllegalArgumentException;
+ User createUser(String userName, String password) throws IdentityException,
IllegalArgumentException;
/**
* Remove a user.
Copied: trunk/identity/src/main/org/jboss/portal/identity/UserProfileModule.java (from rev
5871, trunk/identity/src/main/org/jboss/portal/identity2/UserProfileModule.java)
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/UserProfileModule.java 2006-12-15
15:15:26 UTC (rev 5871)
+++ trunk/identity/src/main/org/jboss/portal/identity/UserProfileModule.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -0,0 +1,46 @@
+/******************************************************************************
+ * 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.identity;
+
+import org.jboss.portal.identity.IdentityException;
+import org.jboss.portal.identity.info.ProfileInfo;
+import org.jboss.portal.identity.User;
+
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz@jboss.org">Boleslaw
Dawidowicz</a>
+ * @version $Revision: 1.1 $
+ */
+public interface UserProfileModule
+{
+
+ public Object getProperty(User user, String propertyName) throws IdentityException,
IllegalArgumentException;
+
+ public void setProperty(User user, String name, Object property) throws
IdentityException, IllegalArgumentException;
+
+ public Map getProperties(User user) throws IdentityException,
IllegalArgumentException;
+
+ public ProfileInfo getProfileInfo() throws IdentityException;
+
+}
Modified: trunk/identity/src/main/org/jboss/portal/identity/auth/IdentityLoginModule.java
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity/auth/IdentityLoginModule.java 2006-12-17
14:45:10 UTC (rev 5884)
+++
trunk/identity/src/main/org/jboss/portal/identity/auth/IdentityLoginModule.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -20,14 +20,15 @@
* 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.legacy_identity.auth;
+package org.jboss.portal.identity.auth;
import org.jboss.portal.common.transaction.Transactions;
-import org.jboss.portal.legacy_identity.NoSuchUserException;
-import org.jboss.portal.legacy_identity.Role;
-import org.jboss.portal.legacy_identity.RoleModule;
-import org.jboss.portal.legacy_identity.User;
-import org.jboss.portal.legacy_identity.UserModule;
+import org.jboss.portal.identity.NoSuchUserException;
+import org.jboss.portal.identity.Role;
+import org.jboss.portal.identity.RoleModule;
+import org.jboss.portal.identity.User;
+import org.jboss.portal.identity.UserModule;
+import org.jboss.portal.identity.MembershipModule;
import org.jboss.security.SimpleGroup;
import org.jboss.security.auth.spi.UsernamePasswordLoginModule;
@@ -55,6 +56,7 @@
protected String userModuleJNDIName;
protected String roleModuleJNDIName;
+ protected String membershipModuleJNDIName;
protected String additionalRole;
protected String havingRole;
@@ -65,18 +67,21 @@
// Get data
userModuleJNDIName = (String)options.get("userModuleJNDIName");
roleModuleJNDIName = (String)options.get("roleModuleJNDIName");
+ membershipModuleJNDIName =
(String)options.get("membershipModuleJNDIName");
additionalRole = (String)options.get("additionalRole");
havingRole = (String)options.get("havingRole");
// Some info
log.trace("userModuleJNDIName = " + userModuleJNDIName);
log.trace("roleModuleJNDIName = " + roleModuleJNDIName);
+ log.trace("membershipModuleJNDIName = " + membershipModuleJNDIName);
log.trace("additionalRole = " + additionalRole);
log.trace("havingRole = " + havingRole);
}
private UserModule userModule;
private RoleModule roleModule;
+ private MembershipModule membershipModule;
protected UserModule getUserModule() throws NamingException
{
@@ -97,6 +102,16 @@
return roleModule;
}
+ protected MembershipModule getMembershipModule() throws NamingException
+ {
+
+ if (membershipModule == null)
+ {
+ membershipModule = (MembershipModule)new
InitialContext().lookup(membershipModuleJNDIName);
+ }
+ return membershipModule;
+ }
+
protected String getUsersPassword() throws LoginException
{
return "";
@@ -122,7 +137,7 @@
if (havingRole != null)
{
boolean hasTheRole = false;
- Set roles = getRoleModule().getRoles(user);
+ Set roles = getMembershipModule().getRoles(user);
for (Iterator i = roles.iterator(); i.hasNext();)
{
Role role = (Role)i.next();
@@ -176,7 +191,7 @@
try
{
User user = getUserModule().findUserByUserName(getUsername());
- Set roles = getRoleModule().getRoles(user);
+ Set roles = getMembershipModule().getRoles(user);
//
Group rolesGroup = new SimpleGroup("Roles");
Copied: trunk/identity/src/main/org/jboss/portal/identity/config (from rev 5871,
trunk/identity/src/main/org/jboss/portal/identity2/config)
Deleted:
trunk/identity/src/main/org/jboss/portal/identity/config/SimpleConfigurationImpl.java
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/config/SimpleConfigurationImpl.java 2006-12-15
15:15:26 UTC (rev 5871)
+++
trunk/identity/src/main/org/jboss/portal/identity/config/SimpleConfigurationImpl.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -1,318 +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.config;
-
-import org.jboss.portal.common.util.JNDI;
-import org.jboss.portal.identity2.IdentityConfiguration;
-import org.jboss.portal.identity2.IdentityContext;
-import org.jboss.portal.jems.as.system.AbstractJBossService;
-import org.jboss.portal.identity.IdentityException;
-import org.jboss.xb.binding.Unmarshaller;
-import org.jboss.xb.binding.ObjectModelFactory;
-import org.jboss.xb.binding.UnmarshallerFactory;
-
-import java.util.Map;
-import java.util.Set;
-import java.net.URL;
-import java.io.InputStream;
-
-/**
- * Immutable object storing options in simple manner
- *
- * @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw
Dawidowicz</a>
- * @version $Revision: 1.1 $
- */
-public class SimpleConfigurationImpl extends AbstractJBossService implements
IdentityConfiguration
-{
-
- private Map data;
-
- private String jndiName;
-
- private String configFile;
-
- protected JNDI.Binding jndiBinding;
-
- private IdentityContext identityContext;
-
- protected void startService() throws Exception
- {
-
-
- try
- {
- log.info("Processing portal identity configuration");
- log.debug("config file: " + configFile);
- URL config =
Thread.currentThread().getContextClassLoader().getResource(configFile);
- InputStream in = config.openStream();
- // create unmarshaller
- Unmarshaller unmarshaller =
UnmarshallerFactory.newInstance().newUnmarshaller();
-
- // create an instance of ObjectModelFactory
- ObjectModelFactory factory = new SimpleIdentityConfigurationFactory();
-
- // let the object model factory to create an instance of Map and populate it
with data from XML
- data = (Map)unmarshaller.unmarshal(in, factory, null);
-
- // close the XML stream
- in.close();
- }
- catch (Exception e)
- {
- throw new IdentityException("Cannot parse configuration file", e);
- }
-
- //
- 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.TYPE_IDENTITY_CONFIGURATION);
- }
-
-
- }
-
-
- 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.TYPE_IDENTITY_CONFIGURATION);
- }
-
- }
-
-
-
- public Set getValues(String optionGroup, String option)
- {
- if (optionGroup == null)
- {
- throw new IllegalArgumentException("null option group");
- }
- if (option == null)
- {
- throw new IllegalArgumentException("null option name");
- }
- if (data.containsKey(optionGroup))
- {
- Map group = (Map)data.get(optionGroup);
- if (group.containsKey(option))
- {
- return (Set)group.get(option);
- }
- }
- return null;
- }
-
- public String getValue(String optionGroup, String option)
- {
- if (optionGroup == null)
- {
- throw new IllegalArgumentException("null option group");
- }
- if (option == null)
- {
- throw new IllegalArgumentException("null option name");
- }
- if (data.containsKey(optionGroup))
- {
- Map group = (Map)data.get(optionGroup);
- if (group.containsKey(option))
- {
- Set values = (Set)group.get(option);
- if (values.size() > 0)
- {
- return (String)values.toArray()[0];
- }
- }
- }
- return null;
- }
-
- public String getValue(String option)
- {
- if (option == null)
- {
- throw new IllegalArgumentException("null option name");
- }
- if (data.containsKey(GROUP_COMMON))
- {
- Map group = (Map)data.get(GROUP_COMMON);
- if (group.containsKey(option))
- {
- Set values = (Set)group.get(option);
- if (values.size() > 0)
- {
- return (String)values.toArray()[0];
- }
- }
- }
- return null;
- }
-
- public void setValues(String optionGroup, String option, Set values)
- {
- if (optionGroup == null)
- {
- throw new IllegalArgumentException("null option group");
- }
- if (option == null)
- {
- throw new IllegalArgumentException("null option name");
- }
- if (values == null)
- {
- throw new IllegalArgumentException("null values list");
- }
- if (data.containsKey(optionGroup))
- {
- ((Map)data.get(optionGroup)).put(option, values);
- }
- }
-
- public void addValue(String optionGroup, String option, String value)
- {
- if (optionGroup == null)
- {
- throw new IllegalArgumentException("null option group");
- }
- if (option == null)
- {
- throw new IllegalArgumentException("null option name");
- }
- if (value == null)
- {
- throw new IllegalArgumentException("null value name");
- }
- if (data.containsKey(optionGroup))
- {
- Map group = (Map)data.get(optionGroup);
- if (group.containsKey(option))
- {
- ((Set)group.get(option)).add(value);
- }
- }
- }
-
- public Map getOptions(String optionGroup)
- {
- if (optionGroup == null)
- {
- throw new IllegalArgumentException("null option group");
- }
- if (data.containsKey(optionGroup))
- {
- return (Map)data.get(optionGroup);
- }
- return null;
- }
-
- public void setOptions(String optionGroup, Map options)
- {
- if (optionGroup == null)
- {
- throw new IllegalArgumentException("null option group");
- }
- if (options == null)
- {
- throw new IllegalArgumentException("null options map");
- }
- data.put(optionGroup,options);
- }
-
- public void remoeOption(String optionGroup, String option)
- {
- if (optionGroup == null)
- {
- throw new IllegalArgumentException("null option group");
- }
- if (option == null)
- {
- throw new IllegalArgumentException("null option name");
- }
- if (data.containsKey(optionGroup))
- {
- ((Map)data.get(optionGroup)).put(option, null);
- }
- }
-
-
- public void setData(Map data)
- {
- this.data = data;
- }
-
- public Map getOptionGroups()
- {
- return data;
- }
-
- public String getJndiName()
- {
- return jndiName;
- }
-
- public void setJndiName(String jndiName)
- {
- this.jndiName = jndiName;
- }
-
- public String getConfigFile()
- {
- return configFile;
- }
-
- public void setConfigFile(String configFile)
- {
- this.configFile = configFile;
- }
-
- public IdentityContext getIdentityContext()
- {
- return identityContext;
- }
-
- public void setIdentityContext(IdentityContext identityContext)
- {
- this.identityContext = identityContext;
- }
-}
Copied:
trunk/identity/src/main/org/jboss/portal/identity/config/SimpleConfigurationImpl.java
(from rev 5883,
trunk/identity/src/main/org/jboss/portal/identity2/config/SimpleConfigurationImpl.java)
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/config/SimpleConfigurationImpl.java 2006-12-17
14:26:07 UTC (rev 5883)
+++
trunk/identity/src/main/org/jboss/portal/identity/config/SimpleConfigurationImpl.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -0,0 +1,318 @@
+/*
+* 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.identity.config;
+
+import org.jboss.portal.common.util.JNDI;
+import org.jboss.portal.identity.IdentityConfiguration;
+import org.jboss.portal.identity.IdentityContext;
+import org.jboss.portal.jems.as.system.AbstractJBossService;
+import org.jboss.portal.identity.IdentityException;
+import org.jboss.xb.binding.Unmarshaller;
+import org.jboss.xb.binding.ObjectModelFactory;
+import org.jboss.xb.binding.UnmarshallerFactory;
+
+import java.util.Map;
+import java.util.Set;
+import java.net.URL;
+import java.io.InputStream;
+
+/**
+ * Immutable object storing options in simple manner
+ *
+ * @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw
Dawidowicz</a>
+ * @version $Revision: 1.1 $
+ */
+public class SimpleConfigurationImpl extends AbstractJBossService implements
IdentityConfiguration
+{
+
+ private Map data;
+
+ private String jndiName;
+
+ private String configFile;
+
+ protected JNDI.Binding jndiBinding;
+
+ private IdentityContext identityContext;
+
+ protected void startService() throws Exception
+ {
+
+
+ try
+ {
+ log.info("Processing portal identity configuration");
+ log.debug("config file: " + configFile);
+ URL config =
Thread.currentThread().getContextClassLoader().getResource(configFile);
+ InputStream in = config.openStream();
+ // create unmarshaller
+ Unmarshaller unmarshaller =
UnmarshallerFactory.newInstance().newUnmarshaller();
+
+ // create an instance of ObjectModelFactory
+ ObjectModelFactory factory = new SimpleIdentityConfigurationFactory();
+
+ // let the object model factory to create an instance of Map and populate it
with data from XML
+ data = (Map)unmarshaller.unmarshal(in, factory, null);
+
+ // close the XML stream
+ in.close();
+ }
+ catch (Exception e)
+ {
+ throw new IdentityException("Cannot parse configuration file", e);
+ }
+
+ //
+ 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.TYPE_IDENTITY_CONFIGURATION);
+ }
+
+
+ }
+
+
+ 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.TYPE_IDENTITY_CONFIGURATION);
+ }
+
+ }
+
+
+
+ public Set getValues(String optionGroup, String option)
+ {
+ if (optionGroup == null)
+ {
+ throw new IllegalArgumentException("null option group");
+ }
+ if (option == null)
+ {
+ throw new IllegalArgumentException("null option name");
+ }
+ if (data.containsKey(optionGroup))
+ {
+ Map group = (Map)data.get(optionGroup);
+ if (group.containsKey(option))
+ {
+ return (Set)group.get(option);
+ }
+ }
+ return null;
+ }
+
+ public String getValue(String optionGroup, String option)
+ {
+ if (optionGroup == null)
+ {
+ throw new IllegalArgumentException("null option group");
+ }
+ if (option == null)
+ {
+ throw new IllegalArgumentException("null option name");
+ }
+ if (data.containsKey(optionGroup))
+ {
+ Map group = (Map)data.get(optionGroup);
+ if (group.containsKey(option))
+ {
+ Set values = (Set)group.get(option);
+ if (values.size() > 0)
+ {
+ return (String)values.toArray()[0];
+ }
+ }
+ }
+ return null;
+ }
+
+ public String getValue(String option)
+ {
+ if (option == null)
+ {
+ throw new IllegalArgumentException("null option name");
+ }
+ if (data.containsKey(GROUP_COMMON))
+ {
+ Map group = (Map)data.get(GROUP_COMMON);
+ if (group.containsKey(option))
+ {
+ Set values = (Set)group.get(option);
+ if (values.size() > 0)
+ {
+ return (String)values.toArray()[0];
+ }
+ }
+ }
+ return null;
+ }
+
+ public void setValues(String optionGroup, String option, Set values)
+ {
+ if (optionGroup == null)
+ {
+ throw new IllegalArgumentException("null option group");
+ }
+ if (option == null)
+ {
+ throw new IllegalArgumentException("null option name");
+ }
+ if (values == null)
+ {
+ throw new IllegalArgumentException("null values list");
+ }
+ if (data.containsKey(optionGroup))
+ {
+ ((Map)data.get(optionGroup)).put(option, values);
+ }
+ }
+
+ public void addValue(String optionGroup, String option, String value)
+ {
+ if (optionGroup == null)
+ {
+ throw new IllegalArgumentException("null option group");
+ }
+ if (option == null)
+ {
+ throw new IllegalArgumentException("null option name");
+ }
+ if (value == null)
+ {
+ throw new IllegalArgumentException("null value name");
+ }
+ if (data.containsKey(optionGroup))
+ {
+ Map group = (Map)data.get(optionGroup);
+ if (group.containsKey(option))
+ {
+ ((Set)group.get(option)).add(value);
+ }
+ }
+ }
+
+ public Map getOptions(String optionGroup)
+ {
+ if (optionGroup == null)
+ {
+ throw new IllegalArgumentException("null option group");
+ }
+ if (data.containsKey(optionGroup))
+ {
+ return (Map)data.get(optionGroup);
+ }
+ return null;
+ }
+
+ public void setOptions(String optionGroup, Map options)
+ {
+ if (optionGroup == null)
+ {
+ throw new IllegalArgumentException("null option group");
+ }
+ if (options == null)
+ {
+ throw new IllegalArgumentException("null options map");
+ }
+ data.put(optionGroup,options);
+ }
+
+ public void remoeOption(String optionGroup, String option)
+ {
+ if (optionGroup == null)
+ {
+ throw new IllegalArgumentException("null option group");
+ }
+ if (option == null)
+ {
+ throw new IllegalArgumentException("null option name");
+ }
+ if (data.containsKey(optionGroup))
+ {
+ ((Map)data.get(optionGroup)).put(option, null);
+ }
+ }
+
+
+ public void setData(Map data)
+ {
+ this.data = data;
+ }
+
+ public Map getOptionGroups()
+ {
+ return data;
+ }
+
+ public String getJndiName()
+ {
+ return jndiName;
+ }
+
+ public void setJndiName(String jndiName)
+ {
+ this.jndiName = jndiName;
+ }
+
+ public String getConfigFile()
+ {
+ return configFile;
+ }
+
+ public void setConfigFile(String configFile)
+ {
+ this.configFile = configFile;
+ }
+
+ public IdentityContext getIdentityContext()
+ {
+ return identityContext;
+ }
+
+ public void setIdentityContext(IdentityContext identityContext)
+ {
+ this.identityContext = identityContext;
+ }
+}
Deleted:
trunk/identity/src/main/org/jboss/portal/identity/config/SimpleIdentityConfigurationFactory.java
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/config/SimpleIdentityConfigurationFactory.java 2006-12-15
15:15:26 UTC (rev 5871)
+++
trunk/identity/src/main/org/jboss/portal/identity/config/SimpleIdentityConfigurationFactory.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -1,117 +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.config;
-
-import org.jboss.xb.binding.UnmarshallingContext;
-import org.jboss.xb.binding.GenericObjectModelFactory;
-import org.xml.sax.Attributes;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-import java.util.HashSet;
-
-/**
- * @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw
Dawidowicz</a>
- * @version $Revision: 1.1 $
- */
-public class SimpleIdentityConfigurationFactory implements GenericObjectModelFactory
-{
- private static final org.jboss.logging.Logger log =
org.jboss.logging.Logger.getLogger(SimpleIdentityConfigurationFactory.class);
-
- String currentGroupName;
-
- String currentOptionName;
-
- public Object newRoot(Object object, UnmarshallingContext unmarshallingContext, String
string, String string1, Attributes attributes)
- {
- return new HashMap();
- }
-
- public Object completeRoot(Object root, UnmarshallingContext unmarshallingContext,
String string, String string1)
- {
- return root;
- }
-
- public Object newChild(Object root, UnmarshallingContext nav, String nsURI, String
localName, Attributes attrs)
- {
- //return a new map for group options
- if ("option-group".equals(localName))
- {
- return new HashMap();
- }
- //return list for option values
- if ("option".equals(localName))
- {
- return new HashSet();
- }
- if (root instanceof Set)
- {
- if ("value".equals(localName))
- {
- return root;
- }
- }
- return null;
- }
-
- public void addChild(Object parent, Object child, UnmarshallingContext nav, String
nsURI, String localName)
- {
- if (child instanceof Set && parent instanceof Map)
- {
- if ("option".equals(localName))
- {
- ((Map)parent).put(this.currentOptionName, child);
- }
- }
- if (child instanceof Map && parent instanceof Map)
- {
- if ("option-group".equals(localName))
- {
- ((Map)parent).put(this.currentGroupName, child);
- }
- }
- }
-
- public void setValue(Object object, UnmarshallingContext unmarshallingContext, String
nsUri, String localName, String value)
- {
- if(object instanceof Map)
- {
- if ("group-name".equals(localName))
- {
- this.currentGroupName = value;
- }
- }
- if(object instanceof Set)
- {
- if ("name".equals(localName))
- {
- this.currentOptionName = value;
- }
- if ("value".equals(localName))
- {
- Set option = (Set)object;
- option.add(value);
- }
- }
- }
-}
Copied:
trunk/identity/src/main/org/jboss/portal/identity/config/SimpleIdentityConfigurationFactory.java
(from rev 5883,
trunk/identity/src/main/org/jboss/portal/identity2/config/SimpleIdentityConfigurationFactory.java)
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/config/SimpleIdentityConfigurationFactory.java 2006-12-17
14:26:07 UTC (rev 5883)
+++
trunk/identity/src/main/org/jboss/portal/identity/config/SimpleIdentityConfigurationFactory.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -0,0 +1,117 @@
+/*
+* 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.identity.config;
+
+import org.jboss.xb.binding.UnmarshallingContext;
+import org.jboss.xb.binding.GenericObjectModelFactory;
+import org.xml.sax.Attributes;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.HashSet;
+
+/**
+ * @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw
Dawidowicz</a>
+ * @version $Revision: 1.1 $
+ */
+public class SimpleIdentityConfigurationFactory implements GenericObjectModelFactory
+{
+ private static final org.jboss.logging.Logger log =
org.jboss.logging.Logger.getLogger(SimpleIdentityConfigurationFactory.class);
+
+ String currentGroupName;
+
+ String currentOptionName;
+
+ public Object newRoot(Object object, UnmarshallingContext unmarshallingContext, String
string, String string1, Attributes attributes)
+ {
+ return new HashMap();
+ }
+
+ public Object completeRoot(Object root, UnmarshallingContext unmarshallingContext,
String string, String string1)
+ {
+ return root;
+ }
+
+ public Object newChild(Object root, UnmarshallingContext nav, String nsURI, String
localName, Attributes attrs)
+ {
+ //return a new map for group options
+ if ("option-group".equals(localName))
+ {
+ return new HashMap();
+ }
+ //return list for option values
+ if ("option".equals(localName))
+ {
+ return new HashSet();
+ }
+ if (root instanceof Set)
+ {
+ if ("value".equals(localName))
+ {
+ return root;
+ }
+ }
+ return null;
+ }
+
+ public void addChild(Object parent, Object child, UnmarshallingContext nav, String
nsURI, String localName)
+ {
+ if (child instanceof Set && parent instanceof Map)
+ {
+ if ("option".equals(localName))
+ {
+ ((Map)parent).put(this.currentOptionName, child);
+ }
+ }
+ if (child instanceof Map && parent instanceof Map)
+ {
+ if ("option-group".equals(localName))
+ {
+ ((Map)parent).put(this.currentGroupName, child);
+ }
+ }
+ }
+
+ public void setValue(Object object, UnmarshallingContext unmarshallingContext, String
nsUri, String localName, String value)
+ {
+ if(object instanceof Map)
+ {
+ if ("group-name".equals(localName))
+ {
+ this.currentGroupName = value;
+ }
+ }
+ if(object instanceof Set)
+ {
+ if ("name".equals(localName))
+ {
+ this.currentOptionName = value;
+ }
+ if ("value".equals(localName))
+ {
+ Set option = (Set)object;
+ option.add(value);
+ }
+ }
+ }
+}
Copied: trunk/identity/src/main/org/jboss/portal/identity/config/info (from rev 5883,
trunk/identity/src/main/org/jboss/portal/identity2/config/info)
Modified:
trunk/identity/src/main/org/jboss/portal/identity/config/info/ProfileInfoSupport.java
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/config/info/ProfileInfoSupport.java 2006-12-17
14:26:07 UTC (rev 5883)
+++
trunk/identity/src/main/org/jboss/portal/identity/config/info/ProfileInfoSupport.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -19,12 +19,12 @@
* 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.config.info;
+package org.jboss.portal.identity.config.info;
-import org.jboss.portal.identity2.info.ProfileInfo;
-import org.jboss.portal.identity2.info.PropertyInfo;
-import org.jboss.portal.identity2.config.metadata.profile.ProfileMetaData;
-import org.jboss.portal.identity2.config.metadata.profile.PropertyMetaData;
+import org.jboss.portal.identity.info.ProfileInfo;
+import org.jboss.portal.identity.info.PropertyInfo;
+import org.jboss.portal.identity.config.metadata.profile.ProfileMetaData;
+import org.jboss.portal.identity.config.metadata.profile.PropertyMetaData;
import org.jboss.portal.identity.IdentityException;
import java.util.Map;
Modified:
trunk/identity/src/main/org/jboss/portal/identity/config/info/PropertyInfoSupport.java
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/config/info/PropertyInfoSupport.java 2006-12-17
14:26:07 UTC (rev 5883)
+++
trunk/identity/src/main/org/jboss/portal/identity/config/info/PropertyInfoSupport.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -19,11 +19,11 @@
* 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.config.info;
+package org.jboss.portal.identity.config.info;
-import org.jboss.portal.identity2.info.PropertyInfo;
-import org.jboss.portal.identity2.config.metadata.profile.PropertyMetaData;
-import org.jboss.portal.identity2.config.metadata.profile.LocalizedValueMetaData;
+import org.jboss.portal.identity.info.PropertyInfo;
+import org.jboss.portal.identity.config.metadata.profile.PropertyMetaData;
+import org.jboss.portal.identity.config.metadata.profile.LocalizedValueMetaData;
import org.jboss.portal.common.util.LocalizedString;
import org.jboss.portal.identity.IdentityException;
import org.jboss.logging.Logger;
Copied: trunk/identity/src/main/org/jboss/portal/identity/config/metadata (from rev 5883,
trunk/identity/src/main/org/jboss/portal/identity2/config/metadata)
Modified:
trunk/identity/src/main/org/jboss/portal/identity/config/metadata/ConfigMetaData.java
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/config/metadata/ConfigMetaData.java 2006-12-17
14:26:07 UTC (rev 5883)
+++
trunk/identity/src/main/org/jboss/portal/identity/config/metadata/ConfigMetaData.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -19,7 +19,7 @@
* 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.config.metadata;
+package org.jboss.portal.identity.config.metadata;
import java.util.Map;
import java.util.HashMap;
Modified:
trunk/identity/src/main/org/jboss/portal/identity/config/metadata/ConfigOptionMetaData.java
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/config/metadata/ConfigOptionMetaData.java 2006-12-17
14:26:07 UTC (rev 5883)
+++
trunk/identity/src/main/org/jboss/portal/identity/config/metadata/ConfigOptionMetaData.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -19,7 +19,7 @@
* 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.config.metadata;
+package org.jboss.portal.identity.config.metadata;
/**
* @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw
Dawidowicz</a>
Modified:
trunk/identity/src/main/org/jboss/portal/identity/config/metadata/ConfigurationParser.java
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/config/metadata/ConfigurationParser.java 2006-12-17
14:26:07 UTC (rev 5883)
+++
trunk/identity/src/main/org/jboss/portal/identity/config/metadata/ConfigurationParser.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -19,10 +19,10 @@
* 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.config.metadata;
+package org.jboss.portal.identity.config.metadata;
-import org.jboss.portal.identity2.config.metadata.profile.ProfileMetaData;
-import org.jboss.portal.identity2.config.metadata.profile.ProfileMetaDataFactory;
+import org.jboss.portal.identity.config.metadata.profile.ProfileMetaData;
+import org.jboss.portal.identity.config.metadata.profile.ProfileMetaDataFactory;
import org.jboss.portal.identity.IdentityException;
import org.jboss.xb.binding.Unmarshaller;
import org.jboss.xb.binding.UnmarshallerFactory;
Modified:
trunk/identity/src/main/org/jboss/portal/identity/config/metadata/DatasourceMetaData.java
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/config/metadata/DatasourceMetaData.java 2006-12-17
14:26:07 UTC (rev 5883)
+++
trunk/identity/src/main/org/jboss/portal/identity/config/metadata/DatasourceMetaData.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -19,7 +19,7 @@
* 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.config.metadata;
+package org.jboss.portal.identity.config.metadata;
/**
* @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw
Dawidowicz</a>
Modified:
trunk/identity/src/main/org/jboss/portal/identity/config/metadata/DatasourcesMetaData.java
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/config/metadata/DatasourcesMetaData.java 2006-12-17
14:26:07 UTC (rev 5883)
+++
trunk/identity/src/main/org/jboss/portal/identity/config/metadata/DatasourcesMetaData.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -19,7 +19,7 @@
* 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.config.metadata;
+package org.jboss.portal.identity.config.metadata;
import java.util.List;
import java.util.LinkedList;
Modified:
trunk/identity/src/main/org/jboss/portal/identity/config/metadata/IdentityConfigurationMetaData.java
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/config/metadata/IdentityConfigurationMetaData.java 2006-12-17
14:26:07 UTC (rev 5883)
+++
trunk/identity/src/main/org/jboss/portal/identity/config/metadata/IdentityConfigurationMetaData.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -19,11 +19,8 @@
* 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.config.metadata;
+package org.jboss.portal.identity.config.metadata;
-import java.util.Map;
-import java.util.HashMap;
-
/**
* @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw
Dawidowicz</a>
* @version $Revision: 1.1 $
Modified:
trunk/identity/src/main/org/jboss/portal/identity/config/metadata/IdentityConfigurationMetaDataFactory.java
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/config/metadata/IdentityConfigurationMetaDataFactory.java 2006-12-17
14:26:07 UTC (rev 5883)
+++
trunk/identity/src/main/org/jboss/portal/identity/config/metadata/IdentityConfigurationMetaDataFactory.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -19,20 +19,20 @@
* 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.config.metadata;
+package org.jboss.portal.identity.config.metadata;
import org.jboss.xb.binding.GenericObjectModelFactory;
import org.jboss.xb.binding.UnmarshallingContext;
-import org.jboss.portal.identity2.config.metadata.IdentityConfigurationMetaData;
-import org.jboss.portal.identity2.config.metadata.ModulesMetaData;
-import org.jboss.portal.identity2.config.metadata.OptionsMetaData;
-import org.jboss.portal.identity2.config.metadata.ModuleMetaData;
-import org.jboss.portal.identity2.config.metadata.ConfigMetaData;
-import org.jboss.portal.identity2.config.metadata.ConfigOptionMetaData;
-import org.jboss.portal.identity2.config.metadata.OptionsGroupMetaData;
-import org.jboss.portal.identity2.config.metadata.OptionsGroupOptionMetaData;
-import org.jboss.portal.identity2.config.metadata.DatasourcesMetaData;
-import org.jboss.portal.identity2.config.metadata.DatasourceMetaData;
+import org.jboss.portal.identity.config.metadata.IdentityConfigurationMetaData;
+import org.jboss.portal.identity.config.metadata.ModulesMetaData;
+import org.jboss.portal.identity.config.metadata.OptionsMetaData;
+import org.jboss.portal.identity.config.metadata.ModuleMetaData;
+import org.jboss.portal.identity.config.metadata.ConfigMetaData;
+import org.jboss.portal.identity.config.metadata.ConfigOptionMetaData;
+import org.jboss.portal.identity.config.metadata.OptionsGroupMetaData;
+import org.jboss.portal.identity.config.metadata.OptionsGroupOptionMetaData;
+import org.jboss.portal.identity.config.metadata.DatasourcesMetaData;
+import org.jboss.portal.identity.config.metadata.DatasourceMetaData;
import org.xml.sax.Attributes;
/**
Modified:
trunk/identity/src/main/org/jboss/portal/identity/config/metadata/ModuleMetaData.java
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/config/metadata/ModuleMetaData.java 2006-12-17
14:26:07 UTC (rev 5883)
+++
trunk/identity/src/main/org/jboss/portal/identity/config/metadata/ModuleMetaData.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -19,7 +19,7 @@
* 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.config.metadata;
+package org.jboss.portal.identity.config.metadata;
/**
* @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw
Dawidowicz</a>
Modified:
trunk/identity/src/main/org/jboss/portal/identity/config/metadata/ModulesMetaData.java
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/config/metadata/ModulesMetaData.java 2006-12-17
14:26:07 UTC (rev 5883)
+++
trunk/identity/src/main/org/jboss/portal/identity/config/metadata/ModulesMetaData.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -19,10 +19,8 @@
* 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.config.metadata;
+package org.jboss.portal.identity.config.metadata;
-import java.util.Map;
-import java.util.HashMap;
import java.util.List;
import java.util.LinkedList;
Modified:
trunk/identity/src/main/org/jboss/portal/identity/config/metadata/OptionsGroupMetaData.java
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/config/metadata/OptionsGroupMetaData.java 2006-12-17
14:26:07 UTC (rev 5883)
+++
trunk/identity/src/main/org/jboss/portal/identity/config/metadata/OptionsGroupMetaData.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -19,7 +19,7 @@
* 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.config.metadata;
+package org.jboss.portal.identity.config.metadata;
import java.util.Map;
import java.util.HashMap;
Modified:
trunk/identity/src/main/org/jboss/portal/identity/config/metadata/OptionsGroupOptionMetaData.java
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/config/metadata/OptionsGroupOptionMetaData.java 2006-12-17
14:26:07 UTC (rev 5883)
+++
trunk/identity/src/main/org/jboss/portal/identity/config/metadata/OptionsGroupOptionMetaData.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -19,7 +19,7 @@
* 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.config.metadata;
+package org.jboss.portal.identity.config.metadata;
import java.util.Set;
import java.util.HashSet;
Modified:
trunk/identity/src/main/org/jboss/portal/identity/config/metadata/OptionsMetaData.java
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/config/metadata/OptionsMetaData.java 2006-12-17
14:26:07 UTC (rev 5883)
+++
trunk/identity/src/main/org/jboss/portal/identity/config/metadata/OptionsMetaData.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -19,7 +19,7 @@
* 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.config.metadata;
+package org.jboss.portal.identity.config.metadata;
import java.util.Map;
import java.util.HashMap;
Modified:
trunk/identity/src/main/org/jboss/portal/identity/config/metadata/profile/LocalizedStringMetaData.java
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/config/metadata/profile/LocalizedStringMetaData.java 2006-12-17
14:26:07 UTC (rev 5883)
+++
trunk/identity/src/main/org/jboss/portal/identity/config/metadata/profile/LocalizedStringMetaData.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -19,7 +19,7 @@
* 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.config.metadata.profile;
+package org.jboss.portal.identity.config.metadata.profile;
import java.util.List;
import java.util.ArrayList;
Modified:
trunk/identity/src/main/org/jboss/portal/identity/config/metadata/profile/LocalizedValueMetaData.java
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/config/metadata/profile/LocalizedValueMetaData.java 2006-12-17
14:26:07 UTC (rev 5883)
+++
trunk/identity/src/main/org/jboss/portal/identity/config/metadata/profile/LocalizedValueMetaData.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -19,7 +19,7 @@
* 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.config.metadata.profile;
+package org.jboss.portal.identity.config.metadata.profile;
import java.util.Locale;
Modified:
trunk/identity/src/main/org/jboss/portal/identity/config/metadata/profile/ProfileMetaData.java
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/config/metadata/profile/ProfileMetaData.java 2006-12-17
14:26:07 UTC (rev 5883)
+++
trunk/identity/src/main/org/jboss/portal/identity/config/metadata/profile/ProfileMetaData.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -19,7 +19,7 @@
* 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.config.metadata.profile;
+package org.jboss.portal.identity.config.metadata.profile;
import java.util.Map;
import java.util.HashMap;
Modified:
trunk/identity/src/main/org/jboss/portal/identity/config/metadata/profile/ProfileMetaDataFactory.java
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/config/metadata/profile/ProfileMetaDataFactory.java 2006-12-17
14:26:07 UTC (rev 5883)
+++
trunk/identity/src/main/org/jboss/portal/identity/config/metadata/profile/ProfileMetaDataFactory.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -19,7 +19,7 @@
* 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.config.metadata.profile;
+package org.jboss.portal.identity.config.metadata.profile;
import org.jboss.xb.binding.GenericObjectModelFactory;
import org.jboss.xb.binding.UnmarshallingContext;
Modified:
trunk/identity/src/main/org/jboss/portal/identity/config/metadata/profile/PropertyMappingDatabaseMetaData.java
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/config/metadata/profile/PropertyMappingDatabaseMetaData.java 2006-12-17
14:26:07 UTC (rev 5883)
+++
trunk/identity/src/main/org/jboss/portal/identity/config/metadata/profile/PropertyMappingDatabaseMetaData.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -19,7 +19,7 @@
* 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.config.metadata.profile;
+package org.jboss.portal.identity.config.metadata.profile;
/**
* @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw
Dawidowicz</a>
Modified:
trunk/identity/src/main/org/jboss/portal/identity/config/metadata/profile/PropertyMappingLDAPMetaData.java
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/config/metadata/profile/PropertyMappingLDAPMetaData.java 2006-12-17
14:26:07 UTC (rev 5883)
+++
trunk/identity/src/main/org/jboss/portal/identity/config/metadata/profile/PropertyMappingLDAPMetaData.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -19,7 +19,7 @@
* 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.config.metadata.profile;
+package org.jboss.portal.identity.config.metadata.profile;
/**
* @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw
Dawidowicz</a>
Modified:
trunk/identity/src/main/org/jboss/portal/identity/config/metadata/profile/PropertyMappingMetaData.java
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/config/metadata/profile/PropertyMappingMetaData.java 2006-12-17
14:26:07 UTC (rev 5883)
+++
trunk/identity/src/main/org/jboss/portal/identity/config/metadata/profile/PropertyMappingMetaData.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -19,7 +19,7 @@
* 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.config.metadata.profile;
+package org.jboss.portal.identity.config.metadata.profile;
/**
* @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw
Dawidowicz</a>
Modified:
trunk/identity/src/main/org/jboss/portal/identity/config/metadata/profile/PropertyMetaData.java
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/config/metadata/profile/PropertyMetaData.java 2006-12-17
14:26:07 UTC (rev 5883)
+++
trunk/identity/src/main/org/jboss/portal/identity/config/metadata/profile/PropertyMetaData.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -19,7 +19,7 @@
* 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.config.metadata.profile;
+package org.jboss.portal.identity.config.metadata.profile;
/**
Deleted: trunk/identity/src/main/org/jboss/portal/identity/db/DBRoleModuleImpl.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity/db/DBRoleModuleImpl.java 2006-12-17
14:45:10 UTC (rev 5884)
+++ trunk/identity/src/main/org/jboss/portal/identity/db/DBRoleModuleImpl.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -1,419 +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.legacy_identity.db;
-
-import org.apache.log4j.Logger;
-import org.hibernate.Criteria;
-import org.hibernate.HibernateException;
-import org.hibernate.Query;
-import org.hibernate.Session;
-import org.hibernate.SessionFactory;
-import org.hibernate.criterion.Restrictions;
-import org.jboss.portal.common.util.JNDI;
-import org.jboss.portal.common.util.Tools;
-import org.jboss.portal.legacy_identity.IdentityException;
-import org.jboss.portal.legacy_identity.Role;
-import org.jboss.portal.legacy_identity.RoleModule;
-import org.jboss.portal.legacy_identity.User;
-import org.jboss.portal.jems.as.system.AbstractJBossService;
-
-import javax.naming.InitialContext;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet </a>
- * @author <a href="mailto:theute@jboss.org">Thomas Heute </a>
- * @author Roy Russo : roy at jboss dot org
- * @version $Revision$
- * @portal.core
- */
-public class DBRoleModuleImpl
- extends AbstractJBossService
- implements RoleModule
-{
-
- /** . */
- private final Logger log = Logger.getLogger(getClass());
-
- /** . */
- protected String sessionFactoryJNDIName;
-
- /** . */
- protected SessionFactory sessionFactory;
-
- /** . */
- protected String jndiName;
-
- /** . */
- protected JNDI.Binding jndiBinding;
-
- public String getSessionFactoryJNDIName()
- {
- return sessionFactoryJNDIName;
- }
-
- public void setSessionFactoryJNDIName(String sessionFactoryJNDIName)
- {
- this.sessionFactoryJNDIName = sessionFactoryJNDIName;
- }
-
- public SessionFactory getSessionFactory()
- {
- return sessionFactory;
- }
-
- public String getJNDIName()
- {
- return jndiName;
- }
-
- public void setJNDIName(String jndiName)
- {
- this.jndiName = jndiName;
- }
-
- 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 Role findRoleByName(String name) throws IdentityException
- {
- if (name != null)
- {
- try
- {
- Session session = getCurrentSession();
- Criteria criteria = session.createCriteria(RoleImpl.class);
- criteria.add(Restrictions.naturalId().set("name", name));
- criteria.setCacheable(true);
- RoleImpl role = (RoleImpl)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 RoleImpl 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();
- RoleImpl role = (RoleImpl)session.get(RoleImpl.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
- {
- RoleImpl role = new RoleImpl(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();
- RoleImpl role = (RoleImpl)session.load(RoleImpl.class, (Long)id);
- Iterator users = role.getUsers().iterator();
- while (users.hasNext())
- {
- UserImpl user = (UserImpl)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 RoleImpl 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 RoleImpl");
- 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();
-
- UserImpl userimpl = new UserImpl();
- userimpl.setEnabled(true);
-
- Query query;
- if (userNameFilter.trim().length() != 0)
- {
- //
- userNameFilter = "%" + userNameFilter.replaceAll("%",
"") + "%";
-
- //
- query = session.createQuery("from UserImpl 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 UserImpl 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 UserImpl))
- {
- 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 RoleImpl)
- {
- copy.add(o);
- }
- else
- {
- throw new IllegalArgumentException("Only db roles can be
accepted");
- }
- }
-
- // Assign new roles
- UserImpl ui = (UserImpl)user;
- ui.setRoles(copy);
- }
-
- public Set getRoles(User user) throws IdentityException
- {
- if (!(user instanceof UserImpl))
- {
- throw new IllegalArgumentException("User is not a db user");
- }
-
- // We return an immutable set to avoid modifications
- UserImpl ui = (UserImpl)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();
- }
-}
Deleted: trunk/identity/src/main/org/jboss/portal/identity/db/DBUserModuleImpl.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity/db/DBUserModuleImpl.java 2006-12-17
14:45:10 UTC (rev 5884)
+++ trunk/identity/src/main/org/jboss/portal/identity/db/DBUserModuleImpl.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -1,321 +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.legacy_identity.db;
-
-import org.apache.log4j.Logger;
-import org.hibernate.HibernateException;
-import org.hibernate.Query;
-import org.hibernate.Session;
-import org.hibernate.SessionFactory;
-import org.jboss.portal.common.util.JNDI;
-import org.jboss.portal.common.util.Tools;
-import org.jboss.portal.legacy_identity.IdentityException;
-import org.jboss.portal.legacy_identity.NoSuchUserException;
-import org.jboss.portal.legacy_identity.User;
-import org.jboss.portal.legacy_identity.UserModule;
-import org.jboss.portal.jems.as.system.AbstractJBossService;
-
-import javax.naming.InitialContext;
-import java.io.Serializable;
-import java.util.Iterator;
-import java.util.Set;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet </a>
- * @version $Revision$
- * @portal.core
- */
-public class DBUserModuleImpl
- extends AbstractJBossService
- implements UserModule
-{
-
- /** . */
- private final Logger log = Logger.getLogger(getClass());
-
- /** . */
- protected SessionFactory sessionFactory;
-
- /** . */
- protected String sessionFactoryJNDIName;
-
- /** . */
- protected String jndiName;
-
- /** . */
- protected JNDI.Binding jndiBinding;
-
- public DBUserModuleImpl()
- {
- }
-
- 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 UserImpl where
userName=:userName");
- query.setParameter("userName", userName);
- query.setCacheable(true);
- UserImpl user = (UserImpl)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();
- UserImpl user = (UserImpl)session.get(UserImpl.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
- {
- UserImpl user = new UserImpl(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();
- UserImpl user = (UserImpl)session.load(UserImpl.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 UserImpl");
- 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 UserImpl 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 UserImpl 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();
- }
-}
Copied:
trunk/identity/src/main/org/jboss/portal/identity/db/HibernateMembershipModuleImpl.java
(from rev 5871,
trunk/identity/src/main/org/jboss/portal/identity2/db/HibernateMembershipModuleImpl.java)
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/db/HibernateMembershipModuleImpl.java 2006-12-15
15:15:26 UTC (rev 5871)
+++
trunk/identity/src/main/org/jboss/portal/identity/db/HibernateMembershipModuleImpl.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -0,0 +1,253 @@
+/*
+* 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.identity.db;
+
+import org.jboss.portal.identity.service.MembershipModuleService;
+import org.jboss.portal.identity.User;
+import org.jboss.portal.identity.Role;
+import org.jboss.portal.identity.db.HibernateUserImpl;
+import org.jboss.portal.identity.db.HibernateRoleImpl;
+import org.jboss.portal.identity.IdentityException;
+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.util.Set;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Collections;
+
+/**
+ * @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw
Dawidowicz</a>
+ * @version $Revision: 1.1 $
+ */
+public class HibernateMembershipModuleImpl extends MembershipModuleService
+{
+ /** . */
+ private static final org.jboss.logging.Logger log =
org.jboss.logging.Logger.getLogger(HibernateMembershipModuleImpl.class);
+ /** . */
+ protected SessionFactory sessionFactory;
+
+ /** . */
+ protected String sessionFactoryJNDIName;
+
+ protected void startService() throws Exception
+ {
+ //
+ sessionFactory = (SessionFactory)new
InitialContext().lookup(sessionFactoryJNDIName);
+
+ super.startService();
+ }
+
+ protected void stopService() throws Exception
+ {
+
+ //
+ sessionFactory = null;
+
+ super.stopService();
+ }
+
+// public SessionFactory getSessionFactory()
+// {
+// return sessionFactory;
+// }
+
+ public String getSessionFactoryJNDIName()
+ {
+ return sessionFactoryJNDIName;
+ }
+
+ public void setSessionFactoryJNDIName(String sessionFactoryJNDIName)
+ {
+ this.sessionFactoryJNDIName = sessionFactoryJNDIName;
+ }
+
+ public Set getRoles(User user) throws IdentityException
+ {
+ //throw new UnsupportedOperationException("Not yet implemented");
+ if (!(user instanceof HibernateUserImpl))
+ {
+ throw new IllegalArgumentException("User is not a HibernateUserImpl
user");
+ }
+
+ // We return an immutable set to avoid modifications
+ HibernateUserImpl ui = (HibernateUserImpl)user;
+ Set roles = ui.getRoles();
+ Set copy = new HashSet();
+ for (Iterator iterator = roles.iterator(); iterator.hasNext();)
+ {
+ HibernateRoleImpl role = (HibernateRoleImpl)iterator.next();
+ copy.add(role);
+ }
+
+ return Collections.unmodifiableSet(copy);
+ }
+
+ public Set getUsers(Role role) throws IdentityException
+ {
+ if (!(role instanceof HibernateRoleImpl))
+ {
+ throw new IllegalArgumentException("User is not a HibernateRoleImpl
user");
+ }
+
+ // We return an immutable set to avoid modifications
+ HibernateRoleImpl ri = (HibernateRoleImpl)role;
+ Set users = ri.getUsers();
+ Set copy = new HashSet();
+ for (Iterator iterator = users.iterator(); iterator.hasNext();)
+ {
+ HibernateUserImpl user = (HibernateUserImpl)iterator.next();
+ copy.add(user);
+ }
+
+ return Collections.unmodifiableSet(copy);
+ }
+
+ public void assignUsers(Role role, Set users) throws IdentityException
+ {
+ //throw new UnsupportedOperationException("Not yet implemented");
+ if (!(role instanceof HibernateRoleImpl))
+ {
+ throw new IllegalArgumentException("User is not a HibernateRoleImpl
user");
+ }
+
+ for (Iterator i = users.iterator(); i.hasNext();)
+ {
+ Object o = i.next();
+ if (o instanceof HibernateUserImpl)
+ {
+ HibernateUserImpl user = (HibernateUserImpl)o;
+ user.getRoles().add(role);
+ }
+ else
+ {
+ throw new IllegalArgumentException("Only HibernateUserImpl roles can be
accepted");
+ }
+ }
+
+ }
+
+ public void assignRoles(User user, Set roles) throws IdentityException
+ {
+ //throw new UnsupportedOperationException("Not yet implemented");
+ if (!(user instanceof HibernateUserImpl))
+ {
+ throw new IllegalArgumentException("User is not a HibernateUserImpl
user");
+ }
+
+ // We make a defensive copy with unwrapped maps and update with a new set
+ Set copy = new HashSet();
+ for (Iterator i = roles.iterator(); i.hasNext();)
+ {
+ Object o = i.next();
+ if (o instanceof HibernateRoleImpl)
+ {
+ copy.add(o);
+ }
+ else
+ {
+ throw new IllegalArgumentException("Only HibernateRoleImpl roles can be
accepted");
+ }
+ }
+
+ // Assign new roles
+ HibernateUserImpl ui = (HibernateUserImpl)user;
+ ui.setRoles(copy);
+ }
+
+ //TODO:
+ public Set findRoleMembers(String roleName, int offset, int limit, String
userNameFilter) throws IdentityException
+ {
+ if (roleName != null)
+ {
+ try
+ {
+ Session session = getCurrentSession();
+
+ HibernateUserImpl userimpl = new HibernateUserImpl();
+ userimpl.setEnabled(true);
+
+ Query query;
+ if (userNameFilter.trim().length() != 0)
+ {
+ //
+ userNameFilter = "%" + userNameFilter.replaceAll("%",
"") + "%";
+
+ //
+ query = session.createQuery("from HibernateUserImpl 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 HibernateUserImpl 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");
+ }
+ }
+
+ /**
+ * Process Set of Map objects and returns a Set of HibernateRoleImpl objects
+ * @param maps
+ * @return
+ * @throws Exception
+ */
+
+ /** 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();
+ }
+}
Copied: trunk/identity/src/main/org/jboss/portal/identity/db/HibernateRoleImpl.java (from
rev 5871, trunk/identity/src/main/org/jboss/portal/identity2/db/HibernateRoleImpl.java)
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/db/HibernateRoleImpl.java 2006-12-15
15:15:26 UTC (rev 5871)
+++ trunk/identity/src/main/org/jboss/portal/identity/db/HibernateRoleImpl.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -0,0 +1,151 @@
+/*
+* 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.identity.db;
+
+import org.jboss.portal.identity.Role;
+
+import java.util.Set;
+import java.util.HashSet;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet </a>
+ * @author <a href="mailto:theute@jboss.org">Thomas Heute </a>
+ * @author Roy Russo : roy at jboss dot org
+ * @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw
Dawidowicz</a>
+ * @version $Revision: 5448 $
+ */
+public class HibernateRoleImpl
+ implements Role
+{
+
+ private Long key;
+ private String name;
+ private Set users;
+ private String displayName;
+
+ /**
+ *
+ */
+ //TODO: make this protected (clashes with bsh script in HibernateSerssionBinder
+ public HibernateRoleImpl()
+ {
+ this.key = null;
+ this.name = null;
+ this.displayName = null;
+ this.users = new HashSet();
+ }
+
+ /**
+ *
+ */
+ //TODO: make this protected (clashes with bsh script in HibernateSerssionBinder
+ public HibernateRoleImpl(String name)
+ {
+ this.key = null;
+ this.name = name;
+ this.displayName = name;
+ this.users = new HashSet();
+ }
+
+ /**
+ *
+ */
+ public HibernateRoleImpl(String name, String displayName)
+ {
+ this.key = null;
+ this.name = name;
+ this.displayName = displayName;
+ this.users = new HashSet();
+ }
+
+ /**
+ * @hibernate.id column="jbp_rid" generator-class="native"
+ * <p/>
+ * 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 + "]";
+ }
+}
Copied: trunk/identity/src/main/org/jboss/portal/identity/db/HibernateRoleModuleImpl.java
(from rev 5871,
trunk/identity/src/main/org/jboss/portal/identity2/db/HibernateRoleModuleImpl.java)
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/db/HibernateRoleModuleImpl.java 2006-12-15
15:15:26 UTC (rev 5871)
+++
trunk/identity/src/main/org/jboss/portal/identity/db/HibernateRoleModuleImpl.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -0,0 +1,391 @@
+/*
+* 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.identity.db;
+
+import org.jboss.portal.identity.Role;
+import org.jboss.portal.identity.IdentityException;
+import org.jboss.portal.identity.db.HibernateRoleImpl;
+import org.jboss.portal.identity.User;
+import org.jboss.portal.identity.db.HibernateUserImpl;
+import org.jboss.portal.common.util.Tools;
+import org.jboss.portal.identity.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@jboss.org">Julien Viet </a>
+ * @author <a href="mailto:theute@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(HibernateRoleModuleImpl.class);
+ /** . */
+ protected SessionFactory sessionFactory;
+
+ /** . */
+ protected String sessionFactoryJNDIName;
+
+ protected void startService() throws Exception
+ {
+ //
+ sessionFactory = (SessionFactory)new
InitialContext().lookup(sessionFactoryJNDIName);
+
+ super.startService();
+ }
+
+ protected void stopService() throws Exception
+ {
+
+ //
+ sessionFactory = null;
+
+ super.stopService();
+ }
+
+// public SessionFactory getSessionFactory()
+// {
+// return sessionFactory;
+// }
+
+ public String getSessionFactoryJNDIName()
+ {
+ return sessionFactoryJNDIName;
+ }
+
+ public void setSessionFactoryJNDIName(String sessionFactoryJNDIName)
+ {
+ this.sessionFactoryJNDIName = sessionFactoryJNDIName;
+ }
+
+
+ public Role findRoleByName(String name) throws IdentityException
+ {
+ if (name != null)
+ {
+ try
+ {
+ Session session = getCurrentSession();
+ Criteria criteria = session.createCriteria(HibernateRoleImpl.class);
+ criteria.add(Restrictions.naturalId().set("name", name));
+ criteria.setCacheable(true);
+ HibernateRoleImpl role = (HibernateRoleImpl)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 HibernateRoleImpl 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();
+ HibernateRoleImpl role =
(HibernateRoleImpl)session.get(HibernateRoleImpl.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
+ {
+ HibernateRoleImpl role = new HibernateRoleImpl(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();
+ HibernateRoleImpl role =
(HibernateRoleImpl)session.load(HibernateRoleImpl.class, (Long)id);
+ Iterator users = role.getUsers().iterator();
+ while (users.hasNext())
+ {
+ HibernateUserImpl user = (HibernateUserImpl)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
HibernateRoleImpl 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 HibernateRoleImpl");
+ 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();
+
+ HibernateUserImpl HibernateUserImpl = new HibernateUserImpl();
+ HibernateUserImpl.setEnabled(true);
+
+ Query query;
+ if (userNameFilter.trim().length() != 0)
+ {
+ //
+ userNameFilter = "%" + userNameFilter.replaceAll("%",
"") + "%";
+
+ //
+ query = session.createQuery("from HibernateUserImpl 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 HibernateUserImpl 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 HibernateUserImpl))
+ {
+ 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 HibernateRoleImpl)
+ {
+ copy.add(o);
+ }
+ else
+ {
+ throw new IllegalArgumentException("Only db roles can be
accepted");
+ }
+ }
+
+ // Assign new roles
+ HibernateUserImpl ui = (HibernateUserImpl)user;
+ ui.setRoles(copy);
+ }
+
+ public Set getRoles(User user) throws IdentityException
+ {
+ if (!(user instanceof HibernateUserImpl))
+ {
+ throw new IllegalArgumentException("User is not a db user");
+ }
+
+ // We return an immutable set to avoid modifications
+ HibernateUserImpl ui = (HibernateUserImpl)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();
+ }
+}
Copied: trunk/identity/src/main/org/jboss/portal/identity/db/HibernateUserImpl.java (from
rev 5871, trunk/identity/src/main/org/jboss/portal/identity2/db/HibernateUserImpl.java)
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/db/HibernateUserImpl.java 2006-12-15
15:15:26 UTC (rev 5871)
+++ trunk/identity/src/main/org/jboss/portal/identity/db/HibernateUserImpl.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -0,0 +1,542 @@
+/*
+* 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.identity.db;
+
+import org.jboss.portal.identity.User;
+import org.jboss.portal.common.util.Tools;
+import org.jboss.portal.common.p3p.P3PConstants;
+import org.jboss.portal.identity.ProfileMap;
+import org.jboss.portal.identity.db.ProfileMapImpl;
+
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Set;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.Collections;
+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@jboss.org">Julien Viet </a>
+ * @author <a href="mailto:theute@jboss.org">Thomas Heute </a>
+ * @author <a href="mailto:mageshbk@jboss.com">Magesh Kumar Bojan
</a>
+ * @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw
Dawidowicz</a>
+ * @version $Revision: 5448 $
+ */
+public class HibernateUserImpl
+ implements User
+{
+
+ private static final org.jboss.logging.Logger log =
org.jboss.logging.Logger.getLogger(HibernateUserImpl.class);
+
+ static final Map ACCESSORS = HibernateUserImpl.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
StringPropertyAccessor(P3PConstants.INFO_USER_NAME_NICKNAME, "userName", false,
false));
+ map.put(P3PConstants.INFO_USER_BUSINESS_INFO_ONLINE_EMAIL, new
StringPropertyAccessor(P3PConstants.INFO_USER_BUSINESS_INFO_ONLINE_EMAIL,
"realEmail", true, true));
+ map.put(P3PConstants.INFO_USER_NAME_GIVEN, new
StringPropertyAccessor(P3PConstants.INFO_USER_NAME_GIVEN, "givenName", true,
true));
+ map.put(P3PConstants.INFO_USER_NAME_FAMILY, new
StringPropertyAccessor(P3PConstants.INFO_USER_NAME_FAMILY, "familyName", true,
true));
+
+ // Map attributes specific to JBoss Portal
+ map.put(org.jboss.portal.identity.User.INFO_USER_EMAIL_FAKE, new
StringPropertyAccessor(org.jboss.portal.identity.User.INFO_USER_EMAIL_FAKE,
"fakeEmail", true, true));
+ map.put(org.jboss.portal.identity.User.INFO_USER_REGISTRATION_DATE, new
DatePropertyAccessor(org.jboss.portal.identity.User.INFO_USER_REGISTRATION_DATE,
"registrationDate", false, false));
+ map.put(org.jboss.portal.identity.User.INFO_USER_VIEW_EMAIL_VIEW_REAL, new
BooleanPropertyAccessor(org.jboss.portal.identity.User.INFO_USER_VIEW_EMAIL_VIEW_REAL,
"viewRealEmail", true, false));
+ map.put(org.jboss.portal.identity.User.INFO_USER_ENABLED, new
BooleanPropertyAccessor(org.jboss.portal.identity.User.INFO_USER_ENABLED,
"enabled", true, false));
+
+ //
+ return Collections.unmodifiableMap(map);
+ }
+
+ protected ProfileMap profileMap;
+
+ /*
+ * 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;
+
+ /**
+ *
+ */
+ //TODO: make this protected (clashes with bsh script in HibernateSerssionBinder
+ public HibernateUserImpl()
+ {
+ this.key = null;
+ this.userName = null;
+ this.dynamic = null;
+ this.roles = null;
+ this.registrationDate = null;
+ this.enabled = false;
+ this.profileMap = new org.jboss.portal.identity.db.ProfileMapImpl(this);
+ }
+
+ /**
+ *
+ */
+ public HibernateUserImpl(String userName)
+ {
+ this.key = null;
+ this.userName = userName;
+ this.dynamic = new HashMap();
+ this.roles = new HashSet();
+ this.registrationDate = new Date();
+ this.enabled = false;
+ this.profileMap = new ProfileMapImpl(this);
+ }
+
+ /** 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;
+ }
+
+ public ProfileMap getProfileMap()
+ {
+ return profileMap;
+ }
+
+ // 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 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;
+ }
+
+ public boolean validatePassword(String password)
+ {
+ if (password != null)
+ {
+ String hashedPassword = Tools.md5AsHexString(password);
+ return hashedPassword.equals(this.password);
+ }
+ return false;
+ }
+
+ /**
+ *
+ */
+ 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 = HibernateUserImpl.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 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 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 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)HibernateUserImpl.DatePropertyAccessor.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)HibernateUserImpl.DatePropertyAccessor.formatLocal.get();
+ return format.format(date);
+ }
+ }
+}
Copied: trunk/identity/src/main/org/jboss/portal/identity/db/HibernateUserModuleImpl.java
(from rev 5871,
trunk/identity/src/main/org/jboss/portal/identity2/db/HibernateUserModuleImpl.java)
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/db/HibernateUserModuleImpl.java 2006-12-15
15:15:26 UTC (rev 5871)
+++
trunk/identity/src/main/org/jboss/portal/identity/db/HibernateUserModuleImpl.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -0,0 +1,288 @@
+/*
+* 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.identity.db;
+
+import org.jboss.portal.identity.User;
+import org.jboss.portal.identity.IdentityException;
+import org.jboss.portal.identity.NoSuchUserException;
+import org.jboss.portal.identity.db.HibernateUserImpl;
+import org.jboss.portal.common.util.Tools;
+import org.jboss.portal.identity.service.UserModuleService;
+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@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 void startService() throws Exception
+ {
+ //
+ sessionFactory = (SessionFactory)new
InitialContext().lookup(sessionFactoryJNDIName);
+
+ super.startService();
+ }
+
+ protected void stopService() throws Exception
+ {
+
+ //
+ sessionFactory = null;
+
+ super.stopService();
+ }
+
+// public SessionFactory getSessionFactory()
+// {
+// return sessionFactory;
+// }
+
+ public String getSessionFactoryJNDIName()
+ {
+ return sessionFactoryJNDIName;
+ }
+
+ public void setSessionFactoryJNDIName(String sessionFactoryJNDIName)
+ {
+ this.sessionFactoryJNDIName = sessionFactoryJNDIName;
+ }
+
+
+ public User findUserByUserName(String userName) throws IdentityException
+ {
+ if (userName != null)
+ {
+ try
+ {
+ Session session = getCurrentSession();
+ Query query = session.createQuery("from HibernateUserImpl where
userName=:userName");
+ query.setParameter("userName", userName);
+ query.setCacheable(true);
+ HibernateUserImpl user = (HibernateUserImpl)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();
+ HibernateUserImpl user =
(HibernateUserImpl)session.get(HibernateUserImpl.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) throws IdentityException
+ {
+ if (userName != null)
+ {
+ try
+ {
+ HibernateUserImpl user = new HibernateUserImpl(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();
+ HibernateUserImpl user =
(HibernateUserImpl)session.load(HibernateUserImpl.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 HibernateUserImpl");
+ 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 HibernateUserImpl 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
HibernateUserImpl 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();
+ }
+}
Copied:
trunk/identity/src/main/org/jboss/portal/identity/db/HibernateUserProfileModuleImpl.java
(from rev 5871,
trunk/identity/src/main/org/jboss/portal/identity2/db/HibernateUserProfileModuleImpl.java)
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/db/HibernateUserProfileModuleImpl.java 2006-12-15
15:15:26 UTC (rev 5871)
+++
trunk/identity/src/main/org/jboss/portal/identity/db/HibernateUserProfileModuleImpl.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -0,0 +1,293 @@
+/*
+* 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.identity.db;
+
+import org.jboss.portal.identity.User;
+import org.jboss.portal.identity.UserProfileModule;
+import org.jboss.portal.identity.IdentityContext;
+import org.jboss.portal.identity.info.ProfileInfo;
+import org.jboss.portal.identity.info.PropertyInfo;
+import org.jboss.portal.identity.db.HibernateUserImpl;
+import org.hibernate.SessionFactory;
+import org.hibernate.Session;
+import org.hibernate.Query;
+import org.hibernate.HibernateException;
+
+import javax.naming.InitialContext;
+import org.jboss.portal.identity.service.UserProfileModuleService;
+import org.jboss.portal.identity.IdentityException;
+
+import java.util.Map;
+import java.util.Set;
+import java.util.Iterator;
+import java.util.HashMap;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz@jboss.org">Boleslaw
Dawidowicz</a>
+ * @version $Revision: 1.1 $
+ */
+public class HibernateUserProfileModuleImpl extends UserProfileModuleService
+{
+
+ /** . */
+ private static final org.jboss.logging.Logger log =
org.jboss.logging.Logger.getLogger(HibernateUserProfileModuleImpl.class);
+ /** . */
+ protected SessionFactory sessionFactory;
+
+ /** . */
+ protected String sessionFactoryJNDIName;
+
+ private boolean synchronizeNonExistingUsers = true;
+
+ private boolean acceptOtherImplementations = true;
+
+ private String defaultSynchronizePassword;
+
+ protected void startService() throws Exception
+ {
+ //
+ sessionFactory = (SessionFactory)new
InitialContext().lookup(sessionFactoryJNDIName);
+
+ super.startService();
+
+ }
+
+ protected void stopService() throws Exception
+ {
+ //
+ sessionFactory = null;
+ super.stopService();
+ }
+
+// public SessionFactory getSessionFactory()
+// {
+// return sessionFactory;
+// }
+
+ public String getSessionFactoryJNDIName()
+ {
+ return sessionFactoryJNDIName;
+ }
+
+ public void setSessionFactoryJNDIName(String sessionFactoryJNDIName)
+ {
+ this.sessionFactoryJNDIName = sessionFactoryJNDIName;
+ }
+
+ public Object getProperty(User user, String propertyName) throws IdentityException
+ {
+ if (user == null)
+ {
+ throw new IllegalArgumentException("User cannot be null");
+ }
+ if (propertyName == null)
+ {
+ throw new IllegalArgumentException("Property name need to have
value");
+ }
+
+ HibernateUserImpl dbUser = processUser(user);
+
+ PropertyInfo pi = getProfileInfo().getPropertyInfo(propertyName);
+
+ if (pi == null)
+ {
+ throw new IdentityException("Cannot find profile information about
property: " + propertyName);
+ }
+
+ return dbUser.getProfileMap().get(propertyName);
+ }
+
+ public void setProperty(User user, String propertyName, Object propertyValue) throws
IdentityException
+ {
+ if (user == null)
+ {
+ throw new IllegalArgumentException("User cannot be null");
+ }
+ if (propertyName == null)
+ {
+ throw new IllegalArgumentException("Property name need to have
value");
+ }
+
+ HibernateUserImpl dbUser = processUser(user);
+
+
+ PropertyInfo pi = getProfileInfo().getPropertyInfo(propertyName);
+
+ if (pi == null)
+ {
+ throw new IdentityException("Cannot find profile information about
property: " + propertyName);
+ }
+ else if (!pi.getAccessMode().equals(PropertyInfo.ACCESS_MODE_READ_WRITE))
+ {
+ throw new IdentityException("Property is not allowed for write access:
" + propertyName);
+ }
+
+ //if value is null reset property
+
+ dbUser.getProfileMap().put(propertyName, propertyValue);
+ }
+
+ public Map getProperties(User user) throws IdentityException
+ {
+ if (user == null)
+ {
+ throw new IllegalArgumentException("User cannot be null");
+ }
+
+ HibernateUserImpl dbUser = processUser(user);
+
+
+
+ //make a copy
+ Map props = new HashMap();
+ Map profile = dbUser.getProfileMap();
+ Set keys = profile.keySet();
+ for (Iterator iterator = keys.iterator(); iterator.hasNext();)
+ {
+ String key = (String)iterator.next();
+ props.put(key, profile.get(key));
+ }
+ return props;
+ }
+
+
+
+ /** 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();
+ }
+
+ protected HibernateUserImpl processUser(User user) throws IdentityException
+ {
+ if (user instanceof HibernateUserImpl)
+ {
+ return (HibernateUserImpl)user;
+ }
+ else if (!isAcceptOtherImplementations())
+ {
+ throw new IllegalArgumentException("This UserProfileModule implementation
support only HibenrateUserImpl objects - set acceptOtherImplementations option to
true");
+ }
+ if (log.isDebugEnabled()) log.debug("Processing non HibernateUserImpl object:
" + user.getClass());
+ //if not Hibernate user try to obtain it using userName
+ Session session = getCurrentSession();
+ Query query = session.createQuery("from HibernateUserImpl where
userName=:userName");
+ query.setParameter("userName", user.getUserName());
+ query.setCacheable(true);
+ HibernateUserImpl hu = (HibernateUserImpl)query.uniqueResult();
+
+ if (hu != null )
+ {
+ return hu;
+ }
+ else if (!isSynchronizeNonExistingUsers())
+ {
+ throw new IdentityException("No user in DB - set
synchronizeNonExistingUsers option to true");
+ }
+ else
+ {
+ try
+ {
+ hu = new HibernateUserImpl(user.getUserName());
+ //user.updatePassword(user.getPassword());
+ if (defaultSynchronizePassword != null)
+ {
+ user.updatePassword(getDefaultSynchronizePassword());
+ }
+ session = getCurrentSession();
+ session.save(hu);
+ return hu;
+ }
+ catch (HibernateException e)
+ {
+ String message = "Cannot create user " + user.getUserName();
+ log.error(message, e);
+ throw new IdentityException(message, e);
+ }
+ }
+
+
+ }
+
+
+ /**
+ * obtains UserProfile object - if module is used as a Delegate it tries to obtain it
from the main one.
+ * @return
+ * @throws IdentityException
+ */
+ public ProfileInfo getProfileInfo() throws IdentityException
+ {
+
+
+ if (profileInfo == null)
+ {
+ //obtain main UserProfileModule
+ UserProfileModule module =
(UserProfileModule)getIdentityContext().getObject(IdentityContext.TYPE_USER_PROFILE_MODULE);
+ if (module == this)
+ {
+ throw new IdentityException("ProfileInfo not accessible - check
configuration");
+ }
+ else
+ {
+ setProfileInfo(module.getProfileInfo());
+ }
+ }
+ return profileInfo;
+ }
+
+
+ public boolean isSynchronizeNonExistingUsers()
+ {
+ return synchronizeNonExistingUsers;
+ }
+
+ public void setSynchronizeNonExistingUsers(boolean synchronizeNonExistingUsers)
+ {
+ this.synchronizeNonExistingUsers = synchronizeNonExistingUsers;
+ }
+
+
+ public boolean isAcceptOtherImplementations()
+ {
+ return acceptOtherImplementations;
+ }
+
+ public void setAcceptOtherImplementations(boolean acceptOtherImplementations)
+ {
+ this.acceptOtherImplementations = acceptOtherImplementations;
+ }
+
+ public String getDefaultSynchronizePassword()
+ {
+ return defaultSynchronizePassword;
+ }
+
+ public void setDefaultSynchronizePassword(String defaultSynchronizePassword)
+ {
+ this.defaultSynchronizePassword = defaultSynchronizePassword;
+ }
+}
+
Modified: trunk/identity/src/main/org/jboss/portal/identity/db/ProfileMapImpl.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity/db/ProfileMapImpl.java 2006-12-17
14:45:10 UTC (rev 5884)
+++ trunk/identity/src/main/org/jboss/portal/identity/db/ProfileMapImpl.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -1,37 +1,36 @@
-/******************************************************************************
- * 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.legacy_identity.db;
+/*
+* 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.identity.db;
-import org.jboss.portal.legacy_identity.ProfileMap;
+import org.jboss.portal.identity.ProfileMap;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
import java.util.Iterator;
-import java.util.Map;
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.
@@ -43,9 +42,9 @@
{
/** . */
- private UserImpl user;
+ private HibernateUserImpl user;
- public ProfileMapImpl(UserImpl user)
+ public ProfileMapImpl(HibernateUserImpl user)
{
if (user == null)
{
@@ -64,13 +63,13 @@
{
throw new ClassCastException("Key must be a string");
}
- UserImpl.PropertyAccessor accessor =
(UserImpl.PropertyAccessor)UserImpl.ACCESSORS.get(key);
+ HibernateUserImpl.PropertyAccessor accessor =
(HibernateUserImpl.PropertyAccessor)HibernateUserImpl.ACCESSORS.get(key);
return accessor != null && !accessor.isWritable();
}
public int size()
{
- return UserImpl.ACCESSORS.size() + user.getDynamic().size();
+ return HibernateUserImpl.ACCESSORS.size() + user.getDynamic().size();
}
public boolean isEmpty()
@@ -89,7 +88,7 @@
{
throw new ClassCastException("Key must be a string");
}
- UserImpl.PropertyAccessor accessor =
(UserImpl.PropertyAccessor)UserImpl.ACCESSORS.get(key);
+ HibernateUserImpl.PropertyAccessor accessor =
(HibernateUserImpl.PropertyAccessor)HibernateUserImpl.ACCESSORS.get(key);
if (accessor != null)
{
return true;
@@ -108,9 +107,9 @@
{
throw new ClassCastException("Value must be a string");
}
- for (Iterator i = UserImpl.ACCESSORS.values().iterator(); i.hasNext();)
+ for (Iterator i = HibernateUserImpl.ACCESSORS.values().iterator(); i.hasNext();)
{
- UserImpl.PropertyAccessor accessor = (UserImpl.PropertyAccessor)i.next();
+ HibernateUserImpl.PropertyAccessor accessor =
(HibernateUserImpl.PropertyAccessor)i.next();
Object value2 = accessor.get(user);
if (value == value2 || value.equals(value2))
{
@@ -131,7 +130,7 @@
{
throw new ClassCastException("Key must be a string");
}
- UserImpl.PropertyAccessor accessor =
(UserImpl.PropertyAccessor)UserImpl.ACCESSORS.get(key);
+ HibernateUserImpl.PropertyAccessor accessor =
(HibernateUserImpl.PropertyAccessor)HibernateUserImpl.ACCESSORS.get(key);
if (accessor != null)
{
return accessor.get(user);
@@ -158,7 +157,7 @@
{
throw new ClassCastException("Key is not a String");
}
- UserImpl.PropertyAccessor accessor =
(UserImpl.PropertyAccessor)UserImpl.ACCESSORS.get(key);
+ HibernateUserImpl.PropertyAccessor accessor =
(HibernateUserImpl.PropertyAccessor)HibernateUserImpl.ACCESSORS.get(key);
if (accessor != null)
{
if (newValue == null && !accessor.isNullable())
@@ -194,7 +193,7 @@
{
throw new ClassCastException("Key is not a String");
}
- UserImpl.PropertyAccessor accessor =
(UserImpl.PropertyAccessor)UserImpl.ACCESSORS.get(key);
+ HibernateUserImpl.PropertyAccessor accessor =
(HibernateUserImpl.PropertyAccessor)HibernateUserImpl.ACCESSORS.get(key);
if (accessor != null)
{
throw new IllegalArgumentException("Key " + key + " is not
removable");
@@ -215,16 +214,16 @@
//
set.addAll(user.getDynamic().keySet());
- set.addAll(UserImpl.ACCESSORS.keySet());
+ set.addAll(HibernateUserImpl.ACCESSORS.keySet());
return set;
}
public Collection values()
{
ArrayList collection = new ArrayList(size());
- for (Iterator i = UserImpl.ACCESSORS.values().iterator(); i.hasNext();)
+ for (Iterator i = HibernateUserImpl.ACCESSORS.values().iterator(); i.hasNext();)
{
- UserImpl.PropertyAccessor accessor = (UserImpl.PropertyAccessor)i.next();
+ HibernateUserImpl.PropertyAccessor accessor =
(HibernateUserImpl.PropertyAccessor)i.next();
collection.add(accessor.get(user));
}
collection.addAll(user.getDynamic().values());
@@ -235,9 +234,9 @@
public Set entrySet()
{
Map copy = new HashMap(user.getDynamic());
- for (Iterator i = UserImpl.ACCESSORS.values().iterator(); i.hasNext();)
+ for (Iterator i = HibernateUserImpl.ACCESSORS.values().iterator(); i.hasNext();)
{
- UserImpl.PropertyAccessor accessor = (UserImpl.PropertyAccessor)i.next();
+ HibernateUserImpl.PropertyAccessor accessor =
(HibernateUserImpl.PropertyAccessor)i.next();
copy.put(accessor.getPropertyName(), accessor.get(user));
}
return Collections.unmodifiableMap(copy).entrySet();
@@ -248,12 +247,12 @@
// todo : check all properties ok with changes before proceeding
for (Iterator i = map.entrySet().iterator(); i.hasNext();)
{
- Map.Entry entry = (Map.Entry)i.next();
+ Entry entry = (Entry)i.next();
Object key = entry.getKey();
if (key instanceof String)
{
Object value = entry.getValue();
- UserImpl.PropertyAccessor accessor =
(UserImpl.PropertyAccessor)UserImpl.ACCESSORS.get(key);
+ HibernateUserImpl.PropertyAccessor accessor =
(HibernateUserImpl.PropertyAccessor)HibernateUserImpl.ACCESSORS.get(key);
if (accessor != null)
{
if (accessor.isWritable())
Deleted: trunk/identity/src/main/org/jboss/portal/identity/db/RoleImpl.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity/db/RoleImpl.java 2006-12-17 14:45:10
UTC (rev 5884)
+++ trunk/identity/src/main/org/jboss/portal/identity/db/RoleImpl.java 2006-12-17 14:52:15
UTC (rev 5885)
@@ -1,149 +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.legacy_identity.db;
-
-import org.jboss.portal.legacy_identity.Role;
-
-import java.util.HashSet;
-import java.util.Set;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet </a>
- * @author <a href="mailto:theute@jboss.org">Thomas Heute </a>
- * @author Roy Russo : roy at jboss dot org
- * @version $Revision$
- */
-public class RoleImpl
- implements Role
-{
-
- private Long key;
- private String name;
- private Set users;
- private String displayName;
-
- /**
- *
- */
- public RoleImpl()
- {
- this.key = null;
- this.name = null;
- this.displayName = null;
- this.users = new HashSet();
- }
-
- /**
- *
- */
- public RoleImpl(String name)
- {
- this.key = null;
- this.name = name;
- this.displayName = name;
- this.users = new HashSet();
- }
-
- /**
- *
- */
- public RoleImpl(String name, String displayName)
- {
- this.key = null;
- this.name = name;
- this.displayName = displayName;
- this.users = new HashSet();
- }
-
- /**
- * @hibernate.id column="jbp_rid" generator-class="native"
- * <p/>
- * 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 + "]";
- }
-}
Deleted: trunk/identity/src/main/org/jboss/portal/identity/db/UserImpl.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity/db/UserImpl.java 2006-12-17 14:45:10
UTC (rev 5884)
+++ trunk/identity/src/main/org/jboss/portal/identity/db/UserImpl.java 2006-12-17 14:52:15
UTC (rev 5885)
@@ -1,661 +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.legacy_identity.db;
-
-import org.apache.log4j.Logger;
-import org.jboss.portal.common.p3p.P3PConstants;
-import org.jboss.portal.common.util.LocaleInfo;
-import org.jboss.portal.common.util.Tools;
-import org.jboss.portal.legacy_identity.ProfileMap;
-import org.jboss.portal.legacy_identity.Role;
-import org.jboss.portal.legacy_identity.User;
-
-import java.lang.reflect.Field;
-import java.text.DateFormat;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Collections;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Locale;
-import java.util.Map;
-import java.util.Set;
-
-/**
- * User interface implementation.
- *
- * @author <a href="mailto:julien@jboss.org">Julien Viet </a>
- * @author <a href="mailto:theute@jboss.org">Thomas Heute </a>
- * @author <a href="mailto:mageshbk@jboss.com">Magesh Kumar Bojan
</a>
- * @version $Revision$
- */
-public class UserImpl
- implements User
-{
-
- private static final Logger log = Logger.getLogger(UserImpl.class);
-
- static final Map ACCESSORS = UserImpl.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
StringPropertyAccessor(P3PConstants.INFO_USER_NAME_NICKNAME, "userName", false,
false));
- map.put(P3PConstants.INFO_USER_BUSINESS_INFO_ONLINE_EMAIL, new
StringPropertyAccessor(P3PConstants.INFO_USER_BUSINESS_INFO_ONLINE_EMAIL,
"realEmail", true, true));
- map.put(P3PConstants.INFO_USER_NAME_GIVEN, new
StringPropertyAccessor(P3PConstants.INFO_USER_NAME_GIVEN, "givenName", true,
true));
- map.put(P3PConstants.INFO_USER_NAME_FAMILY, new
StringPropertyAccessor(P3PConstants.INFO_USER_NAME_FAMILY, "familyName", true,
true));
-
- // Map attributes specific to JBoss Portal
- map.put(User.INFO_USER_EMAIL_FAKE, new
StringPropertyAccessor(User.INFO_USER_EMAIL_FAKE, "fakeEmail", true, true));
- map.put(User.INFO_USER_REGISTRATION_DATE, new
DatePropertyAccessor(User.INFO_USER_REGISTRATION_DATE, "registrationDate",
false, false));
- map.put(User.INFO_USER_VIEW_EMAIL_VIEW_REAL, new
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 UserImpl()
- {
- this.key = null;
- this.userName = null;
- this.dynamic = null;
- this.profile = new ProfileMapImpl(this);
- this.roles = null;
- this.registrationDate = null;
- this.enabled = false;
- }
-
- /**
- *
- */
- public UserImpl(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)
- {
- UserImpl.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 = UserImpl.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 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 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 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)UserImpl.DatePropertyAccessor.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)UserImpl.DatePropertyAccessor.formatLocal.get();
- return format.format(date);
- }
- }
-}
Copied: trunk/identity/src/main/org/jboss/portal/identity/experimental/db (from rev 5871,
trunk/identity/src/main/org/jboss/portal/identity2/experimental/db)
Deleted:
trunk/identity/src/main/org/jboss/portal/identity/experimental/db/HibernateHelper.java
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/experimental/db/HibernateHelper.java 2006-12-15
15:15:26 UTC (rev 5871)
+++
trunk/identity/src/main/org/jboss/portal/identity/experimental/db/HibernateHelper.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -1,143 +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.experimental.db;
-
-import org.jboss.portal.identity2.info.ProfileInfo;
-import org.jboss.portal.identity2.info.PropertyInfo;
-import org.jboss.portal.identity.IdentityException;
-
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.FileOutputStream;
-import java.io.LineNumberReader;
-import java.io.InputStreamReader;
-import java.io.PrintWriter;
-import java.io.OutputStreamWriter;
-import java.io.File;
-import java.util.regex.Pattern;
-import java.util.regex.Matcher;
-import java.util.Map;
-import java.util.Iterator;
-
-/**
- * @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw
Dawidowicz</a>
- * @version $Revision: 1.1 $
- */
-public abstract class HibernateHelper
-{
- private static final org.jboss.logging.Logger log =
org.jboss.logging.Logger.getLogger(HibernateHelper.class);
-
-
- public static synchronized String generateProfileMappings(String template, String
output, String mappingPattern, ProfileInfo info, ClassLoader tcl) throws Exception
- {
- //InputStream profileIS;
- InputStream templateIS;
- OutputStream mappingOS;
- File of = null;
-
- try
- {
- templateIS = tcl.getResourceAsStream(template);
- }
- catch (Exception e)
- {
- throw new IdentityException("Cannot open mapping template resource: "
+ template, e);
- }
-
- try
- {
- of = new File(output);
- if (!of.exists())
- {
- log.info("creating new file");
- of.createNewFile();
- }
- log.info("Generating identity hibernate mappings file to: " +
of.getAbsolutePath());
- mappingOS = new FileOutputStream(of, false);
- }
- catch (Exception e)
- {
- throw new IdentityException("Cannot open mapping file for write",e);
- }
-
- if (output == null)
- {
- throw new IdentityException("Mapping Pattern not specified");
- }
-
-
-
- //process template
- LineNumberReader templateReader = new LineNumberReader(new
InputStreamReader(templateIS));
- PrintWriter mappingWriter = new PrintWriter(new OutputStreamWriter(mappingOS));
-
- Pattern pattern = Pattern.compile(".*@mappings@.*");
-
-
- String line;
-
- while ((line = templateReader.readLine()) != null)
- {
- Matcher matcher = pattern.matcher(line);
- if (matcher.matches())
- {
- if (log.isDebugEnabled())
- {
- log.debug("Found @mappings@ tag at line: " +
templateReader.getLineNumber());
- }
-
- line = generateColumns(info, mappingPattern);
- if (log.isDebugEnabled())
- {
- log.debug("Generated mappings: " + line);
- }
- }
- mappingWriter.println(line);
- }
- templateReader.close();
- mappingWriter.close();
- return of.getAbsolutePath();
- }
-
- private static String generateColumns(ProfileInfo info, String pattern)
- {
- StringBuffer columns = new StringBuffer();
-
- Map properties = info.getPropertiesInfo();
- for (Iterator iterator = properties.keySet().iterator(); iterator.hasNext();)
- {
- String key = (String)iterator.next();
- PropertyInfo property = (PropertyInfo)properties.get(key);
-
- if (property.isMappedDB() &&
property.getMappingDBType().equals(PropertyInfo.MAPPING_DB_TYPE_COLUMN))
- {
- String mapping = pattern.replaceFirst("@name@",
property.getName()).replaceFirst("@column@", property.getMappingDBValue());
- columns.append(mapping);
- columns.append('\n');
- }
-
- }
- return columns.toString();
-
- }
-
-}
Copied:
trunk/identity/src/main/org/jboss/portal/identity/experimental/db/HibernateHelper.java
(from rev 5883,
trunk/identity/src/main/org/jboss/portal/identity2/experimental/db/HibernateHelper.java)
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/experimental/db/HibernateHelper.java 2006-12-17
14:26:07 UTC (rev 5883)
+++
trunk/identity/src/main/org/jboss/portal/identity/experimental/db/HibernateHelper.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -0,0 +1,143 @@
+/*
+* 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.identity.experimental.db;
+
+import org.jboss.portal.identity.info.ProfileInfo;
+import org.jboss.portal.identity.info.PropertyInfo;
+import org.jboss.portal.identity.IdentityException;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.FileOutputStream;
+import java.io.LineNumberReader;
+import java.io.InputStreamReader;
+import java.io.PrintWriter;
+import java.io.OutputStreamWriter;
+import java.io.File;
+import java.util.regex.Pattern;
+import java.util.regex.Matcher;
+import java.util.Map;
+import java.util.Iterator;
+
+/**
+ * @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw
Dawidowicz</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class HibernateHelper
+{
+// private static final org.jboss.logging.Logger log =
org.jboss.logging.Logger.getLogger(HibernateHelper.class);
+//
+//
+// public static synchronized String generateProfileMappings(String template, String
output, String mappingPattern, ProfileInfo info, ClassLoader tcl) throws Exception
+// {
+// //InputStream profileIS;
+// InputStream templateIS;
+// OutputStream mappingOS;
+// File of = null;
+//
+// try
+// {
+// templateIS = tcl.getResourceAsStream(template);
+// }
+// catch (Exception e)
+// {
+// throw new IdentityException("Cannot open mapping template resource:
" + template, e);
+// }
+//
+// try
+// {
+// of = new File(output);
+// if (!of.exists())
+// {
+// log.info("creating new file");
+// of.createNewFile();
+// }
+// log.info("Generating identity hibernate mappings file to: " +
of.getAbsolutePath());
+// mappingOS = new FileOutputStream(of, false);
+// }
+// catch (Exception e)
+// {
+// throw new IdentityException("Cannot open mapping file for
write",e);
+// }
+//
+// if (output == null)
+// {
+// throw new IdentityException("Mapping Pattern not specified");
+// }
+//
+//
+//
+// //process template
+// LineNumberReader templateReader = new LineNumberReader(new
InputStreamReader(templateIS));
+// PrintWriter mappingWriter = new PrintWriter(new OutputStreamWriter(mappingOS));
+//
+// Pattern pattern = Pattern.compile(".*@mappings@.*");
+//
+//
+// String line;
+//
+// while ((line = templateReader.readLine()) != null)
+// {
+// Matcher matcher = pattern.matcher(line);
+// if (matcher.matches())
+// {
+// if (log.isDebugEnabled())
+// {
+// log.debug("Found @mappings@ tag at line: " +
templateReader.getLineNumber());
+// }
+//
+// line = generateColumns(info, mappingPattern);
+// if (log.isDebugEnabled())
+// {
+// log.debug("Generated mappings: " + line);
+// }
+// }
+// mappingWriter.println(line);
+// }
+// templateReader.close();
+// mappingWriter.close();
+// return of.getAbsolutePath();
+// }
+//
+// private static String generateColumns(ProfileInfo info, String pattern)
+// {
+// StringBuffer columns = new StringBuffer();
+//
+// Map properties = info.getPropertiesInfo();
+// for (Iterator iterator = properties.keySet().iterator(); iterator.hasNext();)
+// {
+// String key = (String)iterator.next();
+// PropertyInfo property = (PropertyInfo)properties.get(key);
+//
+// if (property.isMappedDB() &&
property.getMappingDBType().equals(PropertyInfo.MAPPING_DB_TYPE_COLUMN))
+// {
+// String mapping = pattern.replaceFirst("@name@",
property.getName()).replaceFirst("@column@", property.getMappingDBValue());
+// columns.append(mapping);
+// columns.append('\n');
+// }
+//
+// }
+// return columns.toString();
+//
+// }
+
+}
Deleted:
trunk/identity/src/main/org/jboss/portal/identity/experimental/db/HibernateMembershipModuleImpl.java
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/experimental/db/HibernateMembershipModuleImpl.java 2006-12-15
15:15:26 UTC (rev 5871)
+++
trunk/identity/src/main/org/jboss/portal/identity/experimental/db/HibernateMembershipModuleImpl.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -1,267 +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.experimental.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 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.util.Set;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Map;
-
-/**
- * @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw
Dawidowicz</a>
- * @version $Revision: 1.1 $
- */
-public class HibernateMembershipModuleImpl extends MembershipModuleService
-{
- /** . */
- private static final org.jboss.logging.Logger log =
org.jboss.logging.Logger.getLogger(HibernateMembershipModuleImpl.class);
- /** . */
- protected SessionFactory sessionFactory;
-
- /** . */
- protected String sessionFactoryJNDIName;
-
- protected void startService() throws Exception
- {
- //
- sessionFactory = (SessionFactory)new
InitialContext().lookup(sessionFactoryJNDIName);
-
- super.startService();
- }
-
- protected void stopService() throws Exception
- {
-
- //
- sessionFactory = null;
-
- super.stopService();
- }
-
-// public SessionFactory getSessionFactory()
-// {
-// return sessionFactory;
-// }
-
- public String getSessionFactoryJNDIName()
- {
- return sessionFactoryJNDIName;
- }
-
- public void setSessionFactoryJNDIName(String sessionFactoryJNDIName)
- {
- this.sessionFactoryJNDIName = sessionFactoryJNDIName;
- }
-
- public Set getRoles(User user) throws IdentityException
- {
- //throw new UnsupportedOperationException("Not yet implemented");
- if (!(user instanceof HibernateUserImpl))
- {
- throw new IllegalArgumentException("User is not a HibernateUserImpl
user");
- }
-
- // We return an immutable set to avoid modifications
- HibernateUserImpl ui = (HibernateUserImpl)user;
- Set roles = ui.getRoleMapsSet();
- Set wrappers = new HashSet();
- for (Iterator iterator = roles.iterator(); iterator.hasNext();)
- {
- Map map = (Map)iterator.next();
- wrappers.add(new HibernateRoleImpl(getSessionFactory(), map));
- }
-
- return wrappers;
- }
-
- public Set getUsers(Role role) throws IdentityException
- {
- if (!(role instanceof HibernateRoleImpl))
- {
- throw new IllegalArgumentException("User is not a HibernateRoleImpl
user");
- }
-
- // We return an immutable set to avoid modifications
- HibernateRoleImpl ri = (HibernateRoleImpl)role;
- Set users = ri.getUserMapsSet();
- Set wrappers = new HashSet();
- for (Iterator iterator = users.iterator(); iterator.hasNext();)
- {
- Map map = (Map)iterator.next();
- wrappers.add(new HibernateUserImpl(getSessionFactory(), map));
- }
-
- return wrappers;
- }
-
- public void assignUsers(Role role, Set users) throws IdentityException
- {
- //throw new UnsupportedOperationException("Not yet implemented");
- if (!(role instanceof HibernateRoleImpl))
- {
- throw new IllegalArgumentException("User is not a HibernateRoleImpl
user");
- }
-
- for (Iterator i = users.iterator(); i.hasNext();)
- {
- Object o = i.next();
- if (o instanceof HibernateUserImpl)
- {
- ((HibernateUserImpl)o).addRole(((HibernateRoleImpl)role).getCurrentMap());
- }
- else
- {
- throw new IllegalArgumentException("Only HibernateUserImpl roles can be
accepted");
- }
- }
-
- }
-
- public void assignRoles(User user, Set roles) throws IdentityException
- {
- //throw new UnsupportedOperationException("Not yet implemented");
- if (!(user instanceof HibernateUserImpl))
- {
- throw new IllegalArgumentException("User is not a HibernateUserImpl
user");
- }
-
- // We make a defensive copy with unwrapped maps and update with a new set
- Set copy = new HashSet();
- for (Iterator i = roles.iterator(); i.hasNext();)
- {
- Object o = i.next();
- if (o instanceof HibernateRoleImpl)
- {
- copy.add(((HibernateRoleImpl)o).getCurrentMap());
- }
- else
- {
- throw new IllegalArgumentException("Only HibernateRoleImpl roles can be
accepted");
- }
- }
-
- // Assign new roles
- HibernateUserImpl ui = (HibernateUserImpl)user;
- ui.setRoles(copy);
- }
-
- //TODO:
- public Set findRoleMembers(String roleName, int offset, int limit, String
userNameFilter) throws IdentityException
- {
- if (roleName != null)
- {
- try
- {
- Session session = getCurrentSession();
-
- Query query;
- if (userNameFilter.trim().length() != 0)
- {
- //
- userNameFilter = "%" + userNameFilter.replaceAll("%",
"") + "%";
-
- //
- query = session.createQuery("from PortalUser 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 PortalUser 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 = processRolesSet(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");
- }
- }
-
- /**
- * Process Set of Map objects and returns a Set of HibernateRoleImpl objects
- * @param maps
- * @return
- * @throws Exception
- */
- private Set processRolesSet(Set maps) throws IdentityException
- {
- Set roles = new HashSet();
- for (Iterator iterator1 = maps.iterator(); iterator1.hasNext();)
- {
- Map roleMap = (Map)iterator1.next();
- roles.add(new HibernateRoleImpl(getSessionFactory(),roleMap));
- }
- return roles;
- }
-
- /**
- * Can be subclasses to provide testing in a non JTA environement.
- *
- * @throws IllegalStateException if no session factory is present
- */
- protected Session getCurrentSession() throws IllegalStateException
- {
- return getSessionFactory().getCurrentSession();//.getSession(EntityMode.MAP);
-
- }
-
- protected SessionFactory getSessionFactory() throws IllegalStateException
- {
- if (sessionFactory == null)
- {
- throw new IllegalStateException("No session factory");
- }
- return sessionFactory;//.getCurrentSession();
- }
-}
Copied:
trunk/identity/src/main/org/jboss/portal/identity/experimental/db/HibernateMembershipModuleImpl.java
(from rev 5883,
trunk/identity/src/main/org/jboss/portal/identity2/experimental/db/HibernateMembershipModuleImpl.java)
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/experimental/db/HibernateMembershipModuleImpl.java 2006-12-17
14:26:07 UTC (rev 5883)
+++
trunk/identity/src/main/org/jboss/portal/identity/experimental/db/HibernateMembershipModuleImpl.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -0,0 +1,267 @@
+/*
+* 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.identity.experimental.db;
+
+import org.jboss.portal.identity.service.MembershipModuleService;
+import org.jboss.portal.identity.User;
+import org.jboss.portal.identity.Role;
+import org.jboss.portal.identity.IdentityException;
+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.util.Set;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw
Dawidowicz</a>
+ * @version $Revision: 1.1 $
+ */
+public class HibernateMembershipModuleImpl //extends MembershipModuleService
+{
+// /** . */
+// private static final org.jboss.logging.Logger log =
org.jboss.logging.Logger.getLogger(HibernateMembershipModuleImpl.class);
+// /** . */
+// protected SessionFactory sessionFactory;
+//
+// /** . */
+// protected String sessionFactoryJNDIName;
+//
+// protected void startService() throws Exception
+// {
+// //
+// sessionFactory = (SessionFactory)new
InitialContext().lookup(sessionFactoryJNDIName);
+//
+// super.startService();
+// }
+//
+// protected void stopService() throws Exception
+// {
+//
+// //
+// sessionFactory = null;
+//
+// super.stopService();
+// }
+//
+//// public SessionFactory getSessionFactory()
+//// {
+//// return sessionFactory;
+//// }
+//
+// public String getSessionFactoryJNDIName()
+// {
+// return sessionFactoryJNDIName;
+// }
+//
+// public void setSessionFactoryJNDIName(String sessionFactoryJNDIName)
+// {
+// this.sessionFactoryJNDIName = sessionFactoryJNDIName;
+// }
+//
+// public Set getRoles(User user) throws IdentityException
+// {
+// //throw new UnsupportedOperationException("Not yet implemented");
+// if (!(user instanceof HibernateUserImpl))
+// {
+// throw new IllegalArgumentException("User is not a HibernateUserImpl
user");
+// }
+//
+// // We return an immutable set to avoid modifications
+// HibernateUserImpl ui = (HibernateUserImpl)user;
+// Set roles = ui.getRoleMapsSet();
+// Set wrappers = new HashSet();
+// for (Iterator iterator = roles.iterator(); iterator.hasNext();)
+// {
+// Map map = (Map)iterator.next();
+// wrappers.add(new HibernateRoleImpl(getSessionFactory(), map));
+// }
+//
+// return wrappers;
+// }
+//
+// public Set getUsers(Role role) throws IdentityException
+// {
+// if (!(role instanceof HibernateRoleImpl))
+// {
+// throw new IllegalArgumentException("User is not a HibernateRoleImpl
user");
+// }
+//
+// // We return an immutable set to avoid modifications
+// HibernateRoleImpl ri = (HibernateRoleImpl)role;
+// Set users = ri.getUserMapsSet();
+// Set wrappers = new HashSet();
+// for (Iterator iterator = users.iterator(); iterator.hasNext();)
+// {
+// Map map = (Map)iterator.next();
+// wrappers.add(new HibernateUserImpl(getSessionFactory(), map));
+// }
+//
+// return wrappers;
+// }
+//
+// public void assignUsers(Role role, Set users) throws IdentityException
+// {
+// //throw new UnsupportedOperationException("Not yet implemented");
+// if (!(role instanceof HibernateRoleImpl))
+// {
+// throw new IllegalArgumentException("User is not a HibernateRoleImpl
user");
+// }
+//
+// for (Iterator i = users.iterator(); i.hasNext();)
+// {
+// Object o = i.next();
+// if (o instanceof HibernateUserImpl)
+// {
+// ((HibernateUserImpl)o).addRole(((HibernateRoleImpl)role).getCurrentMap());
+// }
+// else
+// {
+// throw new IllegalArgumentException("Only HibernateUserImpl roles can
be accepted");
+// }
+// }
+//
+// }
+//
+// public void assignRoles(User user, Set roles) throws IdentityException
+// {
+// //throw new UnsupportedOperationException("Not yet implemented");
+// if (!(user instanceof HibernateUserImpl))
+// {
+// throw new IllegalArgumentException("User is not a HibernateUserImpl
user");
+// }
+//
+// // We make a defensive copy with unwrapped maps and update with a new set
+// Set copy = new HashSet();
+// for (Iterator i = roles.iterator(); i.hasNext();)
+// {
+// Object o = i.next();
+// if (o instanceof HibernateRoleImpl)
+// {
+// copy.add(((HibernateRoleImpl)o).getCurrentMap());
+// }
+// else
+// {
+// throw new IllegalArgumentException("Only HibernateRoleImpl roles can
be accepted");
+// }
+// }
+//
+// // Assign new roles
+// HibernateUserImpl ui = (HibernateUserImpl)user;
+// ui.setRoles(copy);
+// }
+//
+// //TODO:
+// public Set findRoleMembers(String roleName, int offset, int limit, String
userNameFilter) throws IdentityException
+// {
+// if (roleName != null)
+// {
+// try
+// {
+// Session session = getCurrentSession();
+//
+// Query query;
+// if (userNameFilter.trim().length() != 0)
+// {
+// //
+// userNameFilter = "%" +
userNameFilter.replaceAll("%", "") + "%";
+//
+// //
+// query = session.createQuery("from PortalUser 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 PortalUser 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 = processRolesSet(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");
+// }
+// }
+//
+// /**
+// * Process Set of Map objects and returns a Set of HibernateRoleImpl objects
+// * @param maps
+// * @return
+// * @throws Exception
+// */
+// private Set processRolesSet(Set maps) throws IdentityException
+// {
+// Set roles = new HashSet();
+// for (Iterator iterator1 = maps.iterator(); iterator1.hasNext();)
+// {
+// Map roleMap = (Map)iterator1.next();
+// roles.add(new HibernateRoleImpl(getSessionFactory(),roleMap));
+// }
+// return roles;
+// }
+//
+// /**
+// * Can be subclasses to provide testing in a non JTA environement.
+// *
+// * @throws IllegalStateException if no session factory is present
+// */
+// protected Session getCurrentSession() throws IllegalStateException
+// {
+// return getSessionFactory().getCurrentSession();//.getSession(EntityMode.MAP);
+//
+// }
+//
+// protected SessionFactory getSessionFactory() throws IllegalStateException
+// {
+// if (sessionFactory == null)
+// {
+// throw new IllegalStateException("No session factory");
+// }
+// return sessionFactory;//.getCurrentSession();
+// }
+}
Deleted:
trunk/identity/src/main/org/jboss/portal/identity/experimental/db/HibernateRoleImpl.java
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/experimental/db/HibernateRoleImpl.java 2006-12-15
15:15:26 UTC (rev 5871)
+++
trunk/identity/src/main/org/jboss/portal/identity/experimental/db/HibernateRoleImpl.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -1,206 +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.experimental.db;
-
-import org.jboss.portal.identity2.Role;
-import org.jboss.portal.identity.IdentityException;
-import org.hibernate.SessionFactory;
-import org.hibernate.Session;
-import org.hibernate.EntityMode;
-
-import java.util.Set;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Collections;
-
-/**
- * @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw
Dawidowicz</a>
- * @version $Revision: 5448 $
- */
-public class HibernateRoleImpl
- implements Role
-{
-
- public static final String ENTITY_NAME = "PortalRole";
- public static final String MAPPING_ID = "key";
- public static final String MAPPING_NAME = "name";
- public static final String MAPPING_DISPLAY_NAME = "displayName";
- public static final String MAPPING_USERS = "users";
-
- private SessionFactory sessionFactory;
-
- private Map currentMap;
-
- /*
- * Transient fields.
- */
-
- private HibernateRoleImpl()
- {
-
- }
-
- /**
- * Initializes Hibernate role object. initialContent map should be already persisted
in hibernate Session
- * @param sf
- * @param initialContent
- * @throws IdentityException
- */
- public HibernateRoleImpl(SessionFactory sf, Map initialContent) throws
IdentityException
- {
- if (sf == null)
- {
- throw new IdentityException("SessionFactory is null");
- }
- if (initialContent == null)
- {
- throw new IdentityException("Map is null");
- }
- this.sessionFactory = sf;
- this.currentMap = initialContent;
- //persist();
- }
-
- // ***
- //
- // API
- //
- // ***
-
- public Object getId()
- {
- return getCurrentMap().get(MAPPING_ID);
- }
-
- public String getName()
- {
- return (String)getCurrentMap().get(MAPPING_NAME);
- }
-
- public String getDisplayName()
- {
- return (String)getCurrentMap().get(MAPPING_DISPLAY_NAME);
- }
-
- public void setDisplayName(String name)
- {
- if (name == null)
- {
- throw new IllegalArgumentException("name is null");
- }
- getCurrentMap().put(MAPPING_DISPLAY_NAME, name);
- persist();
- }
-
- //users
- public Set getUserMapsSet()
- {
- return Collections.unmodifiableSet(getUsersSet());
- }
-
- public void setUsers(Set users)
- {
- if (users == null)
- {
- throw new IllegalArgumentException("users set is null");
- }
- getCurrentMap().put(MAPPING_USERS, users);
- }
-
- // ***
- //
- // SPI
- //
-
- // ***
-
- public void setName(String name, String value)
- {
- if (name == null)
- {
- throw new IllegalArgumentException("name is null");
- }
- getCurrentMap().put(name, value);
- persist();
- }
-
- public Map getCurrentMap()
- {
- return currentMap;
- }
-
- // ********
- //
- // Internal
- //
- // ********
- protected SessionFactory getSessionFactory()
- {
- return sessionFactory;
- }
-
- protected void setSessionFactory(SessionFactory sessionFactory)
- {
- this.sessionFactory = sessionFactory;
- }
-
- protected void setCurrentMap(Map currentMap)
- {
- this.currentMap = currentMap;
- }
-
- protected Set getUsersSet()
- {
- Set users = (Set)getCurrentMap().get(MAPPING_USERS);
- if (users == null)
- {
- users = new HashSet();
- getCurrentMap().put(MAPPING_USERS, users);
- }
- return users;
- }
-
- protected void persist()
- {
- getCurrentSession().save(ENTITY_NAME, currentMap);
- }
-
-
- public String toString()
- {
- return "Role[" + getId() + "," + getName() + "]";
- }
-
- /**
- * 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().getSession(EntityMode.MAP);
- }
-}
-
-
Copied:
trunk/identity/src/main/org/jboss/portal/identity/experimental/db/HibernateRoleImpl.java
(from rev 5883,
trunk/identity/src/main/org/jboss/portal/identity2/experimental/db/HibernateRoleImpl.java)
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/experimental/db/HibernateRoleImpl.java 2006-12-17
14:26:07 UTC (rev 5883)
+++
trunk/identity/src/main/org/jboss/portal/identity/experimental/db/HibernateRoleImpl.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -0,0 +1,205 @@
+/*
+* 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.identity.experimental.db;
+
+import org.jboss.portal.identity.Role;
+import org.jboss.portal.identity.IdentityException;
+import org.hibernate.SessionFactory;
+import org.hibernate.Session;
+import org.hibernate.EntityMode;
+
+import java.util.Set;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Collections;
+
+/**
+ * @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw
Dawidowicz</a>
+ * @version $Revision: 5448 $
+ */
+public class HibernateRoleImpl //implements Role
+{
+
+// public static final String ENTITY_NAME = "PortalRole";
+// public static final String MAPPING_ID = "key";
+// public static final String MAPPING_NAME = "name";
+// public static final String MAPPING_DISPLAY_NAME = "displayName";
+// public static final String MAPPING_USERS = "users";
+//
+// private SessionFactory sessionFactory;
+//
+// private Map currentMap;
+//
+// /*
+// * Transient fields.
+// */
+//
+// private HibernateRoleImpl()
+// {
+//
+// }
+//
+// /**
+// * Initializes Hibernate role object. initialContent map should be already persisted
in hibernate Session
+// * @param sf
+// * @param initialContent
+// * @throws IdentityException
+// */
+// public HibernateRoleImpl(SessionFactory sf, Map initialContent) throws
IdentityException
+// {
+// if (sf == null)
+// {
+// throw new IdentityException("SessionFactory is null");
+// }
+// if (initialContent == null)
+// {
+// throw new IdentityException("Map is null");
+// }
+// this.sessionFactory = sf;
+// this.currentMap = initialContent;
+// //persist();
+// }
+//
+// // ***
+// //
+// // API
+// //
+// // ***
+//
+// public Object getId()
+// {
+// return getCurrentMap().get(MAPPING_ID);
+// }
+//
+// public String getName()
+// {
+// return (String)getCurrentMap().get(MAPPING_NAME);
+// }
+//
+// public String getDisplayName()
+// {
+// return (String)getCurrentMap().get(MAPPING_DISPLAY_NAME);
+// }
+//
+// public void setDisplayName(String name)
+// {
+// if (name == null)
+// {
+// throw new IllegalArgumentException("name is null");
+// }
+// getCurrentMap().put(MAPPING_DISPLAY_NAME, name);
+// persist();
+// }
+//
+// //users
+// public Set getUserMapsSet()
+// {
+// return Collections.unmodifiableSet(getUsersSet());
+// }
+//
+// public void setUsers(Set users)
+// {
+// if (users == null)
+// {
+// throw new IllegalArgumentException("users set is null");
+// }
+// getCurrentMap().put(MAPPING_USERS, users);
+// }
+//
+// // ***
+// //
+// // SPI
+// //
+//
+// // ***
+//
+// public void setName(String name, String value)
+// {
+// if (name == null)
+// {
+// throw new IllegalArgumentException("name is null");
+// }
+// getCurrentMap().put(name, value);
+// persist();
+// }
+//
+// public Map getCurrentMap()
+// {
+// return currentMap;
+// }
+//
+// // ********
+// //
+// // Internal
+// //
+// // ********
+// protected SessionFactory getSessionFactory()
+// {
+// return sessionFactory;
+// }
+//
+// protected void setSessionFactory(SessionFactory sessionFactory)
+// {
+// this.sessionFactory = sessionFactory;
+// }
+//
+// protected void setCurrentMap(Map currentMap)
+// {
+// this.currentMap = currentMap;
+// }
+//
+// protected Set getUsersSet()
+// {
+// Set users = (Set)getCurrentMap().get(MAPPING_USERS);
+// if (users == null)
+// {
+// users = new HashSet();
+// getCurrentMap().put(MAPPING_USERS, users);
+// }
+// return users;
+// }
+//
+// protected void persist()
+// {
+// getCurrentSession().save(ENTITY_NAME, currentMap);
+// }
+//
+//
+// public String toString()
+// {
+// return "Role[" + getId() + "," + getName() + "]";
+// }
+//
+// /**
+// * 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().getSession(EntityMode.MAP);
+// }
+}
+
+
Deleted:
trunk/identity/src/main/org/jboss/portal/identity/experimental/db/HibernateRoleModuleImpl.java
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/experimental/db/HibernateRoleModuleImpl.java 2006-12-15
15:15:26 UTC (rev 5871)
+++
trunk/identity/src/main/org/jboss/portal/identity/experimental/db/HibernateRoleModuleImpl.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -1,459 +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.experimental.db;
-
-import org.hibernate.SessionFactory;
-import org.hibernate.Criteria;
-import org.hibernate.Session;
-import org.hibernate.Query;
-import org.hibernate.HibernateException;
-import org.hibernate.criterion.Restrictions;
-import org.jboss.portal.identity.IdentityException;
-import org.jboss.portal.identity2.Role;
-import org.jboss.portal.identity2.service.RoleModuleService;
-import org.jboss.portal.common.util.Tools;
-
-import javax.naming.InitialContext;
-import java.util.Set;
-import java.util.Iterator;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.HashMap;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet </a>
- * @author <a href="mailto:theute@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(HibernateRoleModuleImpl.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
- {
- //throw new UnsupportedOperationException("Not yet implemented");
- if (name != null)
- {
- try
- {
- Session session = getCurrentSession();
- Criteria criteria = session.createCriteria(HibernateRoleImpl.ENTITY_NAME);
- criteria.add(Restrictions.naturalId().set("name", name));
- criteria.setCacheable(true);
- Map roleMap = (Map)criteria.uniqueResult();
- if (roleMap == null)
- {
- throw new IdentityException("No such role " + name);
- }
- return new HibernateRoleImpl(getSessionFactory(), roleMap);
- }
- 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
- {
- //throw new UnsupportedOperationException("Not yet implemented");
- if (names != null)
- {
- try
- {
- Session session = getCurrentSession();
- StringBuffer queryString = new StringBuffer("from PortalRole 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 processRolesSet(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
- {
- //throw new UnsupportedOperationException("Not yet implemented");
- 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
- {
- //throw new UnsupportedOperationException("Not yet implemented");
- if (id instanceof Long)
- {
- try
- {
- Session session = getCurrentSession();
- Map roleMap = (Map)session.get(HibernateRoleImpl.ENTITY_NAME, (Long)id);
- if (roleMap == null)
- {
- throw new IdentityException("No role found for " + id);
- }
- return new HibernateRoleImpl(getSessionFactory(),roleMap);
- }
- 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
- {
- //throw new UnsupportedOperationException("Not yet implemented");
- if (name != null)
- {
- try
- {
- Map roleMap = new HashMap();
- roleMap.put(HibernateRoleImpl.MAPPING_NAME, name);
- getCurrentSession().save(HibernateRoleImpl.ENTITY_NAME, roleMap);
- HibernateRoleImpl role = new HibernateRoleImpl(getSessionFactory(),
roleMap);
- role.setDisplayName(displayName);
- 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
- {
- //throw new UnsupportedOperationException("Not yet implemented");
- if (id instanceof Long)
- {
- try
- {
- Session session = getCurrentSession();
- Map roleMap = (Map)session.load(HibernateRoleImpl.ENTITY_NAME, (Long)id);
-
- //remove users asignments
- Set usersSet = (Set)roleMap.get(HibernateRoleImpl.MAPPING_USERS);
-
- if (usersSet != null)
- {
- Iterator users = usersSet.iterator();
- while (users.hasNext())
- {
- Map userMap = (Map)users.next();
-
- //make a new set of roles without this one
- Set newRoles = new HashSet();
- Set roles = (Set)userMap.get(HibernateUserImpl.MAPPING_ROLES);
- for (Iterator iterator = roles.iterator(); iterator.hasNext();)
- {
- Map role = (Map)iterator.next();
- if (!(role.get(HibernateRoleImpl.MAPPING_ID)).equals(id))
- {
- newRoles.add(role);
- }
- }
- userMap.put(HibernateUserImpl.MAPPING_ROLES, newRoles);
- }
- }
- session.delete(HibernateRoleImpl.ENTITY_NAME, roleMap);
- 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
- {
- //throw new UnsupportedOperationException("Not yet implemented");
- try
- {
- Session session = getCurrentSession();
- Query query = session.createQuery("select count(g.id) from PortalRole 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
- {
- //throw new UnsupportedOperationException("Not yet implemented");
- try
- {
- Session session = getCurrentSession();
- Query query = session.createQuery("from PortalRole");
- Iterator iterator = query.iterate();
- return processRolesSet(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
-// {
-// //throw new UnsupportedOperationException("Not yet implemented");
-// if (roleName != null)
-// {
-// try
-// {
-// Session session = getCurrentSession();
-//
-// Query query;
-// if (userNameFilter.trim().length() != 0)
-// {
-// //
-// userNameFilter = "%" +
userNameFilter.replaceAll("%", "") + "%";
-//
-// //
-// query = session.createQuery("from PortalUser 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 PortalUser 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 = processRolesSet(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");
-// }
-// }
-
- /**
- * @deprecated
- * @param user
- * @param roles
- * @throws IdentityException
- */
-// public void setRoles(User user, Set roles) throws IdentityException
-// {
-// //throw new UnsupportedOperationException("Not yet implemented");
-// if (!(user instanceof HibernateUserImpl))
-// {
-// throw new IllegalArgumentException("User is not a HibernateUserImpl
user");
-// }
-//
-// // We make a defensive copy with unwrapped maps and update with a new set
-// Set copy = new HashSet();
-// for (Iterator i = roles.iterator(); i.hasNext();)
-// {
-// Object o = i.next();
-// if (o instanceof HibernateRoleImpl)
-// {
-// copy.add(((HibernateRoleImpl)o).getCurrentMap());
-// }
-// else
-// {
-// throw new IllegalArgumentException("Only HibernateRoleImpl roles can
be accepted");
-// }
-// }
-//
-// // Assign new roles
-// HibernateUserImpl ui = (HibernateUserImpl)user;
-// ui.setRoles(copy);
-// }
-//
-//
-// public Set getRoles(User user) throws IdentityException
-// {
-// //throw new UnsupportedOperationException("Not yet implemented");
-// if (!(user instanceof HibernateUserImpl))
-// {
-// throw new IllegalArgumentException("User is not a db_old user");
-// }
-//
-// // We return an immutable set to avoid modifications
-// HibernateUserImpl ui = (HibernateUserImpl)user;
-// Set roles = ui.getRoleMapsSet();
-// Set wrappers = new HashSet();
-// for (Iterator iterator = roles.iterator(); iterator.hasNext();)
-// {
-// Map map = (Map)iterator.next();
-// wrappers.add(new HibernateRoleImpl(getSessionFactory(), map));
-// }
-//
-// return wrappers;
-// }
-
- /**
- * Process Set of Map objects and returns a Set of HibernateRoleImpl objects
- * @param maps
- * @return
- * @throws Exception
- */
- private Set processRolesSet(Set maps) throws IdentityException
- {
- Set roles = new HashSet();
- for (Iterator iterator1 = maps.iterator(); iterator1.hasNext();)
- {
- Map roleMap = (Map)iterator1.next();
- roles.add(new HibernateRoleImpl(getSessionFactory(),roleMap));
- }
- return roles;
- }
-
-/**
- * Can be subclasses to provide testing in a non JTA environement.
- *
- * @throws IllegalStateException if no session factory is present
- */
- protected Session getCurrentSession() throws IllegalStateException
- {
- return getSessionFactory().getCurrentSession();//.getSession(EntityMode.MAP);
-
- }
-
- protected SessionFactory getSessionFactory() throws IllegalStateException
- {
- if (sessionFactory == null)
- {
- throw new IllegalStateException("No session factory");
- }
- return sessionFactory;//.getCurrentSession();
- }
-}
Copied:
trunk/identity/src/main/org/jboss/portal/identity/experimental/db/HibernateRoleModuleImpl.java
(from rev 5883,
trunk/identity/src/main/org/jboss/portal/identity2/experimental/db/HibernateRoleModuleImpl.java)
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/experimental/db/HibernateRoleModuleImpl.java 2006-12-17
14:26:07 UTC (rev 5883)
+++
trunk/identity/src/main/org/jboss/portal/identity/experimental/db/HibernateRoleModuleImpl.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -0,0 +1,459 @@
+/*
+* 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.identity.experimental.db;
+
+import org.hibernate.SessionFactory;
+import org.hibernate.Criteria;
+import org.hibernate.Session;
+import org.hibernate.Query;
+import org.hibernate.HibernateException;
+import org.hibernate.criterion.Restrictions;
+import org.jboss.portal.identity.IdentityException;
+import org.jboss.portal.identity.Role;
+import org.jboss.portal.identity.service.RoleModuleService;
+import org.jboss.portal.common.util.Tools;
+
+import javax.naming.InitialContext;
+import java.util.Set;
+import java.util.Iterator;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.HashMap;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet </a>
+ * @author <a href="mailto:theute@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(HibernateRoleModuleImpl.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
+// {
+// //throw new UnsupportedOperationException("Not yet implemented");
+// if (name != null)
+// {
+// try
+// {
+// Session session = getCurrentSession();
+// Criteria criteria = session.createCriteria(HibernateRoleImpl.ENTITY_NAME);
+// criteria.add(Restrictions.naturalId().set("name", name));
+// criteria.setCacheable(true);
+// Map roleMap = (Map)criteria.uniqueResult();
+// if (roleMap == null)
+// {
+// throw new IdentityException("No such role " + name);
+// }
+// return new HibernateRoleImpl(getSessionFactory(), roleMap);
+// }
+// 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
+// {
+// //throw new UnsupportedOperationException("Not yet implemented");
+// if (names != null)
+// {
+// try
+// {
+// Session session = getCurrentSession();
+// StringBuffer queryString = new StringBuffer("from PortalRole 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 processRolesSet(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
+// {
+// //throw new UnsupportedOperationException("Not yet implemented");
+// 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
+// {
+// //throw new UnsupportedOperationException("Not yet implemented");
+// if (id instanceof Long)
+// {
+// try
+// {
+// Session session = getCurrentSession();
+// Map roleMap = (Map)session.get(HibernateRoleImpl.ENTITY_NAME, (Long)id);
+// if (roleMap == null)
+// {
+// throw new IdentityException("No role found for " + id);
+// }
+// return new HibernateRoleImpl(getSessionFactory(),roleMap);
+// }
+// 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
+// {
+// //throw new UnsupportedOperationException("Not yet implemented");
+// if (name != null)
+// {
+// try
+// {
+// Map roleMap = new HashMap();
+// roleMap.put(HibernateRoleImpl.MAPPING_NAME, name);
+// getCurrentSession().save(HibernateRoleImpl.ENTITY_NAME, roleMap);
+// HibernateRoleImpl role = new HibernateRoleImpl(getSessionFactory(),
roleMap);
+// role.setDisplayName(displayName);
+// 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
+// {
+// //throw new UnsupportedOperationException("Not yet implemented");
+// if (id instanceof Long)
+// {
+// try
+// {
+// Session session = getCurrentSession();
+// Map roleMap = (Map)session.load(HibernateRoleImpl.ENTITY_NAME, (Long)id);
+//
+// //remove users asignments
+// Set usersSet = (Set)roleMap.get(HibernateRoleImpl.MAPPING_USERS);
+//
+// if (usersSet != null)
+// {
+// Iterator users = usersSet.iterator();
+// while (users.hasNext())
+// {
+// Map userMap = (Map)users.next();
+//
+// //make a new set of roles without this one
+// Set newRoles = new HashSet();
+// Set roles = (Set)userMap.get(HibernateUserImpl.MAPPING_ROLES);
+// for (Iterator iterator = roles.iterator(); iterator.hasNext();)
+// {
+// Map role = (Map)iterator.next();
+// if (!(role.get(HibernateRoleImpl.MAPPING_ID)).equals(id))
+// {
+// newRoles.add(role);
+// }
+// }
+// userMap.put(HibernateUserImpl.MAPPING_ROLES, newRoles);
+// }
+// }
+// session.delete(HibernateRoleImpl.ENTITY_NAME, roleMap);
+// 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
+// {
+// //throw new UnsupportedOperationException("Not yet implemented");
+// try
+// {
+// Session session = getCurrentSession();
+// Query query = session.createQuery("select count(g.id) from PortalRole 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
+// {
+// //throw new UnsupportedOperationException("Not yet implemented");
+// try
+// {
+// Session session = getCurrentSession();
+// Query query = session.createQuery("from PortalRole");
+// Iterator iterator = query.iterate();
+// return processRolesSet(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
+//// {
+//// //throw new UnsupportedOperationException("Not yet implemented");
+//// if (roleName != null)
+//// {
+//// try
+//// {
+//// Session session = getCurrentSession();
+////
+//// Query query;
+//// if (userNameFilter.trim().length() != 0)
+//// {
+//// //
+//// userNameFilter = "%" +
userNameFilter.replaceAll("%", "") + "%";
+////
+//// //
+//// query = session.createQuery("from PortalUser 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 PortalUser 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 = processRolesSet(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");
+//// }
+//// }
+//
+// /**
+// * @deprecated
+// * @param user
+// * @param roles
+// * @throws IdentityException
+// */
+//// public void setRoles(User user, Set roles) throws IdentityException
+//// {
+//// //throw new UnsupportedOperationException("Not yet implemented");
+//// if (!(user instanceof HibernateUserImpl))
+//// {
+//// throw new IllegalArgumentException("User is not a HibernateUserImpl
user");
+//// }
+////
+//// // We make a defensive copy with unwrapped maps and update with a new set
+//// Set copy = new HashSet();
+//// for (Iterator i = roles.iterator(); i.hasNext();)
+//// {
+//// Object o = i.next();
+//// if (o instanceof HibernateRoleImpl)
+//// {
+//// copy.add(((HibernateRoleImpl)o).getCurrentMap());
+//// }
+//// else
+//// {
+//// throw new IllegalArgumentException("Only HibernateRoleImpl roles can
be accepted");
+//// }
+//// }
+////
+//// // Assign new roles
+//// HibernateUserImpl ui = (HibernateUserImpl)user;
+//// ui.setRoles(copy);
+//// }
+////
+////
+//// public Set getRoles(User user) throws IdentityException
+//// {
+//// //throw new UnsupportedOperationException("Not yet implemented");
+//// if (!(user instanceof HibernateUserImpl))
+//// {
+//// throw new IllegalArgumentException("User is not a db_old user");
+//// }
+////
+//// // We return an immutable set to avoid modifications
+//// HibernateUserImpl ui = (HibernateUserImpl)user;
+//// Set roles = ui.getRoleMapsSet();
+//// Set wrappers = new HashSet();
+//// for (Iterator iterator = roles.iterator(); iterator.hasNext();)
+//// {
+//// Map map = (Map)iterator.next();
+//// wrappers.add(new HibernateRoleImpl(getSessionFactory(), map));
+//// }
+////
+//// return wrappers;
+//// }
+//
+// /**
+// * Process Set of Map objects and returns a Set of HibernateRoleImpl objects
+// * @param maps
+// * @return
+// * @throws Exception
+// */
+// private Set processRolesSet(Set maps) throws IdentityException
+// {
+// Set roles = new HashSet();
+// for (Iterator iterator1 = maps.iterator(); iterator1.hasNext();)
+// {
+// Map roleMap = (Map)iterator1.next();
+// roles.add(new HibernateRoleImpl(getSessionFactory(),roleMap));
+// }
+// return roles;
+// }
+//
+///**
+// * Can be subclasses to provide testing in a non JTA environement.
+// *
+// * @throws IllegalStateException if no session factory is present
+// */
+// protected Session getCurrentSession() throws IllegalStateException
+// {
+// return getSessionFactory().getCurrentSession();//.getSession(EntityMode.MAP);
+//
+// }
+//
+// protected SessionFactory getSessionFactory() throws IllegalStateException
+// {
+// if (sessionFactory == null)
+// {
+// throw new IllegalStateException("No session factory");
+// }
+// return sessionFactory;//.getCurrentSession();
+// }
+}
Deleted:
trunk/identity/src/main/org/jboss/portal/identity/experimental/db/HibernateUserImpl.java
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/experimental/db/HibernateUserImpl.java 2006-12-15
15:15:26 UTC (rev 5871)
+++
trunk/identity/src/main/org/jboss/portal/identity/experimental/db/HibernateUserImpl.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -1,324 +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.experimental.db;
-
-import org.jboss.portal.identity2.User;
-import org.jboss.portal.identity.IdentityException;
-import org.jboss.portal.common.util.Tools;
-import org.hibernate.SessionFactory;
-import org.hibernate.Session;
-import org.hibernate.EntityMode;
-
-import java.util.Map;
-import java.util.HashMap;
-import java.util.Set;
-import java.util.HashSet;
-import java.util.Collections;
-
-/**
- * User interface implementation.
- *
- * @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw
Dawidowicz</a>
- * @version $Revision: 5448 $
- */
-public class HibernateUserImpl
- implements User
-{
-
- private static final org.jboss.logging.Logger log =
org.jboss.logging.Logger.getLogger(HibernateUserImpl.class);
-
- //names used in hibernate.hbm.xml file to map fields
- public static final String ENTITY_NAME = "PortalUser";
- public static final String MAPPING_DYNAMIC_PROPERTY_MAP = "dynamic";
- public static final String MAPPING_ROLES = "roles";
- public static final String MAPPING_ID = "key";
- public static final String MAPPING_USER_NAME = "userName";
- public static final String MAPPING_PASSWORD = "password";
-
- //list of fields used for mapping
- public static final Set restrictedFieldNames = buildRestrictedFields();
-
- private static Set buildRestrictedFields()
- {
- Set set = new HashSet();
- set.add(MAPPING_DYNAMIC_PROPERTY_MAP);
- set.add(MAPPING_ROLES);
- set.add(MAPPING_ID);
- set.add(MAPPING_USER_NAME);
- set.add(MAPPING_PASSWORD);
-
- return Collections.unmodifiableSet(set);
- }
-
- private SessionFactory sessionFactory;
-
- private Map currentMap;
-
- /*
- * Transient fields.
- */
-
- private HibernateUserImpl()
- {
-
- }
-
- /**
- * Initializes Hibernate user object. initialContent map should be already persisted
in hibernate Session
- * @param sf
- * @param initialContent
- * @throws IdentityException
- */
- public HibernateUserImpl(SessionFactory sf, Map initialContent) throws
IdentityException
- {
- if (sf == null)
- {
- throw new IdentityException("SessionFactory is null");
- }
- if (initialContent == null)
- {
- throw new IdentityException("Map is null");
- }
- this.sessionFactory = sf;
- this.currentMap = initialContent;
- //persist();
- }
-
- // ***
- //
- // API
- //
- // ***
-
- public Object getId()
- {
- return getCurrentMap().get(MAPPING_ID);
- }
-
- public String getUserName()
- {
- return (String)getCurrentMap().get(MAPPING_USER_NAME);
- }
-
- public void updatePassword(String password)
- {
- if (password == null)
- {
- throw new IllegalArgumentException("Password is null");
- }
- getCurrentMap().put(MAPPING_PASSWORD, Tools.md5AsHexString(password));
- persist();
- }
-
- public boolean validatePassword(String password)
- {
- if (password != null)
- {
- String hashedPassword = Tools.md5AsHexString(password);
- return hashedPassword.equals(getPassword());
- }
- return false;
- }
-
- public void setPassword(String pass)
- {
- getCurrentMap().put(MAPPING_PASSWORD, pass);
- persist();
- }
-
- // ***
- //
- // SPI
- //
- // ***
-
- public void setUserName(String userName)
- {
- if (userName == null)
- {
- throw new IllegalArgumentException("userName is null");
- }
- getCurrentMap().put(MAPPING_USER_NAME, userName);
- persist();
- }
-
- public Map getCurrentMap()
- {
- return currentMap;
- }
-
- //properties
- public Map getProperties()
- {
- return Collections.unmodifiableMap(getDynamic());
- }
-
- public void setDynamicProperties(Map props)
- {
- getCurrentMap().put(MAPPING_DYNAMIC_PROPERTY_MAP, props);
- persist();
- }
-
- public void setDynamicProperty(String name, String value)
- {
- if (name == null)
- {
- throw new IllegalArgumentException("property name is null");
- }
- getDynamic().put(name, value);
- persist();
- }
-
- public String getDynamicProperty(String name)
- {
- if (name == null)
- {
- throw new IllegalArgumentException("property name is null");
- }
- return (String)getDynamic().get(name);
- }
-
- public boolean hasDynamicPropertyValue(String name)
- {
- if (name == null)
- {
- throw new IllegalArgumentException("property name is null");
- }
-
- return getDynamic().containsKey(name);
- }
-
- //fields
- public String getFieldValue(String name)
- {
- if (name == null)
- {
- throw new IllegalArgumentException("name is null");
- }
- return (String)getCurrentMap().get(name);
- }
-
- public void setFieldValue(String name, String value) throws IdentityException
- {
- if (name == null)
- {
- throw new IllegalArgumentException("property name is null");
- }
- if (restrictedFieldNames.contains(name))
- {
- throw new IdentityException("Cannot set field name: " + name + "
as it's restricted one");
- }
- getCurrentMap().put(name, value);
- persist();
- }
-
- //roles
-
- public Set getRoleMapsSet()
- {
- return Collections.unmodifiableSet(getRolesSet());
- }
-
-
- public void setRoles(Set roles)
- {
- if (roles == null)
- {
- throw new IllegalArgumentException("roles set is null");
- }
- getCurrentMap().put(MAPPING_ROLES, roles);
- persist();
- }
-
- public void addRole(Map map)
- {
- getRolesSet().add(map);
- persist();
- }
-
- public String getPassword()
- {
- return (String)getCurrentMap().get(MAPPING_PASSWORD);
- }
-
- // ********
- //
- // Internal
- //
- // ********
-
-
- protected SessionFactory getSessionFactory()
- {
- return sessionFactory;
- }
-
- protected void setSessionFactory(SessionFactory sessionFactory)
- {
- this.sessionFactory = sessionFactory;
- }
-
- protected Map getDynamic()
- {
- Map props = (Map)getCurrentMap().get(MAPPING_DYNAMIC_PROPERTY_MAP);
- if (props == null)
- {
- props = new HashMap();
- getCurrentMap().put(MAPPING_DYNAMIC_PROPERTY_MAP, props);
- }
- return props;
- }
-
- protected Set getRolesSet()
- {
- Set roles = (Set)getCurrentMap().get(MAPPING_ROLES);
- if (roles == null)
- {
- roles = new HashSet();
- getCurrentMap().put(MAPPING_ROLES, roles);
- }
- return roles;
- }
-
- protected void persist()
- {
- getCurrentSession().save(ENTITY_NAME, currentMap);
- }
-
-
- public String toString()
- {
- return "User[" + getId() + "," + getUserName() +
"]";
- }
-
- /**
- * 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().getSession(EntityMode.MAP);
- }
-}
Copied:
trunk/identity/src/main/org/jboss/portal/identity/experimental/db/HibernateUserImpl.java
(from rev 5883,
trunk/identity/src/main/org/jboss/portal/identity2/experimental/db/HibernateUserImpl.java)
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/experimental/db/HibernateUserImpl.java 2006-12-17
14:26:07 UTC (rev 5883)
+++
trunk/identity/src/main/org/jboss/portal/identity/experimental/db/HibernateUserImpl.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -0,0 +1,323 @@
+/*
+* 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.identity.experimental.db;
+
+import org.jboss.portal.identity.User;
+import org.jboss.portal.identity.IdentityException;
+import org.jboss.portal.common.util.Tools;
+import org.hibernate.SessionFactory;
+import org.hibernate.Session;
+import org.hibernate.EntityMode;
+
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Set;
+import java.util.HashSet;
+import java.util.Collections;
+
+/**
+ * User interface implementation.
+ *
+ * @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw
Dawidowicz</a>
+ * @version $Revision: 5448 $
+ */
+public class HibernateUserImpl //implements User
+{
+
+// private static final org.jboss.logging.Logger log =
org.jboss.logging.Logger.getLogger(HibernateUserImpl.class);
+//
+// //names used in hibernate.hbm.xml file to map fields
+// public static final String ENTITY_NAME = "PortalUser";
+// public static final String MAPPING_DYNAMIC_PROPERTY_MAP = "dynamic";
+// public static final String MAPPING_ROLES = "roles";
+// public static final String MAPPING_ID = "key";
+// public static final String MAPPING_USER_NAME = "userName";
+// public static final String MAPPING_PASSWORD = "password";
+//
+// //list of fields used for mapping
+// public static final Set restrictedFieldNames = buildRestrictedFields();
+//
+// private static Set buildRestrictedFields()
+// {
+// Set set = new HashSet();
+// set.add(MAPPING_DYNAMIC_PROPERTY_MAP);
+// set.add(MAPPING_ROLES);
+// set.add(MAPPING_ID);
+// set.add(MAPPING_USER_NAME);
+// set.add(MAPPING_PASSWORD);
+//
+// return Collections.unmodifiableSet(set);
+// }
+//
+// private SessionFactory sessionFactory;
+//
+// private Map currentMap;
+//
+// /*
+// * Transient fields.
+// */
+//
+// private HibernateUserImpl()
+// {
+//
+// }
+//
+// /**
+// * Initializes Hibernate user object. initialContent map should be already persisted
in hibernate Session
+// * @param sf
+// * @param initialContent
+// * @throws IdentityException
+// */
+// public HibernateUserImpl(SessionFactory sf, Map initialContent) throws
IdentityException
+// {
+// if (sf == null)
+// {
+// throw new IdentityException("SessionFactory is null");
+// }
+// if (initialContent == null)
+// {
+// throw new IdentityException("Map is null");
+// }
+// this.sessionFactory = sf;
+// this.currentMap = initialContent;
+// //persist();
+// }
+//
+// // ***
+// //
+// // API
+// //
+// // ***
+//
+// public Object getId()
+// {
+// return getCurrentMap().get(MAPPING_ID);
+// }
+//
+// public String getUserName()
+// {
+// return (String)getCurrentMap().get(MAPPING_USER_NAME);
+// }
+//
+// public void updatePassword(String password)
+// {
+// if (password == null)
+// {
+// throw new IllegalArgumentException("Password is null");
+// }
+// getCurrentMap().put(MAPPING_PASSWORD, Tools.md5AsHexString(password));
+// persist();
+// }
+//
+// public boolean validatePassword(String password)
+// {
+// if (password != null)
+// {
+// String hashedPassword = Tools.md5AsHexString(password);
+// return hashedPassword.equals(getPassword());
+// }
+// return false;
+// }
+//
+// public void setPassword(String pass)
+// {
+// getCurrentMap().put(MAPPING_PASSWORD, pass);
+// persist();
+// }
+//
+// // ***
+// //
+// // SPI
+// //
+// // ***
+//
+// public void setUserName(String userName)
+// {
+// if (userName == null)
+// {
+// throw new IllegalArgumentException("userName is null");
+// }
+// getCurrentMap().put(MAPPING_USER_NAME, userName);
+// persist();
+// }
+//
+// public Map getCurrentMap()
+// {
+// return currentMap;
+// }
+//
+// //properties
+// public Map getProperties()
+// {
+// return Collections.unmodifiableMap(getDynamic());
+// }
+//
+// public void setDynamicProperties(Map props)
+// {
+// getCurrentMap().put(MAPPING_DYNAMIC_PROPERTY_MAP, props);
+// persist();
+// }
+//
+// public void setDynamicProperty(String name, String value)
+// {
+// if (name == null)
+// {
+// throw new IllegalArgumentException("property name is null");
+// }
+// getDynamic().put(name, value);
+// persist();
+// }
+//
+// public String getDynamicProperty(String name)
+// {
+// if (name == null)
+// {
+// throw new IllegalArgumentException("property name is null");
+// }
+// return (String)getDynamic().get(name);
+// }
+//
+// public boolean hasDynamicPropertyValue(String name)
+// {
+// if (name == null)
+// {
+// throw new IllegalArgumentException("property name is null");
+// }
+//
+// return getDynamic().containsKey(name);
+// }
+//
+// //fields
+// public String getFieldValue(String name)
+// {
+// if (name == null)
+// {
+// throw new IllegalArgumentException("name is null");
+// }
+// return (String)getCurrentMap().get(name);
+// }
+//
+// public void setFieldValue(String name, String value) throws IdentityException
+// {
+// if (name == null)
+// {
+// throw new IllegalArgumentException("property name is null");
+// }
+// if (restrictedFieldNames.contains(name))
+// {
+// throw new IdentityException("Cannot set field name: " + name +
" as it's restricted one");
+// }
+// getCurrentMap().put(name, value);
+// persist();
+// }
+//
+// //roles
+//
+// public Set getRoleMapsSet()
+// {
+// return Collections.unmodifiableSet(getRolesSet());
+// }
+//
+//
+// public void setRoles(Set roles)
+// {
+// if (roles == null)
+// {
+// throw new IllegalArgumentException("roles set is null");
+// }
+// getCurrentMap().put(MAPPING_ROLES, roles);
+// persist();
+// }
+//
+// public void addRole(Map map)
+// {
+// getRolesSet().add(map);
+// persist();
+// }
+//
+// public String getPassword()
+// {
+// return (String)getCurrentMap().get(MAPPING_PASSWORD);
+// }
+//
+// // ********
+// //
+// // Internal
+// //
+// // ********
+//
+//
+// protected SessionFactory getSessionFactory()
+// {
+// return sessionFactory;
+// }
+//
+// protected void setSessionFactory(SessionFactory sessionFactory)
+// {
+// this.sessionFactory = sessionFactory;
+// }
+//
+// protected Map getDynamic()
+// {
+// Map props = (Map)getCurrentMap().get(MAPPING_DYNAMIC_PROPERTY_MAP);
+// if (props == null)
+// {
+// props = new HashMap();
+// getCurrentMap().put(MAPPING_DYNAMIC_PROPERTY_MAP, props);
+// }
+// return props;
+// }
+//
+// protected Set getRolesSet()
+// {
+// Set roles = (Set)getCurrentMap().get(MAPPING_ROLES);
+// if (roles == null)
+// {
+// roles = new HashSet();
+// getCurrentMap().put(MAPPING_ROLES, roles);
+// }
+// return roles;
+// }
+//
+// protected void persist()
+// {
+// getCurrentSession().save(ENTITY_NAME, currentMap);
+// }
+//
+//
+// public String toString()
+// {
+// return "User[" + getId() + "," + getUserName() +
"]";
+// }
+//
+// /**
+// * 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().getSession(EntityMode.MAP);
+// }
+}
Deleted:
trunk/identity/src/main/org/jboss/portal/identity/experimental/db/HibernateUserModuleImpl.java
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/experimental/db/HibernateUserModuleImpl.java 2006-12-15
15:15:26 UTC (rev 5871)
+++
trunk/identity/src/main/org/jboss/portal/identity/experimental/db/HibernateUserModuleImpl.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -1,329 +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.experimental.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.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;
-import java.util.Map;
-import java.util.HashMap;
-import java.util.HashSet;
-
-/**
- * @author <a href="mailto:julien@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 void startService() throws Exception
- {
- //
- sessionFactory = (SessionFactory)new
InitialContext().lookup(sessionFactoryJNDIName);
-
- super.startService();
- }
-
- protected void stopService() throws Exception
- {
-
- //
- sessionFactory = null;
- super.stopService();
- }
-
-// public SessionFactory getSessionFactory()
-// {
-// return sessionFactory;
-// }
-
- public String getSessionFactoryJNDIName()
- {
- return sessionFactoryJNDIName;
- }
-
- public void setSessionFactoryJNDIName(String sessionFactoryJNDIName)
- {
- this.sessionFactoryJNDIName = sessionFactoryJNDIName;
- }
-
- public User findUserByUserName(String userName) throws IdentityException
- {
- //throw new UnsupportedOperationException("Not yet implemented");
-
- if (userName != null)
- {
- try
- {
- Session session = getCurrentSession();
- //TODO: use contants
- Query query = session.createQuery("from PortalUser where
userName=:userName");
- query.setParameter("userName", userName);
- //query.setCacheable(true);
- Map userMap = (Map)query.uniqueResult();
- if (userMap == null)
- {
- throw new NoSuchUserException("No such user " + userName);
- }
- return new HibernateUserImpl(getSessionFactory(), userMap);
- }
- 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
- {
- //throw new UnsupportedOperationException("Not yet implemented");
- if (id instanceof Long)
- {
- try
- {
- Session session = getCurrentSession();
- Map userMap = (Map)session.get(HibernateUserImpl.ENTITY_NAME, (Long)id);
- if (userMap == null)
- {
- throw new NoSuchUserException("No user found for " + id);
- }
- return new HibernateUserImpl(getSessionFactory(),userMap);
- }
- 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) throws IdentityException
- {
- if (userName != null)
- {
- try
- {
- Map mapUser = new HashMap();
- mapUser.put(HibernateUserImpl.MAPPING_USER_NAME, userName);
- mapUser.put(HibernateUserImpl.MAPPING_DYNAMIC_PROPERTY_MAP, new HashMap());
- mapUser.put(HibernateUserImpl.MAPPING_ROLES, new HashSet());
- //persist
- getCurrentSession().save(HibernateUserImpl.ENTITY_NAME, mapUser);
- //create wrapper
- HibernateUserImpl user = new HibernateUserImpl(getSessionFactory(),
mapUser);
- user.updatePassword(password);
- 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
- {
- //throw new UnsupportedOperationException("Not yet implemented");
- if (id instanceof Long)
- {
- try
- {
- Session session = getCurrentSession();
- Map mapUser = (Map)session.load(HibernateUserImpl.ENTITY_NAME,
(Serializable)id);
-
-
- if (mapUser == null)
- {
- throw new NoSuchUserException("No such user " + id);
- }
- session.delete(HibernateUserImpl.ENTITY_NAME, mapUser);
- 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
- {
- //throw new UnsupportedOperationException("Not yet implemented");
- try
- {
- Session session = getCurrentSession();
- //TODO: Use constants
- Query query = session.createQuery("from PortalUser");
- query.setFirstResult(offset);
- query.setMaxResults(limit);
- Iterator iterator = query.iterate();
- return processUsersSet(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
- {
- //throw new UnsupportedOperationException("Not yet implemented");
- try
- {
- // Remove all occurences of % and add ours
- filter = "%" + filter.replaceAll("%", "") +
"%";
-
- //
- Session session = getCurrentSession();
- //TODO: use constants
- Query query = session.createQuery("from PortalUser as u where u.userName
like :filter");
- query.setString("filter", filter);
- query.setFirstResult(offset);
- query.setMaxResults(limit);
- Iterator iterator = query.iterate();
- return processUsersSet(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
- {
- //throw new UnsupportedOperationException("Not yet implemented");
- try
- {
- Session session = getCurrentSession();
- Query query = session.createQuery("select count(u.key) from PortalUser as
u");
- return ((Number)query.uniqueResult()).intValue();
- }
- catch (HibernateException e)
- {
- String message = "Cannot count users";
- log.error(message, e);
- throw new IdentityException(message, e);
- }
- }
-
- /**
- * Process Set of Map objects and returns a Set of HibernateUserImpl objects
- * @param maps
- * @return Set
- * @throws IdentityException
- */
- private Set processUsersSet(Set maps) throws IdentityException
- {
- Set users = new HashSet();
- for (Iterator iterator1 = maps.iterator(); iterator1.hasNext();)
- {
- Map userMap = (Map)iterator1.next();
- users.add(new HibernateUserImpl(getSessionFactory(),userMap));
- }
- return users;
- }
-
-
-
- /**
- * Can be subclasses to provide testing in a non JTA environement.
- *
- * @throws IllegalStateException if no session factory is present
- * @return Session
- */
- protected Session getCurrentSession() throws IllegalStateException
- {
- return getSessionFactory().getCurrentSession();//.getSession(EntityMode.MAP);
-
- }
-
- protected SessionFactory getSessionFactory() throws IllegalStateException
- {
- if (sessionFactory == null)
- {
- throw new IllegalStateException("No session factory");
- }
- return sessionFactory;//.getCurrentSession();
- }
-}
Copied:
trunk/identity/src/main/org/jboss/portal/identity/experimental/db/HibernateUserModuleImpl.java
(from rev 5883,
trunk/identity/src/main/org/jboss/portal/identity2/experimental/db/HibernateUserModuleImpl.java)
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/experimental/db/HibernateUserModuleImpl.java 2006-12-17
14:26:07 UTC (rev 5883)
+++
trunk/identity/src/main/org/jboss/portal/identity/experimental/db/HibernateUserModuleImpl.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -0,0 +1,329 @@
+/*
+* 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.identity.experimental.db;
+
+import org.jboss.portal.identity.User;
+import org.jboss.portal.identity.service.UserModuleService;
+import org.jboss.portal.identity.IdentityException;
+import org.jboss.portal.identity.NoSuchUserException;
+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;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.HashSet;
+
+/**
+ * @author <a href="mailto:julien@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 void startService() throws Exception
+// {
+// //
+// sessionFactory = (SessionFactory)new
InitialContext().lookup(sessionFactoryJNDIName);
+//
+// super.startService();
+// }
+//
+// protected void stopService() throws Exception
+// {
+//
+// //
+// sessionFactory = null;
+// super.stopService();
+// }
+//
+//// public SessionFactory getSessionFactory()
+//// {
+//// return sessionFactory;
+//// }
+//
+// public String getSessionFactoryJNDIName()
+// {
+// return sessionFactoryJNDIName;
+// }
+//
+// public void setSessionFactoryJNDIName(String sessionFactoryJNDIName)
+// {
+// this.sessionFactoryJNDIName = sessionFactoryJNDIName;
+// }
+//
+// public User findUserByUserName(String userName) throws IdentityException
+// {
+// //throw new UnsupportedOperationException("Not yet implemented");
+//
+// if (userName != null)
+// {
+// try
+// {
+// Session session = getCurrentSession();
+// //TODO: use contants
+// Query query = session.createQuery("from PortalUser where
userName=:userName");
+// query.setParameter("userName", userName);
+// //query.setCacheable(true);
+// Map userMap = (Map)query.uniqueResult();
+// if (userMap == null)
+// {
+// throw new NoSuchUserException("No such user " + userName);
+// }
+// return new HibernateUserImpl(getSessionFactory(), userMap);
+// }
+// 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
+// {
+// //throw new UnsupportedOperationException("Not yet implemented");
+// if (id instanceof Long)
+// {
+// try
+// {
+// Session session = getCurrentSession();
+// Map userMap = (Map)session.get(HibernateUserImpl.ENTITY_NAME, (Long)id);
+// if (userMap == null)
+// {
+// throw new NoSuchUserException("No user found for " + id);
+// }
+// return new HibernateUserImpl(getSessionFactory(),userMap);
+// }
+// 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) throws IdentityException
+// {
+// if (userName != null)
+// {
+// try
+// {
+// Map mapUser = new HashMap();
+// mapUser.put(HibernateUserImpl.MAPPING_USER_NAME, userName);
+// mapUser.put(HibernateUserImpl.MAPPING_DYNAMIC_PROPERTY_MAP, new
HashMap());
+// mapUser.put(HibernateUserImpl.MAPPING_ROLES, new HashSet());
+// //persist
+// getCurrentSession().save(HibernateUserImpl.ENTITY_NAME, mapUser);
+// //create wrapper
+// HibernateUserImpl user = new HibernateUserImpl(getSessionFactory(),
mapUser);
+// user.updatePassword(password);
+// 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
+// {
+// //throw new UnsupportedOperationException("Not yet implemented");
+// if (id instanceof Long)
+// {
+// try
+// {
+// Session session = getCurrentSession();
+// Map mapUser = (Map)session.load(HibernateUserImpl.ENTITY_NAME,
(Serializable)id);
+//
+//
+// if (mapUser == null)
+// {
+// throw new NoSuchUserException("No such user " + id);
+// }
+// session.delete(HibernateUserImpl.ENTITY_NAME, mapUser);
+// 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
+// {
+// //throw new UnsupportedOperationException("Not yet implemented");
+// try
+// {
+// Session session = getCurrentSession();
+// //TODO: Use constants
+// Query query = session.createQuery("from PortalUser");
+// query.setFirstResult(offset);
+// query.setMaxResults(limit);
+// Iterator iterator = query.iterate();
+// return processUsersSet(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
+// {
+// //throw new UnsupportedOperationException("Not yet implemented");
+// try
+// {
+// // Remove all occurences of % and add ours
+// filter = "%" + filter.replaceAll("%", "") +
"%";
+//
+// //
+// Session session = getCurrentSession();
+// //TODO: use constants
+// Query query = session.createQuery("from PortalUser as u where u.userName
like :filter");
+// query.setString("filter", filter);
+// query.setFirstResult(offset);
+// query.setMaxResults(limit);
+// Iterator iterator = query.iterate();
+// return processUsersSet(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
+// {
+// //throw new UnsupportedOperationException("Not yet implemented");
+// try
+// {
+// Session session = getCurrentSession();
+// Query query = session.createQuery("select count(u.key) from PortalUser as
u");
+// return ((Number)query.uniqueResult()).intValue();
+// }
+// catch (HibernateException e)
+// {
+// String message = "Cannot count users";
+// log.error(message, e);
+// throw new IdentityException(message, e);
+// }
+// }
+//
+// /**
+// * Process Set of Map objects and returns a Set of HibernateUserImpl objects
+// * @param maps
+// * @return Set
+// * @throws IdentityException
+// */
+// private Set processUsersSet(Set maps) throws IdentityException
+// {
+// Set users = new HashSet();
+// for (Iterator iterator1 = maps.iterator(); iterator1.hasNext();)
+// {
+// Map userMap = (Map)iterator1.next();
+// users.add(new HibernateUserImpl(getSessionFactory(),userMap));
+// }
+// return users;
+// }
+//
+//
+//
+// /**
+// * Can be subclasses to provide testing in a non JTA environement.
+// *
+// * @throws IllegalStateException if no session factory is present
+// * @return Session
+// */
+// protected Session getCurrentSession() throws IllegalStateException
+// {
+// return getSessionFactory().getCurrentSession();//.getSession(EntityMode.MAP);
+//
+// }
+//
+// protected SessionFactory getSessionFactory() throws IllegalStateException
+// {
+// if (sessionFactory == null)
+// {
+// throw new IllegalStateException("No session factory");
+// }
+// return sessionFactory;//.getCurrentSession();
+// }
+}
Deleted:
trunk/identity/src/main/org/jboss/portal/identity/experimental/db/HibernateUserProfileModuleImpl.java
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/experimental/db/HibernateUserProfileModuleImpl.java 2006-12-15
15:15:26 UTC (rev 5871)
+++
trunk/identity/src/main/org/jboss/portal/identity/experimental/db/HibernateUserProfileModuleImpl.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -1,173 +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.experimental.db;
-
-import org.jboss.portal.identity2.experimental.db.HibernateUserImpl;
-import org.jboss.portal.identity2.User;
-import org.jboss.portal.identity2.service.UserProfileModuleService;
-import org.hibernate.SessionFactory;
-import org.hibernate.Session;
-
-import javax.naming.InitialContext;
-import java.util.Map;
-
-/**
- * @author <a href="mailto:boleslaw.dawidowicz@jboss.org">Boleslaw
Dawidowicz</a>
- * @version $Revision: 1.1 $
- */
-public class HibernateUserProfileModuleImpl extends UserProfileModuleService
-{
-
- /** . */
- private static final org.jboss.logging.Logger log =
org.jboss.logging.Logger.getLogger(HibernateUserProfileModuleImpl.class);
- /** . */
- protected SessionFactory sessionFactory;
-
- /** . */
- protected String sessionFactoryJNDIName;
-
- protected void startService() throws Exception
- {
- //
- sessionFactory = (SessionFactory)new
InitialContext().lookup(sessionFactoryJNDIName);
-
- super.startService();
-
- }
-
- protected void stopService() throws Exception
- {
- //
- sessionFactory = null;
- super.stopService();
- }
-
-// public SessionFactory getSessionFactory()
-// {
-// return sessionFactory;
-// }
-
- public String getSessionFactoryJNDIName()
- {
- return sessionFactoryJNDIName;
- }
-
- public void setSessionFactoryJNDIName(String sessionFactoryJNDIName)
- {
- this.sessionFactoryJNDIName = sessionFactoryJNDIName;
- }
-
- public Object 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");
- }
-
- HibernateUserImpl dbUser = null;
-
- if (user instanceof HibernateUserImpl)
- {
- dbUser = (HibernateUserImpl)user;
- }
- else
- {
- throw new IllegalArgumentException("This UserProfileModule implementation
support only DBDBUserImpl objects");
- }
-
- throw new UnsupportedOperationException("Not yet implemented");
- }
-
- public void setProperty(User user, String propertyName, Object propertyValue)
- {
- if (user == null)
- {
- throw new IllegalArgumentException("User cannot be null");
- }
- if (propertyName == null)
- {
- throw new IllegalArgumentException("Property name need to have
value");
- }
-
- HibernateUserImpl dbUser = null;
-
- if (user instanceof HibernateUserImpl)
- {
- dbUser = (HibernateUserImpl)user;
- }
- else
- {
- throw new IllegalArgumentException("This UserProfileModule implementation
support only DBDBUserImpl objects");
- }
-
- //if value is null reset property
-
- throw new UnsupportedOperationException("Not yet implemented");
- }
-
- public Map getProperties(User user)
- {
- if (user == null)
- {
- throw new IllegalArgumentException("User cannot be null");
- }
-
- HibernateUserImpl dbUser = null;
-
- if (user instanceof HibernateUserImpl)
- {
- dbUser = (HibernateUserImpl)user;
- }
- else
- {
- throw new IllegalArgumentException("This UserProfileModule implementation
support only DBDBUserImpl objects");
- }
-
-
- throw new UnsupportedOperationException("Not yet implemented");
- }
-
- /**
- * Can be subclasses to provide testing in a non JTA environement.
- *
- * @throws IllegalStateException if no session factory is present
- */
- protected Session getCurrentSession() throws IllegalStateException
- {
- return getSessionFactory().getCurrentSession();//.getSession(EntityMode.MAP);
-
- }
-
- protected SessionFactory getSessionFactory() throws IllegalStateException
- {
- if (sessionFactory == null)
- {
- throw new IllegalStateException("No session factory");
- }
- return sessionFactory;//.getCurrentSession();
- }
-}
Copied:
trunk/identity/src/main/org/jboss/portal/identity/experimental/db/HibernateUserProfileModuleImpl.java
(from rev 5883,
trunk/identity/src/main/org/jboss/portal/identity2/experimental/db/HibernateUserProfileModuleImpl.java)
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/experimental/db/HibernateUserProfileModuleImpl.java 2006-12-17
14:26:07 UTC (rev 5883)
+++
trunk/identity/src/main/org/jboss/portal/identity/experimental/db/HibernateUserProfileModuleImpl.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -0,0 +1,181 @@
+/******************************************************************************
+ * 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.identity.experimental.db;
+
+import org.jboss.portal.identity.experimental.db.HibernateUserImpl;
+import org.jboss.portal.identity.User;
+import org.jboss.portal.identity.IdentityException;
+import org.jboss.portal.identity.info.ProfileInfo;
+import org.jboss.portal.identity.service.UserProfileModuleService;
+import org.hibernate.SessionFactory;
+import org.hibernate.Session;
+
+import javax.naming.InitialContext;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz@jboss.org">Boleslaw
Dawidowicz</a>
+ * @version $Revision: 1.1 $
+ */
+public class HibernateUserProfileModuleImpl //extends UserProfileModuleService
+{
+
+// /** . */
+// private static final org.jboss.logging.Logger log =
org.jboss.logging.Logger.getLogger(HibernateUserProfileModuleImpl.class);
+// /** . */
+// protected SessionFactory sessionFactory;
+//
+// /** . */
+// protected String sessionFactoryJNDIName;
+//
+// protected void startService() throws Exception
+// {
+// //
+// sessionFactory = (SessionFactory)new
InitialContext().lookup(sessionFactoryJNDIName);
+//
+// super.startService();
+//
+// }
+//
+// protected void stopService() throws Exception
+// {
+// //
+// sessionFactory = null;
+// super.stopService();
+// }
+//
+//// public SessionFactory getSessionFactory()
+//// {
+//// return sessionFactory;
+//// }
+//
+// public String getSessionFactoryJNDIName()
+// {
+// return sessionFactoryJNDIName;
+// }
+//
+// public void setSessionFactoryJNDIName(String sessionFactoryJNDIName)
+// {
+// this.sessionFactoryJNDIName = sessionFactoryJNDIName;
+// }
+//
+// public Object 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");
+// }
+//
+// HibernateUserImpl dbUser = null;
+//
+// if (user instanceof HibernateUserImpl)
+// {
+// dbUser = (HibernateUserImpl)user;
+// }
+// else
+// {
+// throw new IllegalArgumentException("This UserProfileModule implementation
support only DBDBUserImpl objects");
+// }
+//
+// throw new UnsupportedOperationException("Not yet implemented");
+// }
+//
+// public void setProperty(User user, String propertyName, Object propertyValue)
+// {
+// if (user == null)
+// {
+// throw new IllegalArgumentException("User cannot be null");
+// }
+// if (propertyName == null)
+// {
+// throw new IllegalArgumentException("Property name need to have
value");
+// }
+//
+// HibernateUserImpl dbUser = null;
+//
+// if (user instanceof HibernateUserImpl)
+// {
+// dbUser = (HibernateUserImpl)user;
+// }
+// else
+// {
+// throw new IllegalArgumentException("This UserProfileModule implementation
support only DBDBUserImpl objects");
+// }
+//
+// //if value is null reset property
+//
+// throw new UnsupportedOperationException("Not yet implemented");
+// }
+//
+// public Map getProperties(User user)
+// {
+// if (user == null)
+// {
+// throw new IllegalArgumentException("User cannot be null");
+// }
+//
+// HibernateUserImpl dbUser = null;
+//
+// if (user instanceof HibernateUserImpl)
+// {
+// dbUser = (HibernateUserImpl)user;
+// }
+// else
+// {
+// throw new IllegalArgumentException("This UserProfileModule implementation
support only DBDBUserImpl objects");
+// }
+//
+//
+// throw new UnsupportedOperationException("Not yet implemented");
+// }
+//
+//
+// public ProfileInfo getProfileInfo() throws IdentityException
+// {
+// return null; //To change body of implemented methods use File | Settings | File
Templates.
+// }
+//
+// /**
+// * Can be subclasses to provide testing in a non JTA environement.
+// *
+// * @throws IllegalStateException if no session factory is present
+// */
+// protected Session getCurrentSession() throws IllegalStateException
+// {
+// return getSessionFactory().getCurrentSession();//.getSession(EntityMode.MAP);
+//
+// }
+//
+// protected SessionFactory getSessionFactory() throws IllegalStateException
+// {
+// if (sessionFactory == null)
+// {
+// throw new IllegalStateException("No session factory");
+// }
+// return sessionFactory;//.getCurrentSession();
+// }
+}
Deleted:
trunk/identity/src/main/org/jboss/portal/identity/experimental/db/IdentitySessionFactoryBinder.java
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/experimental/db/IdentitySessionFactoryBinder.java 2006-12-15
15:15:26 UTC (rev 5871)
+++
trunk/identity/src/main/org/jboss/portal/identity/experimental/db/IdentitySessionFactoryBinder.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -1,119 +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.experimental.db;
-
-import org.jboss.portal.jems.hibernate.SessionFactoryBinder;
-import org.jboss.portal.identity2.info.ProfileInfo;
-import org.jboss.portal.identity2.config.metadata.profile.ProfileMetaData;
-import org.jboss.portal.identity2.config.metadata.ConfigurationParser;
-import org.jboss.portal.identity2.config.info.ProfileInfoSupport;
-
-/**
- * @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw
Dawidowicz</a>
- * @version $Revision: 1.1 $
- */
-public class IdentitySessionFactoryBinder extends SessionFactoryBinder
-{
-
- private static final org.jboss.logging.Logger log =
org.jboss.logging.Logger.getLogger(IdentitySessionFactoryBinder.class);
-
- private String profileConfigFile;
-
- private String mappingTemplateFile;
-
- private String mappingOutputFile;
-
- private String mappingPattern;
-
- private ProfileInfo profileInfo;
-
- protected void createService() throws Exception
- {
- ClassLoader tcl = Thread.currentThread().getContextClassLoader();
-
-
- //parse profile config
- ProfileMetaData meta =
ConfigurationParser.parseProfileConfiguration(getProfileConfigFile());
- profileInfo = new ProfileInfoSupport(meta);
-
- //process files
- HibernateHelper.generateProfileMappings(getMappingTemplateFile(),
getMappingOutputFile(), getMappingPattern(), profileInfo, tcl);
-
- //create configuration
- super.createService();
-
- //set MAP entity mode
-
config.setProperty("hibernate.default_entity_mode","dynamic-map");
-
- //inject generated mappings into configuration
- config.addFile(getMappingOutputFile());
-
-
- }
-
-
- protected void startService() throws Exception
- {
- //super.startService(); //To change body of overridden methods use File |
Settings | File Templates.
- }
-
-
- public String getProfileConfigFile()
- {
- return profileConfigFile;
- }
-
- public void setProfileConfigFile(String profileConfigFile)
- {
- this.profileConfigFile = profileConfigFile;
- }
-
- public String getMappingTemplateFile()
- {
- return mappingTemplateFile;
- }
-
- public void setMappingTemplateFile(String mappingTemplateFile)
- {
- this.mappingTemplateFile = mappingTemplateFile;
- }
-
- public String getMappingOutputFile()
- {
- return mappingOutputFile;
- }
-
- public void setMappingOutputFile(String mappingOutputFile)
- {
- this.mappingOutputFile = mappingOutputFile;
- }
-
- public String getMappingPattern()
- {
- return mappingPattern;
- }
-
- public void setMappingPattern(String mappingPattern)
- {
- this.mappingPattern = mappingPattern;
- }
-}
Copied:
trunk/identity/src/main/org/jboss/portal/identity/experimental/db/IdentitySessionFactoryBinder.java
(from rev 5883,
trunk/identity/src/main/org/jboss/portal/identity2/experimental/db/IdentitySessionFactoryBinder.java)
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/experimental/db/IdentitySessionFactoryBinder.java 2006-12-17
14:26:07 UTC (rev 5883)
+++
trunk/identity/src/main/org/jboss/portal/identity/experimental/db/IdentitySessionFactoryBinder.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -0,0 +1,119 @@
+/*
+* 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.identity.experimental.db;
+
+import org.jboss.portal.jems.hibernate.SessionFactoryBinder;
+import org.jboss.portal.identity.info.ProfileInfo;
+import org.jboss.portal.identity.config.metadata.profile.ProfileMetaData;
+import org.jboss.portal.identity.config.metadata.ConfigurationParser;
+import org.jboss.portal.identity.config.info.ProfileInfoSupport;
+
+/**
+ * @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw
Dawidowicz</a>
+ * @version $Revision: 1.1 $
+ */
+public class IdentitySessionFactoryBinder //extends SessionFactoryBinder
+{
+
+// private static final org.jboss.logging.Logger log =
org.jboss.logging.Logger.getLogger(IdentitySessionFactoryBinder.class);
+//
+// private String profileConfigFile;
+//
+// private String mappingTemplateFile;
+//
+// private String mappingOutputFile;
+//
+// private String mappingPattern;
+//
+// private ProfileInfo profileInfo;
+//
+// protected void createService() throws Exception
+// {
+// ClassLoader tcl = Thread.currentThread().getContextClassLoader();
+//
+//
+// //parse profile config
+// ProfileMetaData meta =
ConfigurationParser.parseProfileConfiguration(getProfileConfigFile());
+// profileInfo = new ProfileInfoSupport(meta);
+//
+// //process files
+// HibernateHelper.generateProfileMappings(getMappingTemplateFile(),
getMappingOutputFile(), getMappingPattern(), profileInfo, tcl);
+//
+// //create configuration
+// super.createService();
+//
+// //set MAP entity mode
+//
config.setProperty("hibernate.default_entity_mode","dynamic-map");
+//
+// //inject generated mappings into configuration
+// config.addFile(getMappingOutputFile());
+//
+//
+// }
+//
+//
+// protected void startService() throws Exception
+// {
+// //super.startService(); //To change body of overridden methods use File |
Settings | File Templates.
+// }
+//
+//
+// public String getProfileConfigFile()
+// {
+// return profileConfigFile;
+// }
+//
+// public void setProfileConfigFile(String profileConfigFile)
+// {
+// this.profileConfigFile = profileConfigFile;
+// }
+//
+// public String getMappingTemplateFile()
+// {
+// return mappingTemplateFile;
+// }
+//
+// public void setMappingTemplateFile(String mappingTemplateFile)
+// {
+// this.mappingTemplateFile = mappingTemplateFile;
+// }
+//
+// public String getMappingOutputFile()
+// {
+// return mappingOutputFile;
+// }
+//
+// public void setMappingOutputFile(String mappingOutputFile)
+// {
+// this.mappingOutputFile = mappingOutputFile;
+// }
+//
+// public String getMappingPattern()
+// {
+// return mappingPattern;
+// }
+//
+// public void setMappingPattern(String mappingPattern)
+// {
+// this.mappingPattern = mappingPattern;
+// }
+}
Copied: trunk/identity/src/main/org/jboss/portal/identity/info (from rev 5871,
trunk/identity/src/main/org/jboss/portal/identity2/info)
Deleted: trunk/identity/src/main/org/jboss/portal/identity/info/ProfileInfo.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/info/ProfileInfo.java 2006-12-15
15:15:26 UTC (rev 5871)
+++ trunk/identity/src/main/org/jboss/portal/identity/info/ProfileInfo.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -1,43 +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.info;
-
-import java.util.Set;
-import java.util.Map;
-
-/**
- * Class provides info about user profile
- *
- * @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw
Dawidowicz</a>
- * @version $Revision: 1.1 $
- */
-public interface ProfileInfo
-{
- /**
- * Returns a Map o PropertyInfo objects describing profile properties
- * @return Map of PropertyInfo objects
- */
- public Map getPropertiesInfo();
-
- public PropertyInfo getPropertyInfo(String name);
-
-}
Copied: trunk/identity/src/main/org/jboss/portal/identity/info/ProfileInfo.java (from rev
5883, trunk/identity/src/main/org/jboss/portal/identity2/info/ProfileInfo.java)
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/info/ProfileInfo.java 2006-12-17
14:26:07 UTC (rev 5883)
+++ trunk/identity/src/main/org/jboss/portal/identity/info/ProfileInfo.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -0,0 +1,42 @@
+/*
+* 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.identity.info;
+
+import java.util.Map;
+
+/**
+ * Class provides info about user profile
+ *
+ * @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw
Dawidowicz</a>
+ * @version $Revision: 1.1 $
+ */
+public interface ProfileInfo
+{
+ /**
+ * Returns a Map o PropertyInfo objects describing profile properties
+ * @return Map of PropertyInfo objects
+ */
+ public Map getPropertiesInfo();
+
+ public PropertyInfo getPropertyInfo(String name);
+
+}
Deleted: trunk/identity/src/main/org/jboss/portal/identity/info/PropertyInfo.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/info/PropertyInfo.java 2006-12-15
15:15:26 UTC (rev 5871)
+++ trunk/identity/src/main/org/jboss/portal/identity/info/PropertyInfo.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -1,65 +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.info;
-
-import org.jboss.portal.common.util.LocalizedString;
-
-
-/**
- * @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw
Dawidowicz</a>
- * @version $Revision: 1.1 $
- */
-public interface PropertyInfo
-{
-
- //TODO: make it int or safe type enum
- public static final String ACCESS_MODE_READ_ONLY = "read-only";
- public static final String ACCESS_MODE_READ_WRITE = "read-write";
- public static final String USAGE_MANDATORY = "mandatory";
- public static final String USAGE_OPTIONAL = "optional";
- public static final String MAPPING_DB_TYPE_COLUMN = "column";
- public static final String MAPPING_DB_TYPE_DYNAMIC = "dynamic";
-
- public String getName();
-
- public String getType();
-
- public String getAccessMode();
-
- public String getUsage();
-
- public LocalizedString getDisplayName();
-
- public LocalizedString getDescription();
-
- public String getMappingDBType();
-
- public String getMappingLDAPValue();
-
- public String getMappingDBValue();
-
- public boolean isMappedDB();
-
- public boolean isMappedLDAP();
-
-
-}
Copied: trunk/identity/src/main/org/jboss/portal/identity/info/PropertyInfo.java (from rev
5883, trunk/identity/src/main/org/jboss/portal/identity2/info/PropertyInfo.java)
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/info/PropertyInfo.java 2006-12-17
14:26:07 UTC (rev 5883)
+++ trunk/identity/src/main/org/jboss/portal/identity/info/PropertyInfo.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -0,0 +1,65 @@
+/*
+* 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.identity.info;
+
+import org.jboss.portal.common.util.LocalizedString;
+
+
+/**
+ * @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw
Dawidowicz</a>
+ * @version $Revision: 1.1 $
+ */
+public interface PropertyInfo
+{
+
+ //TODO: make it int or safe type enum
+ public static final String ACCESS_MODE_READ_ONLY = "read-only";
+ public static final String ACCESS_MODE_READ_WRITE = "read-write";
+ public static final String USAGE_MANDATORY = "mandatory";
+ public static final String USAGE_OPTIONAL = "optional";
+ public static final String MAPPING_DB_TYPE_COLUMN = "column";
+ public static final String MAPPING_DB_TYPE_DYNAMIC = "dynamic";
+
+ public String getName();
+
+ public String getType();
+
+ public String getAccessMode();
+
+ public String getUsage();
+
+ public LocalizedString getDisplayName();
+
+ public LocalizedString getDescription();
+
+ public String getMappingDBType();
+
+ public String getMappingLDAPValue();
+
+ public String getMappingDBValue();
+
+ public boolean isMappedDB();
+
+ public boolean isMappedLDAP();
+
+
+}
Copied: trunk/identity/src/main/org/jboss/portal/identity/ldap (from rev 5871,
trunk/identity/src/main/org/jboss/portal/identity2/ldap)
Deleted:
trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPConnectionContext.java
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPConnectionContext.java 2006-12-15
15:15:26 UTC (rev 5871)
+++
trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPConnectionContext.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -1,259 +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.jems.as.system.AbstractJBossService;
-import org.jboss.portal.identity2.IdentityContext;
-import org.jboss.portal.identity2.IdentityConfiguration;
-import org.jboss.portal.identity2.service.IdentityModuleService;
-import org.jboss.portal.identity.IdentityException;
-import org.jboss.portal.common.util.JNDI;
-
-import javax.naming.Context;
-import javax.naming.NamingException;
-import javax.naming.ldap.InitialLdapContext;
-import java.util.Hashtable;
-
-/**
- * Keeps configuration of connection to LDAP server
- *
- * @author <a href="mailto:boleslaw.dawidowicz@jboss.org">Boleslaw
Dawidowicz</a>
- * @version $Revision: 1.1 $
- */
-public class LDAPConnectionContext extends AbstractJBossService
-{
- private static final org.jboss.logging.Logger log =
org.jboss.logging.Logger.getLogger(IdentityModuleService.class);
-
- private String jndiName;
-
- private JNDI.Binding jndiBinding;
-
-
- private String name;
-
- private String contextFactory;
-
- private String adminDN;
-
- private String adminPassword;
-
- private String protocol;
-
- private String authentication = "simple";
-
- private String host;
-
- private String port;
-
- /*public LDAPConnectionContext(String name,
- String url,
- String context,
- String admin,
- String password,
- String protocol,
- String authentication)
- {
- this.name = name;
- this.providerUrl = url;
- this.contextFactory = context;
- this.adminDN = admin;
- this.adminPassword = password;
- this.protocol = protocol;
- this.authentication = authentication;
- }*/
-
- /*public LDAPConnectionContext()
- {
- super(IdentityContext.TYPE_CONNECTION_CONTEXT);
- }*/
-
-
-
-
- public InitialLdapContext createInitialContext() throws IdentityException
- {
- try
- {
- Hashtable env = new Hashtable();
- env.put(Context.INITIAL_CONTEXT_FACTORY, this.getContextFactory());
- env.put(Context.PROVIDER_URL, "ldap://" + getHost() + ":" +
getPort());
- env.put(Context.SECURITY_AUTHENTICATION, this.getAuthentication());
- env.put(Context.SECURITY_PRINCIPAL, this.getAdminDN());
- env.put(Context.SECURITY_CREDENTIALS, this.getAdminPassword());
- return new InitialLdapContext(env, null);
- }
- catch (NamingException e)
- {
- throw new IdentityException("Unable to create ConnectionContext: " +
this, e);
- //return null;
- }
-
- }
-
-
- protected void startService() throws Exception
- {
-
- //
- if (jndiName != null)
- {
- log.debug("Binding identity module to JNDI with name: " + jndiName);
- jndiBinding = new JNDI.Binding(jndiName, this);
- jndiBinding.bind();
- }
-
- }
-
-
- protected void stopService() throws Exception
- {
- if (jndiBinding != null)
- {
- jndiBinding.unbind();
- jndiBinding = null;
- }
-
- }
-
- public String toString()
- {
- StringBuffer str = new StringBuffer();
- str.append("Name: ").append(getName())
- .append(", Host: ").append(getHost())
- .append(", Port: ").append(getPort())
- .append(", Context factory: ").append(getContextFactory())
- .append(", Admin user: ").append(getAdminDN())
- .append(", Admin password: ").append(getAdminPassword())
- .append(", Authentication: ").append(getAuthentication());
- return str.toString();
- }
-
- //************************************
- //******* Getters and Setters ********
- //************************************
- public String getAuthentication()
- {
- if (authentication == null)
- {
- return "simple";
- }
- return authentication;
- }
-
- public void setAuthentication(String authentication)
- {
- this.authentication = authentication;
- }
-
-
- public String getJndiName()
- {
- return jndiName;
- }
-
- public void setJndiName(String jndiName)
- {
- this.jndiName = jndiName;
- }
-
- public JNDI.Binding getJndiBinding()
- {
- return jndiBinding;
- }
-
- public void setJndiBinding(JNDI.Binding jndiBinding)
- {
- this.jndiBinding = jndiBinding;
- }
-
- public String getName()
- {
- return name;
- }
-
- public void setName(String name)
- {
- this.name = name;
- }
-
- public String getContextFactory()
- {
- return contextFactory;
- }
-
- public void setContextFactory(String contextFactory)
- {
- this.contextFactory = contextFactory;
- }
-
- public String getAdminDN()
- {
- return adminDN;
- }
-
- public void setAdminDN(String adminDN)
- {
- this.adminDN = adminDN;
- }
-
- public String getAdminPassword()
- {
- return adminPassword;
- }
-
- public void setAdminPassword(String adminPassword)
- {
- this.adminPassword = adminPassword;
- }
-
- public String getProtocol()
- {
- return protocol;
- }
-
- public void setProtocol(String protocol)
- {
- this.protocol = protocol;
- }
-
- public String getHost()
- {
- return host;
- }
-
- public void setHost(String host)
- {
- this.host = host;
- }
-
-
- public String getPort()
- {
- return port;
- }
-
- public void setPort(String port)
- {
- this.port = port;
- }
-}
Copied: trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPConnectionContext.java
(from rev 5883,
trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPConnectionContext.java)
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPConnectionContext.java 2006-12-17
14:26:07 UTC (rev 5883)
+++
trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPConnectionContext.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -0,0 +1,257 @@
+/******************************************************************************
+ * 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.identity.ldap;
+
+import org.jboss.portal.jems.as.system.AbstractJBossService;
+import org.jboss.portal.identity.service.IdentityModuleService;
+import org.jboss.portal.identity.IdentityException;
+import org.jboss.portal.common.util.JNDI;
+
+import javax.naming.Context;
+import javax.naming.NamingException;
+import javax.naming.ldap.InitialLdapContext;
+import java.util.Hashtable;
+
+/**
+ * Keeps configuration of connection to LDAP server
+ *
+ * @author <a href="mailto:boleslaw.dawidowicz@jboss.org">Boleslaw
Dawidowicz</a>
+ * @version $Revision: 1.1 $
+ */
+public class LDAPConnectionContext extends AbstractJBossService
+{
+ private static final org.jboss.logging.Logger log =
org.jboss.logging.Logger.getLogger(IdentityModuleService.class);
+
+ private String jndiName;
+
+ private JNDI.Binding jndiBinding;
+
+
+ private String name;
+
+ private String contextFactory;
+
+ private String adminDN;
+
+ private String adminPassword;
+
+ private String protocol;
+
+ private String authentication = "simple";
+
+ private String host;
+
+ private String port;
+
+ /*public LDAPConnectionContext(String name,
+ String url,
+ String context,
+ String admin,
+ String password,
+ String protocol,
+ String authentication)
+ {
+ this.name = name;
+ this.providerUrl = url;
+ this.contextFactory = context;
+ this.adminDN = admin;
+ this.adminPassword = password;
+ this.protocol = protocol;
+ this.authentication = authentication;
+ }*/
+
+ /*public LDAPConnectionContext()
+ {
+ super(IdentityContext.TYPE_CONNECTION_CONTEXT);
+ }*/
+
+
+
+
+ public InitialLdapContext createInitialContext() throws IdentityException
+ {
+ try
+ {
+ Hashtable env = new Hashtable();
+ env.put(Context.INITIAL_CONTEXT_FACTORY, this.getContextFactory());
+ env.put(Context.PROVIDER_URL, "ldap://" + getHost() + ":" +
getPort());
+ env.put(Context.SECURITY_AUTHENTICATION, this.getAuthentication());
+ env.put(Context.SECURITY_PRINCIPAL, this.getAdminDN());
+ env.put(Context.SECURITY_CREDENTIALS, this.getAdminPassword());
+ return new InitialLdapContext(env, null);
+ }
+ catch (NamingException e)
+ {
+ throw new IdentityException("Unable to create ConnectionContext: " +
this, e);
+ //return null;
+ }
+
+ }
+
+
+ protected void startService() throws Exception
+ {
+
+ //
+ if (jndiName != null)
+ {
+ log.debug("Binding identity module to JNDI with name: " + jndiName);
+ jndiBinding = new JNDI.Binding(jndiName, this);
+ jndiBinding.bind();
+ }
+
+ }
+
+
+ protected void stopService() throws Exception
+ {
+ if (jndiBinding != null)
+ {
+ jndiBinding.unbind();
+ jndiBinding = null;
+ }
+
+ }
+
+ public String toString()
+ {
+ StringBuffer str = new StringBuffer();
+ str.append("Name: ").append(getName())
+ .append(", Host: ").append(getHost())
+ .append(", Port: ").append(getPort())
+ .append(", Context factory: ").append(getContextFactory())
+ .append(", Admin user: ").append(getAdminDN())
+ .append(", Admin password: ").append(getAdminPassword())
+ .append(", Authentication: ").append(getAuthentication());
+ return str.toString();
+ }
+
+ //************************************
+ //******* Getters and Setters ********
+ //************************************
+ public String getAuthentication()
+ {
+ if (authentication == null)
+ {
+ return "simple";
+ }
+ return authentication;
+ }
+
+ public void setAuthentication(String authentication)
+ {
+ this.authentication = authentication;
+ }
+
+
+ public String getJndiName()
+ {
+ return jndiName;
+ }
+
+ public void setJndiName(String jndiName)
+ {
+ this.jndiName = jndiName;
+ }
+
+ public JNDI.Binding getJndiBinding()
+ {
+ return jndiBinding;
+ }
+
+ public void setJndiBinding(JNDI.Binding jndiBinding)
+ {
+ this.jndiBinding = jndiBinding;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public void setName(String name)
+ {
+ this.name = name;
+ }
+
+ public String getContextFactory()
+ {
+ return contextFactory;
+ }
+
+ public void setContextFactory(String contextFactory)
+ {
+ this.contextFactory = contextFactory;
+ }
+
+ public String getAdminDN()
+ {
+ return adminDN;
+ }
+
+ public void setAdminDN(String adminDN)
+ {
+ this.adminDN = adminDN;
+ }
+
+ public String getAdminPassword()
+ {
+ return adminPassword;
+ }
+
+ public void setAdminPassword(String adminPassword)
+ {
+ this.adminPassword = adminPassword;
+ }
+
+ public String getProtocol()
+ {
+ return protocol;
+ }
+
+ public void setProtocol(String protocol)
+ {
+ this.protocol = protocol;
+ }
+
+ public String getHost()
+ {
+ return host;
+ }
+
+ public void setHost(String host)
+ {
+ this.host = host;
+ }
+
+
+ public String getPort()
+ {
+ return port;
+ }
+
+ public void setPort(String port)
+ {
+ this.port = port;
+ }
+}
Deleted:
trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPExtRoleModuleImpl.java
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPExtRoleModuleImpl.java 2006-12-15
15:15:26 UTC (rev 5871)
+++
trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPExtRoleModuleImpl.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -1,77 +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.identity.IdentityException;
-import org.jboss.portal.identity2.Role;
-import org.jboss.portal.jems.as.system.AbstractJBossService;
-
-import java.util.Set;
-
-/**
- * @author <a href="mailto:boleslaw.dawidowicz@jboss.org">Boleslaw
Dawidowicz</a>
- * @version $Revision: 1.1 $
- */
-public class LDAPExtRoleModuleImpl extends LDAPRoleModuleImpl
-{
-
- public Role findRoleByName(String name) throws IdentityException,
IllegalArgumentException
- {
- throw new UnsupportedOperationException("Not yet implemented");
- }
-
- public Set findRolesByNames(String[] names) throws IdentityException,
IllegalArgumentException
- {
- throw new UnsupportedOperationException("Not yet implemented");
- }
-
- public Role findRoleById(Object id) throws IdentityException,
IllegalArgumentException
- {
- throw new UnsupportedOperationException("Not yet implemented");
- }
-
- public Role findRoleById(String id) throws IdentityException,
IllegalArgumentException
- {
- throw new UnsupportedOperationException("Not yet implemented");
- }
-
- public Role createRole(String name, String displayName) throws IdentityException,
IllegalArgumentException
- {
- throw new UnsupportedOperationException("Role management is not supported in
this implementation of RoleModule");
- }
-
- public void removeRole(Object id) throws IdentityException, IllegalArgumentException
- {
- throw new UnsupportedOperationException("Role management is not supported in
this implementation of RoleModule");
- }
-
- public int getRolesCount() throws IdentityException
- {
- throw new UnsupportedOperationException("Not yet implemented");
- }
-
- public Set findRoles() throws IdentityException
- {
- throw new UnsupportedOperationException("Not yet implemented");
- }
-}
Copied: trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPExtRoleModuleImpl.java
(from rev 5883,
trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPExtRoleModuleImpl.java)
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPExtRoleModuleImpl.java 2006-12-17
14:26:07 UTC (rev 5883)
+++
trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPExtRoleModuleImpl.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -0,0 +1,76 @@
+/******************************************************************************
+ * 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.identity.ldap;
+
+import org.jboss.portal.identity.IdentityException;
+import org.jboss.portal.identity.Role;
+
+import java.util.Set;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz@jboss.org">Boleslaw
Dawidowicz</a>
+ * @version $Revision: 1.1 $
+ */
+public class LDAPExtRoleModuleImpl extends LDAPRoleModuleImpl
+{
+
+ public Role findRoleByName(String name) throws IdentityException,
IllegalArgumentException
+ {
+ throw new UnsupportedOperationException("Not yet implemented");
+ }
+
+ public Set findRolesByNames(String[] names) throws IdentityException,
IllegalArgumentException
+ {
+ throw new UnsupportedOperationException("Not yet implemented");
+ }
+
+ public Role findRoleById(Object id) throws IdentityException,
IllegalArgumentException
+ {
+ throw new UnsupportedOperationException("Not yet implemented");
+ }
+
+ public Role findRoleById(String id) throws IdentityException,
IllegalArgumentException
+ {
+ throw new UnsupportedOperationException("Not yet implemented");
+ }
+
+ public Role createRole(String name, String displayName) throws IdentityException,
IllegalArgumentException
+ {
+ throw new UnsupportedOperationException("Role management is not supported in
this implementation of RoleModule");
+ }
+
+ public void removeRole(Object id) throws IdentityException, IllegalArgumentException
+ {
+ throw new UnsupportedOperationException("Role management is not supported in
this implementation of RoleModule");
+ }
+
+ public int getRolesCount() throws IdentityException
+ {
+ throw new UnsupportedOperationException("Not yet implemented");
+ }
+
+ public Set findRoles() throws IdentityException
+ {
+ throw new UnsupportedOperationException("Not yet implemented");
+ }
+}
Deleted:
trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPExtUserModuleImpl.java
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPExtUserModuleImpl.java 2006-12-15
15:15:26 UTC (rev 5871)
+++
trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPExtUserModuleImpl.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -1,78 +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.identity.IdentityException;
-import org.jboss.portal.identity.NoSuchUserException;
-import org.jboss.portal.identity2.User;
-import org.jboss.portal.jems.as.system.AbstractJBossService;
-
-import java.util.Set;
-
-/**
- * @author <a href="mailto:boleslaw.dawidowicz@jboss.org">Boleslaw
Dawidowicz</a>
- * @version $Revision: 1.1 $
- */
-public class LDAPExtUserModuleImpl extends LDAPUserModuleImpl
-{
-
- public User findUserByUserName(String userName) throws IdentityException,
IllegalArgumentException, NoSuchUserException
- {
- throw new UnsupportedOperationException("Not yet implemented");
- }
-
- public User findUserById(Object id) throws IdentityException,
IllegalArgumentException, NoSuchUserException
- {
- throw new UnsupportedOperationException("Not yet implemented");
- }
-
- public User findUserById(String id) throws IdentityException,
IllegalArgumentException, NoSuchUserException
- {
- throw new UnsupportedOperationException("Not yet implemented");
- }
-
- public User createUser(String userName, String password, String realEmail) throws
IdentityException, IllegalArgumentException
- {
- throw new UnsupportedOperationException("User management is not supported in
this implementation of UserModule");
- }
-
- public void removeUser(Object id) throws IdentityException, IllegalArgumentException
- {
- throw new UnsupportedOperationException("User management is not supported in
this implementation of UserModule");
- }
-
- public Set findUsers(int offset, int limit) throws IdentityException,
IllegalArgumentException
- {
- throw new UnsupportedOperationException("Not yet implemented");
- }
-
- public Set findUsersFilteredByUserName(String filter, int offset, int limit) throws
IdentityException, IllegalArgumentException
- {
- throw new UnsupportedOperationException("Not yet implemented");
- }
-
- public int getUserCount() throws IdentityException, IllegalArgumentException
- {
- throw new UnsupportedOperationException("Not yet implemented");
- }
-}
Copied: trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPExtUserModuleImpl.java
(from rev 5883,
trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPExtUserModuleImpl.java)
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPExtUserModuleImpl.java 2006-12-17
14:26:07 UTC (rev 5883)
+++
trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPExtUserModuleImpl.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -0,0 +1,77 @@
+/******************************************************************************
+ * 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.identity.ldap;
+
+import org.jboss.portal.identity.IdentityException;
+import org.jboss.portal.identity.NoSuchUserException;
+import org.jboss.portal.identity.User;
+
+import java.util.Set;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz@jboss.org">Boleslaw
Dawidowicz</a>
+ * @version $Revision: 1.1 $
+ */
+public class LDAPExtUserModuleImpl extends LDAPUserModuleImpl
+{
+
+ public User findUserByUserName(String userName) throws IdentityException,
IllegalArgumentException, NoSuchUserException
+ {
+ throw new UnsupportedOperationException("Not yet implemented");
+ }
+
+ public User findUserById(Object id) throws IdentityException,
IllegalArgumentException, NoSuchUserException
+ {
+ throw new UnsupportedOperationException("Not yet implemented");
+ }
+
+ public User findUserById(String id) throws IdentityException,
IllegalArgumentException, NoSuchUserException
+ {
+ throw new UnsupportedOperationException("Not yet implemented");
+ }
+
+ public User createUser(String userName, String password, String realEmail) throws
IdentityException, IllegalArgumentException
+ {
+ throw new UnsupportedOperationException("User management is not supported in
this implementation of UserModule");
+ }
+
+ public void removeUser(Object id) throws IdentityException, IllegalArgumentException
+ {
+ throw new UnsupportedOperationException("User management is not supported in
this implementation of UserModule");
+ }
+
+ public Set findUsers(int offset, int limit) throws IdentityException,
IllegalArgumentException
+ {
+ throw new UnsupportedOperationException("Not yet implemented");
+ }
+
+ public Set findUsersFilteredByUserName(String filter, int offset, int limit) throws
IdentityException, IllegalArgumentException
+ {
+ throw new UnsupportedOperationException("Not yet implemented");
+ }
+
+ public int getUserCount() throws IdentityException, IllegalArgumentException
+ {
+ throw new UnsupportedOperationException("Not yet implemented");
+ }
+}
Deleted: trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPMembershipModule.java
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPMembershipModule.java 2006-12-15
15:15:26 UTC (rev 5871)
+++
trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPMembershipModule.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -1,127 +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.IdentityContext;
-import org.jboss.portal.identity2.IdentityConfiguration;
-import org.jboss.portal.identity2.service.MembershipModuleService;
-import org.jboss.portal.identity.IdentityException;
-
-import javax.naming.InitialContext;
-
-/**
- * @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw
Dawidowicz</a>
- * @version $Revision: 1.1 $
- */
-public abstract class LDAPMembershipModule extends MembershipModuleService
-{
- private static final org.jboss.logging.Logger log =
org.jboss.logging.Logger.getLogger(LDAPMembershipModule.class);
-
- private LDAPConnectionContext connectionContext;
-
- private LDAPUserModule userModule;
-
- private LDAPRoleModule roleModule;
-
- protected void startService() throws Exception
- {
- if (getConnectionJNDIName() == null)
- {
- throw new IdentityException("Cannot obtain ldap connection context JNDI
name");
- }
-
- connectionContext = (LDAPConnectionContext)new
InitialContext().lookup(getConnectionJNDIName());
-
- super.startService(); //To change body of overridden methods use File | Settings
| File Templates.
- }
-
- //************************************
- //******* Getters and Setters ********
- //************************************
-
- protected LDAPConnectionContext getConnectionContext() throws IdentityException
- {
- if (connectionContext == null)
- {
- //this.connectionContext =
(LDAPConnectionContext)getIdentityContext().getObject(IdentityContext.TYPE_CONNECTION_CONTEXT);
- throw new IdentityException("No LDAPConnectionContext available");
- }
- return connectionContext;
- }
-
-
-
- protected LDAPUserModule getUserModule() throws IdentityException
- {
-
- if (userModule == null)
- {
- try
- {
- this.userModule =
(LDAPUserModule)getIdentityContext().getObject(IdentityContext.TYPE_USER_MODULE);
- }
- catch (ClassCastException e)
- {
- throw new IdentityException("Not supported object as part of the context
- must be LDAPUserModule", e);
- }
- }
- return userModule;
- }
-
- protected LDAPRoleModule getRoleModule() throws IdentityException
- {
-
- if (roleModule == null)
- {
- try
- {
- this.roleModule =
(LDAPRoleModule)getIdentityContext().getObject(IdentityContext.TYPE_ROLE_MODULE);
- }
- catch (ClassCastException e)
- {
- throw new IdentityException("Not supported object as part of the
context", e);
- }
- }
- return roleModule;
- }
-
- protected String getMemberAttributeID() throws IdentityException
- {
- String uid =
getIdentityConfiguration().getValue(IdentityConfiguration.MEMBERSHIP_ATTRIBUTE_ID);
- if (uid == null)
- {
- return "member";
- }
- return uid;
- }
-
- protected boolean isUidAttributeIsDN() throws IdentityException
- {
- if
(getIdentityConfiguration().getValue(IdentityConfiguration.MEMBERSHIP_ATTRIBUTE_IS_DN) ==
null)
- {
- return true;
- }
-
- return
getIdentityConfiguration().getValue(IdentityConfiguration.MEMBERSHIP_ATTRIBUTE_IS_DN).equals("true");
- }
-
-}
Copied: trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPMembershipModule.java
(from rev 5883,
trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPMembershipModule.java)
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPMembershipModule.java 2006-12-17
14:26:07 UTC (rev 5883)
+++
trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPMembershipModule.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -0,0 +1,127 @@
+/*
+* 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.identity.ldap;
+
+import org.jboss.portal.identity.IdentityContext;
+import org.jboss.portal.identity.IdentityConfiguration;
+import org.jboss.portal.identity.service.MembershipModuleService;
+import org.jboss.portal.identity.IdentityException;
+
+import javax.naming.InitialContext;
+
+/**
+ * @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw
Dawidowicz</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class LDAPMembershipModule extends MembershipModuleService
+{
+ private static final org.jboss.logging.Logger log =
org.jboss.logging.Logger.getLogger(LDAPMembershipModule.class);
+
+ private LDAPConnectionContext connectionContext;
+
+ private LDAPUserModule userModule;
+
+ private LDAPRoleModule roleModule;
+
+ protected void startService() throws Exception
+ {
+ if (getConnectionJNDIName() == null)
+ {
+ throw new IdentityException("Cannot obtain ldap connection context JNDI
name");
+ }
+
+ connectionContext = (LDAPConnectionContext)new
InitialContext().lookup(getConnectionJNDIName());
+
+ super.startService(); //To change body of overridden methods use File | Settings
| File Templates.
+ }
+
+ //************************************
+ //******* Getters and Setters ********
+ //************************************
+
+ protected LDAPConnectionContext getConnectionContext() throws IdentityException
+ {
+ if (connectionContext == null)
+ {
+ //this.connectionContext =
(LDAPConnectionContext)getIdentityContext().getObject(IdentityContext.TYPE_CONNECTION_CONTEXT);
+ throw new IdentityException("No LDAPConnectionContext available");
+ }
+ return connectionContext;
+ }
+
+
+
+ protected LDAPUserModule getUserModule() throws IdentityException
+ {
+
+ if (userModule == null)
+ {
+ try
+ {
+ this.userModule =
(LDAPUserModule)getIdentityContext().getObject(IdentityContext.TYPE_USER_MODULE);
+ }
+ catch (ClassCastException e)
+ {
+ throw new IdentityException("Not supported object as part of the context
- must be LDAPUserModule", e);
+ }
+ }
+ return userModule;
+ }
+
+ protected LDAPRoleModule getRoleModule() throws IdentityException
+ {
+
+ if (roleModule == null)
+ {
+ try
+ {
+ this.roleModule =
(LDAPRoleModule)getIdentityContext().getObject(IdentityContext.TYPE_ROLE_MODULE);
+ }
+ catch (ClassCastException e)
+ {
+ throw new IdentityException("Not supported object as part of the
context", e);
+ }
+ }
+ return roleModule;
+ }
+
+ protected String getMemberAttributeID() throws IdentityException
+ {
+ String uid =
getIdentityConfiguration().getValue(IdentityConfiguration.MEMBERSHIP_ATTRIBUTE_ID);
+ if (uid == null)
+ {
+ return "member";
+ }
+ return uid;
+ }
+
+ protected boolean isUidAttributeIsDN() throws IdentityException
+ {
+ if
(getIdentityConfiguration().getValue(IdentityConfiguration.MEMBERSHIP_ATTRIBUTE_IS_DN) ==
null)
+ {
+ return true;
+ }
+
+ return
getIdentityConfiguration().getValue(IdentityConfiguration.MEMBERSHIP_ATTRIBUTE_IS_DN).equals("true");
+ }
+
+}
Deleted: trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPRoleImpl.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPRoleImpl.java 2006-12-15
15:15:26 UTC (rev 5871)
+++ trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPRoleImpl.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -1,133 +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.Role;
-import org.jboss.portal.identity.IdentityException;
-import org.jboss.portal.identity2.IdentityContext;
-import org.jboss.portal.identity2.MembershipModule;
-
-import java.util.Set;
-
-/**
- * @author <a href="mailto:boleslaw.dawidowicz@jboss.org">Boleslaw
Dawidowicz</a>
- * @version $Revision: 1.1 $
- */
-public class LDAPRoleImpl implements Role
-{
- private static final org.jboss.logging.Logger log =
org.jboss.logging.Logger.getLogger(LDAPRoleImpl.class);
-
- //TODO: make setters to update the state of the entry
-
- //TODO:only to make a fasade for implementing old Role interface
- private IdentityContext identityContext;
-
- private String dn;
-
- private String id;
-
- private String displayName;
-
- private LDAPRoleImpl()
- {
-
- }
-
- public LDAPRoleImpl(String dn, IdentityContext context, String id, String display)
- {
- if (dn == null)
- {
- throw new IllegalArgumentException("LDAPRoleImpl need to be aware of its
DN");
- }
-
-
- if (context == null)
- {
- throw new IllegalArgumentException("IdentityContext can't be
null");
- }
-
- if (id == null)
- {
- throw new IllegalArgumentException("Id can't be null");
- }
-
- if (display == null)
- {
- throw new IllegalArgumentException("displayName can't be null");
- }
-
- this.identityContext = context;
- this.id = id;
- this.displayName = display;
- this.dn = dn;
- }
-
- public String getName()
- {
- return this.id;
- }
-
- public String getDisplayName()
- {
- return displayName;
- }
-
- public void setDisplayName(String name)
- {
- this.displayName = name;
- }
-
- //TODO: fasade to MembershipModule.getUsers() method call - change this
-// public Set getUsers()
-// {
-// try
-// {
-// MembershipModule mm =
(MembershipModule)identityContext.getObject(IdentityContext.TYPE_MEMBERSHIP_MODULE);
-// return mm.getUsers(this);
-// }
-// catch (IdentityException e)
-// {
-// log.error("Unable to delegate method to MembershipModule: ", e);
-// }
-// return null;
-// }
-
-
- //**************************
- //*** Getter and Setters
- //**************************
- public String getDn()
- {
- return dn;
- }
-
- public void setId(String id)
- {
- this.id = id;
- }
-
- public Object getId()
- {
- return id;
- }
-}
Copied: trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPRoleImpl.java (from rev
5883, trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPRoleImpl.java)
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPRoleImpl.java 2006-12-17
14:26:07 UTC (rev 5883)
+++ trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPRoleImpl.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -0,0 +1,129 @@
+/******************************************************************************
+ * 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.identity.ldap;
+
+import org.jboss.portal.identity.Role;
+import org.jboss.portal.identity.IdentityContext;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz@jboss.org">Boleslaw
Dawidowicz</a>
+ * @version $Revision: 1.1 $
+ */
+public class LDAPRoleImpl implements Role
+{
+ private static final org.jboss.logging.Logger log =
org.jboss.logging.Logger.getLogger(LDAPRoleImpl.class);
+
+ //TODO: make setters to update the state of the entry
+
+ //TODO:only to make a fasade for implementing old Role interface
+ private IdentityContext identityContext;
+
+ private String dn;
+
+ private String id;
+
+ private String displayName;
+
+ private LDAPRoleImpl()
+ {
+
+ }
+
+ protected LDAPRoleImpl(String dn, IdentityContext context, String id, String display)
+ {
+ if (dn == null)
+ {
+ throw new IllegalArgumentException("LDAPRoleImpl need to be aware of its
DN");
+ }
+
+
+ if (context == null)
+ {
+ throw new IllegalArgumentException("IdentityContext can't be
null");
+ }
+
+ if (id == null)
+ {
+ throw new IllegalArgumentException("Id can't be null");
+ }
+
+ if (display == null)
+ {
+ throw new IllegalArgumentException("displayName can't be null");
+ }
+
+ this.identityContext = context;
+ this.id = id;
+ this.displayName = display;
+ this.dn = dn;
+ }
+
+ public String getName()
+ {
+ return this.id;
+ }
+
+ public String getDisplayName()
+ {
+ return displayName;
+ }
+
+ public void setDisplayName(String name)
+ {
+ this.displayName = name;
+ }
+
+ //TODO: fasade to MembershipModule.getUsers() method call - change this
+// public Set getUsers()
+// {
+// try
+// {
+// MembershipModule mm =
(MembershipModule)identityContext.getObject(IdentityContext.TYPE_MEMBERSHIP_MODULE);
+// return mm.getUsers(this);
+// }
+// catch (IdentityException e)
+// {
+// log.error("Unable to delegate method to MembershipModule: ", e);
+// }
+// return null;
+// }
+
+
+ //**************************
+ //*** Getter and Setters
+ //**************************
+ public String getDn()
+ {
+ return dn;
+ }
+
+ public void setId(String id)
+ {
+ this.id = id;
+ }
+
+ public Object getId()
+ {
+ return id;
+ }
+}
Deleted: trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPRoleModule.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPRoleModule.java 2006-12-15
15:15:26 UTC (rev 5871)
+++ trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPRoleModule.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -1,189 +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.identity.IdentityException;
-import org.jboss.portal.identity2.Role;
-import org.jboss.portal.identity2.IdentityContext;
-import org.jboss.portal.identity2.IdentityConfiguration;
-import org.jboss.portal.identity2.service.RoleModuleService;
-
-import javax.naming.directory.Attributes;
-import javax.naming.directory.Attribute;
-import javax.naming.NamingException;
-import javax.naming.NamingEnumeration;
-import javax.naming.InitialContext;
-import java.util.NoSuchElementException;
-
-/**
- * @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw
Dawidowicz</a>
- * @version $Revision: 1.1 $
- */
-public abstract class LDAPRoleModule extends RoleModuleService
-{
- private static final org.jboss.logging.Logger log =
org.jboss.logging.Logger.getLogger(LDAPRoleModule.class);
-
- private LDAPConnectionContext connectionContext;
-
-
- protected void startService() throws Exception
- {
- if (getConnectionJNDIName() == null)
- {
- throw new IdentityException("Cannot obtain ldap connection context JNDI
name");
- }
-
- connectionContext = (LDAPConnectionContext)new
InitialContext().lookup(getConnectionJNDIName());
-
- super.startService(); //To change body of overridden methods use File | Settings
| File Templates.
- }
-
-
- protected LDAPRoleImpl createRoleInstance(Attributes attrs, String dn) throws
IdentityException
- {
- LDAPRoleImpl ldapr = null;
- try
- {
-
- log.debug("Attributes: " + attrs);
-
- //role name
- Attribute uida = attrs.get(getRidAttributeID());
- if (uida == null)
- {
- throw new IdentityException("LDAP entry doesn't contain proper
attribute:" + getRidAttributeID());
- }
- //ldapr = new
LDAPRoleImpl(uida.getID().concat("=").concat((String)uida.get()) + ","
+ getContainerDN(), identityContext);
- Attribute display = attrs.get(getDisplayNameAttributeID());
- if (display == null)
- {
- throw new IdentityException("LDAP entry doesn't contain proper
attribute:" + getDisplayNameAttributeID());
- }
- ldapr = new LDAPRoleImpl(dn, getIdentityContext(), uida.get().toString(),
display.get().toString());
-
-
-
- log.debug("role uid: " + ldapr.getId());
- log.debug("role dn: " + ldapr.getDn());
-
-
- }
- catch (NamingException e)
- {
- throw new IdentityException("Couldn't create LDAPRoleImpl object from
ldap entry (SearchResult)", e);
- }
-
- return ldapr;
- }
-
- /**
- * method not belonging to UserModule interface - ldap specific.
- *
- */
- public Role findRoleByDN(String dn) throws IdentityException,
IllegalArgumentException
- {
- try
- {
- log.debug("findRoleByDN(): DN = " + dn);
-
- if (dn == null)
- {
- throw new IdentityException("Role dn canot be null");
- }
-
- Attributes attrs =
getConnectionContext().createInitialContext().getAttributes(dn);
-
- if (attrs == null)
- {
- throw new IdentityException("Can't find user entry with DN: " +
dn);
- }
-
- return createRoleInstance(attrs, dn);
-
- }
- catch (NoSuchElementException e)
- {
- log.debug("No user found with dn: " + dn, e);
- }
- catch (NamingException e)
- {
- throw new IdentityException("User search failed.", e);
- }
- return null;
- }
-
- /**
- * This method should be used by over modules to perform searches. It will allow role
module
- * implementation to apply proper filter and search scope from the configuration
- *
- * @param filter that will be concatenated with proper role search filter from the
module
- * @return
- */
- public abstract NamingEnumeration searchRoles(String filter) throws NamingException,
IdentityException;
-
- //**************************
- //*** Getter and Setters
- //**************************
-
- protected String getRidAttributeID() throws IdentityException
- {
- String rid =
getIdentityConfiguration().getValue(IdentityConfiguration.ROLE_RID_ATTRIBUTE_ID);
- if (rid == null)
- {
- return "cn";
- }
- return rid;
- }
-
- protected LDAPConnectionContext getConnectionContext() throws IdentityException
- {
- if (connectionContext == null)
- {
- //this.connectionContext =
(LDAPConnectionContext)getIdentityContext().getObject(IdentityContext.TYPE_CONNECTION_CONTEXT);
- throw new IdentityException("No LDAPConnectionContext available");
- }
- return connectionContext;
- }
-
- protected String getContainerDN() throws IdentityException
- {
- String cont =
getIdentityConfiguration().getValue(IdentityConfiguration.ROLE_CONTAINER_DN);
- if (cont == null)
- {
- throw new IdentityException("Configuration option missing: " +
IdentityConfiguration.ROLE_CONTAINER_DN);
- }
- return cont;
- }
-
- protected String getDisplayNameAttributeID() throws IdentityException
- {
- String display =
getIdentityConfiguration().getValue(IdentityConfiguration.ROLE_DISPLAY_NAME_ATTRIBUTE_ID);
- if (display == null)
- {
- return getRidAttributeID();
- }
- return display;
- }
-
-
-
-}
Copied: trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPRoleModule.java (from
rev 5883, trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPRoleModule.java)
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPRoleModule.java 2006-12-17
14:26:07 UTC (rev 5883)
+++ trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPRoleModule.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -0,0 +1,188 @@
+/*
+* 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.identity.ldap;
+
+import org.jboss.portal.identity.IdentityException;
+import org.jboss.portal.identity.IdentityConfiguration;
+import org.jboss.portal.identity.Role;
+import org.jboss.portal.identity.service.RoleModuleService;
+
+import javax.naming.directory.Attributes;
+import javax.naming.directory.Attribute;
+import javax.naming.NamingException;
+import javax.naming.NamingEnumeration;
+import javax.naming.InitialContext;
+import java.util.NoSuchElementException;
+
+/**
+ * @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw
Dawidowicz</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class LDAPRoleModule extends RoleModuleService
+{
+ private static final org.jboss.logging.Logger log =
org.jboss.logging.Logger.getLogger(LDAPRoleModule.class);
+
+ private LDAPConnectionContext connectionContext;
+
+
+ protected void startService() throws Exception
+ {
+ if (getConnectionJNDIName() == null)
+ {
+ throw new IdentityException("Cannot obtain ldap connection context JNDI
name");
+ }
+
+ connectionContext = (LDAPConnectionContext)new
InitialContext().lookup(getConnectionJNDIName());
+
+ super.startService(); //To change body of overridden methods use File | Settings
| File Templates.
+ }
+
+
+ protected LDAPRoleImpl createRoleInstance(Attributes attrs, String dn) throws
IdentityException
+ {
+ LDAPRoleImpl ldapr = null;
+ try
+ {
+
+ log.debug("Attributes: " + attrs);
+
+ //role name
+ Attribute uida = attrs.get(getRidAttributeID());
+ if (uida == null)
+ {
+ throw new IdentityException("LDAP entry doesn't contain proper
attribute:" + getRidAttributeID());
+ }
+ //ldapr = new
LDAPRoleImpl(uida.getID().concat("=").concat((String)uida.get()) + ","
+ getContainerDN(), identityContext);
+ Attribute display = attrs.get(getDisplayNameAttributeID());
+ if (display == null)
+ {
+ throw new IdentityException("LDAP entry doesn't contain proper
attribute:" + getDisplayNameAttributeID());
+ }
+ ldapr = new LDAPRoleImpl(dn, getIdentityContext(), uida.get().toString(),
display.get().toString());
+
+
+
+ log.debug("role uid: " + ldapr.getId());
+ log.debug("role dn: " + ldapr.getDn());
+
+
+ }
+ catch (NamingException e)
+ {
+ throw new IdentityException("Couldn't create LDAPRoleImpl object from
ldap entry (SearchResult)", e);
+ }
+
+ return ldapr;
+ }
+
+ /**
+ * method not belonging to UserModule interface - ldap specific.
+ *
+ */
+ public Role findRoleByDN(String dn) throws IdentityException,
IllegalArgumentException
+ {
+ try
+ {
+ log.debug("findRoleByDN(): DN = " + dn);
+
+ if (dn == null)
+ {
+ throw new IdentityException("Role dn canot be null");
+ }
+
+ Attributes attrs =
getConnectionContext().createInitialContext().getAttributes(dn);
+
+ if (attrs == null)
+ {
+ throw new IdentityException("Can't find user entry with DN: " +
dn);
+ }
+
+ return createRoleInstance(attrs, dn);
+
+ }
+ catch (NoSuchElementException e)
+ {
+ log.debug("No user found with dn: " + dn, e);
+ }
+ catch (NamingException e)
+ {
+ throw new IdentityException("User search failed.", e);
+ }
+ return null;
+ }
+
+ /**
+ * This method should be used by over modules to perform searches. It will allow role
module
+ * implementation to apply proper filter and search scope from the configuration
+ *
+ * @param filter that will be concatenated with proper role search filter from the
module
+ * @return
+ */
+ public abstract NamingEnumeration searchRoles(String filter) throws NamingException,
IdentityException;
+
+ //**************************
+ //*** Getter and Setters
+ //**************************
+
+ protected String getRidAttributeID() throws IdentityException
+ {
+ String rid =
getIdentityConfiguration().getValue(IdentityConfiguration.ROLE_RID_ATTRIBUTE_ID);
+ if (rid == null)
+ {
+ return "cn";
+ }
+ return rid;
+ }
+
+ protected LDAPConnectionContext getConnectionContext() throws IdentityException
+ {
+ if (connectionContext == null)
+ {
+ //this.connectionContext =
(LDAPConnectionContext)getIdentityContext().getObject(IdentityContext.TYPE_CONNECTION_CONTEXT);
+ throw new IdentityException("No LDAPConnectionContext available");
+ }
+ return connectionContext;
+ }
+
+ protected String getContainerDN() throws IdentityException
+ {
+ String cont =
getIdentityConfiguration().getValue(IdentityConfiguration.ROLE_CONTAINER_DN);
+ if (cont == null)
+ {
+ throw new IdentityException("Configuration option missing: " +
IdentityConfiguration.ROLE_CONTAINER_DN);
+ }
+ return cont;
+ }
+
+ protected String getDisplayNameAttributeID() throws IdentityException
+ {
+ String display =
getIdentityConfiguration().getValue(IdentityConfiguration.ROLE_DISPLAY_NAME_ATTRIBUTE_ID);
+ if (display == null)
+ {
+ return getRidAttributeID();
+ }
+ return display;
+ }
+
+
+
+}
Deleted: trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPRoleModuleImpl.java
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPRoleModuleImpl.java 2006-12-15
15:15:26 UTC (rev 5871)
+++
trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPRoleModuleImpl.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -1,371 +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.common.util.Tools;
-import org.jboss.portal.identity.IdentityException;
-import org.jboss.portal.identity2.Role;
-import org.jboss.portal.identity2.User;
-import org.jboss.portal.identity2.IdentityContext;
-import org.jboss.portal.identity2.MembershipModule;
-import org.jboss.portal.identity2.IdentityConfiguration;
-
-import javax.naming.NamingEnumeration;
-import javax.naming.NamingException;
-import javax.naming.directory.Attribute;
-import javax.naming.directory.Attributes;
-import javax.naming.directory.BasicAttribute;
-import javax.naming.directory.BasicAttributes;
-import javax.naming.directory.SearchControls;
-import javax.naming.directory.SearchResult;
-import javax.naming.directory.DirContext;
-import javax.naming.ldap.LdapContext;
-import java.util.List;
-import java.util.NoSuchElementException;
-import java.util.Set;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Iterator;
-
-/**
- * @author <a href="mailto:boleslaw.dawidowicz@jboss.org">Boleslaw
Dawidowicz</a>
- * @version $Revision: 1.1 $
- */
-public class LDAPRoleModuleImpl extends LDAPRoleModule
-{
- private static final org.jboss.logging.Logger log =
org.jboss.logging.Logger.getLogger(LDAPRoleModuleImpl.class);
-
- public Role findRoleByName(String name) throws IdentityException,
IllegalArgumentException
- {
- try
- {
- log.debug("findRoleByName(): name = " + name);
-
- if (name == null)
- {
- throw new IdentityException("Role name canot be null");
- }
-
-
- String filter =
"(".concat(getRidAttributeID()).concat("=").concat(name).concat(")");
- log.debug("Search filter: " + filter);
-
-
- NamingEnumeration results = searchRoles(filter);
- List sr = Tools.toList(results);
- if (sr.size() > 1)
- {
- throw new IdentityException("Found more than one role with id: " +
name + "" +
- "Posible data inconsistency");
- }
- SearchResult res = (SearchResult)sr.iterator().next();
- DirContext ctx = (DirContext)res.getObject();
- return createRoleInstance(res.getAttributes(),ctx.getNameInNamespace());
-
- }
- catch (NoSuchElementException e)
- {
- log.debug("No role found with name: " + name, e);
- }
- catch (NamingException e)
- {
- throw new IdentityException("Role search failed.", e);
- }
- return null;
- }
-
- public Set findRolesByNames(String[] names) throws IdentityException,
IllegalArgumentException
- {
- if (names == null)
- {
- throw new IllegalArgumentException("null argument");
- }
-
- Set roles = new HashSet();
- try
- {
- //construct a filter with all role names
- StringBuffer filter = new StringBuffer("(| ");
- for (int i = 0; i < names.length; i++)
- {
- String name = names[i];
- filter.append("(")
- .append(getRidAttributeID())
- .append("=")
- .append(name)
- .append(") ");
- }
- filter.append(")");
-
- NamingEnumeration results = searchRoles(filter.toString());
- List sr = Tools.toList(results);
- for (Iterator iterator = sr.iterator(); iterator.hasNext();)
- {
- SearchResult res = (SearchResult)iterator.next();
- DirContext ctx = (DirContext)res.getObject();
- roles.add(createRoleInstance(res.getAttributes(),ctx.getNameInNamespace()));
- }
- }
- catch (Exception e)
- {
- throw new IdentityException("Can't retreive roles", e);
- }
-
- return roles;
-
- }
-
- public Role findRoleById(Object id) throws IdentityException,
IllegalArgumentException
- {
- if (id == null)
- {
- throw new IdentityException("Cannot search role with null id");
- }
- if (!(id instanceof String))
- {
- throw new IdentityException("Only String id is suppoted");
- }
- return findRoleById((String)id);
- }
-
- public Role findRoleById(String id) throws IdentityException,
IllegalArgumentException
- {
- return findRoleByName(id);
- }
-
- public Role createRole(String name, String displayName) throws IdentityException,
IllegalArgumentException
- {
- if (name == null)
- {
- throw new IdentityException("Role name cannot be null");
- }
-
- try
- {
- //
- LdapContext ctx =
(LdapContext)getConnectionContext().createInitialContext().lookup(getContainerDN());
-
- //We store new entry using set of attributes. This should give more flexibility
then
- //extending user object from ContextDir - configure what objectClass place
there
- Attributes attrs = new BasicAttributes(true);
-
- //add attribute using provided configuration
- Map attributesToAdd = getAttributesToAdd();
-
- //attribute
- for (Iterator it1 = attributesToAdd.keySet().iterator(); it1.hasNext();)
- {
- String attributeName = (String)it1.next();
- log.debug("adding attribute: " + attributeName);
- Attribute attr = new BasicAttribute(attributeName);
- Set attributeValues = (Set)attributesToAdd.get(attributeName);
-
- //values
- for (Iterator it2 = attributeValues.iterator(); it2.hasNext();)
- {
- String attrValue = (String)it2.next();
- log.debug("adding attribute value: " + attrValue);
- attr.add(attrValue);
- }
- attrs.put(attr);
- }
-
- //role name
- attrs.put(getRidAttributeID(), name);
-
- //display name
- if (!getDisplayNameAttributeID().equals(getRidAttributeID()))
- {
- attrs.put(getDisplayNameAttributeID(), displayName);
- }
-
- String dn = getRidAttributeID().concat("=").concat(name);
-
- log.debug("creating ldap entry for: " + dn + "; " + attrs);
- ctx.createSubcontext(dn, attrs);
- }
- catch (NamingException e)
- {
- throw new IdentityException("Failed to create role", e);
- }
-
- return findRoleByName(name);
- }
-
- //TODO: remove role assignments before?
- public void removeRole(Object id) throws IdentityException, IllegalArgumentException
- {
- LDAPRoleImpl ldapr = (LDAPRoleImpl)findRoleById(id);
-
- if (ldapr == null)
- {
- throw new IdentityException("Cannot find role for removal");
- }
-
- if (ldapr.getDn() == null)
- {
- throw new IdentityException("Cannot obtain DN of role");
- }
-
- try
- {
- LdapContext ctx =
(LdapContext)getConnectionContext().createInitialContext();//.lookup(getContainerDN());
- log.debug("removing entry: " + ldapr.getDn());
- ctx.unbind(ldapr.getDn());
- }
- catch (Exception e)
- {
- throw new IdentityException("Failed to remove role: ", e);
- }
- }
-
- public int getRolesCount() throws IdentityException
- {
- try
- {
- //search all entries containing "cn" attribute
- String filter =
getRidAttributeID().concat("=").concat("*");
- log.debug("Search filter: " + filter);
-
- NamingEnumeration results = searchRoles(filter);
- List sr = Tools.toList(results);
-
- return sr.size();
-
- }
- catch (NoSuchElementException e)
- {
- log.debug("No roles found", e);
- }
- catch (Exception e)
- {
- throw new IdentityException("Role search failed.", e);
- }
- return 0;
- }
-
- public Set findRoles() throws IdentityException
- {
- Set rf = new HashSet();
- try
- {
- //search all entries containing "cn" attribute
- String filter =
"(".concat(getRidAttributeID()).concat("=").concat("*").concat(")");
- log.debug("Search filter: " + filter);
-
- NamingEnumeration results = searchRoles(filter);
- while (results.hasMoreElements())
- {
- SearchResult res = (SearchResult)results.nextElement();
- DirContext ctx = (DirContext)res.getObject();
- rf.add(createRoleInstance(res.getAttributes(),ctx.getNameInNamespace()));
- }
- }
- catch (NoSuchElementException e)
- {
- log.debug("No roles found", e);
- }
- catch (Exception e)
- {
- throw new IdentityException("Role search failed.", e);
- }
- return rf;
- }
-
- /**
- * This method should be used by over modules to perform searches. It will allow role
module
- * implementation to apply proper filter and search scope from the configuration
- *
- * @param filter that will be concatenated with proper role search filter from the
module
- * @return
- */
- public NamingEnumeration searchRoles(String filter) throws NamingException,
IdentityException
- {
- SearchControls controls = new SearchControls();
- controls.setSearchScope(SearchControls.ONELEVEL_SCOPE);
- controls.setReturningObjFlag(true);
-
- //String filter = getUidAttributeID().concat("=").concat(userName);
- log.debug("Search filter: " + filter);
-
- return getConnectionContext().createInitialContext().search(getContainerDN(),
filter, controls);
- }
-
- //TODO:remove this - it's only a fasade to make this implementation compatible
with old RoleModule interface
- public Set findRoleMembers(String roleName, int offset, int limit, String
userNameFilter) throws IdentityException
- {
- try
- {
- MembershipModule mm =
(MembershipModule)getIdentityContext().getObject(IdentityContext.TYPE_MEMBERSHIP_MODULE);
- return mm.findRoleMembers(roleName, offset, limit, userNameFilter);
- }
- catch (IdentityException e)
- {
- throw new IdentityException("Unable to delegate method to MembershipModule:
", e);
- }
-
- }
-
- //TODO:remove this - it's only a fasade to make this implementation compatible
with old RoleModule interface
- public void setRoles(User user, Set roles) throws IdentityException
- {
- try
- {
- MembershipModule mm =
(MembershipModule)getIdentityContext().getObject(IdentityContext.TYPE_MEMBERSHIP_MODULE);
- mm.assignRoles(user,roles);
- }
- catch (IdentityException e)
- {
- throw new IdentityException("Unable to delegate method to MembershipModule:
", e);
- }
-
- }
-
- //TODO:remove this - it's only a fasade to make this implementation compatible
with old RoleModule interface
- public Set getRoles(User user) throws IdentityException
- {
- try
- {
- MembershipModule mm =
(MembershipModule)getIdentityContext().getObject(IdentityContext.TYPE_MEMBERSHIP_MODULE);
- return mm.getRoles(user);
- }
- catch (IdentityException e)
- {
- throw new IdentityException("Unable to delegate method to MembershipModule:
", e);
- }
-
- }
-
- private Map getAttributesToAdd() throws IdentityException
- {
- Map attributesToAdd =
getIdentityConfiguration().getOptions(IdentityConfiguration.GROUP_ROLE_CREATE_ATTRIBUTES);
- if (attributesToAdd == null)
- {
- throw new IdentityException(IdentityConfiguration.GROUP_ROLE_CREATE_ATTRIBUTES +
" missing in configuration");
- }
- return attributesToAdd;
- }
-
-
-
-}
Copied: trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPRoleModuleImpl.java
(from rev 5883,
trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPRoleModuleImpl.java)
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPRoleModuleImpl.java 2006-12-17
14:26:07 UTC (rev 5883)
+++
trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPRoleModuleImpl.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -0,0 +1,371 @@
+/******************************************************************************
+ * 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.identity.ldap;
+
+import org.jboss.portal.common.util.Tools;
+import org.jboss.portal.identity.IdentityException;
+import org.jboss.portal.identity.Role;
+import org.jboss.portal.identity.User;
+import org.jboss.portal.identity.IdentityContext;
+import org.jboss.portal.identity.MembershipModule;
+import org.jboss.portal.identity.IdentityConfiguration;
+
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.BasicAttribute;
+import javax.naming.directory.BasicAttributes;
+import javax.naming.directory.SearchControls;
+import javax.naming.directory.SearchResult;
+import javax.naming.directory.DirContext;
+import javax.naming.ldap.LdapContext;
+import java.util.List;
+import java.util.NoSuchElementException;
+import java.util.Set;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Iterator;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz@jboss.org">Boleslaw
Dawidowicz</a>
+ * @version $Revision: 1.1 $
+ */
+public class LDAPRoleModuleImpl extends LDAPRoleModule
+{
+ private static final org.jboss.logging.Logger log =
org.jboss.logging.Logger.getLogger(LDAPRoleModuleImpl.class);
+
+ public Role findRoleByName(String name) throws IdentityException,
IllegalArgumentException
+ {
+ try
+ {
+ log.debug("findRoleByName(): name = " + name);
+
+ if (name == null)
+ {
+ throw new IdentityException("Role name canot be null");
+ }
+
+
+ String filter =
"(".concat(getRidAttributeID()).concat("=").concat(name).concat(")");
+ log.debug("Search filter: " + filter);
+
+
+ NamingEnumeration results = searchRoles(filter);
+ List sr = Tools.toList(results);
+ if (sr.size() > 1)
+ {
+ throw new IdentityException("Found more than one role with id: " +
name + "" +
+ "Posible data inconsistency");
+ }
+ SearchResult res = (SearchResult)sr.iterator().next();
+ DirContext ctx = (DirContext)res.getObject();
+ return createRoleInstance(res.getAttributes(),ctx.getNameInNamespace());
+
+ }
+ catch (NoSuchElementException e)
+ {
+ log.debug("No role found with name: " + name, e);
+ }
+ catch (NamingException e)
+ {
+ throw new IdentityException("Role search failed.", e);
+ }
+ return null;
+ }
+
+ public Set findRolesByNames(String[] names) throws IdentityException,
IllegalArgumentException
+ {
+ if (names == null)
+ {
+ throw new IllegalArgumentException("null argument");
+ }
+
+ Set roles = new HashSet();
+ try
+ {
+ //construct a filter with all role names
+ StringBuffer filter = new StringBuffer("(| ");
+ for (int i = 0; i < names.length; i++)
+ {
+ String name = names[i];
+ filter.append("(")
+ .append(getRidAttributeID())
+ .append("=")
+ .append(name)
+ .append(") ");
+ }
+ filter.append(")");
+
+ NamingEnumeration results = searchRoles(filter.toString());
+ List sr = Tools.toList(results);
+ for (Iterator iterator = sr.iterator(); iterator.hasNext();)
+ {
+ SearchResult res = (SearchResult)iterator.next();
+ DirContext ctx = (DirContext)res.getObject();
+ roles.add(createRoleInstance(res.getAttributes(),ctx.getNameInNamespace()));
+ }
+ }
+ catch (Exception e)
+ {
+ throw new IdentityException("Can't retreive roles", e);
+ }
+
+ return roles;
+
+ }
+
+ public Role findRoleById(Object id) throws IdentityException,
IllegalArgumentException
+ {
+ if (id == null)
+ {
+ throw new IdentityException("Cannot search role with null id");
+ }
+ if (!(id instanceof String))
+ {
+ throw new IdentityException("Only String id is suppoted");
+ }
+ return findRoleById((String)id);
+ }
+
+ public Role findRoleById(String id) throws IdentityException,
IllegalArgumentException
+ {
+ return findRoleByName(id);
+ }
+
+ public Role createRole(String name, String displayName) throws IdentityException,
IllegalArgumentException
+ {
+ if (name == null)
+ {
+ throw new IdentityException("Role name cannot be null");
+ }
+
+ try
+ {
+ //
+ LdapContext ctx =
(LdapContext)getConnectionContext().createInitialContext().lookup(getContainerDN());
+
+ //We store new entry using set of attributes. This should give more flexibility
then
+ //extending user object from ContextDir - configure what objectClass place
there
+ Attributes attrs = new BasicAttributes(true);
+
+ //add attribute using provided configuration
+ Map attributesToAdd = getAttributesToAdd();
+
+ //attribute
+ for (Iterator it1 = attributesToAdd.keySet().iterator(); it1.hasNext();)
+ {
+ String attributeName = (String)it1.next();
+ log.debug("adding attribute: " + attributeName);
+ Attribute attr = new BasicAttribute(attributeName);
+ Set attributeValues = (Set)attributesToAdd.get(attributeName);
+
+ //values
+ for (Iterator it2 = attributeValues.iterator(); it2.hasNext();)
+ {
+ String attrValue = (String)it2.next();
+ log.debug("adding attribute value: " + attrValue);
+ attr.add(attrValue);
+ }
+ attrs.put(attr);
+ }
+
+ //role name
+ attrs.put(getRidAttributeID(), name);
+
+ //display name
+ if (!getDisplayNameAttributeID().equals(getRidAttributeID()))
+ {
+ attrs.put(getDisplayNameAttributeID(), displayName);
+ }
+
+ String dn = getRidAttributeID().concat("=").concat(name);
+
+ log.debug("creating ldap entry for: " + dn + "; " + attrs);
+ ctx.createSubcontext(dn, attrs);
+ }
+ catch (NamingException e)
+ {
+ throw new IdentityException("Failed to create role", e);
+ }
+
+ return findRoleByName(name);
+ }
+
+ //TODO: remove role assignments before?
+ public void removeRole(Object id) throws IdentityException, IllegalArgumentException
+ {
+ LDAPRoleImpl ldapr = (LDAPRoleImpl)findRoleById(id);
+
+ if (ldapr == null)
+ {
+ throw new IdentityException("Cannot find role for removal");
+ }
+
+ if (ldapr.getDn() == null)
+ {
+ throw new IdentityException("Cannot obtain DN of role");
+ }
+
+ try
+ {
+ LdapContext ctx =
(LdapContext)getConnectionContext().createInitialContext();//.lookup(getContainerDN());
+ log.debug("removing entry: " + ldapr.getDn());
+ ctx.unbind(ldapr.getDn());
+ }
+ catch (Exception e)
+ {
+ throw new IdentityException("Failed to remove role: ", e);
+ }
+ }
+
+ public int getRolesCount() throws IdentityException
+ {
+ try
+ {
+ //search all entries containing "cn" attribute
+ String filter =
getRidAttributeID().concat("=").concat("*");
+ log.debug("Search filter: " + filter);
+
+ NamingEnumeration results = searchRoles(filter);
+ List sr = Tools.toList(results);
+
+ return sr.size();
+
+ }
+ catch (NoSuchElementException e)
+ {
+ log.debug("No roles found", e);
+ }
+ catch (Exception e)
+ {
+ throw new IdentityException("Role search failed.", e);
+ }
+ return 0;
+ }
+
+ public Set findRoles() throws IdentityException
+ {
+ Set rf = new HashSet();
+ try
+ {
+ //search all entries containing "cn" attribute
+ String filter =
"(".concat(getRidAttributeID()).concat("=").concat("*").concat(")");
+ log.debug("Search filter: " + filter);
+
+ NamingEnumeration results = searchRoles(filter);
+ while (results.hasMoreElements())
+ {
+ SearchResult res = (SearchResult)results.nextElement();
+ DirContext ctx = (DirContext)res.getObject();
+ rf.add(createRoleInstance(res.getAttributes(),ctx.getNameInNamespace()));
+ }
+ }
+ catch (NoSuchElementException e)
+ {
+ log.debug("No roles found", e);
+ }
+ catch (Exception e)
+ {
+ throw new IdentityException("Role search failed.", e);
+ }
+ return rf;
+ }
+
+ /**
+ * This method should be used by over modules to perform searches. It will allow role
module
+ * implementation to apply proper filter and search scope from the configuration
+ *
+ * @param filter that will be concatenated with proper role search filter from the
module
+ * @return
+ */
+ public NamingEnumeration searchRoles(String filter) throws NamingException,
IdentityException
+ {
+ SearchControls controls = new SearchControls();
+ controls.setSearchScope(SearchControls.ONELEVEL_SCOPE);
+ controls.setReturningObjFlag(true);
+
+ //String filter = getUidAttributeID().concat("=").concat(userName);
+ log.debug("Search filter: " + filter);
+
+ return getConnectionContext().createInitialContext().search(getContainerDN(),
filter, controls);
+ }
+
+ //TODO:remove this - it's only a fasade to make this implementation compatible
with old RoleModule interface
+ public Set findRoleMembers(String roleName, int offset, int limit, String
userNameFilter) throws IdentityException
+ {
+ try
+ {
+ MembershipModule mm =
(MembershipModule)getIdentityContext().getObject(IdentityContext.TYPE_MEMBERSHIP_MODULE);
+ return mm.findRoleMembers(roleName, offset, limit, userNameFilter);
+ }
+ catch (IdentityException e)
+ {
+ throw new IdentityException("Unable to delegate method to MembershipModule:
", e);
+ }
+
+ }
+
+ //TODO:remove this - it's only a fasade to make this implementation compatible
with old RoleModule interface
+ public void setRoles(User user, Set roles) throws IdentityException
+ {
+ try
+ {
+ MembershipModule mm =
(MembershipModule)getIdentityContext().getObject(IdentityContext.TYPE_MEMBERSHIP_MODULE);
+ mm.assignRoles(user,roles);
+ }
+ catch (IdentityException e)
+ {
+ throw new IdentityException("Unable to delegate method to MembershipModule:
", e);
+ }
+
+ }
+
+ //TODO:remove this - it's only a fasade to make this implementation compatible
with old RoleModule interface
+ public Set getRoles(User user) throws IdentityException
+ {
+ try
+ {
+ MembershipModule mm =
(MembershipModule)getIdentityContext().getObject(IdentityContext.TYPE_MEMBERSHIP_MODULE);
+ return mm.getRoles(user);
+ }
+ catch (IdentityException e)
+ {
+ throw new IdentityException("Unable to delegate method to MembershipModule:
", e);
+ }
+
+ }
+
+ private Map getAttributesToAdd() throws IdentityException
+ {
+ Map attributesToAdd =
getIdentityConfiguration().getOptions(IdentityConfiguration.GROUP_ROLE_CREATE_ATTRIBUTES);
+ if (attributesToAdd == null)
+ {
+ throw new IdentityException(IdentityConfiguration.GROUP_ROLE_CREATE_ATTRIBUTES +
" missing in configuration");
+ }
+ return attributesToAdd;
+ }
+
+
+
+}
Deleted:
trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPStaticGroupMembershipModuleImpl.java
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPStaticGroupMembershipModuleImpl.java 2006-12-15
15:15:26 UTC (rev 5871)
+++
trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPStaticGroupMembershipModuleImpl.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -1,395 +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.identity.IdentityException;
-import org.jboss.portal.identity2.User;
-import org.jboss.portal.identity2.MembershipModule;
-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;
-import org.jboss.portal.jems.as.system.AbstractJBossService;
-import org.jboss.portal.common.util.JNDI;
-import org.jboss.portal.common.util.Tools;
-
-import javax.naming.directory.Attributes;
-import javax.naming.directory.SearchControls;
-import javax.naming.directory.SearchResult;
-import javax.naming.directory.DirContext;
-import javax.naming.directory.BasicAttributes;
-import javax.naming.directory.Attribute;
-import javax.naming.directory.BasicAttribute;
-import javax.naming.directory.ModificationItem;
-import javax.naming.NamingEnumeration;
-import javax.naming.NamingException;
-import java.util.Set;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Iterator;
-import java.util.LinkedList;
-
-/**
- * @author <a href="mailto:boleslaw.dawidowicz@jboss.org">Boleslaw
Dawidowicz</a>
- * @version $Revision: 1.1 $
- */
-public class LDAPStaticGroupMembershipModuleImpl extends LDAPMembershipModule
-{
- private static final org.jboss.logging.Logger log =
org.jboss.logging.Logger.getLogger(LDAPStaticGroupMembershipModuleImpl.class);
-
-
- public Set getRoles(User user) throws IdentityException
- {
- if (user == null)
- {
- throw new IllegalArgumentException("User cannot be null");
- }
-
- LDAPUserImpl ldapUser = null;
-
- if (user instanceof LDAPUserImpl)
- {
- ldapUser = (LDAPUserImpl)user;
- }
- else
- {
- throw new IllegalArgumentException("UserMembershipModuleImpl supports only
LDAPUserImpl objects");
- }
-
- Set roles = new HashSet();
- try
- {
-
- log.debug("getRoles(): user DN = " + ldapUser.getDn());
-
- String memberName = "";
-
- if (isUidAttributeIsDN())
- {
- memberName = ldapUser.getDn();
- }
- else
- {
- memberName = ldapUser.getId().toString();
- }
-
-
- String filter =
getMemberAttributeID().concat("=").concat(memberName);
- log.debug("Search filter: " + filter);
-
- NamingEnumeration results = getRoleModule().searchRoles(filter);
- List sr = Tools.toList(results);
-
-
- for (Iterator iterator = sr.iterator(); iterator.hasNext();)
- {
- SearchResult res = (SearchResult)iterator.next();
- DirContext ctx = (DirContext)res.getObject();
-
roles.add(getRoleModule().createRoleInstance(res.getAttributes(),ctx.getNameInNamespace()));
- }
-
-
-
- }
- catch (Exception e)
- {
- log.debug("Failed to resolve userRoles: " +
ldapUser.getId().toString(), e);
- }
-
- return roles;
-
- }
-
- public Set getUsers(Role role) throws IdentityException
- {
- if (role == null)
- {
- throw new IllegalArgumentException("Role cannot be null");
- }
-
- LDAPRoleImpl ldapRole = null;
-
- if (role instanceof LDAPRoleImpl)
- {
- ldapRole = (LDAPRoleImpl)role;
- }
- else
- {
- throw new IllegalArgumentException("UserMembershipModuleImpl supports only
LDAPRoleImpl objects");
- }
-
- //throw new UnsupportedOperationException("Not yet implemented");
-
- Set users = new HashSet();
-
- try
- {
- log.debug("findUsers(): role = " + ldapRole.getDn());
-
- if (ldapRole.getName() == null)
- {
- throw new IdentityException("Role name canot be null");
- }
-
- //obtain Role entry attributes from directory
- Attributes attrs =
getConnectionContext().createInitialContext().getAttributes(ldapRole.getDn());
-
- log.debug("Role attributes: " + attrs);
- if (attrs == null )
- {
- throw new IdentityException("Cannot find Role with DN: " +
ldapRole.getDn());
- }
-
- //iterate over user names belonging to this role
- NamingEnumeration values = attrs.get(getMemberAttributeID()).getAll();
- while (values.hasMoreElements())
- {
- String value = values.nextElement().toString();
- String name = value;
-
- try
- {
- //if user is pointed as DN get only it's name
- if (!isUidAttributeIsDN())
- {
- name = LDAPTools.stripDnToName(name);
- users.add(getUserModule().findUserByUserName(name));
- }
- else
- {
- users.add(getUserModule().findUserByDN(name));
- }
- }
- catch(IdentityException ie)
- {
- log.error("Failed to find user: " + name + "/" +
value, ie);
-
- }
- }
- }
- catch (NamingException e)
- {
- throw new IdentityException("Resolving Role Users failed.", e);
- }
-
- return users;
-
- }
-
- public void assignUsers(Role role, Set users) throws IdentityException
- {
- if (role == null)
- {
- throw new IllegalArgumentException("Role cannot be null");
- }
-
- LDAPRoleImpl ldapRole = null;
-
- if (role instanceof LDAPRoleImpl)
- {
- ldapRole = (LDAPRoleImpl)role;
- }
- else
- {
- throw new IllegalArgumentException("UserMembershipModuleImpl supports only
LDAPRoleImpl objects");
- }
-
-
-
- if (users.size() == 0)
- {
- throw new IdentityException("Cannot assigne 0 users to a role using this
membership strategy (because some LDAPs " +
- "require the member field to be set). ");
- }
-
- try
- {
- log.debug("findUsers(): role = " + ldapRole.getDn());
-
- if (ldapRole.getName() == null)
- {
- throw new IdentityException("Role name canot be null");
- }
-
- //construct new member attribute values
- Attributes attrs = new BasicAttributes(true);
-
- Attribute member = new BasicAttribute(getMemberAttributeID());
- for (Iterator iterator = users.iterator(); iterator.hasNext();)
- {
- try
- {
- LDAPUserImpl user = (LDAPUserImpl)iterator.next();
- if (isUidAttributeIsDN())
- {
- member.add(user.getDn());
- }
- else
- {
- member.add(user.getId().toString());
- }
- }
- catch (ClassCastException e)
- {
- throw new IdentityException("Only can add LDAPUserImpl objects",
e);
- }
- }
- attrs.put(member);
-
- getConnectionContext().createInitialContext().modifyAttributes(ldapRole.getDn(),
DirContext.REPLACE_ATTRIBUTE, attrs);
- }
- catch (NamingException e)
- {
- throw new IdentityException("Failed to change Role members", e);
- }
-
- }
-
- public void assignRoles(User user, Set roles) throws IdentityException
- {
- if (user == null)
- {
- throw new IllegalArgumentException("User cannot be null");
- }
-
- LDAPUserImpl ldapUser = null;
-
- if (user instanceof LDAPUserImpl)
- {
- ldapUser = (LDAPUserImpl)user;
- }
- else
- {
- throw new IllegalArgumentException("UserMembershipModuleImpl supports only
LDAPUserImpl objects");
- }
-
- //First build a list of roles DNs to add
- List roleDNsToAdd = new LinkedList();
-
- for (Iterator iterator = roles.iterator(); iterator.hasNext();)
- {
- try
- {
- LDAPRoleImpl role = (LDAPRoleImpl)iterator.next();
- roleDNsToAdd.add(role.getDn());
- }
- catch(ClassCastException e)
- {
- throw new IdentityException("Only can add LDAPRoleImpl objects",
e);
- }
- }
-
- String memberName=null;
-
- //Find all the roles that currently contain user as member (need to remove user
from some of them)
- if (isUidAttributeIsDN())
- {
- memberName = ldapUser.getDn();
- }
- else
- {
- memberName = ldapUser.getId().toString();
- }
-
-
- try
- {
-
- String filter =
getMemberAttributeID().concat("=").concat(memberName);
- log.debug("Search filter: " + filter);
-
- NamingEnumeration results = getRoleModule().searchRoles(filter);
- List sr = Tools.toList(results);
- //iterate over roles that contain a user
- for (Iterator iterator = sr.iterator(); iterator.hasNext();)
- {
- SearchResult res = (SearchResult)iterator.next();
- DirContext ctx = (DirContext)res.getObject();
- String roleDN = ctx.getNameInNamespace();
- //if role is one which we want to add
- if (roleDNsToAdd.contains(roleDN))
- {
- //we do nothing but mark this role as added
- roleDNsToAdd.remove(roleDN);
- continue;
- }
- //if it's not on the list we need to remove user from it
- else
- {
- Attribute attr = res.getAttributes().get(getMemberAttributeID());
-
- //can't remove the last member (if the attribute is required by
schema)
- //TODO: workaround this somehow.... (adding goofy user or admin instead?)
- if (attr.size() != 1)
- {
- //remove user name from the member list
- attr.remove(memberName);
-
- //and replace attributes
- Attributes newAttrs = new BasicAttributes(true);
- //newAttrs.put(getMemberAttributeID(), attr);
- newAttrs.put(attr);
- getConnectionContext().createInitialContext().modifyAttributes(roleDN,
DirContext.REPLACE_ATTRIBUTE, newAttrs);
- }
- else
- {
- log.error("Couldn't remove user from role as it was the last
member - possibly required field in ldap");
- }
-
- //and mark this role as done
- roleDNsToAdd.remove(roleDN);
- }
- }
-
- //now iterate over roles that left to process
- for (Iterator iterator = roleDNsToAdd.iterator(); iterator.hasNext();)
- {
- String roleDN = (String)iterator.next();
-
- //changes to make
- ModificationItem[] mods = new ModificationItem[1];
- mods[0] = new ModificationItem(DirContext.ADD_ATTRIBUTE,
- new BasicAttribute(getMemberAttributeID(), memberName));
- // Perform the requested modifications on the named object
- getConnectionContext().createInitialContext().modifyAttributes(roleDN,
mods);
- }
-
- //and that should be all...
- }
- catch (NamingException e)
- {
- e.printStackTrace(); //To change body of catch statement use File | Settings |
File Templates.
- }
-
-
- }
-
- //TODO:don't forget to add this....
- public Set findRoleMembers(String roleName, int offset, int limit, String
userNameFilter) throws IdentityException
- {
- throw new UnsupportedOperationException("Not yet implemented");
- }
-
-
-
-}
Copied:
trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPStaticGroupMembershipModuleImpl.java
(from rev 5883,
trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPStaticGroupMembershipModuleImpl.java)
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPStaticGroupMembershipModuleImpl.java 2006-12-17
14:26:07 UTC (rev 5883)
+++
trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPStaticGroupMembershipModuleImpl.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -0,0 +1,389 @@
+/******************************************************************************
+ * 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.identity.ldap;
+
+import org.jboss.portal.identity.IdentityException;
+import org.jboss.portal.identity.User;
+import org.jboss.portal.identity.Role;
+import org.jboss.portal.identity.ldap.helper.LDAPTools;
+import org.jboss.portal.common.util.Tools;
+
+import javax.naming.directory.Attributes;
+import javax.naming.directory.SearchResult;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.BasicAttributes;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.BasicAttribute;
+import javax.naming.directory.ModificationItem;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import java.util.Set;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Iterator;
+import java.util.LinkedList;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz@jboss.org">Boleslaw
Dawidowicz</a>
+ * @version $Revision: 1.1 $
+ */
+public class LDAPStaticGroupMembershipModuleImpl extends LDAPMembershipModule
+{
+ private static final org.jboss.logging.Logger log =
org.jboss.logging.Logger.getLogger(LDAPStaticGroupMembershipModuleImpl.class);
+
+
+ public Set getRoles(User user) throws IdentityException
+ {
+ if (user == null)
+ {
+ throw new IllegalArgumentException("User cannot be null");
+ }
+
+ LDAPUserImpl ldapUser = null;
+
+ if (user instanceof LDAPUserImpl)
+ {
+ ldapUser = (LDAPUserImpl)user;
+ }
+ else
+ {
+ throw new IllegalArgumentException("UserMembershipModuleImpl supports only
LDAPUserImpl objects");
+ }
+
+ Set roles = new HashSet();
+ try
+ {
+
+ log.debug("getRoles(): user DN = " + ldapUser.getDn());
+
+ String memberName = "";
+
+ if (isUidAttributeIsDN())
+ {
+ memberName = ldapUser.getDn();
+ }
+ else
+ {
+ memberName = ldapUser.getId().toString();
+ }
+
+
+ String filter =
getMemberAttributeID().concat("=").concat(memberName);
+ log.debug("Search filter: " + filter);
+
+ NamingEnumeration results = getRoleModule().searchRoles(filter);
+ List sr = Tools.toList(results);
+
+
+ for (Iterator iterator = sr.iterator(); iterator.hasNext();)
+ {
+ SearchResult res = (SearchResult)iterator.next();
+ DirContext ctx = (DirContext)res.getObject();
+
roles.add(getRoleModule().createRoleInstance(res.getAttributes(),ctx.getNameInNamespace()));
+ }
+
+
+
+ }
+ catch (Exception e)
+ {
+ log.debug("Failed to resolve userRoles: " +
ldapUser.getId().toString(), e);
+ }
+
+ return roles;
+
+ }
+
+ public Set getUsers(Role role) throws IdentityException
+ {
+ if (role == null)
+ {
+ throw new IllegalArgumentException("Role cannot be null");
+ }
+
+ LDAPRoleImpl ldapRole = null;
+
+ if (role instanceof LDAPRoleImpl)
+ {
+ ldapRole = (LDAPRoleImpl)role;
+ }
+ else
+ {
+ throw new IllegalArgumentException("UserMembershipModuleImpl supports only
LDAPRoleImpl objects");
+ }
+
+ //throw new UnsupportedOperationException("Not yet implemented");
+
+ Set users = new HashSet();
+
+ try
+ {
+ log.debug("findUsers(): role = " + ldapRole.getDn());
+
+ if (ldapRole.getName() == null)
+ {
+ throw new IdentityException("Role name canot be null");
+ }
+
+ //obtain Role entry attributes from directory
+ Attributes attrs =
getConnectionContext().createInitialContext().getAttributes(ldapRole.getDn());
+
+ log.debug("Role attributes: " + attrs);
+ if (attrs == null )
+ {
+ throw new IdentityException("Cannot find Role with DN: " +
ldapRole.getDn());
+ }
+
+ //iterate over user names belonging to this role
+ NamingEnumeration values = attrs.get(getMemberAttributeID()).getAll();
+ while (values.hasMoreElements())
+ {
+ String value = values.nextElement().toString();
+ String name = value;
+
+ try
+ {
+ //if user is pointed as DN get only it's name
+ if (!isUidAttributeIsDN())
+ {
+ name = LDAPTools.stripDnToName(name);
+ users.add(getUserModule().findUserByUserName(name));
+ }
+ else
+ {
+ users.add(getUserModule().findUserByDN(name));
+ }
+ }
+ catch(IdentityException ie)
+ {
+ log.error("Failed to find user: " + name + "/" +
value, ie);
+
+ }
+ }
+ }
+ catch (NamingException e)
+ {
+ throw new IdentityException("Resolving Role Users failed.", e);
+ }
+
+ return users;
+
+ }
+
+ public void assignUsers(Role role, Set users) throws IdentityException
+ {
+ if (role == null)
+ {
+ throw new IllegalArgumentException("Role cannot be null");
+ }
+
+ LDAPRoleImpl ldapRole = null;
+
+ if (role instanceof LDAPRoleImpl)
+ {
+ ldapRole = (LDAPRoleImpl)role;
+ }
+ else
+ {
+ throw new IllegalArgumentException("UserMembershipModuleImpl supports only
LDAPRoleImpl objects");
+ }
+
+
+
+ if (users.size() == 0)
+ {
+ throw new IdentityException("Cannot assigne 0 users to a role using this
membership strategy (because some LDAPs " +
+ "require the member field to be set). ");
+ }
+
+ try
+ {
+ log.debug("findUsers(): role = " + ldapRole.getDn());
+
+ if (ldapRole.getName() == null)
+ {
+ throw new IdentityException("Role name canot be null");
+ }
+
+ //construct new member attribute values
+ Attributes attrs = new BasicAttributes(true);
+
+ Attribute member = new BasicAttribute(getMemberAttributeID());
+ for (Iterator iterator = users.iterator(); iterator.hasNext();)
+ {
+ try
+ {
+ LDAPUserImpl user = (LDAPUserImpl)iterator.next();
+ if (isUidAttributeIsDN())
+ {
+ member.add(user.getDn());
+ }
+ else
+ {
+ member.add(user.getId().toString());
+ }
+ }
+ catch (ClassCastException e)
+ {
+ throw new IdentityException("Only can add LDAPUserImpl objects",
e);
+ }
+ }
+ attrs.put(member);
+
+ getConnectionContext().createInitialContext().modifyAttributes(ldapRole.getDn(),
DirContext.REPLACE_ATTRIBUTE, attrs);
+ }
+ catch (NamingException e)
+ {
+ throw new IdentityException("Failed to change Role members", e);
+ }
+
+ }
+
+ public void assignRoles(User user, Set roles) throws IdentityException
+ {
+ if (user == null)
+ {
+ throw new IllegalArgumentException("User cannot be null");
+ }
+
+ LDAPUserImpl ldapUser = null;
+
+ if (user instanceof LDAPUserImpl)
+ {
+ ldapUser = (LDAPUserImpl)user;
+ }
+ else
+ {
+ throw new IllegalArgumentException("UserMembershipModuleImpl supports only
LDAPUserImpl objects");
+ }
+
+ //First build a list of roles DNs to add
+ List roleDNsToAdd = new LinkedList();
+
+ for (Iterator iterator = roles.iterator(); iterator.hasNext();)
+ {
+ try
+ {
+ LDAPRoleImpl role = (LDAPRoleImpl)iterator.next();
+ roleDNsToAdd.add(role.getDn());
+ }
+ catch(ClassCastException e)
+ {
+ throw new IdentityException("Only can add LDAPRoleImpl objects",
e);
+ }
+ }
+
+ String memberName=null;
+
+ //Find all the roles that currently contain user as member (need to remove user
from some of them)
+ if (isUidAttributeIsDN())
+ {
+ memberName = ldapUser.getDn();
+ }
+ else
+ {
+ memberName = ldapUser.getId().toString();
+ }
+
+
+ try
+ {
+
+ String filter =
getMemberAttributeID().concat("=").concat(memberName);
+ log.debug("Search filter: " + filter);
+
+ NamingEnumeration results = getRoleModule().searchRoles(filter);
+ List sr = Tools.toList(results);
+ //iterate over roles that contain a user
+ for (Iterator iterator = sr.iterator(); iterator.hasNext();)
+ {
+ SearchResult res = (SearchResult)iterator.next();
+ DirContext ctx = (DirContext)res.getObject();
+ String roleDN = ctx.getNameInNamespace();
+ //if role is one which we want to add
+ if (roleDNsToAdd.contains(roleDN))
+ {
+ //we do nothing but mark this role as added
+ roleDNsToAdd.remove(roleDN);
+ continue;
+ }
+ //if it's not on the list we need to remove user from it
+ else
+ {
+ Attribute attr = res.getAttributes().get(getMemberAttributeID());
+
+ //can't remove the last member (if the attribute is required by
schema)
+ //TODO: workaround this somehow.... (adding goofy user or admin instead?)
+ if (attr.size() != 1)
+ {
+ //remove user name from the member list
+ attr.remove(memberName);
+
+ //and replace attributes
+ Attributes newAttrs = new BasicAttributes(true);
+ //newAttrs.put(getMemberAttributeID(), attr);
+ newAttrs.put(attr);
+ getConnectionContext().createInitialContext().modifyAttributes(roleDN,
DirContext.REPLACE_ATTRIBUTE, newAttrs);
+ }
+ else
+ {
+ log.error("Couldn't remove user from role as it was the last
member - possibly required field in ldap");
+ }
+
+ //and mark this role as done
+ roleDNsToAdd.remove(roleDN);
+ }
+ }
+
+ //now iterate over roles that left to process
+ for (Iterator iterator = roleDNsToAdd.iterator(); iterator.hasNext();)
+ {
+ String roleDN = (String)iterator.next();
+
+ //changes to make
+ ModificationItem[] mods = new ModificationItem[1];
+ mods[0] = new ModificationItem(DirContext.ADD_ATTRIBUTE,
+ new BasicAttribute(getMemberAttributeID(), memberName));
+ // Perform the requested modifications on the named object
+ getConnectionContext().createInitialContext().modifyAttributes(roleDN,
mods);
+ }
+
+ //and that should be all...
+ }
+ catch (NamingException e)
+ {
+ e.printStackTrace(); //To change body of catch statement use File | Settings |
File Templates.
+ }
+
+
+ }
+
+ //TODO:don't forget to add this....
+ public Set findRoleMembers(String roleName, int offset, int limit, String
userNameFilter) throws IdentityException
+ {
+ throw new UnsupportedOperationException("Not yet implemented");
+ }
+
+
+
+}
Deleted:
trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPStaticRoleMembershipModuleImpl.java
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPStaticRoleMembershipModuleImpl.java 2006-12-15
15:15:26 UTC (rev 5871)
+++
trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPStaticRoleMembershipModuleImpl.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -1,381 +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.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.identity2.ldap.helper.LDAPTools;
-import org.jboss.portal.common.util.JNDI;
-import org.jboss.portal.common.util.Tools;
-import org.jboss.portal.identity.IdentityException;
-import org.jboss.portal.identity2.User;
-import org.jboss.portal.identity2.Role;
-
-import javax.naming.directory.SearchControls;
-import javax.naming.directory.SearchResult;
-import javax.naming.directory.DirContext;
-import javax.naming.directory.Attributes;
-import javax.naming.directory.BasicAttributes;
-import javax.naming.directory.Attribute;
-import javax.naming.directory.BasicAttribute;
-import javax.naming.directory.ModificationItem;
-import javax.naming.NamingEnumeration;
-import javax.naming.NamingException;
-import java.util.Set;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Iterator;
-import java.util.LinkedList;
-
-/**
- * @author <a href="mailto:boleslaw.dawidowicz@jboss.org">Boleslaw
Dawidowicz</a>
- * @version $Revision: 1.1 $
- */
-public class LDAPStaticRoleMembershipModuleImpl extends LDAPMembershipModule//extends
AbstractJBossService implements MembershipModule
-{
-
- private static final org.jboss.logging.Logger log =
org.jboss.logging.Logger.getLogger(LDAPStaticRoleMembershipModuleImpl.class);
-
- public Set getRoles(User user) throws IdentityException
- {
- if (user == null)
- {
- throw new IllegalArgumentException("User cannot be null");
- }
-
- LDAPUserImpl ldapUser = null;
-
- if (user instanceof LDAPUserImpl)
- {
- ldapUser = (LDAPUserImpl)user;
- }
- else
- {
- throw new IllegalArgumentException("UserMembershipModuleImpl supports only
LDAPUserImpl objects");
- }
-
- Set roles = new HashSet();
-
- try
- {
- log.debug("findRoles(): role = " + ldapUser.getDn());
-
- if (ldapUser.getUserName() == null)
- {
- throw new IdentityException("Role name canot be null");
- }
-
- //obtain Role entry attributes from directory
- Attributes attrs =
getConnectionContext().createInitialContext().getAttributes(ldapUser.getDn());
-
- log.debug("User attributes: " + attrs);
- if (attrs == null )
- {
- throw new IdentityException("Cannot find User with DN: " +
ldapUser.getDn());
- }
-
- Attribute memberOfAttribute = attrs.get(getMemberAttributeID());
-
- //if there are no members
- if (memberOfAttribute == null)
- {
- return roles;
- }
-
- //iterate over user names belonging to this role
- NamingEnumeration values = memberOfAttribute.getAll();
- while (values.hasMoreElements())
- {
- String value = values.nextElement().toString();
- String name = value;
-
- try
- {
- //if user is pointed as DN get only it's name
- if (!isUidAttributeIsDN())
- {
- name = LDAPTools.stripDnToName(name);
- roles.add(getRoleModule().findRoleByName(name));
- }
- else
- {
- roles.add(getRoleModule().findRoleByDN(name));
- }
- }
- catch(IdentityException ie)
- {
- log.error("Failed to find role: " + name + "/" +
value, ie);
-
- }
- }
- }
- catch (NamingException e)
- {
- throw new IdentityException("Resolving User Roles failed.", e);
- }
-
- return roles;
-
- }
-
- public Set getUsers(Role role) throws IdentityException
- {
- if (role == null)
- {
- throw new IllegalArgumentException("Role cannot be null");
- }
-
- LDAPRoleImpl ldapRole = null;
-
- if (role instanceof LDAPRoleImpl)
- {
- ldapRole = (LDAPRoleImpl)role;
- }
- else
- {
- throw new IllegalArgumentException("UserMembershipModuleImpl supports only
LDAPRoleImpl objects");
- }
-
- //throw new UnsupportedOperationException("Not yet implemented");
-
- Set users = new HashSet();
- try
- {
-
- log.debug("getUsers(): user DN = " + ldapRole.getDn());
-
- String memberOfName = "";
-
- if (isUidAttributeIsDN())
- {
- memberOfName = ldapRole.getDn();
- }
- else
- {
- memberOfName = ldapRole.getId().toString();
- }
-
- String filter =
getMemberAttributeID().concat("=").concat(memberOfName);
- log.debug("Search filter: " + filter);
-
-
- //NamingEnumeration results =
getConnectionContext().createInitialContext().search(getUserContainerDN(), filter,
controls);
- NamingEnumeration results = getUserModule().searchUsers(filter);
- List sr = Tools.toList(results);
-
-
- for (Iterator iterator = sr.iterator(); iterator.hasNext();)
- {
- SearchResult res = (SearchResult)iterator.next();
- DirContext ctx = (DirContext)res.getObject();
-
users.add(getUserModule().createUserInstance(res.getAttributes(),ctx.getNameInNamespace()));
- }
-
-
-
- }
- catch (Exception e)
- {
- log.debug("Failed to resolve role users: " +
ldapRole.getId().toString(), e);
- }
-
- return users;
-
- }
-
- public void assignUsers(Role role, Set users) throws IdentityException
- {
- if (role == null)
- {
- throw new IllegalArgumentException("Role cannot be null");
- }
-
- LDAPRoleImpl ldapRole = null;
-
- if (role instanceof LDAPRoleImpl)
- {
- ldapRole = (LDAPRoleImpl)role;
- }
- else
- {
- throw new IllegalArgumentException("UserMembershipModuleImpl supports only
LDAPRoleImpl objects");
- }
-
-
- //First build a list of user DNs to add
- List userDNsToAdd = new LinkedList();
-
- for (Iterator iterator = users.iterator(); iterator.hasNext();)
- {
- try
- {
- LDAPUserImpl user = (LDAPUserImpl)iterator.next();
- userDNsToAdd.add(user.getDn());
- }
- catch(ClassCastException e)
- {
- throw new IdentityException("Only can add LDAPUserImpl objects",
e);
- }
- }
-
- String memberOfName=null;
-
- //Find all the users that currently contain role as member (need to remove role
from some of them)
- if (isUidAttributeIsDN())
- {
- memberOfName = ldapRole.getDn();
- }
- else
- {
- memberOfName = ldapRole.getId().toString();
- }
-
-
- try
- {
- String filter =
getMemberAttributeID().concat("=").concat(memberOfName);
- log.debug("Search filter: " + filter);
-
- NamingEnumeration results = getUserModule().searchUsers(filter);
- List sr = Tools.toList(results);
- //iterate over users that contain a role
- for (Iterator iterator = sr.iterator(); iterator.hasNext();)
- {
- SearchResult res = (SearchResult)iterator.next();
- DirContext ctx = (DirContext)res.getObject();
- String userDN = ctx.getNameInNamespace();
- //if user is one which we want to add
- if (userDNsToAdd.contains(userDN))
- {
- //we do nothing but mark this user as added
- userDNsToAdd.remove(userDN);
- continue;
- }
- //if it's not on the list we need to remove role from it
- else
- {
- Attribute attr = res.getAttributes().get(getMemberAttributeID());
-
- attr.remove(memberOfName);
-
- //and replace attributes
- Attributes newAttrs = new BasicAttributes(true);
- //newAttrs.put(getMemberAttributeID(), attr);
- newAttrs.put(attr);
-
- getConnectionContext().createInitialContext().modifyAttributes(userDN,
DirContext.REPLACE_ATTRIBUTE, newAttrs);
-
- //and mark this role as done
- userDNsToAdd.remove(userDN);
- }
- }
-
- //now iterate over roles that left to process
- for (Iterator iterator = userDNsToAdd.iterator(); iterator.hasNext();)
- {
- String userDN = (String)iterator.next();
-
- //changes to make
- ModificationItem[] mods = new ModificationItem[1];
- mods[0] = new ModificationItem(DirContext.ADD_ATTRIBUTE,
- new BasicAttribute(getMemberAttributeID(), memberOfName));
- // Perform the requested modifications on the named object
- getConnectionContext().createInitialContext().modifyAttributes(userDN,
mods);
- }
-
- //and that should be all...
- }
- catch (NamingException e)
- {
- throw new IdentityException("Failed to assign users", e);
- }
- }
-
- public void assignRoles(User user, Set roles) throws IdentityException
- {
- if (user == null)
- {
- throw new IllegalArgumentException("User cannot be null");
- }
-
- LDAPUserImpl ldapUser = null;
-
- if (user instanceof LDAPUserImpl)
- {
- ldapUser = (LDAPUserImpl)user;
- }
- else
- {
- throw new IllegalArgumentException("UserMembershipModuleImpl supports only
LDAPUserImpl objects");
- }
-
- try
- {
- log.debug("findRoles(): user = " + ldapUser.getDn());
-
- if (ldapUser.getUserName() == null)
- {
- throw new IdentityException("User name canot be null");
- }
-
- //construct new member attribute values
- Attributes attrs = new BasicAttributes(true);
-
- Attribute member = new BasicAttribute(getMemberAttributeID());
- for (Iterator iterator = roles.iterator(); iterator.hasNext();)
- {
- try
- {
- LDAPRoleImpl role = (LDAPRoleImpl)iterator.next();
- if (isUidAttributeIsDN())
- {
- member.add(role.getDn());
- }
- else
- {
- member.add(role.getId().toString());
- }
- }
- catch (ClassCastException e)
- {
- throw new IdentityException("Only can add LDAPRoleImpl objects",
e);
- }
- }
- attrs.put(member);
-
- getConnectionContext().createInitialContext().modifyAttributes(ldapUser.getDn(),
DirContext.REPLACE_ATTRIBUTE, attrs);
- }
- catch (NamingException e)
- {
- throw new IdentityException("Failed to change Role members", e);
- }
-
- }
-
- //TODO:don't forget to add this....
- public Set findRoleMembers(String roleName, int offset, int limit, String
userNameFilter) throws IdentityException
- {
- throw new UnsupportedOperationException("Not yet implemented");
- }
-}
Copied:
trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPStaticRoleMembershipModuleImpl.java
(from rev 5883,
trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPStaticRoleMembershipModuleImpl.java)
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPStaticRoleMembershipModuleImpl.java 2006-12-17
14:26:07 UTC (rev 5883)
+++
trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPStaticRoleMembershipModuleImpl.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -0,0 +1,375 @@
+/*
+* 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.identity.ldap;
+
+import org.jboss.portal.identity.ldap.helper.LDAPTools;
+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 javax.naming.directory.SearchResult;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.BasicAttributes;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.BasicAttribute;
+import javax.naming.directory.ModificationItem;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import java.util.Set;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Iterator;
+import java.util.LinkedList;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz@jboss.org">Boleslaw
Dawidowicz</a>
+ * @version $Revision: 1.1 $
+ */
+public class LDAPStaticRoleMembershipModuleImpl extends LDAPMembershipModule//extends
AbstractJBossService implements MembershipModule
+{
+
+ private static final org.jboss.logging.Logger log =
org.jboss.logging.Logger.getLogger(LDAPStaticRoleMembershipModuleImpl.class);
+
+ public Set getRoles(User user) throws IdentityException
+ {
+ if (user == null)
+ {
+ throw new IllegalArgumentException("User cannot be null");
+ }
+
+ LDAPUserImpl ldapUser = null;
+
+ if (user instanceof LDAPUserImpl)
+ {
+ ldapUser = (LDAPUserImpl)user;
+ }
+ else
+ {
+ throw new IllegalArgumentException("UserMembershipModuleImpl supports only
LDAPUserImpl objects");
+ }
+
+ Set roles = new HashSet();
+
+ try
+ {
+ log.debug("findRoles(): role = " + ldapUser.getDn());
+
+ if (ldapUser.getUserName() == null)
+ {
+ throw new IdentityException("Role name canot be null");
+ }
+
+ //obtain Role entry attributes from directory
+ Attributes attrs =
getConnectionContext().createInitialContext().getAttributes(ldapUser.getDn());
+
+ log.debug("User attributes: " + attrs);
+ if (attrs == null )
+ {
+ throw new IdentityException("Cannot find User with DN: " +
ldapUser.getDn());
+ }
+
+ Attribute memberOfAttribute = attrs.get(getMemberAttributeID());
+
+ //if there are no members
+ if (memberOfAttribute == null)
+ {
+ return roles;
+ }
+
+ //iterate over user names belonging to this role
+ NamingEnumeration values = memberOfAttribute.getAll();
+ while (values.hasMoreElements())
+ {
+ String value = values.nextElement().toString();
+ String name = value;
+
+ try
+ {
+ //if user is pointed as DN get only it's name
+ if (!isUidAttributeIsDN())
+ {
+ name = LDAPTools.stripDnToName(name);
+ roles.add(getRoleModule().findRoleByName(name));
+ }
+ else
+ {
+ roles.add(getRoleModule().findRoleByDN(name));
+ }
+ }
+ catch(IdentityException ie)
+ {
+ log.error("Failed to find role: " + name + "/" +
value, ie);
+
+ }
+ }
+ }
+ catch (NamingException e)
+ {
+ throw new IdentityException("Resolving User Roles failed.", e);
+ }
+
+ return roles;
+
+ }
+
+ public Set getUsers(Role role) throws IdentityException
+ {
+ if (role == null)
+ {
+ throw new IllegalArgumentException("Role cannot be null");
+ }
+
+ LDAPRoleImpl ldapRole = null;
+
+ if (role instanceof LDAPRoleImpl)
+ {
+ ldapRole = (LDAPRoleImpl)role;
+ }
+ else
+ {
+ throw new IllegalArgumentException("UserMembershipModuleImpl supports only
LDAPRoleImpl objects");
+ }
+
+ //throw new UnsupportedOperationException("Not yet implemented");
+
+ Set users = new HashSet();
+ try
+ {
+
+ log.debug("getUsers(): user DN = " + ldapRole.getDn());
+
+ String memberOfName = "";
+
+ if (isUidAttributeIsDN())
+ {
+ memberOfName = ldapRole.getDn();
+ }
+ else
+ {
+ memberOfName = ldapRole.getId().toString();
+ }
+
+ String filter =
getMemberAttributeID().concat("=").concat(memberOfName);
+ log.debug("Search filter: " + filter);
+
+
+ //NamingEnumeration results =
getConnectionContext().createInitialContext().search(getUserContainerDN(), filter,
controls);
+ NamingEnumeration results = getUserModule().searchUsers(filter);
+ List sr = Tools.toList(results);
+
+
+ for (Iterator iterator = sr.iterator(); iterator.hasNext();)
+ {
+ SearchResult res = (SearchResult)iterator.next();
+ DirContext ctx = (DirContext)res.getObject();
+
users.add(getUserModule().createUserInstance(res.getAttributes(),ctx.getNameInNamespace()));
+ }
+
+
+
+ }
+ catch (Exception e)
+ {
+ log.debug("Failed to resolve role users: " +
ldapRole.getId().toString(), e);
+ }
+
+ return users;
+
+ }
+
+ public void assignUsers(Role role, Set users) throws IdentityException
+ {
+ if (role == null)
+ {
+ throw new IllegalArgumentException("Role cannot be null");
+ }
+
+ LDAPRoleImpl ldapRole = null;
+
+ if (role instanceof LDAPRoleImpl)
+ {
+ ldapRole = (LDAPRoleImpl)role;
+ }
+ else
+ {
+ throw new IllegalArgumentException("UserMembershipModuleImpl supports only
LDAPRoleImpl objects");
+ }
+
+
+ //First build a list of user DNs to add
+ List userDNsToAdd = new LinkedList();
+
+ for (Iterator iterator = users.iterator(); iterator.hasNext();)
+ {
+ try
+ {
+ LDAPUserImpl user = (LDAPUserImpl)iterator.next();
+ userDNsToAdd.add(user.getDn());
+ }
+ catch(ClassCastException e)
+ {
+ throw new IdentityException("Only can add LDAPUserImpl objects",
e);
+ }
+ }
+
+ String memberOfName=null;
+
+ //Find all the users that currently contain role as member (need to remove role
from some of them)
+ if (isUidAttributeIsDN())
+ {
+ memberOfName = ldapRole.getDn();
+ }
+ else
+ {
+ memberOfName = ldapRole.getId().toString();
+ }
+
+
+ try
+ {
+ String filter =
getMemberAttributeID().concat("=").concat(memberOfName);
+ log.debug("Search filter: " + filter);
+
+ NamingEnumeration results = getUserModule().searchUsers(filter);
+ List sr = Tools.toList(results);
+ //iterate over users that contain a role
+ for (Iterator iterator = sr.iterator(); iterator.hasNext();)
+ {
+ SearchResult res = (SearchResult)iterator.next();
+ DirContext ctx = (DirContext)res.getObject();
+ String userDN = ctx.getNameInNamespace();
+ //if user is one which we want to add
+ if (userDNsToAdd.contains(userDN))
+ {
+ //we do nothing but mark this user as added
+ userDNsToAdd.remove(userDN);
+ continue;
+ }
+ //if it's not on the list we need to remove role from it
+ else
+ {
+ Attribute attr = res.getAttributes().get(getMemberAttributeID());
+
+ attr.remove(memberOfName);
+
+ //and replace attributes
+ Attributes newAttrs = new BasicAttributes(true);
+ //newAttrs.put(getMemberAttributeID(), attr);
+ newAttrs.put(attr);
+
+ getConnectionContext().createInitialContext().modifyAttributes(userDN,
DirContext.REPLACE_ATTRIBUTE, newAttrs);
+
+ //and mark this role as done
+ userDNsToAdd.remove(userDN);
+ }
+ }
+
+ //now iterate over roles that left to process
+ for (Iterator iterator = userDNsToAdd.iterator(); iterator.hasNext();)
+ {
+ String userDN = (String)iterator.next();
+
+ //changes to make
+ ModificationItem[] mods = new ModificationItem[1];
+ mods[0] = new ModificationItem(DirContext.ADD_ATTRIBUTE,
+ new BasicAttribute(getMemberAttributeID(), memberOfName));
+ // Perform the requested modifications on the named object
+ getConnectionContext().createInitialContext().modifyAttributes(userDN,
mods);
+ }
+
+ //and that should be all...
+ }
+ catch (NamingException e)
+ {
+ throw new IdentityException("Failed to assign users", e);
+ }
+ }
+
+ public void assignRoles(User user, Set roles) throws IdentityException
+ {
+ if (user == null)
+ {
+ throw new IllegalArgumentException("User cannot be null");
+ }
+
+ LDAPUserImpl ldapUser = null;
+
+ if (user instanceof LDAPUserImpl)
+ {
+ ldapUser = (LDAPUserImpl)user;
+ }
+ else
+ {
+ throw new IllegalArgumentException("UserMembershipModuleImpl supports only
LDAPUserImpl objects");
+ }
+
+ try
+ {
+ log.debug("findRoles(): user = " + ldapUser.getDn());
+
+ if (ldapUser.getUserName() == null)
+ {
+ throw new IdentityException("User name canot be null");
+ }
+
+ //construct new member attribute values
+ Attributes attrs = new BasicAttributes(true);
+
+ Attribute member = new BasicAttribute(getMemberAttributeID());
+ for (Iterator iterator = roles.iterator(); iterator.hasNext();)
+ {
+ try
+ {
+ LDAPRoleImpl role = (LDAPRoleImpl)iterator.next();
+ if (isUidAttributeIsDN())
+ {
+ member.add(role.getDn());
+ }
+ else
+ {
+ member.add(role.getId().toString());
+ }
+ }
+ catch (ClassCastException e)
+ {
+ throw new IdentityException("Only can add LDAPRoleImpl objects",
e);
+ }
+ }
+ attrs.put(member);
+
+ getConnectionContext().createInitialContext().modifyAttributes(ldapUser.getDn(),
DirContext.REPLACE_ATTRIBUTE, attrs);
+ }
+ catch (NamingException e)
+ {
+ throw new IdentityException("Failed to change Role members", e);
+ }
+
+ }
+
+ //TODO:don't forget to add this....
+ public Set findRoleMembers(String roleName, int offset, int limit, String
userNameFilter) throws IdentityException
+ {
+ throw new UnsupportedOperationException("Not yet implemented");
+ }
+}
Deleted: trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPUserImpl.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPUserImpl.java 2006-12-15
15:15:26 UTC (rev 5871)
+++ trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPUserImpl.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -1,229 +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.identity.IdentityException;
-import org.jboss.portal.identity.ProfileMap;
-import org.jboss.portal.identity2.User;
-import org.jboss.portal.identity2.UserProfileModule;
-import org.jboss.portal.identity2.IdentityContext;
-import org.jboss.portal.identity2.IdentityConfiguration;
-import org.jboss.portal.common.util.Tools;
-
-import java.security.NoSuchAlgorithmException;
-
-/**
- * @author <a href="mailto:boleslaw.dawidowicz@jboss.org">Boleslaw
Dawidowicz</a>
- * @version $Revision: 1.1 $
- */
-public class LDAPUserImpl implements User
-{
- private static final org.jboss.logging.Logger log =
org.jboss.logging.Logger.getLogger(LDAPUserImpl.class);
-
- //TODO: make setters to update the state of the entry
-
- //TODO:this is to enable user act like a fasade to identity modules calls
- IdentityContext identityContext;
-
- private UserProfileModule userProfileModule;
-
- private String dn;
-
- //In ldap implementation it acts as a userName
- private String id;
-
- private String password;
-
- //private String realEmail;
-
- private LDAPUserImpl()
- {
-
- }
-
- /**
- * Creates a ldap user implementation instance
- *
- * @param dn
- * @param context
- * @param password - should contain already encrypted password from ldap
- * @throws IdentityException
- */
- public LDAPUserImpl(String dn, IdentityContext context, String id, String password)
throws IdentityException
- {
- if (dn == null)
- {
- throw new IdentityException("Cannot create LDAPUserImpl without DN");
- }
- this.dn = dn;
-
- if (context == null)
- {
- throw new IllegalArgumentException("IdentityContext can't be
null");
- }
-
- if (password == null)
- {
- throw new IllegalArgumentException("Password can't be null");
- }
-
- if (id == null)
- {
- throw new IllegalArgumentException("Id can't be null");
- }
-
- this.identityContext = context;
- this.password = password;
- //this.realEmail = email;
- this.id = id;
-
- }
-
- public void updatePassword(String password)
- {
- //TODO: somehow update the password to ldap?
- String algorithm = getHashAlgorightm();
- if (algorithm == null)
- {
- this.password = password;
- }
- else
- {
- try
- {
- this.password = Tools.hashAndEncodeString(password,algorithm,
getHashEncoding());
- }
- catch(Exception e)
- {
- log.error("Cannot update the password",e);
- }
- }
- }
-
- public boolean validatePassword(String password)
- {
-
- String algorithm = getHashAlgorightm();
- if (algorithm == null)
- {
- return this.password.equals(password);
- }
- else
- {
- try
- {
- return this.password.equals(Tools.hashAndEncodeString(password,algorithm,
getHashEncoding()));
- }
- catch(NoSuchAlgorithmException e)
- {
- log.error("Cannot validate the password",e);
- }
- return false;
- }
- }
-
- public String getPassword()
- {
- return this.password;
- }
-
- public void setPassword(String password)
- {
- this.password = password;
- }
-
- //**************************
- //*** Getter and Setters
- //**************************
-
- public String getDn()
- {
- return dn;
- }
-
- public void setId(String id)
- {
- this.id = id;
- }
-
-
- public Object getId()
- {
- return id;
- }
-
- public UserProfileModule getUserProfileModule()
- {
- return userProfileModule;
- }
-
- public void setUserProfileModule(UserProfileModule userProfileModule)
- {
- this.userProfileModule = userProfileModule;
- }
-
-
- public String getUserName()
- {
- return this.id;
- }
-
- public void setUserName(String userName)
- {
- this.id = userName;
- }
-
- private IdentityConfiguration getIdentityConfiguration() throws IdentityException
- {
- return
(IdentityConfiguration)identityContext.getObject(IdentityContext.TYPE_IDENTITY_CONFIGURATION);
- }
-
- private String getHashAlgorightm()
- {
- try
- {
- return
getIdentityConfiguration().getValue(IdentityConfiguration.HASH_ALGORITHM);
- }
- catch(Exception e)
- {
- return null;
- }
- }
-
- private String getHashEncoding()
- {
- try
- {
- String enc =
getIdentityConfiguration().getValue(IdentityConfiguration.HASH_ENCODING);
- if (enc != null)
- {
- return enc;
- }
- }
- catch(Exception e)
- {
- //nothing
- }
- return "hex";
- }
-}
Copied: trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPUserImpl.java (from rev
5883, trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPUserImpl.java)
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPUserImpl.java 2006-12-17
14:26:07 UTC (rev 5883)
+++ trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPUserImpl.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -0,0 +1,228 @@
+/******************************************************************************
+ * 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.identity.ldap;
+
+import org.jboss.portal.identity.IdentityException;
+import org.jboss.portal.identity.IdentityConfiguration;
+import org.jboss.portal.identity.IdentityContext;
+import org.jboss.portal.identity.User;
+import org.jboss.portal.identity.UserProfileModule;
+import org.jboss.portal.common.util.Tools;
+
+import java.security.NoSuchAlgorithmException;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz@jboss.org">Boleslaw
Dawidowicz</a>
+ * @version $Revision: 1.1 $
+ */
+public class LDAPUserImpl implements User
+{
+ private static final org.jboss.logging.Logger log =
org.jboss.logging.Logger.getLogger(LDAPUserImpl.class);
+
+ //TODO: make setters to update the state of the entry
+
+ //TODO:this is to enable user act like a fasade to identity modules calls
+ IdentityContext identityContext;
+
+ private UserProfileModule userProfileModule;
+
+ private String dn;
+
+ //In ldap implementation it acts as a userName
+ private String id;
+
+ private String password;
+
+ //private String realEmail;
+
+ private LDAPUserImpl()
+ {
+
+ }
+
+ /**
+ * Creates a ldap user implementation instance
+ *
+ * @param dn
+ * @param context
+ * @param password - should contain already encrypted password from ldap
+ * @throws IdentityException
+ */
+ protected LDAPUserImpl(String dn, IdentityContext context, String id, String password)
throws IdentityException
+ {
+ if (dn == null)
+ {
+ throw new IdentityException("Cannot create LDAPUserImpl without DN");
+ }
+ this.dn = dn;
+
+ if (context == null)
+ {
+ throw new IllegalArgumentException("IdentityContext can't be
null");
+ }
+
+ if (password == null)
+ {
+ throw new IllegalArgumentException("Password can't be null");
+ }
+
+ if (id == null)
+ {
+ throw new IllegalArgumentException("Id can't be null");
+ }
+
+ this.identityContext = context;
+ this.password = password;
+ //this.realEmail = email;
+ this.id = id;
+
+ }
+
+ public void updatePassword(String password)
+ {
+ //TODO: somehow update the password to ldap?
+ String algorithm = getHashAlgorightm();
+ if (algorithm == null)
+ {
+ this.password = password;
+ }
+ else
+ {
+ try
+ {
+ this.password = Tools.hashAndEncodeString(password,algorithm,
getHashEncoding());
+ }
+ catch(Exception e)
+ {
+ log.error("Cannot update the password",e);
+ }
+ }
+ }
+
+ public boolean validatePassword(String password)
+ {
+
+ String algorithm = getHashAlgorightm();
+ if (algorithm == null)
+ {
+ return this.password.equals(password);
+ }
+ else
+ {
+ try
+ {
+ return this.password.equals(Tools.hashAndEncodeString(password,algorithm,
getHashEncoding()));
+ }
+ catch(NoSuchAlgorithmException e)
+ {
+ log.error("Cannot validate the password",e);
+ }
+ return false;
+ }
+ }
+
+ public String getPassword()
+ {
+ return this.password;
+ }
+
+ public void setPassword(String password)
+ {
+ this.password = password;
+ }
+
+ //**************************
+ //*** Getter and Setters
+ //**************************
+
+ public String getDn()
+ {
+ return dn;
+ }
+
+ public void setId(String id)
+ {
+ this.id = id;
+ }
+
+
+ public Object getId()
+ {
+ return id;
+ }
+
+ public UserProfileModule getUserProfileModule()
+ {
+ return userProfileModule;
+ }
+
+ public void setUserProfileModule(UserProfileModule userProfileModule)
+ {
+ this.userProfileModule = userProfileModule;
+ }
+
+
+ public String getUserName()
+ {
+ return this.id;
+ }
+
+ public void setUserName(String userName)
+ {
+ this.id = userName;
+ }
+
+ private IdentityConfiguration getIdentityConfiguration() throws IdentityException
+ {
+ return
(IdentityConfiguration)identityContext.getObject(IdentityContext.TYPE_IDENTITY_CONFIGURATION);
+ }
+
+ private String getHashAlgorightm()
+ {
+ try
+ {
+ return
getIdentityConfiguration().getValue(IdentityConfiguration.HASH_ALGORITHM);
+ }
+ catch(Exception e)
+ {
+ return null;
+ }
+ }
+
+ private String getHashEncoding()
+ {
+ try
+ {
+ String enc =
getIdentityConfiguration().getValue(IdentityConfiguration.HASH_ENCODING);
+ if (enc != null)
+ {
+ return enc;
+ }
+ }
+ catch(Exception e)
+ {
+ //nothing
+ }
+ return "hex";
+ }
+}
Deleted: trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPUserModule.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPUserModule.java 2006-12-15
15:15:26 UTC (rev 5871)
+++ trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPUserModule.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -1,252 +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.IdentityConfiguration;
-import org.jboss.portal.identity2.IdentityContext;
-import org.jboss.portal.identity2.UserProfileModule;
-import org.jboss.portal.identity.IdentityException;
-import org.jboss.portal.identity2.User;
-import org.jboss.portal.identity2.service.UserModuleService;
-import org.jboss.portal.identity.NoSuchUserException;
-
-import javax.naming.directory.Attributes;
-import javax.naming.directory.Attribute;
-import javax.naming.NamingException;
-import javax.naming.NamingEnumeration;
-import javax.naming.InitialContext;
-import java.util.NoSuchElementException;
-import java.util.Map;
-
-/**
- * Abstract LDAPUserModule that should be extended to provide compabitibility across
identity modules
- *
- * @author <a href="mailto:boleslaw dot dawidowicz at jboss.com">Boleslaw
Dawidowicz</a>
- * @version $Revision: 1.1 $
- */
-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 UserProfileModule userProfileModule;
-
-
- protected void startService() throws Exception
- {
- if (getConnectionJNDIName() == null)
- {
- throw new IdentityException("Cannot obtain ldap connection context JNDI
name");
- }
-
- connectionContext = (LDAPConnectionContext)new
InitialContext().lookup(getConnectionJNDIName());
-
- super.startService(); //To change body of overridden methods use File | Settings
| File Templates.
- }
-
- //TODO: add enabled
- public LDAPUserImpl createUserInstance(Attributes attrs, String dn) throws
IdentityException
- {
- LDAPUserImpl ldapu = null;
- try
- {
- log.debug("Search result attributes: " + attrs);
-
-
- Attribute uida = attrs.get(getUidAttributeID());
- if (uida == null)
- {
- throw new IdentityException("LDAP entry doesn't contain proper
attribute:" + getUidAttributeID());
- }
-
- Attribute passwd = attrs.get(getPasswordAttributeId());
- if (passwd == null)
- {
- throw new IdentityException("LDAP entry doesn't contain proper
attribute:" + getPasswordAttributeId());
- }
-
- ldapu = new LDAPUserImpl(dn,getIdentityContext(), uida.get().toString(),
passwd.get().toString());
-
-
- log.debug("user uid: " + ldapu.getId());
- log.debug("user dn: " + ldapu.getDn());
-
-
- }
- catch (NamingException e)
- {
- throw new IdentityException("Couldn't create LDAPUserImpl object from
ldap entry (SearchResult)", e);
- }
-
- return ldapu;
- }
-
- /**
- * method not belonging to UserModule interface - ldap specific.
- *
- */
- public User findUserByDN(String dn) throws IdentityException,
IllegalArgumentException, NoSuchUserException
- {
- try
- {
- log.debug("findUserByDN(): DN = " + dn);
-
- if (dn == null)
- {
- throw new IdentityException("User dn canot be null");
- }
-
- Attributes attrs =
getConnectionContext().createInitialContext().getAttributes(dn);
-
- if (attrs == null)
- {
- throw new IdentityException("Can't find user entry with DN: " +
dn);
- }
-
- return createUserInstance(attrs, dn);
-
- }
- catch (NoSuchElementException e)
- {
- log.debug("No user found with dn: " + dn, e);
- }
- catch (NamingException e)
- {
- throw new IdentityException("User search failed.", e);
- }
- return null;
-
- }
-
- /**
- * This method should be used by over modules to perform searches. It will allow user
module
- * implementation to apply proper filter and search scope from the configuration
- *
- * @param filter that will be concatenated with proper user search filter from the
module
- * @return
- */
- public abstract NamingEnumeration searchUsers(String filter) throws NamingException,
IdentityException;
-
-
- //**************************
- //*** Getter and Setters
- //**************************
-
- protected UserProfileModule getUserProfileModule() throws IdentityException
- {
- if (userProfileModule == null)
- {
- this.userProfileModule =
(UserProfileModule)getIdentityContext().getObject(IdentityContext.TYPE_USER_PROFILE_MODULE);
- }
- return userProfileModule;
- }
-
- protected String getUidAttributeID() throws IdentityException
- {
- String uid =
getIdentityConfiguration().getValue(IdentityConfiguration.USER_UID_ATTRIBUTE_ID);
- if (uid == null)
- {
- return "uid";
- }
- return uid;
- }
-
- protected String getHashAlgorightm()
- {
- try
- {
- return
getIdentityConfiguration().getValue(IdentityConfiguration.HASH_ALGORITHM);
- }
- catch(Exception e)
- {
- return null;
- }
- }
-
- protected String getHashEncoding() throws IdentityException
- {
- String enc =
getIdentityConfiguration().getValue(IdentityConfiguration.HASH_ENCODING);
- if (enc == null)
- {
- return "hex";
- }
- return enc;
- }
-
- protected LDAPConnectionContext getConnectionContext() throws IdentityException
- {
- if (connectionContext == null)
- {
- //this.connectionContext =
(LDAPConnectionContext)getIdentityContext().getObject(IdentityContext.TYPE_CONNECTION_CONTEXT);
- throw new IdentityException("No LDAPConnectionContext available");
- }
- return connectionContext;
- }
-
- protected String getContainerDN() throws IdentityException
- {
- String cont =
getIdentityConfiguration().getValue(IdentityConfiguration.USER_CONTAINER_DN);
- if (cont == null)
- {
- throw new IdentityException("Configuration option missing: " +
IdentityConfiguration.USER_CONTAINER_DN);
- }
- return cont;
- }
-
- protected String getPasswordAttributeId() throws IdentityException
- {
- String passwd =
getIdentityConfiguration().getValue(IdentityConfiguration.USER_PASSWORD_ATTRIBUTE_ID);
- if (passwd == null)
- {
- return "userPassword";
- }
- else
- {
- return passwd;
- }
- }
-
- /*protected String getEmailAttributeId() throws IdentityException
- {
- String email =
getIdentityConfiguration().getValue(IdentityConfiguration.USER_EMAIL_ATTRIBUTE_ID);
- if (email == null)
- {
- return "mail";
- }
- else
- {
- return email;
- }
- }*/
-
- protected Map getAttributesToAdd() throws IdentityException
- {
- Map attributesToAdd =
getIdentityConfiguration().getOptions(IdentityConfiguration.GROUP_USER_CREATE_ATTRIBUTES);
- if (attributesToAdd == null)
- {
- throw new IdentityException(IdentityConfiguration.GROUP_USER_CREATE_ATTRIBUTES +
" missing in configuration");
- }
- return attributesToAdd;
- }
-
-}
Copied: trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPUserModule.java (from
rev 5883, trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPUserModule.java)
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPUserModule.java 2006-12-17
14:26:07 UTC (rev 5883)
+++ trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPUserModule.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -0,0 +1,252 @@
+/*
+* 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.identity.ldap;
+
+import org.jboss.portal.identity.service.UserModuleService;
+import org.jboss.portal.identity.IdentityException;
+import org.jboss.portal.identity.UserProfileModule;
+import org.jboss.portal.identity.NoSuchUserException;
+import org.jboss.portal.identity.User;
+import org.jboss.portal.identity.IdentityContext;
+import org.jboss.portal.identity.IdentityConfiguration;
+
+import javax.naming.directory.Attributes;
+import javax.naming.directory.Attribute;
+import javax.naming.NamingException;
+import javax.naming.NamingEnumeration;
+import javax.naming.InitialContext;
+import java.util.NoSuchElementException;
+import java.util.Map;
+
+/**
+ * Abstract LDAPUserModule that should be extended to provide compabitibility across
identity modules
+ *
+ * @author <a href="mailto:boleslaw dot dawidowicz at jboss.com">Boleslaw
Dawidowicz</a>
+ * @version $Revision: 1.1 $
+ */
+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 UserProfileModule userProfileModule;
+
+
+ protected void startService() throws Exception
+ {
+ if (getConnectionJNDIName() == null)
+ {
+ throw new IdentityException("Cannot obtain ldap connection context JNDI
name");
+ }
+
+ connectionContext = (LDAPConnectionContext)new
InitialContext().lookup(getConnectionJNDIName());
+
+ super.startService(); //To change body of overridden methods use File | Settings
| File Templates.
+ }
+
+ //TODO: add enabled
+ public LDAPUserImpl createUserInstance(Attributes attrs, String dn) throws
IdentityException
+ {
+ LDAPUserImpl ldapu = null;
+ try
+ {
+ log.debug("Search result attributes: " + attrs);
+
+
+ Attribute uida = attrs.get(getUidAttributeID());
+ if (uida == null)
+ {
+ throw new IdentityException("LDAP entry doesn't contain proper
attribute:" + getUidAttributeID());
+ }
+
+ Attribute passwd = attrs.get(getPasswordAttributeId());
+ if (passwd == null)
+ {
+ throw new IdentityException("LDAP entry doesn't contain proper
attribute:" + getPasswordAttributeId());
+ }
+
+ ldapu = new LDAPUserImpl(dn,getIdentityContext(), uida.get().toString(),
passwd.get().toString());
+
+
+ log.debug("user uid: " + ldapu.getId());
+ log.debug("user dn: " + ldapu.getDn());
+
+
+ }
+ catch (NamingException e)
+ {
+ throw new IdentityException("Couldn't create LDAPUserImpl object from
ldap entry (SearchResult)", e);
+ }
+
+ return ldapu;
+ }
+
+ /**
+ * method not belonging to UserModule interface - ldap specific.
+ *
+ */
+ public User findUserByDN(String dn) throws IdentityException,
IllegalArgumentException, NoSuchUserException
+ {
+ try
+ {
+ log.debug("findUserByDN(): DN = " + dn);
+
+ if (dn == null)
+ {
+ throw new IdentityException("User dn canot be null");
+ }
+
+ Attributes attrs =
getConnectionContext().createInitialContext().getAttributes(dn);
+
+ if (attrs == null)
+ {
+ throw new IdentityException("Can't find user entry with DN: " +
dn);
+ }
+
+ return createUserInstance(attrs, dn);
+
+ }
+ catch (NoSuchElementException e)
+ {
+ log.debug("No user found with dn: " + dn, e);
+ }
+ catch (NamingException e)
+ {
+ throw new IdentityException("User search failed.", e);
+ }
+ return null;
+
+ }
+
+ /**
+ * This method should be used by over modules to perform searches. It will allow user
module
+ * implementation to apply proper filter and search scope from the configuration
+ *
+ * @param filter that will be concatenated with proper user search filter from the
module
+ * @return
+ */
+ public abstract NamingEnumeration searchUsers(String filter) throws NamingException,
IdentityException;
+
+
+ //**************************
+ //*** Getter and Setters
+ //**************************
+
+ protected UserProfileModule getUserProfileModule() throws IdentityException
+ {
+ if (userProfileModule == null)
+ {
+ this.userProfileModule =
(UserProfileModule)getIdentityContext().getObject(IdentityContext.TYPE_USER_PROFILE_MODULE);
+ }
+ return userProfileModule;
+ }
+
+ protected String getUidAttributeID() throws IdentityException
+ {
+ String uid =
getIdentityConfiguration().getValue(IdentityConfiguration.USER_UID_ATTRIBUTE_ID);
+ if (uid == null)
+ {
+ return "uid";
+ }
+ return uid;
+ }
+
+ protected String getHashAlgorightm()
+ {
+ try
+ {
+ return
getIdentityConfiguration().getValue(IdentityConfiguration.HASH_ALGORITHM);
+ }
+ catch(Exception e)
+ {
+ return null;
+ }
+ }
+
+ protected String getHashEncoding() throws IdentityException
+ {
+ String enc =
getIdentityConfiguration().getValue(IdentityConfiguration.HASH_ENCODING);
+ if (enc == null)
+ {
+ return "hex";
+ }
+ return enc;
+ }
+
+ protected LDAPConnectionContext getConnectionContext() throws IdentityException
+ {
+ if (connectionContext == null)
+ {
+ //this.connectionContext =
(LDAPConnectionContext)getIdentityContext().getObject(IdentityContext.TYPE_CONNECTION_CONTEXT);
+ throw new IdentityException("No LDAPConnectionContext available");
+ }
+ return connectionContext;
+ }
+
+ protected String getContainerDN() throws IdentityException
+ {
+ String cont =
getIdentityConfiguration().getValue(IdentityConfiguration.USER_CONTAINER_DN);
+ if (cont == null)
+ {
+ throw new IdentityException("Configuration option missing: " +
IdentityConfiguration.USER_CONTAINER_DN);
+ }
+ return cont;
+ }
+
+ protected String getPasswordAttributeId() throws IdentityException
+ {
+ String passwd =
getIdentityConfiguration().getValue(IdentityConfiguration.USER_PASSWORD_ATTRIBUTE_ID);
+ if (passwd == null)
+ {
+ return "userPassword";
+ }
+ else
+ {
+ return passwd;
+ }
+ }
+
+ /*protected String getEmailAttributeId() throws IdentityException
+ {
+ String email =
getIdentityConfiguration().getValue(IdentityConfiguration.USER_EMAIL_ATTRIBUTE_ID);
+ if (email == null)
+ {
+ return "mail";
+ }
+ else
+ {
+ return email;
+ }
+ }*/
+
+ protected Map getAttributesToAdd() throws IdentityException
+ {
+ Map attributesToAdd =
getIdentityConfiguration().getOptions(IdentityConfiguration.GROUP_USER_CREATE_ATTRIBUTES);
+ if (attributesToAdd == null)
+ {
+ throw new IdentityException(IdentityConfiguration.GROUP_USER_CREATE_ATTRIBUTES +
" missing in configuration");
+ }
+ return attributesToAdd;
+ }
+
+}
Deleted: trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPUserModuleImpl.java
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPUserModuleImpl.java 2006-12-15
15:15:26 UTC (rev 5871)
+++
trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPUserModuleImpl.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -1,327 +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.common.util.Tools;
-import org.jboss.portal.identity.IdentityException;
-import org.jboss.portal.identity.NoSuchUserException;
-import org.jboss.portal.identity2.User;
-import org.jboss.portal.identity2.IdentityConfiguration;
-
-import javax.naming.NamingEnumeration;
-import javax.naming.NamingException;
-import javax.naming.Context;
-import javax.naming.directory.Attribute;
-import javax.naming.directory.Attributes;
-import javax.naming.directory.BasicAttribute;
-import javax.naming.directory.BasicAttributes;
-import javax.naming.directory.SearchControls;
-import javax.naming.directory.SearchResult;
-import javax.naming.ldap.LdapContext;
-import java.util.List;
-import java.util.NoSuchElementException;
-import java.util.Set;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Iterator;
-import java.security.NoSuchAlgorithmException;
-
-/**
- * Simple implementation of UserModule for LDAP support. Search of users is limited to
one place * containerField - DN
- * of entry containing users (like ou=People,dc=example,dc=com). It's where users
will be added using createUser()
- * method. Under this DN users will be searched using ONELEVEL_SCOPE * uidAttributeID -
attribute that stores user id.
- * Default value is "uid"
- *
- * @author <a href="mailto:boleslaw.dawidowicz@jboss.org">Boleslaw
Dawidowicz</a>
- * @version $Revision: 1.1 $
- */
-public class LDAPUserModuleImpl extends LDAPUserModule
-{
- private static final org.jboss.logging.Logger log =
org.jboss.logging.Logger.getLogger(LDAPUserModuleImpl.class);
-
- public User findUserByUserName(String userName) throws IdentityException,
IllegalArgumentException, NoSuchUserException
- {
- try
- {
- log.debug("findUserByUserName(): username = " + userName);
-
- if (userName == null)
- {
- throw new IdentityException("User name canot be null");
- }
-
-
- String filter =
"(".concat(getUidAttributeID()).concat("=").concat(userName).concat(")");
- log.debug("Search filter: " + filter);
-
- NamingEnumeration results = searchUsers(filter);
- List sr = Tools.toList(results);
- if (sr.size() > 1)
- {
- throw new IdentityException("Found more than one user with id: " +
userName + "" +
- "Posible data inconsistency");
- }
- SearchResult res = (SearchResult)sr.iterator().next();
- Context ctx = (Context)res.getObject();
- String dn = ctx.getNameInNamespace();
- return createUserInstance(res.getAttributes(), dn);
-
- }
- catch (NoSuchElementException e)
- {
- log.debug("No user found with name: " + userName, e);
- }
- catch (NamingException e)
- {
- throw new IdentityException("User search failed.", e);
- }
- return null;
-
- }
-
- public User findUserById(Object id) throws IdentityException,
IllegalArgumentException, NoSuchUserException
- {
- if (id == null)
- {
- throw new IdentityException("Cannot search user with null id");
- }
- if (!(id instanceof String))
- {
- throw new IdentityException("Only String id is suppoted");
- }
- return findUserById((String)id);
-
- }
-
- public User findUserById(String id) throws IdentityException,
IllegalArgumentException, NoSuchUserException
- {
- return findUserByUserName(id);
- }
-
-
-
-
- public User createUser(String userName, String password) throws IdentityException,
IllegalArgumentException
- {
-
- if (userName == null)
- {
- throw new IdentityException("User name cannot be null");
- }
- /*if (realEmail == null)
- {
- throw new IdentityException("User email cannot be null");
- }*/
- if (password == null)
- {
- throw new IdentityException("User password cannot be null");
- }
-
- log.debug("Creating user: " + userName);
-
-
- try
- {
- //
- LdapContext ctx =
(LdapContext)getConnectionContext().createInitialContext().lookup(getContainerDN());
-
- //We store new entry using set of attributes. This should give more flexibility
then
- //extending user object from ContextDir - configure what objectClass place
there
- Attributes attrs = new BasicAttributes(true);
-
- //create attribute using provided configuration
- Map attributesToAdd = getAttributesToAdd();
-
- //attributes
- for (Iterator it1 = attributesToAdd.keySet().iterator(); it1.hasNext();)
- {
- String attributeName = (String)it1.next();
- log.debug("adding attribute: " + attributeName);
- Attribute attr = new BasicAttribute(attributeName);
- Set attributeValues = (Set)attributesToAdd.get(attributeName);
-
- //values
- for (Iterator it2 = attributeValues.iterator(); it2.hasNext();)
- {
- String attrValue = (String)it2.next();
- log.debug("adding attribute value: " + attrValue);
- attr.add(attrValue);
- }
- attrs.put(attr);
- }
-
- //TODO:testcase password behaviour
- String algorithm = getHashAlgorightm();
- if (algorithm == null)
- {
- attrs.put(getPasswordAttributeId(), password);
- }
- else
- {
- attrs.put(getPasswordAttributeId(),
Tools.hashAndEncodeString(password,algorithm, getHashEncoding()));
- }
-
- //
- //email
- //attrs.put(getEmailAttributeId(), realEmail);
-
- String dn = getUidAttributeID().concat("=").concat(userName);
-
- log.debug("creating ldap entry for: " + dn + "; " + attrs);
- ctx.createSubcontext(dn, attrs);
- }
- catch (NoSuchAlgorithmException e)
- {
- throw new IdentityException("Failed to create user", e);
- }
- catch (NamingException e)
- {
- throw new IdentityException("Failed to create user", e);
- }
-
- return findUserByUserName(userName);
- }
-
- //TODO: remove user assignments before?
- public void removeUser(Object id) throws IdentityException, IllegalArgumentException
- {
-
- LDAPUserImpl ldapu = (LDAPUserImpl)findUserById(id);
-
- if (ldapu == null)
- {
- throw new IdentityException("Cannot find user for removal");
- }
-
- if (ldapu.getDn() == null)
- {
- throw new IdentityException("Cannot obtain DN of user");
- }
-
- try
- {
- LdapContext ctx =
getConnectionContext().createInitialContext();//.lookup(getContainerDN());
- log.debug("removing entry: " + ldapu.getDn());
- ctx.unbind(ldapu.getDn());
- }
- catch (Exception e)
- {
- throw new IdentityException("Failed to remove user: ", e);
- }
-
-
- }
-
-
- public Set findUsers(int offset, int limit) throws IdentityException,
IllegalArgumentException
- {
-
- return findUsersFilteredByUserName("*",0,0);
-
- }
-
- //TODO:implement something to use offset and limit - sort asc and
- //TODO: and testcase this...
- public Set findUsersFilteredByUserName(String filter, int offset, int limit) throws
IdentityException, IllegalArgumentException
- {
- log.info("Current implementation of findUsersFilteredByUserName returns all
users and is not \"offset\" and \"limit\" sensitive ");
-
- Set uf = new HashSet();
-
- try
- {
- //search all entries containing "uid" attribute
- String ldap_filter =
"(".concat(getUidAttributeID()).concat("=").concat(filter).concat(")");
- log.debug("Search filter: " + filter);
-
-
- NamingEnumeration results = searchUsers(ldap_filter);
- while (results.hasMoreElements())
- {
- SearchResult res = (SearchResult)results.nextElement();
- Context ctx = (Context)res.getObject();
- String dn = ctx.getNameInNamespace();
- uf.add(createUserInstance(res.getAttributes(), dn));
- }
- }
- catch (NoSuchElementException e)
- {
- log.debug("No users found", e);
- }
- catch (Exception e)
- {
- throw new IdentityException("User search failed.", e);
- }
- return uf;
-
- }
-
- public int getUserCount() throws IdentityException, IllegalArgumentException
- {
- try
- {
- //search all entries containing "uid" attribute
- String filter =
"(".concat(getUidAttributeID()).concat("=").concat("*").concat(")");
- log.debug("Search filter: " + filter);
-
-
- NamingEnumeration results = searchUsers(filter);
- List sr = Tools.toList(results);
-
- return sr.size();
-
- }
- catch (NoSuchElementException e)
- {
- log.debug("No users found", e);
- }
- catch (Exception e)
- {
- throw new IdentityException("User search failed.", e);
- }
- return 0;
- }
-
-
- /**
- * This method should be used by over modules to perform searches. It will allow user
module
- * implementation to apply proper filter and search scope from the configuration
- *
- * @param filter that will be concatenated with proper user search filter from the
module
- * @return
- */
- public NamingEnumeration searchUsers(String filter) throws NamingException,
IdentityException
- {
- SearchControls controls = new SearchControls();
- controls.setSearchScope(SearchControls.ONELEVEL_SCOPE);
- controls.setReturningObjFlag(true);
-
- //String filter = getUidAttributeID().concat("=").concat(userName);
- log.debug("Search filter: " + filter);
-
-
- return getConnectionContext().createInitialContext().search(getContainerDN(),
filter, controls);
- }
-}
-
-
Copied: trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPUserModuleImpl.java
(from rev 5883,
trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPUserModuleImpl.java)
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPUserModuleImpl.java 2006-12-17
14:26:07 UTC (rev 5883)
+++
trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPUserModuleImpl.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -0,0 +1,326 @@
+/******************************************************************************
+ * 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.identity.ldap;
+
+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 javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.Context;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.BasicAttribute;
+import javax.naming.directory.BasicAttributes;
+import javax.naming.directory.SearchControls;
+import javax.naming.directory.SearchResult;
+import javax.naming.ldap.LdapContext;
+import java.util.List;
+import java.util.NoSuchElementException;
+import java.util.Set;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Iterator;
+import java.security.NoSuchAlgorithmException;
+
+/**
+ * Simple implementation of UserModule for LDAP support. Search of users is limited to
one place * containerField - DN
+ * of entry containing users (like ou=People,dc=example,dc=com). It's where users
will be added using createUser()
+ * method. Under this DN users will be searched using ONELEVEL_SCOPE * uidAttributeID -
attribute that stores user id.
+ * Default value is "uid"
+ *
+ * @author <a href="mailto:boleslaw.dawidowicz@jboss.org">Boleslaw
Dawidowicz</a>
+ * @version $Revision: 1.1 $
+ */
+public class LDAPUserModuleImpl extends LDAPUserModule
+{
+ private static final org.jboss.logging.Logger log =
org.jboss.logging.Logger.getLogger(LDAPUserModuleImpl.class);
+
+ public User findUserByUserName(String userName) throws IdentityException,
IllegalArgumentException, NoSuchUserException
+ {
+ try
+ {
+ log.debug("findUserByUserName(): username = " + userName);
+
+ if (userName == null)
+ {
+ throw new IdentityException("User name canot be null");
+ }
+
+
+ String filter =
"(".concat(getUidAttributeID()).concat("=").concat(userName).concat(")");
+ log.debug("Search filter: " + filter);
+
+ NamingEnumeration results = searchUsers(filter);
+ List sr = Tools.toList(results);
+ if (sr.size() > 1)
+ {
+ throw new IdentityException("Found more than one user with id: " +
userName + "" +
+ "Posible data inconsistency");
+ }
+ SearchResult res = (SearchResult)sr.iterator().next();
+ Context ctx = (Context)res.getObject();
+ String dn = ctx.getNameInNamespace();
+ return createUserInstance(res.getAttributes(), dn);
+
+ }
+ catch (NoSuchElementException e)
+ {
+ log.debug("No user found with name: " + userName, e);
+ }
+ catch (NamingException e)
+ {
+ throw new IdentityException("User search failed.", e);
+ }
+ return null;
+
+ }
+
+ public User findUserById(Object id) throws IdentityException,
IllegalArgumentException, NoSuchUserException
+ {
+ if (id == null)
+ {
+ throw new IdentityException("Cannot search user with null id");
+ }
+ if (!(id instanceof String))
+ {
+ throw new IdentityException("Only String id is suppoted");
+ }
+ return findUserById((String)id);
+
+ }
+
+ public User findUserById(String id) throws IdentityException,
IllegalArgumentException, NoSuchUserException
+ {
+ return findUserByUserName(id);
+ }
+
+
+
+
+ public User createUser(String userName, String password) throws IdentityException,
IllegalArgumentException
+ {
+
+ if (userName == null)
+ {
+ throw new IdentityException("User name cannot be null");
+ }
+ /*if (realEmail == null)
+ {
+ throw new IdentityException("User email cannot be null");
+ }*/
+ if (password == null)
+ {
+ throw new IdentityException("User password cannot be null");
+ }
+
+ log.debug("Creating user: " + userName);
+
+
+ try
+ {
+ //
+ LdapContext ctx =
(LdapContext)getConnectionContext().createInitialContext().lookup(getContainerDN());
+
+ //We store new entry using set of attributes. This should give more flexibility
then
+ //extending user object from ContextDir - configure what objectClass place
there
+ Attributes attrs = new BasicAttributes(true);
+
+ //create attribute using provided configuration
+ Map attributesToAdd = getAttributesToAdd();
+
+ //attributes
+ for (Iterator it1 = attributesToAdd.keySet().iterator(); it1.hasNext();)
+ {
+ String attributeName = (String)it1.next();
+ log.debug("adding attribute: " + attributeName);
+ Attribute attr = new BasicAttribute(attributeName);
+ Set attributeValues = (Set)attributesToAdd.get(attributeName);
+
+ //values
+ for (Iterator it2 = attributeValues.iterator(); it2.hasNext();)
+ {
+ String attrValue = (String)it2.next();
+ log.debug("adding attribute value: " + attrValue);
+ attr.add(attrValue);
+ }
+ attrs.put(attr);
+ }
+
+ //TODO:testcase password behaviour
+ String algorithm = getHashAlgorightm();
+ if (algorithm == null)
+ {
+ attrs.put(getPasswordAttributeId(), password);
+ }
+ else
+ {
+ attrs.put(getPasswordAttributeId(),
Tools.hashAndEncodeString(password,algorithm, getHashEncoding()));
+ }
+
+ //
+ //email
+ //attrs.put(getEmailAttributeId(), realEmail);
+
+ String dn = getUidAttributeID().concat("=").concat(userName);
+
+ log.debug("creating ldap entry for: " + dn + "; " + attrs);
+ ctx.createSubcontext(dn, attrs);
+ }
+ catch (NoSuchAlgorithmException e)
+ {
+ throw new IdentityException("Failed to create user", e);
+ }
+ catch (NamingException e)
+ {
+ throw new IdentityException("Failed to create user", e);
+ }
+
+ return findUserByUserName(userName);
+ }
+
+ //TODO: remove user assignments before?
+ public void removeUser(Object id) throws IdentityException, IllegalArgumentException
+ {
+
+ LDAPUserImpl ldapu = (LDAPUserImpl)findUserById(id);
+
+ if (ldapu == null)
+ {
+ throw new IdentityException("Cannot find user for removal");
+ }
+
+ if (ldapu.getDn() == null)
+ {
+ throw new IdentityException("Cannot obtain DN of user");
+ }
+
+ try
+ {
+ LdapContext ctx =
getConnectionContext().createInitialContext();//.lookup(getContainerDN());
+ log.debug("removing entry: " + ldapu.getDn());
+ ctx.unbind(ldapu.getDn());
+ }
+ catch (Exception e)
+ {
+ throw new IdentityException("Failed to remove user: ", e);
+ }
+
+
+ }
+
+
+ public Set findUsers(int offset, int limit) throws IdentityException,
IllegalArgumentException
+ {
+
+ return findUsersFilteredByUserName("*",0,0);
+
+ }
+
+ //TODO:implement something to use offset and limit - sort asc and
+ //TODO: and testcase this...
+ public Set findUsersFilteredByUserName(String filter, int offset, int limit) throws
IdentityException, IllegalArgumentException
+ {
+ log.info("Current implementation of findUsersFilteredByUserName returns all
users and is not \"offset\" and \"limit\" sensitive ");
+
+ Set uf = new HashSet();
+
+ try
+ {
+ //search all entries containing "uid" attribute
+ String ldap_filter =
"(".concat(getUidAttributeID()).concat("=").concat(filter).concat(")");
+ log.debug("Search filter: " + filter);
+
+
+ NamingEnumeration results = searchUsers(ldap_filter);
+ while (results.hasMoreElements())
+ {
+ SearchResult res = (SearchResult)results.nextElement();
+ Context ctx = (Context)res.getObject();
+ String dn = ctx.getNameInNamespace();
+ uf.add(createUserInstance(res.getAttributes(), dn));
+ }
+ }
+ catch (NoSuchElementException e)
+ {
+ log.debug("No users found", e);
+ }
+ catch (Exception e)
+ {
+ throw new IdentityException("User search failed.", e);
+ }
+ return uf;
+
+ }
+
+ public int getUserCount() throws IdentityException, IllegalArgumentException
+ {
+ try
+ {
+ //search all entries containing "uid" attribute
+ String filter =
"(".concat(getUidAttributeID()).concat("=").concat("*").concat(")");
+ log.debug("Search filter: " + filter);
+
+
+ NamingEnumeration results = searchUsers(filter);
+ List sr = Tools.toList(results);
+
+ return sr.size();
+
+ }
+ catch (NoSuchElementException e)
+ {
+ log.debug("No users found", e);
+ }
+ catch (Exception e)
+ {
+ throw new IdentityException("User search failed.", e);
+ }
+ return 0;
+ }
+
+
+ /**
+ * This method should be used by over modules to perform searches. It will allow user
module
+ * implementation to apply proper filter and search scope from the configuration
+ *
+ * @param filter that will be concatenated with proper user search filter from the
module
+ * @return
+ */
+ public NamingEnumeration searchUsers(String filter) throws NamingException,
IdentityException
+ {
+ SearchControls controls = new SearchControls();
+ controls.setSearchScope(SearchControls.ONELEVEL_SCOPE);
+ controls.setReturningObjFlag(true);
+
+ //String filter = getUidAttributeID().concat("=").concat(userName);
+ log.debug("Search filter: " + filter);
+
+
+ return getConnectionContext().createInitialContext().search(getContainerDN(),
filter, controls);
+ }
+}
+
+
Deleted:
trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPUserProfileModule.java
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPUserProfileModule.java 2006-12-15
15:15:26 UTC (rev 5871)
+++
trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPUserProfileModule.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -1,64 +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.service.UserProfileModuleService;
-import org.jboss.portal.identity.IdentityException;
-
-import javax.naming.InitialContext;
-
-/**
- * @author <a href="mailto:boleslaw.dawidowicz@jboss.org">Boleslaw
Dawidowicz</a>
- * @version $Revision: 1.1 $
- */
-public abstract class LDAPUserProfileModule extends UserProfileModuleService
-{
- private LDAPConnectionContext connectionContext;
-
- protected void startService() throws Exception
- {
- if (getConnectionJNDIName() == null)
- {
- throw new IdentityException("Cannot obtain ldap connection context JNDI
name");
- }
- connectionContext = (LDAPConnectionContext)new
InitialContext().lookup(getConnectionJNDIName());
-
- super.startService(); //To change body of overridden methods use File | Settings
| File Templates.
- }
-
- protected LDAPConnectionContext getConnectionContext() throws IdentityException
- {
- if (connectionContext == null)
- {
- //this.connectionContext =
(LDAPConnectionContext)getIdentityContext().getObject(IdentityContext.TYPE_CONNECTION_CONTEXT);
- throw new IdentityException("No LDAPConnectionContext available");
- }
- return connectionContext;
- }
-
- public void setConnectionContext(LDAPConnectionContext connectionContext)
- {
- this.connectionContext = connectionContext;
- }
-
-}
Copied: trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPUserProfileModule.java
(from rev 5883,
trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPUserProfileModule.java)
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPUserProfileModule.java 2006-12-17
14:26:07 UTC (rev 5883)
+++
trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPUserProfileModule.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -0,0 +1,64 @@
+/******************************************************************************
+ * 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.identity.ldap;
+
+import org.jboss.portal.identity.service.UserProfileModuleService;
+import org.jboss.portal.identity.IdentityException;
+
+import javax.naming.InitialContext;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz@jboss.org">Boleslaw
Dawidowicz</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class LDAPUserProfileModule extends UserProfileModuleService
+{
+ private LDAPConnectionContext connectionContext;
+
+ protected void startService() throws Exception
+ {
+ if (getConnectionJNDIName() == null)
+ {
+ throw new IdentityException("Cannot obtain ldap connection context JNDI
name");
+ }
+ connectionContext = (LDAPConnectionContext)new
InitialContext().lookup(getConnectionJNDIName());
+
+ super.startService(); //To change body of overridden methods use File | Settings
| File Templates.
+ }
+
+ protected LDAPConnectionContext getConnectionContext() throws IdentityException
+ {
+ if (connectionContext == null)
+ {
+ //this.connectionContext =
(LDAPConnectionContext)getIdentityContext().getObject(IdentityContext.TYPE_CONNECTION_CONTEXT);
+ throw new IdentityException("No LDAPConnectionContext available");
+ }
+ return connectionContext;
+ }
+
+ public void setConnectionContext(LDAPConnectionContext connectionContext)
+ {
+ this.connectionContext = connectionContext;
+ }
+
+}
Deleted:
trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPUserProfileModuleImpl.java
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPUserProfileModuleImpl.java 2006-12-15
15:15:26 UTC (rev 5871)
+++
trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPUserProfileModuleImpl.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -1,278 +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.IdentityConfiguration;
-import org.jboss.portal.identity2.UserProfileModule;
-import org.jboss.portal.identity2.IdentityContext;
-import org.jboss.portal.identity2.info.ProfileInfo;
-import org.jboss.portal.identity2.info.PropertyInfo;
-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);
-
- PropertyInfo pi = getProfileInfo().getPropertyInfo(propertyName);
-
- if (pi == null)
- {
- throw new IdentityException("Cannot find profile information about
property: " + propertyName);
- }
-
- String mapping = pi.getMappingLDAPValue();
- if (mapping == null)
- {
- throw new IdentityException("This property is not mapped as LDAP attribute:
" + propertyName);
- }
- return mapping;
- }
-
- /**
- * 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);
-
-
- Map infos = getProfileInfo().getPropertiesInfo();
- Set keys = infos.keySet();
-
- Map mappings = new HashMap();
- for (Iterator iterator = keys.iterator(); iterator.hasNext();)
- {
- String key = (String)iterator.next();
- PropertyInfo prop = (PropertyInfo)infos.get(key);
- if (prop.isMappedLDAP())
- {
- mappings.put(prop.getName(), prop.getMappingLDAPValue());
- }
- }
- return mappings;
- }
-
-
- /**
- * obtains UserProfile object - if module is used as a Delegate it tries to obtain it
from the main one.
- * @return
- * @throws IdentityException
- */
- public ProfileInfo getProfileInfo() throws IdentityException
- {
-
-
- if (super.getProfileInfo() == null)
- {
- //obtain main UserProfileModule
- UserProfileModule module =
(UserProfileModule)getIdentityContext().getObject(IdentityContext.TYPE_USER_PROFILE_MODULE);
- if (module == this)
- {
- throw new IdentityException("ProfileInfo not accessible - check
configuration");
- }
- else
- {
- setProfileInfo(module.getProfileInfo());
- }
- }
- return super.getProfileInfo();
- }
-
-}
Copied:
trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPUserProfileModuleImpl.java
(from rev 5883,
trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPUserProfileModuleImpl.java)
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPUserProfileModuleImpl.java 2006-12-17
14:26:07 UTC (rev 5883)
+++
trunk/identity/src/main/org/jboss/portal/identity/ldap/LDAPUserProfileModuleImpl.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -0,0 +1,277 @@
+/*
+* 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.identity.ldap;
+
+import org.jboss.portal.identity.User;
+import org.jboss.portal.identity.UserProfileModule;
+import org.jboss.portal.identity.IdentityContext;
+import org.jboss.portal.identity.info.ProfileInfo;
+import org.jboss.portal.identity.info.PropertyInfo;
+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);
+
+ PropertyInfo pi = getProfileInfo().getPropertyInfo(propertyName);
+
+ if (pi == null)
+ {
+ throw new IdentityException("Cannot find profile information about
property: " + propertyName);
+ }
+
+ String mapping = pi.getMappingLDAPValue();
+ if (mapping == null)
+ {
+ throw new IdentityException("This property is not mapped as LDAP attribute:
" + propertyName);
+ }
+ return mapping;
+ }
+
+ /**
+ * 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);
+
+
+ Map infos = getProfileInfo().getPropertiesInfo();
+ Set keys = infos.keySet();
+
+ Map mappings = new HashMap();
+ for (Iterator iterator = keys.iterator(); iterator.hasNext();)
+ {
+ String key = (String)iterator.next();
+ PropertyInfo prop = (PropertyInfo)infos.get(key);
+ if (prop.isMappedLDAP())
+ {
+ mappings.put(prop.getName(), prop.getMappingLDAPValue());
+ }
+ }
+ return mappings;
+ }
+
+
+ /**
+ * obtains UserProfile object - if module is used as a Delegate it tries to obtain it
from the main one.
+ * @return
+ * @throws IdentityException
+ */
+ public ProfileInfo getProfileInfo() throws IdentityException
+ {
+
+
+ if (profileInfo == null)
+ {
+ //obtain main UserProfileModule
+ UserProfileModule module =
(UserProfileModule)getIdentityContext().getObject(IdentityContext.TYPE_USER_PROFILE_MODULE);
+ if (module == this)
+ {
+ throw new IdentityException("ProfileInfo not accessible - check
configuration");
+ }
+ else
+ {
+ setProfileInfo(module.getProfileInfo());
+ }
+ }
+ return profileInfo;
+ }
+
+}
Copied: trunk/identity/src/main/org/jboss/portal/identity/ldap/helper (from rev 5883,
trunk/identity/src/main/org/jboss/portal/identity2/ldap/helper)
Modified: trunk/identity/src/main/org/jboss/portal/identity/ldap/helper/LDAPTools.java
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/ldap/helper/LDAPTools.java 2006-12-17
14:26:07 UTC (rev 5883)
+++
trunk/identity/src/main/org/jboss/portal/identity/ldap/helper/LDAPTools.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -19,7 +19,7 @@
* 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.helper;
+package org.jboss.portal.identity.ldap.helper;
/**
* Helper class for ldap operation
Copied: trunk/identity/src/main/org/jboss/portal/identity/service (from rev 5871,
trunk/identity/src/main/org/jboss/portal/identity2/service)
Deleted:
trunk/identity/src/main/org/jboss/portal/identity/service/IdentityConfigurationService.java
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/service/IdentityConfigurationService.java 2006-12-15
15:15:26 UTC (rev 5871)
+++
trunk/identity/src/main/org/jboss/portal/identity/service/IdentityConfigurationService.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -1,274 +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.service;
-
-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.config.metadata.OptionsMetaData;
-import org.jboss.portal.identity2.config.metadata.OptionsGroupMetaData;
-import org.jboss.portal.identity2.config.metadata.OptionsGroupOptionMetaData;
-import org.jboss.portal.common.util.JNDI;
-import org.jboss.portal.identity.IdentityException;
-
-import java.util.Map;
-import java.util.Set;
-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 IdentityConfigurationService extends IdentityModuleService implements
IdentityConfiguration
-{
-
- //TODO: improve access to data to not blow up by NullPointerEx
-
- private static final org.jboss.logging.Logger log =
org.jboss.logging.Logger.getLogger(IdentityConfigurationService.class);
-
- private Map data;
-
- public IdentityConfigurationService()
- {
- super(IdentityContext.TYPE_IDENTITY_CONFIGURATION);
- }
-
- public IdentityConfigurationService(Map optionGroups)
- {
- this();
- this.data = optionGroups;
- }
-
- public IdentityConfigurationService(OptionsMetaData meta) throws IdentityException
- {
- this();
- if (meta == null || meta.getGroups() == null)
- {
- data = new HashMap();
- return;
- }
- try
- {
- Map newGroups = new HashMap();
- Map groups = meta.getGroups();
- for (Iterator iterator = groups.keySet().iterator(); iterator.hasNext();)
- {
- String groupKey = (String)iterator.next();
- OptionsGroupMetaData group = (OptionsGroupMetaData)groups.get(groupKey);
-
- Map newOptions = new HashMap();
- Map options = group.getOptions();
- for (Iterator iterator1 = options.keySet().iterator(); iterator1.hasNext();)
- {
- String optionKey = (String)iterator1.next();
- OptionsGroupOptionMetaData option =
(OptionsGroupOptionMetaData)options.get(optionKey);
-
- newOptions.put(option.getName(),option.getValues());
- }
-
- newGroups.put(group.getName(), newOptions);
- }
- setData(newGroups);
- }
- catch (Exception e)
- {
- throw new IdentityException("Cannot create identity configuration options
data:", e);
- }
- }
-
- public Set getValues(String optionGroup, String option)
- {
- if (optionGroup == null)
- {
- throw new IllegalArgumentException("null option group");
- }
- if (option == null)
- {
- throw new IllegalArgumentException("null option name");
- }
- if (data.containsKey(optionGroup))
- {
- Map group = (Map)data.get(optionGroup);
- if (group.containsKey(option))
- {
- return (Set)group.get(option);
- }
- }
- return null;
- }
-
- public String getValue(String optionGroup, String option)
- {
- if (optionGroup == null)
- {
- throw new IllegalArgumentException("null option group");
- }
- if (option == null)
- {
- throw new IllegalArgumentException("null option name");
- }
- if (data.containsKey(optionGroup))
- {
- Map group = (Map)data.get(optionGroup);
- if (group.containsKey(option))
- {
- Set values = (Set)group.get(option);
- if (values.size() > 0)
- {
- return (String)values.toArray()[0];
- }
- }
- }
- return null;
- }
-
- public String getValue(String option)
- {
- if (option == null)
- {
- throw new IllegalArgumentException("null option name");
- }
- if (data.containsKey(GROUP_COMMON))
- {
- Map group = (Map)data.get(GROUP_COMMON);
- if (group.containsKey(option))
- {
- Set values = (Set)group.get(option);
- if (values.size() > 0)
- {
- return (String)values.toArray()[0];
- }
- }
- }
- return null;
- }
-
- public void setValues(String optionGroup, String option, Set values)
- {
- if (optionGroup == null)
- {
- throw new IllegalArgumentException("null option group");
- }
- if (option == null)
- {
- throw new IllegalArgumentException("null option name");
- }
- if (values == null)
- {
- throw new IllegalArgumentException("null values list");
- }
- if (data.containsKey(optionGroup))
- {
- ((Map)data.get(optionGroup)).put(option, values);
- }
- }
-
- public void addValue(String optionGroup, String option, String value)
- {
- if (optionGroup == null)
- {
- throw new IllegalArgumentException("null option group");
- }
- if (option == null)
- {
- throw new IllegalArgumentException("null option name");
- }
- if (value == null)
- {
- throw new IllegalArgumentException("null value name");
- }
- if (data.containsKey(optionGroup))
- {
- Map group = (Map)data.get(optionGroup);
- if (group.containsKey(option))
- {
- ((Set)group.get(option)).add(value);
- }
- }
- }
-
- public Map getOptions(String optionGroup)
- {
- if (optionGroup == null)
- {
- throw new IllegalArgumentException("null option group");
- }
- if (data.containsKey(optionGroup))
- {
- return (Map)data.get(optionGroup);
- }
- return null;
- }
-
- public void setOptions(String optionGroup, Map options)
- {
- if (optionGroup == null)
- {
- throw new IllegalArgumentException("null option group");
- }
- if (options == null)
- {
- throw new IllegalArgumentException("null options map");
- }
- data.put(optionGroup,options);
- }
-
- public void remoeOption(String optionGroup, String option)
- {
- if (optionGroup == null)
- {
- throw new IllegalArgumentException("null option group");
- }
- if (option == null)
- {
- throw new IllegalArgumentException("null option name");
- }
- if (data.containsKey(optionGroup))
- {
- ((Map)data.get(optionGroup)).put(option, null);
- }
- }
-
-
- public void setData(Map data)
- {
- this.data = data;
- }
-
- public Map getOptionGroups()
- {
- return data;
- }
-
-// public String getConfigFile()
-// {
-// return configFile;
-// }
-//
-// public void setConfigFile(String configFile)
-// {
-// this.configFile = configFile;
-// }
-
-
-}
Copied:
trunk/identity/src/main/org/jboss/portal/identity/service/IdentityConfigurationService.java
(from rev 5883,
trunk/identity/src/main/org/jboss/portal/identity2/service/IdentityConfigurationService.java)
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/service/IdentityConfigurationService.java 2006-12-17
14:26:07 UTC (rev 5883)
+++
trunk/identity/src/main/org/jboss/portal/identity/service/IdentityConfigurationService.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -0,0 +1,272 @@
+/*
+* 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.identity.service;
+
+import org.jboss.portal.identity.IdentityConfiguration;
+import org.jboss.portal.identity.IdentityContext;
+import org.jboss.portal.identity.config.metadata.OptionsMetaData;
+import org.jboss.portal.identity.config.metadata.OptionsGroupMetaData;
+import org.jboss.portal.identity.config.metadata.OptionsGroupOptionMetaData;
+import org.jboss.portal.identity.IdentityException;
+
+import java.util.Map;
+import java.util.Set;
+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 IdentityConfigurationService extends IdentityModuleService implements
IdentityConfiguration
+{
+
+ //TODO: improve access to data to not blow up by NullPointerEx
+
+ private static final org.jboss.logging.Logger log =
org.jboss.logging.Logger.getLogger(IdentityConfigurationService.class);
+
+ private Map data;
+
+ public IdentityConfigurationService()
+ {
+ super(IdentityContext.TYPE_IDENTITY_CONFIGURATION);
+ }
+
+ public IdentityConfigurationService(Map optionGroups)
+ {
+ this();
+ this.data = optionGroups;
+ }
+
+ public IdentityConfigurationService(OptionsMetaData meta) throws IdentityException
+ {
+ this();
+ if (meta == null || meta.getGroups() == null)
+ {
+ data = new HashMap();
+ return;
+ }
+ try
+ {
+ Map newGroups = new HashMap();
+ Map groups = meta.getGroups();
+ for (Iterator iterator = groups.keySet().iterator(); iterator.hasNext();)
+ {
+ String groupKey = (String)iterator.next();
+ OptionsGroupMetaData group = (OptionsGroupMetaData)groups.get(groupKey);
+
+ Map newOptions = new HashMap();
+ Map options = group.getOptions();
+ for (Iterator iterator1 = options.keySet().iterator(); iterator1.hasNext();)
+ {
+ String optionKey = (String)iterator1.next();
+ OptionsGroupOptionMetaData option =
(OptionsGroupOptionMetaData)options.get(optionKey);
+
+ newOptions.put(option.getName(),option.getValues());
+ }
+
+ newGroups.put(group.getName(), newOptions);
+ }
+ setData(newGroups);
+ }
+ catch (Exception e)
+ {
+ throw new IdentityException("Cannot create identity configuration options
data:", e);
+ }
+ }
+
+ public Set getValues(String optionGroup, String option)
+ {
+ if (optionGroup == null)
+ {
+ throw new IllegalArgumentException("null option group");
+ }
+ if (option == null)
+ {
+ throw new IllegalArgumentException("null option name");
+ }
+ if (data.containsKey(optionGroup))
+ {
+ Map group = (Map)data.get(optionGroup);
+ if (group.containsKey(option))
+ {
+ return (Set)group.get(option);
+ }
+ }
+ return null;
+ }
+
+ public String getValue(String optionGroup, String option)
+ {
+ if (optionGroup == null)
+ {
+ throw new IllegalArgumentException("null option group");
+ }
+ if (option == null)
+ {
+ throw new IllegalArgumentException("null option name");
+ }
+ if (data.containsKey(optionGroup))
+ {
+ Map group = (Map)data.get(optionGroup);
+ if (group.containsKey(option))
+ {
+ Set values = (Set)group.get(option);
+ if (values.size() > 0)
+ {
+ return (String)values.toArray()[0];
+ }
+ }
+ }
+ return null;
+ }
+
+ public String getValue(String option)
+ {
+ if (option == null)
+ {
+ throw new IllegalArgumentException("null option name");
+ }
+ if (data.containsKey(GROUP_COMMON))
+ {
+ Map group = (Map)data.get(GROUP_COMMON);
+ if (group.containsKey(option))
+ {
+ Set values = (Set)group.get(option);
+ if (values.size() > 0)
+ {
+ return (String)values.toArray()[0];
+ }
+ }
+ }
+ return null;
+ }
+
+ public void setValues(String optionGroup, String option, Set values)
+ {
+ if (optionGroup == null)
+ {
+ throw new IllegalArgumentException("null option group");
+ }
+ if (option == null)
+ {
+ throw new IllegalArgumentException("null option name");
+ }
+ if (values == null)
+ {
+ throw new IllegalArgumentException("null values list");
+ }
+ if (data.containsKey(optionGroup))
+ {
+ ((Map)data.get(optionGroup)).put(option, values);
+ }
+ }
+
+ public void addValue(String optionGroup, String option, String value)
+ {
+ if (optionGroup == null)
+ {
+ throw new IllegalArgumentException("null option group");
+ }
+ if (option == null)
+ {
+ throw new IllegalArgumentException("null option name");
+ }
+ if (value == null)
+ {
+ throw new IllegalArgumentException("null value name");
+ }
+ if (data.containsKey(optionGroup))
+ {
+ Map group = (Map)data.get(optionGroup);
+ if (group.containsKey(option))
+ {
+ ((Set)group.get(option)).add(value);
+ }
+ }
+ }
+
+ public Map getOptions(String optionGroup)
+ {
+ if (optionGroup == null)
+ {
+ throw new IllegalArgumentException("null option group");
+ }
+ if (data.containsKey(optionGroup))
+ {
+ return (Map)data.get(optionGroup);
+ }
+ return null;
+ }
+
+ public void setOptions(String optionGroup, Map options)
+ {
+ if (optionGroup == null)
+ {
+ throw new IllegalArgumentException("null option group");
+ }
+ if (options == null)
+ {
+ throw new IllegalArgumentException("null options map");
+ }
+ data.put(optionGroup,options);
+ }
+
+ public void remoeOption(String optionGroup, String option)
+ {
+ if (optionGroup == null)
+ {
+ throw new IllegalArgumentException("null option group");
+ }
+ if (option == null)
+ {
+ throw new IllegalArgumentException("null option name");
+ }
+ if (data.containsKey(optionGroup))
+ {
+ ((Map)data.get(optionGroup)).put(option, null);
+ }
+ }
+
+
+ public void setData(Map data)
+ {
+ this.data = data;
+ }
+
+ public Map getOptionGroups()
+ {
+ return data;
+ }
+
+// public String getConfigFile()
+// {
+// return configFile;
+// }
+//
+// public void setConfigFile(String configFile)
+// {
+// this.configFile = configFile;
+// }
+
+
+}
Deleted:
trunk/identity/src/main/org/jboss/portal/identity/service/IdentityModuleService.java
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/service/IdentityModuleService.java 2006-12-15
15:15:26 UTC (rev 5871)
+++
trunk/identity/src/main/org/jboss/portal/identity/service/IdentityModuleService.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -1,181 +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.service;
-
-import org.jboss.portal.identity2.IdentityContext;
-import org.jboss.portal.identity2.IdentityConfiguration;
-import org.jboss.portal.common.util.JNDI;
-import org.jboss.portal.identity.IdentityException;
-import org.jboss.portal.jems.as.system.AbstractJBossService;
-
-import java.util.Map;
-
-/**
- * @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw
Dawidowicz</a>
- * @version $Revision: 1.1 $
- */
-public class IdentityModuleService extends AbstractJBossService
-{
- private static final org.jboss.logging.Logger log =
org.jboss.logging.Logger.getLogger(IdentityModuleService.class);
-
- private String jndiName;
-
- private String connectionJNDIName;
-
- private IdentityContext identityContext;
-
- private IdentityConfiguration identityConfiguration;
-
- private JNDI.Binding jndiBinding;
-
- private Map initOptions;
-
- protected String moduleType;
-
- //restrict instance creation
- private IdentityModuleService()
- {
-
- }
-
- protected IdentityModuleService(String type)
- {
- moduleType = type;
- }
-
- protected void startService() throws Exception
- {
-
- //
- if (jndiName != null)
- {
- log.debug("Binding identity module to JNDI with name: " + jndiName);
- 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.TYPE_ROLE_MODULE);
- identityContext.register(this, this.moduleType);
- }
- }
-
-
- 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.TYPE_ROLE_MODULE);
- identityContext.unregister(this.moduleType);
- }
-
- }
-
- protected IdentityConfiguration getIdentityConfiguration() //throws IdentityException
- {
- /*if (identityConfiguration == null)
- {
- this.identityConfiguration =
(IdentityConfiguration)identityContext.getObject(IdentityContext.TYPE_IDENTITY_CONFIGURATION);
- }
- return identityConfiguration;*/
- try
- {
- if (identityConfiguration == null)
- {
- this.identityConfiguration =
(IdentityConfiguration)identityContext.getObject(IdentityContext.TYPE_IDENTITY_CONFIGURATION);
- }
- return identityConfiguration;
- }
- catch (IdentityException e)
- {
- throw new RuntimeException("Can't obtain IdentityConfiguration",
e);
- }
- }
-
- 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;
- }
-
- public Map getInitOptions()
- {
- return initOptions;
- }
-
-
- public void setInitOptions(Map initOptions)
- {
- this.initOptions = initOptions;
- }
-
-
- public String getModuleType()
- {
- return moduleType;
- }
-
-
- public void setModuleType(String moduleType)
- {
- this.moduleType = moduleType;
- }
-
- public String getConnectionJNDIName()
- {
- return connectionJNDIName;
- }
-
- public void setConnectionJNDIName(String connectionJNDIName)
- {
- this.connectionJNDIName = connectionJNDIName;
- }
-}
Copied:
trunk/identity/src/main/org/jboss/portal/identity/service/IdentityModuleService.java (from
rev 5883,
trunk/identity/src/main/org/jboss/portal/identity2/service/IdentityModuleService.java)
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/service/IdentityModuleService.java 2006-12-17
14:26:07 UTC (rev 5883)
+++
trunk/identity/src/main/org/jboss/portal/identity/service/IdentityModuleService.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -0,0 +1,181 @@
+/*
+* 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.identity.service;
+
+import org.jboss.portal.identity.IdentityContext;
+import org.jboss.portal.identity.IdentityConfiguration;
+import org.jboss.portal.common.util.JNDI;
+import org.jboss.portal.identity.IdentityException;
+import org.jboss.portal.jems.as.system.AbstractJBossService;
+
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw
Dawidowicz</a>
+ * @version $Revision: 1.1 $
+ */
+public class IdentityModuleService extends AbstractJBossService
+{
+ private static final org.jboss.logging.Logger log =
org.jboss.logging.Logger.getLogger(IdentityModuleService.class);
+
+ private String jndiName;
+
+ private String connectionJNDIName;
+
+ private IdentityContext identityContext;
+
+ private IdentityConfiguration identityConfiguration;
+
+ private JNDI.Binding jndiBinding;
+
+ private Map initOptions;
+
+ protected String moduleType;
+
+ //restrict instance creation
+ private IdentityModuleService()
+ {
+
+ }
+
+ protected IdentityModuleService(String type)
+ {
+ moduleType = type;
+ }
+
+ protected void startService() throws Exception
+ {
+
+ //
+ if (jndiName != null)
+ {
+ log.debug("Binding identity module to JNDI with name: " + jndiName);
+ 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.TYPE_ROLE_MODULE);
+ identityContext.register(this, this.moduleType);
+ }
+ }
+
+
+ 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.TYPE_ROLE_MODULE);
+ identityContext.unregister(this.moduleType);
+ }
+
+ }
+
+ protected IdentityConfiguration getIdentityConfiguration() //throws IdentityException
+ {
+ /*if (identityConfiguration == null)
+ {
+ this.identityConfiguration =
(IdentityConfiguration)identityContext.getObject(IdentityContext.TYPE_IDENTITY_CONFIGURATION);
+ }
+ return identityConfiguration;*/
+ try
+ {
+ if (identityConfiguration == null)
+ {
+ this.identityConfiguration =
(IdentityConfiguration)identityContext.getObject(IdentityContext.TYPE_IDENTITY_CONFIGURATION);
+ }
+ return identityConfiguration;
+ }
+ catch (IdentityException e)
+ {
+ throw new RuntimeException("Can't obtain IdentityConfiguration",
e);
+ }
+ }
+
+ 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;
+ }
+
+ public Map getInitOptions()
+ {
+ return initOptions;
+ }
+
+
+ public void setInitOptions(Map initOptions)
+ {
+ this.initOptions = initOptions;
+ }
+
+
+ public String getModuleType()
+ {
+ return moduleType;
+ }
+
+
+ public void setModuleType(String moduleType)
+ {
+ this.moduleType = moduleType;
+ }
+
+ public String getConnectionJNDIName()
+ {
+ return connectionJNDIName;
+ }
+
+ public void setConnectionJNDIName(String connectionJNDIName)
+ {
+ this.connectionJNDIName = connectionJNDIName;
+ }
+}
Deleted:
trunk/identity/src/main/org/jboss/portal/identity/service/MembershipModuleService.java
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/service/MembershipModuleService.java 2006-12-15
15:15:26 UTC (rev 5871)
+++
trunk/identity/src/main/org/jboss/portal/identity/service/MembershipModuleService.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -1,58 +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.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;
-import org.jboss.portal.identity2.info.ProfileInfo;
-
-import java.util.Map;
-
-/**
- * @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw
Dawidowicz</a>
- * @version $Revision: 1.1 $
- */
-public abstract class MembershipModuleService extends IdentityModuleService implements
MembershipModule
-{
- private static final org.jboss.logging.Logger log =
org.jboss.logging.Logger.getLogger(MembershipModuleService.class);
-
- private ProfileInfo profileInfo;
-
- protected MembershipModuleService()
- {
- super(IdentityContext.TYPE_MEMBERSHIP_MODULE);
- }
-
- public ProfileInfo getProfileInfo()
- {
- return profileInfo;
- }
-
- public void setProfileInfo(ProfileInfo profileInfo)
- {
- this.profileInfo = profileInfo;
- }
-}
Copied:
trunk/identity/src/main/org/jboss/portal/identity/service/MembershipModuleService.java
(from rev 5883,
trunk/identity/src/main/org/jboss/portal/identity2/service/MembershipModuleService.java)
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/service/MembershipModuleService.java 2006-12-17
14:26:07 UTC (rev 5883)
+++
trunk/identity/src/main/org/jboss/portal/identity/service/MembershipModuleService.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -0,0 +1,51 @@
+/*
+* 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.identity.service;
+
+import org.jboss.portal.identity.MembershipModule;
+import org.jboss.portal.identity.IdentityContext;
+import org.jboss.portal.identity.info.ProfileInfo;
+
+/**
+ * @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw
Dawidowicz</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class MembershipModuleService extends IdentityModuleService implements
MembershipModule {
+ private static final org.jboss.logging.Logger log =
org.jboss.logging.Logger.getLogger(MembershipModuleService.class);
+
+ private ProfileInfo profileInfo;
+
+ protected MembershipModuleService()
+ {
+ super(IdentityContext.TYPE_MEMBERSHIP_MODULE);
+ }
+
+ public ProfileInfo getProfileInfo()
+ {
+ return profileInfo;
+ }
+
+ public void setProfileInfo(ProfileInfo profileInfo)
+ {
+ this.profileInfo = profileInfo;
+ }
+}
Deleted: trunk/identity/src/main/org/jboss/portal/identity/service/RoleModuleService.java
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/service/RoleModuleService.java 2006-12-15
15:15:26 UTC (rev 5871)
+++
trunk/identity/src/main/org/jboss/portal/identity/service/RoleModuleService.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -1,45 +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.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;
-
-import java.util.Map;
-
-/**
- * @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw
Dawidowicz</a>
- * @version $Revision: 1.1 $
- */
-public abstract class RoleModuleService extends IdentityModuleService implements
RoleModule
-{
- private static final org.jboss.logging.Logger log =
org.jboss.logging.Logger.getLogger(RoleModuleService.class);
-
- protected RoleModuleService()
- {
- super(IdentityContext.TYPE_ROLE_MODULE);
- }
-}
Copied: trunk/identity/src/main/org/jboss/portal/identity/service/RoleModuleService.java
(from rev 5883,
trunk/identity/src/main/org/jboss/portal/identity2/service/RoleModuleService.java)
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/service/RoleModuleService.java 2006-12-17
14:26:07 UTC (rev 5883)
+++
trunk/identity/src/main/org/jboss/portal/identity/service/RoleModuleService.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -0,0 +1,39 @@
+/*
+* 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.identity.service;
+
+import org.jboss.portal.identity.RoleModule;
+import org.jboss.portal.identity.IdentityContext;
+
+/**
+ * @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw
Dawidowicz</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class RoleModuleService extends IdentityModuleService implements
RoleModule
+{
+ private static final org.jboss.logging.Logger log =
org.jboss.logging.Logger.getLogger(RoleModuleService.class);
+
+ protected RoleModuleService()
+ {
+ super(IdentityContext.TYPE_ROLE_MODULE);
+ }
+}
Deleted: trunk/identity/src/main/org/jboss/portal/identity/service/UserModuleService.java
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/service/UserModuleService.java 2006-12-15
15:15:26 UTC (rev 5871)
+++
trunk/identity/src/main/org/jboss/portal/identity/service/UserModuleService.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -1,45 +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.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;
-
-import java.util.Map;
-
-/**
- * @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw
Dawidowicz</a>
- * @version $Revision: 1.1 $
- */
-public abstract class UserModuleService extends IdentityModuleService implements
UserModule
-{
- private static final org.jboss.logging.Logger log =
org.jboss.logging.Logger.getLogger(UserModuleService.class);
-
- protected UserModuleService()
- {
- super(IdentityContext.TYPE_USER_MODULE);
- }
-}
Copied: trunk/identity/src/main/org/jboss/portal/identity/service/UserModuleService.java
(from rev 5883,
trunk/identity/src/main/org/jboss/portal/identity2/service/UserModuleService.java)
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/service/UserModuleService.java 2006-12-17
14:26:07 UTC (rev 5883)
+++
trunk/identity/src/main/org/jboss/portal/identity/service/UserModuleService.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -0,0 +1,39 @@
+/*
+* 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.identity.service;
+
+import org.jboss.portal.identity.UserModule;
+import org.jboss.portal.identity.IdentityContext;
+
+/**
+ * @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw
Dawidowicz</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class UserModuleService extends IdentityModuleService implements
UserModule
+{
+ private static final org.jboss.logging.Logger log =
org.jboss.logging.Logger.getLogger(UserModuleService.class);
+
+ protected UserModuleService()
+ {
+ super(IdentityContext.TYPE_USER_MODULE);
+ }
+}
Deleted:
trunk/identity/src/main/org/jboss/portal/identity/service/UserProfileModuleService.java
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/service/UserProfileModuleService.java 2006-12-15
15:15:26 UTC (rev 5871)
+++
trunk/identity/src/main/org/jboss/portal/identity/service/UserProfileModuleService.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -1,89 +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.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;
-import org.jboss.portal.identity2.config.info.ProfileInfoSupport;
-import org.jboss.portal.identity2.config.metadata.ConfigurationParser;
-import org.jboss.portal.identity2.info.ProfileInfo;
-
-import java.util.Map;
-
-/**
- * @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw
Dawidowicz</a>
- * @version $Revision: 1.1 $
- */
-public abstract class UserProfileModuleService extends IdentityModuleService implements
UserProfileModule
-{
- private static final org.jboss.logging.Logger log =
org.jboss.logging.Logger.getLogger(UserProfileModuleService.class);
-
- private ProfileInfo profileInfo;
-
- private String profileConfigFile;
-
- protected UserProfileModuleService()
- {
- super(IdentityContext.TYPE_USER_PROFILE_MODULE);
- }
-
-
- protected void startService() throws Exception
- {
- if (getProfileConfigFile() != null)
- {
- if (log.isDebugEnabled())
- {
- log.debug("Processing profile configuration for the module....");
- }
- profileInfo = new
ProfileInfoSupport(ConfigurationParser.parseProfileConfiguration(getProfileConfigFile()));
- }
-
- super.startService();
-
- }
-
- public ProfileInfo getProfileInfo() throws IdentityException
- {
- return profileInfo;
- }
-
- public void setProfileInfo(ProfileInfo profileInfo)
- {
- this.profileInfo = profileInfo;
- }
-
- public String getProfileConfigFile()
- {
- return profileConfigFile;
- }
-
- public void setProfileConfigFile(String profileConfigFile)
- {
- this.profileConfigFile = profileConfigFile;
- }
-}
-
Copied:
trunk/identity/src/main/org/jboss/portal/identity/service/UserProfileModuleService.java
(from rev 5883,
trunk/identity/src/main/org/jboss/portal/identity2/service/UserProfileModuleService.java)
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/service/UserProfileModuleService.java 2006-12-17
14:26:07 UTC (rev 5883)
+++
trunk/identity/src/main/org/jboss/portal/identity/service/UserProfileModuleService.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -0,0 +1,84 @@
+/*
+* 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.identity.service;
+
+import org.jboss.portal.identity.IdentityException;
+import org.jboss.portal.identity.IdentityContext;
+import org.jboss.portal.identity.UserProfileModule;
+import org.jboss.portal.identity.config.info.ProfileInfoSupport;
+import org.jboss.portal.identity.config.metadata.ConfigurationParser;
+import org.jboss.portal.identity.info.ProfileInfo;
+
+/**
+ * @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw
Dawidowicz</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class UserProfileModuleService extends IdentityModuleService implements
UserProfileModule
+{
+ private static final org.jboss.logging.Logger log =
org.jboss.logging.Logger.getLogger(UserProfileModuleService.class);
+
+ protected ProfileInfo profileInfo;
+
+ private String profileConfigFile;
+
+ protected UserProfileModuleService()
+ {
+ super(IdentityContext.TYPE_USER_PROFILE_MODULE);
+ }
+
+
+ protected void startService() throws Exception
+ {
+ if (getProfileConfigFile() != null)
+ {
+ if (log.isDebugEnabled())
+ {
+ log.debug("Processing profile configuration for the module....");
+ }
+ profileInfo = new
ProfileInfoSupport(ConfigurationParser.parseProfileConfiguration(getProfileConfigFile()));
+ }
+
+ super.startService();
+
+ }
+
+// public ProfileInfo getProfileInfo() throws IdentityException
+// {
+// return profileInfo;
+// }
+
+ public void setProfileInfo(ProfileInfo profileInfo)
+ {
+ this.profileInfo = profileInfo;
+ }
+
+ public String getProfileConfigFile()
+ {
+ return profileConfigFile;
+ }
+
+ public void setProfileConfigFile(String profileConfigFile)
+ {
+ this.profileConfigFile = profileConfigFile;
+ }
+}
+
Deleted:
trunk/identity/src/main/org/jboss/portal/identity2/DelegatingUserProfileModuleImpl.java
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/DelegatingUserProfileModuleImpl.java 2006-12-17
14:45:10 UTC (rev 5884)
+++
trunk/identity/src/main/org/jboss/portal/identity2/DelegatingUserProfileModuleImpl.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -1,202 +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;
-
-import org.jboss.portal.identity2.service.UserProfileModuleService;
-import org.jboss.portal.identity2.info.PropertyInfo;
-import org.jboss.portal.identity2.ldap.LDAPUserImpl;
-import org.jboss.portal.identity2.db.HibernateUserImpl;
-import org.jboss.portal.identity.IdentityException;
-
-
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-import java.util.Map;
-
-/**
- * @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw
Dawidowicz</a>
- * @version $Revision: 1.1 $
- */
-public class DelegatingUserProfileModuleImpl extends UserProfileModuleService
-{
- private static final org.jboss.logging.Logger log =
org.jboss.logging.Logger.getLogger(DelegatingUserProfileModuleImpl.class);
-
- private String ldapModuleJNDIName;
-
- private String dbModuleJNDIName;
-
- private UserProfileModule LDAPModule;
-
- private UserProfileModule dbModule;
-
- protected void startService() throws Exception
- {
- super.startService();
-
- if(getProfileInfo() == null)
- {
- throw new IdentityException("No profile information found. Check the
configuration.");
- }
-
- }
-
- public Object getProperty(User user, String propertyName) throws IdentityException,
IllegalArgumentException
- {
- if (log.isDebugEnabled()) log.debug("getProperty: " + propertyName);
- try
- {
- PropertyInfo property = getProfileInfo().getPropertyInfo(propertyName);
- if (property == null)
- {
- throw new IdentityException("Such property name is not
supported");
- }
- else if (property.isMappedLDAP() && isLDAPSupported() && user
instanceof LDAPUserImpl)
- {
- log.debug("Delegating to LDAP module");
- return getLDAPModule().getProperty(user, propertyName);
- }
- else if (property.isMappedDB())
- {
- log.debug("Delegating to DB module");
- return getDBModule().getProperty(user, propertyName);
- }
- throw new IdentityException("Cannot process property - incorrect profile or
module configuration");
- }
- catch (Exception e)
- {
- throw new IdentityException("Cannot resolve property: ", e);
- }
- }
-
- public void setProperty(User user, String name, Object propertyValue) throws
IdentityException, IllegalArgumentException
- {
- if (log.isDebugEnabled()) log.debug("setProperty: " + name +
"/" + propertyValue);
- try
- {
- PropertyInfo property = getProfileInfo().getPropertyInfo(name);
- if (property == null)
- {
- throw new IdentityException("Such property name is not
supported");
- }
- else if (property.isMappedLDAP() && isLDAPSupported() && user
instanceof LDAPUserImpl)
- {
- log.debug("Delegating to LDAP module");
- getLDAPModule().setProperty(user, name, propertyValue);
- return;
- }
- else if (property.isMappedDB())
- {
- log.debug("Delegating to DB module");
- getDBModule().setProperty(user, name, propertyValue);
- return;
- }
- throw new IdentityException("Cannot process property - incorrect profile or
module configuration");
- }
- catch (Exception e)
- {
- throw new IdentityException("Cannot resolve property: ", e);
- }
- }
-
- public Map getProperties(User user) throws IdentityException,
IllegalArgumentException
- {
- if (log.isDebugEnabled()) log.debug("getProperties");//: " + name +
"/" + propertyValue)
- try
- {
- if (user instanceof LDAPUserImpl && isLDAPSupported())
- {
- log.debug("Delegating to LDAP module");
- return getLDAPModule().getProperties(user);
- }
- else if (user instanceof HibernateUserImpl && isDBSupported())
- {
- log.debug("Delegating to DB module");
- return getDBModule().getProperties(user);
- }
- throw new IdentityException("Cannot process properties - incorrect profile
or module configuration");
- }
- catch (Exception e)
- {
- throw new IdentityException("Cannot resolve property: ", e);
- }
- }
-
-
- public String getLdapModuleJNDIName()
- {
- return ldapModuleJNDIName;
- }
-
- public void setLdapModuleJNDIName(String ldapModuleJNDIName)
- {
- this.ldapModuleJNDIName = ldapModuleJNDIName;
- }
-
- public String getDbModuleJNDIName()
- {
- return dbModuleJNDIName;
- }
-
- public void setDbModuleJNDIName(String dbModuleJNDIName)
- {
- this.dbModuleJNDIName = dbModuleJNDIName;
- }
-
- public boolean isLDAPSupported()
- {
- return getLdapModuleJNDIName()!=null;
- }
-
- public boolean isDBSupported()
- {
- return getDbModuleJNDIName()!=null;
- }
-
- protected UserProfileModule getDBModule() throws Exception
- {
-
- //TODO: to tired to clean this at the moment
- if (dbModule == null)
- {
- dbModule = (UserProfileModule)new
InitialContext().lookup(getDbModuleJNDIName());
- if (dbModule == null)
- {
- throw new IdentityException("Couldn't obtain DB
UserProfileModule");
- }
- }
- return dbModule;
- }
-
- protected UserProfileModule getLDAPModule() throws Exception
- {
- if (LDAPModule == null)
- {
- LDAPModule = (UserProfileModule)new
InitialContext().lookup(getLdapModuleJNDIName());
- if (LDAPModule == null)
- {
- throw new IdentityException("Couldn't obtain LDAP
UserProfileModule");
- }
- }
- return LDAPModule;
- }
-
-}
Deleted: trunk/identity/src/main/org/jboss/portal/identity2/IdentityConfiguration.java
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/IdentityConfiguration.java 2006-12-17
14:45:10 UTC (rev 5884)
+++
trunk/identity/src/main/org/jboss/portal/identity2/IdentityConfiguration.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -1,105 +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;
-
-import java.util.Map;
-import java.util.Set;
-
-/**
- * @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw
Dawidowicz</a>
- * @version $Revision: 1.1 $
- */
-public interface IdentityConfiguration
-{
-
- //TODO: isMembershipAttributeRequired
- //TODO: memebershipAttributeEmptyValue
- //TODO: options for secured connection to ldap
- //TODO: let decide if has should be in hex or base64
-
- public static final String GROUP_COMMON = "common";
-
- public static final String GROUP_CONNECTION = "connection";
-
- public static final String GROUP_USER_CREATE_ATTRIBUTES =
"userCreateAttibutes";
-
- 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";
-
- public static final String CONNECTION_HOST = "host";
-
- public static final String CONNECTION_PORT = "port";
-
- public static final String CONNECTION_ADMIN_DN = "admin-dn";
-
- public static final String CONNECTION_ADMIN_PASSWORD = "admin-password";
-
- public static final String CONNECTION_AUTHENTICATION = "authentication";
-
- public static final String USER_CONTAINER_DN = "userContainerDN";
-
- public static final String USER_UID_ATTRIBUTE_ID = "uidAttributeID";
-
- public static final String USER_PASSWORD_ATTRIBUTE_ID =
"passwordAttributeID";
-
- public static final String USER_EMAIL_ATTRIBUTE_ID = "emailAttributeID";
-
- public static final String ROLE_CONTAINER_DN = "roleContainerDN";
-
- public static final String ROLE_RID_ATTRIBUTE_ID = "ridAttributeID";
-
- public static final String ROLE_DISPLAY_NAME_ATTRIBUTE_ID =
"roleDisplayNameAttributeID";
-
- public static final String MEMBERSHIP_ATTRIBUTE_ID =
"membershipAttributeID";
-
- public static final String MEMBERSHIP_ATTRIBUTE_IS_DN =
"membershipAttributeIsDN";
-
- public static final String HASH_ALGORITHM = "hashAlgorithm";
-
- public static final String HASH_ENCODING = "hashEncoding";
-
-
- public Set getValues(String optionGroup, String option);
-
- public String getValue(String optionGroup, String option);
-
- public String getValue(String option);
-
- public void setValues(String optionGroup, String option, Set values);
-
- public void addValue(String optionGroup, String option, String value);
-
- public Map getOptions(String optionGroup);
-
- public void setOptions(String optionGroup, Map options);
-
- public void remoeOption(String optionGroup, String option);
-
- public Map getOptionGroups();
-
-
-}
Deleted: trunk/identity/src/main/org/jboss/portal/identity2/IdentityContext.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/IdentityContext.java 2006-12-17
14:45:10 UTC (rev 5884)
+++ trunk/identity/src/main/org/jboss/portal/identity2/IdentityContext.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -1,52 +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;
-
-import org.jboss.portal.identity.IdentityException;
-
-/**
- * @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw
Dawidowicz</a>
- * @version $Revision: 1.1 $
- */
-public interface IdentityContext
-{
-
- //TODO: move to safe type enum
- public static final String TYPE_USER_MODULE = "User";
-
- public static final String TYPE_ROLE_MODULE = "Role";
-
- public static final String TYPE_MEMBERSHIP_MODULE = "Membership";
-
- public static final String TYPE_USER_PROFILE_MODULE = "UserProfile";
-
- public static final String TYPE_CONNECTION_CONTEXT = "ConnectionContext";
-
- public static final String TYPE_IDENTITY_CONFIGURATION =
"IdentityConfiguration";
-
-
- public void register(Object object, String name) throws IdentityException;
-
- public void unregister(String name);
-
- public Object getObject(String name) throws IdentityException;
-}
Deleted: trunk/identity/src/main/org/jboss/portal/identity2/IdentityContextImpl.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/IdentityContextImpl.java 2006-12-17
14:45:10 UTC (rev 5884)
+++ trunk/identity/src/main/org/jboss/portal/identity2/IdentityContextImpl.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -1,106 +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;
-
-import org.jboss.portal.jems.as.system.AbstractJBossService;
-import org.jboss.portal.identity.IdentityException;
-
-import java.util.Map;
-import java.util.HashMap;
-
-/**
- * Keeps references to all identity related modules to enable them interactions
- *
- * @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw
Dawidowicz</a>
- * @version $Revision: 1.1 $
- */
-public class IdentityContextImpl extends AbstractJBossService implements IdentityContext
-{
- //private static final org.jboss.logging.Logger log =
org.jboss.logging.Logger.getLogger(IdentityContextImpl.class);
-
- private Map registry;
-
- public IdentityContextImpl()
- {
- registry = new HashMap();
- }
-
- public void register(Object object, String name) throws IdentityException
- {
- if (object == null)
- {
- throw new IllegalArgumentException("Cannot register null reference");
- }
- if (name == null)
- {
- throw new IllegalArgumentException("Cannot register object with null
name");
- }
-
- synchronized(this)
- {
- if (registry.containsKey(name))
- {
- throw new IdentityException("Name: " + name + " already
registered.");
- }
- if (log.isDebugEnabled()) log.debug("registering object: " + name +
" ; " + object.getClass());
- registry.put(name, object);
- }
- }
-
- public void unregister(String name)
- {
- if (name == null)
- {
- throw new IllegalArgumentException("Name cannot be null");
- }
- synchronized(this)
- {
- if(registry.containsKey(name))
- {
- if (log.isDebugEnabled()) log.debug("unregistering object: " +
name);
-
- registry.remove(name);
- }
- }
- }
-
- public Object getObject(String name) throws IdentityException
- {
- if (name == null)
- {
- throw new IllegalArgumentException("Name cannot be null");
- }
-
- //TODO:
- synchronized(this)
- {
- if (registry.containsKey(name))
- {
- return registry.get(name);
- }
- else
- {
- throw new IdentityException("No such mapping in IdentityContext: "
+ name);
- }
- }
- }
-}
Deleted:
trunk/identity/src/main/org/jboss/portal/identity2/IdentityServiceController.java
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/IdentityServiceController.java 2006-12-17
14:45:10 UTC (rev 5884)
+++
trunk/identity/src/main/org/jboss/portal/identity2/IdentityServiceController.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -1,32 +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;
-
-/**
- *
- * @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw
Dawidowicz</a>
- * @version $Revision: 1.1 $
- */
-public interface IdentityServiceController
-{
- public IdentityContext getIdentityContext();
-}
Deleted:
trunk/identity/src/main/org/jboss/portal/identity2/IdentityServiceControllerImpl.java
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/IdentityServiceControllerImpl.java 2006-12-17
14:45:10 UTC (rev 5884)
+++
trunk/identity/src/main/org/jboss/portal/identity2/IdentityServiceControllerImpl.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -1,578 +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;
-
-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.config.metadata.IdentityConfigurationMetaDataFactory;
-import org.jboss.portal.identity2.config.metadata.IdentityConfigurationMetaData;
-import org.jboss.portal.identity2.config.metadata.ModuleMetaData;
-import org.jboss.portal.identity2.config.metadata.ConfigOptionMetaData;
-import org.jboss.portal.identity2.config.metadata.OptionsMetaData;
-import org.jboss.portal.identity2.config.metadata.OptionsGroupMetaData;
-import org.jboss.portal.identity2.config.metadata.OptionsGroupOptionMetaData;
-import org.jboss.portal.identity2.config.metadata.DatasourceMetaData;
-import org.jboss.portal.identity2.config.metadata.ConfigurationParser;
-import org.jboss.portal.identity2.service.IdentityModuleService;
-import org.jboss.portal.identity2.service.IdentityConfigurationService;
-import org.jboss.xb.binding.Unmarshaller;
-import org.jboss.xb.binding.UnmarshallerFactory;
-import org.jboss.xb.binding.ObjectModelFactory;
-import org.jboss.kernel.Kernel;
-import org.jboss.kernel.spi.dependency.KernelControllerContext;
-import org.jboss.kernel.plugins.bootstrap.basic.BasicBootstrap;
-import org.jboss.beans.metadata.plugins.AbstractBeanMetaData;
-import org.jboss.beans.metadata.plugins.AbstractPropertyMetaData;
-
-import javax.management.ObjectName;
-import java.net.URL;
-import java.io.InputStream;
-import java.util.Map;
-import java.util.Iterator;
-import java.util.HashMap;
-import java.util.List;
-import java.util.ArrayList;
-
-/**
- * @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw
Dawidowicz</a>
- * @version $Revision: 1.1 $
- */
-public class IdentityServiceControllerImpl extends AbstractJBossService implements
IdentityServiceController
-{
- private static final org.jboss.logging.Logger log =
org.jboss.logging.Logger.getLogger(IdentityServiceControllerImpl.class);
-
- private String jndiName;
-
- protected JNDI.Binding jndiBinding;
-
- private IdentityContext identityContext;
-
- private boolean registerMBeans = true;
-
- private String configFile;
-
- private String defaultConfigFile;
-
- /**
- * .
- */
- protected Kernel kernel;
-
- /**
- * .
- */
- protected List beans;
-
- protected void startService() throws Exception
- {
- if (jndiName != null)
- {
- jndiBinding = new JNDI.Binding(jndiName, this);
- jndiBinding.bind();
- }
-
- //initialize microcontainer stuff
- try
- {
- BasicBootstrap bootstrap = new BasicBootstrap();
- bootstrap.run();
- kernel = bootstrap.getKernel();
- beans = new ArrayList();
- }
- catch (Exception e)
- {
- throw new IdentityException(e);
- }
-
- ClassLoader tcl = Thread.currentThread().getContextClassLoader();
-
- //TODO: make a dtd for config files.
-
- //parse config files
- IdentityConfigurationMetaData meta =
ConfigurationParser.parseIdentityConfiguration(configFile);
- IdentityConfigurationMetaData defaultMeta =
ConfigurationParser.parseIdentityConfiguration(defaultConfigFile);
-
- KernelControllerContext identityKernelContext;
- try
- {
- AbstractBeanMetaData contextBMD = new AbstractBeanMetaData(
- "portal:identity=IdentityContext",
- IdentityContextImpl.class.getName());
- beans.add(contextBMD);
- identityKernelContext = kernel.getController().install(contextBMD);
- identityContext = (IdentityContext)identityKernelContext.getTarget();
-
- }
- catch (Throwable throwable)
- {
- throw new IdentityException(throwable);
- }
-
- //TODO:update meta options using defaultMeta options
-
- //create detault modules set
-
- //Map[implementation] --> Map[Type] --> ModuleMetaData
- Map defaultImplementations = new HashMap();
-
- //update modules data with defaults
- try
- {
- List defaultModules = defaultMeta.getModules().getModules();
- for (Iterator iterator = defaultModules.iterator(); iterator.hasNext();)
- {
- ModuleMetaData module = (ModuleMetaData)iterator.next();
-
- //check if defaults contains all information
- if (module.getType() == null ||
- module.getImplementation() == null ||
- //module.getJndiName() == null ||
- module.getServiceName() == null ||
- module.getConfig() == null)
- {
- throw new IdentityException("Default module configuration must be
complete");
- }
-
- //store them as maps for different implementations
- String implType = module.getImplementation();
- Map implementation;
- if (defaultImplementations.containsKey(implType))
- {
- implementation = (Map)defaultImplementations.get(implType);
- }
- else
- {
- implementation = new HashMap();
- }
-
- //store per implementation
- implementation.put(module.getType(), module);
- defaultImplementations.put(implType, implementation);
- }
- }
- catch (Exception e)
- {
- throw new IdentityException("Error during processing default configuration
file", e);
- }
-
- //map default datasources by name
- Map defaultDatasources = new HashMap();
- for (Iterator iterator = defaultMeta.getDatasources().getDatasources().iterator();
iterator.hasNext();)
- {
- DatasourceMetaData ds = (DatasourceMetaData)iterator.next();
- defaultDatasources.put(ds.getName(), ds);
-
- }
-
- //process the list of modules, instantiate them, configure them, tide them
- try
- {
- List datasources = meta.getDatasources().getDatasources();
- List modules = meta.getModules().getModules();
-
- //inject configuration service
- IdentityConfigurationService configuration = new
IdentityConfigurationService(meta.getOptions());
- configuration.setIdentityContext(identityContext);
-
- //TODO:set proper jndiName and serviceName
- configuration.start();
-
- //update options with defaults
- updateOptionsWithDefaults(configuration, defaultMeta.getOptions());
-
- //process datasources
- for (Iterator iterator = datasources.iterator(); iterator.hasNext();)
- {
- DatasourceMetaData ds = (DatasourceMetaData)iterator.next();
- if (log.isDebugEnabled()) log.debug("processing datasource: " +
ds.getName() + "/" + ds.getClassName());
- updateDatasourceWithDefaults(ds, defaultDatasources);
-
- //generate initial options
- //TODO:presence of config tag should be forced in dtd
- Map configOptions = ds.getConfig().getOptions();
- Map optionMap = new HashMap();
- for (Iterator iterator1 = configOptions.keySet().iterator();
iterator1.hasNext();)
- {
- String optionName = (String)iterator1.next();
- ConfigOptionMetaData option =
(ConfigOptionMetaData)configOptions.get(optionName);
- optionMap.put(optionName, option.getValue());
- }
-
- //instantiate the module
- //IdentityModuleService moduleService = null;
-
-
- if (ds.getClassName() == null)
- {
- throw new IdentityException("Class name not found for datasource
type: " + ds.getName() + " wrong configuration");
- }
-
- /*try
- {
- moduleService =
(IdentityModuleService)tcl.loadClass(module.getClassName()).newInstance();
- }
- catch (Exception e)
- {
- throw new IdentityException("Unable to instantiate the class: "
+ module.getClassName() );
- }*/
-
- //instantiate datasource using MC
- String entryName = "portal:identity=Datasource,type=" +
ds.getName();
- AbstractBeanMetaData dsBMD = new AbstractBeanMetaData(entryName,
- ds.getClassName());
- //AbstractPropertyMetaData propertyBMD = new
AbstractPropertyMetaData("identityContext", identityContext);
- //moduleBMD.addProperty(propertyBMD);
-
- //initiate parameters from <config>
- for (Iterator iterator1 = optionMap.keySet().iterator();
iterator1.hasNext();)
- {
- String propertyKey = (String)iterator1.next();
- String propertyValue = (String)optionMap.get(propertyKey);
- if (log.isDebugEnabled()) log.debug("adding parameter: " +
propertyKey + " ; " + propertyValue);
- AbstractPropertyMetaData propertyBMD = new
AbstractPropertyMetaData(propertyKey, propertyValue);
- dsBMD.addProperty(propertyBMD);
- }
-
- // Installation
- beans.add(dsBMD);
- KernelControllerContext controllerContext =
kernel.getController().install(dsBMD);
- Object datasource = controllerContext.getTarget();
-
- //make a part of identityContext
- //moduleService.setIdentityContext(identityContext);
-
- //register as an mbean
- if (isRegisterMBeans() && (ds.getServiceName() != null))
- {
- getServer().registerMBean(datasource, new
ObjectName(ds.getServiceName()));
- }
-
-
- }
-
-
-
- //process modules for instantiation
- for (Iterator iterator = modules.iterator(); iterator.hasNext();)
- {
-
- ModuleMetaData module = (ModuleMetaData)iterator.next();
- if (log.isDebugEnabled())
- {
- log.debug("Processing module: " + module.getType() +
"/" + module.getImplementation());
- }
- updateModuleWithDefaults(module, defaultImplementations);
-
- //generate initial options
- Map configOptions = module.getConfig().getOptions();
- Map optionMap = new HashMap();
- for (Iterator iterator1 = configOptions.keySet().iterator();
iterator1.hasNext();)
- {
- String optionName = (String)iterator1.next();
- ConfigOptionMetaData option =
(ConfigOptionMetaData)configOptions.get(optionName);
- optionMap.put(optionName, option.getValue());
- }
-
- //instantiate the module
- //IdentityModuleService moduleService = null;
-
-
- if (module.getClassName() == null)
- {
- throw new IdentityException("Class name not found for module type:
" + module.getType() + " wrong configuration");
- }
-
- /*try
- {
- moduleService =
(IdentityModuleService)tcl.loadClass(module.getClassName()).newInstance();
- }
- catch (Exception e)
- {
- throw new IdentityException("Unable to instantiate the class: "
+ module.getClassName() );
- }*/
-
- //instantiate module using MC
- String entryName = "portal:identity=Module,type=" +
module.getType();
- AbstractBeanMetaData moduleBMD = new AbstractBeanMetaData(entryName,
- module.getClassName());
- AbstractPropertyMetaData propertyBMD = new
AbstractPropertyMetaData("identityContext", identityContext);
- moduleBMD.addProperty(propertyBMD);
-
- //initiate parameters from <config>
- for (Iterator iterator1 = optionMap.keySet().iterator();
iterator1.hasNext();)
- {
- String propertyKey = (String)iterator1.next();
- String propertyValue = (String)optionMap.get(propertyKey);
- if (log.isDebugEnabled()) log.debug("adding parameter: " +
propertyKey + " ; " + propertyValue);
- propertyBMD = new AbstractPropertyMetaData(propertyKey, propertyValue);
- moduleBMD.addProperty(propertyBMD);
- }
-
- //make the type from name
- propertyBMD = new AbstractPropertyMetaData("moduleType",
module.getType());
- moduleBMD.addProperty(propertyBMD);
-
-
- // Installation
- beans.add(moduleBMD);
- KernelControllerContext controllerContext =
kernel.getController().install(moduleBMD);
- Object moduleService = (IdentityModuleService)controllerContext.getTarget();
-
- //make a part of identityContext
- //moduleService.setIdentityContext(identityContext);
-
- //register as an mbean
- if (isRegisterMBeans() && (module.getServiceName() != null))
- {
- getServer().registerMBean(moduleService, new
ObjectName(module.getServiceName()));
- }
- }
-
-
- }
- catch (Throwable e)
- {
- throw new IdentityException("Cannot initiate identity modules: ", e);
- }
- }
-
-
- protected void stopService() throws Exception
- {
- if (jndiBinding != null)
- {
- jndiBinding.unbind();
- jndiBinding = null;
- }
-
- }
-
-
-
-
- /**
- * updates module with proper defaults
- *
- * @param module
- * @param defaultModules
- */
- private void updateModuleWithDefaults(ModuleMetaData module, Map defaultModules)
- {
- if (module.getImplementation() == null)
- {
- return;
- }
- if (!defaultModules.containsKey(module.getImplementation()))
- {
- return;
- }
- Map modules = (Map)defaultModules.get(module.getImplementation());
- if (!modules.containsKey(module.getType()))
- {
- return;
- }
- ModuleMetaData def = (ModuleMetaData)modules.get(module.getType());
-
- if (module.getClassName() == null)
- {
- module.setClassName(def.getClassName());
- }
- if (module.getServiceName() == null)
- {
- module.setServiceName(def.getServiceName());
- }
-
- //now check if config options are overwritten
- if (module.getConfig() == null)
- {
- module.setConfig(def.getConfig());
- }
- else
- {
- Map moduleOptions = module.getConfig().getOptions();
- if (moduleOptions == null)
- {
- return;
- }
- Map defOptions = def.getConfig().getOptions();
-
- for (Iterator iterator = defOptions.keySet().iterator(); iterator.hasNext();)
- {
- String key = (String)iterator.next();
- if (!moduleOptions.containsKey(key))
- {
- ConfigOptionMetaData o = (ConfigOptionMetaData)defOptions.get(key);
- module.getConfig().addOption(o);
- }
- }
- }
- }
-
- /**
- * updates module with proper defaults
- */
- private void updateDatasourceWithDefaults(DatasourceMetaData ds, Map defaultDS)
- {
- if (ds.getName() == null)
- {
- return;
- }
- if (!defaultDS.containsKey(ds.getName()))
- {
- return;
- }
- DatasourceMetaData def = (DatasourceMetaData)defaultDS.get(ds.getName());
- if (ds.getClassName() == null)
- {
- ds.setClassName(def.getClassName());
- }
- if (ds.getServiceName() == null)
- {
- ds.setServiceName(def.getServiceName());
- }
-
- //now check if config options are overwritten
- if (ds.getConfig() == null)
- {
- ds.setConfig(def.getConfig());
- }
- else
- {
- Map dsOptions = ds.getConfig().getOptions();
- if (dsOptions == null)
- {
- return;
- }
- Map defOptions = def.getConfig().getOptions();
-
- for (Iterator iterator = defOptions.keySet().iterator(); iterator.hasNext();)
- {
- String key = (String)iterator.next();
- if (!dsOptions.containsKey(key))
- {
- ConfigOptionMetaData o = (ConfigOptionMetaData)defOptions.get(key);
- ds.getConfig().addOption(o);
- }
- }
- }
- }
-
- /**
- * Check current options and update them with defaults if not exists;
- *
- * @param config
- * @param defaults
- */
- public void updateOptionsWithDefaults(IdentityConfigurationService config,
OptionsMetaData defaults)
- {
- //Map newGroups = new HashMap();
- Map groups = defaults.getGroups();
- for (Iterator iterator = groups.keySet().iterator(); iterator.hasNext();)
- {
- String groupKey = (String)iterator.next();
-
- OptionsGroupMetaData group = (OptionsGroupMetaData)groups.get(groupKey);
-
- if (config.getOptions(groupKey) == null)
- {
- config.setOptions(groupKey, new HashMap());
- }
-
- //Map newOptions = new HashMap();
- Map options = group.getOptions();
- for (Iterator iterator1 = options.keySet().iterator(); iterator1.hasNext();)
- {
- String optionKey = (String)iterator1.next();
-
- OptionsGroupOptionMetaData option =
(OptionsGroupOptionMetaData)options.get(optionKey);
-
- if (config.getValues(groupKey, optionKey) == null)
- {
-
- //config.setValues(groupKey, optionKey, new HashSet());
- config.setValues(groupKey, optionKey, option.getValues());
- }
-
-
- }
- }
-
- }
-
-
- public IdentityContext getIdentityContext()
- {
- return identityContext;
- }
-
-
- public String getConfigFile()
- {
- return configFile;
- }
-
- public void setConfigFile(String configFile)
- {
- this.configFile = configFile;
- }
-
- public String getDefaultConfigFile()
- {
- return defaultConfigFile;
- }
-
- public void setDefaultConfigFile(String defaultConfigFile)
- {
- this.defaultConfigFile = defaultConfigFile;
- }
-
- public String getJndiName()
- {
- return jndiName;
- }
-
- public void setJndiName(String jndiName)
- {
- this.jndiName = jndiName;
- }
-
- public JNDI.Binding getJndiBinding()
- {
- return jndiBinding;
- }
-
- public void setJndiBinding(JNDI.Binding jndiBinding)
- {
- this.jndiBinding = jndiBinding;
- }
-
- public boolean isRegisterMBeans()
- {
- return registerMBeans;
- }
-
- public void setRegisterMBeans(boolean registerMBeans)
- {
- this.registerMBeans = registerMBeans;
- }
-}
Deleted: trunk/identity/src/main/org/jboss/portal/identity2/MembershipModule.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/MembershipModule.java 2006-12-17
14:45:10 UTC (rev 5884)
+++ trunk/identity/src/main/org/jboss/portal/identity2/MembershipModule.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -1,82 +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;
-
-
-import org.jboss.portal.identity.IdentityException;
-import org.jboss.portal.identity2.User;
-import org.jboss.portal.identity2.Role;
-
-import java.util.Set;
-
-/**
- * @author <a href="mailto:boleslaw.dawidowicz@jboss.org">Boleslaw
Dawidowicz</a>
- * @version $Revision: 1.1 $
- */
-public interface MembershipModule
-{
-
- //TODO: add isUserInRole method - it could gain better performance
-
- /**
- * Return the set of role objects that a given user has.
- *
- * @param user the user
- * @return the set of roles of the specified user
- */
- Set getRoles(User user) throws IdentityException, IllegalArgumentException;
-
- Set getUsers(Role role) throws IdentityException, IllegalArgumentException;
-
-
- /**
- * Creates a relationship beetween a role and set of users. Other roles that have
assotiontions with
- * those users remain unaffected.
- *
- * @param role
- * @param 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
- * beetween the user and roles not specified in the provided set.
- *
- * @param user
- * @param 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
- * old RoleModule interface
- *
- * @param roleName
- * @param offset
- * @param limit
- * @deprecated
- */
- Set findRoleMembers(String roleName, int offset, int limit, String userNameFilter)
throws IdentityException, IllegalArgumentException;
-}
Deleted: trunk/identity/src/main/org/jboss/portal/identity2/ProfileMap.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/ProfileMap.java 2006-12-17 14:45:10
UTC (rev 5884)
+++ trunk/identity/src/main/org/jboss/portal/identity2/ProfileMap.java 2006-12-17 14:52:15
UTC (rev 5885)
@@ -1,43 +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;
-
-import java.util.Map;
-
-/**
- * Extends <code>java.util.Map</code>le to provide meta information about
user profile.
- *
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 5218 $
- */
-public interface ProfileMap extends Map
-{
- /**
- * Return true if the profile value is read only.
- *
- * @param key
- * @return true if the profile value is read only
- * @throws ClassCastException if the key is not an instance of string
- */
- boolean isReadOnly(Object key);
-}
Deleted: trunk/identity/src/main/org/jboss/portal/identity2/Role.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/Role.java 2006-12-17 14:45:10 UTC
(rev 5884)
+++ trunk/identity/src/main/org/jboss/portal/identity2/Role.java 2006-12-17 14:52:15 UTC
(rev 5885)
@@ -1,45 +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;
-
-/**
- * A role of users.
- *
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @author <a href="mailto:theute@jboss.org">Thomas Heute</a>
- * @version $Revision: 2001 $
- */
-public interface Role
-{
- /** The role identifier. */
- public Object getId();
-
- /** The role name used in security rules. This name can not be modified */
- public String getName();
-
- /** The role display name used on screens. This name can be modified */
- public String getDisplayName();
-
- /** */
- public void setDisplayName(String name);
-}
Deleted: trunk/identity/src/main/org/jboss/portal/identity2/RoleModule.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/RoleModule.java 2006-12-17 14:45:10
UTC (rev 5884)
+++ trunk/identity/src/main/org/jboss/portal/identity2/RoleModule.java 2006-12-17 14:52:15
UTC (rev 5885)
@@ -1,102 +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;
-
-import org.jboss.portal.identity.IdentityException;
-import org.jboss.portal.identity2.Role;
-
-import java.util.Set;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet </a>
- * @author <a href="mailto:theute@jboss.org">Thomas Heute </a>
- * @author Roy Russo : roy at jboss dot org
- * @version $Revision: 2001 $
- */
-public interface RoleModule
-{
- /**
- * Retrieves a role by its name
- *
- * @param name the role name
- * @return the role
- */
- Role findRoleByName(String name) throws IdentityException, IllegalArgumentException;
-
- /**
- * Retrieve a collection of role from the role names.
- *
- * @param names the role names
- * @return a collection of roles
- * @throws IllegalArgumentException
- */
- Set findRolesByNames(String[] names) throws IdentityException,
IllegalArgumentException;
-
- /**
- * Retrieves a role by its id.
- *
- * @param id the role id
- * @return the role
- */
- Role findRoleById(Object id) throws IdentityException, IllegalArgumentException;
-
- /**
- * Retrieves a role by its id.
- *
- * @param id the role id
- * @return the role
- */
- Role findRoleById(String id) throws IdentityException, IllegalArgumentException;
-
- /**
- * Create a new role with the specified name.
- *
- * @param name the role name
- * @param displayName the role display name
- * @return the role
- */
- Role createRole(String name, String displayName) throws IdentityException,
IllegalArgumentException;
-
- /**
- * Remove a role.
- *
- * @param id the role id
- */
- void removeRole(Object id) throws IdentityException, IllegalArgumentException;
-
- /**
- * Returns the number of roles.
- *
- * @return the number of roles
- */
- int getRolesCount() throws IdentityException;
-
- /**
- * Get all the roles
- *
- * @return the roles
- */
- Set findRoles() throws IdentityException;
-
-
-}
Deleted: trunk/identity/src/main/org/jboss/portal/identity2/User.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/User.java 2006-12-17 14:45:10 UTC
(rev 5884)
+++ trunk/identity/src/main/org/jboss/portal/identity2/User.java 2006-12-17 14:52:15 UTC
(rev 5885)
@@ -1,80 +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;
-
-import org.jboss.portal.identity.ProfileMap;
-
-import java.util.Date;
-import java.util.Locale;
-
-/**
- * A user.
- *
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @author <a href="mailto:theute@jboss.org">Thomas Heute</a>
- * @author <a href="mailto:mageshbk@jboss.com">Magesh Kumar Bojan
</a>
- * @version $Revision: 5218 $
- */
-public interface User
-{
- 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";
- String INFO_USER_SIGNATURE = "portal.user.signature";
- String INFO_USER_INTERESTS = "portal.user.interests";
- String INFO_USER_LOCALE = "portal.user.locale";
- String INFO_USER_IM_ICQ = "portal.user.im.icq";
- String INFO_USER_IM_AIM = "portal.user.im.aim";
- 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";
-
- String INFO_USER_ENABLED = "portal.user.enabled";
- String INFO_USER_EMAIL_REAL = "portal.user.email.real";
-
-
-
-
- /** The user identifier. */
- public Object getId();
-
- /** The user name. */
- public String getUserName();
-
- /** Set the password using proper encoding. */
- public void updatePassword(String password);
-
- /** Return true if the password is valid. */
- public boolean validatePassword(String password);
-}
Deleted: trunk/identity/src/main/org/jboss/portal/identity2/UserModule.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/UserModule.java 2006-12-17 14:45:10
UTC (rev 5884)
+++ trunk/identity/src/main/org/jboss/portal/identity2/UserModule.java 2006-12-17 14:52:15
UTC (rev 5885)
@@ -1,103 +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;
-
-import org.jboss.portal.identity.IdentityException;
-import org.jboss.portal.identity.NoSuchUserException;
-import org.jboss.portal.identity2.User;
-
-import java.util.Set;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet </a>
- * @version $Revision: 2001 $
- */
-public interface UserModule
-{
- /**
- * Retrieve a user by its name.
- *
- * @param userName the user name
- * @return the user
- */
- User findUserByUserName(String userName) throws IdentityException,
IllegalArgumentException, NoSuchUserException;
-
- /**
- * Retrieve a user by its id.
- *
- * @param id the user id
- * @return the user
- * @throws IllegalArgumentException if the id is null
- */
- User findUserById(Object id) throws IdentityException, IllegalArgumentException,
NoSuchUserException;
-
- /**
- * Retrieve a user by its id.
- *
- * @param id the user id
- * @return the user
- * @throws IllegalArgumentException if the id is null or not in the good format
- */
- User findUserById(String id) throws IdentityException, IllegalArgumentException,
NoSuchUserException;
-
- /**
- * Creates a new user with the specified name.
- *
- * @param userName
- * @return the user
- */
- User createUser(String userName, String password) throws IdentityException,
IllegalArgumentException;
-
- /**
- * Remove a user.
- *
- * @param id the user id
- */
- void removeUser(Object id) throws IdentityException, IllegalArgumentException;
-
- /**
- * Get a range of users.
- *
- * @param offset the offset of the first result to retrieve
- * @param limit the maximum number of users to retrieve
- * @return the user set
- */
- Set findUsers(int offset, int limit) throws IdentityException,
IllegalArgumentException;
-
- /**
- * Get a range of users.
- *
- * @param filter a string filter applied to the user name.
- * @param offset the offset of the frist result to retrieve
- * @param limit the maximum number of users to retrieve
- * @return the user set
- */
- Set findUsersFilteredByUserName(String filter, int offset, int limit) throws
IdentityException, IllegalArgumentException;
-
- /**
- * Returns the number of users.
- *
- * @return the number of users
- */
- int getUserCount() throws IdentityException, IllegalArgumentException;
-}
Deleted: trunk/identity/src/main/org/jboss/portal/identity2/UserProfileModule.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/UserProfileModule.java 2006-12-17
14:45:10 UTC (rev 5884)
+++ trunk/identity/src/main/org/jboss/portal/identity2/UserProfileModule.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -1,45 +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;
-
-import org.jboss.portal.identity.IdentityException;
-import org.jboss.portal.identity2.info.ProfileInfo;
-
-import java.util.Map;
-
-/**
- * @author <a href="mailto:boleslaw.dawidowicz@jboss.org">Boleslaw
Dawidowicz</a>
- * @version $Revision: 1.1 $
- */
-public interface UserProfileModule
-{
-
- public Object getProperty(User user, String propertyName) throws IdentityException,
IllegalArgumentException;
-
- public void setProperty(User user, String name, Object property) throws
IdentityException, IllegalArgumentException;
-
- public Map getProperties(User user) throws IdentityException,
IllegalArgumentException;
-
- public ProfileInfo getProfileInfo() throws IdentityException;
-
-}
Deleted:
trunk/identity/src/main/org/jboss/portal/identity2/db/HibernateMembershipModuleImpl.java
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/db/HibernateMembershipModuleImpl.java 2006-12-17
14:45:10 UTC (rev 5884)
+++
trunk/identity/src/main/org/jboss/portal/identity2/db/HibernateMembershipModuleImpl.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -1,254 +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.db;
-
-import org.jboss.portal.identity2.service.MembershipModuleService;
-import org.jboss.portal.identity2.User;
-import org.jboss.portal.identity2.Role;
-import org.jboss.portal.identity2.db.HibernateUserImpl;
-import org.jboss.portal.identity2.db.HibernateRoleImpl;
-import org.jboss.portal.identity.IdentityException;
-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.util.Set;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Collections;
-
-/**
- * @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw
Dawidowicz</a>
- * @version $Revision: 1.1 $
- */
-public class HibernateMembershipModuleImpl extends MembershipModuleService
-{
- /** . */
- private static final org.jboss.logging.Logger log =
org.jboss.logging.Logger.getLogger(HibernateMembershipModuleImpl.class);
- /** . */
- protected SessionFactory sessionFactory;
-
- /** . */
- protected String sessionFactoryJNDIName;
-
- protected void startService() throws Exception
- {
- //
- sessionFactory = (SessionFactory)new
InitialContext().lookup(sessionFactoryJNDIName);
-
- super.startService();
- }
-
- protected void stopService() throws Exception
- {
-
- //
- sessionFactory = null;
-
- super.stopService();
- }
-
-// public SessionFactory getSessionFactory()
-// {
-// return sessionFactory;
-// }
-
- public String getSessionFactoryJNDIName()
- {
- return sessionFactoryJNDIName;
- }
-
- public void setSessionFactoryJNDIName(String sessionFactoryJNDIName)
- {
- this.sessionFactoryJNDIName = sessionFactoryJNDIName;
- }
-
- public Set getRoles(User user) throws IdentityException
- {
- //throw new UnsupportedOperationException("Not yet implemented");
- if (!(user instanceof org.jboss.portal.identity2.db.HibernateUserImpl))
- {
- throw new IllegalArgumentException("User is not a HibernateUserImpl
user");
- }
-
- // We return an immutable set to avoid modifications
- HibernateUserImpl ui = (HibernateUserImpl)user;
- Set roles = ui.getRoles();
- Set copy = new HashSet();
- for (Iterator iterator = roles.iterator(); iterator.hasNext();)
- {
- HibernateRoleImpl role = (HibernateRoleImpl)iterator.next();
- copy.add(role);
- }
-
- return Collections.unmodifiableSet(copy);
- }
-
- public Set getUsers(Role role) throws IdentityException
- {
- if (!(role instanceof HibernateRoleImpl))
- {
- throw new IllegalArgumentException("User is not a HibernateRoleImpl
user");
- }
-
- // We return an immutable set to avoid modifications
- HibernateRoleImpl ri = (HibernateRoleImpl)role;
- Set users = ri.getUsers();
- Set copy = new HashSet();
- for (Iterator iterator = users.iterator(); iterator.hasNext();)
- {
- HibernateUserImpl user = (HibernateUserImpl)iterator.next();
- copy.add(user);
- }
-
- return Collections.unmodifiableSet(copy);
- }
-
- public void assignUsers(Role role, Set users) throws IdentityException
- {
- //throw new UnsupportedOperationException("Not yet implemented");
- if (!(role instanceof HibernateRoleImpl))
- {
- throw new IllegalArgumentException("User is not a HibernateRoleImpl
user");
- }
-
- for (Iterator i = users.iterator(); i.hasNext();)
- {
- Object o = i.next();
- if (o instanceof HibernateUserImpl)
- {
- HibernateUserImpl user = (HibernateUserImpl)o;
- user.getRoles().add(role);
- }
- else
- {
- throw new IllegalArgumentException("Only HibernateUserImpl roles can be
accepted");
- }
- }
-
- }
-
- public void assignRoles(User user, Set roles) throws IdentityException
- {
- //throw new UnsupportedOperationException("Not yet implemented");
- if (!(user instanceof HibernateUserImpl))
- {
- throw new IllegalArgumentException("User is not a HibernateUserImpl
user");
- }
-
- // We make a defensive copy with unwrapped maps and update with a new set
- Set copy = new HashSet();
- for (Iterator i = roles.iterator(); i.hasNext();)
- {
- Object o = i.next();
- if (o instanceof HibernateRoleImpl)
- {
- copy.add(o);
- }
- else
- {
- throw new IllegalArgumentException("Only HibernateRoleImpl roles can be
accepted");
- }
- }
-
- // Assign new roles
- HibernateUserImpl ui = (HibernateUserImpl)user;
- ui.setRoles(copy);
- }
-
- //TODO:
- public Set findRoleMembers(String roleName, int offset, int limit, String
userNameFilter) throws IdentityException
- {
- if (roleName != null)
- {
- try
- {
- Session session = getCurrentSession();
-
- HibernateUserImpl userimpl = new HibernateUserImpl();
- userimpl.setEnabled(true);
-
- Query query;
- if (userNameFilter.trim().length() != 0)
- {
- //
- userNameFilter = "%" + userNameFilter.replaceAll("%",
"") + "%";
-
- //
- query = session.createQuery("from HibernateUserImpl 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 HibernateUserImpl 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");
- }
- }
-
- /**
- * Process Set of Map objects and returns a Set of HibernateRoleImpl objects
- * @param maps
- * @return
- * @throws Exception
- */
-
- /** 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();
- }
-}
Deleted: trunk/identity/src/main/org/jboss/portal/identity2/db/HibernateRoleImpl.java
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/db/HibernateRoleImpl.java 2006-12-17
14:45:10 UTC (rev 5884)
+++
trunk/identity/src/main/org/jboss/portal/identity2/db/HibernateRoleImpl.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -1,149 +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.db;
-
-import org.jboss.portal.identity2.Role;
-
-import java.util.Set;
-import java.util.HashSet;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet </a>
- * @author <a href="mailto:theute@jboss.org">Thomas Heute </a>
- * @author Roy Russo : roy at jboss dot org
- * @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw
Dawidowicz</a>
- * @version $Revision: 5448 $
- */
-public class HibernateRoleImpl
- implements Role
-{
-
- private Long key;
- private String name;
- private Set users;
- private String displayName;
-
- /**
- *
- */
- public HibernateRoleImpl()
- {
- this.key = null;
- this.name = null;
- this.displayName = null;
- this.users = new HashSet();
- }
-
- /**
- *
- */
- public HibernateRoleImpl(String name)
- {
- this.key = null;
- this.name = name;
- this.displayName = name;
- this.users = new HashSet();
- }
-
- /**
- *
- */
- public HibernateRoleImpl(String name, String displayName)
- {
- this.key = null;
- this.name = name;
- this.displayName = displayName;
- this.users = new HashSet();
- }
-
- /**
- * @hibernate.id column="jbp_rid" generator-class="native"
- * <p/>
- * 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 + "]";
- }
-}
Deleted:
trunk/identity/src/main/org/jboss/portal/identity2/db/HibernateRoleModuleImpl.java
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/db/HibernateRoleModuleImpl.java 2006-12-17
14:45:10 UTC (rev 5884)
+++
trunk/identity/src/main/org/jboss/portal/identity2/db/HibernateRoleModuleImpl.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -1,393 +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.db;
-
-import org.jboss.portal.identity2.RoleModule;
-import org.jboss.portal.identity2.Role;
-import org.jboss.portal.identity.IdentityException;
-import org.jboss.portal.identity2.User;
-import org.jboss.portal.identity2.db.HibernateRoleImpl;
-import org.jboss.portal.identity2.db.HibernateUserImpl;
-import org.jboss.portal.common.util.JNDI;
-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@jboss.org">Julien Viet </a>
- * @author <a href="mailto:theute@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(HibernateRoleModuleImpl.class);
- /** . */
- protected SessionFactory sessionFactory;
-
- /** . */
- protected String sessionFactoryJNDIName;
-
- protected void startService() throws Exception
- {
- //
- sessionFactory = (SessionFactory)new
InitialContext().lookup(sessionFactoryJNDIName);
-
- super.startService();
- }
-
- protected void stopService() throws Exception
- {
-
- //
- sessionFactory = null;
-
- super.stopService();
- }
-
-// public SessionFactory getSessionFactory()
-// {
-// return sessionFactory;
-// }
-
- public String getSessionFactoryJNDIName()
- {
- return sessionFactoryJNDIName;
- }
-
- public void setSessionFactoryJNDIName(String sessionFactoryJNDIName)
- {
- this.sessionFactoryJNDIName = sessionFactoryJNDIName;
- }
-
-
- public Role findRoleByName(String name) throws IdentityException
- {
- if (name != null)
- {
- try
- {
- Session session = getCurrentSession();
- Criteria criteria = session.createCriteria(HibernateRoleImpl.class);
- criteria.add(Restrictions.naturalId().set("name", name));
- criteria.setCacheable(true);
- HibernateRoleImpl role = (HibernateRoleImpl)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 HibernateRoleImpl 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();
- HibernateRoleImpl role =
(HibernateRoleImpl)session.get(HibernateRoleImpl.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
- {
- HibernateRoleImpl role = new HibernateRoleImpl(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();
- HibernateRoleImpl role =
(HibernateRoleImpl)session.load(HibernateRoleImpl.class, (Long)id);
- Iterator users = role.getUsers().iterator();
- while (users.hasNext())
- {
- HibernateUserImpl user = (HibernateUserImpl)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
HibernateRoleImpl 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 HibernateRoleImpl");
- 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();
-
- HibernateUserImpl HibernateUserImpl = new HibernateUserImpl();
- HibernateUserImpl.setEnabled(true);
-
- Query query;
- if (userNameFilter.trim().length() != 0)
- {
- //
- userNameFilter = "%" + userNameFilter.replaceAll("%",
"") + "%";
-
- //
- query = session.createQuery("from HibernateUserImpl 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 HibernateUserImpl 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 HibernateUserImpl))
- {
- 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 HibernateRoleImpl)
- {
- copy.add(o);
- }
- else
- {
- throw new IllegalArgumentException("Only db roles can be
accepted");
- }
- }
-
- // Assign new roles
- HibernateUserImpl ui = (HibernateUserImpl)user;
- ui.setRoles(copy);
- }
-
- public Set getRoles(User user) throws IdentityException
- {
- if (!(user instanceof HibernateUserImpl))
- {
- throw new IllegalArgumentException("User is not a db user");
- }
-
- // We return an immutable set to avoid modifications
- HibernateUserImpl ui = (HibernateUserImpl)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();
- }
-}
Deleted: trunk/identity/src/main/org/jboss/portal/identity2/db/HibernateUserImpl.java
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/db/HibernateUserImpl.java 2006-12-17
14:45:10 UTC (rev 5884)
+++
trunk/identity/src/main/org/jboss/portal/identity2/db/HibernateUserImpl.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -1,538 +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.db;
-
-import org.jboss.portal.identity2.User;
-import org.jboss.portal.common.util.Tools;
-import org.jboss.portal.common.p3p.P3PConstants;
-import org.jboss.portal.identity2.ProfileMap;
-
-import java.util.Map;
-import java.util.HashMap;
-import java.util.Set;
-import java.util.Date;
-import java.util.HashSet;
-import java.util.Collections;
-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@jboss.org">Julien Viet </a>
- * @author <a href="mailto:theute@jboss.org">Thomas Heute </a>
- * @author <a href="mailto:mageshbk@jboss.com">Magesh Kumar Bojan
</a>
- * @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw
Dawidowicz</a>
- * @version $Revision: 5448 $
- */
-public class HibernateUserImpl
- implements User
-{
-
- static final Map ACCESSORS = HibernateUserImpl.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
StringPropertyAccessor(P3PConstants.INFO_USER_NAME_NICKNAME, "userName", false,
false));
- map.put(P3PConstants.INFO_USER_BUSINESS_INFO_ONLINE_EMAIL, new
StringPropertyAccessor(P3PConstants.INFO_USER_BUSINESS_INFO_ONLINE_EMAIL,
"realEmail", true, true));
- map.put(P3PConstants.INFO_USER_NAME_GIVEN, new
StringPropertyAccessor(P3PConstants.INFO_USER_NAME_GIVEN, "givenName", true,
true));
- map.put(P3PConstants.INFO_USER_NAME_FAMILY, new
StringPropertyAccessor(P3PConstants.INFO_USER_NAME_FAMILY, "familyName", true,
true));
-
- // Map attributes specific to JBoss Portal
- map.put(org.jboss.portal.identity2.User.INFO_USER_EMAIL_FAKE, new
StringPropertyAccessor(org.jboss.portal.identity2.User.INFO_USER_EMAIL_FAKE,
"fakeEmail", true, true));
- map.put(org.jboss.portal.identity2.User.INFO_USER_REGISTRATION_DATE, new
DatePropertyAccessor(org.jboss.portal.identity2.User.INFO_USER_REGISTRATION_DATE,
"registrationDate", false, false));
- map.put(org.jboss.portal.identity2.User.INFO_USER_VIEW_EMAIL_VIEW_REAL, new
BooleanPropertyAccessor(org.jboss.portal.identity2.User.INFO_USER_VIEW_EMAIL_VIEW_REAL,
"viewRealEmail", true, false));
- map.put(org.jboss.portal.identity2.User.INFO_USER_ENABLED, new
BooleanPropertyAccessor(org.jboss.portal.identity2.User.INFO_USER_ENABLED,
"enabled", true, false));
-
- //
- return Collections.unmodifiableMap(map);
- }
-
- protected ProfileMap profileMap;
-
- /*
- * 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 HibernateUserImpl()
- {
- this.key = null;
- this.userName = null;
- this.dynamic = null;
- this.roles = null;
- this.registrationDate = null;
- this.enabled = false;
- this.profileMap = new ProfileMapImpl(this);
- }
-
- /**
- *
- */
- public HibernateUserImpl(String userName)
- {
- this.key = null;
- this.userName = userName;
- this.dynamic = new HashMap();
- this.roles = new HashSet();
- this.registrationDate = new Date();
- this.enabled = false;
- this.profileMap = new ProfileMapImpl(this);
- }
-
- /** 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;
- }
-
- public ProfileMap getProfileMap()
- {
- return profileMap;
- }
-
- // 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 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;
- }
-
- public boolean validatePassword(String password)
- {
- if (password != null)
- {
- String hashedPassword = Tools.md5AsHexString(password);
- return hashedPassword.equals(this.password);
- }
- return false;
- }
-
- /**
- *
- */
- 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 = HibernateUserImpl.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 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 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 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)HibernateUserImpl.DatePropertyAccessor.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)HibernateUserImpl.DatePropertyAccessor.formatLocal.get();
- return format.format(date);
- }
- }
-}
Deleted:
trunk/identity/src/main/org/jboss/portal/identity2/db/HibernateUserModuleImpl.java
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/db/HibernateUserModuleImpl.java 2006-12-17
14:45:10 UTC (rev 5884)
+++
trunk/identity/src/main/org/jboss/portal/identity2/db/HibernateUserModuleImpl.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -1,291 +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.db;
-
-import org.jboss.portal.jems.as.system.AbstractJBossService;
-import org.jboss.portal.identity2.UserModule;
-import org.jboss.portal.identity2.User;
-import org.jboss.portal.identity.IdentityException;
-import org.jboss.portal.identity.NoSuchUserException;
-import org.jboss.portal.identity2.db.HibernateUserImpl;
-import org.jboss.portal.common.util.JNDI;
-import org.jboss.portal.common.util.Tools;
-import org.jboss.portal.identity2.service.UserModuleService;
-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@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 void startService() throws Exception
- {
- //
- sessionFactory = (SessionFactory)new
InitialContext().lookup(sessionFactoryJNDIName);
-
- super.startService();
- }
-
- protected void stopService() throws Exception
- {
-
- //
- sessionFactory = null;
-
- super.stopService();
- }
-
-// public SessionFactory getSessionFactory()
-// {
-// return sessionFactory;
-// }
-
- public String getSessionFactoryJNDIName()
- {
- return sessionFactoryJNDIName;
- }
-
- public void setSessionFactoryJNDIName(String sessionFactoryJNDIName)
- {
- this.sessionFactoryJNDIName = sessionFactoryJNDIName;
- }
-
-
- public User findUserByUserName(String userName) throws IdentityException
- {
- if (userName != null)
- {
- try
- {
- Session session = getCurrentSession();
- Query query = session.createQuery("from HibernateUserImpl where
userName=:userName");
- query.setParameter("userName", userName);
- query.setCacheable(true);
- HibernateUserImpl user = (HibernateUserImpl)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();
- HibernateUserImpl user =
(HibernateUserImpl)session.get(HibernateUserImpl.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) throws IdentityException
- {
- if (userName != null)
- {
- try
- {
- HibernateUserImpl user = new HibernateUserImpl(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();
- HibernateUserImpl user =
(HibernateUserImpl)session.load(HibernateUserImpl.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 HibernateUserImpl");
- 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 HibernateUserImpl 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
HibernateUserImpl 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();
- }
-}
Deleted:
trunk/identity/src/main/org/jboss/portal/identity2/db/HibernateUserProfileModuleImpl.java
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity2/db/HibernateUserProfileModuleImpl.java 2006-12-17
14:45:10 UTC (rev 5884)
+++
trunk/identity/src/main/org/jboss/portal/identity2/db/HibernateUserProfileModuleImpl.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -1,294 +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.db;
-
-import org.jboss.portal.identity2.User;
-import org.jboss.portal.identity2.UserProfileModule;
-import org.jboss.portal.identity2.IdentityContext;
-import org.jboss.portal.identity2.info.ProfileInfo;
-import org.jboss.portal.identity2.info.PropertyInfo;
-import org.jboss.portal.identity2.db.HibernateUserImpl;
-import org.hibernate.SessionFactory;
-import org.hibernate.Session;
-import org.hibernate.Query;
-import org.hibernate.HibernateException;
-
-import javax.naming.InitialContext;
-import org.jboss.portal.identity2.service.UserProfileModuleService;
-import org.jboss.portal.identity.IdentityException;
-import org.jboss.portal.identity.NoSuchUserException;
-
-import java.util.Map;
-import java.util.Set;
-import java.util.Iterator;
-import java.util.HashMap;
-
-/**
- * @author <a href="mailto:boleslaw.dawidowicz@jboss.org">Boleslaw
Dawidowicz</a>
- * @version $Revision: 1.1 $
- */
-public class HibernateUserProfileModuleImpl extends UserProfileModuleService
-{
-
- /** . */
- private static final org.jboss.logging.Logger log =
org.jboss.logging.Logger.getLogger(HibernateUserProfileModuleImpl.class);
- /** . */
- protected SessionFactory sessionFactory;
-
- /** . */
- protected String sessionFactoryJNDIName;
-
- private boolean synchronizeNonExistingUsers = true;
-
- private boolean acceptOtherImplementations = true;
-
- private String defaultSynchronizePassword;
-
- protected void startService() throws Exception
- {
- //
- sessionFactory = (SessionFactory)new
InitialContext().lookup(sessionFactoryJNDIName);
-
- super.startService();
-
- }
-
- protected void stopService() throws Exception
- {
- //
- sessionFactory = null;
- super.stopService();
- }
-
-// public SessionFactory getSessionFactory()
-// {
-// return sessionFactory;
-// }
-
- public String getSessionFactoryJNDIName()
- {
- return sessionFactoryJNDIName;
- }
-
- public void setSessionFactoryJNDIName(String sessionFactoryJNDIName)
- {
- this.sessionFactoryJNDIName = sessionFactoryJNDIName;
- }
-
- public Object getProperty(User user, String propertyName) throws IdentityException
- {
- if (user == null)
- {
- throw new IllegalArgumentException("User cannot be null");
- }
- if (propertyName == null)
- {
- throw new IllegalArgumentException("Property name need to have
value");
- }
-
- HibernateUserImpl dbUser = processUser(user);
-
- PropertyInfo pi = getProfileInfo().getPropertyInfo(propertyName);
-
- if (pi == null)
- {
- throw new IdentityException("Cannot find profile information about
property: " + propertyName);
- }
-
- return dbUser.getProfileMap().get(propertyName);
- }
-
- public void setProperty(User user, String propertyName, Object propertyValue) throws
IdentityException
- {
- if (user == null)
- {
- throw new IllegalArgumentException("User cannot be null");
- }
- if (propertyName == null)
- {
- throw new IllegalArgumentException("Property name need to have
value");
- }
-
- HibernateUserImpl dbUser = processUser(user);
-
-
- PropertyInfo pi = getProfileInfo().getPropertyInfo(propertyName);
-
- if (pi == null)
- {
- throw new IdentityException("Cannot find profile information about
property: " + propertyName);
- }
- else if (!pi.getAccessMode().equals(PropertyInfo.ACCESS_MODE_READ_WRITE))
- {
- throw new IdentityException("Property is not allowed for write access:
" + propertyName);
- }
-
- //if value is null reset property
-
- dbUser.getProfileMap().put(propertyName, propertyValue);
- }
-
- public Map getProperties(User user) throws IdentityException
- {
- if (user == null)
- {
- throw new IllegalArgumentException("User cannot be null");
- }
-
- HibernateUserImpl dbUser = processUser(user);
-
-
-
- //make a copy
- Map props = new HashMap();
- Map profile = dbUser.getProfileMap();
- Set keys = profile.keySet();
- for (Iterator iterator = keys.iterator(); iterator.hasNext();)
- {
- String key = (String)iterator.next();
- props.put(key, profile.get(key));
- }
- return props;
- }
-
-
-
- /** 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();
- }
-
- protected HibernateUserImpl processUser(User user) throws IdentityException
- {
- if (user instanceof HibernateUserImpl)
- {
- return (HibernateUserImpl)user;
- }
- else if (!isAcceptOtherImplementations())
- {
- throw new IllegalArgumentException("This UserProfileModule implementation
support only HibenrateUserImpl objects - set acceptOtherImplementations option to
true");
- }
- if (log.isDebugEnabled()) log.debug("Processing non HibernateUserImpl object:
" + user.getClass());
- //if not Hibernate user try to obtain it using userName
- Session session = getCurrentSession();
- Query query = session.createQuery("from HibernateUserImpl where
userName=:userName");
- query.setParameter("userName", user.getUserName());
- query.setCacheable(true);
- HibernateUserImpl hu = (HibernateUserImpl)query.uniqueResult();
-
- if (hu != null )
- {
- return hu;
- }
- else if (!isSynchronizeNonExistingUsers())
- {
- throw new IdentityException("No user in DB - set
synchronizeNonExistingUsers option to true");
- }
- else
- {
- try
- {
- hu = new HibernateUserImpl(user.getUserName());
- //user.updatePassword(user.getPassword());
- if (defaultSynchronizePassword != null)
- {
- user.updatePassword(getDefaultSynchronizePassword());
- }
- session = getCurrentSession();
- session.save(hu);
- return hu;
- }
- catch (HibernateException e)
- {
- String message = "Cannot create user " + user.getUserName();
- log.error(message, e);
- throw new IdentityException(message, e);
- }
- }
-
-
- }
-
-
- /**
- * obtains UserProfile object - if module is used as a Delegate it tries to obtain it
from the main one.
- * @return
- * @throws IdentityException
- */
- public ProfileInfo getProfileInfo() throws IdentityException
- {
-
-
- if (super.getProfileInfo() == null)
- {
- //obtain main UserProfileModule
- UserProfileModule module =
(UserProfileModule)getIdentityContext().getObject(IdentityContext.TYPE_USER_PROFILE_MODULE);
- if (module == this)
- {
- throw new IdentityException("ProfileInfo not accessible - check
configuration");
- }
- else
- {
- setProfileInfo(module.getProfileInfo());
- }
- }
- return super.getProfileInfo();
- }
-
-
- public boolean isSynchronizeNonExistingUsers()
- {
- return synchronizeNonExistingUsers;
- }
-
- public void setSynchronizeNonExistingUsers(boolean synchronizeNonExistingUsers)
- {
- this.synchronizeNonExistingUsers = synchronizeNonExistingUsers;
- }
-
-
- public boolean isAcceptOtherImplementations()
- {
- return acceptOtherImplementations;
- }
-
- public void setAcceptOtherImplementations(boolean acceptOtherImplementations)
- {
- this.acceptOtherImplementations = acceptOtherImplementations;
- }
-
- public String getDefaultSynchronizePassword()
- {
- return defaultSynchronizePassword;
- }
-
- public void setDefaultSynchronizePassword(String defaultSynchronizePassword)
- {
- this.defaultSynchronizePassword = defaultSynchronizePassword;
- }
-}
-
Deleted: trunk/identity/src/main/org/jboss/portal/identity2/db/ProfileMapImpl.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/db/ProfileMapImpl.java 2006-12-17
14:45:10 UTC (rev 5884)
+++ trunk/identity/src/main/org/jboss/portal/identity2/db/ProfileMapImpl.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -1,275 +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.db;
-
-import org.jboss.portal.identity2.ProfileMap;
-import org.jboss.portal.identity2.db.HibernateUserImpl;
-
-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@jboss.org">Julien Viet</a>
- * @version $Revision: 5448 $
- */
-public class ProfileMapImpl implements ProfileMap
-{
-
- /** . */
- private HibernateUserImpl user;
-
- public ProfileMapImpl(HibernateUserImpl 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");
- }
- HibernateUserImpl.PropertyAccessor accessor =
(HibernateUserImpl.PropertyAccessor)HibernateUserImpl.ACCESSORS.get(key);
- return accessor != null && !accessor.isWritable();
- }
-
- public int size()
- {
- return HibernateUserImpl.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");
- }
- HibernateUserImpl.PropertyAccessor accessor =
(HibernateUserImpl.PropertyAccessor)HibernateUserImpl.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 = HibernateUserImpl.ACCESSORS.values().iterator(); i.hasNext();)
- {
- HibernateUserImpl.PropertyAccessor accessor =
(HibernateUserImpl.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");
- }
- HibernateUserImpl.PropertyAccessor accessor =
(HibernateUserImpl.PropertyAccessor)HibernateUserImpl.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");
- }
- HibernateUserImpl.PropertyAccessor accessor =
(HibernateUserImpl.PropertyAccessor)HibernateUserImpl.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");
- }
- HibernateUserImpl.PropertyAccessor accessor =
(HibernateUserImpl.PropertyAccessor)HibernateUserImpl.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(HibernateUserImpl.ACCESSORS.keySet());
- return set;
- }
-
- public Collection values()
- {
- ArrayList collection = new ArrayList(size());
- for (Iterator i = HibernateUserImpl.ACCESSORS.values().iterator(); i.hasNext();)
- {
- HibernateUserImpl.PropertyAccessor accessor =
(HibernateUserImpl.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 = HibernateUserImpl.ACCESSORS.values().iterator(); i.hasNext();)
- {
- HibernateUserImpl.PropertyAccessor accessor =
(HibernateUserImpl.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();
- HibernateUserImpl.PropertyAccessor accessor =
(HibernateUserImpl.PropertyAccessor)HibernateUserImpl.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/test/identity/ConfigurationTestCase.java
===================================================================
---
trunk/identity/src/main/org/jboss/portal/test/identity/ConfigurationTestCase.java 2006-12-17
14:45:10 UTC (rev 5884)
+++
trunk/identity/src/main/org/jboss/portal/test/identity/ConfigurationTestCase.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -26,18 +26,13 @@
import org.apache.log4j.SimpleLayout;
import org.apache.log4j.Logger;
import org.apache.log4j.Level;
-import org.jboss.portal.identity2.IdentityContextImpl;
-import org.jboss.portal.identity2.IdentityServiceControllerImpl;
-import org.jboss.portal.identity2.IdentityContext;
-import org.jboss.portal.identity2.service.IdentityModuleService;
-import org.jboss.portal.identity2.config.SimpleConfigurationImpl;
+import org.jboss.portal.identity.IdentityContextImpl;
+import org.jboss.portal.identity.IdentityServiceControllerImpl;
+import org.jboss.portal.identity.IdentityContext;
+import org.jboss.portal.identity.service.IdentityModuleService;
import org.jboss.portal.test.framework.TestRuntimeContext;
-import java.util.Set;
-import java.util.Iterator;
-
-
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @author <a href="mailto:boleslaw dot dawidowicz at jboss dot
com">Boleslaw Dawidowicz</a>
Modified:
trunk/identity/src/main/org/jboss/portal/test/identity/MembershipStrategyTest.java
===================================================================
---
trunk/identity/src/main/org/jboss/portal/test/identity/MembershipStrategyTest.java 2006-12-17
14:45:10 UTC (rev 5884)
+++
trunk/identity/src/main/org/jboss/portal/test/identity/MembershipStrategyTest.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -23,9 +23,9 @@
package org.jboss.portal.test.identity;
import junit.framework.Assert;
-import org.jboss.portal.identity2.MembershipModule;
-import org.jboss.portal.identity2.RoleModule;
-import org.jboss.portal.identity2.UserModule;
+import org.jboss.portal.identity.MembershipModule;
+import org.jboss.portal.identity.RoleModule;
+import org.jboss.portal.identity.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/UserProtoTestCase.java
===================================================================
---
trunk/identity/src/main/org/jboss/portal/test/identity/UserProtoTestCase.java 2006-12-17
14:45:10 UTC (rev 5884)
+++
trunk/identity/src/main/org/jboss/portal/test/identity/UserProtoTestCase.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -26,22 +26,12 @@
import org.apache.log4j.SimpleLayout;
import org.apache.log4j.Logger;
import org.apache.log4j.Level;
-import org.jboss.portal.identity2.IdentityContextImpl;
-import org.jboss.portal.identity2.IdentityServiceControllerImpl;
-import org.jboss.portal.identity2.IdentityContext;
-import org.jboss.portal.identity2.service.IdentityModuleService;
+import org.jboss.portal.identity.IdentityContextImpl;
import org.jboss.portal.test.framework.TestRuntimeContext;
import org.jboss.portal.test.framework.embedded.HibernateSupport;
-import org.jboss.portal.identity.Role;
-import org.jboss.portal.identity.db.RoleImpl;
-import org.jboss.portal.identity.db.UserImpl;
-import org.hibernate.SessionFactory;
import org.hibernate.Session;
-import org.hibernate.EntityMode;
import org.hibernate.Query;
-import org.hibernate.Transaction;
-import javax.naming.InitialContext;
import java.util.Map;
import java.util.HashMap;
import java.util.Set;
Modified: trunk/identity/src/main/org/jboss/portal/test/identity/UserTest.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/test/identity/UserTest.java 2006-12-17
14:45:10 UTC (rev 5884)
+++ trunk/identity/src/main/org/jboss/portal/test/identity/UserTest.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -22,12 +22,12 @@
package org.jboss.portal.test.identity;
import junit.framework.Assert;
-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.identity2.MembershipModule;
-import org.jboss.portal.identity2.UserProfileModule;
+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.identity.MembershipModule;
+import org.jboss.portal.identity.UserProfileModule;
import org.jboss.portal.identity.IdentityException;
import org.jboss.portal.common.util.CollectionBuilder;
Modified:
trunk/identity/src/main/org/jboss/portal/test/identity/db/DBIdentityTestCase.java
===================================================================
---
trunk/identity/src/main/org/jboss/portal/test/identity/db/DBIdentityTestCase.java 2006-12-17
14:45:10 UTC (rev 5884)
+++
trunk/identity/src/main/org/jboss/portal/test/identity/db/DBIdentityTestCase.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -21,22 +21,15 @@
*/
package org.jboss.portal.test.identity.db;
-import org.jboss.portal.identity2.IdentityServiceControllerImpl;
-import org.jboss.portal.identity2.IdentityContext;
-import org.jboss.portal.identity2.ProfileMap;
-import org.jboss.portal.identity2.User;
-import org.jboss.portal.identity2.service.UserModuleService;
-import org.jboss.portal.identity2.service.UserProfileModuleService;
-import org.jboss.portal.identity2.service.MembershipModuleService;
-import org.jboss.portal.identity2.service.RoleModuleService;
-import org.jboss.portal.identity2.db.HibernateUserImpl;
-import org.jboss.portal.identity2.db.HibernateUserModuleImpl;
-import org.jboss.portal.identity2.db.HibernateRoleModuleImpl;
-import org.jboss.portal.identity2.db.HibernateMembershipModuleImpl;
-import org.jboss.portal.identity2.db.HibernateUserProfileModuleImpl;
-import org.jboss.portal.identity2.config.metadata.ConfigurationParser;
-import org.jboss.portal.identity2.config.info.ProfileInfoSupport;
-import org.jboss.portal.identity2.info.ProfileInfo;
+import org.jboss.portal.identity.IdentityServiceControllerImpl;
+import org.jboss.portal.identity.IdentityContext;
+import org.jboss.portal.identity.db.HibernateUserImpl;
+import org.jboss.portal.identity.ProfileMap;
+import org.jboss.portal.identity.User;
+import org.jboss.portal.identity.service.UserModuleService;
+import org.jboss.portal.identity.service.UserProfileModuleService;
+import org.jboss.portal.identity.service.MembershipModuleService;
+import org.jboss.portal.identity.service.RoleModuleService;
import org.jboss.portal.test.identity.UserTest;
import org.jboss.portal.common.p3p.P3PConstants;
import junit.framework.TestSuite;
Modified: trunk/identity/src/main/org/jboss/portal/test/identity/db/DBTestCase.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/test/identity/db/DBTestCase.java 2006-12-17
14:45:10 UTC (rev 5884)
+++ trunk/identity/src/main/org/jboss/portal/test/identity/db/DBTestCase.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -27,16 +27,11 @@
import org.jboss.portal.test.identity.UserTest;
import org.jboss.portal.common.test.junit.POJOJUnitTest;
import org.jboss.portal.common.test.junit.JUnitAdapter;
-import org.jboss.portal.identity2.IdentityContext;
-import org.jboss.portal.identity2.DelegatingUserProfileModuleImpl;
-import org.jboss.portal.identity2.service.UserProfileModuleService;
-import org.jboss.portal.identity2.service.MembershipModuleService;
-import org.jboss.portal.identity2.service.RoleModuleService;
-import org.jboss.portal.identity2.service.UserModuleService;
-import org.jboss.portal.identity2.db.HibernateUserModuleImpl;
-import org.jboss.portal.identity2.db.HibernateRoleModuleImpl;
-import org.jboss.portal.identity2.db.HibernateMembershipModuleImpl;
-import org.jboss.portal.identity2.db.HibernateUserProfileModuleImpl;
+import org.jboss.portal.identity.IdentityContext;
+import org.jboss.portal.identity.service.UserProfileModuleService;
+import org.jboss.portal.identity.service.MembershipModuleService;
+import org.jboss.portal.identity.service.RoleModuleService;
+import org.jboss.portal.identity.service.UserModuleService;
import org.apache.log4j.Appender;
import org.apache.log4j.ConsoleAppender;
import org.apache.log4j.SimpleLayout;
Modified:
trunk/identity/src/main/org/jboss/portal/test/identity/db_old/DBUserTestCase.java
===================================================================
---
trunk/identity/src/main/org/jboss/portal/test/identity/db_old/DBUserTestCase.java 2006-12-17
14:45:10 UTC (rev 5884)
+++
trunk/identity/src/main/org/jboss/portal/test/identity/db_old/DBUserTestCase.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -33,8 +33,8 @@
import org.jboss.portal.common.p3p.P3PConstants;
import org.jboss.portal.identity.ProfileMap;
import org.jboss.portal.identity.User;
-import org.jboss.portal.identity.db.DBRoleModuleImpl;
-import org.jboss.portal.identity.db.DBUserModuleImpl;
+//import org.jboss.portal.identity.db.DBRoleModuleImpl;
+//import org.jboss.portal.identity.db.DBUserModuleImpl;
import org.jboss.portal.test.framework.TestRuntimeContext;
import org.jboss.portal.test.framework.embedded.DataSourceSupport;
import org.jboss.portal.test.framework.embedded.HibernateSupport;
@@ -50,278 +50,278 @@
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision$
*/
-public class DBUserTestCase extends junit.framework.TestCase implements UserTest.Context
+public class DBUserTestCase //extends junit.framework.TestCase implements
UserTest.Context
{
- static
- {
- Appender appender = new ConsoleAppender(new SimpleLayout());
- Logger.getRoot().addAppender(appender);
- Logger.getRoot().setLevel(Level.DEBUG);
- Logger.getLogger("org.hibernate").setLevel(Level.ERROR);
- }
-
- public static TestSuite suite() throws Exception
- {
- URL configsURL =
Thread.currentThread().getContextClassLoader().getResource("datasources.xml");
- Map parameterMap = new HashMap();
- parameterMap.put("DataSourceConfig",
DataSourceSupport.Config.fromXML2(configsURL));
- POJOJUnitTest abc = new POJOJUnitTest(DBUserTestCase.class);
- JUnitAdapter adapter = new JUnitAdapter(abc, parameterMap);
- TestSuite suite = new TestSuite();
- suite.addTest(adapter);
- return suite;
- }
-
- /** . */
- private DataSourceSupport.Config dataSourceConfigParameter;
-
- /** . */
- private TestRuntimeContext runtimeContext;
-
- /** . */
- private HibernateSupport hibernate;
-
- /** . */
- private UserTest utc;
-
- /** . */
- private DBUserModuleImpl userModule;
-
- /** . */
- private DBRoleModuleImpl roleModule;
-
- public DataSourceSupport.Config getDataSourceConfigParameter()
- {
- return dataSourceConfigParameter;
- }
-
- public void setDataSourceConfigParameter(DataSourceSupport.Config dataSourceConfig)
- {
- this.dataSourceConfigParameter = dataSourceConfig;
- }
-
- public HibernateSupport getHibernate()
- {
- return hibernate;
- }
-
- public void setHibernate(HibernateSupport hibernate)
- {
- this.hibernate = hibernate;
- }
-
- public String getName()
- {
- return super.getName() + "," + dataSourceConfigParameter.getName();
- }
-
- public void setUp() throws Exception
- {
- runtimeContext = new
TestRuntimeContext("org/jboss/portal/test/identity/db_old-beans.xml");
- runtimeContext.addBean("DBTestBean", this);
- runtimeContext.addBean("DataSourceConfig", dataSourceConfigParameter);
- runtimeContext.addBean("HibernateConfig",
HibernateSupport.getConfig(dataSourceConfigParameter.getName()));
- runtimeContext.start();
-
- //HibernateSupport.getConfig(dataSourceConfigParameter.getName()).
- //
- utc = new UserTest();
- userModule = new DBUserModuleImpl();
- userModule.setSessionFactoryJNDIName("java:/SessionFactory");
- userModule.start();
-
- //
- roleModule = new DBRoleModuleImpl();
- roleModule.setSessionFactoryJNDIName("java:/SessionFactory");
- roleModule.start();
-
- //
- utc.setUserModule(userModule);
- utc.setRoleModule(roleModule);
- utc.setContext(this);
- utc.populate();
- }
-
- public void tearDown() throws Exception
- {
- utc.setUserModule(null);
- utc.setRoleModule(null);
- utc.setContext(null);
- utc = null;
-
- //
- roleModule.destroy();
- userModule.destroy();
- roleModule = null;
- userModule = null;
-
- //
- runtimeContext.stop();
- }
-
-
- public void begin()
- {
- hibernate.openSession();
- }
-
- public void commit()
- {
- assertTrue(hibernate.commitTransaction());
- }
-
- //
-
- public void testFindUsersUsingFilter() throws Exception
- {
- utc.testFindUsersUsingFilter();
- }
-
- public void testFindUser1() throws Exception
- {
- utc.testFindUser1();
- }
-
- public void testFindUser2() throws Exception
- {
- utc.testFindUser2();
- }
-
- public void testFindUsers() throws Exception
- {
- utc.testFindUsers();
- }
-
- public void testCreateUser() throws Exception
- {
- utc.testCreateUser();
- }
-
- public void testCreateRole() throws Exception
- {
- utc.testCreateRole();
- }
-
- public void testCountUser() throws Exception
- {
- utc.testCountUser();
- }
-
- public void testRemoveNonExistingRole() throws Exception
- {
- utc.testRemoveNonExistingRole();
- }
-
- public void testRemoveRole() throws Exception
- {
- utc.testRemoveRole();
- }
-
- public void testRemoveUser() throws Exception
- {
- utc.testRemoveUser();
- }
-
- public void testFindRoles() throws Exception
- {
- utc.testFindRoles();
- }
-
- public void testFindRoleMembers() throws Exception
- {
- utc.testFindRoleMembers();
- }
-
- public void testDynamicProperty() throws Exception
- {
- begin();
- User user = userModule.createUser("testname", "testpassword",
"testemail");
- ProfileMap map = user.getProfile();
- assertNull(map.get("foo"));
- assertFalse(map.isReadOnly("foo"));
- map.put("foo", "value");
- assertEquals("value", map.get("foo"));
- assertFalse(map.isReadOnly("foo"));
- commit();
-
- begin();
- user = userModule.findUserByUserName("testname");
- map = user.getProfile();
- assertEquals("value", map.get("foo"));
- assertFalse(map.isReadOnly("foo"));
- commit();
- }
-
- public void testStaticProperty() throws Exception
- {
- begin();
-
- //
- User user = userModule.createUser("testname", "testpassword",
"testemail");
- ProfileMap map = user.getProfile();
- assertEquals("testname", map.get(P3PConstants.INFO_USER_NAME_NICKNAME));
-
- // Test cannot remove a static property
- try
- {
- map.remove(P3PConstants.INFO_USER_NAME_GIVEN);
- fail("Should not be capable to remove static property");
- }
- catch (IllegalArgumentException expected)
- {
- }
-
- // Test read only property
- assertTrue(map.isReadOnly(P3PConstants.INFO_USER_NAME_NICKNAME));
- try
- {
- map.put(P3PConstants.INFO_USER_NAME_NICKNAME, "anothername");
- fail("Should not be capable to modify a read only static property");
- }
- catch (IllegalArgumentException expected)
- {
- }
-
- // Test non nullable and writable property
- try
- {
- map.put(User.INFO_USER_VIEW_EMAIL_VIEW_REAL, null);
- fail("Should not be capable to nullify a non nullable static
property");
- }
- catch (NullPointerException expected)
- {
- }
- map.put(User.INFO_USER_VIEW_EMAIL_VIEW_REAL, "true");
- assertEquals(true, user.getViewRealEmail());
-
- // Test boolean property
- map.put(User.INFO_USER_VIEW_EMAIL_VIEW_REAL, "false");
- assertEquals("false", map.get(User.INFO_USER_VIEW_EMAIL_VIEW_REAL));
- assertEquals(false, user.getViewRealEmail());
- map.put(User.INFO_USER_VIEW_EMAIL_VIEW_REAL, "true");
- assertEquals("true", map.get(User.INFO_USER_VIEW_EMAIL_VIEW_REAL));
- assertEquals(true, user.getViewRealEmail());
- user.setViewRealEmail(false);
- assertEquals("false", map.get(User.INFO_USER_VIEW_EMAIL_VIEW_REAL));
- assertEquals(false, user.getViewRealEmail());
- user.setViewRealEmail(true);
- assertEquals("true", map.get(User.INFO_USER_VIEW_EMAIL_VIEW_REAL));
- assertEquals(true, user.getViewRealEmail());
- try
- {
- map.put(User.INFO_USER_VIEW_EMAIL_VIEW_REAL, "truee");
- fail("Should not be capable to set a bad value to boolean property");
- }
- catch (IllegalArgumentException expected)
- {
- }
-
- // Test date
- Date date = user.getRegistrationDate();
- SimpleDateFormat sdf = new SimpleDateFormat();
- assertEquals(sdf.format(date), map.get(User.INFO_USER_REGISTRATION_DATE));
-
- commit();
- }
+// static
+// {
+// Appender appender = new ConsoleAppender(new SimpleLayout());
+// Logger.getRoot().addAppender(appender);
+// Logger.getRoot().setLevel(Level.DEBUG);
+// Logger.getLogger("org.hibernate").setLevel(Level.ERROR);
+// }
+//
+// public static TestSuite suite() throws Exception
+// {
+// URL configsURL =
Thread.currentThread().getContextClassLoader().getResource("datasources.xml");
+// Map parameterMap = new HashMap();
+// parameterMap.put("DataSourceConfig",
DataSourceSupport.Config.fromXML2(configsURL));
+// POJOJUnitTest abc = new POJOJUnitTest(DBUserTestCase.class);
+// JUnitAdapter adapter = new JUnitAdapter(abc, parameterMap);
+// TestSuite suite = new TestSuite();
+// suite.addTest(adapter);
+// return suite;
+// }
+//
+// /** . */
+// private DataSourceSupport.Config dataSourceConfigParameter;
+//
+// /** . */
+// private TestRuntimeContext runtimeContext;
+//
+// /** . */
+// private HibernateSupport hibernate;
+//
+// /** . */
+// private UserTest utc;
+//
+// /** . */
+// private DBUserModuleImpl userModule;
+//
+// /** . */
+// private DBRoleModuleImpl roleModule;
+//
+// public DataSourceSupport.Config getDataSourceConfigParameter()
+// {
+// return dataSourceConfigParameter;
+// }
+//
+// public void setDataSourceConfigParameter(DataSourceSupport.Config dataSourceConfig)
+// {
+// this.dataSourceConfigParameter = dataSourceConfig;
+// }
+//
+// public HibernateSupport getHibernate()
+// {
+// return hibernate;
+// }
+//
+// public void setHibernate(HibernateSupport hibernate)
+// {
+// this.hibernate = hibernate;
+// }
+//
+// public String getName()
+// {
+// return super.getName() + "," + dataSourceConfigParameter.getName();
+// }
+//
+// public void setUp() throws Exception
+// {
+// runtimeContext = new
TestRuntimeContext("org/jboss/portal/test/identity/db_old-beans.xml");
+// runtimeContext.addBean("DBTestBean", this);
+// runtimeContext.addBean("DataSourceConfig", dataSourceConfigParameter);
+// runtimeContext.addBean("HibernateConfig",
HibernateSupport.getConfig(dataSourceConfigParameter.getName()));
+// runtimeContext.start();
+//
+// //HibernateSupport.getConfig(dataSourceConfigParameter.getName()).
+// //
+// utc = new UserTest();
+// userModule = new DBUserModuleImpl();
+// userModule.setSessionFactoryJNDIName("java:/SessionFactory");
+// userModule.start();
+//
+// //
+// roleModule = new DBRoleModuleImpl();
+// roleModule.setSessionFactoryJNDIName("java:/SessionFactory");
+// roleModule.start();
+//
+// //
+// utc.setUserModule(userModule);
+// utc.setRoleModule(roleModule);
+// utc.setContext(this);
+// utc.populate();
+// }
+//
+// public void tearDown() throws Exception
+// {
+// utc.setUserModule(null);
+// utc.setRoleModule(null);
+// utc.setContext(null);
+// utc = null;
+//
+// //
+// roleModule.destroy();
+// userModule.destroy();
+// roleModule = null;
+// userModule = null;
+//
+// //
+// runtimeContext.stop();
+// }
+//
+//
+// public void begin()
+// {
+// hibernate.openSession();
+// }
+//
+// public void commit()
+// {
+// assertTrue(hibernate.commitTransaction());
+// }
+//
+// //
+//
+// public void testFindUsersUsingFilter() throws Exception
+// {
+// utc.testFindUsersUsingFilter();
+// }
+//
+// public void testFindUser1() throws Exception
+// {
+// utc.testFindUser1();
+// }
+//
+// public void testFindUser2() throws Exception
+// {
+// utc.testFindUser2();
+// }
+//
+// public void testFindUsers() throws Exception
+// {
+// utc.testFindUsers();
+// }
+//
+// public void testCreateUser() throws Exception
+// {
+// utc.testCreateUser();
+// }
+//
+// public void testCreateRole() throws Exception
+// {
+// utc.testCreateRole();
+// }
+//
+// public void testCountUser() throws Exception
+// {
+// utc.testCountUser();
+// }
+//
+// public void testRemoveNonExistingRole() throws Exception
+// {
+// utc.testRemoveNonExistingRole();
+// }
+//
+// public void testRemoveRole() throws Exception
+// {
+// utc.testRemoveRole();
+// }
+//
+// public void testRemoveUser() throws Exception
+// {
+// utc.testRemoveUser();
+// }
+//
+// public void testFindRoles() throws Exception
+// {
+// utc.testFindRoles();
+// }
+//
+// public void testFindRoleMembers() throws Exception
+// {
+// utc.testFindRoleMembers();
+// }
+//
+// public void testDynamicProperty() throws Exception
+// {
+// begin();
+// User user = userModule.createUser("testname", "testpassword",
"testemail");
+// ProfileMap map = user.getProfile();
+// assertNull(map.get("foo"));
+// assertFalse(map.isReadOnly("foo"));
+// map.put("foo", "value");
+// assertEquals("value", map.get("foo"));
+// assertFalse(map.isReadOnly("foo"));
+// commit();
+//
+// begin();
+// user = userModule.findUserByUserName("testname");
+// map = user.getProfile();
+// assertEquals("value", map.get("foo"));
+// assertFalse(map.isReadOnly("foo"));
+// commit();
+// }
+//
+// public void testStaticProperty() throws Exception
+// {
+// begin();
+//
+// //
+// User user = userModule.createUser("testname", "testpassword",
"testemail");
+// ProfileMap map = user.getProfile();
+// assertEquals("testname",
map.get(P3PConstants.INFO_USER_NAME_NICKNAME));
+//
+// // Test cannot remove a static property
+// try
+// {
+// map.remove(P3PConstants.INFO_USER_NAME_GIVEN);
+// fail("Should not be capable to remove static property");
+// }
+// catch (IllegalArgumentException expected)
+// {
+// }
+//
+// // Test read only property
+// assertTrue(map.isReadOnly(P3PConstants.INFO_USER_NAME_NICKNAME));
+// try
+// {
+// map.put(P3PConstants.INFO_USER_NAME_NICKNAME, "anothername");
+// fail("Should not be capable to modify a read only static
property");
+// }
+// catch (IllegalArgumentException expected)
+// {
+// }
+//
+// // Test non nullable and writable property
+// try
+// {
+// map.put(User.INFO_USER_VIEW_EMAIL_VIEW_REAL, null);
+// fail("Should not be capable to nullify a non nullable static
property");
+// }
+// catch (NullPointerException expected)
+// {
+// }
+// map.put(User.INFO_USER_VIEW_EMAIL_VIEW_REAL, "true");
+// assertEquals(true, user.getViewRealEmail());
+//
+// // Test boolean property
+// map.put(User.INFO_USER_VIEW_EMAIL_VIEW_REAL, "false");
+// assertEquals("false", map.get(User.INFO_USER_VIEW_EMAIL_VIEW_REAL));
+// assertEquals(false, user.getViewRealEmail());
+// map.put(User.INFO_USER_VIEW_EMAIL_VIEW_REAL, "true");
+// assertEquals("true", map.get(User.INFO_USER_VIEW_EMAIL_VIEW_REAL));
+// assertEquals(true, user.getViewRealEmail());
+// user.setViewRealEmail(false);
+// assertEquals("false", map.get(User.INFO_USER_VIEW_EMAIL_VIEW_REAL));
+// assertEquals(false, user.getViewRealEmail());
+// user.setViewRealEmail(true);
+// assertEquals("true", map.get(User.INFO_USER_VIEW_EMAIL_VIEW_REAL));
+// assertEquals(true, user.getViewRealEmail());
+// try
+// {
+// map.put(User.INFO_USER_VIEW_EMAIL_VIEW_REAL, "truee");
+// fail("Should not be capable to set a bad value to boolean
property");
+// }
+// catch (IllegalArgumentException expected)
+// {
+// }
+//
+// // Test date
+// Date date = user.getRegistrationDate();
+// SimpleDateFormat sdf = new SimpleDateFormat();
+// assertEquals(sdf.format(date), map.get(User.INFO_USER_REGISTRATION_DATE));
+//
+// commit();
+// }
}
Modified: trunk/identity/src/main/org/jboss/portal/test/identity/db_old/UserTest.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/test/identity/db_old/UserTest.java 2006-12-17
14:45:10 UTC (rev 5884)
+++ trunk/identity/src/main/org/jboss/portal/test/identity/db_old/UserTest.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -42,352 +42,352 @@
*/
public class UserTest extends Assert
{
-
- /** . */
- private UserModule userModule;
-
- /** . */
- private RoleModule roleModule;
-
- /** . */
- private Context ctx;
-
- public void setUserModule(UserModule userModule)
- {
- this.userModule = userModule;
- }
-
- public void setRoleModule(RoleModule roleModule)
- {
- this.roleModule = roleModule;
- }
-
- public void setContext(Context ctx)
- {
- this.ctx = ctx;
- }
-
- public void testFindUsersUsingFilter() throws Exception
- {
- ctx.begin();
- Set set1 = userModule.findUsersFilteredByUserName("user", 0, 10);
- Set nameSet1 = new HashSet();
- for (Iterator i = set1.iterator(); i.hasNext();)
- {
- User user = (User)i.next();
- nameSet1.add(user.getUserName());
- }
- Set expectedNameSet1 = new HashSet();
- expectedNameSet1.add("user1");
- expectedNameSet1.add("user2");
- assertEquals(expectedNameSet1, nameSet1);
-
- //
- Set set2 = userModule.findUsersFilteredByUserName("blah", 0, 10);
- assertEquals(0, set2.size());
-
- //
- Set set3 = userModule.findUsersFilteredByUserName("", 0, 10);
- Set nameSet3 = new HashSet();
- for (Iterator i = set3.iterator(); i.hasNext();)
- {
- User user = (User)i.next();
- nameSet3.add(user.getUserName());
- }
- Set expectedNameSet3 = new HashSet();
- expectedNameSet3.add("user1");
- expectedNameSet3.add("user2");
- assertEquals(expectedNameSet3, nameSet3);
-
- //
- Set set4 = userModule.findUsersFilteredByUserName("user1", 0, 10);
- Set nameSet4 = new HashSet();
- for (Iterator i = set4.iterator(); i.hasNext();)
- {
- User user = (User)i.next();
- nameSet4.add(user.getUserName());
- }
- Set expectedNameSet4 = new HashSet();
- expectedNameSet4.add("user1");
- assertEquals(expectedNameSet4, nameSet4);
- ctx.commit();
- }
-
- public void testFindUser1() throws Exception
- {
- ctx.begin();
- User u1 = userModule.findUserByUserName("user1");
- assertNotNull(u1);
- Assert.assertEquals("user1", u1.getUserName());
- assertNotNull(roleModule.getRoles(u1));
- Assert.assertEquals(1, roleModule.getRoles(u1).size());
- Assert.assertEquals("role1",
((Role)roleModule.getRoles(u1).iterator().next()).getName());
- Assert.assertEquals(u1.getId(), userModule.findUserById(u1.getId()).getId());
- ctx.commit();
- }
-
- public void testFindUser2() throws Exception
- {
- ctx.begin();
- Set roleNames = new HashSet(Arrays.asList(new Object[]{"role1",
"role2"}));
- User u2 = userModule.findUserByUserName("user2");
- assertNotNull(u2);
- Assert.assertEquals("user2", u2.getUserName());
- assertNotNull(roleModule.getRoles(u2));
- Assert.assertEquals(2, roleModule.getRoles(u2).size());
- Iterator iterator = roleModule.getRoles(u2).iterator();
- assertTrue(roleNames.contains(((Role)iterator.next()).getName()));
- assertTrue(roleNames.contains(((Role)iterator.next()).getName()));
- Assert.assertEquals(u2.getId(), userModule.findUserById(u2.getId()).getId());
- ctx.commit();
- }
-
- public void testFindUsers() throws Exception
- {
- ctx.begin();
- Set c1 = userModule.findUsers(0, 1);
- assertNotNull(c1);
- assertEquals(1, c1.size());
-
- Set c2 = userModule.findUsers(1, 1);
- assertNotNull(c2);
- assertEquals(1, c2.size());
-
- Set c3 = userModule.findUsers(0, 2);
- assertNotNull(c3);
- assertEquals(2, c3.size());
-
- Set s1 = new HashSet();
- s1.add(((User)c1.iterator().next()).getUserName());
- s1.add(((User)c2.iterator().next()).getUserName());
- Set s2 = new HashSet();
- Iterator iterator = c3.iterator();
- s2.add(((User)iterator.next()).getUserName());
- s2.add(((User)iterator.next()).getUserName());
- assertEquals(s1, s2);
- ctx.commit();
- }
-
- public void testCreateUser() throws Exception
- {
- ctx.begin();
- User u3 = userModule.createUser("user3", "password",
"realemail");
- Role g1 = roleModule.findRoleByName("role1");
- roleModule.setRoles(u3, Collections.singleton(g1));
- Assert.assertEquals("user3", u3.getUserName());
- assertNotNull(roleModule.getRoles(u3));
- Assert.assertEquals(1, roleModule.getRoles(u3).size());
- Assert.assertEquals("role1",
((Role)roleModule.getRoles(u3).iterator().next()).getName());
- ctx.commit();
-
- ctx.begin();
- u3 = userModule.findUserByUserName("user3");
- assertNotNull(u3);
- Assert.assertEquals("user3", u3.getUserName());
- assertNotNull(roleModule.getRoles(u3));
- Assert.assertEquals(1, roleModule.getRoles(u3).size());
- Assert.assertEquals("role1",
((Role)roleModule.getRoles(u3).iterator().next()).getName());
- ctx.commit();
- }
-
- // public void testCreateDuplicateUser() throws Exception
- // {
- // try
- // {
- // userModule.createUser("user1");
- // fail("Expected exception on duplicate user");
- // }
- // catch (ModuleException expected)
- // {
- // }
- // }
-
- public void testCreateRole() throws Exception
- {
- ctx.begin();
- Role g3 = roleModule.createRole("role3", "roleName");
- Assert.assertEquals("role3", g3.getName());
- ctx.commit();
-
- ctx.begin();
- g3 = roleModule.findRoleByName("role3");
- assertNotNull(g3);
- Assert.assertEquals("role3", g3.getName());
- ctx.commit();
- }
-
- // public void testCreateDuplicateRole() throws Exception
- // {
- // try
- // {
- // roleModule.createRole("user1");
- // fail("Expected exception on duplicate role");
- // }
- // catch (ModuleException expected)
- // {
- // }
- // }
-
- public void testCountUser() throws Exception
- {
- ctx.begin();
- Assert.assertEquals(2, userModule.getUserCount());
- ctx.commit();
- }
-
- public void testRemoveNonExistingRole() throws Exception
- {
- ctx.begin();
- try
- {
- roleModule.removeRole(new Long(Long.MAX_VALUE));
- fail("Expected exception");
- }
- catch (IdentityException expected)
- {
- }
- ctx.commit();
- }
-
- public void testRemoveRole() throws Exception
- {
- ctx.begin();
- Role g1 = roleModule.findRoleByName("role1");
- Object id = g1.getId();
- roleModule.removeRole(id);
- try
- {
- roleModule.findRoleById(id);
- fail("Expected exception");
- }
- catch (IdentityException expected)
- {
- }
- ctx.commit();
-
- ctx.begin();
- try
- {
- roleModule.findRoleById(id);
- fail("Expected exception");
- }
- catch (IdentityException expected)
- {
- }
- User u1 = userModule.findUserByUserName("user1");
- assertNotNull(u1);
- Assert.assertEquals("user1", u1.getUserName());
- ctx.commit();
- }
-
- public void testRemoveUser() throws Exception
- {
- ctx.begin();
- User u1 = userModule.findUserByUserName("user1");
- Object id = u1.getId();
- userModule.removeUser(id);
- try
- {
- userModule.findUserById(id);
- fail("Expected exception");
- }
- catch (IdentityException expected)
- {
- }
- ctx.commit();
-
- ctx.begin();
- try
- {
- userModule.findUserById(id);
- fail("Expected exception");
- }
- catch (IdentityException expected)
- {
- }
- Role g1 = roleModule.findRoleByName("role1");
- assertNotNull(g1);
- Assert.assertEquals("role1", g1.getName());
- Role g2 = roleModule.findRoleByName("role2");
- assertNotNull(g2);
- Assert.assertEquals("role2", g2.getName());
- ctx.commit();
- }
-
- public void testFindRoles() throws Exception
- {
- ctx.begin();
- Set roleNames = new HashSet(Arrays.asList(new Object[]{"role1",
"role2"}));
- Set roles = roleModule.findRoles();
- assertEquals(2, roles.size());
- Iterator iterator = roles.iterator();
- assertTrue(roleNames.contains(((Role)iterator.next()).getName()));
- assertTrue(roleNames.contains(((Role)iterator.next()).getName()));
- ctx.commit();
- }
-
- public void testFindRoleMembers() throws Exception
- {
- ctx.begin();
- Set set1 = roleModule.findRoleMembers("role1", 0, 10, "user");
- Set nameSet1 = new HashSet();
- for (Iterator i = set1.iterator(); i.hasNext();)
- {
- User user = (User)i.next();
- nameSet1.add(user.getUserName());
- }
- Set expectedNameSet1 = new HashSet();
- expectedNameSet1.add("user1");
- expectedNameSet1.add("user2");
- assertEquals(expectedNameSet1, nameSet1);
-
- //
- Set set2 = roleModule.findRoleMembers("role1", 0, 10, "blah");
- assertEquals(0, set2.size());
-
- //
- Set set3 = roleModule.findRoleMembers("role1", 0, 10, "");
- Set nameSet3 = new HashSet();
- for (Iterator i = set3.iterator(); i.hasNext();)
- {
- User user = (User)i.next();
- nameSet3.add(user.getUserName());
- }
- Set expectedNameSet3 = new HashSet();
- expectedNameSet3.add("user1");
- expectedNameSet3.add("user2");
- assertEquals(expectedNameSet3, nameSet3);
-
- //
- Set set4 = roleModule.findRoleMembers("role1", 0, 10,
"user1");
- Set nameSet4 = new HashSet();
- for (Iterator i = set4.iterator(); i.hasNext();)
- {
- User user = (User)i.next();
- nameSet4.add(user.getUserName());
- }
- Set expectedNameSet4 = new HashSet();
- expectedNameSet4.add("user1");
- assertEquals(expectedNameSet4, nameSet4);
- ctx.commit();
- }
-
- public void populate() throws Exception
- {
- ctx.begin();
- User u1 = userModule.createUser("user1", "", "");
- User u2 = userModule.createUser("user2", "", "");
- Role g1 = roleModule.createRole("role1", "role1");
- Role g2 = roleModule.createRole("role2", "role2");
- roleModule.setRoles(u1, Collections.singleton(g1));
- roleModule.setRoles(u2, new CollectionBuilder().add(g1).add(g2).toHashSet());
- ctx.commit();
- }
-
- public interface Context
- {
- void begin();
-
- void commit();
- }
+//
+// /** . */
+// private UserModule userModule;
+//
+// /** . */
+// private RoleModule roleModule;
+//
+// /** . */
+// private Context ctx;
+//
+// public void setUserModule(UserModule userModule)
+// {
+// this.userModule = userModule;
+// }
+//
+// public void setRoleModule(RoleModule roleModule)
+// {
+// this.roleModule = roleModule;
+// }
+//
+// public void setContext(Context ctx)
+// {
+// this.ctx = ctx;
+// }
+//
+// public void testFindUsersUsingFilter() throws Exception
+// {
+// ctx.begin();
+// Set set1 = userModule.findUsersFilteredByUserName("user", 0, 10);
+// Set nameSet1 = new HashSet();
+// for (Iterator i = set1.iterator(); i.hasNext();)
+// {
+// User user = (User)i.next();
+// nameSet1.add(user.getUserName());
+// }
+// Set expectedNameSet1 = new HashSet();
+// expectedNameSet1.add("user1");
+// expectedNameSet1.add("user2");
+// assertEquals(expectedNameSet1, nameSet1);
+//
+// //
+// Set set2 = userModule.findUsersFilteredByUserName("blah", 0, 10);
+// assertEquals(0, set2.size());
+//
+// //
+// Set set3 = userModule.findUsersFilteredByUserName("", 0, 10);
+// Set nameSet3 = new HashSet();
+// for (Iterator i = set3.iterator(); i.hasNext();)
+// {
+// User user = (User)i.next();
+// nameSet3.add(user.getUserName());
+// }
+// Set expectedNameSet3 = new HashSet();
+// expectedNameSet3.add("user1");
+// expectedNameSet3.add("user2");
+// assertEquals(expectedNameSet3, nameSet3);
+//
+// //
+// Set set4 = userModule.findUsersFilteredByUserName("user1", 0, 10);
+// Set nameSet4 = new HashSet();
+// for (Iterator i = set4.iterator(); i.hasNext();)
+// {
+// User user = (User)i.next();
+// nameSet4.add(user.getUserName());
+// }
+// Set expectedNameSet4 = new HashSet();
+// expectedNameSet4.add("user1");
+// assertEquals(expectedNameSet4, nameSet4);
+// ctx.commit();
+// }
+//
+// public void testFindUser1() throws Exception
+// {
+// ctx.begin();
+// User u1 = userModule.findUserByUserName("user1");
+// assertNotNull(u1);
+// Assert.assertEquals("user1", u1.getUserName());
+// assertNotNull(roleModule.getRoles(u1));
+// Assert.assertEquals(1, roleModule.getRoles(u1).size());
+// Assert.assertEquals("role1",
((Role)roleModule.getRoles(u1).iterator().next()).getName());
+// Assert.assertEquals(u1.getId(), userModule.findUserById(u1.getId()).getId());
+// ctx.commit();
+// }
+//
+// public void testFindUser2() throws Exception
+// {
+// ctx.begin();
+// Set roleNames = new HashSet(Arrays.asList(new Object[]{"role1",
"role2"}));
+// User u2 = userModule.findUserByUserName("user2");
+// assertNotNull(u2);
+// Assert.assertEquals("user2", u2.getUserName());
+// assertNotNull(roleModule.getRoles(u2));
+// Assert.assertEquals(2, roleModule.getRoles(u2).size());
+// Iterator iterator = roleModule.getRoles(u2).iterator();
+// assertTrue(roleNames.contains(((Role)iterator.next()).getName()));
+// assertTrue(roleNames.contains(((Role)iterator.next()).getName()));
+// Assert.assertEquals(u2.getId(), userModule.findUserById(u2.getId()).getId());
+// ctx.commit();
+// }
+//
+// public void testFindUsers() throws Exception
+// {
+// ctx.begin();
+// Set c1 = userModule.findUsers(0, 1);
+// assertNotNull(c1);
+// assertEquals(1, c1.size());
+//
+// Set c2 = userModule.findUsers(1, 1);
+// assertNotNull(c2);
+// assertEquals(1, c2.size());
+//
+// Set c3 = userModule.findUsers(0, 2);
+// assertNotNull(c3);
+// assertEquals(2, c3.size());
+//
+// Set s1 = new HashSet();
+// s1.add(((User)c1.iterator().next()).getUserName());
+// s1.add(((User)c2.iterator().next()).getUserName());
+// Set s2 = new HashSet();
+// Iterator iterator = c3.iterator();
+// s2.add(((User)iterator.next()).getUserName());
+// s2.add(((User)iterator.next()).getUserName());
+// assertEquals(s1, s2);
+// ctx.commit();
+// }
+//
+// public void testCreateUser() throws Exception
+// {
+// ctx.begin();
+// User u3 = userModule.createUser("user3", "password",
"realemail");
+// Role g1 = roleModule.findRoleByName("role1");
+// roleModule.setRoles(u3, Collections.singleton(g1));
+// Assert.assertEquals("user3", u3.getUserName());
+// assertNotNull(roleModule.getRoles(u3));
+// Assert.assertEquals(1, roleModule.getRoles(u3).size());
+// Assert.assertEquals("role1",
((Role)roleModule.getRoles(u3).iterator().next()).getName());
+// ctx.commit();
+//
+// ctx.begin();
+// u3 = userModule.findUserByUserName("user3");
+// assertNotNull(u3);
+// Assert.assertEquals("user3", u3.getUserName());
+// assertNotNull(roleModule.getRoles(u3));
+// Assert.assertEquals(1, roleModule.getRoles(u3).size());
+// Assert.assertEquals("role1",
((Role)roleModule.getRoles(u3).iterator().next()).getName());
+// ctx.commit();
+// }
+//
+// // public void testCreateDuplicateUser() throws Exception
+// // {
+// // try
+// // {
+// // userModule.createUser("user1");
+// // fail("Expected exception on duplicate user");
+// // }
+// // catch (ModuleException expected)
+// // {
+// // }
+// // }
+//
+// public void testCreateRole() throws Exception
+// {
+// ctx.begin();
+// Role g3 = roleModule.createRole("role3", "roleName");
+// Assert.assertEquals("role3", g3.getName());
+// ctx.commit();
+//
+// ctx.begin();
+// g3 = roleModule.findRoleByName("role3");
+// assertNotNull(g3);
+// Assert.assertEquals("role3", g3.getName());
+// ctx.commit();
+// }
+//
+// // public void testCreateDuplicateRole() throws Exception
+// // {
+// // try
+// // {
+// // roleModule.createRole("user1");
+// // fail("Expected exception on duplicate role");
+// // }
+// // catch (ModuleException expected)
+// // {
+// // }
+// // }
+//
+// public void testCountUser() throws Exception
+// {
+// ctx.begin();
+// Assert.assertEquals(2, userModule.getUserCount());
+// ctx.commit();
+// }
+//
+// public void testRemoveNonExistingRole() throws Exception
+// {
+// ctx.begin();
+// try
+// {
+// roleModule.removeRole(new Long(Long.MAX_VALUE));
+// fail("Expected exception");
+// }
+// catch (IdentityException expected)
+// {
+// }
+// ctx.commit();
+// }
+//
+// public void testRemoveRole() throws Exception
+// {
+// ctx.begin();
+// Role g1 = roleModule.findRoleByName("role1");
+// Object id = g1.getId();
+// roleModule.removeRole(id);
+// try
+// {
+// roleModule.findRoleById(id);
+// fail("Expected exception");
+// }
+// catch (IdentityException expected)
+// {
+// }
+// ctx.commit();
+//
+// ctx.begin();
+// try
+// {
+// roleModule.findRoleById(id);
+// fail("Expected exception");
+// }
+// catch (IdentityException expected)
+// {
+// }
+// User u1 = userModule.findUserByUserName("user1");
+// assertNotNull(u1);
+// Assert.assertEquals("user1", u1.getUserName());
+// ctx.commit();
+// }
+//
+// public void testRemoveUser() throws Exception
+// {
+// ctx.begin();
+// User u1 = userModule.findUserByUserName("user1");
+// Object id = u1.getId();
+// userModule.removeUser(id);
+// try
+// {
+// userModule.findUserById(id);
+// fail("Expected exception");
+// }
+// catch (IdentityException expected)
+// {
+// }
+// ctx.commit();
+//
+// ctx.begin();
+// try
+// {
+// userModule.findUserById(id);
+// fail("Expected exception");
+// }
+// catch (IdentityException expected)
+// {
+// }
+// Role g1 = roleModule.findRoleByName("role1");
+// assertNotNull(g1);
+// Assert.assertEquals("role1", g1.getName());
+// Role g2 = roleModule.findRoleByName("role2");
+// assertNotNull(g2);
+// Assert.assertEquals("role2", g2.getName());
+// ctx.commit();
+// }
+//
+// public void testFindRoles() throws Exception
+// {
+// ctx.begin();
+// Set roleNames = new HashSet(Arrays.asList(new Object[]{"role1",
"role2"}));
+// Set roles = roleModule.findRoles();
+// assertEquals(2, roles.size());
+// Iterator iterator = roles.iterator();
+// assertTrue(roleNames.contains(((Role)iterator.next()).getName()));
+// assertTrue(roleNames.contains(((Role)iterator.next()).getName()));
+// ctx.commit();
+// }
+//
+// public void testFindRoleMembers() throws Exception
+// {
+// ctx.begin();
+// Set set1 = roleModule.findRoleMembers("role1", 0, 10,
"user");
+// Set nameSet1 = new HashSet();
+// for (Iterator i = set1.iterator(); i.hasNext();)
+// {
+// User user = (User)i.next();
+// nameSet1.add(user.getUserName());
+// }
+// Set expectedNameSet1 = new HashSet();
+// expectedNameSet1.add("user1");
+// expectedNameSet1.add("user2");
+// assertEquals(expectedNameSet1, nameSet1);
+//
+// //
+// Set set2 = roleModule.findRoleMembers("role1", 0, 10,
"blah");
+// assertEquals(0, set2.size());
+//
+// //
+// Set set3 = roleModule.findRoleMembers("role1", 0, 10, "");
+// Set nameSet3 = new HashSet();
+// for (Iterator i = set3.iterator(); i.hasNext();)
+// {
+// User user = (User)i.next();
+// nameSet3.add(user.getUserName());
+// }
+// Set expectedNameSet3 = new HashSet();
+// expectedNameSet3.add("user1");
+// expectedNameSet3.add("user2");
+// assertEquals(expectedNameSet3, nameSet3);
+//
+// //
+// Set set4 = roleModule.findRoleMembers("role1", 0, 10,
"user1");
+// Set nameSet4 = new HashSet();
+// for (Iterator i = set4.iterator(); i.hasNext();)
+// {
+// User user = (User)i.next();
+// nameSet4.add(user.getUserName());
+// }
+// Set expectedNameSet4 = new HashSet();
+// expectedNameSet4.add("user1");
+// assertEquals(expectedNameSet4, nameSet4);
+// ctx.commit();
+// }
+//
+// public void populate() throws Exception
+// {
+// ctx.begin();
+// User u1 = userModule.createUser("user1", "", "");
+// User u2 = userModule.createUser("user2", "", "");
+// Role g1 = roleModule.createRole("role1", "role1");
+// Role g2 = roleModule.createRole("role2", "role2");
+// roleModule.setRoles(u1, Collections.singleton(g1));
+// roleModule.setRoles(u2, new CollectionBuilder().add(g1).add(g2).toHashSet());
+// ctx.commit();
+// }
+//
+// public interface Context
+// {
+// void begin();
+//
+// void commit();
+// }
}
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-12-17
14:45:10 UTC (rev 5884)
+++
trunk/identity/src/main/org/jboss/portal/test/identity/ldap/LDAPSimpleRoleModuleTestCase.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -23,16 +23,10 @@
package org.jboss.portal.test.identity.ldap;
import junit.framework.TestSuite;
-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;
-import org.jboss.portal.identity2.IdentityContextImpl;
-import org.jboss.portal.identity2.IdentityServiceControllerImpl;
-import org.jboss.portal.identity2.UserModule;
-import org.jboss.portal.identity2.IdentityContext;
-import org.jboss.portal.identity2.config.SimpleConfigurationImpl;
-import org.jboss.portal.test.framework.TestRuntimeContext;
+import org.jboss.portal.identity.RoleModule;
+import org.jboss.portal.identity.ldap.LDAPRoleImpl;
+import org.jboss.portal.identity.IdentityContext;
+import org.jboss.portal.identity.IdentityServiceControllerImpl;
import org.jboss.portal.test.identity.ldap.LDAPTestCase;
import java.util.Set;
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-12-17
14:45:10 UTC (rev 5884)
+++
trunk/identity/src/main/org/jboss/portal/test/identity/ldap/LDAPSimpleUserModuleTestCase.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -23,15 +23,10 @@
package org.jboss.portal.test.identity.ldap;
import junit.framework.TestSuite;
-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;
-import org.jboss.portal.identity2.IdentityContextImpl;
-import org.jboss.portal.identity2.IdentityServiceControllerImpl;
-import org.jboss.portal.identity2.IdentityContext;
-import org.jboss.portal.identity2.config.SimpleConfigurationImpl;
-import org.jboss.portal.test.framework.TestRuntimeContext;
+import org.jboss.portal.identity.UserModule;
+import org.jboss.portal.identity.ldap.LDAPUserImpl;
+import org.jboss.portal.identity.IdentityServiceControllerImpl;
+import org.jboss.portal.identity.IdentityContext;
import org.jboss.portal.test.identity.ldap.LDAPTestCase;
/**
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-12-17
14:45:10 UTC (rev 5884)
+++
trunk/identity/src/main/org/jboss/portal/test/identity/ldap/LDAPStaticGroupMembershipModuleTestCase.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -23,24 +23,14 @@
package org.jboss.portal.test.identity.ldap;
import junit.framework.TestSuite;
-import org.jboss.portal.test.framework.TestRuntimeContext;
import org.jboss.portal.test.identity.ldap.LDAPMembershipModuleTestCase;
-import org.jboss.portal.identity2.IdentityContextImpl;
-import org.jboss.portal.identity2.MembershipModule;
-import org.jboss.portal.identity2.config.SimpleConfigurationImpl;
-import org.jboss.portal.identity2.ldap.LDAPConnectionContext;
-import org.jboss.portal.identity2.ldap.LDAPUserModuleImpl;
-import org.jboss.portal.identity2.ldap.LDAPRoleModuleImpl;
-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.identity2.UserModule;
-import org.jboss.portal.identity2.RoleModule;
-import org.jboss.portal.identity2.User;
-import org.jboss.portal.identity2.Role;
-import org.jboss.portal.identity2.IdentityServiceControllerImpl;
-import org.jboss.portal.identity2.IdentityContext;
-import org.jboss.portal.common.util.Tools;
+import org.jboss.portal.identity.MembershipModule;
+import org.jboss.portal.identity.ldap.LDAPRoleImpl;
+import org.jboss.portal.identity.ldap.LDAPUserImpl;
+import org.jboss.portal.identity.IdentityContext;
+import org.jboss.portal.identity.UserModule;
+import org.jboss.portal.identity.RoleModule;
+import org.jboss.portal.identity.IdentityServiceControllerImpl;
import java.util.Set;
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-12-17
14:45:10 UTC (rev 5884)
+++
trunk/identity/src/main/org/jboss/portal/test/identity/ldap/LDAPStaticRoleMembershipModuleTestCase.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -22,22 +22,16 @@
package org.jboss.portal.test.identity.ldap;
import junit.framework.TestSuite;
-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;
-import org.jboss.portal.identity2.IdentityServiceControllerImpl;
-import org.jboss.portal.identity2.IdentityContext;
-import org.jboss.portal.identity2.service.MembershipModuleService;
-import org.jboss.portal.identity2.ldap.LDAPConnectionContext;
-import org.jboss.portal.identity2.ldap.LDAPUserModuleImpl;
-import org.jboss.portal.identity2.ldap.LDAPRoleModuleImpl;
-import org.jboss.portal.identity2.ldap.LDAPRoleImpl;
-import org.jboss.portal.identity2.ldap.LDAPUserImpl;
-import org.jboss.portal.identity2.ldap.LDAPStaticRoleMembershipModuleImpl;
-import org.jboss.portal.identity2.config.SimpleConfigurationImpl;
-import org.jboss.portal.test.framework.TestRuntimeContext;
+import org.jboss.portal.identity.UserModule;
+import org.jboss.portal.identity.RoleModule;
+import org.jboss.portal.identity.MembershipModule;
+import org.jboss.portal.identity.IdentityConfiguration;
+import org.jboss.portal.identity.IdentityContext;
+import org.jboss.portal.identity.IdentityServiceControllerImpl;
+import org.jboss.portal.identity.service.MembershipModuleService;
+import org.jboss.portal.identity.ldap.LDAPRoleImpl;
+import org.jboss.portal.identity.ldap.LDAPUserImpl;
+import org.jboss.portal.identity.ldap.LDAPStaticRoleMembershipModuleImpl;
import java.util.Set;
@@ -97,7 +91,7 @@
configuration.setValues(IdentityConfiguration.GROUP_COMMON,IdentityConfiguration.ROLE_CONTAINER_DN,
values);
values = new HashSet();
values.add("ou=People,o=example2,dc=testsuite,dc=portal,dc=qa,dc=atl,dc=jboss,dc=com");
-
configuration.setValues(IdentityConfiguration.GROUP_COMMON,IdentityConfiguration.USER_CONTAINER_DN,
values);
+ configuration.setValues(IdentityConfiguration.GROUP_COMMON,
IdentityConfiguration.USER_CONTAINER_DN, values);
values = new HashSet();
values.add("memberOf");
configuration.setValues(IdentityConfiguration.GROUP_COMMON,IdentityConfiguration.MEMBERSHIP_ATTRIBUTE_ID,
values);
Modified: trunk/identity/src/main/org/jboss/portal/test/identity/ldap/LDAPTestCase.java
===================================================================
---
trunk/identity/src/main/org/jboss/portal/test/identity/ldap/LDAPTestCase.java 2006-12-17
14:45:10 UTC (rev 5884)
+++
trunk/identity/src/main/org/jboss/portal/test/identity/ldap/LDAPTestCase.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -28,7 +28,7 @@
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.log4j.SimpleLayout;
-import org.jboss.portal.identity2.IdentityContext;
+import org.jboss.portal.identity.IdentityContext;
import org.jboss.portal.test.framework.TestRuntimeContext;
import org.jboss.portal.test.framework.embedded.DSConfig;
import org.jboss.portal.test.framework.embedded.DataSourceSupport;
Modified:
trunk/identity/src/main/org/jboss/portal/test/identity/ldap/LDAPUserProfileModuleTestCase.java
===================================================================
---
trunk/identity/src/main/org/jboss/portal/test/identity/ldap/LDAPUserProfileModuleTestCase.java 2006-12-17
14:45:10 UTC (rev 5884)
+++
trunk/identity/src/main/org/jboss/portal/test/identity/ldap/LDAPUserProfileModuleTestCase.java 2006-12-17
14:52:15 UTC (rev 5885)
@@ -22,22 +22,15 @@
package org.jboss.portal.test.identity.ldap;
import junit.framework.TestSuite;
-import org.jboss.portal.identity2.UserModule;
-import org.jboss.portal.identity2.RoleModule;
-import org.jboss.portal.identity2.MembershipModule;
-import org.jboss.portal.identity2.IdentityServiceControllerImpl;
-import org.jboss.portal.identity2.IdentityContext;
-import org.jboss.portal.identity2.UserProfileModule;
-import org.jboss.portal.identity2.User;
-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.MembershipModule;
+import org.jboss.portal.identity.IdentityServiceControllerImpl;
+import org.jboss.portal.identity.IdentityContext;
+import org.jboss.portal.identity.UserProfileModule;
+import org.jboss.portal.identity.User;
+import org.jboss.portal.identity.ldap.LDAPUserImpl;
-import java.util.Set;
-import java.util.List;
-import java.util.LinkedList;
-import java.util.Iterator;
-import java.util.HashSet;
-
/**
* @author <a href="mailto:boleslaw.dawidowicz@jboss.org">Boleslaw
Dawidowicz</a>
* @version $Revision: 1.1 $
Modified: trunk/identity/src/resources/hibernate/domain-identity.hbm.xml
===================================================================
--- trunk/identity/src/resources/hibernate/domain-identity.hbm.xml 2006-12-17 14:45:10 UTC
(rev 5884)
+++ trunk/identity/src/resources/hibernate/domain-identity.hbm.xml 2006-12-17 14:52:15 UTC
(rev 5885)
@@ -27,7 +27,7 @@
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class
- name="org.jboss.portal.identity2.db.HibernateUserImpl"
+ name="org.jboss.portal.identity.db.HibernateUserImpl"
table="jbp_users">
<!--<cache usage="@portal.hibernate.cache.usage(a)"/>-->
<id
@@ -128,13 +128,13 @@
<!--<cache usage="@portal.hibernate.cache.usage(a)"/>-->
<key column="jbp_uid"/>
<many-to-many
- class="org.jboss.portal.identity2.db.HibernateRoleImpl"
+ class="org.jboss.portal.identity.db.HibernateRoleImpl"
column="jbp_rid"
outer-join="true"/>
</set>
</class>
<class
- name="org.jboss.portal.identity2.db.HibernateRoleImpl"
+ name="org.jboss.portal.identity.db.HibernateRoleImpl"
table="jbp_roles">
<!--<cache usage="@portal.hibernate.cache.usage(a)"/>-->
<id
@@ -169,7 +169,7 @@
<!--<cache usage="@portal.hibernate.cache.usage(a)"/>-->
<key column="jbp_rid"/>
<many-to-many
- class="org.jboss.portal.identity2.db.HibernateUserImpl"
+ class="org.jboss.portal.identity.db.HibernateUserImpl"
column="jbp_uid"
outer-join="false"/>
</set>
Modified: trunk/identity/src/resources/hibernate/domain.hbm.xml
===================================================================
--- trunk/identity/src/resources/hibernate/domain.hbm.xml 2006-12-17 14:45:10 UTC (rev
5884)
+++ trunk/identity/src/resources/hibernate/domain.hbm.xml 2006-12-17 14:52:15 UTC (rev
5885)
@@ -27,7 +27,7 @@
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class
- name="org.jboss.portal.identity.db.UserImpl"
+ name="org.jboss.portal.identity.db.HibernateUserImpl"
table="jbp_users">
<cache usage="@portal.hibernate.cache.usage(a)"/>
<id
@@ -128,13 +128,13 @@
<cache usage="@portal.hibernate.cache.usage(a)"/>
<key column="jbp_uid"/>
<many-to-many
- class="org.jboss.portal.identity.db.RoleImpl"
+ class="org.jboss.portal.identity.db.HibernateRoleImpl"
column="jbp_rid"
outer-join="true"/>
</set>
</class>
<class
- name="org.jboss.portal.identity.db.RoleImpl"
+ name="org.jboss.portal.identity.db.HibernateRoleImpl"
table="jbp_roles">
<cache usage="@portal.hibernate.cache.usage(a)"/>
<id
@@ -169,7 +169,7 @@
<cache usage="@portal.hibernate.cache.usage(a)"/>
<key column="jbp_rid"/>
<many-to-many
- class="org.jboss.portal.identity.db.UserImpl"
+ class="org.jboss.portal.identity.db.HibernateUserImpl"
column="jbp_uid"
outer-join="false"/>
</set>
Modified: trunk/identity/src/resources/test/config/standardidentity-config.xml
===================================================================
--- trunk/identity/src/resources/test/config/standardidentity-config.xml 2006-12-17
14:45:10 UTC (rev 5884)
+++ trunk/identity/src/resources/test/config/standardidentity-config.xml 2006-12-17
14:52:15 UTC (rev 5885)
@@ -33,7 +33,7 @@
<name>LDAP</name>
<!--name of service and class for creating mbean-->
<service-name>portal:service=Module,type=LDAPConnectionContext</service-name>
-
<class>org.jboss.portal.identity2.ldap.LDAPConnectionContext</class>
+ <class>org.jboss.portal.identity.ldap.LDAPConnectionContext</class>
<config>
<option>
<name>host</name>
@@ -110,7 +110,7 @@
<!--name of service and class for creating mbean-->
<service-name>portal:service=Module,type=UserProfile</service-name>
-
<class>org.jboss.portal.identity2.DelegatingUserProfileModuleImpl</class>
+
<class>org.jboss.portal.identity.DelegatingUserProfileModuleImpl</class>
<!--set of options that are passed to a class constructor-->
<config>
<option>
@@ -133,7 +133,7 @@
<!--name of service and class for creating mbean-->
<service-name>portal:service=Module,type=User</service-name>
-
<class>org.jboss.portal.identity2.db.HibernateUserModuleImpl</class>
+ <class>org.jboss.portal.identity.db.HibernateUserModuleImpl</class>
<!--set of options that are passed to a class constructor-->
<config>
@@ -155,7 +155,7 @@
<!--name of service and class for creating mbean-->
<service-name>portal:service=Module,type=Role</service-name>
-
<class>org.jboss.portal.identity2.db.HibernateRoleModuleImpl</class>
+ <class>org.jboss.portal.identity.db.HibernateRoleModuleImpl</class>
<!--set of options that are passed to a class constructor-->
<config>
@@ -177,7 +177,7 @@
<!--name of service and class for creating mbean-->
<service-name>portal:service=Module,type=Membership</service-name>
-
<class>org.jboss.portal.identity2.db.HibernateMembershipModuleImpl</class>
+
<class>org.jboss.portal.identity.db.HibernateMembershipModuleImpl</class>
<!--set of options that are passed to a class constructor-->
<config>
@@ -199,7 +199,7 @@
<!--name of service and class for creating mbean-->
<service-name>portal:service=Module,type=DBUserProfile</service-name>
-
<class>org.jboss.portal.identity2.db.HibernateUserProfileModuleImpl</class>
+
<class>org.jboss.portal.identity.db.HibernateUserProfileModuleImpl</class>
<!--set of options that are passed to a class constructor-->
<config>
@@ -222,7 +222,7 @@
<!--name of service and class for creating mbean-->
<service-name>portal:service=Module,type=User</service-name>
- <class>org.jboss.portal.identity2.ldap.LDAPUserModuleImpl</class>
+ <class>org.jboss.portal.identity.ldap.LDAPUserModuleImpl</class>
<!--set of options that are passed to a class constructor-->
<config>
@@ -244,7 +244,7 @@
<!--name of service and class for creating mbean-->
<service-name>portal:service=Module,type=Role</service-name>
- <class>org.jboss.portal.identity2.ldap.LDAPRoleModuleImpl</class>
+ <class>org.jboss.portal.identity.ldap.LDAPRoleModuleImpl</class>
<!--set of options that are passed to a class constructor-->
<config>
@@ -266,7 +266,7 @@
<!--name of service and class for creating mbean-->
<service-name>portal:service=Module,type=Membership</service-name>
-
<class>org.jboss.portal.identity2.ldap.LDAPStaticGroupMembershipModuleImpl</class>
+
<class>org.jboss.portal.identity.ldap.LDAPStaticGroupMembershipModuleImpl</class>
<!--set of options that are passed to a class constructor-->
<config>
@@ -288,7 +288,7 @@
<!--name of service and class for creating mbean-->
<service-name>portal:service=Module,type=LDAPUserProfile</service-name>
-
<class>org.jboss.portal.identity2.ldap.LDAPUserProfileModuleImpl</class>
+
<class>org.jboss.portal.identity.ldap.LDAPUserProfileModuleImpl</class>
<!--set of options that are passed to a class constructor-->
<config>