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.CreateUserForm; 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 CreateUserAction 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 try { 37 Mapping.begin(); 38 if (!new SecurityManagerImpl().canAdminSecurity(User.getInstance(request.getSession().getAttribute("userLogin")+"")) ) { 39 throw new Exception (); 40 } 41 } catch (Exception e) { 42 throw new BackofficeSecurityException(); 43 } finally { 44 Mapping.rollback(); 45 } 46 47 CreateUserForm sform = (CreateUserForm) form; 49 ActionErrors errors = sform.myValidate(request); 50 51 if (request.getParameter("cancel") != null) { 53 return (mapping.findForward("cancel")); 55 } 56 57 if (sform.getName() == null) { 59 try { 60 Mapping.begin(); 61 Vector groups = Group.listAll(); 62 Mapping.rollback(); 63 64 request.setAttribute("groups", groups); 65 66 } catch (Exception e) { 67 Mapping.rollback(); 68 throw new ServletException (e); 69 } 70 71 return (mapping.findForward("view")); 73 } 74 75 if (errors.size() > 0) { 77 try { 78 Mapping.begin(); 79 Vector groups = Group.listAll(); 80 Mapping.rollback(); 81 82 request.setAttribute("groups", groups); 83 request.setAttribute(ERROR_KEY, errors); 84 85 } catch (Exception e) { 86 Mapping.rollback(); 87 throw new ServletException (e); 88 } 89 90 return (mapping.findForward("view")); 92 } 93 94 try { 96 Mapping.begin(); 97 User user = User.create(sform.getLogin()); 98 user.setMetaData("name", sform.getName()); 99 user.setMetaData("email", sform.getEmail()); 100 user.setPassword(sform.getPassword()); 101 user.resetGroups(); 102 if (sform.getGroups() != null) { 103 for (int i = 0; i < sform.getGroups().length; i++) { 104 Group group = Group.getInstance(sform.getGroups()[i]); 105 user.addGroup(group); 106 } 107 } 108 Mapping.commit(); 109 110 } catch (Exception e) { 111 Mapping.rollback(); 112 throw new ServletException (e); 113 } 114 115 return (mapping.findForward("ok")); 117 } 118 119 } 120 | Popular Tags |