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
new file mode 100644
index 00000000000..eaecd912705
--- /dev/null
+++ b/orcid-core/src/main/java/org/orcid/core/common/manager/EventManager.java
@@ -0,0 +1,19 @@
+package org.orcid.core.common.manager;
+
+import org.orcid.core.utils.EventType;
+import org.orcid.pojo.ajaxForm.RequestInfoForm;
+
+import javax.servlet.http.HttpServletRequest;
+
+/**
+ *
+ * @author Daniel Palafox
+ *
+ */
+public interface EventManager {
+
+ boolean removeEvents(String orcid);
+
+ void createEvent(String orcid, EventType eventType, HttpServletRequest request, RequestInfoForm requestInfoForm);
+
+}
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
new file mode 100644
index 00000000000..297a6d9b3de
--- /dev/null
+++ b/orcid-core/src/main/java/org/orcid/core/common/manager/impl/EventManagerImpl.java
@@ -0,0 +1,99 @@
+package org.orcid.core.common.manager.impl;
+
+import javax.annotation.Resource;
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.commons.lang.StringUtils;
+import org.orcid.core.common.manager.EventManager;
+import org.orcid.core.constants.OrcidOauth2Constants;
+import org.orcid.core.manager.ClientDetailsEntityCacheManager;
+import org.orcid.core.utils.EventType;
+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.RequestInfoForm;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
+import java.nio.charset.StandardCharsets;
+
+/**
+ *
+ * @author Daniel Palafox
+ *
+ */
+public class EventManagerImpl implements EventManager {
+
+ @Resource
+ private EventDao eventDao;
+
+ @Resource
+ private ClientDetailsEntityCacheManager clientDetailsEntityCacheManager;
+
+ @Override
+ public boolean removeEvents(String orcid) {
+ return eventDao.removeEvents(orcid);
+ }
+
+ @Override
+ public void createEvent(String orcid, EventType eventType, HttpServletRequest request, RequestInfoForm requestInfoForm) {
+ String label = null;
+ String clientId = null;
+ String redirectUrl = null;
+ String publicPage = null;
+
+ switch (eventType) {
+ case PUBLIC_PAGE:
+ publicPage = orcid;
+ orcid = null;
+ break;
+ case REAUTHORIZE:
+ clientId = requestInfoForm.getClientId();
+ redirectUrl = requestInfoForm.getRedirectUrl();
+ label = "OAuth " + requestInfoForm.getClientName();
+ break;
+ default:
+ if (request != null) {
+ Boolean isOauth2ScreensRequest = (Boolean) request.getSession().getAttribute(OrcidOauth2Constants.OAUTH_2SCREENS);
+ 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();
+ }
+ } else {
+ label = "Website";
+ }
+ }
+
+ EventEntity eventEntity = new EventEntity();
+
+ eventEntity.setOrcid(orcid);
+ eventEntity.setEventType(eventType.getValue());
+ eventEntity.setClientId(clientId);
+ eventEntity.setRedirectUrl(redirectUrl);
+ eventEntity.setLabel(label);
+ eventEntity.setPublicPage(publicPage);
+
+ eventDao.createEvent(eventEntity);
+ }
+
+ private String getParameterValue(String queryString, String parameter) {
+ if (StringUtils.isNotEmpty(queryString)) {
+ try {
+ queryString = URLDecoder.decode(queryString, StandardCharsets.UTF_8.toString());
+ } catch (UnsupportedEncodingException u) {
+ // l
+ }
+ String[] parameters = queryString.split("&");
+ for (String p : parameters) {
+ String[] keyValuePair = p.split("=");
+ if (parameter.equals(keyValuePair[0])) {
+ return keyValuePair[1];
+ }
+ }
+ }
+ return null;
+ }
+}
diff --git a/orcid-core/src/main/java/org/orcid/core/togglz/Features.java b/orcid-core/src/main/java/org/orcid/core/togglz/Features.java
index 320c415ab7c..02e386f1dac 100644
--- a/orcid-core/src/main/java/org/orcid/core/togglz/Features.java
+++ b/orcid-core/src/main/java/org/orcid/core/togglz/Features.java
@@ -5,6 +5,9 @@
import org.togglz.core.context.FeatureContext;
public enum Features implements Feature {
+ @Label("Track user events")
+ EVENTS,
+
@Label("Source sorting")
SOURCE_SORTING,
diff --git a/orcid-core/src/main/java/org/orcid/core/utils/EventType.java b/orcid-core/src/main/java/org/orcid/core/utils/EventType.java
new file mode 100644
index 00000000000..d5c248dd171
--- /dev/null
+++ b/orcid-core/src/main/java/org/orcid/core/utils/EventType.java
@@ -0,0 +1,20 @@
+package org.orcid.core.utils;
+
+public enum EventType {
+ SIGN_IN("Sign-In"),
+ NEW_REGISTRATION("New-Registration"),
+ AUTHORIZE("Authorize"),
+ AUTHORIZE_DENY("Authorize-Deny"),
+ REAUTHORIZE("Reauthorize"),
+ PUBLIC_PAGE("Public-Page");
+
+ private final String value;
+
+ EventType(String v) {
+ value = v;
+ }
+
+ public String getValue() {
+ return value;
+ }
+}
diff --git a/orcid-core/src/main/resources/orcid-core-context.xml b/orcid-core/src/main/resources/orcid-core-context.xml
index 3479fe83c8a..ec9a24491d5 100644
--- a/orcid-core/src/main/resources/orcid-core-context.xml
+++ b/orcid-core/src/main/resources/orcid-core-context.xml
@@ -1214,4 +1214,6 @@
+
+
diff --git a/orcid-persistence/src/main/java/org/orcid/persistence/dao/EventDao.java b/orcid-persistence/src/main/java/org/orcid/persistence/dao/EventDao.java
new file mode 100644
index 00000000000..99787a759c5
--- /dev/null
+++ b/orcid-persistence/src/main/java/org/orcid/persistence/dao/EventDao.java
@@ -0,0 +1,20 @@
+package org.orcid.persistence.dao;
+
+import org.orcid.persistence.jpa.entities.EventEntity;
+
+import java.util.List;
+
+/**
+ *
+ * @author Daniel Palafox
+ *
+ */
+public interface EventDao extends GenericDao{
+
+ boolean removeEvents(String orcid);
+
+ List getEvents(String orcid);
+
+ void createEvent(EventEntity eventEntity);
+
+}
diff --git a/orcid-persistence/src/main/java/org/orcid/persistence/dao/impl/EventDaoImpl.java b/orcid-persistence/src/main/java/org/orcid/persistence/dao/impl/EventDaoImpl.java
new file mode 100644
index 00000000000..2d74fee4168
--- /dev/null
+++ b/orcid-persistence/src/main/java/org/orcid/persistence/dao/impl/EventDaoImpl.java
@@ -0,0 +1,45 @@
+package org.orcid.persistence.dao.impl;
+
+import org.orcid.persistence.aop.UpdateProfileLastModified;
+import org.orcid.persistence.dao.EventDao;
+import org.orcid.persistence.jpa.entities.EmailEntity;
+import org.orcid.persistence.jpa.entities.EventEntity;
+import org.orcid.persistence.jpa.entities.SpamEntity;
+import org.springframework.transaction.annotation.Transactional;
+
+import javax.persistence.Query;
+import javax.persistence.TypedQuery;
+import java.util.List;
+
+/**
+ * @author Daniel Palafox
+ */
+public class EventDaoImpl extends GenericDaoImpl implements EventDao {
+
+ public EventDaoImpl() {
+ super(EventEntity.class);
+ }
+
+ @Override
+ public List getEvents(String orcid) {
+ TypedQuery query = entityManager.createQuery("from EventEntity where orcid=:orcid", EventEntity.class);
+ query.setParameter("orcid", orcid);
+ List results = query.getResultList();
+ return results.isEmpty() ? null : results;
+ }
+
+ @Override
+ @Transactional
+ public void createEvent(EventEntity eventEntity) {
+ entityManager.persist(eventEntity);
+ }
+
+ @Override
+ @Transactional
+ public boolean removeEvents(String orcid) {
+ Query query = entityManager.createQuery("delete from EventEntity where orcid = :orcid");
+ query.setParameter("orcid", orcid);
+ query.executeUpdate();
+ return query.executeUpdate() > 0;
+ }
+}
diff --git a/orcid-persistence/src/main/java/org/orcid/persistence/jpa/entities/EventEntity.java b/orcid-persistence/src/main/java/org/orcid/persistence/jpa/entities/EventEntity.java
new file mode 100644
index 00000000000..019a710041c
--- /dev/null
+++ b/orcid-persistence/src/main/java/org/orcid/persistence/jpa/entities/EventEntity.java
@@ -0,0 +1,73 @@
+package org.orcid.persistence.jpa.entities;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.SequenceGenerator;
+import javax.persistence.Table;
+
+/**
+ *
+ * @author Daniel Palafox
+ *
+ */
+@Entity
+@Table(name = "event")
+public class EventEntity extends BaseEntity implements OrcidAware {
+ private static final long serialVersionUID = 1L;
+ private Long id;
+ private String orcid;
+ private String eventType;
+ private String clientId;
+ private String redirectUrl;
+ private String label;
+ private String publicPage;
+
+ @Id
+ @Column(name = "id")
+ @GeneratedValue(strategy = GenerationType.AUTO, generator = "event_seq")
+ @SequenceGenerator(name = "event_seq", sequenceName = "event_seq", allocationSize = 1)
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ @Column(name = "orcid")
+ public String getOrcid() {
+ return orcid;
+ }
+
+ public void setOrcid(String orcid) {
+ this.orcid = orcid;
+ }
+
+ @Column(name = "event_type")
+ public String getEventType() { return eventType; }
+
+ public void setEventType(String eventType) { this.eventType = eventType; }
+
+ @Column(name = "client_id")
+ public String getClientId() { return clientId; }
+
+ public void setClientId(String client_id) { this.clientId = client_id; }
+
+ @Column(name = "redirect_url")
+ public String getRedirectUrl() { return redirectUrl; }
+
+ public void setRedirectUrl(String redirect_url) { this.redirectUrl = redirect_url; }
+
+ @Column(name = "label")
+ public String getLabel() { return label; }
+
+ public void setLabel(String label) { this.label = label; }
+
+ @Column(name = "public_page")
+ public String getPublicPage() { return publicPage; }
+
+ public void setPublicPage(String public_page) { this.publicPage = public_page; }
+}
diff --git a/orcid-persistence/src/main/resources/META-INF/persistence.xml b/orcid-persistence/src/main/resources/META-INF/persistence.xml
index a07674d680a..b3d9d2d886e 100644
--- a/orcid-persistence/src/main/resources/META-INF/persistence.xml
+++ b/orcid-persistence/src/main/resources/META-INF/persistence.xml
@@ -60,6 +60,7 @@
org.orcid.persistence.jpa.entities.ResearchResourceItemEntity
org.orcid.persistence.jpa.entities.FindMyStuffHistoryEntity
org.orcid.persistence.jpa.entities.SpamEntity
+ org.orcid.persistence.jpa.entities.EventEntity
org.orcid.persistence.jpa.entities.ClientDetailsEntity
@@ -104,4 +105,4 @@
-
\ No newline at end of file
+
diff --git a/orcid-persistence/src/main/resources/db-master.xml b/orcid-persistence/src/main/resources/db-master.xml
index d995b2a5b58..c8a8e351c53 100644
--- a/orcid-persistence/src/main/resources/db-master.xml
+++ b/orcid-persistence/src/main/resources/db-master.xml
@@ -373,4 +373,6 @@
-
\ No newline at end of file
+
+
+
diff --git a/orcid-persistence/src/main/resources/db/updates/create_event_table.xml b/orcid-persistence/src/main/resources/db/updates/create_event_table.xml
new file mode 100644
index 00000000000..07d72de0cd4
--- /dev/null
+++ b/orcid-persistence/src/main/resources/db/updates/create_event_table.xml
@@ -0,0 +1,45 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ SELECT 1 FROM pg_roles WHERE rolname='orcidro'
+
+ GRANT SELECT ON event to orcidro;
+
+
+
diff --git a/orcid-persistence/src/main/resources/db/updates/dw_event.xml b/orcid-persistence/src/main/resources/db/updates/dw_event.xml
new file mode 100644
index 00000000000..871803de491
--- /dev/null
+++ b/orcid-persistence/src/main/resources/db/updates/dw_event.xml
@@ -0,0 +1,45 @@
+
+
+
+
+
+
+
+ SELECT event_type, client_id, COUNT(id), DATE_TRUNC('day', date_created)
+ FROM event
+ WHERE event_type != 'Public-Page'
+ GROUP BY event_type, client_id, DATE_TRUNC('day', date_created)
+ ORDER BY DATE_TRUNC('day', date_created) DESC;
+
+
+
+
+
+ SELECT 1 FROM pg_roles WHERE rolname='dw_user'
+
+ GRANT SELECT ON TABLE dw_event to dw_user;
+
+
+
+
+
+
+
+ SELECT event_type, public_page, COUNT(id), DATE_TRUNC('day', date_created)
+ FROM event
+ WHERE event_type = 'Public-Page'
+ GROUP BY event_type, public_page, DATE_TRUNC('day', date_created)
+ ORDER BY DATE_TRUNC('day', date_created) DESC;
+
+
+
+
+
+ SELECT 1 FROM pg_roles WHERE rolname='dw_user'
+
+ GRANT SELECT ON TABLE dw_event_public_page to dw_user;
+
+
+
diff --git a/orcid-persistence/src/main/resources/orcid-persistence-context.xml b/orcid-persistence/src/main/resources/orcid-persistence-context.xml
index 187ba4314b8..1ab08b4705b 100644
--- a/orcid-persistence/src/main/resources/orcid-persistence-context.xml
+++ b/orcid-persistence/src/main/resources/orcid-persistence-context.xml
@@ -457,7 +457,9 @@
-
+
+
+
diff --git a/orcid-persistence/src/test/java/org/orcid/persistence/EventDaoTest.java b/orcid-persistence/src/test/java/org/orcid/persistence/EventDaoTest.java
new file mode 100644
index 00000000000..0b17e0a3079
--- /dev/null
+++ b/orcid-persistence/src/test/java/org/orcid/persistence/EventDaoTest.java
@@ -0,0 +1,77 @@
+package org.orcid.persistence;
+
+import org.apache.commons.lang3.reflect.FieldUtils;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.orcid.persistence.dao.EventDao;
+import org.orcid.persistence.dao.SpamDao;
+import org.orcid.persistence.jpa.entities.EventEntity;
+import org.orcid.persistence.jpa.entities.SourceType;
+import org.orcid.persistence.jpa.entities.SpamEntity;
+import org.orcid.test.DBUnitTest;
+import org.orcid.test.OrcidJUnit4ClassRunner;
+import org.springframework.test.context.ContextConfiguration;
+
+import javax.annotation.Resource;
+import javax.persistence.NoResultException;
+import javax.transaction.Transactional;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+@RunWith(OrcidJUnit4ClassRunner.class)
+@ContextConfiguration(inheritInitializers = false, inheritLocations = false, locations = {"classpath:test-orcid-persistence-context.xml"})
+public class EventDaoTest extends DBUnitTest {
+
+ private static String USER_ORCID = "4444-4444-4444-4497";
+ private static String OTHER_USER_ORCID = "4444-4444-4444-4499";
+
+ @Resource(name = "eventDao")
+ private EventDao eventDao;
+
+ @BeforeClass
+ public static void initDBUnitData() throws Exception {
+ initDBUnitData(Arrays.asList("/data/SourceClientDetailsEntityData.xml", "/data/ProfileEntityData.xml", "/data/EventEntityData.xml"));
+ }
+
+ @AfterClass
+ public static void removeDBUnitData() throws Exception {
+ removeDBUnitData(Arrays.asList("/data/EventEntityData.xml", "/data/ProfileEntityData.xml", "/data/SourceClientDetailsEntityData.xml"));
+ }
+
+ @Test
+ @Transactional
+ public void testFindByOrcid() {
+ List eventEntityList = eventDao.getEvents(OTHER_USER_ORCID);
+ assertNotNull(eventEntityList);
+ assertEquals(OTHER_USER_ORCID, eventEntityList.get(0).getOrcid());
+ }
+
+ @Test
+ public void testWriteSpam() throws IllegalAccessException {
+ EventEntity eventEntity = new EventEntity();
+ eventEntity.setEventType("Sign-In");
+ Date date = new Date();
+ FieldUtils.writeField(eventEntity, "dateCreated", date, true);
+ FieldUtils.writeField(eventEntity, "lastModified", date, true);
+ eventEntity.setOrcid(USER_ORCID);
+
+ eventDao.createEvent(eventEntity);
+
+ List eventEntities = eventDao.getEvents(USER_ORCID);
+ assertNotNull(eventEntities);
+ assertEquals(USER_ORCID, eventEntities.get(0).getOrcid());
+ }
+
+ @Test
+ public void testRemoveSpam() throws NoResultException {
+ List eventEntities = eventDao.getEvents(OTHER_USER_ORCID);
+ assertNotNull(eventEntities);
+ eventDao.removeEvents(eventEntities.get(0).getOrcid());
+ }
+}
diff --git a/orcid-test/src/main/java/org/orcid/test/DBUnitTest.java b/orcid-test/src/main/java/org/orcid/test/DBUnitTest.java
index bbb0a72ddec..470ba8ab1ae 100644
--- a/orcid-test/src/main/java/org/orcid/test/DBUnitTest.java
+++ b/orcid-test/src/main/java/org/orcid/test/DBUnitTest.java
@@ -43,7 +43,7 @@ public class DBUnitTest {
"org_disambiguated", "org_disambiguated_external_identifier", "org", "org_affiliation_relation", "profile_funding", "funding_external_identifier", "address",
"institution", "affiliation", "notification", "client_details", "client_secret", "oauth2_token_detail", "custom_email", "webhook", "granted_authority",
"orcid_props", "peer_review", "peer_review_subject", "shibboleth_account", "group_id_record", "invalid_record_data_changes",
- "research_resource","research_resource_item, spam", "backup_code", "profile_history_event"};
+ "research_resource","research_resource_item, spam", "backup_code", "profile_history_event", "event"};
private static ApplicationContext context;
@@ -156,6 +156,7 @@ private static void cleanClientSourcedProfiles(IDatabaseConnection connection) t
dataSet.addTable("research_resource");
dataSet.addTable("find_my_stuff_history");
dataSet.addTable("spam");
+ dataSet.addTable("event");
DatabaseOperation.DELETE.execute(connection, dataSet);
QueryDataSet theRest = new QueryDataSet(connection);
@@ -190,4 +191,4 @@ public static IDataSet getDataSet(String flatXMLDataFile) {
return ds;
}
-}
\ No newline at end of file
+}
diff --git a/orcid-test/src/main/resources/data/EventEntityData.xml b/orcid-test/src/main/resources/data/EventEntityData.xml
new file mode 100644
index 00000000000..dc4747d37d6
--- /dev/null
+++ b/orcid-test/src/main/resources/data/EventEntityData.xml
@@ -0,0 +1,36 @@
+
+
+
+
+
+
+
+
+
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 f5278118110..0b24e1ec2f5 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
@@ -12,6 +12,7 @@
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
+import org.orcid.core.common.manager.EventManager;
import org.orcid.core.constants.OrcidOauth2Constants;
import org.orcid.core.exception.ClientDeactivatedException;
import org.orcid.core.exception.LockedException;
@@ -21,6 +22,8 @@
import org.orcid.core.oauth.OrcidRandomValueTokenServices;
import org.orcid.core.oauth.service.OrcidAuthorizationEndpoint;
import org.orcid.core.oauth.service.OrcidOAuth2RequestValidator;
+import org.orcid.core.togglz.Features;
+import org.orcid.core.utils.EventType;
import org.orcid.frontend.web.controllers.BaseControllerUtil;
import org.orcid.frontend.web.controllers.helper.OauthHelper;
import org.orcid.frontend.web.exception.OauthInvalidRequestException;
@@ -75,6 +78,9 @@ public class OauthController {
@Resource(name = "profileEntityManagerV3")
private ProfileEntityManager profileEntityManager;
+ @Resource
+ private EventManager eventManager;
+
@RequestMapping(value = { "/oauth/custom/init.json" }, method = RequestMethod.POST)
public @ResponseBody RequestInfoForm loginGetHandler(HttpServletRequest request, Map model, @RequestParam Map requestParameters,
SessionStatus sessionStatus, Principal principal) throws UnsupportedEncodingException {
@@ -90,6 +96,9 @@ public class OauthController {
List responseParam = parameters.get(requestInfoForm.getResponseType());
if (responseParam != null && !responseParam.isEmpty() && !PojoUtil.isEmpty(responseParam.get(0))) {
isResponseSet = true;
+ if (Features.EVENTS.isActive()) {
+ eventManager.createEvent(requestInfoForm.getUserOrcid(), EventType.REAUTHORIZE, null, requestInfoForm);
+ }
}
}
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 5d3fc8bca2c..bd660794e1c 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
@@ -6,6 +6,10 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import org.orcid.core.common.manager.EventManager;
+import org.orcid.core.togglz.Features;
+import org.orcid.core.utils.EventType;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
/*
@@ -15,9 +19,15 @@
* @author Robert Peters (rcpeters)
*/
public class AjaxAuthenticationSuccessHandler extends AjaxAuthenticationSuccessHandlerBase {
+
+ @Autowired
+ EventManager eventManager;
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);
+ }
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/OauthAuthorizeController.java b/orcid-web/src/main/java/org/orcid/frontend/web/controllers/OauthAuthorizeController.java
index 7cef06b82a6..45821b78f64 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
@@ -11,8 +11,11 @@
import org.orcid.core.constants.OrcidOauth2Constants;
import org.orcid.core.exception.ClientDeactivatedException;
import org.orcid.core.exception.LockedException;
+import org.orcid.core.common.manager.EventManager;
import org.orcid.core.manager.v3.ProfileEntityManager;
import org.orcid.core.oauth.OrcidRandomValueTokenServices;
+import org.orcid.core.togglz.Features;
+import org.orcid.core.utils.EventType;
import org.orcid.frontend.web.controllers.helper.OauthHelper;
import org.orcid.jaxb.model.message.ScopePathType;
import org.orcid.persistence.jpa.entities.ClientDetailsEntity;
@@ -52,6 +55,9 @@ public class OauthAuthorizeController extends OauthControllerBase {
@Resource
private OauthHelper oauthHelper;
+
+ @Resource
+ private EventManager eventManager;
/** This is called if user is already logged in.
* Checks permissions have been granted to client and generates access code.
@@ -244,6 +250,10 @@ public ModelAndView loginGetHandler(HttpServletRequest request, HttpServletRespo
// Approve
RedirectView view = (RedirectView) authorizationEndpoint.approveOrDeny(approvalParams, model, status, auth);
requestInfoForm.setRedirectUrl(view.getUrl());
+ if (Features.EVENTS.isActive()) {
+ EventType eventType = "true".equals(approvalParams.get("user_oauth_approval")) ? EventType.AUTHORIZE : EventType.AUTHORIZE_DENY;
+ eventManager.createEvent(auth.getPrincipal().toString(), eventType, null, requestInfoForm);
+ }
if(new HttpSessionRequestCache().getRequest(request, response) != null)
new HttpSessionRequestCache().removeRequest(request, response);
LOGGER.info("OauthConfirmAccessController form.getRedirectUri being sent to client browser: " + requestInfoForm.getRedirectUrl());
@@ -252,7 +262,7 @@ public ModelAndView loginGetHandler(HttpServletRequest request, HttpServletRespo
request.getSession().removeAttribute(OrcidOauth2Constants.OAUTH_2SCREENS);
return requestInfoForm;
}
-
+
/**
* Copies all request parameters into the provided params map
*
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 f0b9d6e2ff5..63f56614557 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
@@ -1,5 +1,6 @@
package org.orcid.frontend.web.controllers;
+import org.orcid.core.common.manager.EventManager;
import org.orcid.core.exception.DeactivatedException;
import org.orcid.core.exception.LockedException;
import org.orcid.core.exception.OrcidDeprecatedException;
@@ -27,6 +28,7 @@
import org.orcid.core.manager.v3.read_only.WorkManagerReadOnly;
import org.orcid.core.oauth.OrcidOauth2TokenDetailService;
import org.orcid.core.togglz.Features;
+import org.orcid.core.utils.EventType;
import org.orcid.core.utils.v3.SourceUtils;
import org.orcid.frontend.web.pagination.Page;
import org.orcid.frontend.web.pagination.ResearchResourcePaginator;
@@ -163,6 +165,9 @@ public class PublicRecordController extends BaseWorkspaceController {
@Resource
PublicProfileController publicProfileController;
+ @Resource
+ private EventManager eventManager;
+
@Resource
private WorksCacheManager worksCacheManager;
@@ -179,6 +184,9 @@ PublicRecord getPublicRecord(@PathVariable("orcid") String orcid) {
boolean isDeprecated = false;
try {
+ if (Features.EVENTS.isActive()) {
+ eventManager.createEvent(orcid, EventType.PUBLIC_PAGE, null, null);
+ }
// Check if the profile is deprecated or locked
orcidSecurityManager.checkProfile(orcid);
} catch (LockedException | DeactivatedException e) {
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 83bf8621655..78f299e9c1d 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
@@ -20,6 +20,7 @@
import org.orcid.core.manager.EncryptionManager;
import org.orcid.core.manager.ProfileEntityCacheManager;
import org.orcid.core.manager.RegistrationManager;
+import org.orcid.core.common.manager.EventManager;
import org.orcid.core.manager.v3.OrcidSearchManager;
import org.orcid.core.manager.v3.ProfileHistoryEventManager;
import org.orcid.core.manager.v3.read_only.AffiliationsManagerReadOnly;
@@ -27,6 +28,8 @@
import org.orcid.core.manager.v3.read_only.RecordNameManagerReadOnly;
import org.orcid.core.profile.history.ProfileHistoryEventType;
import org.orcid.core.security.OrcidUserDetailsService;
+import org.orcid.core.togglz.Features;
+import org.orcid.core.utils.EventType;
import org.orcid.core.utils.OrcidRequestUtil;
import org.orcid.core.utils.OrcidStringUtils;
import org.orcid.frontend.email.RecordEmailSender;
@@ -130,6 +133,9 @@ public class RegistrationController extends BaseController {
@Resource
private SocialSignInUtils socialSignInUtils;
+ @Resource
+ private EventManager eventManager;
+
@RequestMapping(value = "/register.json", method = RequestMethod.GET)
public @ResponseBody Registration getRegister(HttpServletRequest request, HttpServletResponse response) {
// Remove the session hash if needed
@@ -298,6 +304,9 @@ 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;
}
@@ -572,4 +581,4 @@ private void processProfileHistoryEvents(Registration registration, String newUs
}
}
-}
\ No newline at end of file
+}