KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > forrest > forrestbot > webapp > action > ViewSummaryAction


1 /*
2 * Copyright 2002-2004 The Apache Software Foundation or its licensors,
3 * as applicable.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */

17 package org.apache.forrest.forrestbot.webapp.action;
18
19 import java.util.Collection JavaDoc;
20 import java.util.Date JavaDoc;
21 import java.util.Iterator JavaDoc;
22
23 import javax.servlet.http.HttpServletRequest JavaDoc;
24 import javax.servlet.http.HttpServletResponse JavaDoc;
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 JavaDoc request, HttpServletResponse JavaDoc response) throws Exception JavaDoc {
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 JavaDoc username = (String JavaDoc) PropertyUtils.getSimpleProperty(form, "username");
50             String JavaDoc password = (String JavaDoc) 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 JavaDoc());
75
76         if (checkAuthorized(request, response, false)) {
77             // set access for each project
78
String JavaDoc currentUser = (String JavaDoc) request.getSession(true).getAttribute("username");
79             Collection JavaDoc projects = Project.getAllProjects();
80             for (Iterator JavaDoc 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