001: package hero.struts.actions;
002:
003: import java.io.IOException;
004: import javax.servlet.ServletException;
005: import javax.servlet.http.HttpServletRequest;
006: import javax.servlet.http.HttpSession;
007: import javax.servlet.http.HttpServletResponse;
008: import org.apache.struts.action.ActionError;
009: import org.apache.struts.action.ActionErrors;
010: import org.apache.struts.action.ActionForm;
011: import org.apache.struts.action.ActionMapping;
012: import org.apache.struts.action.ActionForward;
013: import hero.interfaces.*;
014:
015: /**
016: * <strong>LoginAction</strong>
017: * Action that performs users authentication and forward activity or project
018: * information
019: *
020: *@author Miguel Valdes Faura
021: */
022: public class LoginAction extends AbstStrutsActionBase {
023: /**
024: *@param String containing username
025: *@param String containing password
026: *@return boolean - true authenticated, false not authenticated.
027: */
028: public boolean authenticate(String username, String password) {
029: return (true);
030: }
031:
032: /**
033: * @param mapping The ActionMapping used to select this instance
034: * @param actionForm The optional AbstActionFormBase bean for this request (if any)
035: * @param request The HTTP request we are processing
036: * @param response The HTTP response we are creating
037: * @exception IOException if an input/output error occurs
038: * @exception ServletException if a servlet exception occurs
039: */
040:
041: public ActionForward perform(ActionMapping mapping,
042: ActionForm form, HttpServletRequest request,
043: HttpServletResponse response) throws IOException,
044: ServletException {
045: // Assume that the login fails, so that the login page is redisplayed
046: // if the user isn't authenticated
047: ActionForward actionForward = mapping.findForward(LOGIN);
048: // Create the container for any errors that occur
049: ActionErrors errors = new ActionErrors();
050:
051: // Extract attributes and parameters we will need from the incoming
052: // form.
053:
054: HttpSession session = request.getSession();
055: String action = (String) session.getAttribute("action");
056:
057: try {
058:
059: hero.interfaces.UserSessionLocalHome userh = (UserSessionLocalHome) hero.interfaces.UserSessionUtil
060: .getLocalHome();
061: hero.interfaces.UserSessionLocal usersession = userh
062: .create();
063:
064: request.getSession(true).setAttribute("username",
065: usersession.getUser());
066: request.getSession(true).setAttribute("password",
067: usersession.getUserPassword());
068: request.getSession(true)
069: .setAttribute("workElement", "null");
070:
071: if (action.equals("user")) {
072: request.getSession(true).setAttribute("user",
073: usersession);
074:
075: String project = (String) session
076: .getAttribute("project");
077:
078: if (project.equals("clone")) {
079: // Forward control to the specified 'success' URI specified in the structs-config.xml
080: actionForward = mapping.findForward(CLONEPROJECT);
081: }
082: if (project.equals("details")) {
083: // Forward control to the specified 'success' URI specified in the structs-config.xml
084: actionForward = mapping.findForward(PROJECTDETAILS);
085: }
086: } else {
087: try {
088: String project = (String) session
089: .getAttribute("projectname");
090:
091: hero.interfaces.ProjectSessionLocalHome projecth = (ProjectSessionLocalHome) hero.interfaces.ProjectSessionUtil
092: .getLocalHome();
093: hero.interfaces.ProjectSessionLocal projectsession = projecth
094: .create();
095: projectsession.initProject(project);
096:
097: if (action.equals("node")) {
098: String name = (String) session
099: .getAttribute("nodename");
100: String username = (String) session
101: .getAttribute("username");
102: hero.util.StrutsNodeValue node = projectsession
103: .getStrutsNode(name);
104: request.getSession(true).setAttribute("node",
105: node);
106:
107: if (!node.getDeadline().equals(
108: "Deadline needed")) {
109: java.sql.Timestamp deadline = java.sql.Timestamp
110: .valueOf(node.getDeadline()
111: + " 00:00:00");
112: if (deadline.getTime() <= (new java.util.Date())
113: .getTime()
114: && !node.getState().equals(
115: "TERMINATED"))
116: ;
117: errors.add("deadline_error",
118: new ActionError("error.deadline"));
119: }
120:
121: request.getSession(true).setAttribute(
122: "project", projectsession);
123: request.getSession(true).setAttribute("proAct",
124: "false");
125: request.getSession(true).setAttribute("edit",
126: "false");
127:
128: // Forward control to the specified 'success' URI specified in the structs-config.xml
129: actionForward = mapping.findForward(ACTIVITY);
130: }
131: if (action.equals("project")) {
132: request.getSession(true).setAttribute(
133: "project", projectsession);
134: request.getSession(true).setAttribute("proAct",
135: "true");
136: request.getSession(true).setAttribute("edit",
137: "false");
138:
139: request.getSession(true).setAttribute("nodes",
140: projectsession.getStrutsNodes());
141: request.getSession(true).setAttribute("edges",
142: projectsession.getStrutsEdges());
143:
144: // Forward control to the specified 'success' URI specified in the structs-config.xml
145: actionForward = mapping.findForward(PROJECT);
146: }
147: } catch (Exception pe) {
148: actionForward = mapping.findForward(INITIAL);
149: errors.add("project_error", new ActionError(
150: "error.project.mismatch"));
151: }
152: }
153: } catch (Exception e) {
154: errors.add(ActionErrors.GLOBAL_ERROR, new ActionError(
155: "error.password.mismatch"));
156: }
157:
158: // If any messages is required, save the specified error messages keys
159: // into the HTTP request for use by the <struts:errors> tag.
160: if (!errors.empty()) {
161: saveErrors(request, errors);
162: }
163:
164: // Forward control to the appropriate URI as determined by the action.
165: return (actionForward);
166: }
167: }
|