package org.nextime.ion.backoffice.action.security;
import java.io.IOException;
import java.util.Vector;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.nextime.ion.backoffice.action.BaseAction;
import org.nextime.ion.backoffice.form.EditUserForm;
import org.nextime.ion.backoffice.exception.BackofficeSecurityException;
import org.nextime.ion.backoffice.security.SecurityManagerImpl;
import org.nextime.ion.framework.business.Group;
import org.nextime.ion.framework.business.User;
import org.nextime.ion.framework.mapping.Mapping;
public class DeleteUserAction extends BaseAction {
public ActionForward perform(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {
// check if user is correctly logged
checkUser(request);
// check if the user is authorized to perform this action
try {
Mapping.begin();
if (!new SecurityManagerImpl().canAdminSecurity(User.getInstance(request.getSession().getAttribute("userLogin")+"")) ) {
throw new Exception();
}
} catch (Exception e) {
throw new BackofficeSecurityException();
} finally {
Mapping.rollback();
}
// retrieve id
String id =
(request.getAttribute("id") != null)
? request.getAttribute("id").toString()
: request.getParameter("id").toString();
// all it's ok : delete user
try {
Mapping.begin();
User user = User.getInstance(id);
user.remove();
Mapping.commit();
} catch (Exception e) {
Mapping.rollback();
throw new ServletException(e);
}
// Forward to the next page
return (mapping.findForward("ok"));
}
}