From d006fa229175bde92cd48b0081fd503fadf0f22f Mon Sep 17 00:00:00 2001 From: Samuel Githengi Date: Mon, 21 May 2018 16:19:51 +0300 Subject: [PATCH 01/13] Add CouchDB dependencies for beans not implemented on Postgres --- opensrp-core/src/main/resources/persistence_postgres.xml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/opensrp-core/src/main/resources/persistence_postgres.xml b/opensrp-core/src/main/resources/persistence_postgres.xml index 62ecde7657..8e7706becd 100644 --- a/opensrp-core/src/main/resources/persistence_postgres.xml +++ b/opensrp-core/src/main/resources/persistence_postgres.xml @@ -47,4 +47,12 @@ + + + + + + + + \ No newline at end of file From 69b40e72a448826fccaea19cd9c32e13d3cf807d Mon Sep 17 00:00:00 2001 From: Samuel Githengi Date: Mon, 21 May 2018 16:21:31 +0300 Subject: [PATCH 02/13] Redis cache configuration --- .../resources/applicationContext-opensrp.xml | 16 +++++++++++++++- opensrp-web/pom.xml | 16 ++++++++++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/opensrp-core/src/main/resources/applicationContext-opensrp.xml b/opensrp-core/src/main/resources/applicationContext-opensrp.xml index 0caa5d75af..627d0996f6 100644 --- a/opensrp-core/src/main/resources/applicationContext-opensrp.xml +++ b/opensrp-core/src/main/resources/applicationContext-opensrp.xml @@ -2,6 +2,7 @@ - + + + + + + + + + diff --git a/opensrp-web/pom.xml b/opensrp-web/pom.xml index 115c8c8668..461b378328 100644 --- a/opensrp-web/pom.xml +++ b/opensrp-web/pom.xml @@ -267,8 +267,20 @@ 3.1 --> - - + + + org.springframework.data + spring-data-redis + 1.3.6.RELEASE + + + + + redis.clients + jedis + 2.4.1 + + From fa2a61e4bfebb491c7373634549ef00189dd840e Mon Sep 17 00:00:00 2001 From: Samuel Githengi Date: Mon, 21 May 2018 16:21:59 +0300 Subject: [PATCH 03/13] Redis cache OpenMRS authentication --- .../DrishtiAuthenticationProvider.java | 164 +++++++++++------- 1 file changed, 98 insertions(+), 66 deletions(-) diff --git a/opensrp-web/src/main/java/org/opensrp/web/security/DrishtiAuthenticationProvider.java b/opensrp-web/src/main/java/org/opensrp/web/security/DrishtiAuthenticationProvider.java index 2548d23a0d..a9d35bd7bf 100644 --- a/opensrp-web/src/main/java/org/opensrp/web/security/DrishtiAuthenticationProvider.java +++ b/opensrp-web/src/main/java/org/opensrp/web/security/DrishtiAuthenticationProvider.java @@ -3,14 +3,18 @@ import static java.text.MessageFormat.format; import java.util.List; +import java.util.concurrent.TimeUnit; + +import javax.annotation.Resource; -import org.json.JSONException; import org.opensrp.api.domain.User; import org.opensrp.connector.openmrs.service.OpenmrsUserService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.data.redis.core.HashOperations; +import org.springframework.data.redis.core.RedisTemplate; import org.springframework.security.authentication.AuthenticationProvider; import org.springframework.security.authentication.BadCredentialsException; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; @@ -18,6 +22,7 @@ import org.springframework.security.core.Authentication; import org.springframework.security.core.AuthenticationException; import org.springframework.security.core.authority.SimpleGrantedAuthority; +import org.springframework.security.web.authentication.WebAuthenticationDetails; import org.springframework.stereotype.Component; import ch.lambdaj.Lambda; @@ -25,70 +30,97 @@ @Component public class DrishtiAuthenticationProvider implements AuthenticationProvider { - private static Logger logger = LoggerFactory.getLogger(DrishtiAuthenticationProvider.class.toString()); - public static final String USER_NOT_FOUND = "The username or password you entered is incorrect. Please enter the correct credentials."; - public static final String USER_NOT_ACTIVATED = "The user has been registered but not activated. Please contact your local administrator."; - public static final String INTERNAL_ERROR = "Failed to authenticate user due to internal server error."; - - //private AllOpenSRPUsers allOpenSRPUsers; - private PasswordEncoder passwordEncoder; - private OpenmrsUserService openmrsUserService; - - - @Autowired - public DrishtiAuthenticationProvider(OpenmrsUserService openmrsUserService, @Qualifier("shaPasswordEncoder") PasswordEncoder passwordEncoder) { - this.openmrsUserService = openmrsUserService; - this.passwordEncoder = passwordEncoder; - } - - @Override - public Authentication authenticate(Authentication authentication) throws AuthenticationException { - User user = getDrishtiUser(authentication, authentication.getName()); - // get user after authentication - if (user == null) { - throw new BadCredentialsException(USER_NOT_FOUND); - } - - if (user.getVoided() != null && user.getVoided()) { - throw new BadCredentialsException(USER_NOT_ACTIVATED); - } - - return new UsernamePasswordAuthenticationToken(authentication.getName(), authentication.getCredentials(), getRolesAsAuthorities(user)); - } - - @Override - public boolean supports(Class authentication) { - return UsernamePasswordAuthenticationToken.class.isAssignableFrom(authentication) - && authentication.equals(UsernamePasswordAuthenticationToken.class); - } - - private List getRolesAsAuthorities(User user) { - return Lambda.convert(user.getRoles(), new Converter() { - @Override - public SimpleGrantedAuthority convert(String role) { - return new SimpleGrantedAuthority("ROLE_OPENMRS"); - } - }); - } - - - - public User getDrishtiUser(Authentication authentication, String username) { - User user = null; - try { - if(openmrsUserService.authenticate(authentication.getName(), authentication.getCredentials().toString())){ - boolean response = openmrsUserService.deleteSession(authentication.getName(),authentication.getCredentials().toString()); - user = openmrsUserService.getUser(username); - if(!response){ - logger.error(format("{0}. Exception: {1}", INTERNAL_ERROR, "Unable to clear session")); - - } + + private static Logger logger = LoggerFactory.getLogger(DrishtiAuthenticationProvider.class.toString()); + + public static final String USER_NOT_FOUND = "The username or password you entered is incorrect. Please enter the correct credentials."; + + public static final String USER_NOT_ACTIVATED = "The user has been registered but not activated. Please contact your local administrator."; + + public static final String INTERNAL_ERROR = "Failed to authenticate user due to internal server error."; + + private static final Integer HASH_KEY = 1; + + //private AllOpenSRPUsers allOpenSRPUsers; + private PasswordEncoder passwordEncoder; + + private OpenmrsUserService openmrsUserService; + + @Resource(name = "redisTemplate") + private HashOperations hashOps; + + @Autowired + private RedisTemplate redisTemplate; + + @Autowired + public DrishtiAuthenticationProvider(OpenmrsUserService openmrsUserService, + @Qualifier("shaPasswordEncoder") PasswordEncoder passwordEncoder) { + this.openmrsUserService = openmrsUserService; + this.passwordEncoder = passwordEncoder; + } + + @Override + public Authentication authenticate(Authentication authentication) throws AuthenticationException { + String userAddress = ((WebAuthenticationDetails) authentication.getDetails()).getRemoteAddress(); + String key = userAddress + "|" + authentication.getName(); + if (hashOps.hasKey(key, HASH_KEY)) { + logger.debug("Cache hit for: " + key); + return hashOps.get(key, HASH_KEY); + } else { + logger.debug("Cache miss for: " + key); + User user = getDrishtiUser(authentication, authentication.getName()); + // get user after authentication + if (user == null) { + throw new BadCredentialsException(USER_NOT_FOUND); + } + + if (user.getVoided() != null && user.getVoided()) { + throw new BadCredentialsException(USER_NOT_ACTIVATED); + } + + Authentication auth = new UsernamePasswordAuthenticationToken(authentication.getName(), + authentication.getCredentials(), getRolesAsAuthorities(user)); + hashOps.put(key, HASH_KEY, auth); + redisTemplate.expire(key, 10, TimeUnit.MINUTES); + return new UsernamePasswordAuthenticationToken(authentication.getName(), authentication.getCredentials(), + getRolesAsAuthorities(user)); + } + } + + @Override + public boolean supports(Class authentication) { + return UsernamePasswordAuthenticationToken.class.isAssignableFrom(authentication) + && authentication.equals(UsernamePasswordAuthenticationToken.class); + } + + private List getRolesAsAuthorities(User user) { + return Lambda.convert(user.getRoles(), new Converter() { + + @Override + public SimpleGrantedAuthority convert(String role) { + return new SimpleGrantedAuthority("ROLE_OPENMRS"); + } + }); + } + + public User getDrishtiUser(Authentication authentication, String username) { + User user = null; + try { + if (openmrsUserService.authenticate(authentication.getName(), authentication.getCredentials().toString())) { + boolean response = openmrsUserService.deleteSession(authentication.getName(), + authentication.getCredentials().toString()); + user = openmrsUserService.getUser(username); + if (!response) { + logger.error(format("{0}. Exception: {1}", INTERNAL_ERROR, "Unable to clear session")); + + } } - } catch (Exception e) { - logger.error(format("{0}. Exception: {1}", INTERNAL_ERROR, e)); - e.printStackTrace(); - throw new BadCredentialsException(INTERNAL_ERROR); - } - return user; - } + } + catch (Exception e) { + logger.error(format("{0}. Exception: {1}", INTERNAL_ERROR, e)); + e.printStackTrace(); + throw new BadCredentialsException(INTERNAL_ERROR); + } + return user; + } } From 5490c7f9dc42f303c96ce112b9b784ca8998e53d Mon Sep 17 00:00:00 2001 From: Samuel Githengi Date: Mon, 21 May 2018 16:39:18 +0300 Subject: [PATCH 04/13] Move cache TTL to properties file, compare if credentials are similar before returned cached version --- assets/config/opensrp.properties | 3 ++ .../main/resources/persistence_postgres.xml | 2 + .../DrishtiAuthenticationProvider.java | 43 +++++++++++-------- 3 files changed, 30 insertions(+), 18 deletions(-) diff --git a/assets/config/opensrp.properties b/assets/config/opensrp.properties index 3d1ebfa523..c9c5beef80 100644 --- a/assets/config/opensrp.properties +++ b/assets/config/opensrp.properties @@ -90,3 +90,6 @@ opensrp.site.url="" #search for missing clients opensrp.sync.search.missing.client=false + +#duration in seconds to cache authetication time to live +opensrp.authencation.cache.ttl=600 \ No newline at end of file diff --git a/opensrp-core/src/main/resources/persistence_postgres.xml b/opensrp-core/src/main/resources/persistence_postgres.xml index 8e7706becd..a211a7ac89 100644 --- a/opensrp-core/src/main/resources/persistence_postgres.xml +++ b/opensrp-core/src/main/resources/persistence_postgres.xml @@ -55,4 +55,6 @@ + + \ No newline at end of file diff --git a/opensrp-web/src/main/java/org/opensrp/web/security/DrishtiAuthenticationProvider.java b/opensrp-web/src/main/java/org/opensrp/web/security/DrishtiAuthenticationProvider.java index a9d35bd7bf..52dc493c38 100644 --- a/opensrp-web/src/main/java/org/opensrp/web/security/DrishtiAuthenticationProvider.java +++ b/opensrp-web/src/main/java/org/opensrp/web/security/DrishtiAuthenticationProvider.java @@ -13,6 +13,7 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.beans.factory.annotation.Value; import org.springframework.data.redis.core.HashOperations; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.security.authentication.AuthenticationProvider; @@ -52,6 +53,9 @@ public class DrishtiAuthenticationProvider implements AuthenticationProvider { @Autowired private RedisTemplate redisTemplate; + @Value("#{opensrp['opensrp.authencation.cache.ttl']}") + private int cacheTTL; + @Autowired public DrishtiAuthenticationProvider(OpenmrsUserService openmrsUserService, @Qualifier("shaPasswordEncoder") PasswordEncoder passwordEncoder) { @@ -62,29 +66,32 @@ public DrishtiAuthenticationProvider(OpenmrsUserService openmrsUserService, @Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { String userAddress = ((WebAuthenticationDetails) authentication.getDetails()).getRemoteAddress(); - String key = userAddress + "|" + authentication.getName(); + String key = userAddress + authentication.getName(); if (hashOps.hasKey(key, HASH_KEY)) { logger.debug("Cache hit for: " + key); - return hashOps.get(key, HASH_KEY); + Authentication auth = hashOps.get(key, HASH_KEY); + if (auth.getCredentials().equals(authentication.getCredentials())) + return auth; } else { logger.debug("Cache miss for: " + key); - User user = getDrishtiUser(authentication, authentication.getName()); - // get user after authentication - if (user == null) { - throw new BadCredentialsException(USER_NOT_FOUND); - } - - if (user.getVoided() != null && user.getVoided()) { - throw new BadCredentialsException(USER_NOT_ACTIVATED); - } - - Authentication auth = new UsernamePasswordAuthenticationToken(authentication.getName(), - authentication.getCredentials(), getRolesAsAuthorities(user)); - hashOps.put(key, HASH_KEY, auth); - redisTemplate.expire(key, 10, TimeUnit.MINUTES); - return new UsernamePasswordAuthenticationToken(authentication.getName(), authentication.getCredentials(), - getRolesAsAuthorities(user)); } + User user = getDrishtiUser(authentication, authentication.getName()); + // get user after authentication + if (user == null) { + throw new BadCredentialsException(USER_NOT_FOUND); + } + + if (user.getVoided() != null && user.getVoided()) { + throw new BadCredentialsException(USER_NOT_ACTIVATED); + } + + Authentication auth = new UsernamePasswordAuthenticationToken(authentication.getName(), + authentication.getCredentials(), getRolesAsAuthorities(user)); + hashOps.put(key, HASH_KEY, auth); + redisTemplate.expire(key, cacheTTL, TimeUnit.SECONDS); + return new UsernamePasswordAuthenticationToken(authentication.getName(), authentication.getCredentials(), + getRolesAsAuthorities(user)); + } @Override From 7f32be76b587684c79dacf197c7d67e000ef7513 Mon Sep 17 00:00:00 2001 From: Samuel Githengi Date: Mon, 21 May 2018 16:56:23 +0300 Subject: [PATCH 05/13] If credentials are not equals to cached eject cached and autheticate again --- .../security/DrishtiAuthenticationProvider.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/opensrp-web/src/main/java/org/opensrp/web/security/DrishtiAuthenticationProvider.java b/opensrp-web/src/main/java/org/opensrp/web/security/DrishtiAuthenticationProvider.java index 52dc493c38..846d7a63cb 100644 --- a/opensrp-web/src/main/java/org/opensrp/web/security/DrishtiAuthenticationProvider.java +++ b/opensrp-web/src/main/java/org/opensrp/web/security/DrishtiAuthenticationProvider.java @@ -40,7 +40,7 @@ public class DrishtiAuthenticationProvider implements AuthenticationProvider { public static final String INTERNAL_ERROR = "Failed to authenticate user due to internal server error."; - private static final Integer HASH_KEY = 1; + private static final String AUTH_HASH_KEY = "_auth"; //private AllOpenSRPUsers allOpenSRPUsers; private PasswordEncoder passwordEncoder; @@ -48,7 +48,7 @@ public class DrishtiAuthenticationProvider implements AuthenticationProvider { private OpenmrsUserService openmrsUserService; @Resource(name = "redisTemplate") - private HashOperations hashOps; + private HashOperations hashOps; @Autowired private RedisTemplate redisTemplate; @@ -67,13 +67,14 @@ public DrishtiAuthenticationProvider(OpenmrsUserService openmrsUserService, public Authentication authenticate(Authentication authentication) throws AuthenticationException { String userAddress = ((WebAuthenticationDetails) authentication.getDetails()).getRemoteAddress(); String key = userAddress + authentication.getName(); - if (hashOps.hasKey(key, HASH_KEY)) { - logger.debug("Cache hit for: " + key); - Authentication auth = hashOps.get(key, HASH_KEY); + if (hashOps.hasKey(key, AUTH_HASH_KEY)) { + Authentication auth = hashOps.get(key, AUTH_HASH_KEY); + //if credentials is same as cached returned cached else eject cached authentication if (auth.getCredentials().equals(authentication.getCredentials())) return auth; - } else { - logger.debug("Cache miss for: " + key); + else + hashOps.delete(key, AUTH_HASH_KEY); + } User user = getDrishtiUser(authentication, authentication.getName()); // get user after authentication @@ -87,7 +88,7 @@ public Authentication authenticate(Authentication authentication) throws Authent Authentication auth = new UsernamePasswordAuthenticationToken(authentication.getName(), authentication.getCredentials(), getRolesAsAuthorities(user)); - hashOps.put(key, HASH_KEY, auth); + hashOps.put(key, AUTH_HASH_KEY, auth); redisTemplate.expire(key, cacheTTL, TimeUnit.SECONDS); return new UsernamePasswordAuthenticationToken(authentication.getName(), authentication.getCredentials(), getRolesAsAuthorities(user)); From f7f0548ec0c5d91e8dd627c5e8ae68a440fa7c1b Mon Sep 17 00:00:00 2001 From: Samuel Githengi Date: Mon, 21 May 2018 17:38:41 +0300 Subject: [PATCH 06/13] Move redis connection properties to properties file --- assets/config/opensrp.properties | 7 ++++++- .../src/main/resources/applicationContext-opensrp.xml | 3 ++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/assets/config/opensrp.properties b/assets/config/opensrp.properties index c9c5beef80..09632b8151 100644 --- a/assets/config/opensrp.properties +++ b/assets/config/opensrp.properties @@ -92,4 +92,9 @@ opensrp.site.url="" opensrp.sync.search.missing.client=false #duration in seconds to cache authetication time to live -opensrp.authencation.cache.ttl=600 \ No newline at end of file +opensrp.authencation.cache.ttl=600 + +#redis settings +redis.host=localhost +redis.port=6379 +redis.password=RedI$P@S5 \ No newline at end of file diff --git a/opensrp-core/src/main/resources/applicationContext-opensrp.xml b/opensrp-core/src/main/resources/applicationContext-opensrp.xml index 627d0996f6..7774ea959e 100644 --- a/opensrp-core/src/main/resources/applicationContext-opensrp.xml +++ b/opensrp-core/src/main/resources/applicationContext-opensrp.xml @@ -36,7 +36,8 @@ + p:host-name="${redis.host}" p:port="${redis.port}" p:password="${redis.password}" + p:use-pool="true"> From 47cdeacd190df7e4c67adc5f11c07055837ce2c3 Mon Sep 17 00:00:00 2001 From: Samuel Githengi Date: Tue, 22 May 2018 09:33:34 +0300 Subject: [PATCH 07/13] Multimedia controller authentication set http request --- .../main/resources/persistence_postgres.xml | 2 +- .../web/controller/MultimediaController.java | 20 +++++++++++-------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/opensrp-core/src/main/resources/persistence_postgres.xml b/opensrp-core/src/main/resources/persistence_postgres.xml index a211a7ac89..621a3abaad 100644 --- a/opensrp-core/src/main/resources/persistence_postgres.xml +++ b/opensrp-core/src/main/resources/persistence_postgres.xml @@ -47,7 +47,7 @@ - + diff --git a/opensrp-web/src/main/java/org/opensrp/web/controller/MultimediaController.java b/opensrp-web/src/main/java/org/opensrp/web/controller/MultimediaController.java index d2b5d1fb61..0bd7f6c948 100644 --- a/opensrp-web/src/main/java/org/opensrp/web/controller/MultimediaController.java +++ b/opensrp-web/src/main/java/org/opensrp/web/controller/MultimediaController.java @@ -11,6 +11,7 @@ import java.net.URLConnection; import java.nio.charset.Charset; +import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.opensrp.domain.Multimedia; @@ -26,6 +27,8 @@ import org.springframework.http.ResponseEntity; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.core.Authentication; +import org.springframework.security.web.authentication.WebAuthenticationDetails; +import org.springframework.security.web.authentication.WebAuthenticationDetailsSource; import org.springframework.stereotype.Controller; import org.springframework.util.FileCopyUtils; import org.springframework.web.bind.annotation.PathVariable; @@ -68,11 +71,11 @@ public class MultimediaController { @RequestMapping(value = "/download/{fileName:.+}", method = RequestMethod.GET) public void downloadFile(HttpServletResponse response, @PathVariable("fileName") String fileName, @RequestHeader(value = "username") String userName, - @RequestHeader(value = "password") String password) + @RequestHeader(value = "password") String password, HttpServletRequest request) throws Exception { try { - if (authenticate(userName, password).isAuthenticated()) { + if (authenticate(userName, password, request).isAuthenticated()) { File file = new File(multiMediaDir + File.separator + "images" + File.separator + fileName); if (fileName.endsWith("mp4")) { file = new File(multiMediaDir + File.separator + "videos" + File.separator + fileName); @@ -99,11 +102,11 @@ public void downloadFile(HttpServletResponse response, @PathVariable("fileName") @RequestMapping(value = "/profileimage/{baseEntityId}", method = RequestMethod.GET) public void downloadFileByClientId(HttpServletResponse response, @PathVariable("baseEntityId") String baseEntityId, @RequestHeader(value = "username") String userName, - @RequestHeader(value = "password") String password) + @RequestHeader(value = "password") String password, HttpServletRequest request) throws Exception { try { - if (authenticate(userName, password).isAuthenticated()) { + if (authenticate(userName, password, request).isAuthenticated()) { Multimedia multiMedia = multimediaService.findByCaseId(baseEntityId); if (multiMedia == null || multiMedia.getFilePath() == null) { @@ -148,10 +151,11 @@ public ResponseEntity uploadFiles(@RequestParam("anm-id") String provide return new ResponseEntity<>(new Gson().toJson(status), HttpStatus.OK); } - private Authentication authenticate(String userName, String password) { - Authentication auth = new UsernamePasswordAuthenticationToken(userName, password); - auth = provider.authenticate(auth); - return auth; + private Authentication authenticate(String userName, String password, HttpServletRequest request) { + UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken(userName, password); + WebAuthenticationDetails details = new WebAuthenticationDetailsSource().buildDetails(request); + auth.setDetails(details); + return provider.authenticate(auth); } private void downloadFile(File file, HttpServletResponse response) throws Exception { From 20b0bfc9c957acaa905649d15901da857608fb80 Mon Sep 17 00:00:00 2001 From: Samuel Githengi Date: Tue, 22 May 2018 14:24:33 +0300 Subject: [PATCH 08/13] Jedis connection pool configure using properties file. Code cleanup --- assets/config/opensrp.properties | 3 ++- opensrp-core/src/main/resources/applicationContext-opensrp.xml | 2 +- .../opensrp/web/security/DrishtiAuthenticationProvider.java | 3 +-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/assets/config/opensrp.properties b/assets/config/opensrp.properties index 09632b8151..f81e15970c 100644 --- a/assets/config/opensrp.properties +++ b/assets/config/opensrp.properties @@ -97,4 +97,5 @@ opensrp.authencation.cache.ttl=600 #redis settings redis.host=localhost redis.port=6379 -redis.password=RedI$P@S5 \ No newline at end of file +redis.password=RedI$P@S5 +jedis.pool.max.connections=5 \ No newline at end of file diff --git a/opensrp-core/src/main/resources/applicationContext-opensrp.xml b/opensrp-core/src/main/resources/applicationContext-opensrp.xml index 7774ea959e..8348f9e74e 100644 --- a/opensrp-core/src/main/resources/applicationContext-opensrp.xml +++ b/opensrp-core/src/main/resources/applicationContext-opensrp.xml @@ -32,7 +32,7 @@ + p:max-total="${jedis.pool.max.connections}" p:test-on-borrow="true" p:test-on-return="true" /> Date: Wed, 23 May 2018 11:04:32 +0300 Subject: [PATCH 09/13] Add Lettuce Redis client configuration --- .../resources/applicationContext-opensrp.xml | 16 ++++++++++++++++ opensrp-web/pom.xml | 9 +++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/opensrp-core/src/main/resources/applicationContext-opensrp.xml b/opensrp-core/src/main/resources/applicationContext-opensrp.xml index 8348f9e74e..055d67f8e7 100644 --- a/opensrp-core/src/main/resources/applicationContext-opensrp.xml +++ b/opensrp-core/src/main/resources/applicationContext-opensrp.xml @@ -41,6 +41,22 @@ + + diff --git a/opensrp-web/pom.xml b/opensrp-web/pom.xml index 461b378328..28a55e653a 100644 --- a/opensrp-web/pom.xml +++ b/opensrp-web/pom.xml @@ -280,8 +280,13 @@ jedis 2.4.1 - - + + + com.lambdaworks + lettuce + 2.3.3 + + From a3974e401d145cae9328f83ca60894fe1bfc81dd Mon Sep 17 00:00:00 2001 From: Samuel Githengi Date: Wed, 23 May 2018 12:12:36 +0300 Subject: [PATCH 10/13] Use SPEL to determine redis client in use --- assets/config/opensrp.properties | 4 +++- .../src/main/resources/applicationContext-opensrp.xml | 10 +++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/assets/config/opensrp.properties b/assets/config/opensrp.properties index f81e15970c..65dc83dfef 100644 --- a/assets/config/opensrp.properties +++ b/assets/config/opensrp.properties @@ -98,4 +98,6 @@ opensrp.authencation.cache.ttl=600 redis.host=localhost redis.port=6379 redis.password=RedI$P@S5 -jedis.pool.max.connections=5 \ No newline at end of file +redis.pool.max.connections=25 +#This defines the Redis client to be used can either be [Jedis,Lettuce] +redis.client=Jedis \ No newline at end of file diff --git a/opensrp-core/src/main/resources/applicationContext-opensrp.xml b/opensrp-core/src/main/resources/applicationContext-opensrp.xml index 055d67f8e7..45a356a5c3 100644 --- a/opensrp-core/src/main/resources/applicationContext-opensrp.xml +++ b/opensrp-core/src/main/resources/applicationContext-opensrp.xml @@ -32,7 +32,7 @@ + p:max-total="${redis.pool.max.connections}" p:test-on-borrow="true" p:test-on-return="true" /> - + From b2cdc1a28e5d7f7b716a72608b9cd839dc8369fa Mon Sep 17 00:00:00 2001 From: Samuel Githengi Date: Wed, 23 May 2018 17:49:10 +0300 Subject: [PATCH 11/13] Use Profiles to build OpenSRP instead of manual edits of XML --- assets/config/opensrp.properties | 2 +- .../resources/applicationContext-opensrp.xml | 24 +++++++++++------- opensrp-web/pom.xml | 25 +++++++++++++++++-- opensrp-web/src/main/webapp/WEB-INF/web.xml | 5 ++++ pom.xml | 25 +++++++++++++++++++ 5 files changed, 69 insertions(+), 12 deletions(-) diff --git a/assets/config/opensrp.properties b/assets/config/opensrp.properties index 65dc83dfef..ddc9675619 100644 --- a/assets/config/opensrp.properties +++ b/assets/config/opensrp.properties @@ -99,5 +99,5 @@ redis.host=localhost redis.port=6379 redis.password=RedI$P@S5 redis.pool.max.connections=25 -#This defines the Redis client to be used can either be [Jedis,Lettuce] +#This defines the Redis client can either be of [Jedis,Lettuce] redis.client=Jedis \ No newline at end of file diff --git a/opensrp-core/src/main/resources/applicationContext-opensrp.xml b/opensrp-core/src/main/resources/applicationContext-opensrp.xml index 45a356a5c3..4cb6b3abeb 100644 --- a/opensrp-core/src/main/resources/applicationContext-opensrp.xml +++ b/opensrp-core/src/main/resources/applicationContext-opensrp.xml @@ -3,10 +3,10 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:util="http://www.springframework.org/schema/util" xmlns:task="http://www.springframework.org/schema/task" xmlns:p="http://www.springframework.org/schema/p" - xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd + xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd - http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd"> + http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd"> @@ -28,11 +28,9 @@ - - - + p:max-total="${redis.pool.max.connections}" p:test-on-borrow="true" + p:test-on-return="true" /> - + @@ -58,7 +57,7 @@ @@ -78,5 +77,12 @@ fixed-delay="120000" /> + + + + + + + diff --git a/opensrp-web/pom.xml b/opensrp-web/pom.xml index 28a55e653a..fb17d80b7d 100644 --- a/opensrp-web/pom.xml +++ b/opensrp-web/pom.xml @@ -22,12 +22,12 @@ 4.2.8.Final - opensrp src/main/resources + true ../assets/config @@ -55,6 +55,23 @@ + + org.apache.maven.plugins + maven-war-plugin + 2.5 + + + + true + src/main/webapp + + **/web.xml + + + + true + + org.mortbay.jetty jetty-maven-plugin @@ -287,6 +304,10 @@ lettuce 2.3.3 - + + org.springframework + spring-tx + 3.1.1.RELEASE + diff --git a/opensrp-web/src/main/webapp/WEB-INF/web.xml b/opensrp-web/src/main/webapp/WEB-INF/web.xml index 8cd616cdcb..3e31f01cd9 100644 --- a/opensrp-web/src/main/webapp/WEB-INF/web.xml +++ b/opensrp-web/src/main/webapp/WEB-INF/web.xml @@ -77,6 +77,11 @@ org.springframework.web.context.ContextLoaderListener + + spring.profiles.active + ${spring.profiles.to.activate} + + opensrp diff --git a/pom.xml b/pom.xml index 5ba7b59c8f..8d05c4437d 100644 --- a/pom.xml +++ b/pom.xml @@ -271,6 +271,31 @@ + + CoachDB + + true + + opensrp.database.type + coachdb + + + + CoachDB + + + + Postgres + + + opensrp.database.type + postgres + + + + Postgres + + From 0d7bb4877875a67f05405333baa75b44b5cc3175 Mon Sep 17 00:00:00 2001 From: Samuel Githengi Date: Wed, 23 May 2018 18:40:28 +0300 Subject: [PATCH 12/13] Use maven to manage active redis client --- assets/config/opensrp.properties | 4 +- .../resources/applicationContext-opensrp.xml | 73 +++++++++++-------- .../main/resources/persistence_postgres.xml | 10 --- opensrp-web/pom.xml | 66 ++++++++++++----- opensrp-web/src/main/webapp/WEB-INF/web.xml | 2 +- pom.xml | 6 +- 6 files changed, 94 insertions(+), 67 deletions(-) diff --git a/assets/config/opensrp.properties b/assets/config/opensrp.properties index ddc9675619..f03f13ee91 100644 --- a/assets/config/opensrp.properties +++ b/assets/config/opensrp.properties @@ -98,6 +98,4 @@ opensrp.authencation.cache.ttl=600 redis.host=localhost redis.port=6379 redis.password=RedI$P@S5 -redis.pool.max.connections=25 -#This defines the Redis client can either be of [Jedis,Lettuce] -redis.client=Jedis \ No newline at end of file +redis.pool.max.connections=25 \ No newline at end of file diff --git a/opensrp-core/src/main/resources/applicationContext-opensrp.xml b/opensrp-core/src/main/resources/applicationContext-opensrp.xml index 4cb6b3abeb..bd8f440f92 100644 --- a/opensrp-core/src/main/resources/applicationContext-opensrp.xml +++ b/opensrp-core/src/main/resources/applicationContext-opensrp.xml @@ -28,38 +28,6 @@ - - - - - - - - - - - - - - - - - - - - - @@ -85,4 +53,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/opensrp-core/src/main/resources/persistence_postgres.xml b/opensrp-core/src/main/resources/persistence_postgres.xml index 621a3abaad..62ecde7657 100644 --- a/opensrp-core/src/main/resources/persistence_postgres.xml +++ b/opensrp-core/src/main/resources/persistence_postgres.xml @@ -47,14 +47,4 @@ - - - - - - - - - - \ No newline at end of file diff --git a/opensrp-web/pom.xml b/opensrp-web/pom.xml index fb17d80b7d..363144dfc5 100644 --- a/opensrp-web/pom.xml +++ b/opensrp-web/pom.xml @@ -22,6 +22,54 @@ 4.2.8.Final + + + Jedis + + true + + opensrp.redis.client.type + jedis + + + + Jedis + + + + + redis.clients + jedis + 2.4.1 + + + + + Lettuce + + + opensrp.redis.client.type + lettuce + + + + Lettuce + + + + + com.lambdaworks + lettuce + 2.3.3 + + + org.springframework + spring-tx + 3.1.1.RELEASE + + + + opensrp @@ -291,23 +339,5 @@ 1.3.6.RELEASE - - - redis.clients - jedis - 2.4.1 - - - - - com.lambdaworks - lettuce - 2.3.3 - - - org.springframework - spring-tx - 3.1.1.RELEASE - diff --git a/opensrp-web/src/main/webapp/WEB-INF/web.xml b/opensrp-web/src/main/webapp/WEB-INF/web.xml index 3e31f01cd9..d9951847a5 100644 --- a/opensrp-web/src/main/webapp/WEB-INF/web.xml +++ b/opensrp-web/src/main/webapp/WEB-INF/web.xml @@ -79,7 +79,7 @@ spring.profiles.active - ${spring.profiles.to.activate} + ${opensrp.database.profile},${opensrp.redis.client.profile} diff --git a/pom.xml b/pom.xml index 8d05c4437d..4b8057007a 100644 --- a/pom.xml +++ b/pom.xml @@ -274,26 +274,26 @@ CoachDB - true opensrp.database.type coachdb - CoachDB + CoachDB Postgres + true opensrp.database.type postgres - Postgres + Postgres From 9b6d85bb99e03bf16617a2be6b5e86d815975960 Mon Sep 17 00:00:00 2001 From: Samuel Githengi Date: Fri, 25 May 2018 14:37:37 +0300 Subject: [PATCH 13/13] use camelcase convention --- .../src/main/resources/applicationContext-opensrp.xml | 8 ++++---- opensrp-web/pom.xml | 8 ++++---- pom.xml | 10 +++++----- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/opensrp-core/src/main/resources/applicationContext-opensrp.xml b/opensrp-core/src/main/resources/applicationContext-opensrp.xml index bd8f440f92..1de8af2410 100644 --- a/opensrp-core/src/main/resources/applicationContext-opensrp.xml +++ b/opensrp-core/src/main/resources/applicationContext-opensrp.xml @@ -45,15 +45,15 @@ fixed-delay="120000" /> - + - + - + @@ -71,7 +71,7 @@ - + diff --git a/opensrp-web/pom.xml b/opensrp-web/pom.xml index 363144dfc5..39575654d2 100644 --- a/opensrp-web/pom.xml +++ b/opensrp-web/pom.xml @@ -24,7 +24,7 @@ - Jedis + jedis true @@ -33,7 +33,7 @@ - Jedis + jedis @@ -45,7 +45,7 @@ - Lettuce + lettuce opensrp.redis.client.type @@ -53,7 +53,7 @@ - Lettuce + lettuce diff --git a/pom.xml b/pom.xml index 4b8057007a..863bb144ab 100644 --- a/pom.xml +++ b/pom.xml @@ -272,19 +272,19 @@ - CoachDB + couchdb opensrp.database.type - coachdb + couchdb - CoachDB + couchDb - Postgres + postgres true @@ -293,7 +293,7 @@ - Postgres + postgres