JBoss Portal SVN: r5837 - trunk/identity/src/main/org/jboss/portal/test/identity/db
by portal-commits@lists.jboss.org
Author: bdaw
Date: 2006-12-13 10:34:31 -0500 (Wed, 13 Dec 2006)
New Revision: 5837
Removed:
trunk/identity/src/main/org/jboss/portal/test/identity/db/DBUserTestCase.java
Log:
cleanup
Deleted: trunk/identity/src/main/org/jboss/portal/test/identity/db/DBUserTestCase.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/test/identity/db/DBUserTestCase.java 2006-12-13 15:28:19 UTC (rev 5836)
+++ trunk/identity/src/main/org/jboss/portal/test/identity/db/DBUserTestCase.java 2006-12-13 15:34:31 UTC (rev 5837)
@@ -1,326 +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.test.identity.db;
-
-import junit.framework.TestSuite;
-import org.apache.log4j.Appender;
-import org.apache.log4j.ConsoleAppender;
-import org.apache.log4j.Level;
-import org.apache.log4j.Logger;
-import org.apache.log4j.SimpleLayout;
-import org.jboss.portal.common.test.junit.POJOJUnitTest;
-import org.jboss.portal.common.test.junit.JUnitAdapter;
-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.test.framework.TestRuntimeContext;
-import org.jboss.portal.test.framework.embedded.DataSourceSupport;
-import org.jboss.portal.test.framework.embedded.HibernateSupport;
-import org.jboss.portal.test.identity.UserTest;
-
-import java.net.URL;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.Map;
-import java.util.HashMap;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision$
- */
-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-beans.xml");
- runtimeContext.addBean("DBTestBean", this);
- runtimeContext.addBean("DataSourceConfig", dataSourceConfigParameter);
- runtimeContext.addBean("HibernateConfig", HibernateSupport.getConfig(dataSourceConfigParameter.getName()));
- runtimeContext.start();
-
- //
- 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();
- }
-}
19 years, 7 months
JBoss Portal SVN: r5836 - trunk/identity/src/main/org/jboss/portal/test/identity/db
by portal-commits@lists.jboss.org
Author: bdaw
Date: 2006-12-13 10:28:19 -0500 (Wed, 13 Dec 2006)
New Revision: 5836
Added:
trunk/identity/src/main/org/jboss/portal/test/identity/db/DBIdentityTestCase.java
Log:
cleanup
Copied: trunk/identity/src/main/org/jboss/portal/test/identity/db/DBIdentityTestCase.java (from rev 5770, trunk/identity/src/main/org/jboss/portal/test/identity/db/DBUserTestCase.java)
===================================================================
--- trunk/identity/src/main/org/jboss/portal/test/identity/db/DBUserTestCase.java 2006-12-06 09:43:49 UTC (rev 5770)
+++ trunk/identity/src/main/org/jboss/portal/test/identity/db/DBIdentityTestCase.java 2006-12-13 15:28:19 UTC (rev 5836)
@@ -0,0 +1,261 @@
+/*
+* 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.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.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.test.identity.UserTest;
+import org.jboss.portal.common.p3p.P3PConstants;
+import junit.framework.TestSuite;
+
+import java.util.Date;
+import java.text.SimpleDateFormat;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision$
+ */
+public class DBIdentityTestCase extends DBTestCase
+{
+
+ public static TestSuite suite() throws Exception
+ {
+ System.out.println("###");
+ return createTestSuite(DBIdentityTestCase.class);
+ }
+
+ public void setUp() throws Exception
+ {
+
+ //generate hibernate mappings based on the profile file
+// ProfileInfo info = new ProfileInfoSupport(ConfigurationParser.parseProfileConfiguration("test/config/profile-config.xml"));
+// String pattern = "<property name=\"@name@\" column=\"@column@\" type=\"java.lang.String\" update=\"true\" insert=\"true\" unique=\"false\"/>";
+// HibernateHelper.generateProfileMappings("hibernate/domain-template-single.hbm.xml",
+// "resources/hibernate/domain-identity.hbm.xml",
+// pattern,
+// info,
+// Thread.currentThread().getContextClassLoader());
+
+
+
+ //initialize microcontainer stuff
+ super.setUp();
+
+
+ //bootstrap identity modules
+ IdentityServiceControllerImpl controller = new IdentityServiceControllerImpl();
+ controller.setConfigFile("test/config/db-config.xml");
+ controller.setDefaultConfigFile("test/config/standardidentity-config.xml");
+ controller.setRegisterMBeans(false);
+ controller.start();
+ identityContext = controller.getIdentityContext();
+ this.userModule = (HibernateUserModuleImpl)identityContext.getObject(IdentityContext.TYPE_USER_MODULE);
+ this.roleModule = (HibernateRoleModuleImpl)identityContext.getObject(IdentityContext.TYPE_ROLE_MODULE);
+ this.membershipModule = (HibernateMembershipModuleImpl)identityContext.getObject(IdentityContext.TYPE_MEMBERSHIP_MODULE);
+ this.userProfileModule = (HibernateUserProfileModuleImpl)identityContext.getObject(IdentityContext.TYPE_USER_PROFILE_MODULE);
+
+ //
+ utc = new UserTest();
+ utc.setUserModule(userModule);
+ utc.setRoleModule(roleModule);
+ utc.setMembershipModule(membershipModule);
+ utc.setContext(this);
+ utc.populate();
+ }
+
+
+
+
+
+
+ public void testWorking() throws Exception
+ {
+
+ }
+
+ //
+
+ 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");
+ ProfileMap map = ((HibernateUserImpl)user).getProfileMap();
+ 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 = ((HibernateUserImpl)user).getProfileMap();
+ assertEquals("value", map.get("foo"));
+ assertFalse(map.isReadOnly("foo"));
+ commit();
+ }
+
+ public void testStaticProperty() throws Exception
+ {
+ begin();
+
+ //
+ User user = userModule.createUser("testname", "testpassword");
+ ProfileMap map = ((HibernateUserImpl)user).getProfileMap();
+ 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", userProfileModule.getProperty(user, User.INFO_USER_VIEW_EMAIL_VIEW_REAL));
+
+ // 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", userProfileModule.getProperty(user, User.INFO_USER_VIEW_EMAIL_VIEW_REAL));
+
+ map.put(User.INFO_USER_VIEW_EMAIL_VIEW_REAL, "true");
+ assertEquals("true", map.get(User.INFO_USER_VIEW_EMAIL_VIEW_REAL));
+ assertEquals("true", userProfileModule.getProperty(user, User.INFO_USER_VIEW_EMAIL_VIEW_REAL));
+
+ userProfileModule.setProperty(user, User.INFO_USER_VIEW_EMAIL_VIEW_REAL, "false");
+ assertEquals("false", map.get(User.INFO_USER_VIEW_EMAIL_VIEW_REAL));
+ assertEquals("false", userProfileModule.getProperty(user, User.INFO_USER_VIEW_EMAIL_VIEW_REAL));
+
+ userProfileModule.setProperty(user, User.INFO_USER_VIEW_EMAIL_VIEW_REAL, "true");
+ assertEquals("true", map.get(User.INFO_USER_VIEW_EMAIL_VIEW_REAL));
+ assertEquals("true", userProfileModule.getProperty(user, User.INFO_USER_VIEW_EMAIL_VIEW_REAL));
+ 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 = ((HibernateUserImpl)user).getRegistrationDate();
+ SimpleDateFormat sdf = new SimpleDateFormat();
+ assertEquals(sdf.format(date), map.get(User.INFO_USER_REGISTRATION_DATE));
+
+ commit();
+ }
+}
Property changes on: trunk/identity/src/main/org/jboss/portal/test/identity/db/DBIdentityTestCase.java
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
19 years, 7 months
JBoss Portal SVN: r5835 - in trunk/identity/src/main/org/jboss/portal/identity2: . db
by portal-commits@lists.jboss.org
Author: bdaw
Date: 2006-12-13 10:23:19 -0500 (Wed, 13 Dec 2006)
New Revision: 5835
Added:
trunk/identity/src/main/org/jboss/portal/identity2/db/
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
Log:
refactored hibernate implementation of identity modules
Added: trunk/identity/src/main/org/jboss/portal/identity2/db/HibernateMembershipModuleImpl.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/db/HibernateMembershipModuleImpl.java 2006-12-13 15:22:51 UTC (rev 5834)
+++ trunk/identity/src/main/org/jboss/portal/identity2/db/HibernateMembershipModuleImpl.java 2006-12-13 15:23:19 UTC (rev 5835)
@@ -0,0 +1,254 @@
+/*
+* 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();
+ }
+}
Added: trunk/identity/src/main/org/jboss/portal/identity2/db/HibernateRoleImpl.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/db/HibernateRoleImpl.java 2006-12-13 15:22:51 UTC (rev 5834)
+++ trunk/identity/src/main/org/jboss/portal/identity2/db/HibernateRoleImpl.java 2006-12-13 15:23:19 UTC (rev 5835)
@@ -0,0 +1,149 @@
+/*
+* 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 + "]";
+ }
+}
Added: trunk/identity/src/main/org/jboss/portal/identity2/db/HibernateRoleModuleImpl.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/db/HibernateRoleModuleImpl.java 2006-12-13 15:22:51 UTC (rev 5834)
+++ trunk/identity/src/main/org/jboss/portal/identity2/db/HibernateRoleModuleImpl.java 2006-12-13 15:23:19 UTC (rev 5835)
@@ -0,0 +1,393 @@
+/*
+* 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();
+ }
+}
Added: trunk/identity/src/main/org/jboss/portal/identity2/db/HibernateUserImpl.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/db/HibernateUserImpl.java 2006-12-13 15:22:51 UTC (rev 5834)
+++ trunk/identity/src/main/org/jboss/portal/identity2/db/HibernateUserImpl.java 2006-12-13 15:23:19 UTC (rev 5835)
@@ -0,0 +1,538 @@
+/*
+* 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);
+ }
+ }
+}
Added: trunk/identity/src/main/org/jboss/portal/identity2/db/HibernateUserModuleImpl.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/db/HibernateUserModuleImpl.java 2006-12-13 15:22:51 UTC (rev 5834)
+++ trunk/identity/src/main/org/jboss/portal/identity2/db/HibernateUserModuleImpl.java 2006-12-13 15:23:19 UTC (rev 5835)
@@ -0,0 +1,291 @@
+/*
+* 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();
+ }
+}
Added: trunk/identity/src/main/org/jboss/portal/identity2/db/HibernateUserProfileModuleImpl.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/db/HibernateUserProfileModuleImpl.java 2006-12-13 15:22:51 UTC (rev 5834)
+++ trunk/identity/src/main/org/jboss/portal/identity2/db/HibernateUserProfileModuleImpl.java 2006-12-13 15:23:19 UTC (rev 5835)
@@ -0,0 +1,280 @@
+/*
+* 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;
+
+ 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());
+ session = getCurrentSession();
+ session.save(user);
+ 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
+ {
+ ProfileInfo profileInfo = super.getProfileInfo();
+ if (profileInfo != null)
+ {
+ return profileInfo;
+ }
+ else
+ {
+ //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;
+ }
+}
Added: trunk/identity/src/main/org/jboss/portal/identity2/db/ProfileMapImpl.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/db/ProfileMapImpl.java 2006-12-13 15:22:51 UTC (rev 5834)
+++ trunk/identity/src/main/org/jboss/portal/identity2/db/ProfileMapImpl.java 2006-12-13 15:23:19 UTC (rev 5835)
@@ -0,0 +1,275 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.portal.identity2.db;
+
+import org.jboss.portal.identity2.ProfileMap;
+import org.jboss.portal.identity2.db.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);
+ }
+ }
+ }
+ }
+}
19 years, 7 months
JBoss Portal SVN: r5833 - trunk/identity/src/main/org/jboss/portal/identity2/service
by portal-commits@lists.jboss.org
Author: bdaw
Date: 2006-12-13 10:21:26 -0500 (Wed, 13 Dec 2006)
New Revision: 5833
Modified:
trunk/identity/src/main/org/jboss/portal/identity2/service/UserProfileModuleService.java
Log:
identity ldap modules improvements
Modified: trunk/identity/src/main/org/jboss/portal/identity2/service/UserProfileModuleService.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/service/UserProfileModuleService.java 2006-12-13 15:20:01 UTC (rev 5832)
+++ trunk/identity/src/main/org/jboss/portal/identity2/service/UserProfileModuleService.java 2006-12-13 15:21:26 UTC (rev 5833)
@@ -27,6 +27,9 @@
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;
@@ -38,11 +41,49 @@
{
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;
+ }
}
19 years, 7 months
JBoss Portal SVN: r5832 - trunk/identity/src/main/org/jboss/portal/identity2/ldap
by portal-commits@lists.jboss.org
Author: bdaw
Date: 2006-12-13 10:20:01 -0500 (Wed, 13 Dec 2006)
New Revision: 5832
Modified:
trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPMembershipModule.java
trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPRoleImpl.java
trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPRoleModule.java
trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPUserImpl.java
trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPUserModule.java
trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPUserModuleImpl.java
trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPUserProfileModule.java
trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPUserProfileModuleImpl.java
Log:
identity ldap modules improvements
Modified: trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPMembershipModule.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPMembershipModule.java 2006-12-13 15:16:44 UTC (rev 5831)
+++ trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPMembershipModule.java 2006-12-13 15:20:01 UTC (rev 5832)
@@ -44,6 +44,11 @@
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.
Modified: trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPRoleImpl.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPRoleImpl.java 2006-12-13 15:16:44 UTC (rev 5831)
+++ trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPRoleImpl.java 2006-12-13 15:20:01 UTC (rev 5832)
@@ -37,6 +37,8 @@
{
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;
@@ -96,19 +98,19 @@
}
//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;
- }
+// 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;
+// }
//**************************
Modified: trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPRoleModule.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPRoleModule.java 2006-12-13 15:16:44 UTC (rev 5831)
+++ trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPRoleModule.java 2006-12-13 15:20:01 UTC (rev 5832)
@@ -47,6 +47,11 @@
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.
Modified: trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPUserImpl.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPUserImpl.java 2006-12-13 15:16:44 UTC (rev 5831)
+++ trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPUserImpl.java 2006-12-13 15:20:01 UTC (rev 5832)
@@ -39,6 +39,8 @@
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;
@@ -140,11 +142,15 @@
}
}
- public ProfileMap getProfile()
+ public String getPassword()
{
- throw new UnsupportedOperationException("Not yet implemented");
+ return this.password;
}
+ public void setPassword(String password)
+ {
+ this.password = password;
+ }
//**************************
//*** Getter and Setters
Modified: trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPUserModule.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPUserModule.java 2006-12-13 15:16:44 UTC (rev 5831)
+++ trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPUserModule.java 2006-12-13 15:20:01 UTC (rev 5832)
@@ -54,6 +54,11 @@
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.
Modified: trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPUserModuleImpl.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPUserModuleImpl.java 2006-12-13 15:16:44 UTC (rev 5831)
+++ trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPUserModuleImpl.java 2006-12-13 15:20:01 UTC (rev 5832)
@@ -121,17 +121,17 @@
- public User createUser(String userName, String password, String realEmail) throws IdentityException, IllegalArgumentException
+ public User createUser(String userName, String password) throws IdentityException, IllegalArgumentException
{
if (userName == null)
{
throw new IdentityException("User name cannot be null");
}
- if (realEmail == null)
+ /*if (realEmail == null)
{
throw new IdentityException("User email cannot be null");
- }
+ }*/
if (password == null)
{
throw new IdentityException("User password cannot be null");
Modified: trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPUserProfileModule.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPUserProfileModule.java 2006-12-13 15:16:44 UTC (rev 5831)
+++ trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPUserProfileModule.java 2006-12-13 15:20:01 UTC (rev 5832)
@@ -37,6 +37,10 @@
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.
Modified: trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPUserProfileModuleImpl.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPUserProfileModuleImpl.java 2006-12-13 15:16:44 UTC (rev 5831)
+++ trunk/identity/src/main/org/jboss/portal/identity2/ldap/LDAPUserProfileModuleImpl.java 2006-12-13 15:20:01 UTC (rev 5832)
@@ -23,6 +23,10 @@
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;
@@ -202,7 +206,21 @@
private String resolveAttributeName(String propertyName) throws IdentityException
{
- return getIdentityConfiguration().getValue(IdentityConfiguration.GROUP_USER_PROFILE_MAPPINGS, propertyName);
+ //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;
}
/**
@@ -212,26 +230,52 @@
*/
private Map resolveAttributesMappingMap() throws IdentityException
{
- Map group = getIdentityConfiguration().getOptions(IdentityConfiguration.GROUP_USER_PROFILE_MAPPINGS);
+ //Map group = getIdentityConfiguration().getOptions(IdentityConfiguration.GROUP_USER_PROFILE_MAPPINGS);
- if (group == null)
- {
- throw new IdentityException("User profile attributes mappings not found in the configuration");
- }
+ Map infos = getProfileInfo().getPropertiesInfo();
+ Set keys = infos.keySet();
+
Map mappings = new HashMap();
- Set options = group.keySet();
- for (Iterator iterator = options.iterator(); iterator.hasNext();)
+ for (Iterator iterator = keys.iterator(); iterator.hasNext();)
{
- String optname = (String)iterator.next();
- Set values = (Set)group.get(optname);
- if (values.size() > 0)
+ String key = (String)iterator.next();
+ PropertyInfo prop = (PropertyInfo)infos.get(key);
+ if (prop.isMappedLDAP())
{
- mappings.put(optname, values.toArray()[0]);
+ 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
+ {
+ ProfileInfo profileInfo = super.getProfileInfo();
+ if (profileInfo == null)
+ {
+ return profileInfo;
+ }
+ else
+ {
+ //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;
+ }
+ }
+ }
+
}
19 years, 7 months
JBoss Portal SVN: r5831 - trunk/identity/src/main/org/jboss/portal/identity2
by portal-commits@lists.jboss.org
Author: bdaw
Date: 2006-12-13 10:16:44 -0500 (Wed, 13 Dec 2006)
New Revision: 5831
Modified:
trunk/identity/src/main/org/jboss/portal/identity2/IdentityContextImpl.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/Role.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
Log:
identity interfaces updates
Modified: trunk/identity/src/main/org/jboss/portal/identity2/IdentityContextImpl.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/IdentityContextImpl.java 2006-12-13 15:14:50 UTC (rev 5830)
+++ trunk/identity/src/main/org/jboss/portal/identity2/IdentityContextImpl.java 2006-12-13 15:16:44 UTC (rev 5831)
@@ -35,6 +35,8 @@
*/
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()
@@ -59,6 +61,7 @@
{
throw new IdentityException("Name: " + name + " already registered.");
}
+ if (log.isDebugEnabled()) log.debug("registering object: " + name + " ; " + object.getClass());
registry.put(name, object);
}
}
@@ -73,6 +76,8 @@
{
if(registry.containsKey(name))
{
+ if (log.isDebugEnabled()) log.debug("unregistering object: " + name);
+
registry.remove(name);
}
}
Modified: trunk/identity/src/main/org/jboss/portal/identity2/IdentityServiceControllerImpl.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/IdentityServiceControllerImpl.java 2006-12-13 15:14:50 UTC (rev 5830)
+++ trunk/identity/src/main/org/jboss/portal/identity2/IdentityServiceControllerImpl.java 2006-12-13 15:16:44 UTC (rev 5831)
@@ -24,7 +24,7 @@
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.IdentityConfigurationMetaDataFactory;
+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;
@@ -32,6 +32,7 @@
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;
@@ -41,7 +42,6 @@
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.AbstractParameterMetaData;
import org.jboss.beans.metadata.plugins.AbstractPropertyMetaData;
import javax.management.ObjectName;
@@ -109,8 +109,8 @@
//TODO: make a dtd for config files.
//parse config files
- IdentityConfigurationMetaData meta = parseConfiguration(configFile);
- IdentityConfigurationMetaData defaultMeta = parseConfiguration(defaultConfigFile);
+ IdentityConfigurationMetaData meta = ConfigurationParser.parseIdentityConfiguration(configFile);
+ IdentityConfigurationMetaData defaultMeta = ConfigurationParser.parseIdentityConfiguration(defaultConfigFile);
KernelControllerContext identityKernelContext;
try
@@ -248,6 +248,7 @@
{
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);
}
@@ -322,6 +323,7 @@
{
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);
}
@@ -361,35 +363,8 @@
}
- private IdentityConfigurationMetaData parseConfiguration(String configFile) throws IdentityException
- {
- ClassLoader tcl = Thread.currentThread().getContextClassLoader();
- IdentityConfigurationMetaData meta;
- try
- {
- log.info("Processing portal identity configuration");
- log.debug("config file: " + configFile);
- URL config = tcl.getResource(configFile);
- InputStream in = config.openStream();
- // create unmarshaller
- Unmarshaller unmarshaller = UnmarshallerFactory.newInstance().newUnmarshaller();
+
- // create an instance of ObjectModelFactory
- ObjectModelFactory factory = new IdentityConfigurationMetaDataFactory();
-
- // let the object model factory to create an instance of Map and populate it with data from XML
- meta = (IdentityConfigurationMetaData)unmarshaller.unmarshal(in, factory, null);
-
- // close the XML stream
- in.close();
- }
- catch (Exception e)
- {
- throw new IdentityException("Cannot parse configuration file", e);
- }
- return meta;
- }
-
/**
* updates module with proper defaults
*
Modified: trunk/identity/src/main/org/jboss/portal/identity2/MembershipModule.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/MembershipModule.java 2006-12-13 15:14:50 UTC (rev 5830)
+++ trunk/identity/src/main/org/jboss/portal/identity2/MembershipModule.java 2006-12-13 15:16:44 UTC (rev 5831)
@@ -36,6 +36,8 @@
public interface MembershipModule
{
+ //TODO: add isUserInRole method - it could gain better performance
+
/**
* Return the set of role objects that a given user has.
*
Modified: trunk/identity/src/main/org/jboss/portal/identity2/Role.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/Role.java 2006-12-13 15:14:50 UTC (rev 5830)
+++ trunk/identity/src/main/org/jboss/portal/identity2/Role.java 2006-12-13 15:16:44 UTC (rev 5831)
@@ -32,14 +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);
+ public void setDisplayName(String name);
}
Modified: trunk/identity/src/main/org/jboss/portal/identity2/User.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/User.java 2006-12-13 15:14:50 UTC (rev 5830)
+++ trunk/identity/src/main/org/jboss/portal/identity2/User.java 2006-12-13 15:16:44 UTC (rev 5831)
@@ -61,20 +61,26 @@
String INFO_USER_REGISTRATION_DATE = "portal.user.registration-date";
String INFO_USER_ENABLED = "portal.user.enabled";
- String INFO_USER_EMAIL_REAL = "portal.user.realEmail";
+ String INFO_USER_EMAIL_REAL = "portal.user.email.real";
/** The user identifier. */
- Object getId();
+ public Object getId();
/** The user name. */
- String getUserName();
+ public String getUserName();
- /** Set the password. */
- void updatePassword(String password);
+ /** Set the password using proper encoding. */
+ public void updatePassword(String password);
+ /** Set the password value directly */
+ public void setPassword(String password);
+
+ /** Returns password value */
+ public String getPassword();
+
/** Return true if the password is valid. */
- boolean validatePassword(String password);
+ public boolean validatePassword(String password);
}
Modified: trunk/identity/src/main/org/jboss/portal/identity2/UserModule.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/UserModule.java 2006-12-13 15:14:50 UTC (rev 5830)
+++ trunk/identity/src/main/org/jboss/portal/identity2/UserModule.java 2006-12-13 15:16:44 UTC (rev 5831)
@@ -66,8 +66,7 @@
* @param userName
* @return the user
*/
- //TODO: remove realEmail from the signature
- User createUser(String userName, String password, String realEmail) throws IdentityException, IllegalArgumentException;
+ User createUser(String userName, String password) throws IdentityException, IllegalArgumentException;
/**
* Remove a user.
Modified: trunk/identity/src/main/org/jboss/portal/identity2/UserProfileModule.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/UserProfileModule.java 2006-12-13 15:14:50 UTC (rev 5830)
+++ trunk/identity/src/main/org/jboss/portal/identity2/UserProfileModule.java 2006-12-13 15:16:44 UTC (rev 5831)
@@ -23,6 +23,7 @@
package org.jboss.portal.identity2;
import org.jboss.portal.identity.IdentityException;
+import org.jboss.portal.identity2.info.ProfileInfo;
import java.util.Map;
@@ -39,4 +40,6 @@
public Map getProperties(User user) throws IdentityException, IllegalArgumentException;
+ public ProfileInfo getProfileInfo() throws IdentityException;
+
}
19 years, 7 months
JBoss Portal SVN: r5830 - in trunk/identity/src/main/org/jboss/portal/identity2: config config/info config/metadata config/metadata/profile info
by portal-commits@lists.jboss.org
Author: bdaw
Date: 2006-12-13 10:14:50 -0500 (Wed, 13 Dec 2006)
New Revision: 5830
Added:
trunk/identity/src/main/org/jboss/portal/identity2/config/metadata/ConfigurationParser.java
trunk/identity/src/main/org/jboss/portal/identity2/config/metadata/IdentityConfigurationMetaDataFactory.java
trunk/identity/src/main/org/jboss/portal/identity2/config/metadata/profile/PropertyMappingDatabaseMetaData.java
trunk/identity/src/main/org/jboss/portal/identity2/config/metadata/profile/PropertyMappingLDAPMetaData.java
Removed:
trunk/identity/src/main/org/jboss/portal/identity2/config/IdentityConfigurationMetaDataFactory.java
Modified:
trunk/identity/src/main/org/jboss/portal/identity2/config/info/ProfileInfoSupport.java
trunk/identity/src/main/org/jboss/portal/identity2/config/info/PropertyInfoSupport.java
trunk/identity/src/main/org/jboss/portal/identity2/config/metadata/profile/ProfileMetaDataFactory.java
trunk/identity/src/main/org/jboss/portal/identity2/config/metadata/profile/PropertyMappingMetaData.java
trunk/identity/src/main/org/jboss/portal/identity2/info/PropertyInfo.java
Log:
Identity configuration and user profile metadata
Deleted: trunk/identity/src/main/org/jboss/portal/identity2/config/IdentityConfigurationMetaDataFactory.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/config/IdentityConfigurationMetaDataFactory.java 2006-12-13 15:13:33 UTC (rev 5829)
+++ trunk/identity/src/main/org/jboss/portal/identity2/config/IdentityConfigurationMetaDataFactory.java 2006-12-13 15:14:50 UTC (rev 5830)
@@ -1,276 +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.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.xml.sax.Attributes;
-
-/**
- * @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw Dawidowicz</a>
- * @version $Revision: 1.1 $
- */
-public class IdentityConfigurationMetaDataFactory implements GenericObjectModelFactory
-{
- private static final org.jboss.logging.Logger log = org.jboss.logging.Logger.getLogger(IdentityConfigurationMetaDataFactory.class);
-
- public Object newRoot(Object object, UnmarshallingContext unmarshallingContext, String string, String string1, Attributes attributes)
- {
- return new IdentityConfigurationMetaData();
- }
-
- 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)
- {
- if (root instanceof IdentityConfigurationMetaData)
- {
- if ("modules".equals(localName))
- {
- return new ModulesMetaData();
- }
- else if ("datasources".equals(localName))
- {
- return new DatasourcesMetaData();
- }
- else if("options".equals(localName))
- {
- return new OptionsMetaData();
- }
- }
- if (root instanceof DatasourcesMetaData)
- {
- if ("datasource".equals(localName))
- {
- return new DatasourceMetaData();
- }
- }
- if (root instanceof DatasourceMetaData)
- {
- if ("config".equals(localName))
- {
- return new ConfigMetaData();
- }
- }
- else if (root instanceof ModulesMetaData)
- {
- if ("module".equals(localName))
- {
- return new ModuleMetaData();
- }
- }
- else if (root instanceof ModuleMetaData)
- {
- if ("config".equals(localName))
- {
- return new ConfigMetaData();
- }
- }
- else if (root instanceof ConfigMetaData)
- {
- if ("option".equals(localName))
- {
- return new ConfigOptionMetaData();
- }
- }
- else if (root instanceof OptionsMetaData)
- {
- if ("option-group".equals(localName))
- {
- return new OptionsGroupMetaData();
- }
- }
- else if (root instanceof OptionsGroupMetaData)
- {
- if ("option".equals(localName))
- {
- return new OptionsGroupOptionMetaData();
- }
- }
- return null;
- }
-
- public void addChild(Object parent, Object child, UnmarshallingContext nav, String nsURI, String localName)
- {
- if (parent instanceof IdentityConfigurationMetaData)
- {
- IdentityConfigurationMetaData identity = (IdentityConfigurationMetaData)parent;
- if (child instanceof ModulesMetaData)
- {
- identity.setModules((ModulesMetaData)child);
- }
- else if (child instanceof DatasourcesMetaData)
- {
- identity.setDatasources((DatasourcesMetaData)child);
- }
- else if (child instanceof OptionsMetaData)
- {
- identity.setOptions((OptionsMetaData)child);
- }
- }
- else if (parent instanceof DatasourcesMetaData)
- {
- DatasourcesMetaData datasources = (DatasourcesMetaData)parent;
- if (child instanceof DatasourceMetaData)
- {
- datasources.addDatasource((DatasourceMetaData)child);
- }
- }
- else if (parent instanceof DatasourceMetaData)
- {
- DatasourceMetaData datasource = (DatasourceMetaData)parent;
- if (child instanceof ConfigMetaData)
- {
- datasource.setConfig((ConfigMetaData)child);
- }
- }
-
- else if (parent instanceof ModulesMetaData)
- {
- ModulesMetaData modules = (ModulesMetaData)parent;
- if (child instanceof ModuleMetaData)
- {
- modules.addModule((ModuleMetaData)child);
- }
- }
- else if (parent instanceof ModuleMetaData)
- {
- ModuleMetaData module = (ModuleMetaData)parent;
- if (child instanceof ConfigMetaData)
- {
- module.setConfig((ConfigMetaData)child);
- }
- }
- else if (parent instanceof ConfigMetaData)
- {
- ConfigMetaData config = (ConfigMetaData)parent;
- if (child instanceof ConfigOptionMetaData)
- {
- config.addOption((ConfigOptionMetaData)child);
- }
- }
- else if (parent instanceof OptionsMetaData)
- {
- OptionsMetaData options = (OptionsMetaData)parent;
- if (child instanceof OptionsGroupMetaData)
- {
- options.addGroup((OptionsGroupMetaData)child);
- }
- }
- else if (parent instanceof OptionsGroupMetaData)
- {
- OptionsGroupMetaData group = (OptionsGroupMetaData)parent;
- if (child instanceof OptionsGroupOptionMetaData)
- {
- group.addOption((OptionsGroupOptionMetaData)child);
- }
- }
- }
-
- public void setValue(Object object, UnmarshallingContext unmarshallingContext, String nsUri, String localName, String value)
- {
- if (object instanceof ModuleMetaData)
- {
- ModuleMetaData module = (ModuleMetaData)object;
- if ("type".equals(localName))
- {
- module.setType(value);
- }
- else if ("implementation".equals(localName))
- {
- module.setImplementation(value);
- }
- else if ("service-name".equals(localName))
- {
- module.setServiceName(value);
- }
- else if ("class".equals(localName))
- {
- module.setClassName(value);
- }
- }
- if (object instanceof DatasourceMetaData)
- {
- DatasourceMetaData ds = (DatasourceMetaData)object;
- if ("name".equals(localName))
- {
- log.info("@@@@ adding name: " + value);
- ds.setName(value);
- }
- else if ("service-name".equals(localName))
- {
- log.info("@@@@ adding service name: " + value);
- ds.setServiceName(value);
- }
- else if ("class".equals(localName))
- {
- log.info("@@@@ class name: " + value);
- ds.setClassName(value);
- }
- }
- else if (object instanceof ConfigOptionMetaData)
- {
- ConfigOptionMetaData option = (ConfigOptionMetaData)object;
- if ("name".equals(localName))
- {
- option.setName(value);
- }
- else if ("value".equals(localName))
- {
- option.setValue(value);
- }
- }
- else if (object instanceof OptionsGroupMetaData)
- {
- OptionsGroupMetaData group = (OptionsGroupMetaData)object;
- if ("group-name".equals(localName))
- {
- group.setName(value);
- }
- }
- else if (object instanceof OptionsGroupOptionMetaData)
- {
- OptionsGroupOptionMetaData option = (OptionsGroupOptionMetaData)object;
- if ("name".equals(localName))
- {
- option.setName(value);
- }
- else if ("value".equals(localName))
- {
- option.addValue(value);
- }
- }
- }
-}
Modified: trunk/identity/src/main/org/jboss/portal/identity2/config/info/ProfileInfoSupport.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/config/info/ProfileInfoSupport.java 2006-12-13 15:13:33 UTC (rev 5829)
+++ trunk/identity/src/main/org/jboss/portal/identity2/config/info/ProfileInfoSupport.java 2006-12-13 15:14:50 UTC (rev 5830)
@@ -25,6 +25,7 @@
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.IdentityException;
import java.util.Map;
import java.util.HashMap;
@@ -40,17 +41,25 @@
private Map properties;
- public ProfileInfoSupport(ProfileMetaData profile)
+ public ProfileInfoSupport(ProfileMetaData profile) throws IdentityException
{
- properties = new HashMap();
- Map meta = profile.getProperties();
- for (Iterator iterator = meta.keySet().iterator(); iterator.hasNext();)
+
+ try
{
- String name = (String)iterator.next();
- PropertyMetaData property = (PropertyMetaData)meta.get(name);
- PropertyInfo pi = new PropertyInfoSupport(property);
- properties.put(pi.getName(), pi);
+ properties = new HashMap();
+ Map meta = profile.getProperties();
+ for (Iterator iterator = meta.keySet().iterator(); iterator.hasNext();)
+ {
+ String name = (String)iterator.next();
+ PropertyMetaData property = (PropertyMetaData)meta.get(name);
+ PropertyInfo pi = new PropertyInfoSupport(property);
+ properties.put(pi.getName(), pi);
+ }
}
+ catch (IdentityException e)
+ {
+ throw new IdentityException("PrifileInfo creation error: ", e);
+ }
}
public Map getPropertiesInfo()
Modified: trunk/identity/src/main/org/jboss/portal/identity2/config/info/PropertyInfoSupport.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/config/info/PropertyInfoSupport.java 2006-12-13 15:13:33 UTC (rev 5829)
+++ trunk/identity/src/main/org/jboss/portal/identity2/config/info/PropertyInfoSupport.java 2006-12-13 15:14:50 UTC (rev 5830)
@@ -25,6 +25,8 @@
import org.jboss.portal.identity2.config.metadata.profile.PropertyMetaData;
import org.jboss.portal.identity2.config.metadata.profile.LocalizedValueMetaData;
import org.jboss.portal.common.util.LocalizedString;
+import org.jboss.portal.identity.IdentityException;
+import org.jboss.logging.Logger;
import java.util.Locale;
import java.util.Iterator;
@@ -37,25 +39,37 @@
*/
public class PropertyInfoSupport implements PropertyInfo
{
+ private static final Logger log = Logger.getLogger(PropertyInfo.class);
+
+ //TODO: introduce safe types enums where possible.
+
private String name;
private String type;
private String accessMode;
private String usage;
private LocalizedString displayName;
private LocalizedString description;
- private String mappingType;
- private String mappingValue;
+ private String mappingDBType;
+ private String mappingDBValue;
+ private String mappingLDAPValue;
+ private boolean mappedLDAP;
+ private boolean mappedDB;
- public PropertyInfoSupport(PropertyMetaData meta)
+ public PropertyInfoSupport(PropertyMetaData meta) throws IdentityException
{
+
+
+
name = meta.getName();
type = meta.getType();
accessMode = meta.getAccessMode();
usage = meta.getUsage();
- mappingType = meta.getMapping().getType();
- mappingValue = meta.getMapping().getValue();
+ //mappingType = meta.getMapping().getType();
+ //mappingValue = meta.getMapping().getValue();
+
+
Map descValues = new HashMap();
for (Iterator iterator = meta.getDescription().getValues().iterator(); iterator.hasNext();)
{
@@ -72,6 +86,33 @@
description = new LocalizedString(descValues, Locale.ENGLISH);
displayName = new LocalizedString(dispValues, Locale.ENGLISH);
+ if (meta.getMapping() == null)
+ {
+ throw new IdentityException("Mapping section is missing");
+ }
+ if (meta.getMapping().getMappingDatabase() != null)
+ {
+ if (meta.getMapping().getMappingDatabase().getType() != null && meta.getMapping().getMappingDatabase().getValue() != null)
+ {
+ mappedDB = true;
+ mappingDBType = meta.getMapping().getMappingDatabase().getType();
+ mappingDBValue = meta.getMapping().getMappingDatabase().getValue();
+ }
+ }
+
+ if (meta.getMapping().getMappingLDAP() != null)
+ {
+ if (meta.getMapping().getMappingLDAP().getValue() != null)
+ {
+ mappedLDAP = true;
+ mappingLDAPValue = meta.getMapping().getMappingLDAP().getValue();
+ }
+ }
+
+ if (log.isDebugEnabled())
+ {
+ log.debug("created PropertyInfo: " + toString());
+ }
}
public String getName()
@@ -104,13 +145,46 @@
return description;
}
- public String getMappingType()
+ public String getMappingDBType()
{
- return mappingType;
+ return mappingDBType;
}
- public String getMappingValue()
+ public String getMappingLDAPValue()
{
- return mappingValue;
+ return mappingLDAPValue;
}
+
+ public String getMappingDBValue()
+ {
+ return mappingDBValue;
+ }
+
+
+ public boolean isMappedDB()
+ {
+ return mappedDB;
+ }
+
+ public boolean isMappedLDAP()
+ {
+ return mappedLDAP;
+ }
+
+ public String toString()
+ {
+ StringBuffer buf = new StringBuffer();
+ buf.append("name: ").append(name)
+ .append("; type:").append(type)
+ .append("; accessMode:").append(accessMode)
+ .append("; usage: ").append(usage)
+ .append("; displayName: ").append(displayName)
+ .append("; description: ").append(description)
+ .append("; mappingDBType: ").append(mappingDBType)
+ .append("; mappingLDAPValue: ").append(mappingLDAPValue)
+ .append("; mappingDBValue: ").append(mappingDBValue)
+ .append("; mappedDB: ").append(mappedDB)
+ .append("; mappedLDAP: ").append(mappedLDAP);
+ return buf.toString();
+ }
}
Added: trunk/identity/src/main/org/jboss/portal/identity2/config/metadata/ConfigurationParser.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/config/metadata/ConfigurationParser.java 2006-12-13 15:13:33 UTC (rev 5829)
+++ trunk/identity/src/main/org/jboss/portal/identity2/config/metadata/ConfigurationParser.java 2006-12-13 15:14:50 UTC (rev 5830)
@@ -0,0 +1,112 @@
+/*
+* 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.metadata;
+
+import org.jboss.portal.identity2.config.metadata.profile.ProfileMetaData;
+import org.jboss.portal.identity2.config.metadata.profile.ProfileMetaDataFactory;
+import org.jboss.portal.identity.IdentityException;
+import org.jboss.xb.binding.Unmarshaller;
+import org.jboss.xb.binding.UnmarshallerFactory;
+import org.jboss.xb.binding.ObjectModelFactory;
+
+import java.net.URL;
+import java.io.InputStream;
+
+/**
+ * @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw Dawidowicz</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class ConfigurationParser
+{
+
+ private static final org.jboss.logging.Logger log = org.jboss.logging.Logger.getLogger(ConfigurationParser.class);
+
+
+ //TODO: merge this two methods (redundancy)
+
+ /**
+ * Parse identity config file
+ * @param configFile
+ * @return
+ * @throws org.jboss.portal.identity.IdentityException
+ */
+ public static ProfileMetaData parseProfileConfiguration(String configFile) throws IdentityException
+ {
+ ClassLoader tcl = Thread.currentThread().getContextClassLoader();
+ ProfileMetaData meta;
+ try
+ {
+ log.info("Processing identity profile configuration");
+ if (log.isDebugEnabled())
+ {
+ log.debug("config file: " + configFile);
+ }
+ URL config = tcl.getResource(configFile);
+ InputStream in = config.openStream();
+ // create unmarshaller
+ Unmarshaller unmarshaller = UnmarshallerFactory.newInstance().newUnmarshaller();
+
+ // create an instance of ObjectModelFactory
+ ObjectModelFactory factory = new ProfileMetaDataFactory();
+
+ // let the object model factory to create an instance of Map and populate it with data from XML
+ meta = (ProfileMetaData)unmarshaller.unmarshal(in, factory, null);
+
+ // close the XML stream
+ in.close();
+ }
+ catch (Exception e)
+ {
+ throw new IdentityException("Cannot parse identity profile configuration file", e);
+ }
+ return meta;
+ }
+
+ public static IdentityConfigurationMetaData parseIdentityConfiguration(String configFile) throws IdentityException
+ {
+ ClassLoader tcl = Thread.currentThread().getContextClassLoader();
+ IdentityConfigurationMetaData meta;
+ try
+ {
+ log.info("Processing portal identity configuration");
+ log.debug("config file: " + configFile);
+ URL config = tcl.getResource(configFile);
+ InputStream in = config.openStream();
+ // create unmarshaller
+ Unmarshaller unmarshaller = UnmarshallerFactory.newInstance().newUnmarshaller();
+
+ // create an instance of ObjectModelFactory
+ ObjectModelFactory factory = new IdentityConfigurationMetaDataFactory();
+
+ // let the object model factory to create an instance of Map and populate it with data from XML
+ meta = (IdentityConfigurationMetaData)unmarshaller.unmarshal(in, factory, null);
+
+ // close the XML stream
+ in.close();
+ }
+ catch (Exception e)
+ {
+ throw new IdentityException("Cannot parse identity configuration file", e);
+ }
+ return meta;
+ }
+}
Copied: trunk/identity/src/main/org/jboss/portal/identity2/config/metadata/IdentityConfigurationMetaDataFactory.java (from rev 5770, trunk/identity/src/main/org/jboss/portal/identity2/config/IdentityConfigurationMetaDataFactory.java)
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/config/IdentityConfigurationMetaDataFactory.java 2006-12-06 09:43:49 UTC (rev 5770)
+++ trunk/identity/src/main/org/jboss/portal/identity2/config/metadata/IdentityConfigurationMetaDataFactory.java 2006-12-13 15:14:50 UTC (rev 5830)
@@ -0,0 +1,273 @@
+/*
+* 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.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.xml.sax.Attributes;
+
+/**
+ * @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw Dawidowicz</a>
+ * @version $Revision: 1.1 $
+ */
+public class IdentityConfigurationMetaDataFactory implements GenericObjectModelFactory
+{
+ private static final org.jboss.logging.Logger log = org.jboss.logging.Logger.getLogger(IdentityConfigurationMetaDataFactory.class);
+
+ public Object newRoot(Object object, UnmarshallingContext unmarshallingContext, String string, String string1, Attributes attributes)
+ {
+ return new IdentityConfigurationMetaData();
+ }
+
+ 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)
+ {
+ if (root instanceof IdentityConfigurationMetaData)
+ {
+ if ("modules".equals(localName))
+ {
+ return new ModulesMetaData();
+ }
+ else if ("datasources".equals(localName))
+ {
+ return new DatasourcesMetaData();
+ }
+ else if("options".equals(localName))
+ {
+ return new OptionsMetaData();
+ }
+ }
+ if (root instanceof DatasourcesMetaData)
+ {
+ if ("datasource".equals(localName))
+ {
+ return new DatasourceMetaData();
+ }
+ }
+ if (root instanceof DatasourceMetaData)
+ {
+ if ("config".equals(localName))
+ {
+ return new ConfigMetaData();
+ }
+ }
+ else if (root instanceof ModulesMetaData)
+ {
+ if ("module".equals(localName))
+ {
+ return new ModuleMetaData();
+ }
+ }
+ else if (root instanceof ModuleMetaData)
+ {
+ if ("config".equals(localName))
+ {
+ return new ConfigMetaData();
+ }
+ }
+ else if (root instanceof ConfigMetaData)
+ {
+ if ("option".equals(localName))
+ {
+ return new ConfigOptionMetaData();
+ }
+ }
+ else if (root instanceof OptionsMetaData)
+ {
+ if ("option-group".equals(localName))
+ {
+ return new OptionsGroupMetaData();
+ }
+ }
+ else if (root instanceof OptionsGroupMetaData)
+ {
+ if ("option".equals(localName))
+ {
+ return new OptionsGroupOptionMetaData();
+ }
+ }
+ return null;
+ }
+
+ public void addChild(Object parent, Object child, UnmarshallingContext nav, String nsURI, String localName)
+ {
+ if (parent instanceof IdentityConfigurationMetaData)
+ {
+ IdentityConfigurationMetaData identity = (IdentityConfigurationMetaData)parent;
+ if (child instanceof ModulesMetaData)
+ {
+ identity.setModules((ModulesMetaData)child);
+ }
+ else if (child instanceof DatasourcesMetaData)
+ {
+ identity.setDatasources((DatasourcesMetaData)child);
+ }
+ else if (child instanceof OptionsMetaData)
+ {
+ identity.setOptions((OptionsMetaData)child);
+ }
+ }
+ else if (parent instanceof DatasourcesMetaData)
+ {
+ DatasourcesMetaData datasources = (DatasourcesMetaData)parent;
+ if (child instanceof DatasourceMetaData)
+ {
+ datasources.addDatasource((DatasourceMetaData)child);
+ }
+ }
+ else if (parent instanceof DatasourceMetaData)
+ {
+ DatasourceMetaData datasource = (DatasourceMetaData)parent;
+ if (child instanceof ConfigMetaData)
+ {
+ datasource.setConfig((ConfigMetaData)child);
+ }
+ }
+
+ else if (parent instanceof ModulesMetaData)
+ {
+ ModulesMetaData modules = (ModulesMetaData)parent;
+ if (child instanceof ModuleMetaData)
+ {
+ modules.addModule((ModuleMetaData)child);
+ }
+ }
+ else if (parent instanceof ModuleMetaData)
+ {
+ ModuleMetaData module = (ModuleMetaData)parent;
+ if (child instanceof ConfigMetaData)
+ {
+ module.setConfig((ConfigMetaData)child);
+ }
+ }
+ else if (parent instanceof ConfigMetaData)
+ {
+ ConfigMetaData config = (ConfigMetaData)parent;
+ if (child instanceof ConfigOptionMetaData)
+ {
+ config.addOption((ConfigOptionMetaData)child);
+ }
+ }
+ else if (parent instanceof OptionsMetaData)
+ {
+ OptionsMetaData options = (OptionsMetaData)parent;
+ if (child instanceof OptionsGroupMetaData)
+ {
+ options.addGroup((OptionsGroupMetaData)child);
+ }
+ }
+ else if (parent instanceof OptionsGroupMetaData)
+ {
+ OptionsGroupMetaData group = (OptionsGroupMetaData)parent;
+ if (child instanceof OptionsGroupOptionMetaData)
+ {
+ group.addOption((OptionsGroupOptionMetaData)child);
+ }
+ }
+ }
+
+ public void setValue(Object object, UnmarshallingContext unmarshallingContext, String nsUri, String localName, String value)
+ {
+ if (object instanceof ModuleMetaData)
+ {
+ ModuleMetaData module = (ModuleMetaData)object;
+ if ("type".equals(localName))
+ {
+ module.setType(value);
+ }
+ else if ("implementation".equals(localName))
+ {
+ module.setImplementation(value);
+ }
+ else if ("service-name".equals(localName))
+ {
+ module.setServiceName(value);
+ }
+ else if ("class".equals(localName))
+ {
+ module.setClassName(value);
+ }
+ }
+ if (object instanceof DatasourceMetaData)
+ {
+ DatasourceMetaData ds = (DatasourceMetaData)object;
+ if ("name".equals(localName))
+ {
+ ds.setName(value);
+ }
+ else if ("service-name".equals(localName))
+ {
+ ds.setServiceName(value);
+ }
+ else if ("class".equals(localName))
+ {
+ ds.setClassName(value);
+ }
+ }
+ else if (object instanceof ConfigOptionMetaData)
+ {
+ ConfigOptionMetaData option = (ConfigOptionMetaData)object;
+ if ("name".equals(localName))
+ {
+ option.setName(value);
+ }
+ else if ("value".equals(localName))
+ {
+ option.setValue(value);
+ }
+ }
+ else if (object instanceof OptionsGroupMetaData)
+ {
+ OptionsGroupMetaData group = (OptionsGroupMetaData)object;
+ if ("group-name".equals(localName))
+ {
+ group.setName(value);
+ }
+ }
+ else if (object instanceof OptionsGroupOptionMetaData)
+ {
+ OptionsGroupOptionMetaData option = (OptionsGroupOptionMetaData)object;
+ if ("name".equals(localName))
+ {
+ option.setName(value);
+ }
+ else if ("value".equals(localName))
+ {
+ option.addValue(value);
+ }
+ }
+ }
+}
Modified: trunk/identity/src/main/org/jboss/portal/identity2/config/metadata/profile/ProfileMetaDataFactory.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/config/metadata/profile/ProfileMetaDataFactory.java 2006-12-13 15:13:33 UTC (rev 5829)
+++ trunk/identity/src/main/org/jboss/portal/identity2/config/metadata/profile/ProfileMetaDataFactory.java 2006-12-13 15:14:50 UTC (rev 5830)
@@ -23,8 +23,6 @@
import org.jboss.xb.binding.GenericObjectModelFactory;
import org.jboss.xb.binding.UnmarshallingContext;
-import org.jboss.portal.identity2.config.IdentityConfigurationMetaDataFactory;
-import org.jboss.portal.identity2.config.metadata.IdentityConfigurationMetaData;
import org.jboss.portal.common.util.LocaleInfo;
import org.xml.sax.Attributes;
@@ -86,6 +84,17 @@
return value;
}
}
+ else if (root instanceof PropertyMappingMetaData)
+ {
+ if ("database".equals(localName))
+ {
+ return new PropertyMappingDatabaseMetaData();
+ }
+ else if ("ldap".equals(localName))
+ {
+ return new PropertyMappingLDAPMetaData();
+ }
+ }
return null;
}
@@ -110,7 +119,7 @@
}
else if ("dispalay-name".equals(localName))
{
- describable.getDisplayName().getValues().add(child);
+ describable.getDisplayName().getValues().add(child);
}
}
else if (child instanceof PropertyMappingMetaData)
@@ -118,6 +127,18 @@
describable.setMapping((PropertyMappingMetaData)child);
}
}
+ else if (parent instanceof PropertyMappingMetaData)
+ {
+ PropertyMappingMetaData mapping = (PropertyMappingMetaData)parent;
+ if (child instanceof PropertyMappingDatabaseMetaData)
+ {
+ mapping.setMappingDatabase((PropertyMappingDatabaseMetaData)child);
+ }
+ else if (child instanceof PropertyMappingLDAPMetaData)
+ {
+ mapping.setMappingLDAP((PropertyMappingLDAPMetaData)child);
+ }
+ }
}
public void setValue(Object object, UnmarshallingContext unmarshallingContext, String nsUri, String localName, String value)
@@ -135,16 +156,28 @@
}
else if ("access-mode".equals(localName))
{
- property.setType(value);
+ property.setAccessMode(value);
}
else if ("usage".equals(localName))
{
property.setUsage(value);
}
}
- else if (object instanceof PropertyMappingMetaData)
+ else if (object instanceof LocalizedValueMetaData)
{
- PropertyMappingMetaData mapping = (PropertyMappingMetaData)object;
+ LocalizedValueMetaData localized = (LocalizedValueMetaData)object;
+ if ("description".equals(localName))
+ {
+ localized.setValue(value);
+ }
+ else if ("display-name".equals(localName))
+ {
+ localized.setValue(value);
+ }
+ }
+ else if (object instanceof PropertyMappingDatabaseMetaData)
+ {
+ PropertyMappingDatabaseMetaData mapping = (PropertyMappingDatabaseMetaData)object;
if ("type".equals(localName))
{
mapping.setType(value);
@@ -154,5 +187,13 @@
mapping.setValue(value);
}
}
+ else if (object instanceof PropertyMappingLDAPMetaData)
+ {
+ PropertyMappingLDAPMetaData mapping = (PropertyMappingLDAPMetaData)object;
+ if ("value".equals(localName))
+ {
+ mapping.setValue(value);
+ }
+ }
}
}
Added: trunk/identity/src/main/org/jboss/portal/identity2/config/metadata/profile/PropertyMappingDatabaseMetaData.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/config/metadata/profile/PropertyMappingDatabaseMetaData.java 2006-12-13 15:13:33 UTC (rev 5829)
+++ trunk/identity/src/main/org/jboss/portal/identity2/config/metadata/profile/PropertyMappingDatabaseMetaData.java 2006-12-13 15:14:50 UTC (rev 5830)
@@ -0,0 +1,57 @@
+/*
+* 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.metadata.profile;
+
+/**
+ * @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw Dawidowicz</a>
+ * @version $Revision: 1.1 $
+ */
+public class PropertyMappingDatabaseMetaData
+{
+ private String type;
+ private String value;
+
+ public PropertyMappingDatabaseMetaData()
+ {
+
+ }
+
+ public String getType()
+ {
+ return type;
+ }
+
+ public void setType(String type)
+ {
+ this.type = type;
+ }
+
+ public String getValue()
+ {
+ return value;
+ }
+
+ public void setValue(String value)
+ {
+ this.value = value;
+ }
+}
Added: trunk/identity/src/main/org/jboss/portal/identity2/config/metadata/profile/PropertyMappingLDAPMetaData.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/config/metadata/profile/PropertyMappingLDAPMetaData.java 2006-12-13 15:13:33 UTC (rev 5829)
+++ trunk/identity/src/main/org/jboss/portal/identity2/config/metadata/profile/PropertyMappingLDAPMetaData.java 2006-12-13 15:14:50 UTC (rev 5830)
@@ -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.identity2.config.metadata.profile;
+
+/**
+ * @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw Dawidowicz</a>
+ * @version $Revision: 1.1 $
+ */
+public class PropertyMappingLDAPMetaData
+{
+ String value;
+
+ public PropertyMappingLDAPMetaData()
+ {
+
+ }
+
+ public String getValue()
+ {
+ return value;
+ }
+
+ public void setValue(String value)
+ {
+ this.value = value;
+ }
+}
Modified: trunk/identity/src/main/org/jboss/portal/identity2/config/metadata/profile/PropertyMappingMetaData.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/config/metadata/profile/PropertyMappingMetaData.java 2006-12-13 15:13:33 UTC (rev 5829)
+++ trunk/identity/src/main/org/jboss/portal/identity2/config/metadata/profile/PropertyMappingMetaData.java 2006-12-13 15:14:50 UTC (rev 5830)
@@ -27,32 +27,31 @@
*/
public class PropertyMappingMetaData
{
- private String type;
- private String value;
+ private PropertyMappingDatabaseMetaData mappingDatabase;
+ private PropertyMappingLDAPMetaData mappingLDAP;
public PropertyMappingMetaData()
{
}
-
- public String getType()
+ public PropertyMappingDatabaseMetaData getMappingDatabase()
{
- return type;
+ return mappingDatabase;
}
- public void setType(String type)
+ public void setMappingDatabase(PropertyMappingDatabaseMetaData mappingDatabase)
{
- this.type = type;
+ this.mappingDatabase = mappingDatabase;
}
- public String getValue()
+ public PropertyMappingLDAPMetaData getMappingLDAP()
{
- return value;
+ return mappingLDAP;
}
- public void setValue(String value)
+ public void setMappingLDAP(PropertyMappingLDAPMetaData mappingLDAP)
{
- this.value = value;
+ this.mappingLDAP = mappingLDAP;
}
}
Modified: trunk/identity/src/main/org/jboss/portal/identity2/info/PropertyInfo.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/info/PropertyInfo.java 2006-12-13 15:13:33 UTC (rev 5829)
+++ trunk/identity/src/main/org/jboss/portal/identity2/info/PropertyInfo.java 2006-12-13 15:14:50 UTC (rev 5830)
@@ -36,19 +36,9 @@
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_TYPE_COLUMN = "column";
- public static final String MAPPING_TYPE_DYNAMIC = "dynamic";
- public static final String MAPPING_TYPE_ATTRIBUTE = "attribute";
+ public static final String MAPPING_DB_TYPE_COLUMN = "column";
+ public static final String MAPPING_DB_TYPE_DYNAMIC = "dynamic";
-
- /*private String name;
- private String type;
- private String accessMode;
- private String usage;
- private LocalizedString displayName;
- private LocalizedString description;
- private PropertyMappingMetaData mapping;*/
-
public String getName();
public String getType();
@@ -61,10 +51,15 @@
public LocalizedString getDescription();
- public String getMappingType();
+ public String getMappingDBType();
- public String getMappingValue();
+ public String getMappingLDAPValue();
+ public String getMappingDBValue();
+ public boolean isMappedDB();
+ public boolean isMappedLDAP();
+
+
}
19 years, 7 months
JBoss Portal SVN: r5829 - in trunk/identity/src/main/org/jboss/portal/identity2: . experimental experimental/db
by portal-commits@lists.jboss.org
Author: bdaw
Date: 2006-12-13 10:13:33 -0500 (Wed, 13 Dec 2006)
New Revision: 5829
Added:
trunk/identity/src/main/org/jboss/portal/identity2/experimental/
trunk/identity/src/main/org/jboss/portal/identity2/experimental/db/
trunk/identity/src/main/org/jboss/portal/identity2/experimental/db/HibernateHelper.java
trunk/identity/src/main/org/jboss/portal/identity2/experimental/db/HibernateMembershipModuleImpl.java
trunk/identity/src/main/org/jboss/portal/identity2/experimental/db/HibernateRoleImpl.java
trunk/identity/src/main/org/jboss/portal/identity2/experimental/db/HibernateRoleModuleImpl.java
trunk/identity/src/main/org/jboss/portal/identity2/experimental/db/HibernateUserImpl.java
trunk/identity/src/main/org/jboss/portal/identity2/experimental/db/HibernateUserModuleImpl.java
trunk/identity/src/main/org/jboss/portal/identity2/experimental/db/HibernateUserProfileModuleImpl.java
trunk/identity/src/main/org/jboss/portal/identity2/experimental/db/IdentitySessionFactoryBinder.java
Removed:
trunk/identity/src/main/org/jboss/portal/identity2/experimental/db/DBRoleImpl.java
trunk/identity/src/main/org/jboss/portal/identity2/experimental/db/DBUserImpl.java
trunk/identity/src/main/org/jboss/portal/identity2/experimental/db/HibernateMembershipModuleImpl.java
trunk/identity/src/main/org/jboss/portal/identity2/experimental/db/HibernateRoleModuleImpl.java
trunk/identity/src/main/org/jboss/portal/identity2/experimental/db/HibernateUserModuleImpl.java
trunk/identity/src/main/org/jboss/portal/identity2/experimental/db/HibernateUserProfileModuleImpl.java
trunk/identity/src/main/org/jboss/portal/identity2/experimental/db/ProfileMapImpl.java
Log:
abandoned dynamic-map implementation of portal hibernate entities because of: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2299
Copied: trunk/identity/src/main/org/jboss/portal/identity2/experimental/db (from rev 5770, trunk/identity/src/main/org/jboss/portal/identity2/db)
Deleted: trunk/identity/src/main/org/jboss/portal/identity2/experimental/db/DBRoleImpl.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/db/DBRoleImpl.java 2006-12-06 09:43:49 UTC (rev 5770)
+++ trunk/identity/src/main/org/jboss/portal/identity2/experimental/db/DBRoleImpl.java 2006-12-13 15:13:33 UTC (rev 5829)
@@ -1,146 +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
- * @version $Revision: 5448 $
- */
-public class DBRoleImpl
- implements Role
-{
-
- private Long key;
- private String name;
- private Set users;
- private String displayName;
-
- /**
- *
- */
- public DBRoleImpl()
- {
- this.key = null;
- this.name = null;
- this.displayName = null;
- this.users = new HashSet();
- }
-
- /**
- *
- */
- public DBRoleImpl(String name)
- {
- this.key = null;
- this.name = name;
- this.displayName = name;
- this.users = new HashSet();
- }
-
- /**
- *
- */
- public DBRoleImpl(String name, String displayName)
- {
- this.key = null;
- this.name = name;
- this.displayName = displayName;
- this.users = new HashSet();
- }
-
- /**
- * Called by hibernate.
- */
- protected Long getKey()
- {
- return key;
- }
-
- /** Called by hibernate. */
- protected void setKey(Long key)
- {
- this.key = key;
- }
-
- /** Called by hibernate. */
- protected void setName(String name)
- {
- this.name = name;
- }
-
- /** Called by hibernate. */
- protected void setUsers(Set users)
- {
- this.users = users;
- }
-
- // ******************************************************************************************************************
-
- public Object getId()
- {
- return key;
- }
-
- /**
- *
- */
- public String getName()
- {
- return name;
- }
-
- /**
- *
- */
- public String getDisplayName()
- {
- return displayName;
- }
-
- /**
- *
- */
- public void setDisplayName(String displayName)
- {
- this.displayName = displayName;
- }
-
- /**
- *
- */
- public Set getUsers()
- {
- return users;
- }
-
- public String toString()
- {
- return "Role[" + key + "," + name + "]";
- }
-}
Deleted: trunk/identity/src/main/org/jboss/portal/identity2/experimental/db/DBUserImpl.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/db/DBUserImpl.java 2006-12-06 09:43:49 UTC (rev 5770)
+++ trunk/identity/src/main/org/jboss/portal/identity2/experimental/db/DBUserImpl.java 2006-12-13 15:13:33 UTC (rev 5829)
@@ -1,660 +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.ProfileMap;
-import org.jboss.portal.identity2.Role;
-import org.jboss.portal.identity2.db.ProfileMapImpl;
-import org.jboss.portal.common.p3p.P3PConstants;
-import org.jboss.portal.common.util.Tools;
-import org.jboss.portal.common.util.LocaleInfo;
-
-import java.util.Map;
-import java.util.HashMap;
-import java.util.Collections;
-import java.util.Set;
-import java.util.Date;
-import java.util.HashSet;
-import java.util.Locale;
-import java.util.Iterator;
-import java.lang.reflect.Field;
-import java.text.SimpleDateFormat;
-import java.text.DateFormat;
-import java.text.ParseException;
-
-/**
- * User interface implementation.
- *
- * @author <a href="mailto:julien@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: 5448 $
- */
-public class DBUserImpl
- implements User
-{
-
- private static final org.jboss.logging.Logger log = org.jboss.logging.Logger.getLogger(DBUserImpl.class);
-
- static final Map ACCESSORS = buildAccessors();
-
- private static Map buildAccessors()
- {
- Map map = new HashMap();
-
- // Map attributes defined by the JSR 168 spec P3P.
- map.put(P3PConstants.INFO_USER_NAME_NICKNAME, new DBUserImpl.StringPropertyAccessor(P3PConstants.INFO_USER_NAME_NICKNAME, "userName", false, false));
- map.put(P3PConstants.INFO_USER_BUSINESS_INFO_ONLINE_EMAIL, new DBUserImpl.StringPropertyAccessor(P3PConstants.INFO_USER_BUSINESS_INFO_ONLINE_EMAIL, "realEmail", true, true));
- map.put(P3PConstants.INFO_USER_NAME_GIVEN, new DBUserImpl.StringPropertyAccessor(P3PConstants.INFO_USER_NAME_GIVEN, "givenName", true, true));
- map.put(P3PConstants.INFO_USER_NAME_FAMILY, new DBUserImpl.StringPropertyAccessor(P3PConstants.INFO_USER_NAME_FAMILY, "familyName", true, true));
-
- // Map attributes specific to JBoss Portal
- map.put(User.INFO_USER_EMAIL_FAKE, new DBUserImpl.StringPropertyAccessor(User.INFO_USER_EMAIL_FAKE, "fakeEmail", true, true));
- map.put(User.INFO_USER_REGISTRATION_DATE, new DBUserImpl.DatePropertyAccessor(User.INFO_USER_REGISTRATION_DATE, "registrationDate", false, false));
- map.put(User.INFO_USER_VIEW_EMAIL_VIEW_REAL, new DBUserImpl.BooleanPropertyAccessor(User.INFO_USER_VIEW_EMAIL_VIEW_REAL, "viewRealEmail", true, false));
-
- //
- return Collections.unmodifiableMap(map);
- }
-
- /*
- * Transient fields.
- */
-
- protected ProfileMap profile;
- protected Set roleNames;
-
- /*
- * P3P mapped persistent fields.
- */
-
- protected String userName;
- protected String givenName;
- protected String familyName;
- protected String realEmail;
-
- /*
- * Non mapped persistent fields.
- */
-
- protected Long key;
- protected boolean enabled;
- protected String password;
-
- /*
- * Extension mapped persistent fields.
- */
-
- protected String fakeEmail;
- protected boolean viewRealEmail;
- protected Date registrationDate;
-
- /*
- * Persistent associations
- */
-
- protected Map dynamic;
- protected Set roles;
-
- /**
- *
- */
- public DBUserImpl()
- {
- this.key = null;
- this.userName = null;
- this.dynamic = null;
- this.profile = new ProfileMapImpl(this);
- this.roles = null;
- this.registrationDate = null;
- this.enabled = false;
- }
-
- /**
- *
- */
- public DBUserImpl(String userName)
- {
- this.key = null;
- this.userName = userName;
- this.dynamic = new HashMap();
- this.profile = new ProfileMapImpl(this);
- this.roles = new HashSet();
- this.registrationDate = new Date();
- this.enabled = false;
- }
-
- /** Called by hibernate. */
- public Long getKey()
- {
- return key;
- }
-
- /** Called by hibernate. */
- protected void setKey(Long key)
- {
- this.key = key;
- }
-
- /** Called by hibernate. */
- protected void setUserName(String userName)
- {
- this.userName = userName;
- }
-
- /** Called by Hibernate. */
- protected Map getDynamic()
- {
- return dynamic;
- }
-
- /** Called by Hibernate. */
- protected void setDynamic(Map dynamic)
- {
- this.dynamic = dynamic;
- }
-
- // User implementation **********************************************************************************************
-
- /**
- *
- */
- public Object getId()
- {
- return key;
- }
-
- /**
- *
- */
- public String getUserName()
- {
- return userName;
- }
-
- /**
- *
- */
- public String getGivenName()
- {
- return givenName;
- }
-
- public void setGivenName(String givenName)
- {
- this.givenName = givenName;
- }
-
- /**
- *
- */
- public String getFamilyName()
- {
- return familyName;
- }
-
- public void setFamilyName(String familyName)
- {
- this.familyName = familyName;
- }
-
- public void updatePassword(String password)
- {
- this.password = Tools.md5AsHexString(password);
- }
-
- /**
- *
- */
- public String getRealEmail()
- {
- return realEmail;
- }
-
- /**
- *
- */
- public void setRealEmail(String realEmail)
- {
- this.realEmail = realEmail;
- }
-
- /**
- *
- */
- public String getFakeEmail()
- {
- return fakeEmail;
- }
-
- /**
- *
- */
- public void setFakeEmail(String fakeEmail)
- {
- this.fakeEmail = fakeEmail;
- }
-
- /**
- *
- */
- public Date getRegistrationDate()
- {
- return registrationDate;
- }
-
- /**
- *
- */
- public void setRegistrationDate(Date registrationDate)
- {
- this.registrationDate = registrationDate;
- }
-
- /**
- *
- */
- public boolean getViewRealEmail()
- {
- return viewRealEmail;
- }
-
- /**
- *
- */
- public void setViewRealEmail(boolean viewRealEmail)
- {
- this.viewRealEmail = viewRealEmail;
- }
-
- /**
- *
- */
- public boolean getEnabled()
- {
- return enabled;
- }
-
- /**
- *
- */
- public void setEnabled(boolean enable)
- {
- this.enabled = enable;
- }
-
- /**
- *
- */
- public ProfileMap getProfile()
- {
- return profile;
- }
-
- public String getPassword()
- {
- return password;
- }
-
- public void setPassword(String password)
- {
- this.password = password;
- }
-
- /** Returns the roles related to this user. */
- public Set getRoles()
- {
- return roles;
- }
-
- /** Update the roles. */
- public void setRoles(Set roles)
- {
- this.roles = roles;
- this.roleNames = null;
- }
-
- // Dynamic attributes
-
- /** Implemented as a dynamic attribute (see #INFO_USER_LAST_LOGIN_DATE). */
- public Date getLastVisitDate()
- {
- Date date = null;
- String dateAsString = (String)getDynamic().get(User.INFO_USER_LAST_LOGIN_DATE);
- if (dateAsString != null)
- {
- try
- {
- long dateAsLong = Long.parseLong(dateAsString);
- date = new Date(dateAsLong);
- }
- catch (NumberFormatException e)
- {
- log.error("Bad date format " + dateAsString + " try to remove it", e);
- getDynamic().remove(User.INFO_USER_LAST_LOGIN_DATE);
- }
- }
- return date;
- }
-
- public void setLastVisitDate(Date date)
- {
- if (date == null)
- {
- getDynamic().remove(User.INFO_USER_LAST_LOGIN_DATE);
- }
- else
- {
- long dateAsLong = date.getTime();
- String dateAsString = Long.toString(dateAsLong);
- getDynamic().put(User.INFO_USER_LAST_LOGIN_DATE, dateAsString);
- }
- }
-
- /** Implemented as a dynamic attribute (see #INFO_USER_SIGNATURE). */
- public String getSignature()
- {
- return (String)getDynamic().get(User.INFO_USER_SIGNATURE);
- }
-
- public void setSignature(String signature)
- {
- getDynamic().put(User.INFO_USER_SIGNATURE, signature);
- }
-
- /** Implemented as a dynamic attribute (see #INFO_USER_LOCALE). */
- public Locale getPreferredLocale()
- {
- Locale locale = null;
- String localeAsString = (String)getDynamic().get(User.INFO_USER_LOCALE);
- if (localeAsString != null)
- {
- LocaleInfo info = LocaleInfo.decodeLocaleInfo(localeAsString);
- if (info != null)
- {
- locale = info.getLocale();
- }
- }
- return locale;
- }
-
- public void setPreferredLocale(Locale locale)
- {
- if (locale == null)
- {
- getDynamic().remove(User.INFO_USER_LOCALE);
- }
- else
- {
- String localeAsString = locale.toString();
- getDynamic().put(User.INFO_USER_LOCALE, localeAsString);
- }
- }
-
- public String getTheme()
- {
- return (String)getDynamic().get(User.INFO_USER_THEME);
- }
-
- public void setTheme(String themeId)
- {
- if ((themeId == null) || (themeId.equals("")))
- {
- getDynamic().remove(User.INFO_USER_THEME);
- }
- else
- {
- getDynamic().put(User.INFO_USER_THEME, themeId);
- }
- }
-
- public boolean validatePassword(String password)
- {
- if (password != null)
- {
- String hashedPassword = Tools.md5AsHexString(password);
- return hashedPassword.equals(this.password);
- }
- return false;
- }
-
- /** Return all the role names of the user. */
- public Set getRoleNames()
- {
- if (roleNames == null)
- {
- Iterator it = roles.iterator();
- roleNames = new HashSet();
- while (it.hasNext())
- {
- roleNames.add(((Role)it.next()).getName());
- }
- }
- return roleNames;
- }
-
- /**
- *
- */
- public String toString()
- {
- return "User[" + key + "," + userName + "]";
- }
-
- /** An accessor that maps a user field to a property name. */
- static abstract class PropertyAccessor
- {
-
- protected final String propertyName;
- protected final Field field;
- protected final boolean writable;
- protected final boolean nullable;
-
- public PropertyAccessor(String propertyName, String fieldName, boolean writable, boolean nullable)
- {
- try
- {
- this.propertyName = propertyName;
- this.writable = writable;
- this.field = DBUserImpl.class.getDeclaredField(fieldName);
- this.nullable = nullable;
- }
- catch (NoSuchFieldException e)
- {
- throw new Error(e);
- }
- }
-
- public String getPropertyName()
- {
- return propertyName;
- }
-
- public boolean isNullable()
- {
- return nullable;
- }
-
- public boolean isWritable()
- {
- return writable;
- }
-
- /**
- * @param instance the user instance
- * @param string the value
- * @throws IllegalArgumentException if the string cannot be converted to an object
- */
- public void set(Object instance, String string) throws IllegalArgumentException
- {
- try
- {
- if (string == null)
- {
- field.set(instance, null);
- }
- else
- {
- Object object = toObject(string);
- field.set(instance, object);
- }
- }
- catch (IllegalAccessException e)
- {
- throw new Error(e);
- }
- }
-
- /**
- * @param instance the user instance
- * @return the converted value
- * @throws IllegalArgumentException if the object cannot be converted to a string
- */
- public String get(Object instance) throws IllegalArgumentException
- {
- try
- {
- Object object = field.get(instance);
- if (object == null)
- {
- return null;
- }
- else
- {
- return toString(object);
- }
- }
- catch (IllegalAccessException e)
- {
- throw new Error(e);
- }
- }
-
- /**
- * Perform the to object conversion.
- *
- * @param value the value to convert
- * @return the converted value
- * @throws IllegalArgumentException if the string cannot be converted to an object
- */
- protected abstract Object toObject(String value) throws IllegalArgumentException;
-
- /**
- * Perform the to strong conversion.
- *
- * @param value the value to convert
- * @return the converted value
- * @throws IllegalArgumentException if the object cannot be converted to a string
- */
- protected abstract String toString(Object value);
-
- public String toString()
- {
- return "PropertyAccessor[" + propertyName + "," + field + "]";
- }
- }
-
- static class StringPropertyAccessor extends DBUserImpl.PropertyAccessor
- {
- public StringPropertyAccessor(String propertyName, String fieldName, boolean writable, boolean nullable)
- {
- super(propertyName, fieldName, writable, nullable);
- }
-
- protected Object toObject(String value)
- {
- return value;
- }
-
- protected String toString(Object value)
- {
- return (String)value;
- }
- }
-
- static class BooleanPropertyAccessor extends DBUserImpl.PropertyAccessor
- {
- public BooleanPropertyAccessor(String propertyName, String fieldName, boolean writable, boolean nullable)
- {
- super(propertyName, fieldName, writable, nullable);
- }
-
- protected Object toObject(String value) throws IllegalArgumentException
- {
- if ("true".equalsIgnoreCase(value))
- {
- return Boolean.TRUE;
- }
- else if ("false".equalsIgnoreCase(value))
- {
- return Boolean.FALSE;
- }
- else
- {
- throw new IllegalArgumentException("The value " + value + " cannot be converted to boolean for accessor " + toString());
- }
- }
-
- protected String toString(Object value)
- {
- return value.toString();
- }
- }
-
- static class DatePropertyAccessor extends DBUserImpl.PropertyAccessor
- {
- private static final ThreadLocal formatLocal = new ThreadLocal()
- {
- protected Object initialValue()
- {
- return new SimpleDateFormat();
- }
- };
-
- public DatePropertyAccessor(String propertyName, String fieldName, boolean writable, boolean nullable)
- {
- super(propertyName, fieldName, writable, nullable);
- }
-
- protected Object toObject(String value) throws IllegalArgumentException
- {
- try
- {
- DateFormat format = (DateFormat)formatLocal.get();
- Date date = format.parse(value);
- return date;
- }
- catch (ParseException e)
- {
- throw new IllegalArgumentException();
- }
- }
-
- protected String toString(Object value)
- {
- Date date = (Date)value;
- DateFormat format = (DateFormat)formatLocal.get();
- return format.format(date);
- }
- }
-}
Added: trunk/identity/src/main/org/jboss/portal/identity2/experimental/db/HibernateHelper.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/db/HibernateHelper.java 2006-12-06 09:43:49 UTC (rev 5770)
+++ trunk/identity/src/main/org/jboss/portal/identity2/experimental/db/HibernateHelper.java 2006-12-13 15:13:33 UTC (rev 5829)
@@ -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.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();
+
+ }
+
+}
Deleted: trunk/identity/src/main/org/jboss/portal/identity2/experimental/db/HibernateMembershipModuleImpl.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/db/HibernateMembershipModuleImpl.java 2006-12-06 09:43:49 UTC (rev 5770)
+++ trunk/identity/src/main/org/jboss/portal/identity2/experimental/db/HibernateMembershipModuleImpl.java 2006-12-13 15:13:33 UTC (rev 5829)
@@ -1,61 +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.identity.IdentityException;
-
-import java.util.Set;
-
-/**
- * @author <a href="mailto:boleslaw dot dawidowicz at jboss.org">Boleslaw Dawidowicz</a>
- * @version $Revision: 1.1 $
- */
-public class HibernateMembershipModuleImpl extends MembershipModuleService
-{
- public Set getRoles(User user) throws IdentityException
- {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public Set getUsers(Role role) throws IdentityException
- {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public void assignUsers(Role role, Set users) throws IdentityException
- {
- //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public void assignRoles(User user, Set roles) throws IdentityException
- {
- //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public Set findRoleMembers(String roleName, int offset, int limit, String userNameFilter) throws IdentityException
- {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
-}
Copied: trunk/identity/src/main/org/jboss/portal/identity2/experimental/db/HibernateMembershipModuleImpl.java (from rev 5809, trunk/identity/src/main/org/jboss/portal/identity2/db/HibernateMembershipModuleImpl.java)
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/db/HibernateMembershipModuleImpl.java 2006-12-12 18:42:45 UTC (rev 5809)
+++ trunk/identity/src/main/org/jboss/portal/identity2/experimental/db/HibernateMembershipModuleImpl.java 2006-12-13 15:13:33 UTC (rev 5829)
@@ -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.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/identity2/experimental/db/HibernateRoleImpl.java (from rev 5746, trunk/identity/src/main/org/jboss/portal/identity2/db/DBRoleImpl.java)
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/db/DBRoleImpl.java 2006-11-30 22:53:29 UTC (rev 5746)
+++ trunk/identity/src/main/org/jboss/portal/identity2/experimental/db/HibernateRoleImpl.java 2006-12-13 15:13:33 UTC (rev 5829)
@@ -0,0 +1,206 @@
+/*
+* 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);
+ }
+}
+
+
Deleted: trunk/identity/src/main/org/jboss/portal/identity2/experimental/db/HibernateRoleModuleImpl.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/db/HibernateRoleModuleImpl.java 2006-12-06 09:43:49 UTC (rev 5770)
+++ trunk/identity/src/main/org/jboss/portal/identity2/experimental/db/HibernateRoleModuleImpl.java 2006-12-13 15:13:33 UTC (rev 5829)
@@ -1,388 +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 org.jboss.portal.identity.IdentityException;
-import org.jboss.portal.identity2.User;
-import org.jboss.portal.common.util.Tools;
-import org.jboss.portal.identity2.service.RoleModuleService;
-import org.hibernate.SessionFactory;
-import org.hibernate.Session;
-import org.hibernate.Criteria;
-import org.hibernate.HibernateException;
-import org.hibernate.Query;
-import org.hibernate.criterion.Restrictions;
-
-import javax.naming.InitialContext;
-import java.util.Set;
-import java.util.Iterator;
-import java.util.HashSet;
-import java.util.Collections;
-
-/**
- * @author <a href="mailto:julien@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(HibernateUserModuleImpl.class);
-
- /** . */
- protected String sessionFactoryJNDIName;
-
- /** . */
- protected SessionFactory sessionFactory;
-
- public String getSessionFactoryJNDIName()
- {
- return sessionFactoryJNDIName;
- }
-
- public void setSessionFactoryJNDIName(String sessionFactoryJNDIName)
- {
- this.sessionFactoryJNDIName = sessionFactoryJNDIName;
- }
-
- public SessionFactory getSessionFactory()
- {
- return sessionFactory;
- }
-
- protected void startService() throws Exception
- {
- //
- sessionFactory = (SessionFactory)new InitialContext().lookup(sessionFactoryJNDIName);
-
- super.startService();
- }
-
- protected void stopService() throws Exception
- {
- sessionFactory = null;
-
- super.stopService();
-
- //
-
- }
-
- public Role findRoleByName(String name) throws IdentityException
- {
- if (name != null)
- {
- try
- {
- Session session = getCurrentSession();
- Criteria criteria = session.createCriteria(DBRoleImpl.class);
- criteria.add(Restrictions.naturalId().set("name", name));
- criteria.setCacheable(true);
- DBRoleImpl role = (DBRoleImpl)criteria.uniqueResult();
- if (role == null)
- {
- throw new IdentityException("No such role " + name);
- }
- return role;
- }
- catch (HibernateException e)
- {
- String message = "Cannot find role by name " + name;
- log.error(message, e);
- throw new IdentityException(message, e);
- }
- }
- else
- {
- throw new IllegalArgumentException("name cannot be null");
- }
- }
-
- public Set findRolesByNames(String[] names) throws IdentityException
- {
- if (names != null)
- {
- try
- {
- Session session = getCurrentSession();
- StringBuffer queryString = new StringBuffer("from DBRoleImpl as g where g.name=?");
- for (int i = 1; i < names.length; i++)
- {
- queryString.append(" or g.name=?");
- }
- Query query = session.createQuery(queryString.toString());
- for (int i = 0; i < names.length; i++)
- {
- query.setString(i, names[i]);
- }
- Iterator iterator = query.iterate();
- return Tools.toSet(iterator);
- }
- catch (HibernateException e)
- {
- String message = "Cannot find roles";
- log.error(message, e);
- throw new IdentityException(message, e);
- }
- }
- else
- {
- throw new IllegalArgumentException("name cannot be null");
- }
- }
-
- public Role findRoleById(String id) throws IllegalArgumentException, IdentityException
- {
- if (id == null)
- {
- throw new IllegalArgumentException("The id is null");
- }
- try
- {
- return findRoleById(new Long(id));
- }
- catch (NumberFormatException e)
- {
- throw new IllegalArgumentException("Cannot parse id into an long " + id);
- }
- }
-
- public Role findRoleById(Object id) throws IdentityException
- {
- if (id instanceof Long)
- {
- try
- {
- Session session = getCurrentSession();
- DBRoleImpl role = (DBRoleImpl)session.get(DBRoleImpl.class, (Long)id);
- if (role == null)
- {
- throw new IdentityException("No role found for " + id);
- }
- return role;
- }
- catch (HibernateException e)
- {
- String message = "Cannot find role by id " + id;
- log.error(message, e);
- throw new IdentityException(message, e);
- }
- }
- else
- {
- throw new IllegalArgumentException("The id is not an long : " + id);
- }
- }
-
- public Role createRole(String name, String displayName) throws IdentityException
- {
- if (name != null)
- {
- try
- {
- DBRoleImpl role = new DBRoleImpl(name, displayName);
- Session session = getCurrentSession();
- session.save(role);
- return role;
- }
- catch (HibernateException e)
- {
- String message = "Cannot create role " + name;
- log.error(message, e);
- throw new IdentityException(message, e);
- }
- }
- else
- {
- throw new IllegalArgumentException("name cannot be null");
- }
- }
-
- public void removeRole(Object id) throws IdentityException
- {
- if (id instanceof Long)
- {
- try
- {
- Session session = getCurrentSession();
- DBRoleImpl role = (DBRoleImpl)session.load(DBRoleImpl.class, (Long)id);
- Iterator users = role.getUsers().iterator();
- while (users.hasNext())
- {
- DBUserImpl user = (DBUserImpl)users.next();
- user.getRoles().remove(role);
- }
- session.delete(role);
- session.flush();
- }
- catch (HibernateException e)
- {
- String message = "Cannot remove role " + id;
- log.error(message, e);
- throw new IdentityException(message, e);
- }
- }
- else
- {
- throw new IllegalArgumentException("The id is not an long : " + id);
- }
- }
-
- public int getRolesCount() throws IdentityException
- {
- try
- {
- Session session = getCurrentSession();
- Query query = session.createQuery("select count(g.id) from DBRoleImpl as g");
- return ((Number)query.uniqueResult()).intValue();
- }
- catch (HibernateException e)
- {
- String message = "Cannot count roles";
- log.error(message, e);
- throw new IdentityException(message, e);
- }
- }
-
- public Set findRoles() throws IdentityException
- {
- try
- {
- Session session = getCurrentSession();
- Query query = session.createQuery("from DBRoleImpl");
- Iterator iterator = query.iterate();
- return Tools.toSet(iterator);
- }
- catch (HibernateException e)
- {
- String message = "Cannot find roles";
- log.error(message, e);
- throw new IdentityException(message, e);
- }
- }
-
- public Set findRoleMembers(String roleName, int offset, int limit, String userNameFilter) throws IdentityException
- {
- if (roleName != null)
- {
- try
- {
- Session session = getCurrentSession();
-
- DBUserImpl userimpl = new DBUserImpl();
- userimpl.setEnabled(true);
-
- Query query;
- if (userNameFilter.trim().length() != 0)
- {
- //
- userNameFilter = "%" + userNameFilter.replaceAll("%", "") + "%";
-
- //
- query = session.createQuery("from DBUserImpl as user left join user.roles role where role.name=:name" + " AND user.userName LIKE :filter");
- query.setString("filter", userNameFilter);
- }
- else
- {
- query = session.createQuery("from DBUserImpl as user left join user.roles role where role.name=:name");
- }
- query.setString("name", roleName);
- query.setFirstResult(offset);
- query.setMaxResults(limit);
-
- Iterator iterator = query.iterate();
- Set result = Tools.toSet(iterator);
-
- Set newResult = new HashSet();
- Iterator cleaner = result.iterator();
- while (cleaner.hasNext())
- {
- Object[] oArr = (Object[])cleaner.next();
- newResult.add(oArr[0]);
- }
-
- return newResult;
- }
- catch (HibernateException e)
- {
- String message = "Cannot find role " + roleName;
- log.error(message, e);
- throw new IdentityException(message, e);
- }
- }
- else
- {
- throw new IllegalArgumentException("id cannot be null");
- }
- }
-
- public void setRoles(User user, Set roles) throws IdentityException
- {
- if (!(user instanceof DBUserImpl))
- {
- throw new IllegalArgumentException("User is not a db user");
- }
-
- // We make a defensive copy and update with a new set
- Set copy = new HashSet();
- for (Iterator i = roles.iterator(); i.hasNext();)
- {
- Object o = i.next();
- if (o instanceof DBRoleImpl)
- {
- copy.add(o);
- }
- else
- {
- throw new IllegalArgumentException("Only db roles can be accepted");
- }
- }
-
- // Assign new roles
- DBUserImpl ui = (DBUserImpl)user;
- ui.setRoles(copy);
- }
-
- public Set getRoles(User user) throws IdentityException
- {
- if (!(user instanceof DBUserImpl))
- {
- throw new IllegalArgumentException("User is not a db user");
- }
-
- // We return an immutable set to avoid modifications
- DBUserImpl ui = (DBUserImpl)user;
- return Collections.unmodifiableSet(ui.getRoles());
- }
-
- /** Can be subclasses to provide testing in a non JTA environement. */
- protected Session getCurrentSession()
- {
- if (sessionFactory == null)
- {
- throw new IllegalStateException("No session factory");
- }
- return sessionFactory.getCurrentSession();
- }
-}
Copied: trunk/identity/src/main/org/jboss/portal/identity2/experimental/db/HibernateRoleModuleImpl.java (from rev 5809, trunk/identity/src/main/org/jboss/portal/identity2/db/HibernateRoleModuleImpl.java)
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/db/HibernateRoleModuleImpl.java 2006-12-12 18:42:45 UTC (rev 5809)
+++ trunk/identity/src/main/org/jboss/portal/identity2/experimental/db/HibernateRoleModuleImpl.java 2006-12-13 15:13:33 UTC (rev 5829)
@@ -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.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/identity2/experimental/db/HibernateUserImpl.java (from rev 5746, trunk/identity/src/main/org/jboss/portal/identity2/db/DBUserImpl.java)
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/db/DBUserImpl.java 2006-11-30 22:53:29 UTC (rev 5746)
+++ trunk/identity/src/main/org/jboss/portal/identity2/experimental/db/HibernateUserImpl.java 2006-12-13 15:13:33 UTC (rev 5829)
@@ -0,0 +1,324 @@
+/*
+* 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);
+ }
+}
Deleted: trunk/identity/src/main/org/jboss/portal/identity2/experimental/db/HibernateUserModuleImpl.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/db/HibernateUserModuleImpl.java 2006-12-06 09:43:49 UTC (rev 5770)
+++ trunk/identity/src/main/org/jboss/portal/identity2/experimental/db/HibernateUserModuleImpl.java 2006-12-13 15:13:33 UTC (rev 5829)
@@ -1,315 +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.service.UserModuleService;
-import org.jboss.portal.identity.IdentityException;
-import org.jboss.portal.identity.NoSuchUserException;
-import org.jboss.portal.common.util.JNDI;
-import org.jboss.portal.common.util.Tools;
-import org.hibernate.SessionFactory;
-import org.hibernate.Session;
-import org.hibernate.Query;
-import org.hibernate.HibernateException;
-
-import javax.naming.InitialContext;
-import java.io.Serializable;
-import java.util.Set;
-import java.util.Iterator;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet </a>
- * @version $Revision: 5448 $
- * @portal.core
- */
-public class HibernateUserModuleImpl extends UserModuleService
-{
-
- /** . */
- private static final org.jboss.logging.Logger log = org.jboss.logging.Logger.getLogger(HibernateUserModuleImpl.class);
- /** . */
- protected SessionFactory sessionFactory;
-
- /** . */
- protected String sessionFactoryJNDIName;
-
- /** . */
- protected String jndiName;
-
- /** . */
- protected JNDI.Binding jndiBinding;
-
- public HibernateUserModuleImpl()
- {
- }
-
- protected void startService() throws Exception
- {
- //
- sessionFactory = (SessionFactory)new InitialContext().lookup(sessionFactoryJNDIName);
-
- //
- if (jndiName != null)
- {
- jndiBinding = new JNDI.Binding(jndiName, this);
- jndiBinding.bind();
- }
- }
-
- protected void stopService() throws Exception
- {
- if (jndiBinding != null)
- {
- jndiBinding.unbind();
- jndiBinding = null;
- }
-
- //
- sessionFactory = null;
- }
-
- public SessionFactory getSessionFactory()
- {
- return sessionFactory;
- }
-
- public String getSessionFactoryJNDIName()
- {
- return sessionFactoryJNDIName;
- }
-
- public void setSessionFactoryJNDIName(String sessionFactoryJNDIName)
- {
- this.sessionFactoryJNDIName = sessionFactoryJNDIName;
- }
-
- public String getJNDIName()
- {
- return jndiName;
- }
-
- public void setJNDIName(String jndiName)
- {
- this.jndiName = jndiName;
- }
-
- public User findUserByUserName(String userName) throws IdentityException
- {
- if (userName != null)
- {
- try
- {
- Session session = getCurrentSession();
- Query query = session.createQuery("from DBDBUserImpl where userName=:userName");
- query.setParameter("userName", userName);
- query.setCacheable(true);
- DBUserImpl user = (DBUserImpl)query.uniqueResult();
- if (user == null)
- {
- throw new NoSuchUserException("No such user " + userName);
- }
- return user;
- }
- catch (HibernateException e)
- {
- String message = "Cannot find user by name " + userName;
- log.error(message, e);
- throw new IdentityException(message, e);
- }
- }
- else
- {
- throw new IllegalArgumentException("user name cannot be null");
- }
- }
-
- public User findUserById(String id) throws IllegalArgumentException, IdentityException, NoSuchUserException
- {
- if (id == null)
- {
- throw new IllegalArgumentException("The id is null");
- }
- try
- {
- return findUserById(new Long(id));
- }
- catch (NumberFormatException e)
- {
- throw new IllegalArgumentException("Cannot parse id into an long " + id);
- }
- }
-
- public User findUserById(Object id) throws IllegalArgumentException, IdentityException, NoSuchUserException
- {
- if (id instanceof Long)
- {
- try
- {
- Session session = getCurrentSession();
- DBUserImpl user = (DBUserImpl)session.get(DBUserImpl.class, (Long)id);
- if (user == null)
- {
- throw new NoSuchUserException("No user found for " + id);
- }
- return user;
- }
- catch (HibernateException e)
- {
- String message = "Cannot find user by id " + id;
- log.error(message, e);
- throw new IdentityException(message, e);
- }
- }
- else
- {
- throw new IllegalArgumentException("The id is not an long : " + id);
- }
- }
-
- public User createUser(String userName, String password, String realEmail) throws IdentityException
- {
- if (userName != null)
- {
- try
- {
- DBUserImpl user = new DBUserImpl(userName);
- user.updatePassword(password);
- user.setRealEmail(realEmail);
- Session session = getCurrentSession();
- session.save(user);
- return user;
- }
- catch (HibernateException e)
- {
- String message = "Cannot create user " + userName;
- log.error(message, e);
- throw new IdentityException(message, e);
- }
- }
- else
- {
- throw new IllegalArgumentException("name cannot be null");
- }
- }
-
- public void removeUser(Object id) throws IdentityException
- {
- if (id instanceof Long)
- {
- try
- {
- Session session = getCurrentSession();
- DBUserImpl user = (DBUserImpl)session.load(DBUserImpl.class, (Serializable)id);
- if (user == null)
- {
- throw new NoSuchUserException("No such user " + id);
- }
- session.delete(user);
- session.flush();
- }
- catch (HibernateException e)
- {
- String message = "Cannot remove user " + id;
- log.error(message, e);
- throw new IdentityException(message, e);
- }
- }
- else
- {
- throw new IllegalArgumentException("The id is not an long : " + id);
- }
- }
-
- public Set findUsers(int offset, int limit) throws IdentityException
- {
- try
- {
- Session session = getCurrentSession();
- Query query = session.createQuery("from DBDBUserImpl");
- query.setFirstResult(offset);
- query.setMaxResults(limit);
- Iterator iterator = query.iterate();
- return Tools.toSet(iterator);
- }
- catch (HibernateException e)
- {
- String message = "Cannot find user range [" + offset + "," + limit + "]";
- log.error(message, e);
- throw new IdentityException(message, e);
- }
- }
-
- public Set findUsersFilteredByUserName(String filter, int offset, int limit) throws IdentityException
- {
- try
- {
- // Remove all occurences of % and add ours
- filter = "%" + filter.replaceAll("%", "") + "%";
-
- //
- Session session = getCurrentSession();
- Query query = session.createQuery("from DBDBUserImpl as u where u.userName like :filter");
- query.setString("filter", filter);
- query.setFirstResult(offset);
- query.setMaxResults(limit);
- Iterator iterator = query.iterate();
- return Tools.toSet(iterator);
- }
- catch (HibernateException e)
- {
- String message = "Cannot find user range [" + offset + "," + limit + "]";
- log.error(message, e);
- throw new IdentityException(message, e);
- }
- }
-
- public int getUserCount() throws IdentityException
- {
- try
- {
- Session session = getCurrentSession();
- Query query = session.createQuery("select count(u.key) from DBDBUserImpl as u");
- return ((Number)query.uniqueResult()).intValue();
- }
- catch (HibernateException e)
- {
- String message = "Cannot count users";
- log.error(message, e);
- throw new IdentityException(message, e);
- }
- }
-
- /**
- * Can be subclasses to provide testing in a non JTA environement.
- *
- * @throws IllegalStateException if no session factory is present
- */
- protected Session getCurrentSession() throws IllegalStateException
- {
- if (sessionFactory == null)
- {
- throw new IllegalStateException("No session factory");
- }
- return sessionFactory.getCurrentSession();
- }
-}
Copied: trunk/identity/src/main/org/jboss/portal/identity2/experimental/db/HibernateUserModuleImpl.java (from rev 5809, trunk/identity/src/main/org/jboss/portal/identity2/db/HibernateUserModuleImpl.java)
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/db/HibernateUserModuleImpl.java 2006-12-12 18:42:45 UTC (rev 5809)
+++ trunk/identity/src/main/org/jboss/portal/identity2/experimental/db/HibernateUserModuleImpl.java 2006-12-13 15:13:33 UTC (rev 5829)
@@ -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.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();
+ }
+}
Deleted: trunk/identity/src/main/org/jboss/portal/identity2/experimental/db/HibernateUserProfileModuleImpl.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/db/HibernateUserProfileModuleImpl.java 2006-12-06 09:43:49 UTC (rev 5770)
+++ trunk/identity/src/main/org/jboss/portal/identity2/experimental/db/HibernateUserProfileModuleImpl.java 2006-12-13 15:13:33 UTC (rev 5829)
@@ -1,110 +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.db.DBUserImpl;
-import org.jboss.portal.identity2.User;
-import org.jboss.portal.identity2.service.UserProfileModuleService;
-
-import java.util.Map;
-
-/**
- * @author <a href="mailto:boleslaw.dawidowicz@jboss.org">Boleslaw Dawidowicz</a>
- * @version $Revision: 1.1 $
- */
-public class HibernateUserProfileModuleImpl extends UserProfileModuleService
-{
- 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");
- }
-
- DBUserImpl dbUser = null;
-
- if (user instanceof DBUserImpl)
- {
- dbUser = (DBUserImpl)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");
- }
-
- DBUserImpl dbUser = null;
-
- if (user instanceof DBUserImpl)
- {
- dbUser = (DBUserImpl)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");
- }
-
- DBUserImpl dbUser = null;
-
- if (user instanceof DBUserImpl)
- {
- dbUser = (DBUserImpl)user;
- }
- else
- {
- throw new IllegalArgumentException("This UserProfileModule implementation support only DBDBUserImpl objects");
- }
-
-
- throw new UnsupportedOperationException("Not yet implemented");
- }
-}
Copied: trunk/identity/src/main/org/jboss/portal/identity2/experimental/db/HibernateUserProfileModuleImpl.java (from rev 5809, trunk/identity/src/main/org/jboss/portal/identity2/db/HibernateUserProfileModuleImpl.java)
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/db/HibernateUserProfileModuleImpl.java 2006-12-12 18:42:45 UTC (rev 5809)
+++ trunk/identity/src/main/org/jboss/portal/identity2/experimental/db/HibernateUserProfileModuleImpl.java 2006-12-13 15:13:33 UTC (rev 5829)
@@ -0,0 +1,173 @@
+/******************************************************************************
+ * 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();
+ }
+}
Added: trunk/identity/src/main/org/jboss/portal/identity2/experimental/db/IdentitySessionFactoryBinder.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/db/IdentitySessionFactoryBinder.java 2006-12-06 09:43:49 UTC (rev 5770)
+++ trunk/identity/src/main/org/jboss/portal/identity2/experimental/db/IdentitySessionFactoryBinder.java 2006-12-13 15:13:33 UTC (rev 5829)
@@ -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.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;
+ }
+}
Deleted: trunk/identity/src/main/org/jboss/portal/identity2/experimental/db/ProfileMapImpl.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/identity2/db/ProfileMapImpl.java 2006-12-06 09:43:49 UTC (rev 5770)
+++ trunk/identity/src/main/org/jboss/portal/identity2/experimental/db/ProfileMapImpl.java 2006-12-13 15:13:33 UTC (rev 5829)
@@ -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.DBUserImpl;
-
-import java.util.Iterator;
-import java.util.Set;
-import java.util.HashSet;
-import java.util.Collection;
-import java.util.ArrayList;
-import java.util.Map;
-import java.util.HashMap;
-import java.util.Collections;
-
-/**
- * A mutable map that expose user properties.
- *
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 5448 $
- */
-public class ProfileMapImpl implements ProfileMap
-{
-
- /** . */
- private DBUserImpl user;
-
- public ProfileMapImpl(DBUserImpl user)
- {
- if (user == null)
- {
- throw new IllegalArgumentException();
- }
- this.user = user;
- }
-
- public boolean isReadOnly(Object key)
- {
- if (key == null)
- {
- return false;
- }
- if (key instanceof String == false)
- {
- throw new ClassCastException("Key must be a string");
- }
- DBUserImpl.PropertyAccessor accessor = (DBUserImpl.PropertyAccessor)DBUserImpl.ACCESSORS.get(key);
- return accessor != null && !accessor.isWritable();
- }
-
- public int size()
- {
- return DBUserImpl.ACCESSORS.size() + user.getDynamic().size();
- }
-
- public boolean isEmpty()
- {
- return false;
- }
-
- /** @throws ClassCastException if the key is not an instance of string */
- public boolean containsKey(Object key) throws ClassCastException
- {
- if (key == null)
- {
- return false;
- }
- if (key instanceof String == false)
- {
- throw new ClassCastException("Key must be a string");
- }
- DBUserImpl.PropertyAccessor accessor = (DBUserImpl.PropertyAccessor)DBUserImpl.ACCESSORS.get(key);
- if (accessor != null)
- {
- return true;
- }
- return user.getDynamic().containsKey(key);
- }
-
- /** @throws ClassCastException if the value is not an instance of string */
- public boolean containsValue(Object value) throws ClassCastException
- {
- if (value == null)
- {
- throw new NullPointerException("Key cannot be null");
- }
- if (value instanceof String == false)
- {
- throw new ClassCastException("Value must be a string");
- }
- for (Iterator i = DBUserImpl.ACCESSORS.values().iterator(); i.hasNext();)
- {
- DBUserImpl.PropertyAccessor accessor = (DBUserImpl.PropertyAccessor)i.next();
- Object value2 = accessor.get(user);
- if (value == value2 || value.equals(value2))
- {
- return true;
- }
- }
- return user.getDynamic().containsValue(value);
- }
-
- /** @throws ClassCastException if the key is not an instance of string */
- public Object get(Object key)
- {
- if (key == null)
- {
- return null;
- }
- if (key instanceof String == false)
- {
- throw new ClassCastException("Key must be a string");
- }
- DBUserImpl.PropertyAccessor accessor = (DBUserImpl.PropertyAccessor)DBUserImpl.ACCESSORS.get(key);
- if (accessor != null)
- {
- return accessor.get(user);
- }
- return user.getDynamic().get(key);
- }
-
- /**
- * Put a value in the dynamic map.
- * <p/>
- * If the key is not an instance of string then an IllegalArgumentException is thrown. If the value is mapped to an
- * accessor of a non writable field then an IllegalArgumentException is thrown. If the value is mapped to an accessor
- * of a non nullable field and the field is null then an IllegalArgumentException is thrown.
- *
- * @throws IllegalArgumentException
- */
- public Object put(Object key, Object newValue) throws IllegalArgumentException
- {
- if (key == null)
- {
- return null;
- }
- if (key instanceof String == false)
- {
- throw new ClassCastException("Key is not a String");
- }
- DBUserImpl.PropertyAccessor accessor = (DBUserImpl.PropertyAccessor)DBUserImpl.ACCESSORS.get(key);
- if (accessor != null)
- {
- if (newValue == null && !accessor.isNullable())
- {
- throw new NullPointerException("Key " + key + " is not nullable");
- }
- if (!accessor.isWritable())
- {
- throw new IllegalArgumentException("Key " + key + " is not modifiable");
- }
- else
- {
- Object oldValue = accessor.get(user);
- accessor.set(user, (String)newValue);
- return oldValue;
- }
- }
- if (newValue instanceof String == false)
- {
- throw new ClassCastException("Dynamic value must be a string");
- }
- return user.getDynamic().put(key, newValue);
- }
-
- /**
- * Only affect dynamic properties, otherwise it throws an IllegalArgumentException.
- *
- * @throws IllegalArgumentException if the key is a not a dynamic property
- */
- public Object remove(Object key) throws IllegalArgumentException
- {
- if (key instanceof String == false)
- {
- throw new ClassCastException("Key is not a String");
- }
- DBUserImpl.PropertyAccessor accessor = (DBUserImpl.PropertyAccessor)DBUserImpl.ACCESSORS.get(key);
- if (accessor != null)
- {
- throw new IllegalArgumentException("Key " + key + " is not removable");
- }
- return user.getDynamic().remove(key);
- }
-
- /** Clear only dynamic properties. */
- public void clear()
- {
- user.getDynamic().clear();
- }
-
- public Set keySet()
- {
- // Get
- Set set = new HashSet(size());
-
- //
- set.addAll(user.getDynamic().keySet());
- set.addAll(DBUserImpl.ACCESSORS.keySet());
- return set;
- }
-
- public Collection values()
- {
- ArrayList collection = new ArrayList(size());
- for (Iterator i = DBUserImpl.ACCESSORS.values().iterator(); i.hasNext();)
- {
- DBUserImpl.PropertyAccessor accessor = (DBUserImpl.PropertyAccessor)i.next();
- collection.add(accessor.get(user));
- }
- collection.addAll(user.getDynamic().values());
- return collection;
- }
-
- /** Returns an immutable collection of entries. */
- public Set entrySet()
- {
- Map copy = new HashMap(user.getDynamic());
- for (Iterator i = DBUserImpl.ACCESSORS.values().iterator(); i.hasNext();)
- {
- DBUserImpl.PropertyAccessor accessor = (DBUserImpl.PropertyAccessor)i.next();
- copy.put(accessor.getPropertyName(), accessor.get(user));
- }
- return Collections.unmodifiableMap(copy).entrySet();
- }
-
- public void putAll(Map map)
- {
- // todo : check all properties ok with changes before proceeding
- for (Iterator i = map.entrySet().iterator(); i.hasNext();)
- {
- Entry entry = (Entry)i.next();
- Object key = entry.getKey();
- if (key instanceof String)
- {
- Object value = entry.getValue();
- DBUserImpl.PropertyAccessor accessor = (DBUserImpl.PropertyAccessor)DBUserImpl.ACCESSORS.get(key);
- if (accessor != null)
- {
- if (accessor.isWritable())
- {
- accessor.set(user, (String)value);
- }
- else
- {
- // julien : Do something better ?
- }
- }
- else
- {
- user.getDynamic().put(key, value);
- }
- }
- }
- }
-}
19 years, 7 months