diff --git a/orcid-core/src/main/java/org/orcid/core/common/manager/EventManager.java b/orcid-core/src/main/java/org/orcid/core/common/manager/EventManager.java index eaecd912705..323f76a9534 100644 --- a/orcid-core/src/main/java/org/orcid/core/common/manager/EventManager.java +++ b/orcid-core/src/main/java/org/orcid/core/common/manager/EventManager.java @@ -14,6 +14,6 @@ public interface EventManager { boolean removeEvents(String orcid); - void createEvent(String orcid, EventType eventType, HttpServletRequest request, RequestInfoForm requestInfoForm); + void createEvent(String orcid, EventType eventType, HttpServletRequest request); } diff --git a/orcid-core/src/main/java/org/orcid/core/common/manager/impl/EventManagerImpl.java b/orcid-core/src/main/java/org/orcid/core/common/manager/impl/EventManagerImpl.java index 11c7b13d6fa..96b6b540bf9 100644 --- a/orcid-core/src/main/java/org/orcid/core/common/manager/impl/EventManagerImpl.java +++ b/orcid-core/src/main/java/org/orcid/core/common/manager/impl/EventManagerImpl.java @@ -7,10 +7,14 @@ import org.orcid.core.common.manager.EventManager; import org.orcid.core.constants.OrcidOauth2Constants; import org.orcid.core.manager.ClientDetailsEntityCacheManager; +import org.orcid.core.manager.v3.read_only.RecordNameManagerReadOnly; import org.orcid.core.utils.EventType; +import org.orcid.jaxb.model.clientgroup.ClientType; +import org.orcid.jaxb.model.v3.release.record.Name; import org.orcid.persistence.dao.EventDao; import org.orcid.persistence.jpa.entities.ClientDetailsEntity; import org.orcid.persistence.jpa.entities.EventEntity; +import org.orcid.pojo.ajaxForm.PojoUtil; import org.orcid.pojo.ajaxForm.RequestInfoForm; import java.io.UnsupportedEncodingException; @@ -30,13 +34,16 @@ public class EventManagerImpl implements EventManager { @Resource private ClientDetailsEntityCacheManager clientDetailsEntityCacheManager; + @Resource(name = "recordNameManagerReadOnlyV3") + private RecordNameManagerReadOnly recordNameManagerReadOnly; + @Override public boolean removeEvents(String orcid) { return eventDao.removeEvents(orcid); } @Override - public void createEvent(String orcid, EventType eventType, HttpServletRequest request, RequestInfoForm requestInfoForm) { + public void createEvent(String orcid, EventType eventType, HttpServletRequest request) { String label = "Website"; String clientId = null; String redirectUrl = null; @@ -48,17 +55,33 @@ public void createEvent(String orcid, EventType eventType, HttpServletRequest re } else { if (request != null) { Boolean isOauth2ScreensRequest = (Boolean) request.getSession().getAttribute(OrcidOauth2Constants.OAUTH_2SCREENS); - if (isOauth2ScreensRequest != null && isOauth2ScreensRequest) { + RequestInfoForm requestInfoForm = (RequestInfoForm) request.getSession().getAttribute("requestInfoForm"); + if (requestInfoForm != null) { + clientId = requestInfoForm.getClientId(); + redirectUrl = removeAttributesFromUrl(requestInfoForm.getRedirectUrl()); + label = "OAuth " + requestInfoForm.getMemberName() + " " + requestInfoForm.getClientName(); + } else if (isOauth2ScreensRequest != null && isOauth2ScreensRequest) { String queryString = (String) request.getSession().getAttribute(OrcidOauth2Constants.OAUTH_QUERY_STRING); clientId = getParameterValue(queryString, "client_id"); redirectUrl = getParameterValue(queryString, "redirect_uri"); ClientDetailsEntity clientDetailsEntity = clientDetailsEntityCacheManager.retrieve(clientId); - label = "OAuth " + clientDetailsEntity.getClientName(); + String memberName = ""; + String clientName = clientDetailsEntity.getClientName(); + + if (ClientType.PUBLIC_CLIENT.equals(clientDetailsEntity.getClientType())) { + memberName = "PubApp"; + } else if (!PojoUtil.isEmpty(clientDetailsEntity.getGroupProfileId())) { + Name name = recordNameManagerReadOnly.getRecordName(clientDetailsEntity.getGroupProfileId()); + if (name != null) { + memberName = name.getCreditName() != null ? name.getCreditName().getContent() : ""; + } + } + + if (StringUtils.isBlank(memberName)) { + memberName = clientName; + } + label = "OAuth " + memberName + " " + clientName; } - } else if (requestInfoForm != null) { - clientId = requestInfoForm.getClientId(); - redirectUrl = removeAttributesFromUrl(requestInfoForm.getRedirectUrl()); - label = "OAuth " + requestInfoForm.getClientName(); } } diff --git a/orcid-web/src/main/java/org/orcid/frontend/oauth2/OauthController.java b/orcid-web/src/main/java/org/orcid/frontend/oauth2/OauthController.java index 0b24e1ec2f5..f11d4ef4f55 100644 --- a/orcid-web/src/main/java/org/orcid/frontend/oauth2/OauthController.java +++ b/orcid-web/src/main/java/org/orcid/frontend/oauth2/OauthController.java @@ -97,7 +97,7 @@ public class OauthController { if (responseParam != null && !responseParam.isEmpty() && !PojoUtil.isEmpty(responseParam.get(0))) { isResponseSet = true; if (Features.EVENTS.isActive()) { - eventManager.createEvent(requestInfoForm.getUserOrcid(), EventType.REAUTHORIZE, null, requestInfoForm); + eventManager.createEvent(requestInfoForm.getUserOrcid(), EventType.REAUTHORIZE, request); } } } diff --git a/orcid-web/src/main/java/org/orcid/frontend/spring/AjaxAuthenticationSuccessHandler.java b/orcid-web/src/main/java/org/orcid/frontend/spring/AjaxAuthenticationSuccessHandler.java index bd660794e1c..6bb187adfbb 100644 --- a/orcid-web/src/main/java/org/orcid/frontend/spring/AjaxAuthenticationSuccessHandler.java +++ b/orcid-web/src/main/java/org/orcid/frontend/spring/AjaxAuthenticationSuccessHandler.java @@ -26,7 +26,7 @@ public class AjaxAuthenticationSuccessHandler extends AjaxAuthenticationSuccessH public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException { String targetUrl = getTargetUrl(request, response, authentication); if (Features.EVENTS.isActive()) { - eventManager.createEvent(authentication.getPrincipal().toString(), EventType.SIGN_IN, request, null); + eventManager.createEvent(authentication.getPrincipal().toString(), EventType.SIGN_IN, request); } response.setContentType("application/json"); response.getWriter().println("{\"success\": true, \"url\": \"" + targetUrl.replaceAll("^/", "") + "\"}"); diff --git a/orcid-web/src/main/java/org/orcid/frontend/web/controllers/LoginController.java b/orcid-web/src/main/java/org/orcid/frontend/web/controllers/LoginController.java index dff31541f06..98a34a18d04 100644 --- a/orcid-web/src/main/java/org/orcid/frontend/web/controllers/LoginController.java +++ b/orcid-web/src/main/java/org/orcid/frontend/web/controllers/LoginController.java @@ -326,9 +326,6 @@ private ModelAndView processSocialLogin(HttpServletRequest request, HttpServletR userConnectionId = userConnection.getId().getUserid(); // Store relevant data in the session socialSignInUtils.setSignedInData(request, userData); - if (Features.EVENTS.isActive()) { - eventManager.createEvent(userConnection.getOrcid(), EventType.SIGN_IN, request, null); - } if(userConnection.isLinked()) { // If user exists and is linked update user connection info @@ -351,6 +348,9 @@ private ModelAndView processSocialLogin(HttpServletRequest request, HttpServletR if (userConnectionId == null) { throw new IllegalArgumentException("Unable to find userConnectionId for providerUserId = " + providerUserId); } + if (Features.EVENTS.isActive()) { + eventManager.createEvent(userConnection.getOrcid(), EventType.SIGN_IN, request); + } userCookieGenerator.addCookie(userConnectionId, response); if ("social_2FA".equals(view.getViewName())) { diff --git a/orcid-web/src/main/java/org/orcid/frontend/web/controllers/OauthAuthorizeController.java b/orcid-web/src/main/java/org/orcid/frontend/web/controllers/OauthAuthorizeController.java index dbed4118a0d..8bdf7fc2bf8 100644 --- a/orcid-web/src/main/java/org/orcid/frontend/web/controllers/OauthAuthorizeController.java +++ b/orcid-web/src/main/java/org/orcid/frontend/web/controllers/OauthAuthorizeController.java @@ -260,7 +260,7 @@ public ModelAndView loginGetHandler(HttpServletRequest request, HttpServletRespo } else { orcid = auth.getPrincipal().toString(); } - eventManager.createEvent(orcid, eventType, null, requestInfoForm); + eventManager.createEvent(orcid, eventType, request); } if(new HttpSessionRequestCache().getRequest(request, response) != null) new HttpSessionRequestCache().removeRequest(request, response); diff --git a/orcid-web/src/main/java/org/orcid/frontend/web/controllers/PublicRecordController.java b/orcid-web/src/main/java/org/orcid/frontend/web/controllers/PublicRecordController.java index 63f56614557..3f2f78febc4 100644 --- a/orcid-web/src/main/java/org/orcid/frontend/web/controllers/PublicRecordController.java +++ b/orcid-web/src/main/java/org/orcid/frontend/web/controllers/PublicRecordController.java @@ -185,7 +185,7 @@ PublicRecord getPublicRecord(@PathVariable("orcid") String orcid) { try { if (Features.EVENTS.isActive()) { - eventManager.createEvent(orcid, EventType.PUBLIC_PAGE, null, null); + eventManager.createEvent(orcid, EventType.PUBLIC_PAGE, null); } // Check if the profile is deprecated or locked orcidSecurityManager.checkProfile(orcid); diff --git a/orcid-web/src/main/java/org/orcid/frontend/web/controllers/RegistrationController.java b/orcid-web/src/main/java/org/orcid/frontend/web/controllers/RegistrationController.java index 78f299e9c1d..9979dfd533f 100644 --- a/orcid-web/src/main/java/org/orcid/frontend/web/controllers/RegistrationController.java +++ b/orcid-web/src/main/java/org/orcid/frontend/web/controllers/RegistrationController.java @@ -281,6 +281,9 @@ public void validateGrcaptcha(HttpServletRequest request, @RequestBody Registrat Locale locale = RequestContextUtils.getLocale(request); // Ip String ip = OrcidRequestUtil.getIpAddress(request); + if (Features.EVENTS.isActive()) { + eventManager.createEvent(getCurrentUserOrcid(), EventType.NEW_REGISTRATION, request); + } createMinimalRegistrationAndLogUserIn(request, response, reg, usedCaptcha, locale, ip); } catch (Exception e) { LOGGER.error("Error registering a new user", e); @@ -304,9 +307,6 @@ public void validateGrcaptcha(HttpServletRequest request, @RequestBody Registrat redirectUrl = calculateRedirectUrl(request, response, true, true); } r.setUrl(redirectUrl); - if (Features.EVENTS.isActive()) { - eventManager.createEvent(getCurrentUserOrcid(), EventType.NEW_REGISTRATION, request, null); - } return r; } diff --git a/orcid-web/src/main/java/org/orcid/frontend/web/controllers/ShibbolethController.java b/orcid-web/src/main/java/org/orcid/frontend/web/controllers/ShibbolethController.java index 9f8e25031c0..9f0dc458c06 100644 --- a/orcid-web/src/main/java/org/orcid/frontend/web/controllers/ShibbolethController.java +++ b/orcid-web/src/main/java/org/orcid/frontend/web/controllers/ShibbolethController.java @@ -10,6 +10,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.orcid.core.common.manager.EventManager; import org.orcid.core.constants.OrcidOauth2Constants; import org.orcid.core.manager.BackupCodeManager; import org.orcid.core.manager.IdentityProviderManager; @@ -20,6 +21,8 @@ import org.orcid.core.manager.v3.read_only.EmailManagerReadOnly; import org.orcid.core.oauth.OrcidProfileUserDetails; import org.orcid.core.security.OrcidUserDetailsService; +import org.orcid.core.togglz.Features; +import org.orcid.core.utils.EventType; import org.orcid.core.utils.JsonUtils; import org.orcid.frontend.web.exception.FeatureDisabledException; import org.orcid.persistence.jpa.entities.ProfileEntity; @@ -81,6 +84,9 @@ public class ShibbolethController extends BaseController { @Resource private OrcidUserDetailsService orcidUserDetailsService; + + @Resource + private EventManager eventManager; @RequestMapping(value = { "/2FA/authenticationCode.json" }, method = RequestMethod.GET) public @ResponseBody TwoFactorAuthenticationCodes getTwoFactorCodeWrapper() { @@ -165,6 +171,10 @@ public ModelAndView signinHandler(HttpServletRequest request, HttpServletRespons try { notifyUser(shibIdentityProvider, userConnectionEntity); processAuthentication(remoteUser, userConnectionEntity); + if (Features.EVENTS.isActive()) { + OrcidProfileUserDetails orcidProfileUserDetails = getOrcidProfileUserDetails(userConnectionEntity.getOrcid()); + eventManager.createEvent(orcidProfileUserDetails.getOrcid(), EventType.SIGN_IN, request); + } } catch (AuthenticationException e) { // this should never happen SecurityContextHolder.getContext().setAuthentication(null);