You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by ep...@apache.org on 2003/08/24 21:41:36 UTC

cvs commit: jakarta-turbine-fulcrum/security/src/java/org/apache/fulcrum/security/spi/hibernate/simple/entity HibernateSimpleUser.java HibernateSimpleRole.java HibernateSimpleGroup.java

epugh       2003/08/24 12:41:35

  Modified:    security/src/java/org/apache/fulcrum/security/spi/hibernate/simple
                        HibernateGroupManagerImpl.java
                        HibernateRoleManagerImpl.java
                        HibernateUserManagerImpl.java
                        HibernatePermissionManagerImpl.java
  Added:       security/src/java/org/apache/fulcrum/security/spi/hibernate/simple
                        BaseHibernateManager.java
               security/src/java/org/apache/fulcrum/security/spi/hibernate/simple/entity
                        HibernateSimpleUser.java HibernateSimpleRole.java
                        HibernateSimpleGroup.java
  Log:
  The Hibernate SPI is now working.
  
  Revision  Changes    Path
  1.3       +37 -164   jakarta-turbine-fulcrum/security/src/java/org/apache/fulcrum/security/spi/hibernate/simple/HibernateGroupManagerImpl.java
  
  Index: HibernateGroupManagerImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-fulcrum/security/src/java/org/apache/fulcrum/security/spi/hibernate/simple/HibernateGroupManagerImpl.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- HibernateGroupManagerImpl.java	23 Aug 2003 21:09:52 -0000	1.2
  +++ HibernateGroupManagerImpl.java	24 Aug 2003 19:41:35 -0000	1.3
  @@ -56,23 +56,14 @@
   
   import net.sf.hibernate.Hibernate;
   import net.sf.hibernate.HibernateException;
  -import net.sf.hibernate.Session;
  -import net.sf.hibernate.Transaction;
  -import net.sf.hibernate.avalon.HibernateService;
   
  -import org.apache.avalon.framework.activity.Disposable;
  -import org.apache.avalon.framework.component.ComponentException;
  -import org.apache.avalon.framework.component.ComponentManager;
  -import org.apache.avalon.framework.component.Composable;
  -import org.apache.avalon.framework.logger.AbstractLogEnabled;
   import org.apache.commons.lang.StringUtils;
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
  -import org.apache.fulcrum.security.RoleManager;
   import org.apache.fulcrum.security.entity.Group;
   import org.apache.fulcrum.security.entity.Role;
  -import org.apache.fulcrum.security.model.simple.entity.SimpleGroup;
   import org.apache.fulcrum.security.model.simple.manager.SimpleGroupManager;
  +import org.apache.fulcrum.security.spi.hibernate.simple.entity.HibernateSimpleGroup;
   import org.apache.fulcrum.security.util.DataBackendException;
   import org.apache.fulcrum.security.util.EntityExistsException;
   import org.apache.fulcrum.security.util.GroupSet;
  @@ -83,28 +74,10 @@
    * @author <a href="mailto:epugh@upstate.com">Eric Pugh</a>
    * @version $Id$
    */
  -public class HibernateGroupManagerImpl extends AbstractLogEnabled implements SimpleGroupManager, Composable, Disposable
  +public class HibernateGroupManagerImpl extends BaseHibernateManager implements SimpleGroupManager
   {
       /** Logging */
       private static Log log = LogFactory.getLog(HibernateGroupManagerImpl.class);
  -    /** Hibernate components */
  -    private HibernateService hibernateService;
  -    private Session session;
  -    private Transaction transaction;
  -    private ComponentManager manager = null;
  -    /** Our role Manager **/
  -    private RoleManager roleManager;
  -    /**
  -    	* @return
  -    	*/
  -    RoleManager getRoleManager() throws ComponentException
  -    {
  -        if (roleManager == null)
  -        {
  -            roleManager = (RoleManager) manager.lookup(RoleManager.ROLE);
  -        }
  -        return roleManager;
  -    }
       /**
       	* Construct a blank Group object.
       	*
  @@ -119,7 +92,7 @@
           Group group;
           try
           {
  -            group = (Group) new SimpleGroup();
  +            group = (Group) new HibernateSimpleGroup();
           }
           catch (Exception e)
           {
  @@ -189,7 +162,7 @@
        * @throws DataBackendException if there is a problem accessing the
        *            storage.
        */
  -    public Group getGroupById(int id) throws DataBackendException, UnknownEntityException
  +    public Group getGroupById(long id) throws DataBackendException, UnknownEntityException
       {
           Group group = getAllGroups().getGroupById(id);
           if (group == null)
  @@ -211,7 +184,7 @@
           try
           {
               session = hibernateService.openSession();
  -            List groups = session.find("from SimpleGroup");
  +            List groups = session.find("from HibernateSimpleGroup");
               groupSet.add(groups);
           }
           catch (HibernateException e)
  @@ -231,28 +204,7 @@
       public synchronized void removeGroup(Group group) throws DataBackendException, UnknownEntityException
       {
           boolean groupExists = false;
  -        try
  -        {
  -            groupExists = checkExists(group);
  -            if (groupExists)
  -            {
  -                session = hibernateService.openSession();
  -                transaction = session.beginTransaction();
  -                session.delete(group);
  -                transaction.commit();
  -            }
  -            else
  -            {
  -                throw new UnknownEntityException("Unknown group '" + group + "'");
  -            }
  -        }
  -        catch (Exception e)
  -        {
  -            log.error("Failed to delete a Group");
  -            log.error(e);
  -            throw new DataBackendException("removeGroup(Group) failed", e);
  -        }
  -
  +        removeEntity(group);
       }
       /**
       	* Renames an existing Group.
  @@ -266,53 +218,15 @@
       public synchronized void renameGroup(Group group, String name) throws DataBackendException, UnknownEntityException
       {
           boolean groupExists = false;
  -        try
  +        groupExists = checkExists(group);
  +        if (groupExists)
           {
  -            groupExists = checkExists(group);
  -            if (groupExists)
  -            {
  -                group.setName(name);
  -                saveGroup(group);
  -            }
  -            else
  -            {
  -                throw new UnknownEntityException("Unknown group '" + group + "'");
  -            }
  +            group.setName(name);
  +            updateEntity(group);
           }
  -        catch (Exception e)
  +        else
           {
  -            throw new DataBackendException("renameGroup(Group,String)", e);
  -        }
  -    }
  -    /**
  -    	* Stores Group's attributes. The Groups is required to exist in the system.
  -    	*
  -    	* @param group The Group to be stored.
  -    	* @throws DataBackendException if there was an error accessing the data
  -    	*         backend.
  -    	* @throws UnknownEntityException if the group does not exist.
  -    	*/
  -    public void saveGroup(Group group) throws DataBackendException, UnknownEntityException
  -    {
  -        boolean groupExists = false;
  -        try
  -        {
  -            groupExists = checkExists(group);
  -            if (groupExists)
  -            {
  -                session = hibernateService.openSession();
  -                transaction = session.beginTransaction();
  -                session.update(group);
  -                transaction.commit();
  -            }
  -            else
  -            {
  -                throw new UnknownEntityException("Unknown group '" + group + "'");
  -            }
  -        }
  -        catch (Exception e)
  -        {
  -            throw new DataBackendException("saveGroup(Group) failed", e);
  +            throw new UnknownEntityException("Unknown group '" + group + "'");
           }
       }
       /**
  @@ -330,7 +244,7 @@
           try
           {
               session = hibernateService.openSession();
  -            groups = session.find("from SimpleGroup sg where sg.name=?", group.getName(), Hibernate.STRING);
  +            groups = session.find("from HibernateSimpleGroup sg where sg.name=?", group.getName(), Hibernate.STRING);
           }
           catch (HibernateException e)
           {
  @@ -343,14 +257,14 @@
           return (groups.size() == 1);
       }
       /**
  -	* Creates a new group with specified attributes.
  -	*
  -	* @param group the object describing the group to be created.
  -	* @return a new Group object that has id set up properly.
  -	* @throws DataBackendException if there was an error accessing the data
  -	*         backend.
  -	* @throws EntityExistsException if the group already exists.
  -	*/
  +    * Creates a new group with specified attributes.
  +    *
  +    * @param group the object describing the group to be created.
  +    * @return a new Group object that has id set up properly.
  +    * @throws DataBackendException if there was an error accessing the data
  +    *         backend.
  +    * @throws EntityExistsException if the group already exists.
  +    */
       public synchronized Group addGroup(Group group) throws DataBackendException, EntityExistsException
       {
           boolean groupExists = false;
  @@ -366,36 +280,18 @@
           {
               throw new EntityExistsException("The group '" + group.getName() + "' already exists");
           }
  -        try
  -        {
  -            session = hibernateService.openSession();
  -            transaction = session.beginTransaction();
  -            session.save(group);
  -            transaction.commit();
  -        }
  -        catch (HibernateException e)
  -        {
  -            log.error("Error adding group", e);
  -            try
  -            {
  -                transaction.rollback();
  -            }
  -            catch (HibernateException he)
  -            {
  -            }
  -            throw new DataBackendException("Failed to create group '" + group.getName() + "'", e);
  -        }
  +        addEntity(group);
           return group;
       }
       /**
  -	  * Grants a Group a Role
  -	  *
  -	  * @param group the Group.
  -	  * @param role the Role.
  -	  * @throws DataBackendException if there was an error accessing the data
  -	  *         backend.
  -	  * @throws UnknownEntityException if group or role is not present.
  -	  */
  +      * Grants a Group a Role
  +      *
  +      * @param group the Group.
  +      * @param role the Role.
  +      * @throws DataBackendException if there was an error accessing the data
  +      *         backend.
  +      * @throws UnknownEntityException if group or role is not present.
  +      */
       public synchronized void grant(Group group, Role role) throws DataBackendException, UnknownEntityException
       {
           boolean groupExists = false;
  @@ -406,7 +302,8 @@
               roleExists = checkExists(role);
               if (groupExists && roleExists)
               {
  -                ((SimpleGroup) group).addRole(role);
  +                ((HibernateSimpleGroup) group).addRole(role);
  +                updateEntity(group);
                   return;
               }
           }
  @@ -442,7 +339,8 @@
               roleExists = checkExists(role);
               if (groupExists && roleExists)
               {
  -                ((SimpleGroup) group).removeRole(role);
  +                ((HibernateSimpleGroup) group).removeRole(role);
  +                updateEntity(group);
                   return;
               }
           }
  @@ -473,31 +371,6 @@
        */
       public boolean checkExists(Role role) throws DataBackendException
       {
  -        try
  -        {
  -            return getRoleManager().checkExists(role);
  -        }
  -        catch (ComponentException ce)
  -        {
  -            throw new DataBackendException("Problem getting role manager", ce);
  -        }
  -    }
  -    /**
  -      * Avalon component lifecycle method
  -      */
  -    public void compose(ComponentManager manager) throws ComponentException
  -    {
  -        this.manager = manager;
  -        hibernateService = (HibernateService) manager.lookup(HibernateService.ROLE);
  -    }
  -    /**
  -    	   * DESTRUCTION: step 2
  -    	   * @see org.apache.avalon.framework.activity.Disposable#dispose()
  -    	   */
  -    public void dispose()
  -    {
  -        hibernateService = null;
  -        manager = null;
  -        roleManager = null;
  +        return getRoleManager().checkExists(role);
       }
  -}
  +}
  \ No newline at end of file
  
  
  
  1.3       +37 -143   jakarta-turbine-fulcrum/security/src/java/org/apache/fulcrum/security/spi/hibernate/simple/HibernateRoleManagerImpl.java
  
  Index: HibernateRoleManagerImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-fulcrum/security/src/java/org/apache/fulcrum/security/spi/hibernate/simple/HibernateRoleManagerImpl.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- HibernateRoleManagerImpl.java	23 Aug 2003 21:09:52 -0000	1.2
  +++ HibernateRoleManagerImpl.java	24 Aug 2003 19:41:35 -0000	1.3
  @@ -56,23 +56,15 @@
   
   import net.sf.hibernate.Hibernate;
   import net.sf.hibernate.HibernateException;
  -import net.sf.hibernate.Session;
  -import net.sf.hibernate.Transaction;
  -import net.sf.hibernate.avalon.HibernateService;
   
  -import org.apache.avalon.framework.activity.Disposable;
  -import org.apache.avalon.framework.component.ComponentException;
  -import org.apache.avalon.framework.component.ComponentManager;
  -import org.apache.avalon.framework.component.Composable;
  -import org.apache.avalon.framework.logger.AbstractLogEnabled;
   import org.apache.commons.lang.StringUtils;
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
  -import org.apache.fulcrum.security.PermissionManager;
   import org.apache.fulcrum.security.entity.Permission;
   import org.apache.fulcrum.security.entity.Role;
   import org.apache.fulcrum.security.model.simple.entity.SimpleRole;
   import org.apache.fulcrum.security.model.simple.manager.SimpleRoleManager;
  +import org.apache.fulcrum.security.spi.hibernate.simple.entity.HibernateSimpleRole;
   import org.apache.fulcrum.security.util.DataBackendException;
   import org.apache.fulcrum.security.util.EntityExistsException;
   import org.apache.fulcrum.security.util.PermissionSet;
  @@ -85,29 +77,10 @@
    * @author <a href="mailto:epugh@upstate.com">Eric Pugh</a>
    * @version $Id$
    */
  -public class HibernateRoleManagerImpl extends AbstractLogEnabled implements SimpleRoleManager, Composable, Disposable
  +public class HibernateRoleManagerImpl extends BaseHibernateManager implements SimpleRoleManager
   {
  -    boolean composed = false;
       /** Logging */
       private static Log log = LogFactory.getLog(HibernateRoleManagerImpl.class);
  -    /** Our permissionManager **/
  -    private PermissionManager permissionManager;
  -    /** Hibernate components */
  -    private HibernateService hibernateService;
  -    private Session session;
  -    private Transaction transaction;
  -    private ComponentManager manager = null;
  -    /**
  -     * @return
  -     */
  -    PermissionManager getPermissionManager() throws ComponentException
  -    {
  -        if (permissionManager == null)
  -        {
  -            permissionManager = (PermissionManager) manager.lookup(PermissionManager.ROLE);
  -        }
  -        return permissionManager;
  -    }
       /**
       	* Construct a blank Role object.
       	*
  @@ -122,7 +95,7 @@
           Role role;
           try
           {
  -            role = (Role) new SimpleRole();
  +            role = (Role) new HibernateSimpleRole();
           }
           catch (Exception e)
           {
  @@ -164,7 +137,6 @@
           {
               throw new UnknownEntityException("The specified role does not exist");
           }
  -        role.setPermissions(getPermissions(role));
           return role;
       }
       /**
  @@ -179,14 +151,13 @@
       	* @throws DataBackendException if there is a problem accessing the
       	*            storage.
       	*/
  -    public Role getRoleById(int id) throws DataBackendException, UnknownEntityException
  +    public Role getRoleById(long id) throws DataBackendException, UnknownEntityException
       {
           Role role = getAllRoles().getRoleById(id);
           if (role == null)
           {
               throw new UnknownEntityException("The specified role does not exist");
           }
  -        role.setPermissions(getPermissions(role));
           return role;
       }
       /**
  @@ -209,7 +180,8 @@
               permissionExists = checkExists(permission);
               if (roleExists && permissionExists)
               {
  -                ((SimpleRole) role).addPermission(permission);
  +                ((HibernateSimpleRole) role).addPermission(permission);
  +                updateEntity(role);
                   return;
               }
           }
  @@ -246,7 +218,8 @@
               permissionExists = checkExists(permission);
               if (roleExists && permissionExists)
               {
  -                ((SimpleRole) role).removePermission(permission);
  +                ((HibernateSimpleRole) role).removePermission(permission);
  +                updateEntity(role);
                   return;
               }
           }
  @@ -284,7 +257,8 @@
               roleExists = checkExists(role);
               if (roleExists)
               {
  -                role.setPermissions(new PermissionSet());
  +                ((SimpleRole) role).setPermissions(new PermissionSet());
  +                updateEntity(role);
                   return;
               }
           }
  @@ -298,35 +272,28 @@
           throw new UnknownEntityException("Unknown role '" + role.getName() + "'");
       }
       /**
  -    	* Renames an existing Role.
  -    	*
  -    	* @param role The object describing the role to be renamed.
  -    	* @param name the new name for the role.
  -    	* @throws DataBackendException if there was an error accessing the data
  -    	*         backend.
  -    	* @throws UnknownEntityException if the role does not exist.
  -    	*/
  +    * Renames an existing Role.
  +    *
  +    * @param role The object describing the role to be renamed.
  +    * @param name the new name for the role.
  +    * @throws DataBackendException if there was an error accessing the data
  +    *         backend.
  +    * @throws UnknownEntityException if the role does not exist.
  +    */
       public synchronized void renameRole(Role role, String name) throws DataBackendException, UnknownEntityException
       {
           boolean roleExists = false;
  -        try
  +        roleExists = checkExists(role);
  +        if (roleExists)
           {
  -            roleExists = checkExists(role);
  -            if (roleExists)
  -            {
  -                role.setName(name);
  -                saveRole(role);
  -                return;
  -            }
  +            role.setName(name);
  +            updateEntity(role);
  +            return;
           }
  -        catch (Exception e)
  +        else
           {
  -            throw new DataBackendException("renameRole(Role,String)", e);
  +            throw new UnknownEntityException("Unknown role '" + role + "'");
           }
  -        finally
  -        {
  -        }
  -        throw new UnknownEntityException("Unknown role '" + role + "'");
       }
       /**
         * Determines if the <code>Role</code> exists in the security system.
  @@ -343,7 +310,7 @@
           try
           {
               session = hibernateService.openSession();
  -            roles = session.find("from SimpleRole sr where sr.name=?", role.getName(), Hibernate.STRING);
  +            roles = session.find("from HibernateSimpleRole sr where sr.name=?", role.getName(), Hibernate.STRING);
           }
           catch (HibernateException e)
           {
  @@ -356,19 +323,19 @@
           return (roles.size() == 1);
       }
       /**
  -	 * Retrieves all roles defined in the system.
  -	 *
  -	 * @return the names of all roles defined in the system.
  -	 * @throws DataBackendException if there was an error accessing the
  -	 *         data backend.
  -	 */
  +     * Retrieves all roles defined in the system.
  +     *
  +     * @return the names of all roles defined in the system.
  +     * @throws DataBackendException if there was an error accessing the
  +     *         data backend.
  +     */
       public RoleSet getAllRoles() throws DataBackendException
       {
           RoleSet roleSet = new RoleSet();
           try
           {
               session = hibernateService.openSession();
  -            List roles = session.find("from SimpleRole");
  +            List roles = session.find("from HibernateSimpleRole");
               roleSet.add(roles);
           }
           catch (HibernateException e)
  @@ -417,14 +384,7 @@
        */
       public boolean checkExists(Permission permission) throws DataBackendException
       {
  -        try
  -        {
  -            return getPermissionManager().checkExists(permission);
  -        }
  -        catch (ComponentException ce)
  -        {
  -            throw new DataBackendException("Problem getting permission manager", ce);
  -        }
  +        return getPermissionManager().checkExists(permission);
       }
       /**
       * Creates a new role with specified attributes.
  @@ -450,59 +410,10 @@
           {
               throw new EntityExistsException("The role '" + role.getName() + "' already exists");
           }
  -        try
  -        {
  -            session = hibernateService.openSession();
  -            transaction = session.beginTransaction();
  -            session.save(role);
  -            transaction.commit();
  -        }
  -        catch (HibernateException e)
  -        {
  -            log.error("Error adding role", e);
  -            try
  -            {
  -                transaction.rollback();
  -            }
  -            catch (HibernateException he)
  -            {
  -            }
  -            throw new DataBackendException("Failed to create role '" + role.getName() + "'", e);
  -        }
  +        addEntity(role);
           return role;
       }
       /**
  -    * Stores Role's attributes. The Roles is required to exist in the system.
  -    *
  -    * @param role The Role to be stored.
  -    * @throws DataBackendException if there was an error accessing the data
  -    *         backend.
  -    * @throws UnknownEntityException if the role does not exist.
  -    */
  -    public void saveRole(Role role) throws DataBackendException, UnknownEntityException
  -    {
  -        boolean roleExists = false;
  -        try
  -        {
  -            roleExists = checkExists(role);
  -            if (roleExists)
  -            {
  -                session = hibernateService.openSession();
  -                transaction = session.beginTransaction();
  -                session.update(role);
  -                transaction.commit();
  -            }
  -            else
  -            {
  -                throw new UnknownEntityException("Unknown role '" + role + "'");
  -            }
  -        }
  -        catch (Exception e)
  -        {
  -            throw new DataBackendException("saveRole(Role) failed", e);
  -        }
  -    }
  -    /**
       * Removes a Role from the system.
       *
       * @param role The object describing the role to be removed.
  @@ -518,10 +429,7 @@
               roleExists = checkExists(role);
               if (roleExists)
               {
  -                session = hibernateService.openSession();
  -                transaction = session.beginTransaction();
  -                session.delete(role);
  -                transaction.commit();
  +                removeEntity(role);
               }
               else
               {
  @@ -534,19 +442,5 @@
               log.error(e);
               throw new DataBackendException("removeRole(Role) failed", e);
           }
  -    }
  -    /**
  -    * Avalon component lifecycle method
  -    */
  -    public void compose(ComponentManager manager) throws ComponentException
  -    {
  -        this.manager = manager;
  -        hibernateService = (HibernateService) manager.lookup(HibernateService.ROLE);
  -    }
  -    public void dispose()
  -    {
  -        hibernateService = null;
  -        manager = null;
  -        permissionManager = null;
       }
   }
  
  
  
  1.3       +17 -186   jakarta-turbine-fulcrum/security/src/java/org/apache/fulcrum/security/spi/hibernate/simple/HibernateUserManagerImpl.java
  
  Index: HibernateUserManagerImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-fulcrum/security/src/java/org/apache/fulcrum/security/spi/hibernate/simple/HibernateUserManagerImpl.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- HibernateUserManagerImpl.java	23 Aug 2003 21:09:52 -0000	1.2
  +++ HibernateUserManagerImpl.java	24 Aug 2003 19:41:35 -0000	1.3
  @@ -56,22 +56,14 @@
   import java.util.Iterator;
   import java.util.List;
   import java.util.Map;
  +
   import net.sf.hibernate.Hibernate;
   import net.sf.hibernate.HibernateException;
  -import net.sf.hibernate.Session;
  -import net.sf.hibernate.Transaction;
  -import net.sf.hibernate.avalon.HibernateService;
  -import org.apache.avalon.framework.activity.Disposable;
  -import org.apache.avalon.framework.component.ComponentException;
  -import org.apache.avalon.framework.component.ComponentManager;
  -import org.apache.avalon.framework.component.Composable;
  -import org.apache.avalon.framework.logger.AbstractLogEnabled;
  +
   import org.apache.commons.lang.StringUtils;
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   import org.apache.fulcrum.factory.FactoryService;
  -import org.apache.fulcrum.security.GroupManager;
  -import org.apache.fulcrum.security.RoleManager;
   import org.apache.fulcrum.security.acl.AccessControlList;
   import org.apache.fulcrum.security.acl.DefaultAccessControlList;
   import org.apache.fulcrum.security.entity.Group;
  @@ -81,6 +73,7 @@
   import org.apache.fulcrum.security.model.simple.entity.SimpleRole;
   import org.apache.fulcrum.security.model.simple.entity.SimpleUser;
   import org.apache.fulcrum.security.model.simple.manager.SimpleUserManager;
  +import org.apache.fulcrum.security.spi.hibernate.simple.entity.HibernateSimpleUser;
   import org.apache.fulcrum.security.util.DataBackendException;
   import org.apache.fulcrum.security.util.EntityExistsException;
   import org.apache.fulcrum.security.util.GroupSet;
  @@ -94,43 +87,12 @@
    * @author <a href="mailto:epugh@upstate.com">Eric Pugh</a>
    * @version $Id$
    */
  -public class HibernateUserManagerImpl extends AbstractLogEnabled implements SimpleUserManager, Composable, Disposable
  +public class HibernateUserManagerImpl extends BaseHibernateManager implements SimpleUserManager
   {
       /** Logging */
       private static Log log = LogFactory.getLog(HibernateUserManagerImpl.class);
       /** A factory to construct ACL Objects */
       private FactoryService aclFactoryService = null;
  -    private ComponentManager manager = null;
  -    /** Our groupManager **/
  -    private GroupManager groupManager;
  -    /** Our roleManager **/
  -    private RoleManager roleManager;
  -    /** Hibernate components */
  -    private HibernateService hibernateService;
  -    private Session session;
  -    private Transaction transaction;
  -    /**
  -     * @return
  -     */
  -    GroupManager getGroupManager() throws ComponentException
  -    {
  -        if (groupManager == null)
  -        {
  -            groupManager = (GroupManager) manager.lookup(GroupManager.ROLE);
  -        }
  -        return groupManager;
  -    }
  -    /**
  -    	* @return
  -    	*/
  -    RoleManager getRoleManager() throws ComponentException
  -    {
  -        if (roleManager == null)
  -        {
  -            roleManager = (RoleManager) manager.lookup(RoleManager.ROLE);
  -        }
  -        return roleManager;
  -    }
       /**
        * Check whether a specified user's account exists.
        *
  @@ -161,7 +123,7 @@
           try
           {
               session = hibernateService.openSession();
  -            users = session.find("from SimpleUser su where su.name=?", userName, Hibernate.STRING);
  +            users = session.find("from HibernateSimpleUser su where su.name=?", userName, Hibernate.STRING);
           }
           catch (HibernateException e)
           {
  @@ -190,7 +152,7 @@
           try
           {
               session = hibernateService.openSession();
  -            users = session.find("from SimpleUser su where su.name=?", userName, Hibernate.STRING);
  +            users = session.find("from HibernateSimpleUser su where su.name=?", userName.toLowerCase(), Hibernate.STRING);
           }
           catch (HibernateException e)
           {
  @@ -339,26 +301,9 @@
           {
               throw new EntityExistsException("The account '" + user.getName() + "' already exists");
           }
  +        
           user.setPassword(initialPassword);
  -        try
  -        {
  -            session = hibernateService.openSession();
  -            transaction = session.beginTransaction();
  -            session.save(user);
  -            transaction.commit();
  -        }
  -        catch (HibernateException e)
  -        {
  -            log.error("Error adding user", e);
  -            try
  -            {
  -                transaction.rollback();
  -            }
  -            catch (HibernateException he)
  -            {
  -            }
  -            throw new DataBackendException("Failed to create account '" + user.getName() + "'", e);
  -        }
  +        addEntity(user);
       }
       /**
        * Construct a blank User object.
  @@ -374,7 +319,7 @@
           User user;
           try
           {
  -            user = (User) new SimpleUser();
  +            user = (User) new HibernateSimpleUser();
           }
           catch (Exception e)
           {
  @@ -419,6 +364,7 @@
               if (userExists)
               {
                   ((SimpleUser) user).setGroups(new GroupSet());
  +				updateEntity(user);
                   return;
               }
           }
  @@ -431,70 +377,8 @@
           }
           throw new UnknownEntityException("Unknown user '" + user.getName() + "'");
       }
  -    /*-----------------------------------------------------------------------
  -    	 Security management
  -    	 -----------------------------------------------------------------------*/
  -    /**
  -    	* Grant an User a Role in a Group.
  -    	*
  -    	* @param user the user.
  -    	* @param group the group.
  -    	* @param role the role.
  -    	* @throws DataBackendException if there was an error accessing the data
  -    	*         backend.
  -    	* @throws UnknownEntityException if user account, group or role is not
  -    	*         present.
  -    	*/
  -    /* public synchronized void grant(User user, Group group, Role role)
  -         throws DataBackendException, UnknownEntityException
  -     {
  -         boolean userExists = false;
  -         boolean groupExists = false;
  -         boolean roleExists = false;
  -         try
  -         {
  -             userExists = checkExists(user);
  -             groupExists = checkExists(group);
  -             roleExists = checkExists(role);
  -             if (userExists && groupExists && roleExists)
  -             {
  -                 ((SimpleUser) user).addGroup(group);
  -                 ((SimpleUser) user).addRole(role);
  -                 return;
  -             }
  -         }
  -         catch (Exception e)
  -         {
  -             throw new DataBackendException("grant(User,Group,Role) failed", e);
  -         }
  -         finally
  -         {
  -         }
  -         if (!userExists)
  -         {
  -             throw new UnknownEntityException("Unknown user '" + user.getName() + "'");
  -         }
  -         if (!groupExists)
  -         {
  -             throw new UnknownEntityException("Unknown group '" + group.getName() + "'");
  -         }
  -         if (!roleExists)
  -         {
  -             throw new UnknownEntityException("Unknown role '" + role.getName() + "'");
  -         }
  -     }
  -     */
  -    /**
  -    	* Revoke a Role in a Group from an User.
  -    	*
  -    	* @param user the user.
  -    	* @param group the group.
  -    	* @param role the role.
  -    	* @throws DataBackendException if there was an error accessing the data
  -    	*         backend.
  -    	* @throws UnknownEntityException if user account, group or role is not
  -    	*         present.
  -    	*/
  +    
  +
       /**
       * Determines if the <code>Group</code> exists in the security system.
       *
  @@ -642,25 +526,7 @@
       {
           // revoke all roles form the user
           revokeAll(user);
  -        try
  -        {
  -            session = hibernateService.openSession();
  -            transaction = session.beginTransaction();
  -            session.delete(user);
  -            transaction.commit();
  -        }
  -        catch (HibernateException e)
  -        {
  -            log.error("Error deleting user", e);
  -            try
  -            {
  -                transaction.rollback();
  -            }
  -            catch (HibernateException he)
  -            {
  -            }
  -            throw new DataBackendException("Failed to remove account '" + user.getName() + "'", e);
  -        }
  +        removeEntity(user);
       }
       /**
          * Creates new user account with specified attributes.
  @@ -690,25 +556,7 @@
           userExists = checkExists(user);
           if (userExists)
           {
  -            try
  -            {
  -                session = hibernateService.openSession();
  -                transaction = session.beginTransaction();
  -                session.update(user);
  -                transaction.commit();
  -            }
  -            catch (HibernateException e)
  -            {
  -                log.error("Error adding user", e);
  -                try
  -                {
  -                    transaction.rollback();
  -                }
  -                catch (HibernateException he)
  -                {
  -                }
  -                throw new DataBackendException("Failed to create account '" + user.getName() + "'", e);
  -            }
  +            updateEntity(user);
           }
           else
           {
  @@ -736,6 +584,7 @@
               if (groupExists && userExists)
               {
                   ((SimpleUser) user).addGroup(group);
  +				updateEntity(user);
                   return;
               }
           }
  @@ -776,6 +625,7 @@
               if (groupExists && userExists)
               {
                   ((SimpleUser) user).removeGroup(group);
  +                updateEntity(user);
                   return;
               }
           }
  @@ -794,24 +644,5 @@
           {
               throw new UnknownEntityException("Unknown user '" + user.getName() + "'");
           }
  -    }
  -    /**
  -    	  * Avalon component lifecycle method
  -    	  */
  -    public void compose(ComponentManager manager) throws ComponentException
  -    {
  -        this.manager = manager;
  -        hibernateService = (HibernateService) manager.lookup(HibernateService.ROLE);
  -    }
  -    /**
  -    	* DESTRUCTION: step 2
  -    	* @see org.apache.avalon.framework.activity.Disposable#dispose()
  -    	*/
  -    public void dispose()
  -    {
  -        hibernateService = null;
  -        manager = null;
  -        groupManager = null;
  -        roleManager = null;
       }
   }
  
  
  
  1.3       +35 -170   jakarta-turbine-fulcrum/security/src/java/org/apache/fulcrum/security/spi/hibernate/simple/HibernatePermissionManagerImpl.java
  
  Index: HibernatePermissionManagerImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-fulcrum/security/src/java/org/apache/fulcrum/security/spi/hibernate/simple/HibernatePermissionManagerImpl.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- HibernatePermissionManagerImpl.java	23 Aug 2003 21:09:52 -0000	1.2
  +++ HibernatePermissionManagerImpl.java	24 Aug 2003 19:41:35 -0000	1.3
  @@ -53,26 +53,16 @@
    * <http://www.apache.org/>.
    */
   import java.util.List;
  -
   import net.sf.hibernate.Hibernate;
   import net.sf.hibernate.HibernateException;
  -import net.sf.hibernate.Session;
  -import net.sf.hibernate.Transaction;
  -import net.sf.hibernate.avalon.HibernateService;
  -
  -import org.apache.avalon.framework.activity.Disposable;
  -import org.apache.avalon.framework.component.ComponentException;
  -import org.apache.avalon.framework.component.ComponentManager;
  -import org.apache.avalon.framework.component.Composable;
  -import org.apache.avalon.framework.logger.AbstractLogEnabled;
   import org.apache.commons.lang.StringUtils;
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   import org.apache.fulcrum.security.PermissionManager;
  -import org.apache.fulcrum.security.RoleManager;
   import org.apache.fulcrum.security.entity.Permission;
   import org.apache.fulcrum.security.entity.Role;
   import org.apache.fulcrum.security.model.simple.entity.SimplePermission;
  +import org.apache.fulcrum.security.model.simple.entity.SimpleRole;
   import org.apache.fulcrum.security.util.DataBackendException;
   import org.apache.fulcrum.security.util.EntityExistsException;
   import org.apache.fulcrum.security.util.PermissionSet;
  @@ -83,29 +73,10 @@
    * @author <a href="mailto:epugh@upstate.com">Eric Pugh</a>
    * @version $Id$
    */
  -public class HibernatePermissionManagerImpl
  -    extends AbstractLogEnabled
  -    implements PermissionManager, Composable, Disposable
  +public class HibernatePermissionManagerImpl extends BaseHibernateManager implements PermissionManager
   {
       /** Logging */
       private static Log log = LogFactory.getLog(HibernatePermissionManagerImpl.class);
  -    private RoleManager roleManager = null;
  -    /** Hibernate components */
  -    private HibernateService hibernateService;
  -    private Session session;
  -    private Transaction transaction;
  -    private ComponentManager manager = null;
  -    /**
  -    	 * @return
  -    	 */
  -    RoleManager getRoleManager() throws ComponentException
  -    {
  -        if (roleManager == null)
  -        {
  -            roleManager = (RoleManager) manager.lookup(RoleManager.ROLE);
  -        }
  -        return roleManager;
  -    }
       /**
        * Construct a blank Permission object.
        *
  @@ -175,7 +146,7 @@
        * @throws DataBackendException if there is a problem accessing the
        *            storage.
        */
  -    public Permission getPermissionById(int id) throws DataBackendException, UnknownEntityException
  +    public Permission getPermissionById(long id) throws DataBackendException, UnknownEntityException
       {
           Permission permission = getAllPermissions().getPermissionById(id);
           if (permission == null)
  @@ -219,24 +190,17 @@
           throws DataBackendException, UnknownEntityException
       {
           boolean permissionExists = false;
  -        try
  -        {
  -            permissionExists = checkExists(permission);
  -            if (permissionExists)
  -            {
  -                permission.setName(name);
  -                savePermission(permission);
  -                return;
  -            }
  -        }
  -        catch (Exception e)
  +        permissionExists = checkExists(permission);
  +        if (permissionExists)
           {
  -            throw new DataBackendException("renamePermission(Permission,name)", e);
  +            permission.setName(name);
  +            updateEntity(permission);
  +            return;
           }
  -        finally
  +        else
           {
  +            throw new UnknownEntityException("Unknown permission '" + permission + "'");
           }
  -        throw new UnknownEntityException("Unknown permission '" + permission + "'");
       }
       /**
       * Determines if the <code>Permission</code> exists in the security system.
  @@ -267,38 +231,6 @@
           return (permissions.size() == 1);
       }
       /**
  -    * Stores Permission's attributes. The Permissions is required to exist in
  -    * the system.
  -    *
  -    * @param permission The Permission to be stored.
  -    * @throws DataBackendException if there was an error accessing the data
  -    *         backend.
  -    * @throws UnknownEntityException if the permission does not exist.
  -    */
  -    public void savePermission(Permission permission) throws DataBackendException, UnknownEntityException
  -    {
  -        boolean permissionExists = false;
  -        try
  -        {
  -            permissionExists = checkExists(permission);
  -            if (permissionExists)
  -            {
  -                session = hibernateService.openSession();
  -                transaction = session.beginTransaction();
  -                session.update(permission);
  -                transaction.commit();
  -            }
  -            else
  -            {
  -                throw new UnknownEntityException("Unknown permission '" + permission + "'");
  -            }
  -        }
  -        catch (Exception e)
  -        {
  -            throw new DataBackendException("savePermission(Permission) failed", e);
  -        }
  -    }
  -    /**
        * Removes a Permission from the system.
        *
        * @param permission The object describing the permission to be removed.
  @@ -310,26 +242,14 @@
           throws DataBackendException, UnknownEntityException
       {
           boolean permissionExists = false;
  -        try
  +        permissionExists = checkExists(permission);
  +        if (permissionExists)
           {
  -            permissionExists = checkExists(permission);
  -            if (permissionExists)
  -            {
  -                session = hibernateService.openSession();
  -                transaction = session.beginTransaction();
  -                session.delete(permission);
  -                transaction.commit();
  -            }
  -            else
  -            {
  -                throw new UnknownEntityException("Unknown permission '" + permission + "'");
  -            }
  +            deleteEntity(permission);
           }
  -        catch (Exception e)
  +        else
           {
  -            log.error("Failed to delete a Permission");
  -            log.error(e);
  -            throw new DataBackendException("removePermission(Permission) failed", e);
  +            throw new UnknownEntityException("Unknown permission '" + permission + "'");
           }
       }
       /**
  @@ -357,88 +277,33 @@
           {
               throw new EntityExistsException("The permission '" + permission.getName() + "' already exists");
           }
  -        try
  -        {
  -            session = hibernateService.openSession();
  -            transaction = session.beginTransaction();
  -            session.save(permission);
  -            transaction.commit();
  -        }
  -        catch (HibernateException e)
  -        {
  -            log.error("Error adding permission", e);
  -            try
  -            {
  -                transaction.rollback();
  -            }
  -            catch (HibernateException he)
  -            {
  -            }
  -            throw new DataBackendException("Failed to create permission '" + permission.getName() + "'", e);
  -        }
  +        addEntity(permission);
           return permission;
       }
       /**
  -	 * Retrieves all permissions associated with a role.
  -	 *
  -	 * @param role the role name, for which the permissions are to be retrieved.
  -	 * @return A Permission set for the Role.
  -	 * @throws DataBackendException if there was an error accessing the data
  -	 *         backend.
  -	 * @throws UnknownEntityException if the role is not present.
  -	 */
  +     * Retrieves all permissions associated with a role.
  +     *
  +     * @param role the role name, for which the permissions are to be retrieved.
  +     * @return A Permission set for the Role.
  +     * @throws DataBackendException if there was an error accessing the data
  +     *         backend.
  +     * @throws UnknownEntityException if the role is not present.
  +     */
       public PermissionSet getPermissions(Role role) throws DataBackendException, UnknownEntityException
       {
  -        boolean roleExists = false;
  -        try
  -        {
  -            roleExists = checkExists(role);
  -            if (roleExists)
  -            {
  -                return role.getPermissions();
  -            }
  -        }
  -        catch (Exception e)
  -        {
  -            throw new DataBackendException("getPermissions(Role) failed", e);
  -        }
  -        finally
  -        {
  -        }
  -        throw new UnknownEntityException("Unknown role '" + role.getName() + "'");
  +        return ((SimpleRole)role).getPermissions();
       }
       /**
  -	* Determines if the <code>Role</code> exists in the security system.
  -	*
  -	* @param role a <code>Role</code> value
  -	* @return true if the role exists in the system, false otherwise
  -	* @throws DataBackendException when more than one Role with
  -	*         the same name exists.
  -	* @throws Exception A generic exception.
  -	*/
  -    public boolean checkExists(Role role) throws DataBackendException
  -    {
  -        try
  -        {
  -            return getRoleManager().checkExists(role);
  -        }
  -        catch (ComponentException ce)
  -        {
  -            throw new DataBackendException("Problem accessing role manager", ce);
  -        }
  -    }
  -    /**
  -    * Avalon component lifecycle method
  +    * Determines if the <code>Role</code> exists in the security system.
  +    *
  +    * @param role a <code>Role</code> value
  +    * @return true if the role exists in the system, false otherwise
  +    * @throws DataBackendException when more than one Role with
  +    *         the same name exists.
  +    * @throws Exception A generic exception.
       */
  -    public void compose(ComponentManager manager) throws ComponentException
  -    {
  -        this.manager = manager;
  -        hibernateService = (HibernateService) manager.lookup(HibernateService.ROLE);
  -    }
  -    public void dispose()
  +    public boolean checkExists(Role role) throws DataBackendException
       {
  -        hibernateService = null;
  -        manager = null;
  -        roleManager = null;
  +        return getRoleManager().checkExists(role);
       }
   }
  
  
  
  1.1                  jakarta-turbine-fulcrum/security/src/java/org/apache/fulcrum/security/spi/hibernate/simple/BaseHibernateManager.java
  
  Index: BaseHibernateManager.java
  ===================================================================
  package org.apache.fulcrum.security.spi.hibernate.simple;
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001-2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Turbine" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Turbine", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  import net.sf.hibernate.HibernateException;
  import net.sf.hibernate.Session;
  import net.sf.hibernate.Transaction;
  import net.sf.hibernate.avalon.HibernateService;
  import org.apache.avalon.framework.activity.Disposable;
  import org.apache.avalon.framework.component.ComponentException;
  import org.apache.avalon.framework.component.ComponentManager;
  import org.apache.avalon.framework.component.Composable;
  import org.apache.avalon.framework.logger.AbstractLogEnabled;
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  import org.apache.fulcrum.security.GroupManager;
  import org.apache.fulcrum.security.PermissionManager;
  import org.apache.fulcrum.security.RoleManager;
  import org.apache.fulcrum.security.entity.SecurityEntity;
  import org.apache.fulcrum.security.util.DataBackendException;
  import org.apache.fulcrum.security.util.UnknownEntityException;
  /**
   *
   * This implementation persists to a database via Hibernate.
   *
   * @author <a href="mailto:epugh@upstate.com">Eric Pugh</a>
   * @version $Id: BaseHibernateManager.java,v 1.1 2003/08/24 19:41:35 epugh Exp $
   */
  public class BaseHibernateManager extends AbstractLogEnabled implements Composable, Disposable
  {
      boolean composed = false;
      /** Logging */
      private static Log log = LogFactory.getLog(BaseHibernateManager.class);
      protected HibernateService hibernateService;
      protected Session session;
      protected Transaction transaction;
      protected ComponentManager manager = null;
      protected PermissionManager permissionManager;
      protected RoleManager roleManager;
      protected GroupManager groupManager;
      /**
       * @return
       */
      PermissionManager getPermissionManager() throws DataBackendException
      {
          if (permissionManager == null)
          {
              try
              {
                  permissionManager = (PermissionManager) manager.lookup(PermissionManager.ROLE);
              }
              catch (ComponentException ce)
              {
                  throw new DataBackendException(ce.getMessage(), ce);
              }
          }
          return permissionManager;
      }
      /**
       * @return
       */
      RoleManager getRoleManager() throws DataBackendException
      {
          if (roleManager == null)
          {
              try
              {
                  roleManager = (RoleManager) manager.lookup(RoleManager.ROLE);
              }
              catch (ComponentException ce)
              {
                  throw new DataBackendException(ce.getMessage(), ce);
              }
          }
          return roleManager;
      }
      /**
      * @return
      */
      GroupManager getGroupManager() throws DataBackendException
      {
          if (groupManager == null)
          {
              try
              {
                  groupManager = (GroupManager) manager.lookup(GroupManager.ROLE);
              }
              catch (ComponentException ce)
              {
                  throw new DataBackendException(ce.getMessage(), ce);
              }
          }
          return groupManager;
      }
      void removeEntity(SecurityEntity entity) throws DataBackendException, UnknownEntityException
      {
          try
          {
              session = hibernateService.openSession();
              transaction = session.beginTransaction();
              session.delete(entity);
              transaction.commit();
          }
          catch (HibernateException he)
          {
              try
              {
                  transaction.rollback();
              }
              catch (HibernateException hex)
              {
              }
              throw new DataBackendException("Problem removing entity.", he);
          }
      }
      /**
        * Stores changes made to an object
        *
        * @param role The object to be saved
        * @throws DataBackendException if there was an error accessing the data
        *         backend.
        * @throws UnknownEntityException if the role does not exist.
        */
      void updateEntity(SecurityEntity entity) throws DataBackendException
      {
          try
          {
              session = hibernateService.openSession();
              transaction = session.beginTransaction();
              session.update(entity);
              transaction.commit();
          }
          catch (HibernateException he)
          {
              try
              {
                  transaction.rollback();
              }
              catch (HibernateException hex)
              {
              }
              throw new DataBackendException("renameRole(s,name)", he);
          }
          return;
      }
      /**
      	  * adds an entity
      	  *
      	  * @param role The object to be saved
      	  * @throws DataBackendException if there was an error accessing the data
      	  *         backend.
      	  * @throws UnknownEntityException if the role does not exist.
      	  */
      void addEntity(SecurityEntity entity) throws DataBackendException
      {
          try
          {
              session = hibernateService.openSession();
              transaction = session.beginTransaction();
              session.save(entity);
              transaction.commit();
          }
          catch (HibernateException he)
          {
              try
              {
                  transaction.rollback();
              }
              catch (HibernateException hex)
              {
              }
              throw new DataBackendException("addEntity(s,name)", he);
          }
          return;
      }
      /**
      	  * Deletes an entity object
      	  *
      	  * @param role The object to be saved
      	  * @throws DataBackendException if there was an error accessing the data
      	  *         backend.
      	  * @throws UnknownEntityException if the role does not exist.
      	  */
      void deleteEntity(SecurityEntity entity) throws DataBackendException
      {
          try
          {
              session = hibernateService.openSession();
              transaction = session.beginTransaction();
              session.delete(entity);
              transaction.commit();
          }
          catch (HibernateException he)
          {
              try
              {
                  transaction.rollback();
              }
              catch (HibernateException hex)
              {
              }
              throw new DataBackendException("delete()", he);
          }
          return;
      }
      /**
      * Avalon component lifecycle method
      */
      public void compose(ComponentManager manager) throws ComponentException
      {
          this.manager = manager;
          hibernateService = (HibernateService) manager.lookup(HibernateService.ROLE);
      }
      public void dispose()
      {
          hibernateService = null;
          manager = null;
          permissionManager = null;
          roleManager = null;
          groupManager = null;
      }
  }
  
  
  
  1.1                  jakarta-turbine-fulcrum/security/src/java/org/apache/fulcrum/security/spi/hibernate/simple/entity/HibernateSimpleUser.java
  
  Index: HibernateSimpleUser.java
  ===================================================================
  /*
   * Created on Aug 24, 2003
   *
   */
  package org.apache.fulcrum.security.spi.hibernate.simple.entity;
  
  import java.util.Set;
  
  import org.apache.fulcrum.security.model.simple.entity.SimpleUser;
  
  /**
   * @author Eric Pugh
   *
   * Helper class for Hibernate.  For some reason, hibernate won't 
   * map the darn SecuritySet subclasses to sets, even though they
   * implement set.  
   */
  public class HibernateSimpleUser extends SimpleUser
  {
  	
  	void setHibernateGroups(Set permissions){
  		this.getGroups().add(permissions);
  	}
  	
  	Set getHibernateGroups(){
  		return getGroups().getSet();	
  	}
  	
  	
  }
  
  
  
  1.1                  jakarta-turbine-fulcrum/security/src/java/org/apache/fulcrum/security/spi/hibernate/simple/entity/HibernateSimpleRole.java
  
  Index: HibernateSimpleRole.java
  ===================================================================
  /*
   * Created on Aug 24, 2003
   *
   */
  package org.apache.fulcrum.security.spi.hibernate.simple.entity;
  
  import java.util.Set;
  
  import org.apache.fulcrum.security.model.simple.entity.SimpleRole;
  
  /**
   * @author Eric Pugh
   *
   * To change the template for this generated type comment go to
   * Window>Preferences>Java>Code Generation>Code and Comments
   */
  public class HibernateSimpleRole extends SimpleRole
  {
  	
  	void setHibernatePermissions(Set permissions){
  		this.getPermissions().add(permissions);
  	}
  	
  	Set getHibernatePermissions(){
  		return getPermissions().getSet();	
  	}
  	
  	
  }
  
  
  
  1.1                  jakarta-turbine-fulcrum/security/src/java/org/apache/fulcrum/security/spi/hibernate/simple/entity/HibernateSimpleGroup.java
  
  Index: HibernateSimpleGroup.java
  ===================================================================
  /*
   * Created on Aug 24, 2003
   *
   */
  package org.apache.fulcrum.security.spi.hibernate.simple.entity;
  
  import java.util.Set;
  
  import org.apache.fulcrum.security.model.simple.entity.SimpleGroup;
  
  /**
   * @author Eric Pugh
   *
   * Helper class for Hibernate.  For some reason, hibernate won't 
   * map the darn SecuritySet subclasses to sets, even though they
   * implement set.  
   */
  public class HibernateSimpleGroup extends SimpleGroup
  {
  	
  	void setHibernateRoles(Set permissions){
  		this.getRoles().add(permissions);
  	}
  	
  	Set getHibernateRoles(){
  		return getRoles().getSet();	
  	}
  	
  	
  }