01: package org.claros.mini.actions;
02:
03: import javax.servlet.http.HttpServletRequest;
04: import javax.servlet.http.HttpServletResponse;
05: import org.apache.struts.action.ActionForm;
06: import org.apache.struts.action.ActionForward;
07: import org.apache.struts.action.ActionMapping;
08:
09: import org.claros.commons.auth.MailAuth;
10: import org.claros.commons.auth.exception.LoginInvalidException;
11: import org.claros.commons.mail.models.ConnectionMetaHandler;
12: import org.claros.commons.mail.models.ConnectionProfile;
13: import org.claros.commons.mail.models.ConnectionProfileList;
14: import org.claros.commons.models.AuthProfile;
15: import org.claros.mini.common.BaseClarosAction;
16: import org.claros.mini.models.LoginFormBean;
17:
18: /**
19: * @version 1.0
20: * @author Umut Gökbayrak
21: */
22: public class VerifyAction extends BaseClarosAction {
23:
24: public ActionForward myExecute(ActionMapping mapping,
25: ActionForm form, HttpServletRequest request,
26: HttpServletResponse response) throws Exception {
27: ActionForward forward = null;
28: LoginFormBean bean = (LoginFormBean) form;
29:
30: try {
31: if (bean != null && bean.getServer() != null) {
32: ConnectionProfile profile = ConnectionProfileList
33: .getProfileByShortName(bean.getServer());
34: if (bean.getUsername() != null
35: && bean.getPassword() != null) {
36: AuthProfile auth = new AuthProfile();
37: auth.setUsername(bean.getUsername());
38: auth.setPassword(bean.getPassword());
39: ConnectionMetaHandler handler = getConnectionHandler(request);
40: handler = MailAuth.authenticate(profile, auth,
41: handler);
42: if (handler != null) {
43: request.getSession().setAttribute("handler",
44: handler);
45: request.getSession().setAttribute("auth", auth);
46: request.getSession().setAttribute("profile",
47: profile);
48:
49: /*
50: // create default mailboxes if not exists
51: FolderControllerFactory factory = new FolderControllerFactory(auth, profile, handler);
52: FolderController foldCont = factory.getFolderController();
53: foldCont.createDefaultFolders();
54: */
55:
56: // forward the request
57: forward = mapping.findForward("success");
58: return forward;
59: }
60: }
61: }
62: } catch (LoginInvalidException e) {
63: request.setAttribute("myexception",
64: "Please check credentials");
65: }
66: forward = mapping.findForward("/login.do");
67:
68: return forward;
69: }
70: }
|