dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #41545
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 21166: Impl read-only mode configuration. Useful for read-only database replicas.
------------------------------------------------------------
revno: 21166
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2015-11-23 10:51:36 +0100
message:
Impl read-only mode configuration. Useful for read-only database replicas.
modified:
dhis-2/dhis-support/dhis-support-external/src/main/java/org/hisp/dhis/external/conf/ConfigurationKey.java
dhis-2/dhis-support/dhis-support-external/src/main/java/org/hisp/dhis/external/conf/DefaultDhisConfigurationProvider.java
dhis-2/dhis-support/dhis-support-external/src/main/java/org/hisp/dhis/external/conf/DhisConfigurationProvider.java
dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/startup/DefaultStartupRoutineExecutor.java
dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/security/DefaultAuthenticationSuccessHandler.java
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-support/dhis-support-external/src/main/java/org/hisp/dhis/external/conf/ConfigurationKey.java'
--- dhis-2/dhis-support/dhis-support-external/src/main/java/org/hisp/dhis/external/conf/ConfigurationKey.java 2015-11-12 16:02:05 +0000
+++ dhis-2/dhis-support/dhis-support-external/src/main/java/org/hisp/dhis/external/conf/ConfigurationKey.java 2015-11-23 09:51:36 +0000
@@ -34,6 +34,7 @@
public enum ConfigurationKey
{
SYSTEM_ID( "system.id" ),
+ SYSTEM_READ_ONLY_MODE( "system.read_only_mode", "off" ),
CONNECTION_DIALECT( "connection.dialect" ),
CONNECTION_DRIVER_CLASS( "connection.driver_class" ),
CONNECTION_URL( "connection.url" ),
=== modified file 'dhis-2/dhis-support/dhis-support-external/src/main/java/org/hisp/dhis/external/conf/DefaultDhisConfigurationProvider.java'
--- dhis-2/dhis-support/dhis-support-external/src/main/java/org/hisp/dhis/external/conf/DefaultDhisConfigurationProvider.java 2015-11-10 23:04:08 +0000
+++ dhis-2/dhis-support/dhis-support-external/src/main/java/org/hisp/dhis/external/conf/DefaultDhisConfigurationProvider.java 2015-11-23 09:51:36 +0000
@@ -46,6 +46,7 @@
private static final Log log = LogFactory.getLog( DefaultDhisConfigurationProvider.class );
private static final String CONF_FILENAME = "dhis.conf";
+ private static final String ENABLED_VALUE = "on";
// -------------------------------------------------------------------------
// Dependencies
@@ -123,6 +124,12 @@
{
return properties.getProperty( key.getKey(), defaultValue );
}
+
+ @Override
+ public boolean isEnabled( ConfigurationKey key )
+ {
+ return ENABLED_VALUE.equals( getProperty( key ) );
+ }
@Override
public boolean isLdapConfigured()
=== modified file 'dhis-2/dhis-support/dhis-support-external/src/main/java/org/hisp/dhis/external/conf/DhisConfigurationProvider.java'
--- dhis-2/dhis-support/dhis-support-external/src/main/java/org/hisp/dhis/external/conf/DhisConfigurationProvider.java 2015-11-10 23:04:08 +0000
+++ dhis-2/dhis-support/dhis-support-external/src/main/java/org/hisp/dhis/external/conf/DhisConfigurationProvider.java 2015-11-23 09:51:36 +0000
@@ -65,6 +65,14 @@
String getPropertyOrDefault( ConfigurationKey key, String defaultValue );
/**
+ * Indicates whether a value for the given key is equal to "on".
+ *
+ * @param key the configuration key.
+ * @return true if the configuration key is enabled.
+ */
+ boolean isEnabled( ConfigurationKey key );
+
+ /**
* Indicates whether LDAP authentication is configured.
*
* @return true if LDAP authentication is configured.
=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/startup/DefaultStartupRoutineExecutor.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/startup/DefaultStartupRoutineExecutor.java 2015-05-30 13:36:07 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/startup/DefaultStartupRoutineExecutor.java 2015-11-23 09:51:36 +0000
@@ -35,6 +35,9 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.hisp.dhis.external.conf.ConfigurationKey;
+import org.hisp.dhis.external.conf.DhisConfigurationProvider;
+import org.springframework.beans.factory.annotation.Autowired;
/**
* Default implementation of StartupRoutineExecutor. The execute method will
@@ -54,6 +57,9 @@
private static final String TRUE = "true";
private static final String SKIP_PROP = "dhis.skip.startup";
+ @Autowired
+ private DhisConfigurationProvider config;
+
private List<StartupRoutine> routines = new ArrayList<>();
// -------------------------------------------------------------------------
@@ -98,7 +104,13 @@
{
if ( TRUE.equalsIgnoreCase( System.getProperty( SKIP_PROP ) ) )
{
- LOG.info( "Skipping startup routines" );
+ LOG.info( "Skipping startup routines, system property " + SKIP_PROP + " is true" );
+ return;
+ }
+
+ if ( config.isEnabled( ConfigurationKey.SYSTEM_READ_ONLY_MODE ) )
+ {
+ LOG.info( "Skipping startup routines, read-only mode is enabled" );
return;
}
=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/security/DefaultAuthenticationSuccessHandler.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/security/DefaultAuthenticationSuccessHandler.java 2015-10-27 03:18:11 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/security/DefaultAuthenticationSuccessHandler.java 2015-11-23 09:51:36 +0000
@@ -35,6 +35,8 @@
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
+import org.hisp.dhis.external.conf.ConfigurationKey;
+import org.hisp.dhis.external.conf.DhisConfigurationProvider;
import org.hisp.dhis.security.intercept.LoginInterceptor;
import org.hisp.dhis.user.UserCredentials;
import org.hisp.dhis.user.UserService;
@@ -63,6 +65,9 @@
@Autowired
private UserService userService;
+
+ @Autowired
+ private DhisConfigurationProvider config;
@Override
public void onAuthenticationSuccess( HttpServletRequest request, HttpServletResponse response, Authentication authentication )
@@ -87,7 +92,9 @@
UserCredentials credentials = userService.getUserCredentialsByUsername( username );
- if ( credentials != null )
+ boolean readOnly = config.isEnabled( ConfigurationKey.SYSTEM_READ_ONLY_MODE );
+
+ if ( credentials != null && !readOnly )
{
credentials.updateLastLogin();
userService.updateUserCredentials( credentials );