|
1 | 1 | package edu.harvard.iq.dataverse.authorization; |
2 | 2 |
|
3 | 3 | import edu.harvard.iq.dataverse.UserNotificationServiceBean; |
| 4 | +import edu.harvard.iq.dataverse.UserServiceBean; |
4 | 5 | import edu.harvard.iq.dataverse.search.IndexServiceBean; |
5 | 6 | import edu.harvard.iq.dataverse.actionlogging.ActionLogRecord; |
6 | 7 | import edu.harvard.iq.dataverse.actionlogging.ActionLogServiceBean; |
@@ -95,6 +96,9 @@ public class AuthenticationServiceBean { |
95 | 96 | @EJB |
96 | 97 | PasswordResetServiceBean passwordResetServiceBean; |
97 | 98 |
|
| 99 | + @EJB |
| 100 | + UserServiceBean userService; |
| 101 | + |
98 | 102 | @PersistenceContext(unitName = "VDCNet-ejbPU") |
99 | 103 | private EntityManager em; |
100 | 104 |
|
@@ -321,13 +325,17 @@ public AuthenticatedUser authenticate( String authenticationProviderId, Authenti |
321 | 325 | // yay! see if we already have this user. |
322 | 326 | AuthenticatedUser user = lookupUser(authenticationProviderId, resp.getUserId()); |
323 | 327 |
|
| 328 | + if (user != null){ |
| 329 | + user = userService.updateLastLogin(user); |
| 330 | + } |
| 331 | + |
324 | 332 | /** |
325 | 333 | * @todo Why does a method called "authenticate" have the potential |
326 | 334 | * to call "createAuthenticatedUser"? Isn't the creation of a user a |
327 | 335 | * different action than authenticating? |
328 | 336 | * |
329 | 337 | * @todo Wouldn't this be more readable with if/else rather than |
330 | | - * ternary? |
| 338 | + * ternary? (please) |
331 | 339 | */ |
332 | 340 | return ( user == null ) ? |
333 | 341 | AuthenticationServiceBean.this.createAuthenticatedUser( |
@@ -433,14 +441,12 @@ public AuthenticatedUser lookupUser( String apiToken ) { |
433 | 441 | } |
434 | 442 |
|
435 | 443 | public AuthenticatedUser save( AuthenticatedUser user ) { |
436 | | - user.setModificationTime(getCurrentTimestamp()); |
437 | 444 | em.persist(user); |
438 | 445 | em.flush(); |
439 | 446 | return user; |
440 | 447 | } |
441 | 448 |
|
442 | 449 | public AuthenticatedUser update( AuthenticatedUser user ) { |
443 | | - user.setModificationTime(getCurrentTimestamp()); |
444 | 450 | return em.merge(user); |
445 | 451 | } |
446 | 452 |
|
@@ -493,12 +499,16 @@ public boolean updateProvider( AuthenticatedUser authenticatedUser, String authe |
493 | 499 | * @throws EJBException which may wrap an ConstraintViolationException if the proposed user does not pass bean validation. |
494 | 500 | */ |
495 | 501 | public AuthenticatedUser createAuthenticatedUser(UserRecordIdentifier userRecordId, |
496 | | - String proposedAuthenticatedUserIdentifier, |
497 | | - AuthenticatedUserDisplayInfo userDisplayInfo, |
498 | | - boolean generateUniqueIdentifier) { |
| 502 | + String proposedAuthenticatedUserIdentifier, |
| 503 | + AuthenticatedUserDisplayInfo userDisplayInfo, |
| 504 | + boolean generateUniqueIdentifier) { |
499 | 505 | AuthenticatedUser authenticatedUser = new AuthenticatedUser(); |
500 | | - authenticatedUser.applyDisplayInfo(userDisplayInfo); |
| 506 | + // set account creation time & initial login time (same timestamp) |
| 507 | + authenticatedUser.setCreatedTime(new Timestamp(new Date().getTime())); |
| 508 | + authenticatedUser.setLastLoginTime(authenticatedUser.getCreatedTime()); |
501 | 509 |
|
| 510 | + authenticatedUser.applyDisplayInfo(userDisplayInfo); |
| 511 | + |
502 | 512 | // we have no desire for leading or trailing whitespace in identifiers |
503 | 513 | if (proposedAuthenticatedUserIdentifier != null) { |
504 | 514 | proposedAuthenticatedUserIdentifier = proposedAuthenticatedUserIdentifier.trim(); |
@@ -535,7 +545,7 @@ public AuthenticatedUser createAuthenticatedUser(UserRecordIdentifier userRecord |
535 | 545 | * better to do something like "startConfirmEmailProcessForNewUser". */ |
536 | 546 | confirmEmailService.createToken(authenticatedUser); |
537 | 547 | } |
538 | | - |
| 548 | + |
539 | 549 | actionLogSvc.log( new ActionLogRecord(ActionLogRecord.ActionType.Auth, "createUser") |
540 | 550 | .setInfo(authenticatedUser.getIdentifier())); |
541 | 551 |
|
|
0 commit comments