01: /* Copyright (c) 2001 - 2007 TOPP - www.openplans.org. All rights reserved.
02: * This code is licensed under the GPL 2.0 license, availible at the root
03: * application directory.
04: */
05:
06: /*
07: * Created on Feb 3, 2004
08: *
09: * To change the template for this generated file go to
10: * Window - Preferences - Java - Code Generation - Code and Comments
11: */
12: package org.vfny.geoserver.action;
13:
14: import org.apache.struts.Globals;
15: import org.apache.struts.action.ActionError;
16: import org.apache.struts.action.ActionErrors;
17: import org.apache.struts.action.ActionForm;
18: import org.apache.struts.action.ActionForward;
19: import org.apache.struts.action.ActionMapping;
20: import org.springframework.beans.BeansException;
21: import org.springframework.context.ApplicationContext;
22: import org.springframework.context.ApplicationContextAware;
23: import org.vfny.geoserver.form.LoginForm;
24: import org.vfny.geoserver.global.GeoServer;
25: import org.vfny.geoserver.global.UserContainer;
26: import javax.servlet.http.HttpServletRequest;
27: import javax.servlet.http.HttpServletResponse;
28:
29: /**
30: * LoginAction purpose.
31: *
32: * <p>
33: * Processes the login of a user to gain access to the GeoServer Configuration.
34: * Currently the defaults are "admin" for username, "geoserver" for password,
35: * case insensitive. This value can be changed in the services.xml file,
36: * found in the WEB-INF directory of a running GeoServer. A page to change
37: * the log in would be nice, but it's not here yet.
38: * </p>
39: *
40: * @author rgould, Refractions Research, Inc.
41: * @author $Author: cholmesny $ (last modification)
42: * @version $Id: LoginAction.java 6326 2007-03-15 18:36:40Z jdeolive $
43: *
44: * @task TODO: add a page to change the username and password from the ui.
45: */
46: public class LoginAction extends GeoServerAction implements
47: ApplicationContextAware {
48: ApplicationContext context;
49:
50: public ActionForward execute(ActionMapping mapping,
51: ActionForm form, HttpServletRequest request,
52: HttpServletResponse response) {
53: LoginForm loginForm = (LoginForm) form;
54: String username = loginForm.getUsername();
55: String password = loginForm.getPassword();
56:
57: //GlobalConfig global = (GlobalConfig) getServlet().getServletContext()
58: // .getAttribute(GlobalConfig.CONFIG_KEY);
59: GeoServer geoserver = getWFS(request).getGeoServer();
60:
61: if (username.equalsIgnoreCase(geoserver.getAdminUserName())
62: && password.equalsIgnoreCase(geoserver
63: .getAdminPassword())) {
64: UserContainer user = new UserContainer();
65: user.setUsername(username);
66: request.getSession().setAttribute(
67: UserContainer.SESSION_KEY, user);
68:
69: String forward = (String) request.getAttribute("forward");
70:
71: if (forward == null) {
72: forward = "welcome";
73: }
74:
75: return mapping.findForward(forward);
76: }
77:
78: ActionErrors errors = new ActionErrors();
79: errors.add(ActionErrors.GLOBAL_ERROR, new ActionError(
80: "error.login.invalidCombo"));
81: errors.add(ActionErrors.GLOBAL_ERROR, new ActionError(
82: "message.login.hint"));
83: request.setAttribute(Globals.ERROR_KEY, errors);
84:
85: return mapping.findForward("login");
86: }
87:
88: public void setApplicationContext(ApplicationContext arg0)
89: throws BeansException {
90: this.context = arg0;
91: }
92: }
|