protected void updateUser(int userId, IPerson person, TemplateUser templateUser) throws Exception {
// Remove my existing group memberships
IGroupMember me = GroupService.getGroupMember(person.getEntityIdentifier());
Iterator myExistingGroups = me.getContainingGroups();
while (myExistingGroups.hasNext()) {
IEntityGroup eg = (IEntityGroup)myExistingGroups.next();
ILockableEntityGroup leg = getSafeLockableGroup(eg, me);
if (leg != null) {
removePersonFromGroup(person, me, leg);
}
}
// Copy template user's groups memberships
IGroupMember template = GroupService.getEntity(templateUser.getUserName(), Class.forName("org.jasig.portal.security.IPerson"));
Iterator templateGroups = template.getContainingGroups();
while (templateGroups.hasNext()) {
IEntityGroup eg = (IEntityGroup)templateGroups.next();
ILockableEntityGroup leg = getSafeLockableGroup(eg, me);
if (leg != null) {
addPersonToGroup(person, me, leg);
}
}