6 Replies Latest reply on Jul 18, 2006 3:07 AM by kazam

    Remove or Delete User - Group from Identity store

    kazam Newbie


      The identity session has ways of saving and updating users and groups to the datastore but how can I remove a user or a group.

      In the membership.hbm.xml I can see the cascade options but, where in the Identity API are the removal calls.

      Thanks, Kazam.

        • 1. Re: Remove or Delete User - Group from Identity store
          David Hosier Novice

          There are none. And be careful with the cascades, they are screwed up. If you were to implement the removeUser(), it will cause all groups the user belongs to to be deleted, along with all users that are in those groups. I've implemented the removeUser() myself, and I fixed the cascade settings in my own server, but I don't really have time right now to post that stuff here. Let me know if you're interested, and I can try to do it this weekend. Sorry.

          • 2. Re: Remove or Delete User - Group from Identity store
            kazam Newbie

            Thanks very much David,
            If you could put up the removeUser and cascade issues you resolved, that would be great.
            Kazam.

            • 3. Re: Remove or Delete User - Group from Identity store
              kazam Newbie

              The persitence mechanism for identitySession is failing for any commit operation.

              Please look at the following post, http://www.jboss.com/index.html?module=bb&op=viewtopic&t=86898

              David, please let me know how you are using identitySession to commit transactions.
              Thanks, Kazam.

              • 4. Re: Remove or Delete User - Group from Identity store
                David Hosier Novice

                So first off, sorry for the delay...very busy with work stuff. Second, I'm not sure what you mean when you ask about using the identitySession to commit transactions. I call IdentitySession methods, that's it. Hibernate takes care of all that stuff in the background. I responded to the thread you referenced, but my response isn't much help right now.

                Ok, here is what I did for deleting Users. I added a method called deleteUserByName(String ) to the IdentitySession class, which is as follows:

                public void deleteUserByName(String userName) {
                 User user = getUserByName(userName);
                 session.delete(user);
                }

                And here is the method I have in a class of mine where I call this:
                public void deleteUser(String userName)
                {
                 JbpmContext jbpmContext = _jbpmConfig.createJbpmContext();
                 try
                 {
                 IdentitySession idSession = new IdentitySession(jbpmContext.getSession());
                 idSession.deleteUserByName(userName);
                 }
                 finally
                 {
                 jbpmContext.close();
                 }
                }

                As for the cascade changes, give me a bit to do a diff, and then I'll post that information as well.

                • 5. Re: Remove or Delete User - Group from Identity store
                  David Hosier Novice

                  As promised, here are the hibernate cascade changes. All the identity hibernate mapping files I changed can be found in the jBPM source directory src\java.identity\org\jbpm\identity.

                  In User.hbm.xml, change

                  <set name="memberships" cascade="all">
                  to
                  <set name="memberships" cascade="all-delete-orphan">


                  In Group.hbm.xml, change
                  <set name="memberships" cascade="all">
                  to
                  <set name="memberships" cascade="all-delete-orphan">


                  In Membership.hbm.xml, change
                  <many-to-one name="user" column="USER_" cascade="all"
                   foreign-key="FK_ID_MEMSHIP_USR"/>
                  <many-to-one name="group" column="GROUP_" cascade="all"
                   foreign-key="FK_ID_MEMSHIP_GRP"/>
                  to
                  <many-to-one name="user" column="USER_" cascade="save-update"
                   foreign-key="FK_ID_MEMSHIP_USR"/>
                  <many-to-one name="group" column="GROUP_" cascade="save-update"
                   foreign-key="FK_ID_MEMSHIP_GRP"/>


                  Bear in mind that I have absolutely zero experience with Hibernate. I was only able to tweak these settings after checking out a website that my boss sent me, which I unfortunately did not bookmark (so I can't pass it along). But I'm sure a Google search can help elucidate these cascade settings if you have questions about them. And maybe someone smart like Ronald or Koen might stumble across this and point out that I've done something terribly wrong. All I know is that these changes worked for me to accomplish what I needed to add to jBPM (running with Oracle10g to boot). I've added other methods to the IdentitySession class as well if you have any other needs, but you could also try taking a stab at writing the methods based on my example and the others that already exist...which is what I did.

                  • 6. Re: Remove or Delete User - Group from Identity store
                    kazam Newbie

                    Great! Thanks for your help David.