Skip to content

Commit

Permalink
6630 lastlogintime not updated (#10135)
Browse files Browse the repository at this point in the history
* add Added Last Login Date Update

* update lastLogin for OAuth2Login

* using UserServiceBean for updating
  • Loading branch information
stevenferey committed May 10, 2024
1 parent d72d347 commit 3867cfe
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/main/java/edu/harvard/iq/dataverse/Shib.java
Expand Up @@ -59,6 +59,8 @@ public class Shib implements java.io.Serializable {
SettingsServiceBean settingsService;
@EJB
SystemConfig systemConfig;
@EJB
UserServiceBean userService;

HttpServletRequest request;

Expand Down Expand Up @@ -259,6 +261,7 @@ else if (ShibAffiliationOrder.equals("firstAffiliation")) {
state = State.REGULAR_LOGIN_INTO_EXISTING_SHIB_ACCOUNT;
logger.fine("Found user based on " + userPersistentId + ". Logging in.");
logger.fine("Updating display info for " + au.getName());
userService.updateLastLogin(au);
authSvc.updateAuthenticatedUser(au, displayInfo);
logInUserAndSetShibAttributes(au);
String prettyFacesHomePageString = getPrettyFacesHomePageString(false);
Expand Down
Expand Up @@ -307,11 +307,9 @@ public AuthenticatedUser getUpdateAuthenticatedUser( String authenticationProvid
if (user != null && !user.isDeactivated()) {
user = userService.updateLastLogin(user);
}

if ( user == null ) {
throw new IllegalStateException("Authenticated user does not exist. The functionality to support creating one at this point in authentication has been removed.");
//return createAuthenticatedUser(
// new UserRecordIdentifier(authenticationProviderId, resp.getUserId()), resp.getUserId(), resp.getUserDisplayInfo(), true );
} else {
if (BuiltinAuthenticationProvider.PROVIDER_ID.equals(user.getAuthenticatedUserLookup().getAuthenticationProviderId())) {
return user;
Expand Down
@@ -1,6 +1,7 @@
package edu.harvard.iq.dataverse.authorization.providers.oauth2;

import edu.harvard.iq.dataverse.DataverseSession;
import edu.harvard.iq.dataverse.UserServiceBean;
import edu.harvard.iq.dataverse.authorization.AuthenticationProvider;
import edu.harvard.iq.dataverse.authorization.AuthenticationServiceBean;
import edu.harvard.iq.dataverse.authorization.UserRecordIdentifier;
Expand Down Expand Up @@ -65,6 +66,9 @@ public class OAuth2LoginBackingBean implements Serializable {
@EJB
SystemConfig systemConfig;

@EJB
UserServiceBean userService;

@Inject
DataverseSession session;

Expand Down Expand Up @@ -128,6 +132,7 @@ public void exchangeCodeForToken() throws IOException {
} else {
// login the user and redirect to HOME of intended page (if any).
// setUser checks for deactivated users.
dvUser = userService.updateLastLogin(dvUser);
session.setUser(dvUser);
final OAuth2TokenData tokenData = oauthUser.getTokenData();
if (tokenData != null) {
Expand Down
@@ -1,6 +1,7 @@
package edu.harvard.iq.dataverse.authorization.providers.oauth2;

import edu.harvard.iq.dataverse.DataverseSession;
import edu.harvard.iq.dataverse.UserServiceBean;
import edu.harvard.iq.dataverse.authorization.AuthenticationServiceBean;
import edu.harvard.iq.dataverse.authorization.UserRecordIdentifier;
import edu.harvard.iq.dataverse.authorization.providers.oauth2.impl.GitHubOAuth2APTest;
Expand Down Expand Up @@ -48,6 +49,7 @@ class OAuth2LoginBackingBeanTest {

@Mock AuthenticationServiceBean authenticationServiceBean;
@Mock SystemConfig systemConfig;
@Mock UserServiceBean userService;

Clock constantClock = Clock.fixed(Instant.now(), ZoneId.systemDefault());

Expand All @@ -70,6 +72,7 @@ void setUp() {
this.loginBackingBean.clock = constantClock;
this.loginBackingBean.authenticationSvc = this.authenticationServiceBean;
this.loginBackingBean.systemConfig = this.systemConfig;
this.loginBackingBean.userService = this.userService;
lenient().when(this.authenticationServiceBean.getOAuth2Provider(testIdp.getId())).thenReturn(testIdp);
}

Expand Down Expand Up @@ -178,6 +181,7 @@ void existingUser() throws Exception {
// also fake the result of the lookup in the auth service
doReturn(userIdentifier).when(userRecord).getUserRecordIdentifier();
doReturn(user).when(authenticationServiceBean).lookupUser(userIdentifier);
doReturn(user).when(userService).updateLastLogin(user);

// WHEN (& then)
// capture the redirect target from the faces context
Expand Down

0 comments on commit 3867cfe

Please sign in to comment.