BrightSide Workbench Full Report + Source Code
org.turro.auth.Authentication Class Reference

Static Public Member Functions

static void doLogin (String login, String pass, String redir, Object extra) throws IOException
 
static boolean authenticate (String login, String pass) throws IOException
 
static void reauthenticate () throws IOException
 
static void doLogout (String redir) throws IOException
 
static boolean canLogin (String login, int minutes)
 
static boolean hasContact ()
 
static IContact getIContact ()
 
static IContact reloadIContact ()
 
static IContact getRealIContact ()
 
static boolean canImpersonate ()
 
static boolean isBehaving ()
 
static void impersonateContact (Object contact)
 
static void impersonateIContact (IContact contact)
 
static IContact getLoggedIContact ()
 
static boolean isWebapp ()
 
static boolean isContactLogged ()
 
static boolean isAdministrator ()
 
static boolean isRealAdministrator ()
 
static boolean isLogged (IContact contact)
 
static boolean sendReminder (IConstructor constructor, String name, String email)
 
static boolean isCloudAdmin ()
 

Detailed Description

Author
Lluis TurrĂ³ Cutiller lluis.nosp@m.@tur.nosp@m.ro.or.nosp@m.g

Definition at line 51 of file Authentication.java.

Member Function Documentation

◆ authenticate()

static boolean org.turro.auth.Authentication.authenticate ( String  login,
String  pass 
) throws IOException
static

Definition at line 80 of file Authentication.java.

80  {
81  IConstructor constructor = Application.getApplication().getConstructor();
82  IContact user = Contacts.getEmpty();
83  if (user.validate(login, pass)) {
84  constructor.setSessionAttribute(IUser.LOGGED_USER, user);
85  constructor.setSessionAttribute(IUser.INTERNAL_SIGNIN, Boolean.TRUE);
86  if (user instanceof IContact) {
87  constructor.setSessionAttribute(Contacts.LOGGED_ICONTACT, user);
88  } else {
89  constructor.setSessionAttribute(Contacts.LOGGED_ICONTACT, getLoggedIContact());
90  }
91  SystemLogger.getInstance().doLog(SystemLogType.LOG_INFO, "/log/in", null, null);
92  return true;
93  } else {
94  SystemLogger.getInstance().doLog(SystemLogType.LOG_INFO, "/log/failed", login, null);
95  constructor.setSessionAttribute(IUser.INTERNAL_SIGNIN, Boolean.FALSE);
96  constructor.removeSessionAttribute(Contacts.LOGGED_ICONTACT);
97  constructor.removeSessionAttribute(IUser.LOGGED_USER);
98  return false;
99  }
100  }
static IContact getLoggedIContact()
Here is the call graph for this function:

◆ canImpersonate()

static boolean org.turro.auth.Authentication.canImpersonate ( )
static

Definition at line 191 of file Authentication.java.

191  {
192  return isRealAdministrator();
193  }
static boolean isRealAdministrator()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ canLogin()

static boolean org.turro.auth.Authentication.canLogin ( String  login,
int  minutes 
)
static

Definition at line 133 of file Authentication.java.

133  {
134  if(!Strings.isBlank(login) && login.length() > 3) {
135  return SystemLogger.getInstance().getCountOf(login, "/log/failed", new CheckDate().addMinutes(-minutes).getDate()) < 3;
136  }
137  return false;
138  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ doLogin()

static void org.turro.auth.Authentication.doLogin ( String  login,
String  pass,
String  redir,
Object  extra 
) throws IOException
static

Definition at line 53 of file Authentication.java.

53  {
54  IConstructor constructor = Application.getApplication().getConstructor();
55  IContact user = resolveUser(login, pass, extra);
56  if (user != null) {
57  constructor.setMaxInactiveInterval(1 * 60 * 60);
58  constructor.setSessionAttribute(IUser.LOGGED_USER, user);
59  SystemLogger.getInstance().doLog(SystemLogType.LOG_INFO, "/log/in", null, null);
60  constructor.setSessionAttribute(IUser.INTERNAL_SIGNIN, Boolean.TRUE);
61  if (user instanceof IContact) {
62  constructor.setSessionAttribute(Contacts.LOGGED_ICONTACT, user);
63  } else {
64  constructor.setSessionAttribute(Contacts.LOGGED_ICONTACT, getLoggedIContact());
65  }
66  if(SSO.hasSSO()) {
67  SSO.getSSO().createAssertion(constructor.getRequest(), constructor.getResponse(),
68  (IContact) constructor.getSessionAttribute(Contacts.LOGGED_ICONTACT));
69  }
70  } else {
71  SystemLogger.getInstance().doLog(SystemLogType.LOG_INFO, "/log/failed", login, null);
72  constructor.setSessionAttribute(IUser.INTERNAL_SIGNIN, Boolean.FALSE);
73  constructor.removeSessionAttribute(Contacts.LOGGED_ICONTACT);
74  constructor.removeSessionAttribute(IUser.LOGGED_USER);
75  }
76  Application.getApplication().sendRedirect(redir == null ? constructor.getLastReferringContext() : redir);
77  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ doLogout()

static void org.turro.auth.Authentication.doLogout ( String  redir) throws IOException
static

Definition at line 119 of file Authentication.java.

119  {
120  IConstructor constructor = Application.getApplication().getConstructor();
121  if(SSO.hasSSO()) {
122  SSO.getProvider().removeAssertion(constructor.getRequest(), constructor.getResponse(),
123  (IContact) constructor.getSessionAttribute(Contacts.LOGGED_ICONTACT));
124  SystemLogger.getInstance().doLog(SystemLogType.LOG_INFO, "/log/out", "sso", null);
125  } else {
126  SystemLogger.getInstance().doLog(SystemLogType.LOG_INFO, "/log/out", null, null);
127  }
128  constructor.setSessionAttribute(IUser.INTERNAL_SIGNIN, Boolean.FALSE);
129  Application.getApplication().sendRedirect(redir == null ? "/" : redir);
130  Application.getApplication().invalidateSession();
131  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getIContact()

static IContact org.turro.auth.Authentication.getIContact ( )
static

Definition at line 145 of file Authentication.java.

145  {
146  IContact contact = null;
147  try {
148  contact = getBehaveAsIContact();
149  if (contact == null) {
150  contact = getRealIContact();
151  }
152  } catch (Exception ex) {
153  contact = null;
154  }
155  return contact;
156  }
Here is the call graph for this function:

◆ getLoggedIContact()

static IContact org.turro.auth.Authentication.getLoggedIContact ( )
static

Definition at line 234 of file Authentication.java.

234  {
235  return Contacts.getLoggedIContact(Application.getApplication());
236  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getRealIContact()

static IContact org.turro.auth.Authentication.getRealIContact ( )
static

Definition at line 178 of file Authentication.java.

178  {
179  IContact contact = null;
180  try {
181  contact = getRealLoggedIContact();
182  if (contact == null) { // should be a viewer, no framework
183  contact = getLoggedIContact();
184  }
185  } catch (Exception ex) {
186  contact = null;
187  }
188  return contact;
189  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ hasContact()

static boolean org.turro.auth.Authentication.hasContact ( )
static

Definition at line 140 of file Authentication.java.

140  {
141  IContact contact = getIContact();
142  return contact != null && contact.isValid();
143  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ impersonateContact()

static void org.turro.auth.Authentication.impersonateContact ( Object  contact)
static

Definition at line 200 of file Authentication.java.

200  {
201  impersonateIContact(Contacts.getContact(contact));
202  }
static void impersonateIContact(IContact contact)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ impersonateIContact()

static void org.turro.auth.Authentication.impersonateIContact ( IContact  contact)
static

Definition at line 204 of file Authentication.java.

204  {
205  Application app = Application.getApplication();
206  if (contact != null && contact.isWebUser()) {
207  IContact user = contact;
208  user.impersonateByEmail(contact.getConnector(IUser.CONNECTOR_EMAIL));
209  app.getHttpSession(false).setAttribute(IUser.LOGGED_USER, user);
210  app.getHttpSession(false).setAttribute(Contacts.BEHAVEAS_ICONTACT, contact);
211  UserSummaries.removeAttributes();
212  SystemLogger.getInstance().doLog(SystemLogType.LOG_INFO, "/log/impersonate", null, user.getName());
213  } else {
214  contact = getRealLoggedIContact();
215  IContact user = contact;
216  user.impersonateByEmail(contact.getConnector(IUser.CONNECTOR_EMAIL));
217  app.getHttpSession(false).setAttribute(IUser.LOGGED_USER, user);
218  app.getHttpSession(false).removeAttribute(Contacts.BEHAVEAS_ICONTACT);
219  UserSummaries.removeAttributes();
220  SystemLogger.getInstance().doLog(SystemLogType.LOG_INFO, "/log/backtoself", null, null);
221  }
222  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ isAdministrator()

static boolean org.turro.auth.Authentication.isAdministrator ( )
static

Definition at line 248 of file Authentication.java.

248  {
249  IContact contact = getIContact();
250  return isWebapp() && contact.isAdmin();
251  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ isBehaving()

static boolean org.turro.auth.Authentication.isBehaving ( )
static

Definition at line 195 of file Authentication.java.

195  {
196  Application app = Application.getApplication();
197  return app.getHttpSession(false).getAttribute(BEHAVEAS_ICONTACT) != null;
198  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ isCloudAdmin()

static boolean org.turro.auth.Authentication.isCloudAdmin ( )
static

Definition at line 284 of file Authentication.java.

284  {
285  return Secrets.isSecret("key=cloudadmin", Authentication.getIContact());
286  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ isContactLogged()

static boolean org.turro.auth.Authentication.isContactLogged ( )
static

Definition at line 243 of file Authentication.java.

243  {
244  IContact contact = getIContact();
245  return contact != null && contact.isWebUser();
246  }
Here is the call graph for this function:

◆ isLogged()

static boolean org.turro.auth.Authentication.isLogged ( IContact  contact)
static

Definition at line 258 of file Authentication.java.

258  {
259  IContact logged = getIContact();
260  return logged != null && logged.isValid() && logged.equals(contact);
261  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ isRealAdministrator()

static boolean org.turro.auth.Authentication.isRealAdministrator ( )
static

Definition at line 253 of file Authentication.java.

253  {
254  IContact contact = getRealIContact();
255  return contact != null && contact.isWebapp() && contact.isAdmin();
256  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ isWebapp()

static boolean org.turro.auth.Authentication.isWebapp ( )
static

Definition at line 238 of file Authentication.java.

238  {
239  IContact contact = getIContact();
240  return contact != null && contact.isWebapp();
241  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ reauthenticate()

static void org.turro.auth.Authentication.reauthenticate ( ) throws IOException
static

Definition at line 103 of file Authentication.java.

103  {
104  IConstructor constructor = Application.getApplication().getConstructor();
105  IContact user = constructor.getUser();
106  if (user != null && user.isValid()) {
107  constructor.setSessionAttribute(IUser.INTERNAL_SIGNIN, Boolean.FALSE);
108  user.reload();
109  constructor.setSessionAttribute(IUser.LOGGED_USER, user);
110  constructor.setSessionAttribute(IUser.INTERNAL_SIGNIN, Boolean.TRUE);
111  if (user instanceof IContact) {
112  constructor.setSessionAttribute(Contacts.LOGGED_ICONTACT, user);
113  } else {
114  constructor.setSessionAttribute(Contacts.LOGGED_ICONTACT, getLoggedIContact());
115  }
116  }
117  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ reloadIContact()

static IContact org.turro.auth.Authentication.reloadIContact ( )
static

Definition at line 158 of file Authentication.java.

158  {
159  Application app = Application.getApplication();
160  HttpSession session = app.getHttpSession(false);
161  if(session != null && hasContact()) {
162  IContact contact = Contacts.getContactById(getIContact().getId());
163  if(contact.isValid()) {
164  session.setAttribute(IUser.LOGGED_USER, contact);
165  if(isBehaving()) {
166  session.setAttribute(Contacts.BEHAVEAS_ICONTACT, contact);
167  } else {
168  session.setAttribute(Contacts.LOGGED_ICONTACT, contact);
169  }
170  return contact;
171  }
172  }
173  Application.getApplication().sendRedirect("/");
174  Application.getApplication().invalidateSession();
175  return null;
176  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sendReminder()

static boolean org.turro.auth.Authentication.sendReminder ( IConstructor  constructor,
String  name,
String  email 
)
static

Definition at line 263 of file Authentication.java.

263  {
264  try {
265  Map args = new HashMap();
266  args.put("email", email);
267  args.put("name", name);
268  try {
269  args.put("link", ElephantContext.getServerUrl("http") + "?" + Actions.createAction((String) args.get("email"), "/user/changepass"));
270  } catch (Exception ex) {
271  Logger.getLogger(Authentication.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
272  }
273  MailSenders.getPool()
274  .addUser((String) args.get("name"), (String) args.get("email"))
275  .putAll(args)
276  .sendTemplate("sign-reminder", I_.get("Password reminder") + " : " + ElephantContext.getSiteName());
277  return true;
278  } catch (EmailException ex) {
279  Logger.getLogger(Authentication.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
280  return false;
281  }
282  }
Here is the call graph for this function:
Here is the caller graph for this function:

The documentation for this class was generated from the following file: