1 19 20 package com.sslexplorer.security.actions; 21 22 import javax.servlet.http.HttpServletRequest ; 23 import javax.servlet.http.HttpServletResponse ; 24 25 import org.apache.struts.Globals; 26 import org.apache.struts.action.ActionForm; 27 import org.apache.struts.action.ActionForward; 28 import org.apache.struts.action.ActionMapping; 29 import org.apache.struts.action.ActionMessage; 30 import org.apache.struts.action.ActionMessages; 31 32 import com.sslexplorer.core.CoreAttributeConstants; 33 import com.sslexplorer.core.CoreEvent; 34 import com.sslexplorer.core.CoreEventConstants; 35 import com.sslexplorer.core.CoreServlet; 36 import com.sslexplorer.core.UserDatabaseManager; 37 import com.sslexplorer.core.actions.AuthenticatedDispatchAction; 38 import com.sslexplorer.policyframework.PolicyConstants; 39 import com.sslexplorer.policyframework.PolicyUtil; 40 import com.sslexplorer.security.LogonControllerFactory; 41 import com.sslexplorer.security.SessionInfo; 42 import com.sslexplorer.security.User; 43 import com.sslexplorer.security.UserDatabase; 44 45 51 public class DeleteAccountsAction extends AuthenticatedDispatchAction { 52 53 56 public DeleteAccountsAction() { 57 super(); 58 } 59 60 68 public ActionForward onExecute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) 69 throws Exception { 70 PolicyUtil.checkPermission(PolicyConstants.ACCOUNTS_AND_GROUPS_RESOURCE_TYPE, PolicyConstants.PERM_DELETE, request); 71 72 User currentUser = isSetupMode() ? null : LogonControllerFactory.getInstance().getUser(request); 73 74 String [] accounts = request.getParameterValues("username"); 75 boolean found = false; 76 for (int i = 0; i < accounts.length; i++) { 77 if (currentUser != null && accounts[i].equals(currentUser.getPrincipalName())) { 78 found = true; 79 } 80 } 81 if (!found) { 82 UserDatabase udb = UserDatabaseManager.getInstance().getUserDatabase(currentUser.getRealm()); 83 for (int i = 0; accounts != null && i < accounts.length; i++) { 84 User user = udb.getAccount(accounts[i]); 85 if(udb.supportsAccountCreation()) { 86 try { 87 udb.deleteAccount(user); 88 CoreServlet.getServlet().fireCoreEvent(new CoreEvent(this, CoreEventConstants.USER_REMOVED, null, null, CoreEvent.STATE_SUCCESSFUL) 89 .addAttribute(CoreAttributeConstants.EVENT_ATTR_PRINCIPAL_ID, user.getPrincipalName()) 90 .addAttribute(CoreAttributeConstants.EVENT_ATTR_FULL_NAME, user.getFullname())); 91 } catch (Exception e) { 92 CoreServlet.getServlet().fireCoreEvent(new CoreEvent(this, CoreEventConstants.USER_REMOVED, null, null, e) 93 .addAttribute(CoreAttributeConstants.EVENT_ATTR_PRINCIPAL_ID, user.getPrincipalName()) 94 .addAttribute(CoreAttributeConstants.EVENT_ATTR_FULL_NAME, user.getFullname())); 95 throw e; 96 } 97 } 98 } 99 } else { 100 ActionMessages mesgs = new ActionMessages(); 101 mesgs.add(Globals.ERROR_KEY, new ActionMessage("availableAccounts.cannotDeleteOwnAccount")); 102 saveErrors(request, mesgs); 103 } 104 105 return mapping.findForward("refresh"); 106 } 107 108 111 public int getNavigationContext(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { 112 return SessionInfo.MANAGEMENT_CONSOLE_CONTEXT; 113 } 114 115 123 public ActionForward delete(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) 124 throws Exception { 125 return mapping.findForward("success"); 126 } 127 } | Popular Tags |