From d5d3b604f135e8b6c2242354efe811ce6f32d08b Mon Sep 17 00:00:00 2001 From: unaibrrgn <75972112+unaibrrgn@users.noreply.github.com> Date: Tue, 7 Feb 2023 13:38:18 +0100 Subject: [PATCH 01/15] Get an email when the user's groups have changed #201 --- .../web/controller/RegistryManagerUsers.java | 151 ++++++++++++++---- .../configuration.properties | 5 + .../configuration.properties.orig | 5 + .../main/webapp/jsp/registryManagerUsers.jsp | 30 ++-- .../base/utility/BaseConstants.java | 5 + .../javaapi/handler/RegUserHandler.java | 12 +- .../public_html/js-ecl-v2/app_core.js | 6 +- 7 files changed, 168 insertions(+), 46 deletions(-) diff --git a/sources/Re3gistry2/src/main/java/eu/europa/ec/re3gistry2/web/controller/RegistryManagerUsers.java b/sources/Re3gistry2/src/main/java/eu/europa/ec/re3gistry2/web/controller/RegistryManagerUsers.java index 4a7bf15d..9a8b46b8 100644 --- a/sources/Re3gistry2/src/main/java/eu/europa/ec/re3gistry2/web/controller/RegistryManagerUsers.java +++ b/sources/Re3gistry2/src/main/java/eu/europa/ec/re3gistry2/web/controller/RegistryManagerUsers.java @@ -26,6 +26,7 @@ import eu.europa.ec.re3gistry2.base.utility.Configuration; import eu.europa.ec.re3gistry2.base.utility.BaseConstants; import eu.europa.ec.re3gistry2.base.utility.InputSanitizerHelper; +import eu.europa.ec.re3gistry2.base.utility.MailManager; import eu.europa.ec.re3gistry2.base.utility.PersistenceFactory; import eu.europa.ec.re3gistry2.base.utility.UserHelper; import eu.europa.ec.re3gistry2.base.utility.WebConstants; @@ -37,15 +38,20 @@ import eu.europa.ec.re3gistry2.javaapi.handler.RegUserHandler; import eu.europa.ec.re3gistry2.model.RegGroup; import eu.europa.ec.re3gistry2.model.RegLanguagecode; +import eu.europa.ec.re3gistry2.model.RegStatuslocalization; import eu.europa.ec.re3gistry2.model.RegUser; import eu.europa.ec.re3gistry2.model.RegUserRegGroupMapping; import eu.europa.ec.re3gistry2.model.uuidhandlers.RegUserRegGroupMappingUuidHelper; import java.io.IOException; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.Arrays; import java.util.Date; import java.util.HashMap; +import java.util.LinkedHashSet; import java.util.List; +import javax.mail.internet.InternetAddress; import javax.persistence.EntityManager; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; @@ -75,18 +81,19 @@ private void processRequest(HttpServletRequest request, HttpServletResponse resp RegUserRegGroupMappingManager regUserRegGroupMappingManager = new RegUserRegGroupMappingManager(entityManager); RegUserHandler regUserHandler = new RegUserHandler(); RegGroupManager regGroupManager = new RegGroupManager(entityManager); + // Getting form parameter String formRegUserUuid = request.getParameter(BaseConstants.KEY_FORM_FIELD_NAME_USERUUID); String formSubmitAction = request.getParameter(BaseConstants.KEY_FORM_FIELD_NAME_SUBMITACTION); String formName = request.getParameter(BaseConstants.KEY_FORM_FIELD_NAME_USER_NAME); - + formRegUserUuid = (formRegUserUuid != null) ? InputSanitizerHelper.sanitizeInput(formRegUserUuid) : null; formSubmitAction = (formSubmitAction != null) ? InputSanitizerHelper.sanitizeInput(formSubmitAction) : null; - + // Handling charset for the textual contents byte[] bytes; - if (formName!=null) { + if (formName != null) { bytes = formName.getBytes(Charset.defaultCharset()); formName = new String(bytes, StandardCharsets.UTF_8); formName = InputSanitizerHelper.sanitizeInput(formName); @@ -94,19 +101,30 @@ private void processRequest(HttpServletRequest request, HttpServletResponse resp // Getting request parameter String regUserDetailUUID = request.getParameter(BaseConstants.KEY_REQUEST_USERDETAIL_UUID); - String regUserRegGroupMappingUUID = request.getParameter(BaseConstants.KEY_REQUEST_USERGROUPMAPPING_UUID); String languageUUID = request.getParameter(BaseConstants.KEY_REQUEST_LANGUAGEUUID); String actionType = request.getParameter(BaseConstants.KEY_REQUEST_ACTIONTYPE); - String checkBoxChecked = request.getParameter(BaseConstants.KEY_REQUEST_CHECKED); - String selectedRegGroupUUID = request.getParameter(BaseConstants.KEY_REQUEST_GROUP_UUID); - + + String[] checkBoxCheckedNoFormat = request.getParameterValues(BaseConstants.KEY_REQUEST_CHECKED); + String[] selectedRegGroupUUIDNoFormat = request.getParameterValues(BaseConstants.KEY_REQUEST_GROUP_UUID); + String[] regUserRegGroupMappingUUIDNoFormat = request.getParameterValues(BaseConstants.KEY_REQUEST_USERGROUPMAPPING_UUID); + List checkBoxChecked = null; + List selectedRegGroupUUID = null; + List regUserRegGroupMappingUUID = null; + + if (checkBoxCheckedNoFormat != null) { + checkBoxChecked = Arrays.asList(checkBoxCheckedNoFormat[0].split(",")); + } + if (selectedRegGroupUUIDNoFormat != null) { + selectedRegGroupUUID = Arrays.asList(selectedRegGroupUUIDNoFormat[0].split(",")); + } + if (regUserRegGroupMappingUUIDNoFormat != null) { + regUserRegGroupMappingUUID = Arrays.asList(regUserRegGroupMappingUUIDNoFormat[0].split(",")); + } + regUserDetailUUID = (regUserDetailUUID != null) ? InputSanitizerHelper.sanitizeInput(regUserDetailUUID) : null; - regUserRegGroupMappingUUID = (regUserRegGroupMappingUUID != null) ? InputSanitizerHelper.sanitizeInput(regUserRegGroupMappingUUID) : null; languageUUID = (languageUUID != null) ? InputSanitizerHelper.sanitizeInput(languageUUID) : null; actionType = (actionType != null) ? InputSanitizerHelper.sanitizeInput(actionType) : null; - selectedRegGroupUUID = (selectedRegGroupUUID != null) ? InputSanitizerHelper.sanitizeInput(selectedRegGroupUUID) : null; - checkBoxChecked = (checkBoxChecked != null) ? InputSanitizerHelper.sanitizeInput(checkBoxChecked) : null; - + //Getting the master language RegLanguagecode masterLanguage = regLanguagecodeManager.getMasterLanguage(); request.setAttribute(BaseConstants.KEY_REQUEST_MASTERLANGUAGE, masterLanguage); @@ -136,7 +154,7 @@ private void processRequest(HttpServletRequest request, HttpServletResponse resp if (permissionManageSystem) { - if (((formRegUserUuid != null && formRegUserUuid.length() > 0) || (regUserDetailUUID != null && regUserDetailUUID.length() > 0) || (regUserRegGroupMappingUUID != null && regUserRegGroupMappingUUID.length() > 0)) && ((formSubmitAction != null && formSubmitAction.length() > 0) || (actionType != null && actionType.length() > 0))) { + if (((formRegUserUuid != null && formRegUserUuid.length() > 0) || (regUserDetailUUID != null && regUserDetailUUID.length() > 0) || (regUserRegGroupMappingUUID != null && !regUserRegGroupMappingUUID.isEmpty())) && ((formSubmitAction != null && formSubmitAction.length() > 0) || (actionType != null && actionType.length() > 0))) { // This is a save request boolean result = false; @@ -160,26 +178,103 @@ private void processRequest(HttpServletRequest request, HttpServletResponse resp regUserDetail.setName(formName); result = regUserHandler.updateUser(regUserDetail); } else if (actionType != null && actionType.equals(BaseConstants.KEY_ACTION_TYPE_REMOVEUSERGROUP)) { - - if (checkBoxChecked.equals(BaseConstants.KEY_BOOLEAN_STRING_FALSE)) { - // Removing the selected group from the user - RegUserRegGroupMapping regUserRegGroupMapping = regUserRegGroupMappingManager.get(regUserRegGroupMappingUUID); - result = regUserHandler.removeUserFromGroup(regUserRegGroupMapping); + List addedGroups = new ArrayList<>(); + List removedGroups = new ArrayList<>(); + if (checkBoxChecked != null) { + List activeGroupsList = regUserRegGroupMappingManager.getAll(regUserDetail); + for (int i = 0; i < checkBoxChecked.size(); i++) { + if (checkBoxChecked.get(i).equals(BaseConstants.KEY_BOOLEAN_STRING_FALSE)) { + // Removing the selected group from the user + if (regUserRegGroupMappingUUID != null && !regUserRegGroupMappingUUID.isEmpty() && regUserRegGroupMappingUUID.size() >= i) { + if (!regUserRegGroupMappingUUID.get(i).isEmpty()) { + try{ + RegUserRegGroupMapping regUserRegGroupMapping = regUserRegGroupMappingManager.get(regUserRegGroupMappingUUID.get(i)); + for (RegUserRegGroupMapping r : activeGroupsList) { + if (r.getUuid().equals(regUserRegGroupMapping.getUuid())) { + result = regUserHandler.removeUserFromGroup(regUserRegGroupMapping); + if (selectedRegGroupUUID != null && !selectedRegGroupUUID.isEmpty() && selectedRegGroupUUID.size() >= i) { + RegGroup selectedRegGroup = regGroupManager.get(selectedRegGroupUUID.get(i)); + String group = selectedRegGroup.getName(); + removedGroups.add(group); + break; + } + } + + } + }catch(Exception e){ + logger.error(e.getMessage(), e); + } + } + } + }else { + // Adding the selected group to the user + if(selectedRegGroupUUID != null && !selectedRegGroupUUID.isEmpty() && selectedRegGroupUUID.size() >= i){ + //RegUserRegGroupMapping regUserRegGroupMapping = regUserRegGroupMappingManager.get(regUserRegGroupMappingUUID.get(i)); + RegGroup selectedRegGroup = regGroupManager.get(selectedRegGroupUUID.get(i)); + RegUserRegGroupMapping newMapping = new RegUserRegGroupMapping(); + boolean b = false; + for (RegUserRegGroupMapping r : activeGroupsList) { + if (r.getRegGroup().getUuid().equals(selectedRegGroup.getUuid())) { + b = true; + break; + } + } + if(!b){ + String newUUID = RegUserRegGroupMappingUuidHelper.getUuid(regUserDetail, selectedRegGroup); + newMapping.setUuid(newUUID); + newMapping.setRegUser(regUserDetail); + newMapping.setRegGroup(selectedRegGroup); + newMapping.setIsGroupadmin(true); + newMapping.setInsertdate(new Date()); + result = regUserHandler.addUserFromGroup(newMapping); + String group = selectedRegGroup.getName(); + addedGroups.add(group); + } + + }else{ + logger.error("Error: Failed retrieving selected regGroup"); + } + } + } } else { - // Adding the selected group to the user - RegGroup selectedRegGroup = regGroupManager.get(selectedRegGroupUUID); - RegUserRegGroupMapping newMapping = new RegUserRegGroupMapping(); - String newUUID = RegUserRegGroupMappingUuidHelper.getUuid(regUserDetail, selectedRegGroup); - newMapping.setUuid(newUUID); - newMapping.setRegUser(regUserDetail); - newMapping.setRegGroup(selectedRegGroup); - newMapping.setIsGroupadmin(true); - newMapping.setInsertdate(new Date()); - result = regUserHandler.addUserFromGroup(newMapping); + logger.error("Error: Couldn't retrieve checkboxes"); + } + //Send email to affected user/s + LinkedHashSet users = new LinkedHashSet<>(); + users.add(new InternetAddress(regUserDetail.getEmail())); + if (!users.isEmpty()) { + InternetAddress[] recipient = new InternetAddress[users.size()]; + users.toArray(recipient); + String subject = "User's group has changed."; + String body = "
Dear User

The groups assigned to " + regUserDetail.getEmail() + " have changed.
"; + + if (!addedGroups.isEmpty()) { + body += "The user "+regUserDetail.getEmail()+" has been added to the group(s): "; + for (int i = 0; i < addedGroups.size(); i++) { + if (i == addedGroups.size() - 1) { + body += addedGroups.get(i) + ".
"; + } else { + body += addedGroups.get(i) + ", "; + } + } + } + + if (!removedGroups.isEmpty()) { + body += "The user "+regUserDetail.getEmail()+" has been removed from the group(s): "; + for (int y = 0; y < removedGroups.size(); y++) { + if (y == removedGroups.size() - 1) { + body += removedGroups.get(y) + ". "; + } else { + body += removedGroups.get(y) + ", "; + } + } + } + body += "

If you have any questions, please do not hesitate to contact [contact].

"; + body += "Regards."; + MailManager.sendMail(recipient, subject, body); } } } - } catch (Exception e) { logger.error(e.getMessage(), e); } diff --git a/sources/Re3gistry2/src/main/resources/configurations_files/configuration.properties b/sources/Re3gistry2/src/main/resources/configurations_files/configuration.properties index c3f31637..64b9e8b3 100644 --- a/sources/Re3gistry2/src/main/resources/configurations_files/configuration.properties +++ b/sources/Re3gistry2/src/main/resources/configurations_files/configuration.properties @@ -168,6 +168,11 @@ mail.text.subject.bulkimport.error=Re3gistry - bulk import {itemclass} error mail.text.body.bulkimport.success=Dear {name},

The bulk import has been completed with success. mail.text.body.bulkimport.error=Dear {name},

The bulk import has been completed with some error(s) when importing the file.
{errors} Than retry to load the file. +mail.text.subject.groupschanged=User's group has changed +mail.text.body.groupschanged=The groups assigned to {name} have changed. +mail.text.body.groupschanged.add=User has been added to group(s): +mail.text.body.groupschanged.remove=User has been removed from the group(s): + ### Webapp properties #### web.application_root_url=${application.rooturl} web.cdn_url=https://inspire.ec.europa.eu/cdn/1.0/ diff --git a/sources/Re3gistry2/src/main/resources/configurations_files/configuration.properties.orig b/sources/Re3gistry2/src/main/resources/configurations_files/configuration.properties.orig index 39b06917..7bddbc2d 100644 --- a/sources/Re3gistry2/src/main/resources/configurations_files/configuration.properties.orig +++ b/sources/Re3gistry2/src/main/resources/configurations_files/configuration.properties.orig @@ -164,6 +164,11 @@ mail.text.body.error=An error has occurred during the Re3gistry installation, pl mail.text.subject.newregistration=Re3gistry - Your account have been successfully added to the system mail.text.error.newregistration=Dear {name},

Your account has been successfully created and it is now enabled.

You can access the management interface using the following credentials:
Username: {email}
Key: {key}

Please change your key after the first access.
+mail.text.subject.groupschanged=User's group has changed +mail.text.body.groupschanged=The groups assigned to {name} have changed. +mail.text.body.groupschanged.add=User has been added to group(s): +mail.text.body.groupschanged.remove=User has been removed from the group(s): + mail.text.subject.bulkimport.success=Re3gistry - bulk import {itemclass} success mail.text.subject.bulkimport.error=Re3gistry - bulk import {itemclass} error mail.text.body.bulkimport.success=Dear {name},

The bulk import has been completed with success. diff --git a/sources/Re3gistry2/src/main/webapp/jsp/registryManagerUsers.jsp b/sources/Re3gistry2/src/main/webapp/jsp/registryManagerUsers.jsp index 23285635..9bcc6425 100644 --- a/sources/Re3gistry2/src/main/webapp/jsp/registryManagerUsers.jsp +++ b/sources/Re3gistry2/src/main/webapp/jsp/registryManagerUsers.jsp @@ -285,6 +285,7 @@
+

${localization.getString("label.completerequiredfields")}

@@ -335,11 +336,15 @@ %> +
+ +
<% } %> - + + <%@include file="includes/footer.inc.jsp" %> <%@include file="includes/pageend.inc.jsp" %> @@ -362,14 +367,21 @@ "dom": '<"top">rt<"bottom"lip><"clear">', "order": [[0, "desc"]] }); - }); - - $(".cbUpdate").on('change', function () { - var regGroupUuid = $(this).data("<%=BaseConstants.KEY_REQUEST_GROUP_UUID%>"); - var regUserRegGroupMappingUuid = $(this).data("<%=BaseConstants.KEY_REQUEST_USERGROUPMAPPING_UUID%>"); - var regUserDetailUuid = $(this).data("<%=BaseConstants.KEY_REQUEST_USERDETAIL_UUID%>"); - var checked = $(this).is(":checked"); - $.get(".<%=WebConstants.PAGE_URINAME_REGISTRYMANAGER_USERS%>?<%=BaseConstants.KEY_REQUEST_GROUP_UUID%>=" + regGroupUuid + "&<%=BaseConstants.KEY_REQUEST_USERDETAIL_UUID%>=" + regUserDetailUuid + "&<%=BaseConstants.KEY_REQUEST_ACTIONTYPE%>=<%=BaseConstants.KEY_ACTION_TYPE_REMOVEUSERGROUP%>&<%=BaseConstants.KEY_REQUEST_USERGROUPMAPPING_UUID%>=" + regUserRegGroupMappingUuid + "&<%=BaseConstants.KEY_REQUEST_CHECKED%>=" + checked, function (data) {}); + }); + $("#mySaveButton").on('click', function () { + var collection = document.getElementsByClassName("cbUpdate"); + var regUserDetailUuid = $(collection[0]).data("<%=BaseConstants.KEY_REQUEST_USERDETAIL_UUID%>"); + var regUserRegGroupMappingUuidList = new Array (collection.length); + var regGroupUUIDList = new Array(collection.length); + var checkedList = new Array(collection.length); + + for(var i=0; i"); + regGroupUUIDList[i] = $(collection[i]).data("<%=BaseConstants.KEY_REQUEST_GROUP_UUID%>"); + checkedList[i] = $(collection[i]).is(":checked"); + } + + $.get(".<%=WebConstants.PAGE_URINAME_REGISTRYMANAGER_USERS%>?<%=BaseConstants.KEY_REQUEST_GROUP_UUID%>=" + regGroupUUIDList + "&<%=BaseConstants.KEY_REQUEST_USERDETAIL_UUID%>=" + regUserDetailUuid + "&<%=BaseConstants.KEY_REQUEST_ACTIONTYPE%>=<%=BaseConstants.KEY_ACTION_TYPE_REMOVEUSERGROUP%>&<%=BaseConstants.KEY_REQUEST_USERGROUPMAPPING_UUID%>=" + regUserRegGroupMappingUuidList + "&<%=BaseConstants.KEY_REQUEST_CHECKED%>=" + checkedList, function (data) {}); }); diff --git a/sources/Re3gistry2Base/src/main/java/eu/europa/ec/re3gistry2/base/utility/BaseConstants.java b/sources/Re3gistry2Base/src/main/java/eu/europa/ec/re3gistry2/base/utility/BaseConstants.java index d49f17e2..dad80675 100644 --- a/sources/Re3gistry2Base/src/main/java/eu/europa/ec/re3gistry2/base/utility/BaseConstants.java +++ b/sources/Re3gistry2Base/src/main/java/eu/europa/ec/re3gistry2/base/utility/BaseConstants.java @@ -140,6 +140,11 @@ public class BaseConstants { public static final String KEY_EMAIL_BODY_CACHE_ERROR = "mail.text.body.cache.error"; public static final String KEY_EMAIL_SUBJECT_ITEM_PUBLISHED = "mail.text.subject.item.publised"; public static final String KEY_EMAIL_BODY_ITEM_PUBLISHED = "mail.text.body.item.publised"; + + public static final String KEY_EMAIL_SUBJECT_GROUPSCHANGED = "mail.text.subject.groupschanged"; + public static final String KEY_EMAIL_BODY_GROUPSCHANGED = "mail.text.body.groupschanged"; + public static final String KEY_EMAIL_BODY_GROUPSCHANGED_ADD = "mail.text.body.groupschanged.add"; + public static final String KEY_EMAIL_BODY_GROUPSCHANGED_REMOVE = "mail.text.body.groupschanged.remove"; /** * mail subject and body bulk import diff --git a/sources/Re3gistry2JavaAPI/src/main/java/eu/europa/ec/re3gistry2/javaapi/handler/RegUserHandler.java b/sources/Re3gistry2JavaAPI/src/main/java/eu/europa/ec/re3gistry2/javaapi/handler/RegUserHandler.java index 0f2db269..9d0a9cb4 100644 --- a/sources/Re3gistry2JavaAPI/src/main/java/eu/europa/ec/re3gistry2/javaapi/handler/RegUserHandler.java +++ b/sources/Re3gistry2JavaAPI/src/main/java/eu/europa/ec/re3gistry2/javaapi/handler/RegUserHandler.java @@ -147,9 +147,9 @@ public boolean removeUserFromGroup(RegUserRegGroupMapping regUserRegGroupMapping } catch (Exception e) { logger.error("@ RegUserHandler.removeUserFromGroup: generic error.", e); } finally { - if (entityManager != null) { - entityManager.close(); - } +// if (entityManager != null) { +// entityManager.close(); +// } } return operationResult; } @@ -179,9 +179,9 @@ public boolean addUserFromGroup(RegUserRegGroupMapping regUserRegGroupMapping){ } catch (Exception e) { logger.error("@ RegUserHandler.addUserFromGroup: generic error.", e); } finally { - if (entityManager != null) { - entityManager.close(); - } +// if (entityManager != null) { +// entityManager.close(); +// } } return operationResult; } diff --git a/sources/Re3gistry2ServiceWebapp/public_html/js-ecl-v2/app_core.js b/sources/Re3gistry2ServiceWebapp/public_html/js-ecl-v2/app_core.js index ff60a869..feca6275 100644 --- a/sources/Re3gistry2ServiceWebapp/public_html/js-ecl-v2/app_core.js +++ b/sources/Re3gistry2ServiceWebapp/public_html/js-ecl-v2/app_core.js @@ -175,9 +175,9 @@ function renderFetchError(data) { mainContainer.empty(); if (data) { - mainContainer.append(htmlSnippet_errorMessage.replace('{0}', i18n[key_errorPrefix + data.error.code])); + mainContainer.append(htmlSnippet_errorMessage.replace('{0}', i18n[key_errorPrefix + data.error.code].replace('{0}',registryApp.errorMessageURL).replace('{1}',registryApp.errorMessageDefinition))); } else { - mainContainer.append(htmlSnippet_errorMessage.replace('{0}', i18n[key_genericError])); + mainContainer.append(htmlSnippet_errorMessage.replace('{0}', i18n[key_genericError].replace('{0}',registryApp.errorMessageURL).replace('{1}',registryApp.errorMessageDefinition))); } // Initializing the ECL Message component after creating it @@ -196,7 +196,7 @@ function renderServiceError(data) { let htmlOutput = val_emptyString; - htmlOutput += htmlSnippet_errorMessage.replace('{0}', i18n[key_errorPrefix + data.error.code]); + htmlOutput += htmlSnippet_errorMessage.replace('{0}', i18n[key_errorPrefix + data.error.code].replace('{0}',registryApp.errorMessageURL).replace('{1}',registryApp.errorMessageDefinition)); mainContainer.append(htmlOutput); From c40409a4c99c1ac73efce2fa2ff0beb40048119f Mon Sep 17 00:00:00 2001 From: unaibrrgn <75972112+unaibrrgn@users.noreply.github.com> Date: Wed, 8 Feb 2023 14:31:39 +0100 Subject: [PATCH 02/15] Added parameters to sent email --- .../web/controller/RegistryManagerUsers.java | 29 +++++++++++++++---- .../configuration.properties | 12 +++++--- .../configuration.properties.orig | 11 ++++--- .../LocalizationBundle_en.properties | 8 +++++ .../base/utility/BaseConstants.java | 3 ++ .../javaapi/handler/RegUserHandler.java | 14 ++++----- 6 files changed, 55 insertions(+), 22 deletions(-) diff --git a/sources/Re3gistry2/src/main/java/eu/europa/ec/re3gistry2/web/controller/RegistryManagerUsers.java b/sources/Re3gistry2/src/main/java/eu/europa/ec/re3gistry2/web/controller/RegistryManagerUsers.java index 9a8b46b8..84d0fb24 100644 --- a/sources/Re3gistry2/src/main/java/eu/europa/ec/re3gistry2/web/controller/RegistryManagerUsers.java +++ b/sources/Re3gistry2/src/main/java/eu/europa/ec/re3gistry2/web/controller/RegistryManagerUsers.java @@ -51,6 +51,7 @@ import java.util.HashMap; import java.util.LinkedHashSet; import java.util.List; +import java.util.ResourceBundle; import javax.mail.internet.InternetAddress; import javax.persistence.EntityManager; import javax.servlet.ServletException; @@ -82,6 +83,8 @@ private void processRequest(HttpServletRequest request, HttpServletResponse resp RegUserHandler regUserHandler = new RegUserHandler(); RegGroupManager regGroupManager = new RegGroupManager(entityManager); + //System localization + ResourceBundle systemLocalization = Configuration.getInstance().getLocalization(); // Getting form parameter String formRegUserUuid = request.getParameter(BaseConstants.KEY_FORM_FIELD_NAME_USERUUID); @@ -245,11 +248,18 @@ private void processRequest(HttpServletRequest request, HttpServletResponse resp if (!users.isEmpty()) { InternetAddress[] recipient = new InternetAddress[users.size()]; users.toArray(recipient); - String subject = "User's group has changed."; - String body = "
Dear User

The groups assigned to " + regUserDetail.getEmail() + " have changed.
"; + String subject = systemLocalization.getString(BaseConstants.KEY_EMAIL_SUBJECT_GROUPSCHANGED); + String body = ""; + body = systemLocalization.getString(BaseConstants.KEY_EMAIL_BODY_GROUPSCHANGED); + body = (body != null) + ? body.replace("{name}", regUserDetail.getEmail()) + : ""; if (!addedGroups.isEmpty()) { - body += "The user "+regUserDetail.getEmail()+" has been added to the group(s): "; + body += systemLocalization.getString(BaseConstants.KEY_EMAIL_BODY_GROUPSCHANGED_ADD); + body = (body != null) + ? body.replace("{name}", regUserDetail.getEmail()) + : ""; for (int i = 0; i < addedGroups.size(); i++) { if (i == addedGroups.size() - 1) { body += addedGroups.get(i) + ".
"; @@ -260,7 +270,10 @@ private void processRequest(HttpServletRequest request, HttpServletResponse resp } if (!removedGroups.isEmpty()) { - body += "The user "+regUserDetail.getEmail()+" has been removed from the group(s): "; + body += systemLocalization.getString(BaseConstants.KEY_EMAIL_BODY_GROUPSCHANGED_REMOVE); + body = (body != null) + ? body.replace("{name}", regUserDetail.getEmail()) + : ""; for (int y = 0; y < removedGroups.size(); y++) { if (y == removedGroups.size() - 1) { body += removedGroups.get(y) + ". "; @@ -269,9 +282,13 @@ private void processRequest(HttpServletRequest request, HttpServletResponse resp } } } - body += "

If you have any questions, please do not hesitate to contact [contact].

"; - body += "Regards."; + body += systemLocalization.getString(BaseConstants.KEY_EMAIL_BODY_GROUPSCHANGED_ENDING); + body = (body != null) + ? body.replace("{contact}", systemLocalization.getString(BaseConstants.KEY_EMAIL_BODY_GROUPSCHANGED_ENDING_CONTACT_NAME)) + .replace("{webpage}",systemLocalization.getString(BaseConstants.KEY_EMAIL_BODY_GROUPSCHANGED_ENDING_CONTACT_WEBPAGE)) + : ""; MailManager.sendMail(recipient, subject, body); + regUserHandler.closeEntityManager(); } } } diff --git a/sources/Re3gistry2/src/main/resources/configurations_files/configuration.properties b/sources/Re3gistry2/src/main/resources/configurations_files/configuration.properties index 64b9e8b3..cd7b93d9 100644 --- a/sources/Re3gistry2/src/main/resources/configurations_files/configuration.properties +++ b/sources/Re3gistry2/src/main/resources/configurations_files/configuration.properties @@ -168,10 +168,14 @@ mail.text.subject.bulkimport.error=Re3gistry - bulk import {itemclass} error mail.text.body.bulkimport.success=Dear {name},

The bulk import has been completed with success. mail.text.body.bulkimport.error=Dear {name},

The bulk import has been completed with some error(s) when importing the file.
{errors} Than retry to load the file. -mail.text.subject.groupschanged=User's group has changed -mail.text.body.groupschanged=The groups assigned to {name} have changed. -mail.text.body.groupschanged.add=User has been added to group(s): -mail.text.body.groupschanged.remove=User has been removed from the group(s): +mail.text.subject.groupschanged=User's group has changed. +mail.text.body.groupschanged=
Dear User

The groups assigned to {name} have changed.
+mail.text.body.groupschanged.add=The user {name} has been added to the group(s): +mail.text.body.groupschanged.remove=The user {name} has been removed from the group(s): +mail.text.body.groupschanged.ending=

If you have any questions, please do not hesitate to contact {contact}.

Regards. +mail.text.body.groupschanged.ending.contact=Registry software +mail.text.body.groupschanged.ending.contact.webpage=https://github.com/ec-jrc/re3gistry + ### Webapp properties #### web.application_root_url=${application.rooturl} diff --git a/sources/Re3gistry2/src/main/resources/configurations_files/configuration.properties.orig b/sources/Re3gistry2/src/main/resources/configurations_files/configuration.properties.orig index 7bddbc2d..0045347c 100644 --- a/sources/Re3gistry2/src/main/resources/configurations_files/configuration.properties.orig +++ b/sources/Re3gistry2/src/main/resources/configurations_files/configuration.properties.orig @@ -164,10 +164,13 @@ mail.text.body.error=An error has occurred during the Re3gistry installation, pl mail.text.subject.newregistration=Re3gistry - Your account have been successfully added to the system mail.text.error.newregistration=Dear {name},

Your account has been successfully created and it is now enabled.

You can access the management interface using the following credentials:
Username: {email}
Key: {key}

Please change your key after the first access.
-mail.text.subject.groupschanged=User's group has changed -mail.text.body.groupschanged=The groups assigned to {name} have changed. -mail.text.body.groupschanged.add=User has been added to group(s): -mail.text.body.groupschanged.remove=User has been removed from the group(s): +mail.text.subject.groupschanged=User's group has changed. +mail.text.body.groupschanged=
Dear User

The groups assigned to {name} have changed.
+mail.text.body.groupschanged.add=The user {name} has been added to the group(s): +mail.text.body.groupschanged.remove=The user {name} has been removed from the group(s): +mail.text.body.groupschanged.ending=

If you have any questions, please do not hesitate to contact {contact}.

Regards. +mail.text.body.groupschanged.ending.contact=Registry software +mail.text.body.groupschanged.ending.contact.webpage=https://github.com/ec-jrc/re3gistry mail.text.subject.bulkimport.success=Re3gistry - bulk import {itemclass} success mail.text.subject.bulkimport.error=Re3gistry - bulk import {itemclass} error diff --git a/sources/Re3gistry2/src/main/resources/localizations/LocalizationBundle_en.properties b/sources/Re3gistry2/src/main/resources/localizations/LocalizationBundle_en.properties index 2df722c3..8b282286 100644 --- a/sources/Re3gistry2/src/main/resources/localizations/LocalizationBundle_en.properties +++ b/sources/Re3gistry2/src/main/resources/localizations/LocalizationBundle_en.properties @@ -609,6 +609,14 @@ mail.text.subject.bulkimport.error=Re3gistry - bulk import {itemclass} error mail.text.body.bulkimport.success=Dear {name},

The bulk import has been completed with success. For more details please access the management interface.

Best regards,
INSPIRE Re3gistry Team mail.text.body.bulkimport.error=Dear {name},

The bulk import has been completed with some error(s) when importing the file. Please correct the following errors: {errors} and retry to load the file.

Best regards,
INSPIRE Re3gistry Team +mail.text.subject.groupschanged=User's group has changed. +mail.text.body.groupschanged=
Dear User

The groups assigned to {name} have changed.
+mail.text.body.groupschanged.add=The user {name} has been added to the group(s): +mail.text.body.groupschanged.remove=The user {name} has been removed from the group(s): +mail.text.body.groupschanged.ending=

If you have any questions, please do not hesitate to contact {contact}.

Regards. +mail.text.body.groupschanged.ending.contact=Registry software +mail.text.body.groupschanged.ending.contact.webpage=https://github.com/ec-jrc/re3gistry + #tooltiop add registry registry.tooltip=Target registry where the register that you are about to create will be sitting registry.path.tooltip=This option allows to include the 'registry' word for all the elements belonging to the register that you are about to create diff --git a/sources/Re3gistry2Base/src/main/java/eu/europa/ec/re3gistry2/base/utility/BaseConstants.java b/sources/Re3gistry2Base/src/main/java/eu/europa/ec/re3gistry2/base/utility/BaseConstants.java index dad80675..b89461a5 100644 --- a/sources/Re3gistry2Base/src/main/java/eu/europa/ec/re3gistry2/base/utility/BaseConstants.java +++ b/sources/Re3gistry2Base/src/main/java/eu/europa/ec/re3gistry2/base/utility/BaseConstants.java @@ -145,6 +145,9 @@ public class BaseConstants { public static final String KEY_EMAIL_BODY_GROUPSCHANGED = "mail.text.body.groupschanged"; public static final String KEY_EMAIL_BODY_GROUPSCHANGED_ADD = "mail.text.body.groupschanged.add"; public static final String KEY_EMAIL_BODY_GROUPSCHANGED_REMOVE = "mail.text.body.groupschanged.remove"; + public static final String KEY_EMAIL_BODY_GROUPSCHANGED_ENDING = "mail.text.body.groupschanged.ending"; + public static final String KEY_EMAIL_BODY_GROUPSCHANGED_ENDING_CONTACT_NAME = "mail.text.body.groupschanged.ending.contact"; + public static final String KEY_EMAIL_BODY_GROUPSCHANGED_ENDING_CONTACT_WEBPAGE = "mail.text.body.groupschanged.ending.contact.webpage"; /** * mail subject and body bulk import diff --git a/sources/Re3gistry2JavaAPI/src/main/java/eu/europa/ec/re3gistry2/javaapi/handler/RegUserHandler.java b/sources/Re3gistry2JavaAPI/src/main/java/eu/europa/ec/re3gistry2/javaapi/handler/RegUserHandler.java index 9d0a9cb4..65d283c6 100644 --- a/sources/Re3gistry2JavaAPI/src/main/java/eu/europa/ec/re3gistry2/javaapi/handler/RegUserHandler.java +++ b/sources/Re3gistry2JavaAPI/src/main/java/eu/europa/ec/re3gistry2/javaapi/handler/RegUserHandler.java @@ -146,10 +146,6 @@ public boolean removeUserFromGroup(RegUserRegGroupMapping regUserRegGroupMapping } catch (Exception e) { logger.error("@ RegUserHandler.removeUserFromGroup: generic error.", e); - } finally { -// if (entityManager != null) { -// entityManager.close(); -// } } return operationResult; } @@ -178,10 +174,6 @@ public boolean addUserFromGroup(RegUserRegGroupMapping regUserRegGroupMapping){ } catch (Exception e) { logger.error("@ RegUserHandler.addUserFromGroup: generic error.", e); - } finally { -// if (entityManager != null) { -// entityManager.close(); -// } } return operationResult; } @@ -217,4 +209,10 @@ public boolean addUser(RegUser regUser){ } return operationResult; } + + public void closeEntityManager(){ + if (entityManager != null) { + entityManager.close(); + } + } } \ No newline at end of file From be4ec72bcc28a823633f8c1a8fe76cc55d716e62 Mon Sep 17 00:00:00 2001 From: unaibrrgn <75972112+unaibrrgn@users.noreply.github.com> Date: Fri, 10 Feb 2023 14:31:39 +0100 Subject: [PATCH 03/15] Enhancements --- .../web/controller/RegistryManagerUsers.java | 18 +++++++++++++++--- .../configuration.properties | 12 ++++++------ .../configuration.properties.orig | 12 ++++++------ .../LocalizationBundle_en.properties | 10 +++++----- 4 files changed, 32 insertions(+), 20 deletions(-) diff --git a/sources/Re3gistry2/src/main/java/eu/europa/ec/re3gistry2/web/controller/RegistryManagerUsers.java b/sources/Re3gistry2/src/main/java/eu/europa/ec/re3gistry2/web/controller/RegistryManagerUsers.java index 84d0fb24..647f6cc3 100644 --- a/sources/Re3gistry2/src/main/java/eu/europa/ec/re3gistry2/web/controller/RegistryManagerUsers.java +++ b/sources/Re3gistry2/src/main/java/eu/europa/ec/re3gistry2/web/controller/RegistryManagerUsers.java @@ -48,9 +48,11 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Date; +import java.util.Enumeration; import java.util.HashMap; import java.util.LinkedHashSet; import java.util.List; +import java.util.Map; import java.util.ResourceBundle; import javax.mail.internet.InternetAddress; import javax.persistence.EntityManager; @@ -249,10 +251,15 @@ private void processRequest(HttpServletRequest request, HttpServletResponse resp InternetAddress[] recipient = new InternetAddress[users.size()]; users.toArray(recipient); String subject = systemLocalization.getString(BaseConstants.KEY_EMAIL_SUBJECT_GROUPSCHANGED); + subject = (subject != null) + ? subject.replace("{contact}",systemLocalization.getString(BaseConstants.KEY_EMAIL_BODY_GROUPSCHANGED_ENDING_CONTACT_NAME)) + : ""; + String body = ""; body = systemLocalization.getString(BaseConstants.KEY_EMAIL_BODY_GROUPSCHANGED); body = (body != null) - ? body.replace("{name}", regUserDetail.getEmail()) + ? body.replace("{user}", regUserDetail.getName()) + .replace("{id}",regUserDetail.getEmail()) : ""; if (!addedGroups.isEmpty()) { @@ -283,9 +290,14 @@ private void processRequest(HttpServletRequest request, HttpServletResponse resp } } body += systemLocalization.getString(BaseConstants.KEY_EMAIL_BODY_GROUPSCHANGED_ENDING); + + + String value = request.getHeader("host"); + value = value + "/re3gistry2/userProfile"; body = (body != null) - ? body.replace("{contact}", systemLocalization.getString(BaseConstants.KEY_EMAIL_BODY_GROUPSCHANGED_ENDING_CONTACT_NAME)) - .replace("{webpage}",systemLocalization.getString(BaseConstants.KEY_EMAIL_BODY_GROUPSCHANGED_ENDING_CONTACT_WEBPAGE)) + ? body.replace("{page}", value) + .replace("{name}", regUserDetail.getName()) + .replace("{contact}",systemLocalization.getString(BaseConstants.KEY_EMAIL_BODY_GROUPSCHANGED_ENDING_CONTACT_NAME)) : ""; MailManager.sendMail(recipient, subject, body); regUserHandler.closeEntityManager(); diff --git a/sources/Re3gistry2/src/main/resources/configurations_files/configuration.properties b/sources/Re3gistry2/src/main/resources/configurations_files/configuration.properties index cd7b93d9..26d2a5d0 100644 --- a/sources/Re3gistry2/src/main/resources/configurations_files/configuration.properties +++ b/sources/Re3gistry2/src/main/resources/configurations_files/configuration.properties @@ -154,7 +154,7 @@ mail.smtp.starttls.enable=${mail.smtp.starttls.enable} mail.user=${mail.user} mail.password=${mail.password} mail.sender=${mail.sender} -mail.template=%subject%
%subject%

%mailbody%


This email has been automatically generated, please do not reply to it. For more details please access the management interface.

Best regards,
Signature
+mail.template=
%subject%

%mailbody%


This email has been automatically generated, please do not reply to it.

mail.text.subject.success=Re3gistry - installation success mail.text.body.success=The Re3gistry software has been properly installed. You can start managing your registry content by signing in. @@ -168,11 +168,11 @@ mail.text.subject.bulkimport.error=Re3gistry - bulk import {itemclass} error mail.text.body.bulkimport.success=Dear {name},

The bulk import has been completed with success. mail.text.body.bulkimport.error=Dear {name},

The bulk import has been completed with some error(s) when importing the file.
{errors} Than retry to load the file. -mail.text.subject.groupschanged=User's group has changed. -mail.text.body.groupschanged=
Dear User

The groups assigned to {name} have changed.
-mail.text.body.groupschanged.add=The user {name} has been added to the group(s): -mail.text.body.groupschanged.remove=The user {name} has been removed from the group(s): -mail.text.body.groupschanged.ending=

If you have any questions, please do not hesitate to contact {contact}.

Regards. +mail.text.subject.groupschanged=Changes to {contact} user groups +mail.text.body.groupschanged=
Dear {user},

The group(s) associated with your user {id} have changed.
+mail.text.body.groupschanged.add=You have been added to the group(s): +mail.text.body.groupschanged.remove=You are no longer in the group(s): +mail.text.body.groupschanged.ending=

Access your user profile page details in the management interface for more information:

{name}

{contact} manager. mail.text.body.groupschanged.ending.contact=Registry software mail.text.body.groupschanged.ending.contact.webpage=https://github.com/ec-jrc/re3gistry diff --git a/sources/Re3gistry2/src/main/resources/configurations_files/configuration.properties.orig b/sources/Re3gistry2/src/main/resources/configurations_files/configuration.properties.orig index 0045347c..4322f9a8 100644 --- a/sources/Re3gistry2/src/main/resources/configurations_files/configuration.properties.orig +++ b/sources/Re3gistry2/src/main/resources/configurations_files/configuration.properties.orig @@ -155,7 +155,7 @@ mail.smtp.starttls.enable=true mail.user=name mail.password=password mail.sender=jrc-inspire-support@ec.europa.eu -mail.template=%subject%
%subject%

%mailbody%


This email has been automatically generated, please do not reply to it. For more details please access the management interface.

Best regards,
INSPIRE Re3gistry Team
+mail.template=
%subject%

%mailbody%


This email has been automatically generated, please do not reply to it.

mail.text.subject.success=Re3gistry - installation success mail.text.body.success=The Re3gistry software has been properly installed. You can start managing your registry content by signing in. @@ -164,11 +164,11 @@ mail.text.body.error=An error has occurred during the Re3gistry installation, pl mail.text.subject.newregistration=Re3gistry - Your account have been successfully added to the system mail.text.error.newregistration=Dear {name},

Your account has been successfully created and it is now enabled.

You can access the management interface using the following credentials:
Username: {email}
Key: {key}

Please change your key after the first access.
-mail.text.subject.groupschanged=User's group has changed. -mail.text.body.groupschanged=
Dear User

The groups assigned to {name} have changed.
-mail.text.body.groupschanged.add=The user {name} has been added to the group(s): -mail.text.body.groupschanged.remove=The user {name} has been removed from the group(s): -mail.text.body.groupschanged.ending=

If you have any questions, please do not hesitate to contact {contact}.

Regards. +mail.text.subject.groupschanged=Changes to {contact} user groups +mail.text.body.groupschanged=
Dear {user},

The group(s) associated with your user {id} have changed.
+mail.text.body.groupschanged.add=You have been added to the group(s): +mail.text.body.groupschanged.remove=You are no longer in the group(s): +mail.text.body.groupschanged.ending=

Access your user profile page details in the management interface for more information:

{name}

{contact} manager. mail.text.body.groupschanged.ending.contact=Registry software mail.text.body.groupschanged.ending.contact.webpage=https://github.com/ec-jrc/re3gistry diff --git a/sources/Re3gistry2/src/main/resources/localizations/LocalizationBundle_en.properties b/sources/Re3gistry2/src/main/resources/localizations/LocalizationBundle_en.properties index 8b282286..eb85f5ac 100644 --- a/sources/Re3gistry2/src/main/resources/localizations/LocalizationBundle_en.properties +++ b/sources/Re3gistry2/src/main/resources/localizations/LocalizationBundle_en.properties @@ -609,11 +609,11 @@ mail.text.subject.bulkimport.error=Re3gistry - bulk import {itemclass} error mail.text.body.bulkimport.success=Dear {name},

The bulk import has been completed with success. For more details please access the management interface.

Best regards,
INSPIRE Re3gistry Team mail.text.body.bulkimport.error=Dear {name},

The bulk import has been completed with some error(s) when importing the file. Please correct the following errors: {errors} and retry to load the file.

Best regards,
INSPIRE Re3gistry Team -mail.text.subject.groupschanged=User's group has changed. -mail.text.body.groupschanged=
Dear User

The groups assigned to {name} have changed.
-mail.text.body.groupschanged.add=The user {name} has been added to the group(s): -mail.text.body.groupschanged.remove=The user {name} has been removed from the group(s): -mail.text.body.groupschanged.ending=

If you have any questions, please do not hesitate to contact {contact}.

Regards. +mail.text.subject.groupschanged=Changes to {contact} user groups +mail.text.body.groupschanged=
Dear {user},

The group(s) associated with your user {id} have changed.
+mail.text.body.groupschanged.add=You have been added to the group(s): +mail.text.body.groupschanged.remove=You are no longer in the group(s): +mail.text.body.groupschanged.ending=

Access your user profile page details in the management interface for more information:

{name}

{contact} manager. mail.text.body.groupschanged.ending.contact=Registry software mail.text.body.groupschanged.ending.contact.webpage=https://github.com/ec-jrc/re3gistry From e17d7f8d36dc26ded25fecd3ec095847de1f7cb1 Mon Sep 17 00:00:00 2001 From: oruscalleda <116353060+oruscalleda@users.noreply.github.com> Date: Wed, 15 Feb 2023 13:42:57 +0100 Subject: [PATCH 04/15] Adding a user to the platform let them accept if he/she agrees to join --- ...egistry2_drop-and-create-and-init.sql.orig | 14 +- .../re3gistry2/web/controller/Activate.java | 109 ++++++++++++ .../controller/RegistryManagerUsersAdd.java | 67 +++++--- .../main/resources/META-INF/persistence.xml | 1 + .../configuration.properties | 1 + .../LocalizationBundle_en.properties | 5 + .../Re3gistry2/src/main/resources/shiro.ini | 2 + .../src/main/webapp/jsp/activate.jsp | 73 ++++++++ .../main/webapp/jsp/registryManagerUsers.jsp | 3 + .../src/main/webapp/jsp/userDeleted.jsp | 72 ++++++++ .../base/utility/BaseConstants.java | 7 +- .../base/utility/Configuration.java | 8 +- .../re3gistry2/base/utility/Initializer.java | 5 + .../re3gistry2/base/utility/UserCodesJob.java | 96 +++++++++++ .../re3gistry2/base/utility/WebConstants.java | 6 + .../crudinterface/IRegUserCodesManager.java | 24 +++ .../crudinterface/IRegUserManager.java | 1 + .../RegUserCodesManager.java | 145 ++++++++++++++++ .../crudimplementation/RegUserManager.java | 21 +++ .../javaapi/handler/RegUserHandler.java | 43 +++++ .../handler/RegUserRegCodesHandler.java | 96 +++++++++++ .../ec/re3gistry2/model/RegUserCodes.java | 162 ++++++++++++++++++ .../model/utility/RandomStringUtils.java | 54 ++++++ .../uuidhandlers/RegUserCodesUuidHelper.java | 22 +++ .../main/resources/META-INF/persistence.xml | 1 + 25 files changed, 1013 insertions(+), 25 deletions(-) create mode 100644 sources/Re3gistry2/src/main/java/eu/europa/ec/re3gistry2/web/controller/Activate.java create mode 100644 sources/Re3gistry2/src/main/webapp/jsp/activate.jsp create mode 100644 sources/Re3gistry2/src/main/webapp/jsp/userDeleted.jsp create mode 100644 sources/Re3gistry2Base/src/main/java/eu/europa/ec/re3gistry2/base/utility/UserCodesJob.java create mode 100644 sources/Re3gistry2CRUDinterface/src/main/java/eu/europa/ec/re3gistry2/crudinterface/IRegUserCodesManager.java create mode 100644 sources/Re3gistry2CRUDrdb/src/main/java/eu/europa/ec/re3gistry2/crudimplementation/RegUserCodesManager.java create mode 100644 sources/Re3gistry2JavaAPI/src/main/java/eu/europa/ec/re3gistry2/javaapi/handler/RegUserRegCodesHandler.java create mode 100644 sources/Re3gistry2Model/src/main/java/eu/europa/ec/re3gistry2/model/RegUserCodes.java create mode 100644 sources/Re3gistry2Model/src/main/java/eu/europa/ec/re3gistry2/model/utility/RandomStringUtils.java create mode 100644 sources/Re3gistry2Model/src/main/java/eu/europa/ec/re3gistry2/model/uuidhandlers/RegUserCodesUuidHelper.java diff --git a/dist/db-scripts/registry2_drop-and-create-and-init.sql.orig b/dist/db-scripts/registry2_drop-and-create-and-init.sql.orig index 2183ebd5..e3a58a7e 100644 --- a/dist/db-scripts/registry2_drop-and-create-and-init.sql.orig +++ b/dist/db-scripts/registry2_drop-and-create-and-init.sql.orig @@ -365,6 +365,14 @@ CREATE TABLE reg_user_reg_group_mapping editdate TIMESTAMP WITHOUT TIME ZONE ); +CREATE TABLE reg_user_codes +( + uuid VARCHAR(50) NOT NULL, + reg_user VARCHAR(50) NOT NULL, + code VARCHAR(80), + action VARCHAR(50), + insertdate TIMESTAMP WITHOUT TIME ZONE NOT NULL DEFAULT now() +); /* Create Primary Keys */ @@ -448,7 +456,9 @@ ALTER TABLE reg_user ADD CONSTRAINT PK_reg_user ALTER TABLE reg_user_reg_group_mapping ADD CONSTRAINT PK_reg_user_reg_group_mapping PRIMARY KEY (uuid); - + +ALTER TABLE reg_user_codes ADD CONSTRAINT PK_reg_user_codes + PRIMARY KEY (uuid); /* Create Uniques */ @@ -722,6 +732,8 @@ ALTER TABLE reg_user_reg_group_mapping ADD CONSTRAINT FK_reg_user_reg_group_mapp ALTER TABLE reg_user_reg_group_mapping ADD CONSTRAINT FK_reg_user_reg_group_mapping_reg_user FOREIGN KEY (reg_user) REFERENCES reg_user (uuid) ON DELETE NO ACTION ON UPDATE CASCADE; +ALTER TABLE reg_user_codes ADD CONSTRAINT FK_reg_user_code_reg_user + FOREIGN KEY (reg_user) REFERENCES reg_user (uuid) ON DELETE NO ACTION ON UPDATE CASCADE; /* Create functions and triggers */ diff --git a/sources/Re3gistry2/src/main/java/eu/europa/ec/re3gistry2/web/controller/Activate.java b/sources/Re3gistry2/src/main/java/eu/europa/ec/re3gistry2/web/controller/Activate.java new file mode 100644 index 00000000..376ca06e --- /dev/null +++ b/sources/Re3gistry2/src/main/java/eu/europa/ec/re3gistry2/web/controller/Activate.java @@ -0,0 +1,109 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template + */ +package eu.europa.ec.re3gistry2.web.controller; + +import eu.europa.ec.re3gistry2.base.utility.BaseConstants; +import eu.europa.ec.re3gistry2.base.utility.Configuration; +import eu.europa.ec.re3gistry2.base.utility.PersistenceFactory; +import eu.europa.ec.re3gistry2.base.utility.WebConstants; +import eu.europa.ec.re3gistry2.crudimplementation.RegUserCodesManager; +import eu.europa.ec.re3gistry2.crudimplementation.RegUserManager; +import eu.europa.ec.re3gistry2.crudimplementation.RegUserRegGroupMappingManager; +import eu.europa.ec.re3gistry2.javaapi.handler.RegUserHandler; +import eu.europa.ec.re3gistry2.javaapi.handler.RegUserRegCodesHandler; +import eu.europa.ec.re3gistry2.model.RegUser; +import eu.europa.ec.re3gistry2.model.RegUserCodes; +import eu.europa.ec.re3gistry2.model.RegUserRegGroupMapping; +import java.io.IOException; +import java.util.List; +import javax.persistence.EntityManager; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import org.apache.logging.log4j.Logger; + +@WebServlet(WebConstants.PAGE_URINAME_ACTIVATE) +public class Activate extends HttpServlet { + + private void processRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { + + //Init frontend servlet + //aƱadir booleano para no login? + Configuration.getInstance().initServlet(request, response, false, false); + + // Setup the entity manager + EntityManager entityManager = PersistenceFactory.getEntityManagerFactory().createEntityManager(); + + // Init logger + Logger logger = Configuration.getInstance().getLogger(); + + // Instantiating managers + RegUserCodesManager regUserCodesManager = new RegUserCodesManager(entityManager); + RegUserRegCodesHandler regUserCodesHandler = new RegUserRegCodesHandler(); + RegUserManager regUserManager = new RegUserManager(entityManager); + RegUserHandler regUserHandler = new RegUserHandler(); + + // Getting form parameter + String code = request.getParameter("code"); + + // Getting the user from the code + RegUserCodes regCode = regUserCodesManager.getByCode(code); + RegUser regUser = regUserManager.get(regCode.getRegUser()); + List regCodeAux = regUserCodesManager.getByRegUser(regCode.getRegUser()); + + if(regCode.getAction().equals(BaseConstants.KEY_USER_ACTION_ACTIVATE_USER)){ + //Enabling the user + Boolean enabled = regUserHandler.toggleUserEnabled(regUser, Boolean.TRUE); + + if(enabled){ + //Delete the codes + for(RegUserCodes r:regCodeAux){ + regUserCodesHandler.deleteCode(r); + } + request.getRequestDispatcher(WebConstants.PAGE_JSP_FOLDER + WebConstants.PAGE_PATH_ACTIVATE+ WebConstants.PAGE_URINAME_ACTIVATE + WebConstants.PAGE_JSP_EXTENSION).forward(request, response); + }else{ + //Dispatch request + request.getRequestDispatcher(WebConstants.PAGE_JSP_FOLDER + WebConstants.PAGE_PATH_REGISTRYMANAGER_USERS_ADD + WebConstants.PAGE_URINAME_REGISTRYMANAGER_USERS_ADD + WebConstants.PAGE_JSP_EXTENSION).forward(request, response); + } + }else{ + //Delete the codes + for(RegUserCodes r:regCodeAux){ + regUserCodesHandler.deleteCode(r); + } + + //Delete the user + Boolean removed = regUserHandler.removeUser(regUser); + if(removed){ + //response.sendRedirect("/help"); + request.getRequestDispatcher(WebConstants.PAGE_JSP_FOLDER + WebConstants.PAGE_PATH_DELETE_USER+ WebConstants.PAGE_URINAME_DELETE_USER + WebConstants.PAGE_JSP_EXTENSION).forward(request, response); + }else{ + //Dispatch request + request.getRequestDispatcher(WebConstants.PAGE_JSP_FOLDER + WebConstants.PAGE_PATH_REGISTRYMANAGER_USERS_ADD + WebConstants.PAGE_URINAME_REGISTRYMANAGER_USERS_ADD + WebConstants.PAGE_JSP_EXTENSION).forward(request, response); + } + } + } + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { + try { + processRequest(request, response); + } catch (Exception ex) { + Logger logger = Configuration.getInstance().getLogger(); + logger.error(ex.getMessage(), ex); + } + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { + try { + processRequest(request, response); + } catch (Exception ex) { + Logger logger = Configuration.getInstance().getLogger(); + logger.error(ex.getMessage(), ex); + } + } +} diff --git a/sources/Re3gistry2/src/main/java/eu/europa/ec/re3gistry2/web/controller/RegistryManagerUsersAdd.java b/sources/Re3gistry2/src/main/java/eu/europa/ec/re3gistry2/web/controller/RegistryManagerUsersAdd.java index 193d6237..ec77c34e 100644 --- a/sources/Re3gistry2/src/main/java/eu/europa/ec/re3gistry2/web/controller/RegistryManagerUsersAdd.java +++ b/sources/Re3gistry2/src/main/java/eu/europa/ec/re3gistry2/web/controller/RegistryManagerUsersAdd.java @@ -34,16 +34,19 @@ import eu.europa.ec.re3gistry2.crudimplementation.RegGroupManager; import eu.europa.ec.re3gistry2.crudimplementation.RegItemRegGroupRegRoleMappingManager; import eu.europa.ec.re3gistry2.crudimplementation.RegLanguagecodeManager; +import eu.europa.ec.re3gistry2.crudimplementation.RegUserCodesManager; import eu.europa.ec.re3gistry2.crudimplementation.RegUserManager; import eu.europa.ec.re3gistry2.javaapi.handler.RegUserHandler; import eu.europa.ec.re3gistry2.javaapi.handler.RegUserRegGrouprHandler; import eu.europa.ec.re3gistry2.model.RegGroup; import eu.europa.ec.re3gistry2.model.RegLanguagecode; import eu.europa.ec.re3gistry2.model.RegUser; +import eu.europa.ec.re3gistry2.model.RegUserCodes; import eu.europa.ec.re3gistry2.model.RegUserRegGroupMapping; import eu.europa.ec.re3gistry2.model.uuidhandlers.RegUserRegGroupMappingUuidHelper; import eu.europa.ec.re3gistry2.model.uuidhandlers.RegUserUuidHelper; import java.io.IOException; +import java.net.URL; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.security.SecureRandom; @@ -172,7 +175,7 @@ private void processRequest(HttpServletRequest request, HttpServletResponse resp newUser.setSsoreference(email); } newUser.setInsertdate(new Date()); - newUser.setEnabled(true); + newUser.setEnabled(false); String loginType = properties.getProperty(BaseConstants.KEY_PROPERTY_LOGIN_TYPE, BaseConstants.KEY_PROPERTY_LOGIN_TYPE_SHIRO); String key = ""; @@ -189,28 +192,46 @@ private void processRequest(HttpServletRequest request, HttpServletResponse resp /** * save group reference */ - RegGroupManager regGroupManager = new RegGroupManager(entityManager); - for (String selectedgroup : selectedgroups) { - RegUserRegGroupMapping regUserRegGroupMapping = new RegUserRegGroupMapping(); - final RegGroup group = regGroupManager.get(selectedgroup); - String newRegUserRegGroupUUID = RegUserRegGroupMappingUuidHelper.getUuid(newUser, group); - regUserRegGroupMapping.setUuid(newRegUserRegGroupUUID); - regUserRegGroupMapping.setRegUser(newUser); - regUserRegGroupMapping.setRegGroup(group); - regUserRegGroupMapping.setIsGroupadmin(Boolean.TRUE); - regUserRegGroupMapping.setInsertdate(new Date()); - - try { - if (!entityManager.getTransaction().isActive()) { - entityManager.getTransaction().begin(); + if(selectedgroups != null && selectedgroups.length > 0){ + RegGroupManager regGroupManager = new RegGroupManager(entityManager); + for (String selectedgroup : selectedgroups) { + RegUserRegGroupMapping regUserRegGroupMapping = new RegUserRegGroupMapping(); + final RegGroup group = regGroupManager.get(selectedgroup); + String newRegUserRegGroupUUID = RegUserRegGroupMappingUuidHelper.getUuid(newUser, group); + regUserRegGroupMapping.setUuid(newRegUserRegGroupUUID); + regUserRegGroupMapping.setRegUser(newUser); + regUserRegGroupMapping.setRegGroup(group); + regUserRegGroupMapping.setIsGroupadmin(Boolean.TRUE); + regUserRegGroupMapping.setInsertdate(new Date()); + + try { + if (!entityManager.getTransaction().isActive()) { + entityManager.getTransaction().begin(); + } + entityManager.persist(regUserRegGroupMapping); + entityManager.getTransaction().commit(); + } catch (Exception ec) { + logger.error("@ RegUserHandler.addUser: generic error.", e); } - entityManager.persist(regUserRegGroupMapping); - entityManager.getTransaction().commit(); - } catch (Exception ec) { - logger.error("@ RegUserHandler.addUser: generic error.", e); } } - + + //Generate activation and deletion codes + RegUserCodes codeActivation = new RegUserCodes(newUser.getUuid(),BaseConstants.KEY_USER_ACTION_ACTIVATE_USER,new Date()); + RegUserCodes codeDeletion = new RegUserCodes(newUser.getUuid(),BaseConstants.KEY_USER_ACTION_DELETE_USER,new Date()); + + try{ + if (!entityManager.getTransaction().isActive()) { + entityManager.getTransaction().begin(); + } + //Persist both codes + entityManager.persist(codeActivation); + entityManager.persist(codeDeletion); + entityManager.getTransaction().commit(); + } catch (Exception ec) { + logger.error("@ RegUserHandler.addUser: generic error.", ec); + } + // Prepare the email email to the user with the generated key String recipientString = newUser.getEmail(); InternetAddress[] recipient = { @@ -221,11 +242,17 @@ private void processRequest(HttpServletRequest request, HttpServletResponse resp String body; if (loginType.equals(BaseConstants.KEY_PROPERTY_LOGIN_TYPE_SHIRO)) { + String host = request.getHeader(BaseConstants.KEY_PROPERTY_HOST); + URL activationUrl = new URL(host.concat(WebConstants.PAGE_PATH_ACTIVATE).concat("?").concat(BaseConstants.KEY_PROPERTY_CODE).concat("="+codeActivation.getCode())); + URL deletionUrl = new URL(host.concat(WebConstants.PAGE_PATH_ACTIVATE).concat("?").concat(BaseConstants.KEY_PROPERTY_CODE).concat("="+codeDeletion.getCode())); + body = systemLocalization.getString(BaseConstants.KEY_EMAIL_BODY_NEW_REGISTRATION); body = (body != null) ? body.replace("{name}", name) .replace("{email}", email) .replace("{key}", key) + .replace("{acceptLink}",activationUrl.toString()) + .replace("{deleteLink}",deletionUrl.toString()) : ""; } else { body = systemLocalization.getString(BaseConstants.KEY_EMAIL_BODY_ECAS_NEW_REGISTRATION); diff --git a/sources/Re3gistry2/src/main/resources/META-INF/persistence.xml b/sources/Re3gistry2/src/main/resources/META-INF/persistence.xml index babfec06..1b1735e5 100644 --- a/sources/Re3gistry2/src/main/resources/META-INF/persistence.xml +++ b/sources/Re3gistry2/src/main/resources/META-INF/persistence.xml @@ -30,6 +30,7 @@ eu.europa.ec.re3gistry2.model.RegUserRegGroupMapping eu.europa.ec.re3gistry2.model.RegItemproposedRegGroupRegRoleMapping eu.europa.ec.re3gistry2.model.RegItemhistoryRegGroupRegRoleMapping + eu.europa.ec.re3gistry2.model.RegUserCodes false diff --git a/sources/Re3gistry2/src/main/resources/configurations_files/configuration.properties b/sources/Re3gistry2/src/main/resources/configurations_files/configuration.properties index c3f31637..3f0145f5 100644 --- a/sources/Re3gistry2/src/main/resources/configurations_files/configuration.properties +++ b/sources/Re3gistry2/src/main/resources/configurations_files/configuration.properties @@ -162,6 +162,7 @@ mail.text.subject.error=Re3gistry - installation error mail.text.body.error=An error has occurred during the Re3gistry installation, please review your settings. mail.text.subject.newregistration=Re3gistry - Your account have been successfully added to the system mail.text.error.newregistration=Dear {name},

Your account has been successfully created and it is now enabled.

You can access the management interface using the following credentials:
Username: {email}
Key: {key}

Please change your key after the first access.
+mail.text.option.newregistration=Dear {name},

Your account has been successfully created.

You can access the management interface using the following credentials:
Username: {email}
Key: {key}

Please change your key after the first access.
You can activate your account following this link.
If you don\u2019t want to accept this invitation please follow this link. to remove your user.
mail.text.subject.bulkimport.success=Re3gistry - bulk import {itemclass} success mail.text.subject.bulkimport.error=Re3gistry - bulk import {itemclass} error diff --git a/sources/Re3gistry2/src/main/resources/localizations/LocalizationBundle_en.properties b/sources/Re3gistry2/src/main/resources/localizations/LocalizationBundle_en.properties index 2df722c3..0a6ed78f 100644 --- a/sources/Re3gistry2/src/main/resources/localizations/LocalizationBundle_en.properties +++ b/sources/Re3gistry2/src/main/resources/localizations/LocalizationBundle_en.properties @@ -379,6 +379,11 @@ index.text.solrindexer.temporary-text=This is a temporary panel to test the Solr about.label.title=About +activate.label.title=User enabled +activate.body=Your user has been enabled! +activate.body.login=You can login pressing here. +userDeleted.body=Your account has been succesfully deleted. + help.label.title=Help status.label.title=Status diff --git a/sources/Re3gistry2/src/main/resources/shiro.ini b/sources/Re3gistry2/src/main/resources/shiro.ini index 6ddd1b26..59b195e7 100644 --- a/sources/Re3gistry2/src/main/resources/shiro.ini +++ b/sources/Re3gistry2/src/main/resources/shiro.ini @@ -78,4 +78,6 @@ securityManager.realms = $jdbcRealm /help/** = anon /login = authc /logout = logout +/activate = anon +/userDeleted = anon /** = authc diff --git a/sources/Re3gistry2/src/main/webapp/jsp/activate.jsp b/sources/Re3gistry2/src/main/webapp/jsp/activate.jsp new file mode 100644 index 00000000..3242249b --- /dev/null +++ b/sources/Re3gistry2/src/main/webapp/jsp/activate.jsp @@ -0,0 +1,73 @@ +<%-- +/* + * Copyright 2007,2016 EUROPEAN UNION + * Licensed under the EUPL, Version 1.2 or - as soon they will be approved by + * the European Commission - subsequent versions of the EUPL (the "Licence"); + * You may not use this work except in compliance with the Licence. + * You may obtain a copy of the Licence at: + * + * https://ec.europa.eu/isa2/solutions/european-union-public-licence-eupl_en + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the Licence is distributed on an "AS IS" basis, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the Licence for the specific language governing permissions and + * limitations under the Licence. + * + * Date: 2020/05/11 + * Authors: + * European Commission, Joint Research Centre - jrc-inspire-support@ec.europa.eu + * + * This work was supported by the Interoperability solutions for public + * administrations, businesses and citizens programme (http://ec.europa.eu/isa2) + * through Action 2016.10: European Location Interoperability Solutions for e-Government (ELISE) + */ +--%> +<%@page import="java.util.ResourceBundle"%> +<%@page import="java.text.MessageFormat"%> +<%@page import="eu.europa.ec.re3gistry2.base.utility.UserHelper"%> +<%@page import="eu.europa.ec.re3gistry2.crudimplementation.RegItemRegGroupRegRoleMappingManager"%> +<%@page import="eu.europa.ec.re3gistry2.model.RegGroup"%> +<%@page import="java.util.HashMap"%> +<%@page import="eu.europa.ec.re3gistry2.base.utility.BaseConstants"%> +<%@page import="javax.persistence.EntityManager"%> +<%@page import="eu.europa.ec.re3gistry2.base.utility.PersistenceFactory"%> +<%@page contentType="text/html" pageEncoding="UTF-8"%> +<%@include file="includes/common.inc.jsp" %> + + +<% // Checking if the current user has the rights to add a new itemclass + ResourceBundle localization = (ResourceBundle) request.getAttribute(BaseConstants.KEY_REQUEST_LOCALIZATION); +%> + + + <%@include file="includes/head.inc.jsp" %> + + <%@include file="includes/header.inc.jsp"%> + +
+ +
+
+

${localization.getString("activate.label.title")}

+
+
+ +
+
+ +

${localization.getString("activate.body")}

+

<%=MessageFormat.format(localization.getString("activate.body.login"), WebConstants.PAGE_URINAME_LOGIN)%>

+ +
+
+ +
+ +
+ + <%@include file="includes/footer.inc.jsp" %> + <%@include file="includes/pageend.inc.jsp" %> + + + \ No newline at end of file diff --git a/sources/Re3gistry2/src/main/webapp/jsp/registryManagerUsers.jsp b/sources/Re3gistry2/src/main/webapp/jsp/registryManagerUsers.jsp index 23285635..577e036f 100644 --- a/sources/Re3gistry2/src/main/webapp/jsp/registryManagerUsers.jsp +++ b/sources/Re3gistry2/src/main/webapp/jsp/registryManagerUsers.jsp @@ -335,6 +335,9 @@ %> +
+ +
<% } %> diff --git a/sources/Re3gistry2/src/main/webapp/jsp/userDeleted.jsp b/sources/Re3gistry2/src/main/webapp/jsp/userDeleted.jsp new file mode 100644 index 00000000..fe25d133 --- /dev/null +++ b/sources/Re3gistry2/src/main/webapp/jsp/userDeleted.jsp @@ -0,0 +1,72 @@ +<%-- +/* + * Copyright 2007,2016 EUROPEAN UNION + * Licensed under the EUPL, Version 1.2 or - as soon they will be approved by + * the European Commission - subsequent versions of the EUPL (the "Licence"); + * You may not use this work except in compliance with the Licence. + * You may obtain a copy of the Licence at: + * + * https://ec.europa.eu/isa2/solutions/european-union-public-licence-eupl_en + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the Licence is distributed on an "AS IS" basis, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the Licence for the specific language governing permissions and + * limitations under the Licence. + * + * Date: 2020/05/11 + * Authors: + * European Commission, Joint Research Centre - jrc-inspire-support@ec.europa.eu + * + * This work was supported by the Interoperability solutions for public + * administrations, businesses and citizens programme (http://ec.europa.eu/isa2) + * through Action 2016.10: European Location Interoperability Solutions for e-Government (ELISE) + */ +--%> +<%@page import="java.util.ResourceBundle"%> +<%@page import="java.text.MessageFormat"%> +<%@page import="eu.europa.ec.re3gistry2.base.utility.UserHelper"%> +<%@page import="eu.europa.ec.re3gistry2.crudimplementation.RegItemRegGroupRegRoleMappingManager"%> +<%@page import="eu.europa.ec.re3gistry2.model.RegGroup"%> +<%@page import="java.util.HashMap"%> +<%@page import="eu.europa.ec.re3gistry2.base.utility.BaseConstants"%> +<%@page import="javax.persistence.EntityManager"%> +<%@page import="eu.europa.ec.re3gistry2.base.utility.PersistenceFactory"%> +<%@page contentType="text/html" pageEncoding="UTF-8"%> +<%@include file="includes/common.inc.jsp" %> + + +<% // Checking if the current user has the rights to add a new itemclass + ResourceBundle localization = (ResourceBundle) request.getAttribute(BaseConstants.KEY_REQUEST_LOCALIZATION); +%> + + + <%@include file="includes/head.inc.jsp" %> + + <%@include file="includes/header.inc.jsp"%> + +
+ +
+
+

${localization.getString("activate.label.title")}

+
+
+ +
+
+ +

${localization.getString("userDeleted.body")}

+ +
+
+ +
+ +
+ + <%@include file="includes/footer.inc.jsp" %> + <%@include file="includes/pageend.inc.jsp" %> + + + \ No newline at end of file diff --git a/sources/Re3gistry2Base/src/main/java/eu/europa/ec/re3gistry2/base/utility/BaseConstants.java b/sources/Re3gistry2Base/src/main/java/eu/europa/ec/re3gistry2/base/utility/BaseConstants.java index d49f17e2..0de38839 100644 --- a/sources/Re3gistry2Base/src/main/java/eu/europa/ec/re3gistry2/base/utility/BaseConstants.java +++ b/sources/Re3gistry2Base/src/main/java/eu/europa/ec/re3gistry2/base/utility/BaseConstants.java @@ -94,6 +94,9 @@ public class BaseConstants { public static final String ATTRIBUTE_CACHE_KEY = "re3gistry-rest-api-cache"; public static final String ATTRIBUTE_CACHE_QUEUE_KEY = "re3gistry-rest-api-cache-queue"; + + public static final String KEY_PROPERTY_CODE = "code"; + public static final String KEY_PROPERTY_HOST = "host"; /** * Mail keys @@ -125,7 +128,7 @@ public class BaseConstants { public static final String KEY_EMAIL_SUBJECT_ERROR = "mail.text.subject.error"; public static final String KEY_EMAIL_BODY_ERROR = "mail.text.body.error"; public static final String KEY_EMAIL_SUBJECT_NEW_REGISTRATION = "mail.text.subject.newregistration"; - public static final String KEY_EMAIL_BODY_NEW_REGISTRATION = "mail.text.error.newregistration"; + public static final String KEY_EMAIL_BODY_NEW_REGISTRATION = "mail.text.option.newregistration"; public static final String KEY_EMAIL_BODY_ECAS_NEW_REGISTRATION = "mail.text.error.ecas.newregistration"; public static final String KEY_EMAIL_SUBJECT_RESETPASSWORD = "mail.text.subject.resetpassword.registration"; public static final String KEY_EMAIL_BODY_RESETPASSWORD = "mail.text.error.resetpassword.registration"; @@ -247,6 +250,8 @@ public class BaseConstants { public static final String KEY_USER_ACTION_APPROVEPROPOSAL = "ApproveProposal"; public static final String KEY_USER_ACTION_PUBLISHPROPOSAL = "PublishProposal"; public static final String KEY_USER_ACTION_MANAGESYSTEM = "ManageSystem"; + public static final String KEY_USER_ACTION_ACTIVATE_USER = "ActivateUser"; + public static final String KEY_USER_ACTION_DELETE_USER = "DeleteUser"; /* - Request keys - */ // Request parameters keys diff --git a/sources/Re3gistry2Base/src/main/java/eu/europa/ec/re3gistry2/base/utility/Configuration.java b/sources/Re3gistry2Base/src/main/java/eu/europa/ec/re3gistry2/base/utility/Configuration.java index 6964e547..d04b27f7 100644 --- a/sources/Re3gistry2Base/src/main/java/eu/europa/ec/re3gistry2/base/utility/Configuration.java +++ b/sources/Re3gistry2Base/src/main/java/eu/europa/ec/re3gistry2/base/utility/Configuration.java @@ -28,8 +28,11 @@ import eu.europa.ec.re3gistry2.model.RegUser; import java.io.*; import java.util.ArrayList; +import java.util.Enumeration; +import java.util.HashMap; import java.util.List; import java.util.Locale; +import java.util.Map; import java.util.Properties; import java.util.ResourceBundle; import javax.servlet.ServletException; @@ -218,12 +221,11 @@ public void initServlet(HttpServletRequest request, HttpServletResponse response request.setAttribute(BaseConstants.KEY_REQUEST_AVAILABLELANGUAGES, session.getAttribute(BaseConstants.KEY_SESSION_AVAILABLELANGUAGES)); } - String uri = request.getRequestURI(); + String uri = request.getRequestURL().toString(); String currentPageName = "/" + uri.substring(uri.lastIndexOf("/") + 1); request.setAttribute(BaseConstants.KEY_REQUEST_CURRENTPAGENAME, currentPageName); Configuration.getInstance().getLogger().debug("Current page name=" + currentPageName); - - + //Getting logged user RegUser regUser = (RegUser) session.getAttribute(BaseConstants.KEY_SESSION_USER); diff --git a/sources/Re3gistry2Base/src/main/java/eu/europa/ec/re3gistry2/base/utility/Initializer.java b/sources/Re3gistry2Base/src/main/java/eu/europa/ec/re3gistry2/base/utility/Initializer.java index 0085620a..4d350dd0 100644 --- a/sources/Re3gistry2Base/src/main/java/eu/europa/ec/re3gistry2/base/utility/Initializer.java +++ b/sources/Re3gistry2Base/src/main/java/eu/europa/ec/re3gistry2/base/utility/Initializer.java @@ -38,6 +38,11 @@ public void init() throws ServletException { Configuration.getInstance(); String pathHelperFiles = getServletContext().getRealPath("/" + BaseConstants.KEY_FOLDER_NAME_WEBINF); Configuration.setPathHelperFiles(pathHelperFiles + File.separator + BaseConstants.KEY_FOLDER_NAME_CLASSES + File.separator + BaseConstants.KEY_FOLDER_NAME_CONFIGURATIONS); + + //Initialize the cronJobs + UserCodesJob userCodesJob = new UserCodesJob(); + userCodesJob.deleteExpiredCodes(); + System.out.println("### The system is now initialized. Path for the helper files: " + pathHelperFiles); } catch (Exception e) { //Error during system's copnfiguration diff --git a/sources/Re3gistry2Base/src/main/java/eu/europa/ec/re3gistry2/base/utility/UserCodesJob.java b/sources/Re3gistry2Base/src/main/java/eu/europa/ec/re3gistry2/base/utility/UserCodesJob.java new file mode 100644 index 00000000..03552c18 --- /dev/null +++ b/sources/Re3gistry2Base/src/main/java/eu/europa/ec/re3gistry2/base/utility/UserCodesJob.java @@ -0,0 +1,96 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template + */ +package eu.europa.ec.re3gistry2.base.utility; + +import eu.europa.ec.re3gistry2.crudimplementation.RegUserCodesManager; +import eu.europa.ec.re3gistry2.crudimplementation.RegUserManager; +import eu.europa.ec.re3gistry2.crudimplementation.RegUserRegGroupMappingManager; +import eu.europa.ec.re3gistry2.model.RegUser; +import eu.europa.ec.re3gistry2.model.RegUserCodes; +import eu.europa.ec.re3gistry2.model.RegUserRegGroupMapping; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.util.Date; +import java.util.List; +import java.util.ResourceBundle; +import java.util.Timer; +import java.util.TimerTask; +import javax.persistence.EntityManager; +import org.apache.logging.log4j.Logger; + +public class UserCodesJob{ + + private EntityManager em; + // Init logger + Logger logger; + // System localization + ResourceBundle systemLocalization; + // Synchronization object + private static final Object sync = new Object(); + + public UserCodesJob() throws Exception{ + this.em = PersistenceFactory.getEntityManagerFactory().createEntityManager(); + this.logger = Configuration.getInstance().getLogger(); + this.systemLocalization = Configuration.getInstance().getLocalization(); + } + + public void deleteExpiredCodes(){ + TimerTask task = new TimerTask(){ + @Override + public void run() { + List expired = null; + try { + RegUserCodesManager regUserCodesManager = new RegUserCodesManager(em); + RegUserManager regUserManager = new RegUserManager(em); + Date currentDate = new Date(); + + // convert date to localdatetime + LocalDateTime localDateTime = currentDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime(); + localDateTime = localDateTime.minusDays(1); + + // convert LocalDateTime to date + Date yesterdayDate = Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant()); + + expired = regUserCodesManager.getByInsertDate(yesterdayDate); + + if(!expired.isEmpty()){ + for(RegUserCodes ruCodes : expired){ + + RegUser regUser = regUserManager.get(ruCodes.getRegUser()); + // The writing operation on the Database are synchronized + /* ## Start Synchronized ## */ + synchronized (sync) { + if (!em.getTransaction().isActive()) { + em.getTransaction().begin(); + } + regUserCodesManager.delete(ruCodes); + //First we delete all group mapping for the user + RegUserRegGroupMappingManager regUserRegGroupMappingManager = new RegUserRegGroupMappingManager(em); + List groups = regUserRegGroupMappingManager.getAll(regUser); + for(RegUserRegGroupMapping group : groups){ + regUserRegGroupMappingManager.delete(group); + } + + // Remove the user + regUserManager.delete(regUser); + } + /* ## End Synchronized ## */ + } + em.getTransaction().commit(); + } + } catch (Exception e) { + System.out.println("@ UserCodesJob.deleteExpiredCodes: generic error."+ e); + } + } + }; + + Timer timer = new Timer("deleteExpiredCodes"); + + long delay = 1000L; + //Set the period as every 5 minutes + long period = 1000L * 60L * 5L; + timer.scheduleAtFixedRate(task, delay, period); + } +} diff --git a/sources/Re3gistry2Base/src/main/java/eu/europa/ec/re3gistry2/base/utility/WebConstants.java b/sources/Re3gistry2Base/src/main/java/eu/europa/ec/re3gistry2/base/utility/WebConstants.java index fb39da51..755d18ed 100644 --- a/sources/Re3gistry2Base/src/main/java/eu/europa/ec/re3gistry2/base/utility/WebConstants.java +++ b/sources/Re3gistry2Base/src/main/java/eu/europa/ec/re3gistry2/base/utility/WebConstants.java @@ -125,7 +125,13 @@ public class WebConstants { public static final String PAGE_URINAME_ADDFIELD = "/addField"; public static final String PAGE_PATH_ADDFIELD = ""; + + public static final String PAGE_URINAME_ACTIVATE = "/activate"; + public static final String PAGE_PATH_ACTIVATE = ""; + public static final String PAGE_URINAME_DELETE_USER = "/userDeleted"; + public static final String PAGE_PATH_DELETE_USER = ""; + /** * installation steps */ diff --git a/sources/Re3gistry2CRUDinterface/src/main/java/eu/europa/ec/re3gistry2/crudinterface/IRegUserCodesManager.java b/sources/Re3gistry2CRUDinterface/src/main/java/eu/europa/ec/re3gistry2/crudinterface/IRegUserCodesManager.java new file mode 100644 index 00000000..506d1955 --- /dev/null +++ b/sources/Re3gistry2CRUDinterface/src/main/java/eu/europa/ec/re3gistry2/crudinterface/IRegUserCodesManager.java @@ -0,0 +1,24 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Interface.java to edit this template + */ +package eu.europa.ec.re3gistry2.crudinterface; + +import eu.europa.ec.re3gistry2.model.RegUserCodes; +import java.util.Date; +import java.util.List; + +/** + * + * @author oriol + */ +public interface IRegUserCodesManager { + public RegUserCodes get(String uuid) throws Exception; + public List getByRegUser(String regUser) throws Exception; + public RegUserCodes getByCode(String code) throws Exception; + public List getByInsertDate(Date date) throws Exception; + public List getAll() throws Exception; + + public boolean add(RegUserCodes regUserCode) throws Exception; + public boolean delete(RegUserCodes regUserCode) throws Exception; +} diff --git a/sources/Re3gistry2CRUDinterface/src/main/java/eu/europa/ec/re3gistry2/crudinterface/IRegUserManager.java b/sources/Re3gistry2CRUDinterface/src/main/java/eu/europa/ec/re3gistry2/crudinterface/IRegUserManager.java index 2e81d6c7..1d961489 100644 --- a/sources/Re3gistry2CRUDinterface/src/main/java/eu/europa/ec/re3gistry2/crudinterface/IRegUserManager.java +++ b/sources/Re3gistry2CRUDinterface/src/main/java/eu/europa/ec/re3gistry2/crudinterface/IRegUserManager.java @@ -33,6 +33,7 @@ public interface IRegUserManager{ public boolean add(RegUser i) throws Exception; public boolean update(RegUser i) throws Exception; + public boolean delete(RegUser i) throws Exception; public RegUser findByEmail(String email) throws Exception; diff --git a/sources/Re3gistry2CRUDrdb/src/main/java/eu/europa/ec/re3gistry2/crudimplementation/RegUserCodesManager.java b/sources/Re3gistry2CRUDrdb/src/main/java/eu/europa/ec/re3gistry2/crudimplementation/RegUserCodesManager.java new file mode 100644 index 00000000..5c7e3393 --- /dev/null +++ b/sources/Re3gistry2CRUDrdb/src/main/java/eu/europa/ec/re3gistry2/crudimplementation/RegUserCodesManager.java @@ -0,0 +1,145 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template + */ +package eu.europa.ec.re3gistry2.crudimplementation; + +import eu.europa.ec.re3gistry2.crudimplementation.constants.ErrorConstants; +import eu.europa.ec.re3gistry2.crudinterface.IRegUserCodesManager; +import eu.europa.ec.re3gistry2.model.RegUserCodes; +import java.text.MessageFormat; +import java.util.Date; +import java.util.List; +import javax.persistence.EntityManager; +import javax.persistence.Query; + +/** + * + * @author oriol + */ +public class RegUserCodesManager implements IRegUserCodesManager { + + private EntityManager em; + + public RegUserCodesManager(EntityManager em){ + this.em = em; + } + + /** + * Returns the RegUserCodes object + * + * @param uuid The uuid of the RegUserCodes + * @return RegUserCodes object with the uuid passed by parameter + * @throws Exception + */ + @Override + public RegUserCodes get(String uuid) throws Exception { + //Checking parameters + if(uuid == null){ + throw new Exception(MessageFormat.format(ErrorConstants.ERROR_MANAGER_PATTERN_NULL, "uuid")); + } + + //Preparing query + Query q = this.em.createNamedQuery("RegUserCodes.findByUuid"); + q.setParameter("uuid",uuid); + return (RegUserCodes) q.getSingleResult(); + } + + /** + * Returns all the RegUserCodes + * + * @return all the RegUserCodes + * @throws Exception + */ + @Override + public List getByRegUser(String regUser) throws Exception { + //Checking parameters + if(regUser == null){ + throw new Exception(MessageFormat.format(ErrorConstants.ERROR_MANAGER_PATTERN_NULL, "regUser")); + } + + //Preparing query + Query q = this.em.createNamedQuery("RegUserCodes.findByRegUser"); + q.setParameter("reguser",regUser); + return (List) q.getResultList(); + } + + /** + * Returns the RegUserCode by the code + * @param code the code + * @return the RegUserCode + * @throws Exception + */ + @Override + public RegUserCodes getByCode(String code) throws Exception { + //Checking parameters + if(code == null){ + throw new Exception(MessageFormat.format(ErrorConstants.ERROR_MANAGER_PATTERN_NULL, "regUser")); + } + + //Preparing query + Query q = this.em.createNamedQuery("RegUserCodes.findByCode"); + q.setParameter("code",code); + return (RegUserCodes) q.getSingleResult(); + } + + @Override + public List getAll() throws Exception { + //Preparing query + Query q = this.em.createNamedQuery("RegUserCodes.findAll"); + return (List) q.getResultList(); + } + + @Override + public boolean add(RegUserCodes regUserCode) throws Exception { + //Checking parameters + if (regUserCode == null) { + throw new Exception(MessageFormat.format(ErrorConstants.ERROR_MANAGER_PATTERN_NULL, RegUserCodes.class)); + } + + //Checking the DB managers + if (this.em == null) { + throw new Exception(ErrorConstants.ERROR_MANAGER_PERSISTENCE_LAYER_NULL); + } + + //Saving the object + this.em.persist(regUserCode); + + return true; + } + + @Override + public boolean delete(RegUserCodes regUserCode) throws Exception { + //Checking parameters + if (regUserCode == null) { + throw new Exception(MessageFormat.format(ErrorConstants.ERROR_MANAGER_PATTERN_NULL, RegUserCodes.class)); + } + + //Checking the DB managers + if (this.em == null) { + throw new Exception(ErrorConstants.ERROR_MANAGER_PERSISTENCE_LAYER_NULL); + } + + if(!em.contains(regUserCode)){ + regUserCode = em.merge(regUserCode); + } + + //Removing the object + this.em.remove(regUserCode); + + return true; + } + + @Override + public List getByInsertDate(Date date) throws Exception { + //Checking parameters + if(date == null){ + throw new Exception(MessageFormat.format(ErrorConstants.ERROR_MANAGER_PATTERN_NULL, "regUser")); + } + + //Preparing query + Query q = this.em.createNamedQuery("RegUserCodes.findByDate"); + q.setParameter("insertdate",date); + return (List) q.getResultList(); + } +} diff --git a/sources/Re3gistry2CRUDrdb/src/main/java/eu/europa/ec/re3gistry2/crudimplementation/RegUserManager.java b/sources/Re3gistry2CRUDrdb/src/main/java/eu/europa/ec/re3gistry2/crudimplementation/RegUserManager.java index 108216e1..3f71b8a4 100644 --- a/sources/Re3gistry2CRUDrdb/src/main/java/eu/europa/ec/re3gistry2/crudimplementation/RegUserManager.java +++ b/sources/Re3gistry2CRUDrdb/src/main/java/eu/europa/ec/re3gistry2/crudimplementation/RegUserManager.java @@ -143,4 +143,25 @@ public RegUser findByEmail(String email) throws Exception { return (RegUser) q.getSingleResult(); } + @Override + public boolean delete(RegUser regUser) throws Exception { + //Checking parameters + if (regUser == null) { + throw new Exception(MessageFormat.format(ErrorConstants.ERROR_MANAGER_PATTERN_NULL, RegUser.class)); + } + + //Checking the DB managers + if (this.em == null) { + throw new Exception(ErrorConstants.ERROR_MANAGER_PERSISTENCE_LAYER_NULL); + } + + if(!em.contains(regUser)){ + regUser = em.merge(regUser); + } + //Saving the object + this.em.remove(regUser); + + return true; + } + } diff --git a/sources/Re3gistry2JavaAPI/src/main/java/eu/europa/ec/re3gistry2/javaapi/handler/RegUserHandler.java b/sources/Re3gistry2JavaAPI/src/main/java/eu/europa/ec/re3gistry2/javaapi/handler/RegUserHandler.java index 0f2db269..3377d1f8 100644 --- a/sources/Re3gistry2JavaAPI/src/main/java/eu/europa/ec/re3gistry2/javaapi/handler/RegUserHandler.java +++ b/sources/Re3gistry2JavaAPI/src/main/java/eu/europa/ec/re3gistry2/javaapi/handler/RegUserHandler.java @@ -29,6 +29,7 @@ import eu.europa.ec.re3gistry2.crudimplementation.RegUserRegGroupMappingManager; import eu.europa.ec.re3gistry2.model.RegUser; import eu.europa.ec.re3gistry2.model.RegUserRegGroupMapping; +import java.util.List; import java.util.ResourceBundle; import javax.persistence.EntityManager; import org.apache.logging.log4j.Logger; @@ -217,4 +218,46 @@ public boolean addUser(RegUser regUser){ } return operationResult; } + + public boolean removeUser(RegUser regUser){ + // initializing managers + RegUserManager regUserManager = new RegUserManager(entityManager); + + boolean operationResult = false; + + try { + // The writing operation on the Database are synchronized + /* ## Start Synchronized ## */ + synchronized (sync) { + if (!entityManager.getTransaction().isActive()) { + entityManager.getTransaction().begin(); + } + //First we delete all group mapping for the user + RegUserRegGroupMappingManager regUserRegGroupMappingManager = new RegUserRegGroupMappingManager(entityManager); + List groups = regUserRegGroupMappingManager.getAll(regUser); + if(!entityManager.getTransaction().isActive()){ + entityManager.getTransaction().begin(); + } + for(RegUserRegGroupMapping group : groups){ + regUserRegGroupMappingManager.delete(group); + } + + // Remove the user + regUserManager.delete(regUser); + + operationResult = true; + + entityManager.getTransaction().commit(); + } + /* ## End Synchronized ## */ + + } catch (Exception e) { + logger.error("@ RegUserHandler.removeUser: generic error.", e); + } finally { + if (entityManager != null) { + entityManager.close(); + } + } + return operationResult; + } } \ No newline at end of file diff --git a/sources/Re3gistry2JavaAPI/src/main/java/eu/europa/ec/re3gistry2/javaapi/handler/RegUserRegCodesHandler.java b/sources/Re3gistry2JavaAPI/src/main/java/eu/europa/ec/re3gistry2/javaapi/handler/RegUserRegCodesHandler.java new file mode 100644 index 00000000..2b780c11 --- /dev/null +++ b/sources/Re3gistry2JavaAPI/src/main/java/eu/europa/ec/re3gistry2/javaapi/handler/RegUserRegCodesHandler.java @@ -0,0 +1,96 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template + */ +package eu.europa.ec.re3gistry2.javaapi.handler; + +import eu.europa.ec.re3gistry2.base.utility.Configuration; +import eu.europa.ec.re3gistry2.base.utility.PersistenceFactory; +import eu.europa.ec.re3gistry2.crudimplementation.RegUserCodesManager; +import eu.europa.ec.re3gistry2.model.RegUserCodes; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.util.Calendar; +import java.util.Date; +import java.util.List; +import java.util.ResourceBundle; +import java.util.logging.Level; +import javax.persistence.EntityManager; +import org.apache.logging.log4j.Logger; + +public class RegUserRegCodesHandler { + // Init logger + Logger logger; + + // Setup the entity manager + EntityManager entityManager; + + // System localization + ResourceBundle systemLocalization; + + // Synchronization object + private static final Object sync = new Object(); + + public RegUserRegCodesHandler () throws Exception{ + entityManager = PersistenceFactory.getEntityManagerFactory().createEntityManager(); + logger = Configuration.getInstance().getLogger(); + systemLocalization = Configuration.getInstance().getLocalization(); + } + + public boolean deleteCode(RegUserCodes regUserCodes){ + RegUserCodesManager regUserCodesManager = new RegUserCodesManager(entityManager); + + boolean operationResult = false; + + try { + // The writing operation on the Database are synchronized + /* ## Start Synchronized ## */ + synchronized(sync) { + if (!entityManager.getTransaction().isActive()) { + entityManager.getTransaction().begin(); + } + + //Remove de code + regUserCodesManager.delete(regUserCodes); + + operationResult = true; + + entityManager.getTransaction().commit(); + } + /* ## End Synchronized ## */ + } catch (Exception e){ + logger.error("@ RegUserRegCodesHandler.deleteCode: generic error.", e); + } finally{ + if (entityManager != null) { + //entityManager.close(); + } + } + return operationResult; + } + /** + * Get all codes expired + * + * @return list of the expired codes + */ + public List getExpiredCodes(){ + List codes = null; + try { + RegUserCodesManager regUserCodesManager = new RegUserCodesManager(entityManager); + Date currentDate = new Date(); + + // convert date to localdatetime + LocalDateTime localDateTime = currentDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime(); + localDateTime = localDateTime.minusDays(1); + + // convert LocalDateTime to date + Date yesterdayDate = Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant()); + + codes = regUserCodesManager.getByInsertDate(yesterdayDate); + + + } catch (Exception e) { + logger.error("@ RegUserRegCodesHandler.getExpiredCodes: generic error.", e); + } + return codes; + } +} diff --git a/sources/Re3gistry2Model/src/main/java/eu/europa/ec/re3gistry2/model/RegUserCodes.java b/sources/Re3gistry2Model/src/main/java/eu/europa/ec/re3gistry2/model/RegUserCodes.java new file mode 100644 index 00000000..ab138131 --- /dev/null +++ b/sources/Re3gistry2Model/src/main/java/eu/europa/ec/re3gistry2/model/RegUserCodes.java @@ -0,0 +1,162 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template + */ +package eu.europa.ec.re3gistry2.model; + +import eu.europa.ec.re3gistry2.model.utility.RandomStringUtils; +import eu.europa.ec.re3gistry2.model.uuidhandlers.RegUserCodesUuidHelper; +import java.io.Serializable; +import java.security.NoSuchAlgorithmException; +import java.security.Timestamp; +import java.util.Calendar; +import java.util.Date; +import java.util.logging.Logger; +import javax.persistence.Basic; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import javax.xml.bind.annotation.XmlRootElement; + +/** + * + * @author oriol + */ +@Entity +@Table(name = "reg_user_codes") +@XmlRootElement +@NamedQueries({ + @NamedQuery(name = "RegUserCodes.findAll", query = "SELECT r from RegUserCodes r"), + @NamedQuery(name = "RegUserCodes.findByUuid", query = "SELECT r from RegUserCodes r WHERE r.uuid = :uuid"), + @NamedQuery(name = "RegUserCodes.findByRegUser", query = "SELECT r from RegUserCodes r WHERE r.regUser = :reguser"), + @NamedQuery(name = "RegUserCodes.findByCode", query = "SELECT r from RegUserCodes r WHERE r.code = :code"), + @NamedQuery(name = "RegUserCodes.findByDate", query = "SELECT r from RegUserCodes r WHERE r.insertdate >= :insertdate") +}) +public class RegUserCodes implements Serializable { + private static final long serialVersionUID = 1L; + + private static final int EXPIRATION = 60 * 24; + + @Id + @Basic(optional = false) + @NotNull + @Size(min = 1, max = 50) + @Column(name = "uuid") + private String uuid; + + @Basic(optional = false) + @NotNull + @Size(min = 1, max = 50) + @Column(name = "reg_user") + private String regUser; + + @Basic(optional = false) + @NotNull + @Size(min = 1, max = 50) + @Column(name = "code") + private String code; + + @Basic(optional = false) + @NotNull + @Size(min = 1, max = 50) + @Column(name = "action") + private String action; + + @Basic(optional = false) + @NotNull + @Column(name = "insertdate") + @Temporal(TemporalType.TIMESTAMP) + private Date insertdate; + + /*private Date expiryDate; + + private Date calculateExpiryDate(int expiryTimeInMinutes) { + Calendar cal = Calendar.getInstance(); + cal.setTime(new Timestamp(cal.getTime().getTime())); + cal.add(Calendar.MINUTE, expiryTimeInMinutes); + return new Date(cal.getTime().getTime()); + }*/ + + public RegUserCodes(){ + } + + public RegUserCodes(String uuid, String regUser, String code, String action, Date insertdate)throws NoSuchAlgorithmException{ + this.uuid = uuid; + this.regUser = regUser; + this.code = RandomStringUtils.encodeString(50,regUser); + this.action = action; + this.insertdate = insertdate; + } + + public RegUserCodes(String uuid, String regUser, String action, Date insertdate) throws NoSuchAlgorithmException{ + this.uuid = uuid; + this.regUser = regUser; + this.code = RandomStringUtils.encodeString(50,regUser); + this.action = action; + this.insertdate = insertdate; + } + + public RegUserCodes(String regUser, String action, Date insertdate) throws NoSuchAlgorithmException, Exception{ + this.uuid = RegUserCodesUuidHelper.getUuid(regUser, action); + this.regUser = regUser; + this.code = RandomStringUtils.encodeString(50,action+regUser); + this.action = action; + this.insertdate = insertdate; + } + + public static long getSerialVersionUID() { + return serialVersionUID; + } + + public String getUuid() { + return uuid; + } + + public String getRegUser() { + return regUser; + } + + public String getCode() { + return code; + } + + public String getAction() { + return action; + } + + public Date getInsertdate() { + return insertdate; + } + + @Override + public int hashCode() { + int hash = 0; + hash += (uuid != null ? uuid.hashCode() : 0); + return hash; + } + + @Override + public boolean equals(Object object) { + + if (!(object instanceof RegUser)) { + return false; + } + RegUserCodes other = (RegUserCodes) object; + if ((this.uuid == null && other.uuid != null) || (this.uuid != null && !this.uuid.equals(other.uuid))) { + return false; + } + return true; + } + + @Override + public String toString() { + return "eu.europa.ec.re3gistry2.model.RegUserCodes[ uuid=" + uuid + " ]"; + } +} diff --git a/sources/Re3gistry2Model/src/main/java/eu/europa/ec/re3gistry2/model/utility/RandomStringUtils.java b/sources/Re3gistry2Model/src/main/java/eu/europa/ec/re3gistry2/model/utility/RandomStringUtils.java new file mode 100644 index 00000000..9c8c715b --- /dev/null +++ b/sources/Re3gistry2Model/src/main/java/eu/europa/ec/re3gistry2/model/utility/RandomStringUtils.java @@ -0,0 +1,54 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template + */ +package eu.europa.ec.re3gistry2.model.utility; + +import java.nio.charset.StandardCharsets; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + +/** + * + * @author oriol + */ +public class RandomStringUtils { + + /** + * A method to generate encoded Strings + * + * @param size The size + * @param param + * @return + * @throws NoSuchAlgorithmException + */ + public static String encodeString(int size, String param) throws NoSuchAlgorithmException { + MessageDigest digest = MessageDigest.getInstance("SHA-256"); + byte[] encodedhash = digest.digest(param.trim().getBytes(StandardCharsets.UTF_8)); + + return bytesToHex(encodedhash,size); + } + + /** + * Translates bytes into Hexadecimal + * + * @param hash the hash to translate + * @return the translated String + */ + private static String bytesToHex(byte[] hash,int size) { + StringBuilder hexString = new StringBuilder(2 * hash.length); + for (int i = 0; i < hash.length; i++) { + String hex = Integer.toHexString(0xff & hash[i]); + if (hex.length() == 1) { + hexString.append('0'); + } + hexString.append(hex); + } + if(hexString.length() > size){ + return hexString.toString().substring(0, size-1); + }else{ + return hexString.toString(); + } + + } +} diff --git a/sources/Re3gistry2Model/src/main/java/eu/europa/ec/re3gistry2/model/uuidhandlers/RegUserCodesUuidHelper.java b/sources/Re3gistry2Model/src/main/java/eu/europa/ec/re3gistry2/model/uuidhandlers/RegUserCodesUuidHelper.java new file mode 100644 index 00000000..c0db9e10 --- /dev/null +++ b/sources/Re3gistry2Model/src/main/java/eu/europa/ec/re3gistry2/model/uuidhandlers/RegUserCodesUuidHelper.java @@ -0,0 +1,22 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template + */ +package eu.europa.ec.re3gistry2.model.uuidhandlers; + +import eu.europa.ec.re3gistry2.model.RegUserCodes; +import eu.europa.ec.re3gistry2.model.utility.UuidHelper; + +/** + * + * @author oriol + */ +public class RegUserCodesUuidHelper { + private RegUserCodesUuidHelper(){ + } + + public static String getUuid(String user, String action) throws Exception{ + + return UuidHelper.createUuid(action+user, RegUserCodes.class); + } +} diff --git a/sources/Re3gistry2RestAPI/src/main/resources/META-INF/persistence.xml b/sources/Re3gistry2RestAPI/src/main/resources/META-INF/persistence.xml index babfec06..1b1735e5 100644 --- a/sources/Re3gistry2RestAPI/src/main/resources/META-INF/persistence.xml +++ b/sources/Re3gistry2RestAPI/src/main/resources/META-INF/persistence.xml @@ -30,6 +30,7 @@ eu.europa.ec.re3gistry2.model.RegUserRegGroupMapping eu.europa.ec.re3gistry2.model.RegItemproposedRegGroupRegRoleMapping eu.europa.ec.re3gistry2.model.RegItemhistoryRegGroupRegRoleMapping + eu.europa.ec.re3gistry2.model.RegUserCodes false From b21b596ffc456c491d6f3f9803fff33f2419b121 Mon Sep 17 00:00:00 2001 From: oruscalleda <116353060+oruscalleda@users.noreply.github.com> Date: Wed, 22 Feb 2023 12:58:42 +0100 Subject: [PATCH 05/15] Fix configuration files --- dist/webapp/httpd-vhosts.conf | 131 +++++ dist/webapp/httpd.conf | 551 ++++++++++++++++++ .../docker-compose.yml | 99 ++++ sources/Re3gistry2-build-helper/pom.xml | 37 +- 4 files changed, 817 insertions(+), 1 deletion(-) create mode 100644 dist/webapp/httpd-vhosts.conf create mode 100644 dist/webapp/httpd.conf create mode 100644 sources/Re3gistry2-build-helper/docker-compose.yml diff --git a/dist/webapp/httpd-vhosts.conf b/dist/webapp/httpd-vhosts.conf new file mode 100644 index 00000000..4f3d779b --- /dev/null +++ b/dist/webapp/httpd-vhosts.conf @@ -0,0 +1,131 @@ + + + AllowOverride All + Options -Indexes -FollowSymLinks + Require all granted + +ServerName host.docker.internal + +ErrorLog /var/log/re3gistry-int_error_log +CustomLog /var/log/re3gistry-int_access_log combined + +#### Basic configuration ### +# +#Alias /registry /var/www/registry +#Alias /registry/release-note.xml /var/www/host.docker.internal/public_html/release-note.xml +Alias /registry /var/www/host.docker.internal/public_html + +DirectoryIndex index.html + +DocumentRoot /var/www/host.docker.internal/public_html +#DocumentRoot /var/www/empty + +ProxyPreserveHost Off + +## SSLProxyEngine on +# SSLProxyEngine On +# SSLProxyCheckPeerCN on +# SSLProxyCheckPeerExpire on + +## Proxy to expose the Re2gistry 2 management interface +ProxyPass /re3gistry2 http://host.docker.internal:8080/re3gistry2 +ProxyPassReverse /re3gistry2 http://host.docker.internal:8080/re3gistry2 + +## Proxy to expose the Re2gistry 2 rest API +ProxyPass /registry/rest http://host.docker.internal:8080/re3gistry2restapi/items/any Keepalive=On +ProxyPassReverse /registry/rest http://host.docker.internal:8080/re3gistry2restapi/items/any Keepalive=On + +## Proxypass to expose the Re3gistry 2 Solr instance (select) +ProxyPass /registry/searchapi http://host.docker.internal:8983/solr/re3gistry/select Keepalive=On +ProxyPassReverse /registry/searchapi http://host.docker.internal:8983/solr/re3gistry/select Keepalive=On + +### Rewrite rules ### +RewriteEngine on +loglevel debug rewrite:trace3 + +## Handling direct request to a file +RewriteCond %{REQUEST_URI} !^/registry/js-ecl-v2 +RewriteRule ^/(.*)/(.*)\.([a-z]{2})\.(jsonc|json|xml|atom|csv|rdf|iso19135xml|ror)$ %{REQUEST_SCHEME}://%{HTTP_HOST}/registry/rest?lang=$3&uri=http://%{HTTP_HOST}/$1&format=$4 [P,L] + +#Handling dynamic XSD +RewriteCond %{REQUEST_URI} ^/registry/schemas/2.0 +RewriteRule ^/registry/schemas/2.0/(.*)\.xsd$ %{REQUEST_SCHEME}://%{HTTP_HOST}/registry/rest?itemclass=$1&format=xsd [P,L] + + +## Handling content negotiation: json +RewriteCond %{REQUEST_URI} !^/registry/rest +RewriteCond %{HTTP_ACCEPT} ^application/json$ +RewriteCond %{HTTP:Accept-Language} ([a-z]{2}) [OR] +RewriteCond %{HTTP:Accept-Language} ^()$ +RewriteRule ^/(.*) %{REQUEST_SCHEME}://%{HTTP_HOST}/registry/rest?lang=%1&uri=http://%{HTTP_HOST}/$1&format=json [P,L] + +## Handling content negotiation: iso19135xml +RewriteCond %{REQUEST_URI} !^/registry/rest +RewriteCond %{HTTP_ACCEPT} ^application/x-iso19135+xml$ +RewriteCond %{HTTP:Accept-Language} ([a-z]{2}) [OR] +RewriteCond %{HTTP:Accept-Language} ^()$ +RewriteRule ^/(.*) %{REQUEST_SCHEME}://%{HTTP_HOST}/registry/rest?lang=%1&uri=http://%{HTTP_HOST}/$1&format=iso19135xml [P,L] + +## Handling content negotiation: re3gistry xml +RewriteCond %{REQUEST_URI} !^/registry/rest +RewriteCond %{HTTP_ACCEPT} ^application/xml$ +RewriteCond %{HTTP:Accept-Language} ([a-z]{2}) [OR] +RewriteCond %{HTTP:Accept-Language} ^()$ +RewriteRule ^/(.*) %{REQUEST_SCHEME}://%{HTTP_HOST}/registry/rest?lang=%1&uri=http://%{HTTP_HOST}/$1&format=xml [P,L] + +## Handling content negotiation: atom +RewriteCond %{REQUEST_URI} !^/registry/rest +RewriteCond %{HTTP_ACCEPT} ^application/atom+xml$ +RewriteCond %{HTTP:Accept-Language} ([a-z]{2}) [OR] +RewriteCond %{HTTP:Accept-Language} ^()$ +RewriteRule ^/(.*) %{REQUEST_SCHEME}://%{HTTP_HOST}/registry/rest?lang=%1&uri=http://%{HTTP_HOST}/$1&format=atom [P,L] + +## Handling content negotiation: atom +RewriteCond %{REQUEST_URI} !^/registry/rest +RewriteCond %{HTTP_ACCEPT} ^application/rdf+xml$ +RewriteCond %{HTTP:Accept-Language} ([a-z]{2}) [OR] +RewriteCond %{HTTP:Accept-Language} ^()$ +RewriteRule ^/(.*) %{REQUEST_SCHEME}://%{HTTP_HOST}/registry/rest?lang=%1&uri=http://%{HTTP_HOST}/$1&format=rdf [P,L] + +## Handling content negotiation: atom +RewriteCond %{REQUEST_URI} !^/registry/rest +RewriteCond %{HTTP_ACCEPT} ^text/csv$ +RewriteCond %{HTTP:Accept-Language} ([a-z]{2}) [OR] +RewriteCond %{HTTP:Accept-Language} ^()$ +RewriteRule ^/(.*) %{REQUEST_SCHEME}://%{HTTP_HOST}/registry/rest?lang=%1&uri=http://%{HTTP_HOST}/$1&format=csv [P,L] + +#Handling ROR format without specific language (defaults to ENG) + +RewriteRule ^/(.*)/((.*)\.(ror))$ %{REQUEST_SCHEME}://%{HTTP_HOST}/registry/rest?uri=http://%{HTTP_HOST}/$1&lang=en&format=ror [P,NE,L] + +## Generic request to the registry +RewriteCond %{REQUEST_URI} !^/cache-all-reg +RewriteCond %{REQUEST_URI} !^/re3gistry +RewriteCond %{REQUEST_URI} !^/registry/searchapi +RewriteCond %{REQUEST_URI} !^/registry/search +RewriteCond %{REQUEST_URI} !^/registry/rest +RewriteCond %{REQUEST_URI} !^/registry/index\.html +RewriteCond %{REQUEST_URI} !^/registry/about\.html +RewriteCond %{REQUEST_URI} !^/registry/api\.html +RewriteCond %{REQUEST_URI} !^/registry/release-note\.xml +RewriteCond %{REQUEST_URI} !^/registry/js-ecl-v2 +RewriteCond %{REQUEST_URI} !^/registry/ecl-v2 +RewriteCond %{REQUEST_URI} !^/registry/css +RewriteCond %{REQUEST_URI} !^/registry/conf +RewriteCond %{REQUEST_URI} !^/registry/libs +RewriteCond %{REQUEST_URI} !index\.html$ +RewriteCond %{REQUEST_URI} !\.json$ +RewriteRule ^/(.*) /index.html [L] + + +## Handling search requests +RewriteCond %{REQUEST_URI} !^/registry/searchapi +RewriteRule ^/registry/search(.*) /search.html$1 [L] + + + Header set Cache-Control "no-cache, no-store, must-revalidate, s-max-age=1" + Header set Pragma "no-cache" + Header set Expires "Sat, 1 Jan 2000 00:00:00 GMT" + + + diff --git a/dist/webapp/httpd.conf b/dist/webapp/httpd.conf new file mode 100644 index 00000000..20b3d625 --- /dev/null +++ b/dist/webapp/httpd.conf @@ -0,0 +1,551 @@ +# +# This is the main Apache HTTP server configuration file. It contains the +# configuration directives that give the server its instructions. +# See for detailed information. +# In particular, see +# +# for a discussion of each configuration directive. +# +# Do NOT simply read the instructions in here without understanding +# what they do. They're here only as hints or reminders. If you are unsure +# consult the online docs. You have been warned. +# +# Configuration and logfile names: If the filenames you specify for many +# of the server's control files begin with "/" (or "drive:/" for Win32), the +# server will use that explicit path. If the filenames do *not* begin +# with "/", the value of ServerRoot is prepended -- so "logs/access_log" +# with ServerRoot set to "/usr/local/apache2" will be interpreted by the +# server as "/usr/local/apache2/logs/access_log", whereas "/logs/access_log" +# will be interpreted as '/logs/access_log'. + +# +# ServerRoot: The top of the directory tree under which the server's +# configuration, error, and log files are kept. +# +# Do not add a slash at the end of the directory path. If you point +# ServerRoot at a non-local disk, be sure to specify a local disk on the +# Mutex directive, if file-based mutexes are used. If you wish to share the +# same ServerRoot for multiple httpd daemons, you will need to change at +# least PidFile. +# +ServerRoot "/usr/local/apache2" + +# +# Mutex: Allows you to set the mutex mechanism and mutex file directory +# for individual mutexes, or change the global defaults +# +# Uncomment and change the directory if mutexes are file-based and the default +# mutex file directory is not on a local disk or is not appropriate for some +# other reason. +# +# Mutex default:logs + +# +# Listen: Allows you to bind Apache to specific IP addresses and/or +# ports, instead of the default. See also the +# directive. +# +# Change this to Listen on specific IP addresses as shown below to +# prevent Apache from glomming onto all bound IP addresses. +# +#Listen 12.34.56.78:80 +Listen 80 + +# +# Dynamic Shared Object (DSO) Support +# +# To be able to use the functionality of a module which was built as a DSO you +# have to place corresponding `LoadModule' lines at this location so the +# directives contained in it are actually available _before_ they are used. +# Statically compiled modules (those listed by `httpd -l') do not need +# to be loaded here. +# +# Example: +# LoadModule foo_module modules/mod_foo.so +# +LoadModule mpm_event_module modules/mod_mpm_event.so +#LoadModule mpm_prefork_module modules/mod_mpm_prefork.so +#LoadModule mpm_worker_module modules/mod_mpm_worker.so +LoadModule authn_file_module modules/mod_authn_file.so +#LoadModule authn_dbm_module modules/mod_authn_dbm.so +#LoadModule authn_anon_module modules/mod_authn_anon.so +#LoadModule authn_dbd_module modules/mod_authn_dbd.so +#LoadModule authn_socache_module modules/mod_authn_socache.so +LoadModule authn_core_module modules/mod_authn_core.so +LoadModule authz_host_module modules/mod_authz_host.so +LoadModule authz_groupfile_module modules/mod_authz_groupfile.so +LoadModule authz_user_module modules/mod_authz_user.so +#LoadModule authz_dbm_module modules/mod_authz_dbm.so +#LoadModule authz_owner_module modules/mod_authz_owner.so +#LoadModule authz_dbd_module modules/mod_authz_dbd.so +LoadModule authz_core_module modules/mod_authz_core.so +#LoadModule authnz_ldap_module modules/mod_authnz_ldap.so +#LoadModule authnz_fcgi_module modules/mod_authnz_fcgi.so +LoadModule access_compat_module modules/mod_access_compat.so +LoadModule auth_basic_module modules/mod_auth_basic.so +#LoadModule auth_form_module modules/mod_auth_form.so +#LoadModule auth_digest_module modules/mod_auth_digest.so +#LoadModule allowmethods_module modules/mod_allowmethods.so +#LoadModule isapi_module modules/mod_isapi.so +#LoadModule file_cache_module modules/mod_file_cache.so +#LoadModule cache_module modules/mod_cache.so +#LoadModule cache_disk_module modules/mod_cache_disk.so +#LoadModule cache_socache_module modules/mod_cache_socache.so +LoadModule socache_shmcb_module modules/mod_socache_shmcb.so +#LoadModule socache_dbm_module modules/mod_socache_dbm.so +#LoadModule socache_memcache_module modules/mod_socache_memcache.so +#LoadModule socache_redis_module modules/mod_socache_redis.so +#LoadModule watchdog_module modules/mod_watchdog.so +#LoadModule macro_module modules/mod_macro.so +#LoadModule dbd_module modules/mod_dbd.so +#LoadModule bucketeer_module modules/mod_bucketeer.so +#LoadModule dumpio_module modules/mod_dumpio.so +#LoadModule echo_module modules/mod_echo.so +#LoadModule example_hooks_module modules/mod_example_hooks.so +#LoadModule case_filter_module modules/mod_case_filter.so +#LoadModule case_filter_in_module modules/mod_case_filter_in.so +#LoadModule example_ipc_module modules/mod_example_ipc.so +#LoadModule buffer_module modules/mod_buffer.so +#LoadModule data_module modules/mod_data.so +#LoadModule ratelimit_module modules/mod_ratelimit.so +LoadModule reqtimeout_module modules/mod_reqtimeout.so +#LoadModule ext_filter_module modules/mod_ext_filter.so +#LoadModule request_module modules/mod_request.so +#LoadModule include_module modules/mod_include.so +LoadModule filter_module modules/mod_filter.so +#LoadModule reflector_module modules/mod_reflector.so +#LoadModule substitute_module modules/mod_substitute.so +#LoadModule sed_module modules/mod_sed.so +#LoadModule charset_lite_module modules/mod_charset_lite.so +#LoadModule deflate_module modules/mod_deflate.so +LoadModule xml2enc_module modules/mod_xml2enc.so +LoadModule proxy_html_module modules/mod_proxy_html.so +#LoadModule brotli_module modules/mod_brotli.so +LoadModule mime_module modules/mod_mime.so +#LoadModule ldap_module modules/mod_ldap.so +LoadModule log_config_module modules/mod_log_config.so +#LoadModule log_debug_module modules/mod_log_debug.so +#LoadModule log_forensic_module modules/mod_log_forensic.so +#LoadModule logio_module modules/mod_logio.so +#LoadModule lua_module modules/mod_lua.so +LoadModule env_module modules/mod_env.so +#LoadModule mime_magic_module modules/mod_mime_magic.so +#LoadModule cern_meta_module modules/mod_cern_meta.so +#LoadModule expires_module modules/mod_expires.so +LoadModule headers_module modules/mod_headers.so +#LoadModule ident_module modules/mod_ident.so +#LoadModule usertrack_module modules/mod_usertrack.so +#LoadModule unique_id_module modules/mod_unique_id.so +LoadModule setenvif_module modules/mod_setenvif.so +LoadModule version_module modules/mod_version.so +#LoadModule remoteip_module modules/mod_remoteip.so +LoadModule proxy_module modules/mod_proxy.so +#LoadModule proxy_connect_module modules/mod_proxy_connect.so +#LoadModule proxy_ftp_module modules/mod_proxy_ftp.so +LoadModule proxy_http_module modules/mod_proxy_http.so +#LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so +#LoadModule proxy_scgi_module modules/mod_proxy_scgi.so +#LoadModule proxy_uwsgi_module modules/mod_proxy_uwsgi.so +#LoadModule proxy_fdpass_module modules/mod_proxy_fdpass.so +#LoadModule proxy_wstunnel_module modules/mod_proxy_wstunnel.so +#LoadModule proxy_ajp_module modules/mod_proxy_ajp.so +#LoadModule proxy_balancer_module modules/mod_proxy_balancer.so +#LoadModule proxy_express_module modules/mod_proxy_express.so +#LoadModule proxy_hcheck_module modules/mod_proxy_hcheck.so +#LoadModule session_module modules/mod_session.so +#LoadModule session_cookie_module modules/mod_session_cookie.so +#LoadModule session_crypto_module modules/mod_session_crypto.so +#LoadModule session_dbd_module modules/mod_session_dbd.so +#LoadModule slotmem_shm_module modules/mod_slotmem_shm.so +#LoadModule slotmem_plain_module modules/mod_slotmem_plain.so +#LoadModule ssl_module modules/mod_ssl.so +#LoadModule optional_hook_export_module modules/mod_optional_hook_export.so +#LoadModule optional_hook_import_module modules/mod_optional_hook_import.so +#LoadModule optional_fn_import_module modules/mod_optional_fn_import.so +#LoadModule optional_fn_export_module modules/mod_optional_fn_export.so +#LoadModule dialup_module modules/mod_dialup.so +#LoadModule http2_module modules/mod_http2.so +#LoadModule proxy_http2_module modules/mod_proxy_http2.so +#LoadModule md_module modules/mod_md.so +#LoadModule lbmethod_byrequests_module modules/mod_lbmethod_byrequests.so +#LoadModule lbmethod_bytraffic_module modules/mod_lbmethod_bytraffic.so +#LoadModule lbmethod_bybusyness_module modules/mod_lbmethod_bybusyness.so +#LoadModule lbmethod_heartbeat_module modules/mod_lbmethod_heartbeat.so +LoadModule unixd_module modules/mod_unixd.so +#LoadModule heartbeat_module modules/mod_heartbeat.so +#LoadModule heartmonitor_module modules/mod_heartmonitor.so +#LoadModule dav_module modules/mod_dav.so +LoadModule status_module modules/mod_status.so +LoadModule autoindex_module modules/mod_autoindex.so +#LoadModule asis_module modules/mod_asis.so +#LoadModule info_module modules/mod_info.so +#LoadModule suexec_module modules/mod_suexec.so + + #LoadModule cgid_module modules/mod_cgid.so + + + #LoadModule cgi_module modules/mod_cgi.so + +#LoadModule dav_fs_module modules/mod_dav_fs.so +#LoadModule dav_lock_module modules/mod_dav_lock.so +#LoadModule vhost_alias_module modules/mod_vhost_alias.so +#LoadModule negotiation_module modules/mod_negotiation.so +LoadModule dir_module modules/mod_dir.so +#LoadModule imagemap_module modules/mod_imagemap.so +#LoadModule actions_module modules/mod_actions.so +#LoadModule speling_module modules/mod_speling.so +#LoadModule userdir_module modules/mod_userdir.so +LoadModule alias_module modules/mod_alias.so +LoadModule rewrite_module modules/mod_rewrite.so + + +# +# If you wish httpd to run as a different user or group, you must run +# httpd as root initially and it will switch. +# +# User/Group: The name (or #number) of the user/group to run httpd as. +# It is usually good practice to create a dedicated user and group for +# running httpd, as with most system services. +# +User www-data +Group www-data + + + +# 'Main' server configuration +# +# The directives in this section set up the values used by the 'main' +# server, which responds to any requests that aren't handled by a +# definition. These values also provide defaults for +# any containers you may define later in the file. +# +# All of these directives may appear inside containers, +# in which case these default settings will be overridden for the +# virtual host being defined. +# + +# +# ServerAdmin: Your address, where problems with the server should be +# e-mailed. This address appears on some server-generated pages, such +# as error documents. e.g. admin@your-domain.com +# +ServerAdmin you@example.com + +# +# ServerName gives the name and port that the server uses to identify itself. +# This can often be determined automatically, but we recommend you specify +# it explicitly to prevent problems during startup. +# +# If your host doesn't have a registered DNS name, enter its IP address here. +# +#ServerName www.example.com:80 +ServerName host.docker.internal + +# +# Deny access to the entirety of your server's filesystem. You must +# explicitly permit access to web content directories in other +# blocks below. +# + + AllowOverride none + Require all granted + + +# +# Note that from this point forward you must specifically allow +# particular features to be enabled - so if something's not working as +# you might expect, make sure that you have specifically enabled it +# below. +# + +# +# DocumentRoot: The directory out of which you will serve your +# documents. By default, all requests are taken from this directory, but +# symbolic links and aliases may be used to point to other locations. +# +DocumentRoot "/usr/local/apache2/htdocs" + + # + # Possible values for the Options directive are "None", "All", + # or any combination of: + # Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews + # + # Note that "MultiViews" must be named *explicitly* --- "Options All" + # doesn't give it to you. + # + # The Options directive is both complicated and important. Please see + # http://httpd.apache.org/docs/2.4/mod/core.html#options + # for more information. + # + Options Indexes FollowSymLinks + + # + # AllowOverride controls what directives may be placed in .htaccess files. + # It can be "All", "None", or any combination of the keywords: + # AllowOverride FileInfo AuthConfig Limit + # + AllowOverride None + + # + # Controls who can get stuff from this server. + # + Require all granted + + +# +# DirectoryIndex: sets the file that Apache will serve if a directory +# is requested. +# + + DirectoryIndex index.html + + +# +# The following lines prevent .htaccess and .htpasswd files from being +# viewed by Web clients. +# + + Require all denied + + +# +# ErrorLog: The location of the error log file. +# If you do not specify an ErrorLog directive within a +# container, error messages relating to that virtual host will be +# logged here. If you *do* define an error logfile for a +# container, that host's errors will be logged there and not here. +# +ErrorLog /proc/self/fd/2 + +# +# LogLevel: Control the number of messages logged to the error_log. +# Possible values include: debug, info, notice, warn, error, crit, +# alert, emerg. +# +LogLevel warn + + + # + # The following directives define some format nicknames for use with + # a CustomLog directive (see below). + # + LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined + LogFormat "%h %l %u %t \"%r\" %>s %b" common + + + # You need to enable mod_logio.c to use %I and %O + LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio + + + # + # The location and format of the access logfile (Common Logfile Format). + # If you do not define any access logfiles within a + # container, they will be logged here. Contrariwise, if you *do* + # define per- access logfiles, transactions will be + # logged therein and *not* in this file. + # + CustomLog /proc/self/fd/1 common + + # + # If you prefer a logfile with access, agent, and referer information + # (Combined Logfile Format) you can use the following directive. + # + #CustomLog "logs/access_log" combined + + + + # + # Redirect: Allows you to tell clients about documents that used to + # exist in your server's namespace, but do not anymore. The client + # will make a new request for the document at its new location. + # Example: + # Redirect permanent /foo http://www.example.com/bar + + # + # Alias: Maps web paths into filesystem paths and is used to + # access content that does not live under the DocumentRoot. + # Example: + # Alias /webpath /full/filesystem/path + # + # If you include a trailing / on /webpath then the server will + # require it to be present in the URL. You will also likely + # need to provide a section to allow access to + # the filesystem path. + + # + # ScriptAlias: This controls which directories contain server scripts. + # ScriptAliases are essentially the same as Aliases, except that + # documents in the target directory are treated as applications and + # run by the server when requested rather than as documents sent to the + # client. The same rules about trailing "/" apply to ScriptAlias + # directives as to Alias. + # + ScriptAlias /cgi-bin/ "/usr/local/apache2/cgi-bin/" + + + + + # + # ScriptSock: On threaded servers, designate the path to the UNIX + # socket used to communicate with the CGI daemon of mod_cgid. + # + #Scriptsock cgisock + + +# +# "/usr/local/apache2/cgi-bin" should be changed to whatever your ScriptAliased +# CGI directory exists, if you have that configured. +# + + AllowOverride None + Options None + Require all granted + + + + # + # Avoid passing HTTP_PROXY environment to CGI's on this or any proxied + # backend servers which have lingering "httpoxy" defects. + # 'Proxy' request header is undefined by the IETF, not listed by IANA + # + RequestHeader unset Proxy early + + + + # + # TypesConfig points to the file containing the list of mappings from + # filename extension to MIME-type. + # + TypesConfig conf/mime.types + + # + # AddType allows you to add to or override the MIME configuration + # file specified in TypesConfig for specific file types. + # + #AddType application/x-gzip .tgz + # + # AddEncoding allows you to have certain browsers uncompress + # information on the fly. Note: Not all browsers support this. + # + #AddEncoding x-compress .Z + #AddEncoding x-gzip .gz .tgz + # + # If the AddEncoding directives above are commented-out, then you + # probably should define those extensions to indicate media types: + # + AddType application/x-compress .Z + AddType application/x-gzip .gz .tgz + + # + # AddHandler allows you to map certain file extensions to "handlers": + # actions unrelated to filetype. These can be either built into the server + # or added with the Action directive (see below) + # + # To use CGI scripts outside of ScriptAliased directories: + # (You will also need to add "ExecCGI" to the "Options" directive.) + # + #AddHandler cgi-script .cgi + + # For type maps (negotiated resources): + #AddHandler type-map var + + # + # Filters allow you to process content before it is sent to the client. + # + # To parse .shtml files for server-side includes (SSI): + # (You will also need to add "Includes" to the "Options" directive.) + # + #AddType text/html .shtml + #AddOutputFilter INCLUDES .shtml + + +# +# The mod_mime_magic module allows the server to use various hints from the +# contents of the file itself to determine its type. The MIMEMagicFile +# directive tells the module where the hint definitions are located. +# +#MIMEMagicFile conf/magic + +# +# Customizable error responses come in three flavors: +# 1) plain text 2) local redirects 3) external redirects +# +# Some examples: +#ErrorDocument 500 "The server made a boo boo." +#ErrorDocument 404 /missing.html +#ErrorDocument 404 "/cgi-bin/missing_handler.pl" +#ErrorDocument 402 http://www.example.com/subscription_info.html +# + +# +# MaxRanges: Maximum number of Ranges in a request before +# returning the entire resource, or one of the special +# values 'default', 'none' or 'unlimited'. +# Default setting is to accept 200 Ranges. +#MaxRanges unlimited + +# +# EnableMMAP and EnableSendfile: On systems that support it, +# memory-mapping or the sendfile syscall may be used to deliver +# files. This usually improves server performance, but must +# be turned off when serving from networked-mounted +# filesystems or if support for these functions is otherwise +# broken on your system. +# Defaults: EnableMMAP On, EnableSendfile Off +# +#EnableMMAP off +#EnableSendfile on + +# Supplemental configuration +# +# The configuration files in the conf/extra/ directory can be +# included to add extra features or to modify the default configuration of +# the server, or you may simply copy their contents here and change as +# necessary. + +# Server-pool management (MPM specific) +#Include conf/extra/httpd-mpm.conf + +# Multi-language error messages +#Include conf/extra/httpd-multilang-errordoc.conf + +# Fancy directory listings +#Include conf/extra/httpd-autoindex.conf + +# Language settings +#Include conf/extra/httpd-languages.conf + +# User home directories +#Include conf/extra/httpd-userdir.conf + +# Real-time info on requests and configuration +#Include conf/extra/httpd-info.conf + +# Virtual hosts +Include conf/extra/httpd-vhosts.conf + +# Local access to the Apache HTTP Server Manual +#Include conf/extra/httpd-manual.conf + +# Distributed authoring and versioning (WebDAV) +#Include conf/extra/httpd-dav.conf + +# Various default settings +#Include conf/extra/httpd-default.conf + +# Configure mod_proxy_html to understand HTML4/XHTML1 + +Include conf/extra/proxy-html.conf + + +# Secure (SSL/TLS) connections +# Include conf/extra/httpd-ssl.conf +# +# Note: The following must must be present to support +# starting without SSL on platforms with no /dev/random equivalent +# but a statically compiled-in mod_ssl. +# + +SSLRandomSeed startup builtin +SSLRandomSeed connect builtin + \ No newline at end of file diff --git a/sources/Re3gistry2-build-helper/docker-compose.yml b/sources/Re3gistry2-build-helper/docker-compose.yml new file mode 100644 index 00000000..76b9138e --- /dev/null +++ b/sources/Re3gistry2-build-helper/docker-compose.yml @@ -0,0 +1,99 @@ +## YAML Template. +--- +version: '3.3' + +services: + db: + image: postgres:10.20-alpine + container_name: reg-postgres + healthcheck: + test: ["CMD-SHELL", "pg_isready", "-d", "db_prod"] + interval: 30s + timeout: 60s + retries: 5 + start_period: 80s + restart: always + environment: + - POSTGRES_USER=name + - POSTGRES_PASSWORD=password + - POSTGRES_DB=registrydb + - ALLOW_IP_RANGE="0.0.0.0/0" + volumes: + - ../../dist/db-scripts/registry2_drop-and-create-and-init.sql.orig:/docker-entrypoint-initdb.d/init.sql + # Test database tu use it without installation + # Be sure file sources-main/resources-configurations_files/system.installed + # is removed from the war file. If not, installation will be not detected. + - ../../dist/customize-interface/example-profile-developer-docker/dump-docker-202205180929.sql:/docker-entrypoint-initdb.d/init_backup.sql + # login example db: name@example.com password + expose: + - "5432" + ports: + - 5432:5432 + networks: + - main + web: + depends_on: + - db + - solr + image: tomcat:7.0.109-jdk8-adoptopenjdk-hotspot + #image: tomcat:8.5.81-jdk8 + container_name: reg-tomcat + # Take war files from compiled + volumes: + - ../Re3gistry2/target/re3gistry2.war:/usr/local/tomcat/webapps/re3gistry2.war + - ../Re3gistry2RestAPI/target/re3gistry2restapi.war:/usr/local/tomcat/webapps/re3gistry2restapi.war + ports: + - 8080:8080 + - 8888:8888 + - 9000:9000 + - 8000:8000 + restart: always + networks: + - main + # Allows debug application + environment: + JPDA_ADDRESS: 8000 + JPDA_TRANSPORT: dt_socket + entrypoint: /usr/local/tomcat/bin/catalina.sh jpda run + apache: + image: httpd:2.4.53-alpine + container_name: reg-httpd + ports: + - 80:80 + depends_on: + - db + - solr + - web + volumes: + - ../../dist/webapp/httpd.conf:/usr/local/apache2/conf/httpd.conf + - ../../dist/webapp/httpd-vhosts.conf:/usr/local/apache2/conf/extra/httpd-vhosts.conf + - ../Re3gistry2ServiceWebapp/public_html:/var/www/host.docker.internal/public_html + restart: always + networks: + - main + + solr: + image: solr:8.11.1 + container_name: reg-solr + ports: + - "9983:9983" + - "8983:8983" +# volumes: +# - ../../../solr:/opt/solr/server/solr/re3gistry2 +# entrypoint: +# - docker-entrypoint.sh +# - solr-precreate +# - re3gistry + entrypoint: + - bash + - "-c" + - "precreate-core re3gistry; precreate-core rortest; exec solr -f" + mailserver: + image: marcopas/docker-mailslurper + container_name: mailserver + ports: + - 2500:2500 + - 8081:8080 # http://localhost:8081/ + - 8085:8085 +networks: + main: diff --git a/sources/Re3gistry2-build-helper/pom.xml b/sources/Re3gistry2-build-helper/pom.xml index e31efa30..e02af4e0 100644 --- a/sources/Re3gistry2-build-helper/pom.xml +++ b/sources/Re3gistry2-build-helper/pom.xml @@ -44,7 +44,42 @@ ../Re3gistry2RestAPI ../Re3gistry2 - + + + developer-docker + + developer-docker + 5432 + host.docker.internal + registrydb + name + password + jdbc:postgresql://${persistence.db.address}:${persistence.db.port}/${persistence.db.name} + SHIRO + http://localhost/re3gistry2/ + localhost + alert-warning + local environment of the Re3gistry 2 software
If you would like to participate to the testing check out the software repository Re3gistry - localhost Instance - frontend view]]>
+ work/ehcache + + webapps/re3gistry2/WEB-INF/classes + work/registrylogger.log + OFF + ecl + localhost + 2500 + false + false + name + password + admin@example.com + false + neutral + ON + /schemas/2.0 + +
+
developer-example-profile From a3cc50e9920c809c8b3c702cc78b42710a98883c Mon Sep 17 00:00:00 2001 From: unaibrrgn <75972112+unaibrrgn@users.noreply.github.com> Date: Fri, 3 Mar 2023 14:20:19 +0100 Subject: [PATCH 06/15] basic action email system --- .../web/controller/ControlBody.java | 112 ++++++++++-------- .../web/controller/DiscardProposal.java | 3 + .../controller/SubmittingOrganisations.java | 11 +- .../configuration.properties | 9 ++ .../base/utility/BaseConstants.java | 12 +- .../re3gistry2/base/utility/MailManager.java | 73 ++++++++++++ 6 files changed, 170 insertions(+), 50 deletions(-) diff --git a/sources/Re3gistry2/src/main/java/eu/europa/ec/re3gistry2/web/controller/ControlBody.java b/sources/Re3gistry2/src/main/java/eu/europa/ec/re3gistry2/web/controller/ControlBody.java index 681b6c07..769fbee2 100644 --- a/sources/Re3gistry2/src/main/java/eu/europa/ec/re3gistry2/web/controller/ControlBody.java +++ b/sources/Re3gistry2/src/main/java/eu/europa/ec/re3gistry2/web/controller/ControlBody.java @@ -26,6 +26,7 @@ import eu.europa.ec.re3gistry2.base.utility.Configuration; import eu.europa.ec.re3gistry2.base.utility.BaseConstants; import eu.europa.ec.re3gistry2.base.utility.InputSanitizerHelper; +import eu.europa.ec.re3gistry2.base.utility.MailManager; import eu.europa.ec.re3gistry2.base.utility.PersistenceFactory; import eu.europa.ec.re3gistry2.base.utility.UserHelper; import eu.europa.ec.re3gistry2.base.utility.WebConstants; @@ -53,6 +54,7 @@ import eu.europa.ec.re3gistry2.model.RegRelationproposed; import eu.europa.ec.re3gistry2.model.RegRole; import eu.europa.ec.re3gistry2.model.RegUser; +import eu.europa.ec.re3gistry2.web.utility.SendEmailFromAction; import java.io.IOException; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; @@ -60,8 +62,11 @@ import java.util.Collections; import java.util.HashMap; import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.List; import java.util.Optional; +import java.util.ResourceBundle; +import javax.mail.internet.InternetAddress; import javax.persistence.EntityManager; import javax.persistence.NoResultException; import javax.persistence.Persistence; @@ -167,53 +172,53 @@ private void processRequest(HttpServletRequest request, HttpServletResponse resp // This is a view request - //Cache the parent of the proposed item - ItemCache cache = (ItemCache) request.getAttribute(BaseConstants.ATTRIBUTE_CACHE_KEY); - if (cache == null) { - cache = new EhCache(); - request.setAttribute(BaseConstants.ATTRIBUTE_CACHE_KEY, cache); - } - if (formRegActionUuid != null){ - RegAction regActionForCache; - List regItemProposeds; - try{ - regActionForCache = regActionManager.get(formRegActionUuid); - regItemProposeds = regItemproposedManager.getAll(regActionForCache); - }catch(Exception e){ - regItemProposeds = Collections.emptyList(); - } - - HashSet parentsList = new HashSet (); - HashSet collectionsList = new HashSet (); - for (RegItemproposed regItemProposed : regItemProposeds) { - List collections = regRelationproposedManager.getAllByObject(regItemProposed); - - if(collections != null && collections.size() > 0 ){ - for (RegRelationproposed collection : collections) { - if(collection.getRegRelationpredicate().getLocalid().equals(BaseConstants.KEY_PREDICATE_COLLECTION)){ - String uuid = collection.getRegItemObject().getUuid(); - collectionsList.add(uuid); - } - } - } - if(regItemProposed.getRegAction() != null && regItemProposed.getRegAction().getRegItemRegister() != null){ - if(regItemProposed.getRegAction().getRegItemRegister().getRegItemclass() != null && regItemProposed.getRegAction().getRegItemRegister().getRegItemclass().getUuid() != null){ - String uuid = regItemProposed.getRegAction().getRegItemRegister().getRegItemclass().getUuid(); - parentsList.add(uuid); - } - } - } - EntityManager emCache = PersistenceFactory.getEntityManagerFactory().createEntityManager(); - CacheAll cacheAll = new CacheAll(emCache, cache, null); - for (String uuid : parentsList) { -// EntityManager emCache = Persistence.createEntityManagerFactory(BaseConstants.KEY_PROPERTY_PERSISTENCE_UNIT_NAME).createEntityManager(); - cacheAll.run(uuid); - } - for (String uuid : collectionsList) { -// EntityManager emCache = Persistence.createEntityManagerFactory(BaseConstants.KEY_PROPERTY_PERSISTENCE_UNIT_NAME).createEntityManager(); - cacheAll.run(uuid); - } - } +// //Cache the parent of the proposed item +// ItemCache cache = (ItemCache) request.getAttribute(BaseConstants.ATTRIBUTE_CACHE_KEY); +// if (cache == null) { +// cache = new EhCache(); +// request.setAttribute(BaseConstants.ATTRIBUTE_CACHE_KEY, cache); +// } +// if (formRegActionUuid != null){ +// RegAction regActionForCache; +// List regItemProposeds; +// try{ +// regActionForCache = regActionManager.get(formRegActionUuid); +// regItemProposeds = regItemproposedManager.getAll(regActionForCache); +// }catch(Exception e){ +// regItemProposeds = Collections.emptyList(); +// } +// +// HashSet parentsList = new HashSet (); +// HashSet collectionsList = new HashSet (); +// for (RegItemproposed regItemProposed : regItemProposeds) { +// List collections = regRelationproposedManager.getAllByObject(regItemProposed); +// +// if(collections != null && collections.size() > 0 ){ +// for (RegRelationproposed collection : collections) { +// if(collection.getRegRelationpredicate().getLocalid().equals(BaseConstants.KEY_PREDICATE_COLLECTION)){ +// String uuid = collection.getRegItemObject().getUuid(); +// collectionsList.add(uuid); +// } +// } +// } +// if(regItemProposed.getRegAction() != null && regItemProposed.getRegAction().getRegItemRegister() != null){ +// if(regItemProposed.getRegAction().getRegItemRegister().getRegItemclass() != null && regItemProposed.getRegAction().getRegItemRegister().getRegItemclass().getUuid() != null){ +// String uuid = regItemProposed.getRegAction().getRegItemRegister().getRegItemclass().getUuid(); +// parentsList.add(uuid); +// } +// } +// } +// EntityManager emCache = PersistenceFactory.getEntityManagerFactory().createEntityManager(); +// CacheAll cacheAll = new CacheAll(emCache, cache, null); +// for (String uuid : parentsList) { +//// EntityManager emCache = Persistence.createEntityManagerFactory(BaseConstants.KEY_PROPERTY_PERSISTENCE_UNIT_NAME).createEntityManager(); +// cacheAll.run(uuid); +// } +// for (String uuid : collectionsList) { +//// EntityManager emCache = Persistence.createEntityManagerFactory(BaseConstants.KEY_PROPERTY_PERSISTENCE_UNIT_NAME).createEntityManager(); +// cacheAll.run(uuid); +// } +// } // Getting the submitting organization RegRole @@ -269,12 +274,23 @@ private void processRequest(HttpServletRequest request, HttpServletResponse resp } catch (NoResultException e) { } } - + + + if (regItemproposeds == null && regAction!=null) { + regItemproposeds = (List) regItemproposedManager.getAll(regAction); + } + request.setAttribute(BaseConstants.KEY_REQUEST_ACTION_LIST, regActions); request.setAttribute(BaseConstants.KEY_REQUEST_ACTION, regAction); request.setAttribute(BaseConstants.KEY_REQUEST_ITEM_PROPOSEDS, regItemproposeds); request.setAttribute(BaseConstants.KEY_REQUEST_ITEM_HISTORYS, regItemhistorys); request.setAttribute(BaseConstants.KEY_REQUEST_REGITEMS, regItems); + + if(regAction!=null){ + if(regAction.getApprovedBy()!=null | regAction.getRejectedBy()!=null){ + MailManager.sendActionMail(regItemproposeds, regAction, BaseConstants.KEY_FIELD_MANDATORY_CONTROLBODY); + } + } //Dispatch request request.getRequestDispatcher(WebConstants.PAGE_JSP_FOLDER + WebConstants.PAGE_PATH_CONTROLBODY + WebConstants.PAGE_URINAME_CONTROLBODY + WebConstants.PAGE_JSP_EXTENSION).forward(request, response); diff --git a/sources/Re3gistry2/src/main/java/eu/europa/ec/re3gistry2/web/controller/DiscardProposal.java b/sources/Re3gistry2/src/main/java/eu/europa/ec/re3gistry2/web/controller/DiscardProposal.java index 1266b844..3ebd53e8 100644 --- a/sources/Re3gistry2/src/main/java/eu/europa/ec/re3gistry2/web/controller/DiscardProposal.java +++ b/sources/Re3gistry2/src/main/java/eu/europa/ec/re3gistry2/web/controller/DiscardProposal.java @@ -26,6 +26,7 @@ import eu.europa.ec.re3gistry2.base.utility.BaseConstants; import eu.europa.ec.re3gistry2.base.utility.Configuration; import eu.europa.ec.re3gistry2.base.utility.InputSanitizerHelper; +import eu.europa.ec.re3gistry2.base.utility.MailManager; import eu.europa.ec.re3gistry2.base.utility.PersistenceFactory; import eu.europa.ec.re3gistry2.javaapi.handler.RegItemproposedHandler; import eu.europa.ec.re3gistry2.model.RegUser; @@ -120,6 +121,8 @@ private void processRequest(HttpServletRequest request, HttpServletResponse resp // get all regItemProposed for this action List regItemproposedList = regItemproposedManager.getAll(regAction); + + MailManager.sendActionMail(regItemproposedList, regAction, BaseConstants.KEY_FIELD_MANDATORY_SUBMITTINGORGANIZATIONS); if (!regItemproposedList.isEmpty()) { for (RegItemproposed regItemproposed : regItemproposedList) { diff --git a/sources/Re3gistry2/src/main/java/eu/europa/ec/re3gistry2/web/controller/SubmittingOrganisations.java b/sources/Re3gistry2/src/main/java/eu/europa/ec/re3gistry2/web/controller/SubmittingOrganisations.java index 692c0ed5..dbedd6af 100644 --- a/sources/Re3gistry2/src/main/java/eu/europa/ec/re3gistry2/web/controller/SubmittingOrganisations.java +++ b/sources/Re3gistry2/src/main/java/eu/europa/ec/re3gistry2/web/controller/SubmittingOrganisations.java @@ -26,6 +26,7 @@ import eu.europa.ec.re3gistry2.base.utility.Configuration; import eu.europa.ec.re3gistry2.base.utility.BaseConstants; import eu.europa.ec.re3gistry2.base.utility.InputSanitizerHelper; +import eu.europa.ec.re3gistry2.base.utility.MailManager; import eu.europa.ec.re3gistry2.base.utility.PersistenceFactory; import eu.europa.ec.re3gistry2.base.utility.UserHelper; import eu.europa.ec.re3gistry2.base.utility.WebConstants; @@ -48,6 +49,7 @@ import eu.europa.ec.re3gistry2.model.RegRole; import eu.europa.ec.re3gistry2.model.RegUser; import eu.europa.ec.re3gistry2.model.RegUserRegGroupMapping; +import eu.europa.ec.re3gistry2.web.utility.SendEmailFromAction; import java.io.IOException; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; @@ -56,6 +58,7 @@ import java.util.HashSet; import java.util.Iterator; import java.util.List; +import java.util.ResourceBundle; import java.util.Set; import javax.persistence.EntityManager; import javax.persistence.NoResultException; @@ -276,7 +279,13 @@ private void processRequest(HttpServletRequest request, HttpServletResponse resp request.setAttribute(BaseConstants.KEY_REQUEST_ITEM_PROPOSEDS, regItemproposeds); request.setAttribute(BaseConstants.KEY_REQUEST_ITEM_HISTORYS, regItemhistorys); request.setAttribute(BaseConstants.KEY_REQUEST_REGITEMS, regItems); - + + if(regAction!=null){ + if(regAction.getApprovedBy()!=null | regAction.getSubmittedBy()!=null | regAction.getRejectedBy()!=null){ + MailManager.sendActionMail(regItemproposeds, regAction, BaseConstants.KEY_FIELD_MANDATORY_SUBMITTINGORGANIZATIONS); + } + } + //Dispatch request request.getRequestDispatcher(WebConstants.PAGE_JSP_FOLDER + WebConstants.PAGE_PATH_SUBMITTINGORGANISATIONS + WebConstants.PAGE_URINAME_SUBMITTINGORGANISATIONS + WebConstants.PAGE_JSP_EXTENSION).forward(request, response); diff --git a/sources/Re3gistry2/src/main/resources/configurations_files/configuration.properties b/sources/Re3gistry2/src/main/resources/configurations_files/configuration.properties index 26d2a5d0..6138e561 100644 --- a/sources/Re3gistry2/src/main/resources/configurations_files/configuration.properties +++ b/sources/Re3gistry2/src/main/resources/configurations_files/configuration.properties @@ -176,6 +176,15 @@ mail.text.body.groupschanged.ending=

Access your user profile page det mail.text.body.groupschanged.ending.contact=Registry software mail.text.body.groupschanged.ending.contact.webpage=https://github.com/ec-jrc/re3gistry +mail.text.body.itemaction.basebody=The following item(s) were changed:
+mail.text.body.itemaction.acceptedwithchanges=accepted with changes +mail.text.body.itemaction.notaccepted=not accepted +mail.text.body.itemaction.rejected=rejected +mail.text.body.itemaction.basebody.controlbody=Actions on the Control Body were made +mail.text.body.itemaction.basebody.submitting=Actions on the Submitting Organizations were made +mail.text.body.itemaction.proposedby= proposed by +mail.text.body.itemaction.was= was +mail.text.body.itemaction.actionmadeby=. The action was made by ### Webapp properties #### web.application_root_url=${application.rooturl} diff --git a/sources/Re3gistry2Base/src/main/java/eu/europa/ec/re3gistry2/base/utility/BaseConstants.java b/sources/Re3gistry2Base/src/main/java/eu/europa/ec/re3gistry2/base/utility/BaseConstants.java index b89461a5..d15e31f4 100644 --- a/sources/Re3gistry2Base/src/main/java/eu/europa/ec/re3gistry2/base/utility/BaseConstants.java +++ b/sources/Re3gistry2Base/src/main/java/eu/europa/ec/re3gistry2/base/utility/BaseConstants.java @@ -148,7 +148,17 @@ public class BaseConstants { public static final String KEY_EMAIL_BODY_GROUPSCHANGED_ENDING = "mail.text.body.groupschanged.ending"; public static final String KEY_EMAIL_BODY_GROUPSCHANGED_ENDING_CONTACT_NAME = "mail.text.body.groupschanged.ending.contact"; public static final String KEY_EMAIL_BODY_GROUPSCHANGED_ENDING_CONTACT_WEBPAGE = "mail.text.body.groupschanged.ending.contact.webpage"; - + + public static final String KEY_EMAIL_SUBJECT_ITEMACTION_CONTROLBODY = "mail.text.body.itemaction.basebody.controlbody"; + public static final String KEY_EMAIL_SUBJECT_ITEMACTION_SUBMITTINGORG = "mail.text.body.itemaction.basebody.submitting"; + public static final String KEY_EMAIL_BODY_ITEMACTION_BASE = "mail.text.body.itemaction.basebody"; + public static final String KEY_EMAIL_BODY_ITEMACTION_ACCEPTEDWCHANGES = "mail.text.body.itemaction.acceptedwithchanges"; + public static final String KEY_EMAIL_BODY_ITEMACTION_NOTACCEPTED = "mail.text.body.itemaction.notaccepted"; + public static final String KEY_EMAIL_BODY_ITEMACTION_REJECTED = "mail.text.body.itemaction.rejected"; + public static final String KEY_EMAIL_BODY_ITEMACTION_PROPOSEDBY = "mail.text.body.itemaction.proposedby"; + public static final String KEY_EMAIL_BODY_ITEMACTION_WAS = "mail.text.body.itemaction.was"; + public static final String KEY_EMAIL_BODY_ITEMACTION_ACTIONMADEBY = "mail.text.body.itemaction.actionmadeby"; + /** * mail subject and body bulk import */ diff --git a/sources/Re3gistry2Base/src/main/java/eu/europa/ec/re3gistry2/base/utility/MailManager.java b/sources/Re3gistry2Base/src/main/java/eu/europa/ec/re3gistry2/base/utility/MailManager.java index 532cd793..e8277284 100644 --- a/sources/Re3gistry2Base/src/main/java/eu/europa/ec/re3gistry2/base/utility/MailManager.java +++ b/sources/Re3gistry2Base/src/main/java/eu/europa/ec/re3gistry2/base/utility/MailManager.java @@ -23,9 +23,15 @@ */ package eu.europa.ec.re3gistry2.base.utility; +import eu.europa.ec.re3gistry2.model.RegAction; +import eu.europa.ec.re3gistry2.model.RegItemproposed; import java.security.InvalidParameterException; +import java.util.ArrayList; import java.util.Date; +import java.util.LinkedHashSet; +import java.util.List; import java.util.Properties; +import java.util.logging.Level; import javax.mail.Authenticator; import javax.mail.Message; import javax.mail.MessagingException; @@ -157,4 +163,71 @@ public PasswordAuthentication getPasswordAuthentication() { throw new MessagingException(e.getMessage()); } } + + public static void sendActionMail(List regItemproposeds, RegAction regAction, String originClass) throws AddressException{ + + List itemUserNames = new ArrayList (); + List itemUserEmails = new ArrayList (); + List actionMakerNames = new ArrayList (); + List actionMakerEmails = new ArrayList (); + + if(regItemproposeds!=null && regAction!=null){ + for(RegItemproposed ri : regItemproposeds){ + + itemUserNames.add(ri.getRegUser().getName()); + itemUserEmails.add(ri.getRegUser().getEmail()); + actionMakerNames.add(regAction.getRegUser().getName()); + actionMakerEmails.add(regAction.getRegUser().getEmail()); + } + + LinkedHashSet users = new LinkedHashSet<>(); + for(int i=0; i Date: Tue, 7 Mar 2023 12:21:28 +0100 Subject: [PATCH 07/15] RDF/SKOS format fix --- .../restapi/format/RDFFormatter.java | 56 +++++++++---------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/sources/Re3gistry2RestAPI/src/main/java/eu/europa/ec/re3gistry2/restapi/format/RDFFormatter.java b/sources/Re3gistry2RestAPI/src/main/java/eu/europa/ec/re3gistry2/restapi/format/RDFFormatter.java index a4fd95a8..0cd4d5f5 100644 --- a/sources/Re3gistry2RestAPI/src/main/java/eu/europa/ec/re3gistry2/restapi/format/RDFFormatter.java +++ b/sources/Re3gistry2RestAPI/src/main/java/eu/europa/ec/re3gistry2/restapi/format/RDFFormatter.java @@ -251,8 +251,8 @@ private void writeItemShortVersion(XMLStreamWriter xml, ContainedItem item) thro writeDescription(xml, item); writeNarrower(xml, item); - writeBroader(xml, item);//WRONG -// writeHasPartsTopConcepts(xml, item); +// writeBroader(xml, item);//WRONG + writeHasPartsTopConcepts(xml, item); writeIsDefinedBy(xml, item); writeStatus(xml, item); @@ -423,22 +423,19 @@ private void writeRoles(XMLStreamWriter xml, ContainedItem item) throws XMLStrea } private void writeHasPartsTopConcepts(XMLStreamWriter xml, ContainedItem containedItem) throws XMLStreamException { - if (containedItem.getTopConcepts() != null) { - for (BasicContainedItem ci : containedItem.getTopConcepts()) { - switch (containedItem.getType()) { - case BaseConstants.KEY_ITEMCLASS_TYPE_REGISTRY: { - writeEmptyElement(xml, DCAT, "dataset", RDF, "resource", ci.getUri()); - } - break; - default: - writeEmptyElement(xml, DCT, "hasPart", RDF, "resource", ci.getUri()); - break; - } - } - for (BasicContainedItem ci : containedItem.getTopConcepts()) { - writeEmptyElement(xml, SKOS, "hasTopConcept", RDF, "resource", ci.getUri()); + switch (containedItem.getType()) { + case BaseConstants.KEY_ITEMCLASS_TYPE_REGISTRY: { } - } + break; + case BaseConstants.KEY_ITEMCLASS_TYPE_REGISTER: + writeEmptyElement(xml, SKOS, "hasTopConcept", RDF, "resource", containedItem.getRegistry().getUri()); + break; + default: + if (containedItem.getTopConceptOf() != null) { + writeEmptyElement(xml, SKOS, "hasTopConcept", RDF, "resource", containedItem.getTopConceptOf().getUri()); + } + break; + } } private XMLStreamWriter getXMLWriter(OutputStream out, String rootNS, String rootElement) throws XMLStreamException { @@ -502,18 +499,21 @@ private void writeInScheme(XMLStreamWriter xml, ContainedItem item) throws XMLSt } private void writeTopConceptOf(XMLStreamWriter xml, ContainedItem item) throws XMLStreamException { - switch (item.getType()) { - case BaseConstants.KEY_ITEMCLASS_TYPE_REGISTRY: { - } - break; - case BaseConstants.KEY_ITEMCLASS_TYPE_REGISTER: - writeEmptyElement(xml, SKOS, "topConceptOf", RDF, "resource", item.getRegistry().getUri()); - break; - default: - if (item.getTopConceptOf() != null) { - writeEmptyElement(xml, SKOS, "topConceptOf", RDF, "resource", item.getTopConceptOf().getUri()); + if (item.getTopConcepts() != null) { + for (BasicContainedItem ci : item.getTopConcepts()) { + switch (item.getType()) { + case BaseConstants.KEY_ITEMCLASS_TYPE_REGISTRY: { + writeEmptyElement(xml, DCAT, "dataset", RDF, "resource", ci.getUri()); + } + break; + default: + writeEmptyElement(xml, DCT, "hasPart", RDF, "resource", ci.getUri()); + break; } - break; + } + for (BasicContainedItem ci : item.getTopConcepts()) { + writeEmptyElement(xml, SKOS, "topConceptOf", RDF, "resource", ci.getUri()); + } } } From 06f7d7e2aa77143084a880e6ce36b1efa7f1906a Mon Sep 17 00:00:00 2001 From: oruscalleda <116353060+oruscalleda@users.noreply.github.com> Date: Tue, 7 Mar 2023 16:12:23 +0100 Subject: [PATCH 08/15] Dependencies vulnerabilities update Update dependencies to fix vulnerabilities --- sources/Re3gistry2Base/pom.xml | 6 +++--- .../base/utility/InputSanitizerHelper.java | 14 +++++++------- sources/Re3gistry2JavaAPI/pom.xml | 4 ++-- sources/Re3gistry2RestAPI/pom.xml | 2 +- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/sources/Re3gistry2Base/pom.xml b/sources/Re3gistry2Base/pom.xml index e377ecee..ace01e07 100644 --- a/sources/Re3gistry2Base/pom.xml +++ b/sources/Re3gistry2Base/pom.xml @@ -44,12 +44,12 @@ org.apache.shiro shiro-core - 1.6.0 + 1.10.0 org.apache.shiro shiro-web - 1.6.0 + 1.7.1 javax.servlet @@ -108,7 +108,7 @@ org.jsoup jsoup - 1.14.3 + 1.15.3 org.json diff --git a/sources/Re3gistry2Base/src/main/java/eu/europa/ec/re3gistry2/base/utility/InputSanitizerHelper.java b/sources/Re3gistry2Base/src/main/java/eu/europa/ec/re3gistry2/base/utility/InputSanitizerHelper.java index 22cce1bc..ffecf326 100644 --- a/sources/Re3gistry2Base/src/main/java/eu/europa/ec/re3gistry2/base/utility/InputSanitizerHelper.java +++ b/sources/Re3gistry2Base/src/main/java/eu/europa/ec/re3gistry2/base/utility/InputSanitizerHelper.java @@ -24,7 +24,7 @@ package eu.europa.ec.re3gistry2.base.utility; import org.jsoup.Jsoup; -import org.jsoup.safety.Whitelist; +import org.jsoup.safety.Safelist; public class InputSanitizerHelper { @@ -39,23 +39,23 @@ public static String sanitizeInput(String input){ // Getting the sanitization level (defaut basic) String sanitizerLevel = configuration.getProperties().getProperty(BaseConstants.KEY_PROPERTY_INPUT_SANITIZER_LEVEL,BaseConstants.KEY_PROPERTY_INPUT_SANITIZER_LEVEL_BASIC); - Whitelist whitelist; + Safelist whitelist; switch(sanitizerLevel){ case BaseConstants.KEY_PROPERTY_INPUT_SANITIZER_LEVEL_SIMPLETEXT: - whitelist = Whitelist.simpleText(); + whitelist = Safelist.simpleText(); break; case BaseConstants.KEY_PROPERTY_INPUT_SANITIZER_LEVEL_BASIC: - whitelist = Whitelist.basic(); + whitelist = Safelist.basic(); break; case BaseConstants.KEY_PROPERTY_INPUT_SANITIZER_LEVEL_BASICWITHIMAGES: - whitelist = Whitelist.basicWithImages(); + whitelist = Safelist.basicWithImages(); break; case BaseConstants.KEY_PROPERTY_INPUT_SANITIZER_LEVEL_RELAXED: - whitelist = Whitelist.relaxed(); + whitelist = Safelist.relaxed(); break; default: - whitelist = Whitelist.basic(); + whitelist = Safelist.basic(); break; } diff --git a/sources/Re3gistry2JavaAPI/pom.xml b/sources/Re3gistry2JavaAPI/pom.xml index b5db6662..191575f1 100644 --- a/sources/Re3gistry2JavaAPI/pom.xml +++ b/sources/Re3gistry2JavaAPI/pom.xml @@ -32,7 +32,7 @@ commons-fileupload commons-fileupload - 1.4 + 1.5 org.apache.solr @@ -47,7 +47,7 @@ com.fasterxml.jackson.core jackson-databind - 2.13.2.1 + 2.13.4.1 diff --git a/sources/Re3gistry2RestAPI/pom.xml b/sources/Re3gistry2RestAPI/pom.xml index 08781180..e6c8d4a8 100644 --- a/sources/Re3gistry2RestAPI/pom.xml +++ b/sources/Re3gistry2RestAPI/pom.xml @@ -10,7 +10,7 @@ 1.8 1.8 2.5 - 2.13.0 + 2.13.4 2.7.0 From 69fdd79b132dd10f2d7a3923fdd8ad35e0bfe6d1 Mon Sep 17 00:00:00 2001 From: unaibrrgn <75972112+unaibrrgn@users.noreply.github.com> Date: Wed, 8 Mar 2023 12:48:53 +0100 Subject: [PATCH 09/15] BaseConstants now working correctly #191 --- .../ec/re3gistry2/web/controller/ControlBody.java | 8 +++----- .../re3gistry2/web/controller/DiscardProposal.java | 2 +- .../web/controller/SubmittingOrganisations.java | 8 +++----- .../configuration.properties.orig | 10 ++++++++++ .../localizations/LocalizationBundle_en.properties | 10 ++++++++++ .../ec/re3gistry2/base/utility/MailManager.java | 13 +++++++------ 6 files changed, 34 insertions(+), 17 deletions(-) diff --git a/sources/Re3gistry2/src/main/java/eu/europa/ec/re3gistry2/web/controller/ControlBody.java b/sources/Re3gistry2/src/main/java/eu/europa/ec/re3gistry2/web/controller/ControlBody.java index 769fbee2..c6f5ecc9 100644 --- a/sources/Re3gistry2/src/main/java/eu/europa/ec/re3gistry2/web/controller/ControlBody.java +++ b/sources/Re3gistry2/src/main/java/eu/europa/ec/re3gistry2/web/controller/ControlBody.java @@ -286,12 +286,10 @@ private void processRequest(HttpServletRequest request, HttpServletResponse resp request.setAttribute(BaseConstants.KEY_REQUEST_ITEM_HISTORYS, regItemhistorys); request.setAttribute(BaseConstants.KEY_REQUEST_REGITEMS, regItems); - if(regAction!=null){ - if(regAction.getApprovedBy()!=null | regAction.getRejectedBy()!=null){ - MailManager.sendActionMail(regItemproposeds, regAction, BaseConstants.KEY_FIELD_MANDATORY_CONTROLBODY); - } + if (formRegActionUuid != null && formRegActionUuid.length() > 0 && formSubmitAction != null && formSubmitAction.length() > 0 && formActionType != null && formActionType.length() > 0) { + MailManager.sendActionMail(regItemproposeds, regAction, Configuration.getInstance().getLocalization(), BaseConstants.KEY_FIELD_MANDATORY_CONTROLBODY); } - + //Dispatch request request.getRequestDispatcher(WebConstants.PAGE_JSP_FOLDER + WebConstants.PAGE_PATH_CONTROLBODY + WebConstants.PAGE_URINAME_CONTROLBODY + WebConstants.PAGE_JSP_EXTENSION).forward(request, response); diff --git a/sources/Re3gistry2/src/main/java/eu/europa/ec/re3gistry2/web/controller/DiscardProposal.java b/sources/Re3gistry2/src/main/java/eu/europa/ec/re3gistry2/web/controller/DiscardProposal.java index 3ebd53e8..98e92851 100644 --- a/sources/Re3gistry2/src/main/java/eu/europa/ec/re3gistry2/web/controller/DiscardProposal.java +++ b/sources/Re3gistry2/src/main/java/eu/europa/ec/re3gistry2/web/controller/DiscardProposal.java @@ -122,7 +122,7 @@ private void processRequest(HttpServletRequest request, HttpServletResponse resp // get all regItemProposed for this action List regItemproposedList = regItemproposedManager.getAll(regAction); - MailManager.sendActionMail(regItemproposedList, regAction, BaseConstants.KEY_FIELD_MANDATORY_SUBMITTINGORGANIZATIONS); + MailManager.sendActionMail(regItemproposedList, regAction, Configuration.getInstance().getLocalization(), BaseConstants.KEY_FIELD_MANDATORY_SUBMITTINGORGANIZATIONS); if (!regItemproposedList.isEmpty()) { for (RegItemproposed regItemproposed : regItemproposedList) { diff --git a/sources/Re3gistry2/src/main/java/eu/europa/ec/re3gistry2/web/controller/SubmittingOrganisations.java b/sources/Re3gistry2/src/main/java/eu/europa/ec/re3gistry2/web/controller/SubmittingOrganisations.java index dbedd6af..7a1bc140 100644 --- a/sources/Re3gistry2/src/main/java/eu/europa/ec/re3gistry2/web/controller/SubmittingOrganisations.java +++ b/sources/Re3gistry2/src/main/java/eu/europa/ec/re3gistry2/web/controller/SubmittingOrganisations.java @@ -280,12 +280,10 @@ private void processRequest(HttpServletRequest request, HttpServletResponse resp request.setAttribute(BaseConstants.KEY_REQUEST_ITEM_HISTORYS, regItemhistorys); request.setAttribute(BaseConstants.KEY_REQUEST_REGITEMS, regItems); - if(regAction!=null){ - if(regAction.getApprovedBy()!=null | regAction.getSubmittedBy()!=null | regAction.getRejectedBy()!=null){ - MailManager.sendActionMail(regItemproposeds, regAction, BaseConstants.KEY_FIELD_MANDATORY_SUBMITTINGORGANIZATIONS); + if (formRegActionUuid != null && formRegActionUuid.length() > 0 && formSubmitAction != null && formSubmitAction.length() > 0) { + MailManager.sendActionMail(regItemproposeds, regAction, Configuration.getInstance().getLocalization(), BaseConstants.KEY_FIELD_MANDATORY_SUBMITTINGORGANIZATIONS); } - } - + //Dispatch request request.getRequestDispatcher(WebConstants.PAGE_JSP_FOLDER + WebConstants.PAGE_PATH_SUBMITTINGORGANISATIONS + WebConstants.PAGE_URINAME_SUBMITTINGORGANISATIONS + WebConstants.PAGE_JSP_EXTENSION).forward(request, response); diff --git a/sources/Re3gistry2/src/main/resources/configurations_files/configuration.properties.orig b/sources/Re3gistry2/src/main/resources/configurations_files/configuration.properties.orig index 4322f9a8..c12b05bc 100644 --- a/sources/Re3gistry2/src/main/resources/configurations_files/configuration.properties.orig +++ b/sources/Re3gistry2/src/main/resources/configurations_files/configuration.properties.orig @@ -172,6 +172,16 @@ mail.text.body.groupschanged.ending=

Access your user profile page det mail.text.body.groupschanged.ending.contact=Registry software mail.text.body.groupschanged.ending.contact.webpage=https://github.com/ec-jrc/re3gistry +mail.text.body.itemaction.basebody=The following item(s) were changed:
+mail.text.body.itemaction.acceptedwithchanges=accepted with changes +mail.text.body.itemaction.notaccepted=not accepted +mail.text.body.itemaction.rejected=rejected +mail.text.body.itemaction.basebody.controlbody=Actions on the Control Body were made +mail.text.body.itemaction.basebody.submitting=Actions on the Submitting Organizations were made +mail.text.body.itemaction.proposedby= proposed by +mail.text.body.itemaction.was= was +mail.text.body.itemaction.actionmadeby=. The action was made by + mail.text.subject.bulkimport.success=Re3gistry - bulk import {itemclass} success mail.text.subject.bulkimport.error=Re3gistry - bulk import {itemclass} error mail.text.body.bulkimport.success=Dear {name},

The bulk import has been completed with success. diff --git a/sources/Re3gistry2/src/main/resources/localizations/LocalizationBundle_en.properties b/sources/Re3gistry2/src/main/resources/localizations/LocalizationBundle_en.properties index eb85f5ac..a9e4a51c 100644 --- a/sources/Re3gistry2/src/main/resources/localizations/LocalizationBundle_en.properties +++ b/sources/Re3gistry2/src/main/resources/localizations/LocalizationBundle_en.properties @@ -617,6 +617,16 @@ mail.text.body.groupschanged.ending=

Access your user profile page det mail.text.body.groupschanged.ending.contact=Registry software mail.text.body.groupschanged.ending.contact.webpage=https://github.com/ec-jrc/re3gistry +mail.text.body.itemaction.basebody=The following item(s) were changed:
+mail.text.body.itemaction.acceptedwithchanges=accepted with changes +mail.text.body.itemaction.notaccepted=not accepted +mail.text.body.itemaction.rejected=rejected +mail.text.body.itemaction.basebody.controlbody=Actions on the Control Body were made +mail.text.body.itemaction.basebody.submitting=Actions on the Submitting Organizations were made +mail.text.body.itemaction.proposedby= proposed by +mail.text.body.itemaction.was= was +mail.text.body.itemaction.actionmadeby=. The action was made by + #tooltiop add registry registry.tooltip=Target registry where the register that you are about to create will be sitting registry.path.tooltip=This option allows to include the 'registry' word for all the elements belonging to the register that you are about to create diff --git a/sources/Re3gistry2Base/src/main/java/eu/europa/ec/re3gistry2/base/utility/MailManager.java b/sources/Re3gistry2Base/src/main/java/eu/europa/ec/re3gistry2/base/utility/MailManager.java index e8277284..cbf7038a 100644 --- a/sources/Re3gistry2Base/src/main/java/eu/europa/ec/re3gistry2/base/utility/MailManager.java +++ b/sources/Re3gistry2Base/src/main/java/eu/europa/ec/re3gistry2/base/utility/MailManager.java @@ -31,6 +31,7 @@ import java.util.LinkedHashSet; import java.util.List; import java.util.Properties; +import java.util.ResourceBundle; import java.util.logging.Level; import javax.mail.Authenticator; import javax.mail.Message; @@ -164,7 +165,7 @@ public PasswordAuthentication getPasswordAuthentication() { } } - public static void sendActionMail(List regItemproposeds, RegAction regAction, String originClass) throws AddressException{ + public static void sendActionMail(List regItemproposeds, RegAction regAction, ResourceBundle systemLocalization, String originClass) throws AddressException{ List itemUserNames = new ArrayList (); List itemUserEmails = new ArrayList (); @@ -198,14 +199,14 @@ public static void sendActionMail(List regItemproposeds, RegAct String itemstatus =regAction.getRegStatus().getLocalid(); String subject = ""; - String body = BaseConstants.KEY_EMAIL_BODY_ITEMACTION_BASE; + String body = systemLocalization.getString(BaseConstants.KEY_EMAIL_BODY_ITEMACTION_BASE); if(itemstatus.equals(BaseConstants.KEY_STATUS_LOCALID_DRAFT) && originClass.equals(BaseConstants.KEY_FIELD_MANDATORY_SUBMITTINGORGANIZATIONS)){ - itemstatus = BaseConstants.KEY_EMAIL_BODY_ITEMACTION_REJECTED; + itemstatus = systemLocalization.getString(BaseConstants.KEY_EMAIL_BODY_ITEMACTION_REJECTED); }else if(itemstatus.equals(BaseConstants.KEY_STATUS_LOCALID_NOTACCEPTED)){ - itemstatus = BaseConstants.KEY_EMAIL_BODY_ITEMACTION_NOTACCEPTED; + itemstatus = systemLocalization.getString(BaseConstants.KEY_EMAIL_BODY_ITEMACTION_NOTACCEPTED); }else if(itemstatus.equals(BaseConstants.KEY_STATUS_LOCALID_DRAFT)){ - itemstatus = BaseConstants.KEY_EMAIL_BODY_ITEMACTION_ACCEPTEDWCHANGES; + itemstatus = systemLocalization.getString(BaseConstants.KEY_EMAIL_BODY_ITEMACTION_ACCEPTEDWCHANGES); } if(originClass.equalsIgnoreCase(BaseConstants.KEY_FIELD_MANDATORY_CONTROLBODY)){ @@ -214,7 +215,7 @@ public static void sendActionMail(List regItemproposeds, RegAct body +="The item "+ regItemproposeds.get(i).getLocalid() + " proposed by " + itemUserNames.get(i) + " was "+ itemstatus + ". The action was made by " + actionMakerNames.get(i); } }else if(originClass.equalsIgnoreCase(BaseConstants.KEY_FIELD_MANDATORY_SUBMITTINGORGANIZATIONS)){ - subject = BaseConstants.KEY_EMAIL_SUBJECT_ITEMACTION_SUBMITTINGORG; + subject = systemLocalization.getString(BaseConstants.KEY_EMAIL_SUBJECT_ITEMACTION_SUBMITTINGORG); for(int i=0;i Date: Thu, 16 Mar 2023 13:35:24 +0100 Subject: [PATCH 10/15] #191 Adapted new email template proposal --- .../configurations_files/configuration.properties | 2 ++ .../configuration.properties.orig | 2 ++ .../localizations/LocalizationBundle_en.properties | 2 ++ .../ec/re3gistry2/base/utility/BaseConstants.java | 2 ++ .../ec/re3gistry2/base/utility/MailManager.java | 11 +++++------ 5 files changed, 13 insertions(+), 6 deletions(-) diff --git a/sources/Re3gistry2/src/main/resources/configurations_files/configuration.properties b/sources/Re3gistry2/src/main/resources/configurations_files/configuration.properties index 6138e561..c59e1865 100644 --- a/sources/Re3gistry2/src/main/resources/configurations_files/configuration.properties +++ b/sources/Re3gistry2/src/main/resources/configurations_files/configuration.properties @@ -42,6 +42,8 @@ application.language.label.en=English (en) #application.language.label.it=Italiano (it) application.language.defaultLocale=en +application.default.name = Re3gistry2 + # ECAS base URL (authetication method) application.ecas.baseurl = https://webgate.ec.europa.eu diff --git a/sources/Re3gistry2/src/main/resources/configurations_files/configuration.properties.orig b/sources/Re3gistry2/src/main/resources/configurations_files/configuration.properties.orig index c12b05bc..4b8acae2 100644 --- a/sources/Re3gistry2/src/main/resources/configurations_files/configuration.properties.orig +++ b/sources/Re3gistry2/src/main/resources/configurations_files/configuration.properties.orig @@ -145,6 +145,8 @@ role.permissions.registerOwner=ManageUser,ManageGroup,MapUserToGroup role.permissions.controlBody=ApproveProposal role.permissions.submittingOrganization=ManageItemProposal,SubmitProposal +application.default.name + #### End Roles and permissions section ######################################### ### Mail ### diff --git a/sources/Re3gistry2/src/main/resources/localizations/LocalizationBundle_en.properties b/sources/Re3gistry2/src/main/resources/localizations/LocalizationBundle_en.properties index a9e4a51c..f4b383c7 100644 --- a/sources/Re3gistry2/src/main/resources/localizations/LocalizationBundle_en.properties +++ b/sources/Re3gistry2/src/main/resources/localizations/LocalizationBundle_en.properties @@ -448,6 +448,8 @@ discard.contentclass.confirm=Are you sure you want to remove the content class? profile.label.title = User profile +application.default.name = Re3gistry2 + #installation fileds installation.main.title=Re3gistry installation wizard diff --git a/sources/Re3gistry2Base/src/main/java/eu/europa/ec/re3gistry2/base/utility/BaseConstants.java b/sources/Re3gistry2Base/src/main/java/eu/europa/ec/re3gistry2/base/utility/BaseConstants.java index d15e31f4..9c1e6093 100644 --- a/sources/Re3gistry2Base/src/main/java/eu/europa/ec/re3gistry2/base/utility/BaseConstants.java +++ b/sources/Re3gistry2Base/src/main/java/eu/europa/ec/re3gistry2/base/utility/BaseConstants.java @@ -84,6 +84,8 @@ public class BaseConstants { public static final String KEY_PROPERTY_LOGIN_TYPE = "application.login.type"; public static final String KEY_PROPERTY_LOGIN_TYPE_SHIRO = "SHIRO"; public static final String KEY_PROPERTY_LOGIN_TYPE_ECAS = "ECAS"; + + public static final String KEY_PROPERTY_APP_DEFAULT_NAME = "application.default.name"; public static final String KEY_PROPERTY_INTERFACE_TYPE = "application.selected.interface"; public static final String KEY_PROPERTY_INTERFACE_NEUTRAL_TYPE = "neutral"; diff --git a/sources/Re3gistry2Base/src/main/java/eu/europa/ec/re3gistry2/base/utility/MailManager.java b/sources/Re3gistry2Base/src/main/java/eu/europa/ec/re3gistry2/base/utility/MailManager.java index cbf7038a..c70860fa 100644 --- a/sources/Re3gistry2Base/src/main/java/eu/europa/ec/re3gistry2/base/utility/MailManager.java +++ b/sources/Re3gistry2Base/src/main/java/eu/europa/ec/re3gistry2/base/utility/MailManager.java @@ -198,8 +198,9 @@ public static void sendActionMail(List regItemproposeds, RegAct String itemstatus =regAction.getRegStatus().getLocalid(); - String subject = ""; - String body = systemLocalization.getString(BaseConstants.KEY_EMAIL_BODY_ITEMACTION_BASE); + //Subject: Updates on [Registry name variable] change proposals +systemLocalization.getString(BaseConstants.KEY_PROPERTY_APP_DEFAULT_NAME)+ + String subject = "Updates on "+ systemLocalization.getString(BaseConstants.KEY_PROPERTY_APP_DEFAULT_NAME) +" change proposals"; + String body = "
Dear " + regAction.getRegUser().getName()+",

Changes have ocurred on the following item(s):

"; if(itemstatus.equals(BaseConstants.KEY_STATUS_LOCALID_DRAFT) && originClass.equals(BaseConstants.KEY_FIELD_MANDATORY_SUBMITTINGORGANIZATIONS)){ itemstatus = systemLocalization.getString(BaseConstants.KEY_EMAIL_BODY_ITEMACTION_REJECTED); @@ -210,14 +211,12 @@ public static void sendActionMail(List regItemproposeds, RegAct } if(originClass.equalsIgnoreCase(BaseConstants.KEY_FIELD_MANDATORY_CONTROLBODY)){ - subject = BaseConstants.KEY_EMAIL_SUBJECT_ITEMACTION_CONTROLBODY; for(int i=0;i
"; } }else if(originClass.equalsIgnoreCase(BaseConstants.KEY_FIELD_MANDATORY_SUBMITTINGORGANIZATIONS)){ - subject = systemLocalization.getString(BaseConstants.KEY_EMAIL_SUBJECT_ITEMACTION_SUBMITTINGORG); for(int i=0;i
"; } } From 4d46826e534b377d7f1434d92f0d726e2da5850a Mon Sep 17 00:00:00 2001 From: oruscalleda <116353060+oruscalleda@users.noreply.github.com> Date: Mon, 20 Mar 2023 12:50:13 +0100 Subject: [PATCH 11/15] Add status tag to ISO19135 format --- .../restapi/format/ISO19135Formatter.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/sources/Re3gistry2RestAPI/src/main/java/eu/europa/ec/re3gistry2/restapi/format/ISO19135Formatter.java b/sources/Re3gistry2RestAPI/src/main/java/eu/europa/ec/re3gistry2/restapi/format/ISO19135Formatter.java index 86b96bf0..1103e435 100644 --- a/sources/Re3gistry2RestAPI/src/main/java/eu/europa/ec/re3gistry2/restapi/format/ISO19135Formatter.java +++ b/sources/Re3gistry2RestAPI/src/main/java/eu/europa/ec/re3gistry2/restapi/format/ISO19135Formatter.java @@ -293,8 +293,18 @@ private void writeRegisterItem(XMLStreamWriter xml, ContainedItem item, RegLangu writeXLink(xml, "additionInformation", item.getUri()); } - private void writeStatus(XMLStreamWriter xml, ContainedItem item) { - // TODO Auto-generated method stub + private void writeStatus(XMLStreamWriter xml, ContainedItem item) throws XMLStreamException { + Optional val = item.getProperty("status"); + if (!val.isPresent()) { + writeGcoNilReason(xml, "status", "missing"); + } else { + LocalizedProperty prop = val.get(); + if (prop.getValues().isEmpty()) { + writeGcoNilReason(xml, "status", "missing"); + } else { + writeGcoCharacterString(xml, "status", prop.getValues().get(0).getValue()); + } + } } private void writeDefinition(XMLStreamWriter xml, ContainedItem item) throws XMLStreamException { From b5bead8ad8a3bd07bebd52b5378bf2417a016079 Mon Sep 17 00:00:00 2001 From: oruscalleda <116353060+oruscalleda@users.noreply.github.com> Date: Mon, 20 Mar 2023 13:20:30 +0100 Subject: [PATCH 12/15] changes on mail templates --- .../resources/configurations_files/configuration.properties | 2 +- .../localizations/LocalizationBundle_en.properties | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sources/Re3gistry2/src/main/resources/configurations_files/configuration.properties b/sources/Re3gistry2/src/main/resources/configurations_files/configuration.properties index 99d918c4..ff624bb3 100644 --- a/sources/Re3gistry2/src/main/resources/configurations_files/configuration.properties +++ b/sources/Re3gistry2/src/main/resources/configurations_files/configuration.properties @@ -164,7 +164,7 @@ mail.text.subject.error=Re3gistry - installation error mail.text.body.error=An error has occurred during the Re3gistry installation, please review your settings. mail.text.subject.newregistration=Re3gistry - Your account have been successfully added to the system mail.text.error.newregistration=Dear {name},

Your account has been successfully created and it is now enabled.

You can access the management interface using the following credentials:
Username: {email}
Key: {key}

Please change your key after the first access.
-mail.text.option.newregistration=Dear {name},

Your account has been successfully created.

You can access the management interface using the following credentials:
Username: {email}
Key: {key}

Please change your key after the first access.
You can activate your account following this link.
If you don\u2019t want to accept this invitation please follow this link. to remove your user.
+mail.text.option.newregistration=Dear {name},

Your account within Re3gistry has been successfully created.

Use the following credentials to access the management interface and set your password:
Username: {email}
Password: {key}

Please change your password after the first access.

Click here to activate your account.
To ignore this invitation, please click here.
This activation code will expire in 24 hours

Re3gistry manager

This email has been automatically generated, please do not reply to it.

mail.text.subject.bulkimport.success=Re3gistry - bulk import {itemclass} success mail.text.subject.bulkimport.error=Re3gistry - bulk import {itemclass} error diff --git a/sources/Re3gistry2/src/main/resources/localizations/LocalizationBundle_en.properties b/sources/Re3gistry2/src/main/resources/localizations/LocalizationBundle_en.properties index 7b2abef8..c669d79c 100644 --- a/sources/Re3gistry2/src/main/resources/localizations/LocalizationBundle_en.properties +++ b/sources/Re3gistry2/src/main/resources/localizations/LocalizationBundle_en.properties @@ -379,9 +379,9 @@ index.text.solrindexer.temporary-text=This is a temporary panel to test the Solr about.label.title=About -activate.label.title=User enabled -activate.body=Your user has been enabled! -activate.body.login=You can login pressing here. +activate.label.title=Account activated +activate.body=Your account is now activated. +activate.body.login=Please log in here to start using Re3gistry.
Find user documentation here. userDeleted.body=Your account has been succesfully deleted. help.label.title=Help From fd24f8ec0e44d1389eb77bad24b40347b423be90 Mon Sep 17 00:00:00 2001 From: unaibrrgn <75972112+unaibrrgn@users.noreply.github.com> Date: Mon, 20 Mar 2023 14:37:31 +0100 Subject: [PATCH 13/15] Email notification update user-manual Signed-off-by: unaibrrgn <75972112+unaibrrgn@users.noreply.github.com> --- documentation/user-manual.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/documentation/user-manual.md b/documentation/user-manual.md index ded8b9a3..6b9970ba 100644 --- a/documentation/user-manual.md +++ b/documentation/user-manual.md @@ -532,6 +532,10 @@ Depending on the type of installation, using an external authentication provider ![User profile section - Editing details](images/userprofile.png) +## Email notifications + +Users can receive different email notifications, indicating different statuses and actions done to the items and actions they're related to. These notifications indicate the status of the items (Item's been submitted, published etc.) and some of the actions done in the instance such as permissions and roles given to a user. + From 5b877cf6ff1e9443b98e0fc18a0f49f09fa141ab Mon Sep 17 00:00:00 2001 From: unaibrrgn <75972112+unaibrrgn@users.noreply.github.com> Date: Mon, 20 Mar 2023 14:41:22 +0100 Subject: [PATCH 14/15] Email noti and templates update Signed-off-by: unaibrrgn <75972112+unaibrrgn@users.noreply.github.com> --- documentation/developer-manual.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/documentation/developer-manual.md b/documentation/developer-manual.md index 7cb9b485..a6ff9e10 100644 --- a/documentation/developer-manual.md +++ b/documentation/developer-manual.md @@ -178,3 +178,11 @@ For tomcat, add two files to the tomcat lib folder: ecas-tomcat-x.y.z.jar and lo Verify that the JDK trusts the [ECAS certificates](https://webgate.ec.europa.eu/CITnet/confluence/display/IAM/Downloads-Certificates) else import them on the keystore of the JVM. Restart the service and check the authentication menchanism. + +### Email notifications and templates + +You can currently change some of the variables of the different email templates such as the instance/organisation name. +To change those you can access the [configuration.properties](https://github.com/ec-jrc/re3gistry/blob/master/sources/Re3gistry2/src/main/resources/configurations_files/configuration.properties) file, where you can search the mail template data under [mail.text]. +You can there see the different subjects and text that you can change. Have in account that some of these may need some proper code changing in their respective java classes. + + From ad13d5cc975bf606af4bc78d27b846401d37b964 Mon Sep 17 00:00:00 2001 From: unaibrrgn <75972112+unaibrrgn@users.noreply.github.com> Date: Mon, 20 Mar 2023 14:46:38 +0100 Subject: [PATCH 15/15] Manual update 2 Signed-off-by: unaibrrgn <75972112+unaibrrgn@users.noreply.github.com> --- documentation/developer-manual.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/documentation/developer-manual.md b/documentation/developer-manual.md index a6ff9e10..16610236 100644 --- a/documentation/developer-manual.md +++ b/documentation/developer-manual.md @@ -182,7 +182,9 @@ Restart the service and check the authentication menchanism. ### Email notifications and templates You can currently change some of the variables of the different email templates such as the instance/organisation name. -To change those you can access the [configuration.properties](https://github.com/ec-jrc/re3gistry/blob/master/sources/Re3gistry2/src/main/resources/configurations_files/configuration.properties) file, where you can search the mail template data under [mail.text]. + +To change those you can access the [configuration.properties](https://github.com/ec-jrc/re3gistry/blob/master/sources/Re3gistry2/src/main/resources/configurations_files/configuration.properties) file, where you can search the mail template variables by searching the "mail.text" variables. You can there see the different subjects and text that you can change. Have in account that some of these may need some proper code changing in their respective java classes. +App's default name is Re3gistry2, this variable is used in some email templates that show the instance name. The property that manages this name is called "application.default.name". This variable can be found in the same [configuration.properties](https://github.com/ec-jrc/re3gistry/blob/master/sources/Re3gistry2/src/main/resources/configurations_files/configuration.properties) file.