1 package org.nextime.ion.backoffice.action.security; 2 3 import java.io.IOException ; 4 import java.util.Vector ; 5 6 import javax.servlet.ServletException ; 7 import javax.servlet.http.HttpServletRequest ; 8 import javax.servlet.http.HttpServletResponse ; 9 10 import org.apache.struts.action.ActionErrors; 11 import org.apache.struts.action.ActionForm; 12 import org.apache.struts.action.ActionForward; 13 import org.apache.struts.action.ActionMapping; 14 import org.nextime.ion.backoffice.action.BaseAction; 15 import org.nextime.ion.backoffice.form.EditUserForm; 16 import org.nextime.ion.backoffice.exception.BackofficeSecurityException; 17 import org.nextime.ion.backoffice.security.SecurityManagerImpl; 18 19 import org.nextime.ion.framework.business.Group; 20 import org.nextime.ion.framework.business.User; 21 import org.nextime.ion.framework.mapping.Mapping; 22 23 public class EditUserAction extends BaseAction { 24 25 public ActionForward perform( 26 ActionMapping mapping, 27 ActionForm form, 28 HttpServletRequest request, 29 HttpServletResponse response) 30 throws IOException , ServletException { 31 32 checkUser(request); 34 35 36 try { 38 Mapping.begin(); 39 if (!new SecurityManagerImpl().canAdminSecurity(User.getInstance(request.getSession().getAttribute("userLogin")+"")) ) { 40 throw new Exception (); 41 } 42 } catch (Exception e) { 43 throw new BackofficeSecurityException(); 44 } finally { 45 Mapping.rollback(); 46 } 47 48 49 EditUserForm sform = (EditUserForm) form; 51 ActionErrors errors = sform.myValidate(request); 52 53 if (request.getParameter("cancel") != null) { 55 return (mapping.findForward("cancel")); 57 } 58 59 String id = 61 (request.getAttribute("id") != null) 62 ? request.getAttribute("id").toString() 63 : request.getParameter("id").toString(); 64 65 if (sform.getName() == null) { 67 try { 68 Mapping.begin(); 69 User user = User.getInstance(id); 70 Vector groups = Group.listAll(); 71 Mapping.rollback(); 72 73 sform.setEmail((String )user.getMetaData("email")); 74 sform.setName((String )user.getMetaData("name")); 75 sform.setGroups(user.getGroupsIds()); 76 sform.setPassword(user.getPassword()); 77 request.setAttribute("groups", groups); 78 79 } catch (Exception e) { 80 Mapping.rollback(); 81 throw new ServletException (e); 82 } 83 84 return (mapping.findForward("view")); 86 } 87 88 if (errors.size() > 0) { 90 try { 91 Mapping.begin(); 92 Vector groups = Group.listAll(); 93 Mapping.rollback(); 94 95 request.setAttribute("groups", groups); 96 request.setAttribute(ERROR_KEY, errors); 97 98 } catch (Exception e) { 99 Mapping.rollback(); 100 throw new ServletException (e); 101 } 102 103 return (mapping.findForward("view")); 105 } 106 107 try { 109 Mapping.begin(); 110 User user = User.getInstance(id); 111 user.setMetaData("name", sform.getName()); 112 user.setMetaData("email", sform.getEmail()); 113 user.setPassword(sform.getPassword()); 114 user.resetGroups(); 115 for( int i=0; i<sform.getGroups().length; i++ ) { 116 Group group = Group.getInstance(sform.getGroups()[i]); 117 user.addGroup(group); 118 } 119 Mapping.commit(); 120 121 } catch (Exception e) { 122 Mapping.rollback(); 123 throw new ServletException (e); 124 } 125 126 return (mapping.findForward("ok")); 128 } 129 130 } 131 | Popular Tags |