01: package com.jat.presentation.controller.action;
02:
03: import javax.servlet.http.HttpServletRequest;
04: import javax.servlet.http.HttpServletResponse;
05:
06: import com.jat.business.JatUser;
07: import com.jat.business.authentication.AuthenticationException;
08: import com.jat.business.authentication.Authenticator;
09: import com.jat.core.log.LogManager;
10: import com.jat.presentation.controller.Action;
11: import com.jat.presentation.PresentationException;
12:
13: /**
14: * <p>Title: JAT</p>
15: * <p>Description: </p>
16: * <p>Copyright: Copyright (c) 2004 -2005 Stefano Fratini (stefano.fratini@gmail.com)</p>
17: * <p>Distributed under the terms of the GNU Lesser General Public License, v2.1 or later</p>
18: * @author stf
19: * @version 1.0
20: * @since 1.2
21: */
22:
23: public class LoginAction extends Action {
24:
25: public LoginAction() throws Exception {
26: String authClass = com.jat.core.config.Config.getCurrent()
27: .getValue("authentication", "class");
28: auth = (Authenticator) Class.forName(authClass).newInstance();
29: }
30:
31: public void doAction(HttpServletRequest request,
32: HttpServletResponse response) throws PresentationException {
33: String username = request.getParameter("username");
34: String password = request.getParameter("password");
35: JatUser user = null;
36: try {
37: user = auth.authenticate(username, password);
38: request.getSession(true).setAttribute(JatUser.JAT_USER,
39: user);
40: LogManager
41: .sendLog(this .getClass().getName()
42: + "::authentication: User successfully authenticated: "
43: + user);
44: } catch (AuthenticationException ex) {
45: throw new PresentationException(ex.getMessage());
46: }
47: }
48:
49: private Authenticator auth;
50: }
|