1 17 package org.apache.forrest.forrestbot.webapp.action; 18 19 import java.util.Collection ; 20 import java.util.Date ; 21 import java.util.Iterator ; 22 23 import javax.servlet.http.HttpServletRequest ; 24 import javax.servlet.http.HttpServletResponse ; 25 26 import org.apache.commons.beanutils.PropertyUtils; 27 import org.apache.forrest.forrestbot.webapp.Constants; 28 import org.apache.forrest.forrestbot.webapp.dto.ProjectDTO; 29 import org.apache.forrest.forrestbot.webapp.util.Project; 30 import org.apache.log4j.Logger; 31 import org.apache.struts.action.ActionError; 32 import org.apache.struts.action.ActionErrors; 33 import org.apache.struts.action.ActionForm; 34 import org.apache.struts.action.ActionForward; 35 import org.apache.struts.action.ActionMapping; 36 37 import com.opensymphony.user.EntityNotFoundException; 38 import com.opensymphony.user.UserManager; 39 40 public final class ViewSummaryAction extends BaseAction { 41 private static Logger log = Logger.getLogger(ViewSummaryAction.class); 42 43 public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { 44 super.execute(mapping, form, request, response); 45 46 if (form != null && !PropertyUtils.getSimpleProperty(form, "submit").equals("unsubmitted")) { 47 ActionErrors errors = form.validate(mapping, request); 48 49 String username = (String ) PropertyUtils.getSimpleProperty(form, "username"); 50 String password = (String ) PropertyUtils.getSimpleProperty(form, "password"); 51 52 request.setAttribute("username", username); 53 54 55 UserManager userManager = UserManager.getInstance(); 56 57 boolean validPassword = false; 58 try { 59 validPassword = userManager.getUser(username).authenticate(password); 60 } catch (EntityNotFoundException e) { 61 validPassword = false; 62 } 63 if (!validPassword) { 64 log.debug("bad password"); 65 errors.add("password", new ActionError("error.authentication")); 66 saveErrors(request, errors); 67 } else { 68 log.debug("authenticated"); 69 request.getSession(true).setAttribute("auth", Boolean.TRUE); 70 request.getSession(true).setAttribute("username", username); 71 } 72 } 73 74 request.setAttribute("serverTime", new Date ()); 75 76 if (checkAuthorized(request, response, false)) { 77 String currentUser = (String ) request.getSession(true).getAttribute("username"); 79 Collection projects = Project.getAllProjects(); 80 for (Iterator i = projects.iterator(); i.hasNext();) { 81 ProjectDTO projectDTO = (ProjectDTO)i.next(); 82 (new Project(projectDTO)).loadSecurity(currentUser); 83 } 84 request.setAttribute("projects", projects); 85 86 return mapping.findForward(Constants.FORWARD_NAME_AUTHORIZED); 87 } 88 89 request.setAttribute("projects", Project.getAllProjects()); 90 return mapping.findForward(Constants.FORWARD_NAME_SUCCESS); 91 92 } 93 } 94 | Popular Tags |