BrightSide Workbench Full Report + Source Code
LoginAction.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2011 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 package org.turro.elephant.impl.security;
19 
20 import org.turro.elephant.context.IAction;
21 import org.turro.elephant.impl.abstracts.AbstractAction;
22 import org.turro.elephant.impl.context.ContextFactory;
23 import org.turro.elephant.impl.util.ContactPlugin;
24 import org.turro.elephant.security.IUser;
25 import org.turro.elephant.security.IUserAdmin;
26 import org.turro.log.SystemLogType;
27 import org.turro.log.SystemLogger;
28 import org.turro.server.MailServer;
29 
35 @Deprecated
36 public class LoginAction extends AbstractAction implements IAction {
37 
39  public LoginAction() {
40  }
41 
42  @Override
43  public int execute() throws Exception {
44  String action = getActionParameter(),
45  login = getParameter("login"),
46  pass = getParameter("pass");
47 
48  if ("login".equals(action)) {
50  if (user.validate(login, pass)) {
52  SystemLogger.getInstance().doLog(SystemLogType.LOG_INFO, "/log/in", null, null);
53  } else {
54  SystemLogger.getInstance().doLog(SystemLogType.LOG_INFO, "/log/failed", login, null);
55  }
56  String redir = getParameter("redir");
57  constructor.redirect(redir == null ? constructor.getLastReferringContext() : redir);
58  } else if ("logout".equals(action)) {
59  SystemLogger.getInstance().doLog(SystemLogType.LOG_INFO, "/log/out", null, null);
62  String redir = getParameter("redir");
63  constructor.redirect(redir == null ? "/" : redir);
64  } else if ("profile".equals(action)) {
65  SystemLogger.getInstance().doLog(SystemLogType.LOG_INFO, "/log/profile", null, null);
66  login = constructor.getUser().getId();
67  if (ContactPlugin.hasContacts()) {
69  } else {
71  String pass1 = getParameter("pass1"),
72  pass1r = getParameter("pass1r"),
73  pass2 = getParameter("pass2"),
74  pass2r = getParameter("pass2r"),
75  name = getParameter("name"),
76  email = getParameter("email"),
77  emailLogin = getParameter("emailLogin"),
78  emailPass = getParameter("emailPass"),
79  emailPassr = getParameter("emailPassr");
80  if (name != null) {
81  ua.setName(login, name);
82  }
83  if (pass1 != null && pass1.trim().length() > 0 && pass1.equals(pass1r)) {
84  if (pass2 == null || pass2.equals(pass2r)) {
85  ua.setPasswords(login, pass1, pass2);
86  }
87  }
88  if (email != null) {
89  ua.setProperty(login, IUser.CONNECTOR_EMAIL, email);
90  }
91  if (emailLogin != null && emailLogin.trim().length() > 0) {
92  if (emailPass != null && emailPass.trim().length() > 0 && emailPass.equals(emailPassr)) {
93  setMailServerUserPassword(emailLogin, emailPass);
94  }
95  }
96  }
98  user.impersonate(login);
101  }
102 
103  return IAction.DONE;
104  }
105 
106  public void setMailServerUserPassword(String emailLogin, String emailPass) {
108  if(ms != null) {
109  ms.changePassword(emailLogin, emailPass);
110  }
111  }
112 
113 }
static IUserAdmin getUserAdmin(IConstructor constructor)
static IUser getUser(IConstructor constructor)
static Object getImplementation(IElement iel, String name)
void setMailServerUserPassword(String emailLogin, String emailPass)
static void saveChangesToContact(LoginAction action)
static ISystemLogger getInstance()
void changePassword(String user, String password)
Definition: MailServer.java:32
String getParameter(String param)
void setSessionAttribute(String key, Object value)
void setPasswords(String id, String pass1, String pass2)
void setProperty(String id, String name, String value)
void setName(String id, String name)
static final String CONNECTOR_EMAIL
Definition: IUser.java:32
boolean impersonate(String login)
static final String LOGGED_USER
Definition: IUser.java:37
boolean validate(String login, String password)
void doLog(SystemLogType type, Object entity, String comment, Serializable data)