*/
public ActionForward accountDeletion(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
PolicyUtil.checkPermission(PolicyConstants.ACCOUNTS_AND_GROUPS_RESOURCE_TYPE, PolicyConstants.PERM_DELETE, request);
User currentUser = isSetupMode() ? null : LogonControllerFactory.getInstance().getUser(request);
String[] accounts = request.getParameterValues("username");
boolean found = false;
for (int i = 0; i < accounts.length; i++) {
if (currentUser != null && accounts[i].equals(currentUser.getPrincipalName())) {
found = true;
}
}
if (!found) {
UserDatabase udb = UserDatabaseManager.getInstance().getUserDatabase(getSessionInfo(request).getUser().getRealm());
for (int i = 0; accounts != null && i < accounts.length; i++) {
User user = udb.getAccount(accounts[i]);
if (udb.supportsAccountCreation()) {
try {
// check to see if the user has a session, if so then logoff.
Iterator loggedOnUserSessions = LogonControllerFactory.getInstance().getActiveSessions().values()
.iterator();
while (loggedOnUserSessions.hasNext()) {
SessionInfo element = (SessionInfo) loggedOnUserSessions.next();
if (element.getUser().equals(user)) {
element.invalidate();
}
}
// Revoke all polices from the user
PolicyDatabaseFactory.getInstance().revokeAllPoliciesFromPrincipal(user);
udb.deleteAccount(user);
CoreServlet.getServlet().fireCoreEvent(
new CoreEvent(this, CoreEventConstants.USER_REMOVED, null, null, CoreEvent.STATE_SUCCESSFUL)
.addAttribute(CoreAttributeConstants.EVENT_ATTR_PRINCIPAL_ID, user.getPrincipalName())
.addAttribute(CoreAttributeConstants.EVENT_ATTR_FULL_NAME, user.getFullname()));
} catch (Exception e) {
CoreServlet.getServlet().fireCoreEvent(
new CoreEvent(this, CoreEventConstants.USER_REMOVED, null, null, e)
.addAttribute(CoreAttributeConstants.EVENT_ATTR_PRINCIPAL_ID, user.getPrincipalName())
.addAttribute(CoreAttributeConstants.EVENT_ATTR_FULL_NAME, user.getFullname()));
throw e;
}
}
}
} else {