From 981fe2104a89f8f38d2348d8d00529494b5ce92f 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 4095b8a72ce3f32402c7460ffa1176960a59de1f 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 | 45 ++++++++++++------- opensrp-web/pom.xml | 16 ++++++- 2 files changed, 43 insertions(+), 18 deletions(-) diff --git a/opensrp-core/src/main/resources/applicationContext-opensrp.xml b/opensrp-core/src/main/resources/applicationContext-opensrp.xml index bad0b47046..af630eca0e 100644 --- a/opensrp-core/src/main/resources/applicationContext-opensrp.xml +++ b/opensrp-core/src/main/resources/applicationContext-opensrp.xml @@ -1,32 +1,45 @@ - - - - + + + + - - - - - + + + + + - + - + - + + + + + + + + + diff --git a/opensrp-web/pom.xml b/opensrp-web/pom.xml index 0a7848ee5d..f459b76b5e 100644 --- a/opensrp-web/pom.xml +++ b/opensrp-web/pom.xml @@ -278,8 +278,20 @@ 3.1 --> - - + + + org.springframework.data + spring-data-redis + 1.3.6.RELEASE + + + + + redis.clients + jedis + 2.4.1 + + From 7ed531752059ef915a2443f122c5c0734a311673 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 0ba44bc14532020dc0b1a7f4a2ff3469e365ec4e 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 7eccfece2c..6e96dcb832 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 cd746e3f8cde2a7511cf148f45ad4a8be7d9090e 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 b8e5abf41951bb3370b6f12eea5aa5a5534a6f19 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 6e96dcb832..f60366ee82 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 af630eca0e..11aefbb906 100644 --- a/opensrp-core/src/main/resources/applicationContext-opensrp.xml +++ b/opensrp-core/src/main/resources/applicationContext-opensrp.xml @@ -34,7 +34,8 @@ + p:host-name="${redis.host}" p:port="${redis.port}" p:password="${redis.password}" + p:use-pool="true"> From 9c9790126b3f67cd2ec1715557ebadc48d493a94 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 95bb009ce182a9990af95e7438624c592b98e7a2 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 f60366ee82..51fead620e 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 11aefbb906..6e38758802 100644 --- a/opensrp-core/src/main/resources/applicationContext-opensrp.xml +++ b/opensrp-core/src/main/resources/applicationContext-opensrp.xml @@ -30,7 +30,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 6e38758802..a02f6ec180 100644 --- a/opensrp-core/src/main/resources/applicationContext-opensrp.xml +++ b/opensrp-core/src/main/resources/applicationContext-opensrp.xml @@ -39,6 +39,22 @@ + + diff --git a/opensrp-web/pom.xml b/opensrp-web/pom.xml index f459b76b5e..9cf42bfaa6 100644 --- a/opensrp-web/pom.xml +++ b/opensrp-web/pom.xml @@ -291,8 +291,13 @@ jedis 2.4.1 - - + + + com.lambdaworks + lettuce + 2.3.3 + + From 93774649861e8cc3cbb742d734bd5ddf3d0098ff 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 51fead620e..f29c580559 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 a02f6ec180..b1ab5102ca 100644 --- a/opensrp-core/src/main/resources/applicationContext-opensrp.xml +++ b/opensrp-core/src/main/resources/applicationContext-opensrp.xml @@ -30,7 +30,7 @@ + p:max-total="${redis.pool.max.connections}" p:test-on-borrow="true" p:test-on-return="true" /> - + From 90bcd5286768cc20074a4cf8531d6633d3ae0425 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 | 23 +++++++++++------ opensrp-web/pom.xml | 19 +++++++++++++- opensrp-web/src/main/webapp/WEB-INF/web.xml | 5 ++++ pom.xml | 25 +++++++++++++++++++ 5 files changed, 64 insertions(+), 10 deletions(-) diff --git a/assets/config/opensrp.properties b/assets/config/opensrp.properties index f29c580559..876a30bda2 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 b1ab5102ca..2aaeb84b74 100644 --- a/opensrp-core/src/main/resources/applicationContext-opensrp.xml +++ b/opensrp-core/src/main/resources/applicationContext-opensrp.xml @@ -2,7 +2,7 @@ @@ -26,11 +26,9 @@ - - - + p:max-total="${redis.pool.max.connections}" p:test-on-borrow="true" + p:test-on-return="true" /> - + @@ -56,7 +55,15 @@ + + + + + + + + diff --git a/opensrp-web/pom.xml b/opensrp-web/pom.xml index 9cf42bfaa6..2eb0758eed 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 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 8dc95f796a..540b8e6c73 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 0b0198f791864b5fb40401370abc4e34bdcccb40 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 +++++++++++-------- opensrp-web/pom.xml | 57 +++++++++++---- opensrp-web/src/main/webapp/WEB-INF/web.xml | 2 +- pom.xml | 6 +- 5 files changed, 89 insertions(+), 53 deletions(-) diff --git a/assets/config/opensrp.properties b/assets/config/opensrp.properties index 876a30bda2..76be2b4fd1 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 2aaeb84b74..6aeac0ced9 100644 --- a/opensrp-core/src/main/resources/applicationContext-opensrp.xml +++ b/opensrp-core/src/main/resources/applicationContext-opensrp.xml @@ -26,38 +26,6 @@ - - - - - - - - - - - - - - - - - - - - - @@ -66,4 +34,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/opensrp-web/pom.xml b/opensrp-web/pom.xml index 2eb0758eed..ef88335437 100644 --- a/opensrp-web/pom.xml +++ b/opensrp-web/pom.xml @@ -22,6 +22,49 @@ 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 + + + + opensrp @@ -301,20 +344,6 @@ spring-data-redis 1.3.6.RELEASE - - - - redis.clients - jedis - 2.4.1 - - - - - com.lambdaworks - lettuce - 2.3.3 - 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 540b8e6c73..7610ae4639 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 b4dadedf4610bbfafc87f3b526cf619e9b62c71c Mon Sep 17 00:00:00 2001 From: Martin Ndegwa Date: Thu, 7 Jun 2018 16:53:22 +0300 Subject: [PATCH 13/13] Update profile configuration identifiers for consistency --- .../resources/applicationContext-opensrp.xml | 113 +-- opensrp-web/pom.xml | 8 +- pom.xml | 860 +++++++++--------- 3 files changed, 491 insertions(+), 490 deletions(-) diff --git a/opensrp-core/src/main/resources/applicationContext-opensrp.xml b/opensrp-core/src/main/resources/applicationContext-opensrp.xml index 6aeac0ced9..538214525d 100644 --- a/opensrp-core/src/main/resources/applicationContext-opensrp.xml +++ b/opensrp-core/src/main/resources/applicationContext-opensrp.xml @@ -1,78 +1,79 @@ - - - - + + + + - - - - - + + + + + - + - + - + - + - - - + + + - - - + + + - - + + - - - + + + - + - + - - - - - - - + + + + + + + - + - - - + + + - + - + diff --git a/opensrp-web/pom.xml b/opensrp-web/pom.xml index ef88335437..b34ef5605e 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 7610ae4639..26cd2b48c8 100644 --- a/pom.xml +++ b/pom.xml @@ -1,449 +1,449 @@ - 4.0.0 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 - org.opensrp - opensrp - pom - 0.1-SNAPSHOT - opensrp + org.opensrp + opensrp + pom + 0.1-SNAPSHOT + opensrp http://github.com/OpenSRP/opensrp-server - - opensrp-common - opensrp-api - opensrp-form - opensrp-core - opensrp-interface - opensrp-register - opensrp-connector - opensrp-web - - + + opensrp-common + opensrp-api + opensrp-form + opensrp-core + opensrp-interface + opensrp-register + opensrp-connector + opensrp-web + + - - ${project.basedir} + + ${project.basedir} 0.11 org.motechproject.contrib-drishti 0.1-SNAPSHOT UTF-8 3.1.1.RELEASE - 5.1.36 + 5.1.36 1.9.7 - always - + always + - - - opensrp.nexus - OpenSRP Releases Repository - http://ci.smartregistries.org:8081/nexus/content/repositories/releases - false - - - opensrp.nexus - OpenSRP Snapshots Repository - http://ci.smartregistries.org:8081/nexus/content/repositories/opensrp-server - false - - + + + opensrp.nexus + OpenSRP Releases Repository + http://ci.smartregistries.org:8081/nexus/content/repositories/releases + false + + + opensrp.nexus + OpenSRP Snapshots Repository + http://ci.smartregistries.org:8081/nexus/content/repositories/opensrp-server + false + + - - - jasmine-js-bdd - Jasmine JavaScript BDD Repository - http://searls-maven-repository.googlecode.com/svn/trunk/snapshots - - + + + jasmine-js-bdd + Jasmine JavaScript BDD Repository + http://searls-maven-repository.googlecode.com/svn/trunk/snapshots + + - - - central - http://repo1.maven.org/maven2 - Repository for dependencies - - true - - - - spring-maven-release - Spring Maven Release Repository - http://maven.springframework.org/release - - - spring-maven-milestone - Spring Maven Milestone Repository - http://maven.springframework.org/milestone - - - motech.opensrp - Motech Snapshots Repository - http://nexus.motechproject.org/content/repositories/opensrp-server - - true - ${opensrp.updatePolicy} - - - - motech.nexus - Motech Snapshots Repository - http://nexus.motechproject.org/content/repositories/snapshots - - true - ${opensrp.updatePolicy} - - - - motech.nexus.release - Motech Snapshots Repository - http://nexus.motechproject.org/content/repositories/releases - - - - - skip-integration-tests - - - - org.apache.maven.plugins - maven-failsafe-plugin - 2.9 - - - - integration-test - verify - - - -XX:MaxPermSize=1024M - - **/it/** - - true - - - - - - - - - integration-tests - - true - - - - - - - maven-antrun-plugin - 1.6 - - - Drop DB Before Unit and Repository Tests - process-test-classes - - - - - - - - - - - - - - - - - run - - - - CREATE DB OPENSRP - pre-integration-test - - - - - - - - - - - - - run - - - - - - org.codehaus.mojo - sql-maven-plugin - 1.5 - - - - mysql - mysql-connector-java - ${mysql.connector.version} - - + + + central + http://repo1.maven.org/maven2 + Repository for dependencies + + true + + + + spring-maven-release + Spring Maven Release Repository + http://maven.springframework.org/release + + + spring-maven-milestone + Spring Maven Milestone Repository + http://maven.springframework.org/milestone + + + motech.opensrp + Motech Snapshots Repository + http://nexus.motechproject.org/content/repositories/opensrp-server + + true + ${opensrp.updatePolicy} + + + + motech.nexus + Motech Snapshots Repository + http://nexus.motechproject.org/content/repositories/snapshots + + true + ${opensrp.updatePolicy} + + + + motech.nexus.release + Motech Snapshots Repository + http://nexus.motechproject.org/content/repositories/releases + + + + + skip-integration-tests + + + + org.apache.maven.plugins + maven-failsafe-plugin + 2.9 + + + + integration-test + verify + + + -XX:MaxPermSize=1024M + + **/it/** + + true + + + + + + + + + integration-tests + + true + - - ${jdbc.driverClassName} - ${jdbc.url-wo-db} - ${jdbc.username} - ${jdbc.password} - ${maven.test.skip} - + + + + + maven-antrun-plugin + 1.6 + + + Drop DB Before Unit and Repository Tests + process-test-classes + + + + + + + + + + + + + + + + + run + + + + CREATE DB OPENSRP + pre-integration-test + + + + + + + + + + + + + run + + + + + + org.codehaus.mojo + sql-maven-plugin + 1.5 + + + + mysql + mysql-connector-java + ${mysql.connector.version} + + - - - - drop-create-relational-db - pre-integration-test - - execute - - - ${jdbc.url-wo-db} - ${jdbc.username} - ${jdbc.password} - true - - drop database if exists ${db.quartz}; - create database ${db.quartz}; - - abort - - - - - create-quartz-tables - pre-integration-test - - execute - - - ${jdbc.url-wo-db}/${db.quartz} - ${jdbc.username} - ${jdbc.password} - true - - ../build/sql/tables_quartz_${jdbc.backend}.sql - - - - - - - org.apache.maven.plugins - maven-failsafe-plugin - 2.9 - - - - integration-test - verify - - - -XX:MaxPermSize=1024M - - **/it/** - - true - - - - - - - - - - CoachDB - - - opensrp.database.type - coachdb - - - - CoachDB - - - - Postgres - - true - - opensrp.database.type - postgres - - - - Postgres - - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 2.5.1 - - 1.7 - 1.7 - UTF-8 - - - - org.apache.maven.plugins - maven-resources-plugin - 2.5 - - UTF-8 - - - - - org.apache.maven.plugins - maven-deploy-plugin - 2.5 - + + ${jdbc.driverClassName} + ${jdbc.url-wo-db} + ${jdbc.username} + ${jdbc.password} + ${maven.test.skip} + - - org.codehaus.mojo - properties-maven-plugin - 1.0-alpha-2 - - - initialize - - read-project-properties - - - - ${main.basedir}/build/maven.properties - ${main.basedir}/assets/config/opensrp.properties - - - - - - - org.apache.maven.plugins - maven-surefire-plugin - 2.20 - - true - - **/it/** - - - - - - - org.jacoco - jacoco-maven-plugin - 0.7.9 - - ${basedir}/target/coverage-reports/jacoco-unit.exec - ${basedir}/target/coverage-reports/jacoco-unit.exec - - - - jacoco-initialize - - prepare-agent - - - - jacoco-site - test - - report - - - - - - org.eluder.coveralls - coveralls-maven-plugin - 4.0.0 - - - - - - - - - org.eclipse.m2e - lifecycle-mapping - 1.0.0 - - - - - - - org.apache.maven.plugins - - - maven-antrun-plugin - - - [1.6,) - - - run - - - - - - - - - - org.codehaus.mojo - - - properties-maven-plugin - - - [1.0-alpha-2,) - - - - read-project-properties - - - - - - - - - - - - - - + + + + drop-create-relational-db + pre-integration-test + + execute + + + ${jdbc.url-wo-db} + ${jdbc.username} + ${jdbc.password} + true + + drop database if exists ${db.quartz}; + create database ${db.quartz}; + + abort + + + + + create-quartz-tables + pre-integration-test + + execute + + + ${jdbc.url-wo-db}/${db.quartz} + ${jdbc.username} + ${jdbc.password} + true + + ../build/sql/tables_quartz_${jdbc.backend}.sql + + + + + + + org.apache.maven.plugins + maven-failsafe-plugin + 2.9 + + + + integration-test + verify + + + -XX:MaxPermSize=1024M + + **/it/** + + true + + + + + + + + + + couchDb + + + opensrp.database.type + couchdb + + + + couchdb + + + + postgres + + true + + opensrp.database.type + postgres + + + + postgres + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.5.1 + + 1.7 + 1.7 + UTF-8 + + + + org.apache.maven.plugins + maven-resources-plugin + 2.5 + + UTF-8 + + + + + org.apache.maven.plugins + maven-deploy-plugin + 2.5 + + + + org.codehaus.mojo + properties-maven-plugin + 1.0-alpha-2 + + + initialize + + read-project-properties + + + + ${main.basedir}/build/maven.properties + ${main.basedir}/assets/config/opensrp.properties + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.20 + + true + + **/it/** + + + + + + + org.jacoco + jacoco-maven-plugin + 0.7.9 + + ${basedir}/target/coverage-reports/jacoco-unit.exec + ${basedir}/target/coverage-reports/jacoco-unit.exec + + + + jacoco-initialize + + prepare-agent + + + + jacoco-site + test + + report + + + + + + org.eluder.coveralls + coveralls-maven-plugin + 4.0.0 + + + + + + + + + org.eclipse.m2e + lifecycle-mapping + 1.0.0 + + + + + + + org.apache.maven.plugins + + + maven-antrun-plugin + + + [1.6,) + + + run + + + + + + + + + + org.codehaus.mojo + + + properties-maven-plugin + + + [1.0-alpha-2,) + + + + read-project-properties + + + + + + + + + + + + + +