Commits

hani  committed aa6e591

UNTESTED!!!
Fixed a bunch of xdoclet stuff, and converted beans to ejb 2.0
Added a frontend session bean facade

  • Participants
  • Parent commits 3c895d7

Comments (0)

Files changed (7)

File src/java/com/opensymphony/user/provider/ejb/EJBAccessProvider.java

 import com.opensymphony.user.Entity;
 import com.opensymphony.user.UserManagerImplementationException;
 import com.opensymphony.user.provider.AccessProvider;
-import com.opensymphony.user.provider.ejb.entity.*;
 
 import com.opensymphony.util.EJBUtils;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
-import java.rmi.RemoteException;
-
 import java.util.*;
 
 import javax.ejb.CreateException;
-import javax.ejb.ObjectNotFoundException;
-import javax.ejb.RemoveException;
-
-import javax.naming.NamingException;
 
 
 /**
  * @author <a href="mailto:joe@truemesh.com">Joe Walnes</a>
  * @author <a href="mailto:mike@atlassian.com">Mike Cannon-Brookes</a>
  * @author <a href="mailto:plightbo@cisco.com">Patrick Lightbody</a>
- * $Revision: 1.2 $
+ * $Revision: 1.3 $
  */
 public class EJBAccessProvider implements AccessProvider {
     //~ Static fields/initializers /////////////////////////////////////////////
 
     //~ Instance fields ////////////////////////////////////////////////////////
 
-    private GroupHome groupHome;
-    private MembershipHome membershipHome;
-    private UserHome userHome;
+    private UserManagerSession session;
 
     //~ Methods ////////////////////////////////////////////////////////////////
 
     public boolean addToGroup(String username, String groupname) {
-        //XXX Should we return true or false if the user is already in the group?
+        //todo Should we return true or false if the user is already in the group?
         if (inGroup(username, groupname)) {
             return true;
         }
                 logger.debug("adding user (" + username + ") to group (" + groupname + ")");
             }
 
-            UserRemote user = userHome.findByName(username);
-            GroupRemote group = groupHome.findByName(groupname);
-            membershipHome.create(user.getName(), group.getName());
-
-            if (logger.isDebugEnabled()) {
-                logger.debug("success");
-            }
-
-            return true;
-        } catch (ObjectNotFoundException e) {
-            if (logger.isDebugEnabled()) {
-                logger.debug("not found");
-            }
-
-            return false;
-        } catch (CreateException e) {
-            if (logger.isDebugEnabled()) {
-                logger.debug("create exception");
-            }
-
-            return false;
+            return session.addToGroup(username, groupname);
         } catch (Exception e) {
             throw new UserManagerImplementationException(e);
         }
 
     public boolean create(String name) {
         try {
-            groupHome.create(name);
-
-            return true;
+            return session.createGroup(name);
         } catch (CreateException e) {
             return false;
         } catch (Exception e) {
     }
 
     public boolean handles(String name) {
-        try {
-            try {
-                groupHome.findByName(name);
+        if (session.groupExists(name)) {
+            return true;
+        }
 
-                return true;
-            } catch (ObjectNotFoundException e) {
-                // @TODO: consider this! It binds the users and groups together into one place
-                try {
-                    userHome.findByName(name);
-
-                    return true;
-                } catch (ObjectNotFoundException e2) {
-                }
-            }
-        } catch (Exception e) {
-            throw new UserManagerImplementationException(e);
+        // @TODO: consider this! It binds the users and groups together into one place
+        if (session.userExists(name)) {
+            return true;
         }
 
         return false;
     }
 
     public boolean inGroup(String username, String groupname) {
-        return getMembership(username, groupname) != null;
+        return session.isUserInGroup(username, groupname);
     }
 
     public boolean init(Properties properties) {
         try {
-            String userLocation = properties.getProperty("location.user", "ejb/osuser/User");
-
-            try {
-                userHome = (UserHome) EJBUtils.lookup(userLocation, UserHome.class);
-            } catch (NamingException e) {
-                try {
-                    userHome = (UserHome) EJBUtils.lookup(UserHomeFactory.COMP_NAME, UserHome.class);
-                } catch (NamingException e1) {
-                    try {
-                        userHome = (UserHome) EJBUtils.lookup(UserHomeFactory.JNDI_NAME, UserHome.class);
-                    } catch (NamingException e2) {
-                        // throw the original exception
-                        throw e;
-                    }
-                }
-            }
-
-            String groupLocation = properties.getProperty("location.group", "ejb/osuser/Group");
-
-            try {
-                groupHome = (GroupHome) EJBUtils.lookup(groupLocation, GroupHome.class);
-            } catch (NamingException e) {
-                try {
-                    groupHome = (GroupHome) EJBUtils.lookup(GroupHomeFactory.COMP_NAME, GroupHome.class);
-                } catch (NamingException e1) {
-                    try {
-                        groupHome = (GroupHome) EJBUtils.lookup(GroupHomeFactory.JNDI_NAME, GroupHome.class);
-                    } catch (NamingException e2) {
-                        // throw the original exception
-                        throw e;
-                    }
-                }
-            }
-
-            String membershipLocation = properties.getProperty("location.membership", "ejb/osuser/Membership");
-
-            try {
-                membershipHome = (MembershipHome) EJBUtils.lookup(membershipLocation, MembershipHome.class);
-            } catch (NamingException e) {
-                try {
-                    membershipHome = (MembershipHome) EJBUtils.lookup(MembershipHomeFactory.COMP_NAME, MembershipHome.class);
-                } catch (NamingException e1) {
-                    try {
-                        membershipHome = (MembershipHome) EJBUtils.lookup(MembershipHomeFactory.JNDI_NAME, MembershipHome.class);
-                    } catch (NamingException e2) {
-                        // throw the original exception
-                        throw e;
-                    }
-                }
-            }
+            String managerLocation = properties.getProperty("location.manager", UserManagerHomeFactory.JNDI_NAME);
+            session = (UserManagerSession) EJBUtils.lookup(managerLocation, UserManagerSession.class);
 
             return true;
         } catch (Exception e) {
-            logger.fatal(e);
-            throw new UserManagerImplementationException("Could not lookup User home interface", e);
+            logger.fatal("Unable to look up session bean", e);
+            throw new UserManagerImplementationException("Unable to look up user manager session bean", e);
         }
     }
 
     public List list() {
-        try {
-            Collection groups = groupHome.findAll();
-            List result = new ArrayList(groups.size());
-
-            for (Iterator i = groups.iterator(); i.hasNext();) {
-                GroupRemote group = (GroupRemote) EJBUtils.narrow(i.next(), GroupRemote.class);
-                result.add(group.getName());
-            }
-
-            return result;
-        } catch (Exception e) {
-            logger.error("Could not list groups", e);
-            throw new UserManagerImplementationException(e);
-        }
+        return session.getGroupNames();
     }
 
     public List listGroupsContainingUser(String username) {
         try {
-            UserRemote user = userHome.findByName(username);
-            Collection memberships = membershipHome.findByUser(user.getName());
-            List result = new ArrayList(memberships.size());
-
-            for (Iterator iterator = memberships.iterator();
-                    iterator.hasNext();) {
-                MembershipRemote membership = (MembershipRemote) iterator.next();
-                result.add(membership.getGroup());
-            }
-
-            return result;
+            return session.getUserGroups(username);
         } catch (Exception e) {
             logger.info(e);
             throw new UserManagerImplementationException(e);
 
     public List listUsersInGroup(String groupname) {
         try {
-            GroupRemote group = groupHome.findByName(groupname);
-            Collection memberships = membershipHome.findByGroup(group.getName());
-            List result = new ArrayList(memberships.size());
-
-            for (Iterator iterator = memberships.iterator();
-                    iterator.hasNext();) {
-                MembershipRemote membership = (MembershipRemote) iterator.next();
-                result.add(membership.getUser());
-            }
-
-            return result;
+            return session.getUsersInGroup(groupname);
         } catch (Exception e) {
             e.printStackTrace();
             logger.info(e);
 
     public boolean remove(String name) {
         try {
-            Collection c = membershipHome.findByGroup(name);
-
-            for (Iterator itr = c.iterator(); itr.hasNext();) {
-                try {
-                    MembershipRemote home = (MembershipRemote) itr.next();
-                    home.remove();
-                } catch (RemoteException e) {
-                    // should not happen
-                } catch (RemoveException e) {
-                    // should not happen Log.error(e);
-                }
-            }
-
-            groupHome.findByName(name).remove();
-
-            return true;
-        } catch (RemoveException e) {
-            return false;
+            return session.removeGroup(name);
         } catch (Exception e) {
             throw new UserManagerImplementationException(e);
         }
             logger.debug("removing user (" + username + ") from group (" + groupname + ")");
         }
 
-        MembershipRemote membership = getMembership(username, groupname);
-
-        if (membership == null) {
-            return false;
-        }
-
         try {
-            if (logger.isDebugEnabled()) {
-                logger.debug("found membership for user (" + membership.getUser() + ") to group (" + membership.getGroup() + ")");
-            }
-
-            membership.remove();
-
-            return true;
+            return session.removeFromGroup(username, groupname);
         } catch (Exception e) {
             throw new UserManagerImplementationException(e);
         }
     public boolean store(String name, Entity.Accessor accessor) {
         return true;
     }
-
-    /**
-    * Get the Membership Entity for user and group. Null is returned if not found.
-    */
-    private MembershipRemote getMembership(String username, String groupname) {
-        if (logger.isDebugEnabled()) {
-            logger.debug("Getting membership for user (" + username + ") to group (" + groupname + ")");
-        }
-
-        try {
-            UserRemote user = userHome.findByName(username);
-            GroupRemote group = groupHome.findByName(groupname);
-
-            return membershipHome.findByUserAndGroup(user.getName(), group.getName());
-        } catch (ObjectNotFoundException e) {
-            return null;
-        } catch (Exception e) {
-            throw new UserManagerImplementationException(e);
-        }
-    }
 }

File src/java/com/opensymphony/user/provider/ejb/EJBCredentialsProvider.java

 import com.opensymphony.user.Entity;
 import com.opensymphony.user.UserManagerImplementationException;
 import com.opensymphony.user.provider.CredentialsProvider;
-import com.opensymphony.user.provider.ejb.entity.*;
 
 import com.opensymphony.util.EJBUtils;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
-import java.rmi.RemoteException;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Properties;
 
 import javax.ejb.CreateException;
-import javax.ejb.ObjectNotFoundException;
-import javax.ejb.RemoveException;
-
-import javax.naming.NamingException;
 
 
 /**
  * @author <a href="mailto:joe@truemesh.com">Joe Walnes</a>
  * @author <a href="mailto:mike@atlassian.com">Mike Cannon-Brookes</a>
- * $Revision: 1.4 $
+ * $Revision: 1.5 $
  */
 public class EJBCredentialsProvider implements CredentialsProvider {
     //~ Static fields/initializers /////////////////////////////////////////////
 
     //~ Instance fields ////////////////////////////////////////////////////////
 
-    private MembershipHome membershipHome;
-    private UserHome userHome;
+    private UserManagerSession session;
 
     //~ Methods ////////////////////////////////////////////////////////////////
 
         }
 
         try {
-            return userHome.findByName(name).authenticate(password);
-        } catch (ObjectNotFoundException e) {
-            return false;
+            return session.authenticate(name, password);
         } catch (Exception e) {
             throw new UserManagerImplementationException(e);
         }
         }
 
         try {
-            userHome.findByName(name).setPassword(password);
-
-            return true;
-        } catch (ObjectNotFoundException e) {
-            return false;
+            return session.changePassword(name, password);
         } catch (Exception e) {
             throw new UserManagerImplementationException(e);
         }
         }
 
         try {
-            userHome.create(name);
-
-            return true;
+            return session.createUser(name);
         } catch (CreateException e) {
             logger.error("CreateException creating : " + name, e);
 
     }
 
     public boolean handles(String name) {
-        if (logger.isDebugEnabled()) {
-            logger.debug("EJBCredentialsProvider.handles");
+        if (session.userExists(name)) {
+            return true;
         }
 
-        try {
-            userHome.findByName(name);
-
-            return true;
-        } catch (ObjectNotFoundException e) {
-            return false;
-        } catch (Exception e) {
-            throw new UserManagerImplementationException(e);
-        }
+        return false;
     }
 
     public boolean init(Properties properties) {
-        if (logger.isDebugEnabled()) {
-            logger.debug("EJBCredentialsProvider.init");
-        }
-
         try {
-            String location = properties.getProperty("location", "ejb/osuser/User");
-
-            if (logger.isDebugEnabled()) {
-                logger.debug("Looking up UserHome at location: " + location);
-            }
-
-            try {
-                userHome = (UserHome) EJBUtils.lookup(location, UserHome.class);
-            } catch (NamingException e) {
-                try {
-                    userHome = (UserHome) EJBUtils.lookup(UserHomeFactory.COMP_NAME, UserHome.class);
-                } catch (NamingException e1) {
-                    try {
-                        userHome = (UserHome) EJBUtils.lookup(UserHomeFactory.JNDI_NAME, UserHome.class);
-                    } catch (NamingException e2) {
-                        // throw the original exception
-                        throw e;
-                    }
-                }
-            }
-
-            String membershipLocation = properties.getProperty("location.membership", "ejb/osuser/Membership");
-
-            try {
-                membershipHome = (MembershipHome) EJBUtils.lookup(membershipLocation, MembershipHome.class);
-            } catch (NamingException e) {
-                try {
-                    membershipHome = (MembershipHome) EJBUtils.lookup(MembershipHomeFactory.COMP_NAME, MembershipHome.class);
-                } catch (NamingException e1) {
-                    try {
-                        membershipHome = (MembershipHome) EJBUtils.lookup(MembershipHomeFactory.JNDI_NAME, MembershipHome.class);
-                    } catch (NamingException e2) {
-                        // throw the original exception
-                        throw e;
-                    }
-                }
-            }
+            String managerLocation = properties.getProperty("location.manager", UserManagerHomeFactory.JNDI_NAME);
+            session = (UserManagerSession) EJBUtils.lookup(managerLocation, UserManagerSession.class);
 
             return true;
         } catch (Exception e) {
-            logger.fatal(e);
-            throw new UserManagerImplementationException("Could not lookup User home interface", e);
+            logger.fatal("Unable to look up session bean", e);
+            throw new UserManagerImplementationException("Unable to look up user manager session bean", e);
         }
     }
 
         }
 
         try {
-            Collection users = userHome.findAll();
-            List result = new ArrayList(users.size());
-
-            for (Iterator i = users.iterator(); i.hasNext();) {
-                UserRemote user = (UserRemote) EJBUtils.narrow(i.next(), UserRemote.class);
-                result.add(user.getName());
-            }
-
-            return result;
+            return session.getUserNames();
         } catch (Exception e) {
             throw new UserManagerImplementationException(e);
         }
         }
 
         try {
-            Collection c = membershipHome.findByUser(name);
-
-            for (Iterator itr = c.iterator(); itr.hasNext();) {
-                try {
-                    MembershipRemote home = (MembershipRemote) itr.next();
-                    home.remove();
-                } catch (RemoteException e) {
-                    // should not happen
-                } catch (RemoveException e) {
-                    // should not happen Log.error(e);
-                }
-            }
-
-            userHome.findByName(name).remove();
-
-            return true;
-        } catch (ObjectNotFoundException e) {
-            return false;
+            return session.removeUser(name);
         } catch (Exception e) {
             throw new UserManagerImplementationException(e);
         }

File src/java/com/opensymphony/user/provider/ejb/EJBProfileProvider.java

 import com.opensymphony.user.Entity;
 import com.opensymphony.user.UserManagerImplementationException;
 import com.opensymphony.user.provider.ProfileProvider;
-import com.opensymphony.user.provider.ejb.entity.*;
 
 import com.opensymphony.util.EJBUtils;
 
 import java.util.List;
 import java.util.Properties;
 
-import javax.ejb.ObjectNotFoundException;
-
-import javax.naming.NamingException;
-
 
 /**
  * @author <a href="mailto:joe@truemesh.com">Joe Walnes</a>
  * @author <a href="mailto:mike@atlassian.com">Mike Cannon-Brookes</a>
- * $Revision: 1.4 $
+ * $Revision: 1.5 $
  */
 public class EJBProfileProvider implements ProfileProvider {
     //~ Static fields/initializers /////////////////////////////////////////////
 
     //~ Instance fields ////////////////////////////////////////////////////////
 
-    private GroupHome groupHome;
-    private UserHome userHome;
+    private UserManagerSession session;
 
     //~ Methods ////////////////////////////////////////////////////////////////
 
     public PropertySet getPropertySet(String name) {
         try {
-            return userHome.findByName(name).getPropertySet();
-        } catch (ObjectNotFoundException e) {
-            try {
-                return groupHome.findByName(name).getPropertySet();
-            } catch (ObjectNotFoundException e2) {
-            } catch (Exception e2) {
-                throw new UserManagerImplementationException(e);
+            PropertySet ps = session.getUserPropertySet(name);
+
+            if (ps == null) {
+                ps = session.getGroupPropertySet(name);
             }
 
-            return null;
+            return ps;
         } catch (Exception e) {
             throw new UserManagerImplementationException(e);
         }
     }
 
     public boolean handles(String name) {
-        try {
-            userHome.findByName(name);
+        if (session.userExists(name)) {
+            return true;
+        }
 
+        if (session.groupExists(name)) {
             return true;
-        } catch (ObjectNotFoundException e) {
-            try {
-                groupHome.findByName(name);
+        }
 
-                return true;
-            } catch (ObjectNotFoundException e2) {
-            } catch (Exception e2) {
-                throw new UserManagerImplementationException(e);
-            }
-
-            return false;
-        } catch (Exception e) {
-            throw new UserManagerImplementationException(e);
-        }
+        return false;
     }
 
     public boolean init(Properties properties) {
         try {
-            String userLocation = properties.getProperty("location.user", "ejb/osuser/User");
-            String groupLocation = properties.getProperty("location.group", "ejb/osuser/Group");
-
-            try {
-                userHome = (UserHome) EJBUtils.lookup(userLocation, UserHome.class);
-            } catch (NamingException e) {
-                try {
-                    userHome = (UserHome) EJBUtils.lookup(UserHomeFactory.COMP_NAME, UserHome.class);
-                } catch (NamingException e1) {
-                    try {
-                        userHome = (UserHome) EJBUtils.lookup(UserHomeFactory.JNDI_NAME, UserHome.class);
-                    } catch (NamingException e2) {
-                        // throw the original exception
-                        throw e;
-                    }
-                }
-            }
-
-            try {
-                groupHome = (GroupHome) EJBUtils.lookup(groupLocation, GroupHome.class);
-            } catch (NamingException e) {
-                try {
-                    groupHome = (GroupHome) EJBUtils.lookup(GroupHomeFactory.COMP_NAME, GroupHome.class);
-                } catch (NamingException e1) {
-                    try {
-                        groupHome = (GroupHome) EJBUtils.lookup(GroupHomeFactory.JNDI_NAME, GroupHome.class);
-                    } catch (NamingException e2) {
-                        // throw the original exception
-                        throw e;
-                    }
-                }
-            }
+            String managerLocation = properties.getProperty("location.manager", UserManagerHomeFactory.JNDI_NAME);
+            session = (UserManagerSession) EJBUtils.lookup(managerLocation, UserManagerSession.class);
 
             return true;
         } catch (Exception e) {
-            logger.fatal(e);
-            throw new UserManagerImplementationException("Could not lookup User or Group home interface", e);
+            logger.fatal("Unable to look up session bean", e);
+            throw new UserManagerImplementationException("Unable to look up user manager session bean", e);
         }
     }
 

File src/java/com/opensymphony/user/provider/ejb/UserManagerEJB.java

+/*
+ * Copyright (c) 2002-2003 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.user.provider.ejb;
+
+import com.opensymphony.ejb.SessionAdapter;
+
+import com.opensymphony.module.propertyset.PropertySet;
+
+import com.opensymphony.user.provider.ejb.entity.*;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.rmi.RemoteException;
+
+import java.util.*;
+
+import javax.ejb.CreateException;
+import javax.ejb.FinderException;
+import javax.ejb.RemoveException;
+
+import javax.naming.NamingException;
+
+
+/**
+ * User: Hani Suleiman
+ * Date: Dec 22, 2003
+ * Time: 4:25:35 PM
+ *
+ * @ejb.bean
+ *  name="UserManager"
+ *  display-name="User Manager Session Bean"
+ *  jndi-name="ejb/osuser/Manager"
+ *  view-type="remote"
+ *  type="Stateless"
+ *  transaction-type="Container"
+ *
+ * @ejb.interface
+ *  extends="javax.ejb.EJBObject"
+ *
+ * @ejb.home
+ *  generate="remote"
+ *  extends="javax.ejb.EJBHome"
+ *
+ * @ejb.ejb-ref
+ *  ejb-name="User"
+ *  view-type="local"
+ *
+ * @ejb.ejb-ref
+ *  ejb-name="Group"
+ *  view-type="local"
+ *
+ * @ejb.transaction type="Supports"
+ * @ejb.permission unchecked="true"
+ *
+ * @orion.bean copy-by-value="false"
+ */
+public class UserManagerEJB extends SessionAdapter {
+    //~ Static fields/initializers /////////////////////////////////////////////
+
+    private static final Log log = LogFactory.getLog(UserManagerEJB.class);
+
+    //~ Instance fields ////////////////////////////////////////////////////////
+
+    private GroupLocalHome groupHome = null;
+    private UserLocalHome userHome;
+
+    //~ Methods ////////////////////////////////////////////////////////////////
+
+    /**
+     * @ejb.interface-method
+     */
+    public List getGroupNames() {
+        try {
+            Iterator iter = groupHome.findAll().iterator();
+            List results = new ArrayList();
+
+            while (iter.hasNext()) {
+                GroupLocal group = (GroupLocal) iter.next();
+                results.add(group.getName());
+            }
+
+            return results;
+        } catch (FinderException e) {
+            log.error("Unexpected error getting group names", e);
+        }
+
+        return Collections.EMPTY_LIST;
+    }
+
+    /**
+     * @ejb.interface-method
+     */
+    public PropertySet getGroupPropertySet(String name) throws RemoteException {
+        try {
+            return groupHome.findByName(name).getPropertySet();
+        } catch (FinderException e) {
+            return null;
+        }
+    }
+
+    /**
+     * Get a list of group names that the specified user belongs to.
+     * @return a List of group names, or an empty list if the user
+     * does not exist or does not belong to any groups.
+     * @ejb.interface-method
+     */
+    public List getUserGroups(String user) {
+        try {
+            return userHome.findByName(user).getGroupNames();
+        } catch (FinderException e) {
+            log.error("No such user " + user + " in getUserGroups");
+        }
+
+        return Collections.EMPTY_LIST;
+    }
+
+    /**
+     * @ejb.interface-method
+     */
+    public boolean isUserInGroup(String user, String group) {
+        try {
+            return userHome.findByName(user).inGroup(group);
+        } catch (FinderException e) {
+            log.error("No user found for isUserInGroup(" + user + ", " + group + ")");
+        }
+
+        return false;
+    }
+
+    /**
+     * @ejb.interface-method
+     */
+    public List getUserNames() {
+        try {
+            Iterator iter = userHome.findAll().iterator();
+            List results = new ArrayList();
+
+            while (iter.hasNext()) {
+                UserLocal user = (UserLocal) iter.next();
+                results.add(user.getName());
+            }
+
+            return results;
+        } catch (FinderException e) {
+            log.error("Unexpected error getting user names", e);
+        }
+
+        return Collections.EMPTY_LIST;
+    }
+
+    /**
+     * @ejb.interface-method
+     */
+    public PropertySet getUserPropertySet(String name) throws RemoteException {
+        try {
+            return userHome.findByName(name).getPropertySet();
+        } catch (FinderException e) {
+            return null;
+        }
+    }
+
+    /**
+     * Get a list of user names that the specified group contains.
+     * @return a List of user names, or an empty list if the group
+     * does not exist or does not contain any users.
+     * @ejb.interface-method
+     */
+    public List getUsersInGroup(String group) {
+        try {
+            return groupHome.findByName(group).getUserNames();
+        } catch (FinderException e) {
+            log.error("No such group " + group + " in getUsersInGroup");
+        }
+
+        return Collections.EMPTY_LIST;
+    }
+
+    /**
+     * @ejb.interface-method
+     * @ejb.transaction type="Required"
+     * @param userName The user to add to the group.
+     * @param groupName The group to add the user to.
+     * @return true if the user was added to the group, false otherwise.
+     */
+    public boolean addToGroup(String userName, String groupName) {
+        UserLocal user;
+        GroupLocal group;
+
+        try {
+            user = userHome.findByName(userName);
+        } catch (FinderException e) {
+            log.error("No such user " + userName + " exists to add to group " + groupName);
+
+            return false;
+        }
+
+        try {
+            group = groupHome.findByName(groupName);
+        } catch (FinderException e) {
+            log.error("No such group " + groupName + " exists to add user " + userName + " to");
+
+            return false;
+        }
+
+        return user.getGroups().add(group);
+    }
+
+    /**
+     * @ejb.interface-method
+     */
+    public boolean authenticate(String user, String password) {
+        try {
+            return userHome.findByName(user).authenticate(password);
+        } catch (FinderException e) {
+            log.error("Unable to authenticate non-existent user " + user);
+
+            return false;
+        }
+    }
+
+    /**
+     * @ejb.interface-method
+     */
+    public boolean changePassword(String user, String password) {
+        try {
+            userHome.findByName(user).setPassword(password);
+
+            return true;
+        } catch (FinderException e) {
+            log.error("Unable to modify password for non-existent user " + user);
+
+            return false;
+        }
+    }
+
+    /**
+     * @ejb.interface-method
+     * @param name the group name to create.
+     * @return true if the group was created successfully.
+     */
+    public boolean createGroup(String name) throws CreateException {
+        groupHome.create(name);
+
+        return true;
+    }
+
+    /**
+     * @ejb.interface-method
+     */
+    public boolean createUser(String name) throws CreateException {
+        userHome.create(name);
+
+        return true;
+    }
+
+    public void ejbCreate() throws CreateException {
+        try {
+            groupHome = GroupHomeFactory.getLocalHome();
+            userHome = UserHomeFactory.getLocalHome();
+        } catch (NamingException e) {
+            log.error("Error looking up homes", e);
+            throw new CreateException(e.getMessage());
+        }
+    }
+
+    /**
+     * @ejb.interface-method
+     */
+    public boolean groupExists(String name) {
+        try {
+            groupHome.findByName(name);
+
+            return true;
+        } catch (FinderException ex) {
+            return false;
+        }
+    }
+
+    /**
+     * @ejb.interface-method
+     */
+    public boolean removeFromGroup(String userName, String groupName) {
+        try {
+            UserLocal user = userHome.findByName(userName);
+
+            return user.removeGroup(groupName);
+        } catch (FinderException e) {
+            log.error("Cannot remove non-existent user " + userName + " from group " + groupName);
+
+            return false;
+        }
+    }
+
+    /**
+     * Remove the specified group.
+     * @ejb.interface-method
+     * @return true if the group was successfully removed,
+     * false if the group does not exist or there was an error
+     * removing it.
+     */
+    public boolean removeGroup(String group) {
+        try {
+            groupHome.findByName(group).remove();
+
+            return true;
+        } catch (RemoveException e) {
+            log.error("Error removing group", e);
+
+            return false;
+        } catch (FinderException e) {
+            log.error("Cannot remove non-existent group " + group);
+        }
+
+        return false;
+    }
+
+    /**
+     * Remove the specified user.
+     * @ejb.interface-method
+     * @return true if the user was successfully removed,
+     * false if the user does not exist or there was an error
+     * removing it.
+     */
+    public boolean removeUser(String user) {
+        try {
+            userHome.findByName(user).remove();
+
+            return true;
+        } catch (RemoveException e) {
+            log.error("Error removing user", e);
+
+            return false;
+        } catch (FinderException e) {
+            log.error("Cannot remove non-existent user " + user);
+        }
+
+        return false;
+    }
+
+    /**
+     * @ejb.interface-method
+     */
+    public boolean userExists(String name) {
+        try {
+            userHome.findByName(name);
+
+            return true;
+        } catch (FinderException ex) {
+            return false;
+        }
+    }
+}

File src/java/com/opensymphony/user/provider/ejb/entity/GroupEJB.java

 
 import java.rmi.RemoteException;
 
+import java.util.*;
+
 import javax.ejb.CreateException;
 import javax.ejb.EntityBean;
 import javax.ejb.EntityContext;
 /**
  * Entity bean representing Group.
  *
- * @ejb.bean type="CMP" name="Group" primkey-field="id" jndi-name="ejb/osuser/Group" view-type="remote" schema="OSGroup"
- * @ejb.interface remote-class="com.opensymphony.user.provider.ejb.entity.GroupRemote" extends="javax.ejb.EJBObject"
- * @ejb.home class="com.opensymphony.user.provider.ejb.entity.GroupHome" extends="javax.ejb.EJBHome"
+ * @ejb.bean type="CMP" name="Group" primkey-field="id" jndi-name="ejb/osuser/Group" view-type="local" schema="OSGroup"
+ * @ejb.interface local-extends="javax.ejb.EJBLocalObject"
+ * @ejb.home local-extends="javax.ejb.EJBLocalHome"
  * @ejb.pk class="java.lang.Long" extends="java.lang.Object"
  *
- * @ejb.finder  name="findAll" signature="java.util.Collection findAll()" query="select object(g) from OSGroup g"
- * @jboss.query name="findAll" signature="java.util.Collection findAll()" query="select object(g) from OSGroup g order by g.name"
- * @ejb.finder  name="findByName" signature="com.opensymphony.user.provider.ejb.entity.GroupRemote findByName(java.lang.String name)" query="select object(g) from OSGroup g where g.name = ?1"
- * @jboss.query name="findByName" signature="com.opensymphony.user.provider.ejb.entity.GroupRemote findByName(java.lang.String name)" query="select object(g) from OSGroup g where g.name = ?1 order by g.name"
+ * @ejb.finder
+ *  signature="Collection findAll()"
+ *  query="select DISTINCT OBJECT(u) from OSGroup g"
+ *  orion-sql-query="1=1 order by $name"
+ *  result-type-mapping="Local"
+ *
+ * @ejb.finder
+ *  signature="com.opensymphony.user.provider.ejb.entity.GroupLocal findByName(java.lang.String name)"
+ *  query="select DISTINCT OBJECT(u) from OSGroup g where g.name = ?1"
+ *  orion-sql-query="$name = $1 order by $name"
+ *  result-type-mapping="Local"
  *
  * @ejb.env-entry name="sequenceName" type="java.lang.String" value="OSUEntityEJB"
- * @ejb.ejb-external-ref ref-name="sequenceGenerator" type="Session" home="com.opensymphony.module.sequence.SequenceGeneratorHome" remote="com.opensymphony.module.sequence.SequenceGenerator" link="SequenceGenerator"
- * @ejb.ejb-external-ref ref-name="propertyStore" type="Session" home="com.opensymphony.module.propertyset.ejb.PropertyStoreHome" remote="com.opensymphony.module.propertyset.ejb.PropertyStore" link="PropertyStore"
+ *
+ * @ejb.ejb-external-ref
+ *  ref-name="sequenceGenerator"
+ *  type="Session"
+ *  view-type="remote"
+ *  home="com.opensymphony.module.sequence.SequenceGeneratorHome"
+ *  business="com.opensymphony.module.sequence.SequenceGenerator"
+ *  link="SequenceGenerator"
+ *
+ * @ejb.ejb-external-ref
+ *  ref-name="propertyStore"
+ *  type="Session"
+ *  view-type="remote"
+ *  home="com.opensymphony.module.propertyset.ejb.PropertyStoreHome"
+ *  business="com.opensymphony.module.propertyset.ejb.PropertyStore"
+ *  link="PropertyStore"
+ *
  *
  * @ejb.persistence table-name="OSGroup"
  *
  * @author <a href="mailto:joe@truemesh.com">Joe Walnes</a>
  * @author <a href="mailto:mike@atlassian.com">Mike Cannon-Brookes</a>
  * @author <a href="mailto:plightbo@cisco.com">Patrick Lightbody</a>
- * @version $Revision: 1.4 $
+ * @version $Revision: 1.5 $
  */
 public abstract class GroupEJB extends AbstractEntityAdapter implements EntityBean {
     //~ Methods ////////////////////////////////////////////////////////////////
     }
 
     /**
+     * @ejb.interface-method
+     */
+    public abstract void setUsers(Set users);
+
+    /**
+     * Collection of users with this group.
+     *
+     * @ejb.interface-method
+     * @ejb.relation
+     *  name="user-groups"
+     *  role-name="Group-Has-Users"
+     *  cascade-delete="no"
+     *
+     * @jboss.relation
+     *  related-pk-field="name"
+     *  fk-column="value"
+     *
+     * @jboss.relation-table table-name="osgroup_users"
+     *
+     * @jboss.relation-mapping style="relation-table"
+     *
+     * @weblogic.column-map
+     *  key-column="name"
+     *  foreign-key-column="value"
+     *
+     * @weblogic.relation
+     *  join-table-name="osgroup_users"
+     */
+    public abstract Set getUsers();
+
+    /**
+     * @ejb.interface-method
+     */
+    public List getUserNames() {
+        Iterator iter = getUsers().iterator();
+        List list = new ArrayList();
+
+        while (iter.hasNext()) {
+            UserLocal user = (UserLocal) iter.next();
+            list.add(user.getName());
+        }
+
+        return list;
+    }
+
+    /**
     * Create new Group with given name.
     *
     * @ejb.create-method
      */
-    public Long ejbCreate(String name) throws RemoteException, CreateException {
-        Long id = new Long(nextLong());
-
-        setId(id);
+    public Long ejbCreate(String name) throws CreateException {
+        try {
+            setId(new Long(nextLong()));
+        } catch (RemoteException e) {
+            throw new CreateException("Unable to obtain id:" + e);
+        }
 
         setName(name);
 
-        return id;
+        return null;
     }
 
     public void ejbPostCreate(String name) {

File src/java/com/opensymphony/user/provider/ejb/entity/MembershipEJB.java

-/*
- * Copyright (c) 2002-2003 by OpenSymphony
- * All rights reserved.
- */
-package com.opensymphony.user.provider.ejb.entity;
-
-import com.opensymphony.ejb.AbstractEntityAdapter;
-
-import java.rmi.RemoteException;
-
-import javax.ejb.CreateException;
-import javax.ejb.EntityBean;
-import javax.ejb.EntityContext;
-
-
-/**
- * Entity bean linking a User to a Group.
- *
- * @ejb.bean type="CMP" name="Membership" primkey-field="id" jndi-name="ejb/osuser/Membership" view-type="remote"
- * @ejb.interface remote-class="com.opensymphony.user.provider.ejb.entity.MembershipRemote" extends="javax.ejb.EJBObject"
- * @ejb.home class="com.opensymphony.user.provider.ejb.entity.MembershipHome" extends="javax.ejb.EJBHome"
- * @ejb.pk class="java.lang.Long" extends="java.lang.Object"
- *
- * @ejb.finder  name="findAll" signature="java.util.Collection findAll()" query="select object(m) from Membership m"
- * @ejb.finder  name="findByUser" signature="java.util.Collection findByUser(java.lang.String user)" query="select object(m) from Membership m where m.user = ?1"
- * @jboss.query name="findByUser" signature="java.util.Collection findByUser(java.lang.String user)" query="select object(m) from Membership m where m.user = ?1 order by m.user"
- * @ejb.finder  name="findByGroup" signature="java.util.Collection findByGroup(java.lang.String group)" query="select object(m) from Membership m where m.group = ?1"
- * @jboss.query name="findByGroup" signature="java.util.Collection findByGroup(java.lang.String group)" query="select object(m) from Membership m where m.group = ?1 order by m.group"
- * @ejb.finder    name="findByUserAndGroup" signature="com.opensymphony.user.provider.ejb.entity.MembershipRemote findByUserAndGroup(java.lang.String user, java.lang.String group)" query="select object(m) from Membership m where m.group = ?1 AND m.user = ?2"
- * @jboss.finder  name="findByUserAndGroup" signature="com.opensymphony.user.provider.ejb.entity.MembershipRemote findByUserAndGroup(java.lang.String user, java.lang.String group)" query="select object(m) from Membership m where m.group = ?1 AND m.user = ?2 order by m.group, m.user"
- *
- * @ejb.env-entry name="sequenceName" type="java.lang.String" value="MembershipEJB"
- * @ejb.ejb-external-ref ejb-name="sequenceGenerator" type="Session" home="com.opensymphony.module.sequence.SequenceGeneratorHome" remote="com.opensymphony.module.sequence.SequenceGenerator" link="SequenceGenerator"
- * @ejb.ejb-external-ref ejb-name="propertyStore" type="Session" home="com.opensymphony.module.propertyset.ejb.PropertyStoreHome" remote="com.opensymphony.module.propertyset.ejb.PropertyStore" link="PropertyStore"
- *
- * @ejb.persistence table-name="OSMembership"
- *
- * @author <a href="mailto:joe@truemesh.com">Joe Walnes</a>
- * @author <a href="mailto:mike@atlassian.com">Mike Cannon-Brookes</a>
- * @author <a href="mailto:plightbo@cisco.com">Patrick Lightbody</a>
- * @version $Revision: 1.3 $
- */
-public abstract class MembershipEJB extends AbstractEntityAdapter implements EntityBean {
-    //~ Methods ////////////////////////////////////////////////////////////////
-
-    /**
-     * Required to implement EntityBean. Sets the EntityContext.
-     * Also, attempts to detemine the <code>sequenceName</code>.
-     */
-    public void setEntityContext(EntityContext context) {
-        this.setContext(context);
-    }
-
-    public abstract void setGroup(String group);
-
-    /**
-     * Get Group
-     *
-     * @ejb.interface-method
-     * @ejb.persistence column-name="groupId"
-     */
-    public abstract String getGroup();
-
-    public abstract void setId(Long id);
-
-    /**
-     * Unique primary key of Membership.
-     *
-     * @ejb.interface-method
-     * @ejb.pk-field
-     * @ejb.persistence column-name="id"
-     */
-    public abstract Long getId();
-
-    public abstract void setUser(String user);
-
-    /**
-     * Get User
-     *
-     * @ejb.interface-method
-     * @ejb.persistence column-name="userId"
-     */
-    public abstract String getUser();
-
-    /**
-     * Create new Membership of User and Group.
-     *
-     * @ejb.create-method
-     */
-    public Long ejbCreate(String user, String group) throws RemoteException, CreateException {
-        Long id = new Long(nextLong());
-
-        setId(id);
-
-        setUser(user);
-
-        setGroup(group);
-
-        return id;
-    }
-
-    public void ejbPostCreate(String user, String group) {
-    }
-
-    /**
-     * Required to implement EntityBean. Sets the EntityContext to null.
-     */
-    public void unsetEntityContext() {
-        context = null;
-    }
-}

File src/java/com/opensymphony/user/provider/ejb/entity/UserEJB.java

  */
 package com.opensymphony.user.provider.ejb.entity;
 
-import com.opensymphony.ejb.AbstractEntityAdapter;
+import com.opensymphony.ejb.ExceptionlessEntityAdapter;
 
 import com.opensymphony.module.propertyset.PropertySet;
 
 
 import java.rmi.RemoteException;
 
+import java.util.*;
+
 import javax.ejb.CreateException;
 import javax.ejb.EntityBean;
 import javax.ejb.EntityContext;
 /**
  * Entity bean representing User. Stores name and hashed password.
  *
- * @ejb.bean type="CMP" name="User" primkey-field="id" jndi-name="ejb/osuser/User" view-type="remote"
- * @ejb.interface remote-class="com.opensymphony.user.provider.ejb.entity.UserRemote" extends="javax.ejb.EJBObject"
- * @ejb.home class="com.opensymphony.user.provider.ejb.entity.UserHome" extends="javax.ejb.EJBHome"
+ * @ejb.bean type="CMP" name="User" primkey-field="id" jndi-name="ejb/osuser/User" view-type="local"
+ * @ejb.interface local-extends="javax.ejb.EJBLocalObject"
+ * @ejb.home local-extends="javax.ejb.EJBLocalHome"
  * @ejb.pk class="java.lang.Long" extends="java.lang.Object"
  *
- * @ejb.finder  name="findAll" signature="java.util.Collection findAll()" query="select object(u) from User u"
- * @jboss.query name="findAll" signature="java.util.Collection findAll()" query="select object(u) from User u order by u.name"
- * @ejb.finder  name="findByName" signature="com.opensymphony.user.provider.ejb.entity.UserRemote findByName(java.lang.String name)" query="select object(u) from User u where u.name = ?1"
- * @jboss.query name="findByName" signature="com.opensymphony.user.provider.ejb.entity.UserRemote findByName(java.lang.String name)" query="select object(u) from User u where u.name = ?1 order by u.name"
+ * @ejb.finder
+ *  signature="Collection findAll()"
+ *  query="select DISTINCT OBJECT(u) from User u"
+ *  orion-sql-query="1=1 order by $name"
+ *  result-type-mapping="Local"
+ *
+ * @ejb.finder
+ *  signature="com.opensymphony.user.provider.ejb.entity.UserLocal findByName(java.lang.String name)"
+ *  query="select DISTINCT OBJECT(u) from User u where u.name = ?1"
+ *  orion-sql-query="$name = $1 order by $name"
+ *  result-type-mapping="Local"
  *
  * @ejb.env-entry name="sequenceName" type="java.lang.String" value="OSUEntityEJB"
- * @ejb.ejb-external-ref ref-name="sequenceGenerator" type="Session" home="com.opensymphony.module.sequence.SequenceGeneratorHome" remote="com.opensymphony.module.sequence.SequenceGenerator" link="SequenceGenerator"
- * @ejb.ejb-external-ref ref-name="propertyStore" type="Session" home="com.opensymphony.module.propertyset.ejb.PropertyStoreHome" remote="com.opensymphony.module.propertyset.ejb.PropertyStore" link="SequenceGenerator"
+ *
+ * @ejb.ejb-external-ref
+ *  ref-name="sequenceGenerator"
+ *  type="Session"
+ *  view-type="remote"
+ *  home="com.opensymphony.module.sequence.SequenceGeneratorHome"
+ *  business="com.opensymphony.module.sequence.SequenceGenerator"
+ *  link="SequenceGenerator"
+ *
+ * @ejb.ejb-external-ref
+ *  ref-name="propertyStore"
+ *  type="Session"
+ *  view-type="remote"
+ *  home="com.opensymphony.module.propertyset.ejb.PropertyStoreHome"
+ *  business="com.opensymphony.module.propertyset.ejb.PropertyStore"
+ *  link="PropertyStore"
  *
  * @ejb.persistence table="OSUser"
  *
  * @author <a href="mailto:joe@truemesh.com">Joe Walnes</a>
  * @author <a href="mailto:mike@atlassian.com">Mike Cannon-Brookes</a>
  * @author <a href="mailto:plightbo@cisco.com">Patrick Lightbody</a>
- * @version $Revision: 1.2 $
+ * @version $Revision: 1.3 $
  */
-public abstract class UserEJB extends AbstractEntityAdapter implements EntityBean {
+public abstract class UserEJB extends ExceptionlessEntityAdapter implements EntityBean {
     //~ Methods ////////////////////////////////////////////////////////////////
 
     /**
     /**
      * @ejb.interface-method
      */
+    public List getGroupNames() {
+        Iterator iter = getGroups().iterator();
+        List list = new ArrayList();
+
+        while (iter.hasNext()) {
+            GroupLocal group = (GroupLocal) iter.next();
+            list.add(group.getName());
+        }
+
+        return list;
+    }
+
+    /**
+     * @ejb.interface-method
+     */
+    public abstract void setGroups(Set groups);
+
+    /**
+     * Set of roles for this user
+     * @ejb.interface-method
+     *
+     * @ejb.relation
+     *    name="user-groups"
+     *    role-name="User-Has-Groups"
+     *    cascade-delete="no"
+     *
+     * @jboss.relation
+     *    related-pk-field="id"
+     *    fk-column="id"
+     *
+     * @jboss.relation-mapping style="relation-table"
+     *
+     * @jboss.relation-table
+     *    table-name="osgroup_users"
+     *
+     * @weblogic.column-map
+     * key-column="id"
+     * foreign-key-column="id"
+     *
+     * @weblogic.relation
+     *     join-table-name="osgroup_users"
+     */
+    public abstract Set getGroups();
+
+    /**
+     * @ejb.interface-method
+     */
     public void setPassword(String password) {
         setPasswordHash(createHash(password));
     }
     *
     * @ejb.create-method
     */
-    public Long ejbCreate(String name) throws RemoteException, CreateException {
-        Long id = new Long(nextLong());
-
-        setId(id);
+    public Long ejbCreate(String name) throws CreateException {
+        try {
+            Long id = new Long(nextLong());
+            setId(id);
+        } catch (RemoteException e) {
+            throw new CreateException("Unable to obtain id:" + e);
+        }
 
         setName(name);
 
     }
 
     /**
+     * @ejb.interface-method
+     */
+    public boolean inGroup(String groupName) {
+        Iterator iter = getGroups().iterator();
+
+        while (iter.hasNext()) {
+            GroupLocal group = (GroupLocal) iter.next();
+
+            if (group.getName().equals(groupName)) {
+                return true;
+            }
+        }
+
+        return false;
+    }
+
+    /**
+     * @ejb.interface-method
+     */
+    public boolean removeGroup(String name) {
+        Iterator iter = getGroups().iterator();
+
+        while (iter.hasNext()) {
+            GroupLocal group = (GroupLocal) iter.next();
+
+            if (group.getName().equals(name)) {
+                iter.remove();
+
+                return true;
+            }
+        }
+
+        return false;
+    }
+
+    /**
     * Required to implement EntityBean. Sets the EntityContext to null.
     */
     public void unsetEntityContext() {