From 797623a3528f86e3b63b033bd81a8d3e9a726e83 Mon Sep 17 00:00:00 2001 From: Michael Seaton Date: Wed, 30 Nov 2022 15:55:34 -0500 Subject: [PATCH 1/3] MLW-1410 - Upgrade Malawi distribution to latest OpenMRS 2.5.x release, including updates to modules as needed --- api/pom.xml | 2 +- distro/pom.xml | 2 +- omod/pom.xml | 2 +- pom.xml | 63 ++++++++++++++++++++++++++++++-------------------- 4 files changed, 41 insertions(+), 28 deletions(-) diff --git a/api/pom.xml b/api/pom.xml index a42f4716..4e67c9f2 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -4,7 +4,7 @@ org.openmrs.module pihmalawi - 6.9.0-SNAPSHOT + 7.0.0-SNAPSHOT org.openmrs.module pihmalawi-api diff --git a/distro/pom.xml b/distro/pom.xml index a6b2489d..32f71dd1 100644 --- a/distro/pom.xml +++ b/distro/pom.xml @@ -4,7 +4,7 @@ org.openmrs.module pihmalawi - 6.9.0-SNAPSHOT + 7.0.0-SNAPSHOT org.openmrs.distro diff --git a/omod/pom.xml b/omod/pom.xml index 8542c8ac..ae8db3da 100644 --- a/omod/pom.xml +++ b/omod/pom.xml @@ -3,7 +3,7 @@ org.openmrs.module pihmalawi - 6.9.0-SNAPSHOT + 7.0.0-SNAPSHOT org.openmrs.module pihmalawi-omod diff --git a/pom.xml b/pom.xml index e9ab9271..e3cd5d73 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ org.openmrs.module pihmalawi - 6.9.0-SNAPSHOT + 7.0.0-SNAPSHOT pom PIH Malawi Customizations Parent project for PIH Malawi Customizations @@ -36,42 +36,42 @@ - 2.3.5 - 2.14.2 - 2.16.0 - 1.14.0 + 2.5.8-SNAPSHOT + 2.15.0 + 2.17.0-SNAPSHOT + 1.16.0 1.3.0 - 1.33.0 - 1.33.0-SNAPSHOT - 2.9.0 - 1.3.0 - 4.4.0 + 1.38.0-SNAPSHOT + 1.33.0 + 2.10.0 + 1.7.0-SNAPSHOT + 5.1.0-SNAPSHOT 2.3.0-SNAPSHOT 1.10.0 - 4.7.0 + 4.8.0 2.2.4 - 1.10.0 + 1.13.0-SNAPSHOT 1.13.0 - 1.4.0 + 1.5.0 1.8.0 - 1.18.0 - 1.12.0 + 2.0.0-SNAPSHOT + 1.13.0 2.13.0 - 1.24.0 + 1.25.0-SNAPSHOT 1.11.0 2.0.9-SNAPSHOT - 1.23.0 - 1.11.0 - 1.7.0 + 1.25.0 + 1.13.0 + 1.11.0-SNAPSHOT 0.2.15 1.0.8 - 2.0.0-SNAPSHOT + 3.0.0-SNAPSHOT 1.7.0 - 2.18.0 - 3.21.0 - 2.0.6 + 2.23.0-SNAPSHOT + 3.22.1 + 2.0.7 2.2.0-SNAPSHOT - 2.36.0 + 2.37.0-SNAPSHOT UTF-8 false ${project.parent.artifactId} @@ -88,7 +88,6 @@ 2.3 compile - org.openmrs.module appui-api @@ -286,6 +285,20 @@ provided + + + javax.el + javax.el-api + 3.0.0 + test + + + org.glassfish + javax.el + 3.0.0 + test + + From 27e36b4fe22d518dcc1c29ef9973620932973c43 Mon Sep 17 00:00:00 2001 From: Michael Seaton Date: Thu, 1 Dec 2022 21:10:53 -0500 Subject: [PATCH 2/3] MLW-1410 - Add authentication modules MLW-1410 - Enable 2fa MLW-1410 - Move ui configuration to extensions MLW-1410 - Move ui configuration to extensions MLW-1410 - Increment module dependency versions following releases MLW-1410 - Increment module dependency versions following releases MLW-1410 - Configure the edit user page for administrators to use the legacyui page. --- .../module/pihmalawi/PihMalawiConstants.java | 8 + .../activator/AuthenticationInitializer.java | 135 ++++++++++++ .../activator/PihMalawiModuleActivator.java | 1 + .../apps/authenticationui_extension.json | 38 ++++ api/src/test/resources/log4j.xml | 14 +- distro/openmrs-distro.properties | 3 + .../pihmalawi/HomepageOverrideController.java | 5 - .../pihmalawi/PihMalawiWebConstants.java | 19 -- ...nfoAndErrorMessagesFragmentController.java | 11 +- .../page/controller/LoginPageController.java | 199 ------------------ .../QuickProgramsFormController.java | 1 - omod/src/main/resources/config.xml | 11 +- omod/src/main/webapp/pages/login.gsp | 139 ------------ .../main/webapp/resources/styles/login.css | 6 - pom.xml | 91 +++++++- 15 files changed, 288 insertions(+), 393 deletions(-) create mode 100644 api/src/main/java/org/openmrs/module/pihmalawi/activator/AuthenticationInitializer.java create mode 100644 api/src/main/resources/apps/authenticationui_extension.json delete mode 100644 omod/src/main/java/org/openmrs/module/pihmalawi/PihMalawiWebConstants.java delete mode 100644 omod/src/main/java/org/openmrs/module/pihmalawi/page/controller/LoginPageController.java delete mode 100644 omod/src/main/webapp/pages/login.gsp delete mode 100644 omod/src/main/webapp/resources/styles/login.css diff --git a/api/src/main/java/org/openmrs/module/pihmalawi/PihMalawiConstants.java b/api/src/main/java/org/openmrs/module/pihmalawi/PihMalawiConstants.java index da75ba25..b4e87322 100644 --- a/api/src/main/java/org/openmrs/module/pihmalawi/PihMalawiConstants.java +++ b/api/src/main/java/org/openmrs/module/pihmalawi/PihMalawiConstants.java @@ -20,4 +20,12 @@ public class PihMalawiConstants { public static final String TASK_MIGRATE_EID_TEST_RESULTS = "Migrate EID Test Results"; public static final String TASK_MIGRATE_EID_TEST_RESULTS_DESCRIPTION = "Migrates EID Test Results on the Exposed Child Initial Form to the EID Screening Form"; public static final String MEDIC_MOBILE_FACILITY = "Yendanafe Catchment"; + + public static final String REQUEST_PARAMETER_NAME_REDIRECT_URL = "redirectUrl"; + public static final String COOKIE_NAME_LAST_SESSION_LOCATION = "pihmalawi.lastSessionLocation"; + public static final String SESSION_ATTRIBUTE_REDIRECT_URL = "_REFERENCE_APPLICATION_REDIRECT_URL_"; + public static final String SESSION_ATTRIBUTE_ERROR_MESSAGE = "_REFERENCE_APPLICATION_ERROR_MESSAGE_"; + public static final String SESSION_ATTRIBUTE_INFO_MESSAGE = "_REFERENCE_APPLICATION_INFO_MESSAGE_"; + public static final String SESSION_LOCATION_ID = "emrContext.sessionLocationId"; + public static final String PATIENT_DASHBOARD_URL = "patientDashboard.form"; } diff --git a/api/src/main/java/org/openmrs/module/pihmalawi/activator/AuthenticationInitializer.java b/api/src/main/java/org/openmrs/module/pihmalawi/activator/AuthenticationInitializer.java new file mode 100644 index 00000000..5e466b23 --- /dev/null +++ b/api/src/main/java/org/openmrs/module/pihmalawi/activator/AuthenticationInitializer.java @@ -0,0 +1,135 @@ +package org.openmrs.module.pihmalawi.activator; + +import org.apache.commons.lang.StringUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.openmrs.module.authentication.AuthenticationConfig; +import org.openmrs.module.pihmalawi.PihMalawiConstants; + +import java.util.HashSet; +import java.util.Properties; +import java.util.Set; +import java.util.TreeSet; + +import static org.openmrs.module.authentication.AuthenticationConfig.SCHEME; +import static org.openmrs.module.authentication.AuthenticationConfig.SCHEME_CONFIG_PREFIX_TEMPLATE; +import static org.openmrs.module.authentication.AuthenticationConfig.SCHEME_ID; +import static org.openmrs.module.authentication.AuthenticationConfig.SCHEME_TYPE_TEMPLATE; +import static org.openmrs.module.authentication.AuthenticationConfig.WHITE_LIST; + +public class AuthenticationInitializer implements Initializer { + + protected static Log log = LogFactory.getLog(AuthenticationInitializer.class); + + public static final String BASIC = "basic"; + public static final String SECRET = "secret"; + public static final String TOTP = "totp"; + public static final String TWO_FACTOR = "2fa"; + + @Override + public void started() { + + // Add this classloader + AuthenticationConfig.registerClassLoader(AuthenticationInitializer.class.getClassLoader()); + + // If no authentication scheme is explicitly configured, default to basic + AuthenticationConfig.setProperty(SCHEME, "2fa"); + + // We set up white list as everything needed for the basic login page and any additional scheme login page + // Add in any additional white list pages that are included in the config + + Set whitelist = new HashSet<>(); + whitelist.add("/login.htm"); + whitelist.add("/authenticationui/login/login.page"); + whitelist.add("/appui/session/getLoginLocations.action"); + whitelist.add("/csrfguard"); + whitelist.add("*.js"); + whitelist.add("*.css"); + whitelist.add("*.gif"); + whitelist.add("*.jpg"); + whitelist.add("*.png"); + whitelist.add("*.ico"); + whitelist.add("*.ttf"); + whitelist.add("*.woff"); + + // Set up all the supported authentication schemes with default values. + // Allow overriding with values from the config + + // Basic Authentication Scheme. This provides basic auth + session location selection + { + String className = "org.openmrs.module.authentication.web.BasicWithLocationAuthenticationScheme"; + Properties p = new Properties(); + p.put("loginPage", "/authenticationui/login/login.page"); + p.put("usernameParam", "username"); + p.put("passwordParam", "password"); + p.put("locationParamName", "sessionLocation"); + p.put("locationRequired", "false"); + p.put("onlyLocationsWithTag", "Login Location"); + p.put("locationSessionAttributeName", PihMalawiConstants.SESSION_LOCATION_ID); + p.put("lastLocationCookieName", PihMalawiConstants.COOKIE_NAME_LAST_SESSION_LOCATION); + addScheme(BASIC, className, p, whitelist); + } + + // Secret Question Authentication Scheme. This is an available 2nd factor + { + String className = "org.openmrs.module.authentication.web.SecretQuestionAuthenticationScheme"; + Properties p = new Properties(); + p.put("loginPage", "/authenticationui/login/loginSecret.page"); + p.put("configurationPage", "/authenticationui/account/changeSecurityQuestion.page?schemeId={schemeId}&userId={userId}"); + addScheme(SECRET, className, p, whitelist); + } + + // Totp Authentication Scheme. This is an available 2nd factor + { + String className = "org.openmrs.module.authentication.web.TotpAuthenticationScheme"; + Properties p = new Properties(); + p.put("qrCodeIssuer", "PIHEMR"); + p.put("loginPage", "/authenticationui/login/loginTotp.page"); + p.put("configurationPage", "/authenticationui/account/configureTotp.page?schemeId={schemeId}&userId={userId}"); + addScheme(TOTP, className, p, whitelist); + } + + // Two-Factor Authentication Scheme. + { + String className = "org.openmrs.module.authentication.web.TwoFactorAuthenticationScheme"; + Properties p = new Properties(); + p.put("primaryOptions", BASIC); + p.put("secondaryOptions", SECRET + "," + TOTP); + addScheme(TWO_FACTOR, className, p, whitelist); + } + + AuthenticationConfig.setProperty(WHITE_LIST, String.join(",", whitelist)); + + log.info("Authentication Schemes Configured"); + Properties p = AuthenticationConfig.getConfig(); + Set sortedKeys = new TreeSet<>(p.stringPropertyNames()); + for (String key : sortedKeys) { + log.info(key + " = " + p.getProperty(key)); + } + } + + @Override + public void stopped() { + + } + + /** + * Add configuration for a scheme with the given schemeId, if a scheme with this schemeId is not already configured + */ + protected void addScheme(String schemeId, String className, Properties config, Set whitelist) { + String schemeTypeProperty = SCHEME_TYPE_TEMPLATE.replace(SCHEME_ID, schemeId); + if (StringUtils.isBlank(AuthenticationConfig.getProperty(schemeTypeProperty))) { + AuthenticationConfig.setProperty(schemeTypeProperty, className); + if (config != null) { + for (String propertyName : config.stringPropertyNames()) { + String key = SCHEME_CONFIG_PREFIX_TEMPLATE.replace(SCHEME_ID, schemeId) + propertyName; + String value = config.getProperty(propertyName); + AuthenticationConfig.setProperty(key, value); + if (propertyName.equalsIgnoreCase("loginPage")) { + whitelist.add(value); + } + } + } + } + } +} diff --git a/api/src/main/java/org/openmrs/module/pihmalawi/activator/PihMalawiModuleActivator.java b/api/src/main/java/org/openmrs/module/pihmalawi/activator/PihMalawiModuleActivator.java index a75551ed..e77a4e19 100644 --- a/api/src/main/java/org/openmrs/module/pihmalawi/activator/PihMalawiModuleActivator.java +++ b/api/src/main/java/org/openmrs/module/pihmalawi/activator/PihMalawiModuleActivator.java @@ -65,6 +65,7 @@ public List getInitializers() { l.add(new AddressTemplateInitializer()); l.add(new HtmlFormInitializer()); l.add(new ReportInitializer()); + l.add(new AuthenticationInitializer()); return l; } diff --git a/api/src/main/resources/apps/authenticationui_extension.json b/api/src/main/resources/apps/authenticationui_extension.json new file mode 100644 index 00000000..65cc8197 --- /dev/null +++ b/api/src/main/resources/apps/authenticationui_extension.json @@ -0,0 +1,38 @@ +[ + { + "id": "pih.authenticationui.header", + "extensionPointId": "org.openmrs.module.appui.header.config", + "type":"config", + "extensionParams": { + "logo-icon-url": "/ms/uiframework/resource/pihmalawi/images/openMrsLogo.png", + "logo-link-url": "/index.htm" + } + }, + { + "id": "pih.authenticationui.admin", + "extensionPointId": "org.openmrs.module.authenticationui.admin.config", + "type": "config", + "extensionParams": { + "admin-page-url": "/admin/index.htm", + "manage-users-page-url": "/admin/users/users.list", + "admin-edit-user-page-url": "/admin/users/user.form", + "required-privilege": "Edit User Passwords", + "phone-number-person-attribute-type": "667f45ee-977f-11e1-8993-905e29aff6c1", + "default-location-user-property": "" + } + }, + { + "id": "pih.authenticationui.login", + "extensionPointId": "org.openmrs.module.authenticationui.loginPage.config", + "type": "config", + "extensionParams": { + "show-locations": true, + "require-location": false, + "location-tag-name": "Login Location", + "last-location-cookie-name": "pihmalawi.lastSessionLocation", + "welcome-message": "", + "warning-if-not-chrome": "", + "allow-password-reset": false + } + } +] \ No newline at end of file diff --git a/api/src/test/resources/log4j.xml b/api/src/test/resources/log4j.xml index 67a3af71..0bbc5fa4 100644 --- a/api/src/test/resources/log4j.xml +++ b/api/src/test/resources/log4j.xml @@ -50,5 +50,17 @@ - + + + + + + + + + + + + + diff --git a/distro/openmrs-distro.properties b/distro/openmrs-distro.properties index 630bfd41..dca1d8af 100644 --- a/distro/openmrs-distro.properties +++ b/distro/openmrs-distro.properties @@ -4,6 +4,8 @@ war.openmrs=${openMRSVersion} omod.addresshierarchy=${addresshierarchyVersion} omod.appframework=${appframeworkVersion} omod.appui=${appuiVersion} +omod.authentication=${authenticationVersion} +omod.authenticationui=${authenticationuiVersion} omod.calculation=${calculationVersion} omod.coreapps=${coreappsVersion} omod.emrapi=${emrapiVersion} @@ -15,6 +17,7 @@ omod.htmlformentry=${htmlformentryVersion} omod.htmlformentryui=${htmlformentryuiVersion} omod.htmlwidgets=${htmlwidgetsVersion} omod.idgen=${idgenVersion} +omod.initializer=${initializerVersion} omod.legacyui=${legacyuiVersion} omod.metadatadeploy=${metadatadeployVersion} omod.metadatamapping=${metadatamappingVersion} diff --git a/omod/src/main/java/org/openmrs/module/pihmalawi/HomepageOverrideController.java b/omod/src/main/java/org/openmrs/module/pihmalawi/HomepageOverrideController.java index f5a9bfc1..f44ab8f5 100644 --- a/omod/src/main/java/org/openmrs/module/pihmalawi/HomepageOverrideController.java +++ b/omod/src/main/java/org/openmrs/module/pihmalawi/HomepageOverrideController.java @@ -16,9 +16,4 @@ public String showOurHomepage() { return "forward:/findPatient.htm"; } - @RequestMapping("/login.htm") - public String showLoginHomepage() { - return "forward:/pihmalawi/login.page"; - } - } diff --git a/omod/src/main/java/org/openmrs/module/pihmalawi/PihMalawiWebConstants.java b/omod/src/main/java/org/openmrs/module/pihmalawi/PihMalawiWebConstants.java deleted file mode 100644 index 6213170a..00000000 --- a/omod/src/main/java/org/openmrs/module/pihmalawi/PihMalawiWebConstants.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.openmrs.module.pihmalawi; - - -public final class PihMalawiWebConstants { - - public static final String REQUEST_PARAMETER_NAME_REDIRECT_URL = "redirectUrl"; - - public static final String COOKIE_NAME_LAST_SESSION_LOCATION = "pihmalawi.lastSessionLocation"; - - public static final String SESSION_ATTRIBUTE_REDIRECT_URL = "_REFERENCE_APPLICATION_REDIRECT_URL_"; - - public static final String SESSION_ATTRIBUTE_ERROR_MESSAGE = "_REFERENCE_APPLICATION_ERROR_MESSAGE_"; - - public static final String SESSION_ATTRIBUTE_INFO_MESSAGE = "_REFERENCE_APPLICATION_INFO_MESSAGE_"; - - public static final String SESSION_LOCATION_ID = "emrContext.sessionLocationId"; - - public static final String PATIENT_DASHBOARD_URL = "patientDashboard.form"; -} diff --git a/omod/src/main/java/org/openmrs/module/pihmalawi/fragment/controller/InfoAndErrorMessagesFragmentController.java b/omod/src/main/java/org/openmrs/module/pihmalawi/fragment/controller/InfoAndErrorMessagesFragmentController.java index bb5a2fe2..54337a67 100644 --- a/omod/src/main/java/org/openmrs/module/pihmalawi/fragment/controller/InfoAndErrorMessagesFragmentController.java +++ b/omod/src/main/java/org/openmrs/module/pihmalawi/fragment/controller/InfoAndErrorMessagesFragmentController.java @@ -1,7 +1,7 @@ package org.openmrs.module.pihmalawi.fragment.controller; -import org.openmrs.module.pihmalawi.PihMalawiWebConstants; +import org.openmrs.module.pihmalawi.PihMalawiConstants; import org.openmrs.ui.framework.fragment.FragmentModel; import javax.servlet.http.HttpServletRequest; @@ -11,11 +11,10 @@ public class InfoAndErrorMessagesFragmentController { public void controller(HttpServletRequest request, FragmentModel fragmentModel) { HttpSession session = request.getSession(); - String errorMessage = (String) session - .getAttribute(PihMalawiWebConstants.SESSION_ATTRIBUTE_ERROR_MESSAGE); - String infoMessage = (String) session.getAttribute(PihMalawiWebConstants.SESSION_ATTRIBUTE_INFO_MESSAGE); - session.setAttribute(PihMalawiWebConstants.SESSION_ATTRIBUTE_ERROR_MESSAGE, null); - session.setAttribute(PihMalawiWebConstants.SESSION_ATTRIBUTE_INFO_MESSAGE, null); + String errorMessage = (String) session.getAttribute(PihMalawiConstants.SESSION_ATTRIBUTE_ERROR_MESSAGE); + String infoMessage = (String) session.getAttribute(PihMalawiConstants.SESSION_ATTRIBUTE_INFO_MESSAGE); + session.setAttribute(PihMalawiConstants.SESSION_ATTRIBUTE_ERROR_MESSAGE, null); + session.setAttribute(PihMalawiConstants.SESSION_ATTRIBUTE_INFO_MESSAGE, null); fragmentModel.addAttribute("errorMessage", errorMessage); fragmentModel.addAttribute("infoMessage", infoMessage); } diff --git a/omod/src/main/java/org/openmrs/module/pihmalawi/page/controller/LoginPageController.java b/omod/src/main/java/org/openmrs/module/pihmalawi/page/controller/LoginPageController.java deleted file mode 100644 index f6b8938d..00000000 --- a/omod/src/main/java/org/openmrs/module/pihmalawi/page/controller/LoginPageController.java +++ /dev/null @@ -1,199 +0,0 @@ -package org.openmrs.module.pihmalawi.page.controller; - -import org.apache.commons.lang.StringUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.openmrs.Location; -import org.openmrs.api.LocationService; -import org.openmrs.api.context.Context; -import org.openmrs.api.context.ContextAuthenticationException; -import org.openmrs.module.appframework.service.AppFrameworkService; -import org.openmrs.module.pihmalawi.PihMalawiConstants; -import org.openmrs.module.pihmalawi.PihMalawiWebConstants; -import org.openmrs.module.reporting.common.ObjectUtil; -import org.openmrs.ui.framework.UiUtils; -import org.openmrs.ui.framework.annotation.SpringBean; -import org.openmrs.ui.framework.page.PageModel; -import org.openmrs.ui.framework.page.PageRequest; -import org.openmrs.util.PrivilegeConstants; -import org.openmrs.web.WebConstants; -import org.openmrs.web.user.CurrentUsers; -import org.springframework.web.bind.annotation.CookieValue; -import org.springframework.web.bind.annotation.RequestParam; - -import javax.servlet.http.HttpSession; -import java.util.List; - -public class LoginPageController { - private static final String GET_LOCATIONS = "Get Locations"; - - protected final Log log = LogFactory.getLog(getClass()); - - /** - * @should redirect the user to the home page if they are already authenticated - * @should show the user the login page if they are not authenticated - * @should set redirectUrl in the page model if any was specified in the request - * @should set the referer as the redirectUrl in the page model if no redirect param exists - * @should set redirectUrl in the page model if any was specified in the session - */ - public String get(PageModel model, - UiUtils ui, - PageRequest pageRequest, - @CookieValue(value = PihMalawiWebConstants.COOKIE_NAME_LAST_SESSION_LOCATION, required = false) String lastSessionLocationId, - @SpringBean("locationService") LocationService locationService, - @SpringBean("appFrameworkService") AppFrameworkService appFrameworkService) { - - if (Context.isAuthenticated()) { - return "redirect:findPatient.htm"; - } - - String redirectUrl = ObjectUtil.nvlStr(pageRequest.getRequest().getSession().getAttribute(PihMalawiWebConstants.SESSION_ATTRIBUTE_REDIRECT_URL), ""); - pageRequest.getRequest().getSession().removeAttribute(PihMalawiWebConstants.SESSION_ATTRIBUTE_REDIRECT_URL); - - if (StringUtils.isBlank(redirectUrl)) { - redirectUrl = pageRequest.getRequest().getParameter(PihMalawiWebConstants.REQUEST_PARAMETER_NAME_REDIRECT_URL); - } - if (StringUtils.isBlank(redirectUrl)) { - redirectUrl = pageRequest.getRequest().getHeader("Referer"); - } - if (redirectUrl == null) { - redirectUrl = ""; - } - model.addAttribute(PihMalawiWebConstants.REQUEST_PARAMETER_NAME_REDIRECT_URL, redirectUrl); - - Location lastSessionLocation = null; - List loginLocations = null; - try { - Context.addProxyPrivilege(PrivilegeConstants.GET_LOCATIONS); - Context.addProxyPrivilege(GET_LOCATIONS); - loginLocations = appFrameworkService.getLoginLocations(); - lastSessionLocation = locationService.getLocation(Integer.valueOf(lastSessionLocationId)); - } - catch (Exception ex) { - // pass - } - finally { - Context.removeProxyPrivilege(PrivilegeConstants.GET_LOCATIONS); - Context.removeProxyPrivilege(GET_LOCATIONS); - } - - model.addAttribute("lastSessionLocation", lastSessionLocation); - model.addAttribute("locations", loginLocations); - return null; - } - - /** - * Processes requests to authenticate a user - * - * @param username - * @param password - * @param sessionLocationId - * @param locationService - * @param ui {@link UiUtils} object - * @param pageRequest {@link PageRequest} object - * @return - * @should redirect the user back to the redirectUrl if any - * @should redirect the user to the home page if the redirectUrl is the login page - * @should send the user back to the login page if an invalid location is selected - * @should send the user back to the login page when authentication fails - */ - public String post(@RequestParam(value = "username", required = false) String username, - @RequestParam(value = "password", required = false) String password, - @RequestParam(value = "sessionLocation", required = false) Integer sessionLocationId, - @SpringBean("locationService") LocationService locationService, UiUtils ui, - PageRequest pageRequest - ) { - - String redirectUrl = pageRequest.getRequest().getParameter(PihMalawiWebConstants.REQUEST_PARAMETER_NAME_REDIRECT_URL); - redirectUrl = getRelativeUrl(redirectUrl, pageRequest); - HttpSession httpSession = pageRequest.getRequest().getSession(); - Location sessionLocation = null; - if (sessionLocationId != null && (sessionLocationId != null && sessionLocationId.intValue() > 0)) { - try { - // TODO as above, grant this privilege to Anonymous instead of using a proxy privilege - Context.addProxyPrivilege(PrivilegeConstants.GET_LOCATIONS); - Context.addProxyPrivilege(GET_LOCATIONS); - sessionLocation = locationService.getLocation(sessionLocationId); - } - finally { - Context.removeProxyPrivilege(PrivilegeConstants.GET_LOCATIONS); - Context.removeProxyPrivilege(GET_LOCATIONS); - } - } - - if (sessionLocationId != null) { - // Set a cookie, so next time someone logs in on this machine, we can default to that same location - pageRequest.setCookieValue(PihMalawiWebConstants.COOKIE_NAME_LAST_SESSION_LOCATION, sessionLocationId.toString()); - } - - try { - Context.authenticate(username, password); - - if (Context.isAuthenticated()) { - pageRequest.getRequest().getSession().removeAttribute(WebConstants.OPENMRS_MSG_ATTR); - - CurrentUsers.addUser(httpSession, Context.getAuthenticatedUser()); - - if (log.isDebugEnabled()) { - log.debug("User has successfully authenticated"); - } - - if (sessionLocation != null && httpSession!=null) { - httpSession.setAttribute(PihMalawiWebConstants.SESSION_LOCATION_ID, sessionLocation.getId()); - } - - if (StringUtils.isNotBlank(redirectUrl)) { - //don't redirect back to the login page on success nor an external url - if (!redirectUrl.contains("login.")) { - if (log.isDebugEnabled()) - log.debug("Redirecting user to " + redirectUrl); - - return "redirect:" + redirectUrl; - } else { - if (log.isDebugEnabled()) - log.debug("Redirect contains 'login.', redirecting to home page"); - } - } - - return "redirect:/openmrs/findPatient.htm"; - } - } - catch (ContextAuthenticationException ex) { - if (log.isDebugEnabled()) - log.debug("Failed to authenticate user"); - - pageRequest.getSession().setAttribute(PihMalawiWebConstants.SESSION_ATTRIBUTE_ERROR_MESSAGE, - ui.message(PihMalawiConstants.MODULE_ID + ".error.login.fail")); - } - - - - if (log.isDebugEnabled()) - log.debug("Sending user back to login page"); - - pageRequest.getSession().setAttribute(PihMalawiWebConstants.SESSION_ATTRIBUTE_REDIRECT_URL, redirectUrl); - - return "redirect:" + ui.pageLink(PihMalawiConstants.MODULE_ID, "login"); - } - - public String getRelativeUrl(String url, PageRequest pageRequest) { - if (url == null) - return null; - - if (url.startsWith("/") || (!url.startsWith("http://") && !url.startsWith("https://"))) { - return url; - } - - //This is an absolute url, discard the protocal, domain name/host and port section - int indexOfContextPath = url.indexOf(pageRequest.getRequest().getContextPath()); - if (indexOfContextPath >= 0) { - url = url.substring(indexOfContextPath); - log.debug("Relative redirect:" + url); - - return url; - } - - return null; - } - -} diff --git a/omod/src/main/java/org/openmrs/module/pihmalawi/web/controller/QuickProgramsFormController.java b/omod/src/main/java/org/openmrs/module/pihmalawi/web/controller/QuickProgramsFormController.java index c3c7965d..a7d18589 100644 --- a/omod/src/main/java/org/openmrs/module/pihmalawi/web/controller/QuickProgramsFormController.java +++ b/omod/src/main/java/org/openmrs/module/pihmalawi/web/controller/QuickProgramsFormController.java @@ -7,7 +7,6 @@ import org.openmrs.ProgramWorkflowState; import org.openmrs.api.ProgramWorkflowService; import org.openmrs.api.context.Context; -import org.openmrs.module.pihmalawi.PihMalawiWebConstants; import org.openmrs.web.WebConstants; import org.springframework.beans.propertyeditors.CustomDateEditor; import org.springframework.stereotype.Controller; diff --git a/omod/src/main/resources/config.xml b/omod/src/main/resources/config.xml index 959e0142..e09709d7 100644 --- a/omod/src/main/resources/config.xml +++ b/omod/src/main/resources/config.xml @@ -9,15 +9,12 @@ Partners In Health PIH Malawi Implementation Module org.openmrs.module.pihmalawi.activator.PihMalawiModuleActivator - 1.9.7 - - - org.openmrs.module.legacyui - - + ${openMRSVersion} org.openmrs.module.addresshierarchy org.openmrs.module.appframework + org.openmrs.module.authentication + org.openmrs.module.authenticationui org.openmrs.module.appui org.openmrs.calculation org.openmrs.module.emrapi @@ -26,6 +23,8 @@ org.openmrs.module.htmlformentryui org.openmrs.module.htmlwidgets org.openmrs.module.idgen + org.openmrs.module.initializer + org.openmrs.module.legacyui org.openmrs.module.metadatadeploy org.openmrs.module.metadatamapping org.openmrs.module.metadatasharing diff --git a/omod/src/main/webapp/pages/login.gsp b/omod/src/main/webapp/pages/login.gsp deleted file mode 100644 index 6ba7f1ea..00000000 --- a/omod/src/main/webapp/pages/login.gsp +++ /dev/null @@ -1,139 +0,0 @@ -<% - ui.includeFragment("appui", "standardEmrIncludes") - ui.includeCss("pihmalawi", "login.css") -%> - - - - - ${ ui.message("pihmalawi.login.title") } - - - ${ ui.resourceLinks() } - - - - - -${ ui.includeFragment("pihmalawi", "infoAndErrorMessages") } - - - -
- -
- -
-
-
-
- - - - ${ ui.message("pihmalawi.login.loginHeading") } - - -

- - -

- -

- - -

- -

- -

    -
  • No Location
  • - <% locations.sort { ui.format(it) }.each { %> -
  • ${ui.format(it)}
  • - <% } %> -
-

- - value="${lastSessionLocation.id}" <% } %> /> - -

-

- -

-

- - - ${ ui.message("pihmalawi.login.cannotLogin") } - -

- -
- - - -
- -
-
- - - - - \ No newline at end of file diff --git a/omod/src/main/webapp/resources/styles/login.css b/omod/src/main/webapp/resources/styles/login.css deleted file mode 100644 index bcf80d09..00000000 --- a/omod/src/main/webapp/resources/styles/login.css +++ /dev/null @@ -1,6 +0,0 @@ -#login-form ul.select { - width: 850px; -} -#login-form p input[type=text], #login-form p input[type=password] { - width: 405px; -} diff --git a/pom.xml b/pom.xml index e3cd5d73..2ef5bcf1 100644 --- a/pom.xml +++ b/pom.xml @@ -38,37 +38,40 @@ 2.5.8-SNAPSHOT 2.15.0 - 2.17.0-SNAPSHOT + 2.17.0 1.16.0 + 1.0.0-SNAPSHOT + 1.0.0-SNAPSHOT 1.3.0 - 1.38.0-SNAPSHOT + 1.38.0 1.33.0 2.10.0 - 1.7.0-SNAPSHOT + 1.7.0 5.1.0-SNAPSHOT 2.3.0-SNAPSHOT 1.10.0 4.8.0 + 2.4.0 2.2.4 - 1.13.0-SNAPSHOT + 1.14.0-SNAPSHOT 1.13.0 - 1.5.0 + 1.6.0 1.8.0 2.0.0-SNAPSHOT 1.13.0 - 2.13.0 + 2.14.0 1.25.0-SNAPSHOT 1.11.0 2.0.9-SNAPSHOT 1.25.0 1.13.0 - 1.11.0-SNAPSHOT - 0.2.15 - 1.0.8 + 1.11.0 + 0.2.16 + 1.0.9 3.0.0-SNAPSHOT 1.7.0 - 2.23.0-SNAPSHOT - 3.22.1 + 2.23.0 + 3.23.0 2.0.7 2.2.0-SNAPSHOT 2.37.0-SNAPSHOT @@ -88,6 +91,20 @@ 2.3 compile + + org.openmrs.module + authentication-api + ${authenticationVersion} + jar + provided + + + org.openmrs.module + authenticationui-api + ${authenticationuiVersion} + jar + provided + org.openmrs.module appui-api @@ -134,6 +151,30 @@ jar provided + + org.openmrs.module + fhir2-api + ${fhir2Version} + provided + + + org.openmrs.module + fhir2-api-2.1 + ${fhir2Version} + provided + + + org.openmrs.module + fhir2-api-2.2 + ${fhir2Version} + provided + + + org.openmrs.module + fhir2-api-2.5 + ${fhir2Version} + provided + org.openmrs.module htmlformentry-api @@ -161,6 +202,34 @@ jar provided + + org.openmrs.module + initializer-api + ${initializerVersion} + jar + provided + + + org.openmrs.module + initializer-api-2.2 + ${initializerVersion} + jar + provided + + + org.openmrs.module + initializer-api-2.3 + ${initializerVersion} + jar + provided + + + org.openmrs.module + initializer-api-2.4 + ${initializerVersion} + jar + provided + org.openmrs.module metadatadeploy-api From 348796beb016406fc7f84f05143c07f76257489c Mon Sep 17 00:00:00 2001 From: Michael Seaton Date: Mon, 5 Dec 2022 19:19:34 -0500 Subject: [PATCH 3/3] Increment module versions --- pom.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index 2ef5bcf1..57cb2eed 100644 --- a/pom.xml +++ b/pom.xml @@ -49,16 +49,16 @@ 1.7.0 5.1.0-SNAPSHOT 2.3.0-SNAPSHOT - 1.10.0 - 4.8.0 + 1.11.0 + 4.9.0 2.4.0 2.2.4 1.14.0-SNAPSHOT 1.13.0 1.6.0 - 1.8.0 + 1.9.0 2.0.0-SNAPSHOT - 1.13.0 + 1.14.0 2.14.0 1.25.0-SNAPSHOT 1.11.0