Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

7.x #125

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

7.x #125

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.openmrs.module</groupId>
<artifactId>pihmalawi</artifactId>
<version>6.9.0-SNAPSHOT</version>
<version>7.0.0-SNAPSHOT</version>
</parent>
<groupId>org.openmrs.module</groupId>
<artifactId>pihmalawi-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Original file line number Diff line number Diff line change
@@ -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<String> 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<String> 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<String> 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);
}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public List<Initializer> getInitializers() {
l.add(new AddressTemplateInitializer());
l.add(new HtmlFormInitializer());
l.add(new ReportInitializer());
l.add(new AuthenticationInitializer());
return l;
}

Expand Down
38 changes: 38 additions & 0 deletions api/src/main/resources/apps/authenticationui_extension.json
Original file line number Diff line number Diff line change
@@ -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
}
}
]
14 changes: 13 additions & 1 deletion api/src/test/resources/log4j.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,17 @@
<level value="FATAL" />
<appender-ref ref="CONSOLE" />
</logger>

<logger name="org.hibernate">
<level value="ERROR" />
<appender-ref ref="CONSOLE" />
</logger>
<logger name="org.hibernate.orm.deprecation" additivity="false">
<level value="ERROR" />
<appender-ref ref="CONSOLE" />
</logger>
<logger name="org.hibernate.engine.internal.StatefulPersistenceContext" additivity="false">
<level value="ERROR" />
<appender-ref ref="CONSOLE" />
</logger>

</log4j:configuration>
3 changes: 3 additions & 0 deletions distro/openmrs-distro.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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}
Expand Down
2 changes: 1 addition & 1 deletion distro/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.openmrs.module</groupId>
<artifactId>pihmalawi</artifactId>
<version>6.9.0-SNAPSHOT</version>
<version>7.0.0-SNAPSHOT</version>
</parent>

<groupId>org.openmrs.distro</groupId>
Expand Down
2 changes: 1 addition & 1 deletion omod/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>org.openmrs.module</groupId>
<artifactId>pihmalawi</artifactId>
<version>6.9.0-SNAPSHOT</version>
<version>7.0.0-SNAPSHOT</version>
</parent>
<groupId>org.openmrs.module</groupId>
<artifactId>pihmalawi-omod</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,4 @@ public String showOurHomepage() {
return "forward:/findPatient.htm";
}

@RequestMapping("/login.htm")
public String showLoginHomepage() {
return "forward:/pihmalawi/login.page";
}

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
}
Expand Down
Loading