18 package org.turro.auth;
20 import java.io.IOException;
21 import java.util.HashMap;
23 import java.util.logging.Level;
24 import java.util.logging.Logger;
25 import javax.servlet.http.HttpSession;
26 import org.amic.util.date.CheckDate;
27 import org.turro.string.Strings;
28 import org.apache.commons.mail.EmailException;
29 import org.turro.action.Actions;
30 import org.turro.action.Contacts;
31 import static org.turro.action.Contacts.BEHAVEAS_ICONTACT;
32 import org.turro.action.MailSenders;
33 import org.turro.action.Secrets;
34 import org.turro.action.UserSummaries;
35 import org.turro.elephant.context.Application;
36 import org.turro.elephant.context.ElephantContext;
37 import org.turro.elephant.context.IConstructor;
38 import org.turro.elephant.security.IUser;
39 import org.turro.external.Authentications;
40 import org.turro.external.IElephantAuthentication;
41 import org.turro.i18n.I_;
42 import org.turro.log.SystemLogType;
43 import org.turro.log.SystemLogger;
44 import org.turro.plugin.contacts.IContact;
45 import org.turro.sso.SSO;
53 public static void doLogin(String login, String pass, String redir, Object extra)
throws IOException {
55 IContact user = resolveUser(login, pass, extra);
80 public static boolean authenticate(String login, String pass)
throws IOException {
106 if (user !=
null && user.
isValid()) {
119 public static void doLogout(String redir)
throws IOException {
133 public static boolean canLogin(String login,
int minutes) {
134 if(!Strings.isBlank(login) && login.length() > 3) {
142 return contact !=
null && contact.
isValid();
148 contact = getBehaveAsIContact();
149 if (contact ==
null) {
152 }
catch (Exception ex) {
166 session.setAttribute(
Contacts.BEHAVEAS_ICONTACT, contact);
181 contact = getRealLoggedIContact();
182 if (contact ==
null) {
185 }
catch (Exception ex) {
197 return app.
getHttpSession(
false).getAttribute(BEHAVEAS_ICONTACT) !=
null;
206 if (contact !=
null && contact.
isWebUser()) {
214 contact = getRealLoggedIContact();
224 private static IContact getBehaveAsIContact() {
229 private static IContact getRealLoggedIContact() {
231 return (IContact) app.
getHttpSession(
false).getAttribute(Contacts.LOGGED_ICONTACT);
240 return contact !=
null && contact.
isWebapp();
245 return contact !=
null && contact.
isWebUser();
260 return logged !=
null && logged.
isValid() && logged.
equals(contact);
265 Map args =
new HashMap();
266 args.put(
"email", email);
267 args.put(
"name", name);
270 }
catch (Exception ex) {
274 .
addUser((String) args.get(
"name"), (String) args.get(
"email"))
278 }
catch (EmailException ex) {
288 private static IContact resolveUser(String login, String pass, Object extra) {
293 if(c !=
null)
return c;
296 IContact user = Contacts.getEmpty();
297 if(user.validate(login, pass))
return user;
302 private Authentication() {
static String createAction(String email, String redir)
static IMailSender getPool()
static boolean isSecret(String key, Object value)
static void removeAttributes()
static boolean isRealAdministrator()
static void impersonateIContact(IContact contact)
static boolean isAdministrator()
static boolean canLogin(String login, int minutes)
static IContact getIContact()
static void doLogout(String redir)
static boolean canImpersonate()
static IContact getRealIContact()
static boolean isWebapp()
static boolean sendReminder(IConstructor constructor, String name, String email)
static boolean isContactLogged()
static void doLogin(String login, String pass, String redir, Object extra)
static IContact reloadIContact()
static void impersonateContact(Object contact)
static boolean hasContact()
static boolean authenticate(String login, String pass)
static boolean isLogged(IContact contact)
static void reauthenticate()
static boolean isCloudAdmin()
static boolean isBehaving()
static IContact getLoggedIContact()
IConstructor getConstructor()
abstract void sendRedirect(String uri)
HttpSession getHttpSession(boolean create)
static Application getApplication()
static String getSiteName()
static String getServerUrl(String scheme)
static String logMsg(String msg)
static IElephantAuthentication getFor(Object extra)
static String get(String msg)
static ISystemLogger getInstance()
static IElephantSSO getSSO()
static IAssertionProvider getProvider()
void setMaxInactiveInterval(int i)
HttpServletResponse getResponse()
HttpServletRequest getRequest()
void setSessionAttribute(String key, Object value)
String getLastReferringContext()
void removeSessionAttribute(String key)
Object getSessionAttribute(String key)
static final String INTERNAL_SIGNIN
static final String CONNECTOR_EMAIL
static final String LOGGED_USER
boolean equals(Object obj)
boolean impersonateByEmail(String email)
boolean validate(String login, String password)
void removeAssertion(HttpServletRequest request, HttpServletResponse response, IContact contact)
void createAssertion(HttpServletRequest request, HttpServletResponse response, IContact contact)
IContact doLogin(String login, String pass, Object extra)
void doLog(SystemLogType type, Object entity, String comment, Serializable data)
long getCountOf(String comment, String logPath, Date since)