+ } catch (IllegalStateException | SecurityException | SystemException e) {
+ log.error("Unable to rollback session in 'finally', " + "the system might be in a dirty state");
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+
+ private class ResetEmail {
+ private String newEmail;
+ private UserAdminWrapper userAdminWrapper;
+ private List<User> usersToUpdate;
+
+ public ResetEmail(UserAdminWrapper userAdminWrapper, List<User> usersToUpdate, String newEmail) {
+ this.newEmail = newEmail;
+ this.usersToUpdate = usersToUpdate;
+ this.userAdminWrapper = userAdminWrapper;
+ }
+
+ @SuppressWarnings("unchecked")
+ protected void doUpdate() {
+ userAdminWrapper.beginTransactionIfNeeded();
+ try {
+ for (User user : usersToUpdate) {
+ // the char array is emptied after being used.
+ user.getProperties().put(LdapAttrs.mail.name(), newEmail);
+ }
+
+ userAdminWrapper.commitOrNotifyTransactionStateChange();
+ if (!usersToUpdate.isEmpty())
+ userAdminWrapper.notifyListeners(
+ new UserAdminEvent(null, UserAdminEvent.ROLE_CHANGED, usersToUpdate.get(0)));
+ } catch (Exception e) {
+ throw new CmsException("Cannot perform batch update on users", e);
+ } finally {
+ UserTransaction ut = userAdminWrapper.getUserTransaction();
+ try {
+ if (ut.getStatus() != javax.transaction.Status.STATUS_NO_TRANSACTION)
+ ut.rollback();
+ } catch (IllegalStateException | SecurityException | SystemException e) {
+ log.error("Unable to rollback session in finally block, the system might be in a dirty state");