From bd74c7c1446566a659a84e8aed376b6359c4c3b1 Mon Sep 17 00:00:00 2001 From: Chi Dov Date: Sun, 15 Jul 2018 21:09:39 -0500 Subject: [PATCH 01/31] update config server to spring boot 2.0.3 and spring cloud finchley --- config/pom.xml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/config/pom.xml b/config/pom.xml index 9d69727b14..37fe889695 100644 --- a/config/pom.xml +++ b/config/pom.xml @@ -14,12 +14,13 @@ org.springframework.boot spring-boot-starter-parent - 1.3.5.RELEASE + 2.0.3.RELEASE UTF-8 + Finchley.RELEASE 1.8 @@ -33,13 +34,13 @@ spring-boot-starter-security - + org.springframework.cloud spring-cloud-dependencies - Brixton.RELEASE + ${spring-cloud.version} pom import From 50d896e8a20c150b4f2972edd2d421d69e552aa8 Mon Sep 17 00:00:00 2001 From: Chi Dov Date: Sun, 15 Jul 2018 21:11:30 -0500 Subject: [PATCH 02/31] update registry server to spring boot 2.0.3 and spring cloud finchley --- registry/pom.xml | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/registry/pom.xml b/registry/pom.xml index aada05dd99..6cf9771161 100644 --- a/registry/pom.xml +++ b/registry/pom.xml @@ -13,20 +13,21 @@ org.springframework.boot spring-boot-starter-parent - 1.3.5.RELEASE + 2.0.3.RELEASE UTF-8 - 1.8 + Finchley.RELEASE + 1.8 - - org.springframework.cloud - spring-cloud-starter-eureka-server - + + org.springframework.cloud + spring-cloud-starter-netflix-eureka-server + org.springframework.cloud spring-cloud-starter-config @@ -37,13 +38,13 @@ test - + org.springframework.cloud - spring-cloud-starter-parent - Brixton.RELEASE + spring-cloud-dependencies + ${spring-cloud.version} pom import From 1be5dffa8e444110e40e063494a1813169ca791a Mon Sep 17 00:00:00 2001 From: Chi Dov Date: Sun, 15 Jul 2018 23:44:48 -0500 Subject: [PATCH 03/31] update auth server to spring boot 2.0.3 and spring cloud finchley --- account-service/pom.xml | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/account-service/pom.xml b/account-service/pom.xml index 378ff05e90..8aa8ca435c 100644 --- a/account-service/pom.xml +++ b/account-service/pom.xml @@ -13,12 +13,13 @@ org.springframework.boot spring-boot-starter-parent - 1.3.3.RELEASE + 2.0.3.RELEASE UTF-8 + Finchley.RELEASE 1.8 @@ -26,8 +27,8 @@ org.springframework.cloud - spring-cloud-starter-parent - Brixton.RELEASE + spring-cloud-dependencies + ${spring-cloud.version} pom import @@ -43,10 +44,6 @@ org.springframework.boot spring-boot-starter-security - - org.springframework.security.oauth - spring-security-oauth2 - org.springframework.cloud spring-cloud-starter-config @@ -57,11 +54,11 @@ org.springframework.cloud - spring-cloud-starter-feign + spring-cloud-starter-openfeign org.springframework.cloud - spring-cloud-starter-eureka + spring-cloud-starter-netflix-eureka-client org.springframework.boot From 8d462c470afc3f7a0afeda1985fd5838e9a38f4a Mon Sep 17 00:00:00 2001 From: Chi Dov Date: Sun, 15 Jul 2018 23:46:37 -0500 Subject: [PATCH 04/31] separate config from auth application for loose couping unit test purpose --- .../piggymetrics/auth/AuthApplication.java | 108 ------------------ .../config/OAuth2AuthorizationConfig.java | 78 +++++++++++++ .../auth/config/WebSecurityConfig.java | 43 +++++++ 3 files changed, 121 insertions(+), 108 deletions(-) create mode 100644 auth-service/src/main/java/com/piggymetrics/auth/config/OAuth2AuthorizationConfig.java create mode 100644 auth-service/src/main/java/com/piggymetrics/auth/config/WebSecurityConfig.java diff --git a/auth-service/src/main/java/com/piggymetrics/auth/AuthApplication.java b/auth-service/src/main/java/com/piggymetrics/auth/AuthApplication.java index 5748f82779..d02157a5c3 100644 --- a/auth-service/src/main/java/com/piggymetrics/auth/AuthApplication.java +++ b/auth-service/src/main/java/com/piggymetrics/auth/AuthApplication.java @@ -1,29 +1,10 @@ package com.piggymetrics.auth; -import com.piggymetrics.auth.service.security.MongoUserDetailsService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.core.env.Environment; -import org.springframework.security.authentication.AuthenticationManager; -import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; -import org.springframework.security.config.annotation.web.builders.HttpSecurity; -import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; -import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; -import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; -import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer; -import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter; -import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer; import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer; -import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer; -import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerSecurityConfigurer; -import org.springframework.security.oauth2.provider.token.TokenStore; -import org.springframework.security.oauth2.provider.token.store.InMemoryTokenStore; @SpringBootApplication @EnableResourceServer @@ -35,93 +16,4 @@ public static void main(String[] args) { SpringApplication.run(AuthApplication.class, args); } - @Configuration - @EnableWebSecurity - protected static class webSecurityConfig extends WebSecurityConfigurerAdapter { - - @Autowired - private MongoUserDetailsService userDetailsService; - - @Override - protected void configure(HttpSecurity http) throws Exception { - // @formatter:off - http - .authorizeRequests().anyRequest().authenticated() - .and() - .csrf().disable(); - // @formatter:on - } - - @Override - protected void configure(AuthenticationManagerBuilder auth) throws Exception { - auth.userDetailsService(userDetailsService) - .passwordEncoder(new BCryptPasswordEncoder()); - } - - @Override - @Bean - public AuthenticationManager authenticationManagerBean() throws Exception { - return super.authenticationManagerBean(); - } - } - - @Configuration - @EnableAuthorizationServer - protected static class OAuth2AuthorizationConfig extends AuthorizationServerConfigurerAdapter { - - private TokenStore tokenStore = new InMemoryTokenStore(); - - @Autowired - @Qualifier("authenticationManagerBean") - private AuthenticationManager authenticationManager; - - @Autowired - private MongoUserDetailsService userDetailsService; - - @Autowired - private Environment env; - - @Override - public void configure(ClientDetailsServiceConfigurer clients) throws Exception { - - // TODO persist clients details - - // @formatter:off - clients.inMemory() - .withClient("browser") - .authorizedGrantTypes("refresh_token", "password") - .scopes("ui") - .and() - .withClient("account-service") - .secret(env.getProperty("ACCOUNT_SERVICE_PASSWORD")) - .authorizedGrantTypes("client_credentials", "refresh_token") - .scopes("server") - .and() - .withClient("statistics-service") - .secret(env.getProperty("STATISTICS_SERVICE_PASSWORD")) - .authorizedGrantTypes("client_credentials", "refresh_token") - .scopes("server") - .and() - .withClient("notification-service") - .secret(env.getProperty("NOTIFICATION_SERVICE_PASSWORD")) - .authorizedGrantTypes("client_credentials", "refresh_token") - .scopes("server"); - // @formatter:on - } - - @Override - public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception { - endpoints - .tokenStore(tokenStore) - .authenticationManager(authenticationManager) - .userDetailsService(userDetailsService); - } - - @Override - public void configure(AuthorizationServerSecurityConfigurer oauthServer) throws Exception { - oauthServer - .tokenKeyAccess("permitAll()") - .checkTokenAccess("isAuthenticated()"); - } - } } diff --git a/auth-service/src/main/java/com/piggymetrics/auth/config/OAuth2AuthorizationConfig.java b/auth-service/src/main/java/com/piggymetrics/auth/config/OAuth2AuthorizationConfig.java new file mode 100644 index 0000000000..0ad464335c --- /dev/null +++ b/auth-service/src/main/java/com/piggymetrics/auth/config/OAuth2AuthorizationConfig.java @@ -0,0 +1,78 @@ +package com.piggymetrics.auth.config; + +import com.piggymetrics.auth.service.security.MongoUserDetailsService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.env.Environment; +import org.springframework.security.authentication.AuthenticationManager; +import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer; +import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter; +import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer; +import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer; +import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerSecurityConfigurer; +import org.springframework.security.oauth2.provider.token.TokenStore; +import org.springframework.security.oauth2.provider.token.store.InMemoryTokenStore; + +/** + * @author cdov + */ +@Configuration +@EnableAuthorizationServer +public class OAuth2AuthorizationConfig extends AuthorizationServerConfigurerAdapter { + + private TokenStore tokenStore = new InMemoryTokenStore(); + + @Autowired + @Qualifier("authenticationManagerBean") + private AuthenticationManager authenticationManager; + + @Autowired + private MongoUserDetailsService userDetailsService; + + @Autowired + private Environment env; + + @Override + public void configure(ClientDetailsServiceConfigurer clients) throws Exception { + + // TODO persist clients details + + // @formatter:off + clients.inMemory() + .withClient("browser") + .authorizedGrantTypes("refresh_token", "password") + .scopes("ui") + .and() + .withClient("account-service") + .secret(env.getProperty("ACCOUNT_SERVICE_PASSWORD")) + .authorizedGrantTypes("client_credentials", "refresh_token") + .scopes("server") + .and() + .withClient("statistics-service") + .secret(env.getProperty("STATISTICS_SERVICE_PASSWORD")) + .authorizedGrantTypes("client_credentials", "refresh_token") + .scopes("server") + .and() + .withClient("notification-service") + .secret(env.getProperty("NOTIFICATION_SERVICE_PASSWORD")) + .authorizedGrantTypes("client_credentials", "refresh_token") + .scopes("server"); + // @formatter:on + } + + @Override + public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception { + endpoints + .tokenStore(tokenStore) + .authenticationManager(authenticationManager) + .userDetailsService(userDetailsService); + } + + @Override + public void configure(AuthorizationServerSecurityConfigurer oauthServer) throws Exception { + oauthServer + .tokenKeyAccess("permitAll()") + .checkTokenAccess("isAuthenticated()"); + } +} diff --git a/auth-service/src/main/java/com/piggymetrics/auth/config/WebSecurityConfig.java b/auth-service/src/main/java/com/piggymetrics/auth/config/WebSecurityConfig.java new file mode 100644 index 0000000000..fbff80f6c2 --- /dev/null +++ b/auth-service/src/main/java/com/piggymetrics/auth/config/WebSecurityConfig.java @@ -0,0 +1,43 @@ +package com.piggymetrics.auth.config; + +import com.piggymetrics.auth.service.security.MongoUserDetailsService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.authentication.AuthenticationManager; +import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; + +/** + * @author cdov + */ +@Configuration +public class WebSecurityConfig extends WebSecurityConfigurerAdapter { + + @Autowired + private MongoUserDetailsService userDetailsService; + + @Override + protected void configure(HttpSecurity http) throws Exception { + // @formatter:off + http + .authorizeRequests().anyRequest().authenticated() + .and() + .csrf().disable(); + // @formatter:on + } + + @Override + protected void configure(AuthenticationManagerBuilder auth) throws Exception { + auth.userDetailsService(userDetailsService) + .passwordEncoder(new BCryptPasswordEncoder()); + } + + @Override + @Bean + public AuthenticationManager authenticationManagerBean() throws Exception { + return super.authenticationManagerBean(); + } +} \ No newline at end of file From f9cb2e0a4b85a79c7bb9b67671b64f24d68bf08b Mon Sep 17 00:00:00 2001 From: Chi Dov Date: Sun, 15 Jul 2018 23:47:39 -0500 Subject: [PATCH 05/31] fix repository error for auth service --- .../com/piggymetrics/auth/service/UserServiceImpl.java | 6 ++++-- .../auth/service/security/MongoUserDetailsService.java | 9 +-------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/auth-service/src/main/java/com/piggymetrics/auth/service/UserServiceImpl.java b/auth-service/src/main/java/com/piggymetrics/auth/service/UserServiceImpl.java index ecbbdfa585..9347289211 100644 --- a/auth-service/src/main/java/com/piggymetrics/auth/service/UserServiceImpl.java +++ b/auth-service/src/main/java/com/piggymetrics/auth/service/UserServiceImpl.java @@ -9,6 +9,8 @@ import org.springframework.stereotype.Service; import org.springframework.util.Assert; +import java.util.Optional; + @Service public class UserServiceImpl implements UserService { @@ -22,8 +24,8 @@ public class UserServiceImpl implements UserService { @Override public void create(User user) { - User existing = repository.findOne(user.getUsername()); - Assert.isNull(existing, "user already exists: " + user.getUsername()); + Optional existing = repository.findById(user.getUsername()); + existing.ifPresent(it-> {throw new IllegalArgumentException("user already exists: " + it.getUsername());}); String hash = encoder.encode(user.getPassword()); user.setPassword(hash); diff --git a/auth-service/src/main/java/com/piggymetrics/auth/service/security/MongoUserDetailsService.java b/auth-service/src/main/java/com/piggymetrics/auth/service/security/MongoUserDetailsService.java index 130f09099e..f7081ce997 100644 --- a/auth-service/src/main/java/com/piggymetrics/auth/service/security/MongoUserDetailsService.java +++ b/auth-service/src/main/java/com/piggymetrics/auth/service/security/MongoUserDetailsService.java @@ -1,6 +1,5 @@ package com.piggymetrics.auth.service.security; -import com.piggymetrics.auth.domain.User; import com.piggymetrics.auth.repository.UserRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.core.userdetails.UserDetails; @@ -17,12 +16,6 @@ public class MongoUserDetailsService implements UserDetailsService { @Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { - User user = repository.findOne(username); - - if (user == null) { - throw new UsernameNotFoundException(username); - } - - return user; + return repository.findById(username).orElseThrow(()->new UsernameNotFoundException(username)); } } From 9ee137c49640c63a44ad39aa44c8c13b2ef95741 Mon Sep 17 00:00:00 2001 From: Chi Dov Date: Sun, 15 Jul 2018 23:48:56 -0500 Subject: [PATCH 06/31] fix unit test for auth-server --- .../auth/AuthServiceApplicationTests.java | 4 ++-- .../auth/controller/UserControllerTest.java | 7 ++----- .../auth/repository/UserRepositoryTest.java | 18 ++++++++++++------ .../auth/service/UserServiceTest.java | 4 +++- .../security/MongoUserDetailsServiceTest.java | 4 +++- 5 files changed, 22 insertions(+), 15 deletions(-) diff --git a/auth-service/src/test/java/com/piggymetrics/auth/AuthServiceApplicationTests.java b/auth-service/src/test/java/com/piggymetrics/auth/AuthServiceApplicationTests.java index fd9841d35a..4f597906a8 100644 --- a/auth-service/src/test/java/com/piggymetrics/auth/AuthServiceApplicationTests.java +++ b/auth-service/src/test/java/com/piggymetrics/auth/AuthServiceApplicationTests.java @@ -2,11 +2,11 @@ import org.junit.Test; import org.junit.runner.RunWith; -import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @RunWith(SpringJUnit4ClassRunner.class) -@SpringApplicationConfiguration(classes = AuthApplication.class) +@SpringBootTest public class AuthServiceApplicationTests { @Test diff --git a/auth-service/src/test/java/com/piggymetrics/auth/controller/UserControllerTest.java b/auth-service/src/test/java/com/piggymetrics/auth/controller/UserControllerTest.java index 40d3a23c52..7117e60c42 100644 --- a/auth-service/src/test/java/com/piggymetrics/auth/controller/UserControllerTest.java +++ b/auth-service/src/test/java/com/piggymetrics/auth/controller/UserControllerTest.java @@ -1,7 +1,6 @@ package com.piggymetrics.auth.controller; import com.fasterxml.jackson.databind.ObjectMapper; -import com.piggymetrics.auth.AuthApplication; import com.piggymetrics.auth.domain.User; import com.piggymetrics.auth.service.UserService; import com.sun.security.auth.UserPrincipal; @@ -10,10 +9,9 @@ import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; -import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.boot.test.context.SpringBootTest; import org.springframework.http.MediaType; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.setup.MockMvcBuilders; @@ -24,8 +22,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @RunWith(SpringJUnit4ClassRunner.class) -@SpringApplicationConfiguration(classes = AuthApplication.class) -@WebAppConfiguration +@SpringBootTest public class UserControllerTest { private static final ObjectMapper mapper = new ObjectMapper(); diff --git a/auth-service/src/test/java/com/piggymetrics/auth/repository/UserRepositoryTest.java b/auth-service/src/test/java/com/piggymetrics/auth/repository/UserRepositoryTest.java index b22bb64b57..0c6a369ee6 100644 --- a/auth-service/src/test/java/com/piggymetrics/auth/repository/UserRepositoryTest.java +++ b/auth-service/src/test/java/com/piggymetrics/auth/repository/UserRepositoryTest.java @@ -1,17 +1,22 @@ package com.piggymetrics.auth.repository; -import com.piggymetrics.auth.AuthApplication; import com.piggymetrics.auth.domain.User; +import com.piggymetrics.auth.service.security.MongoUserDetailsService; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.boot.autoconfigure.mongo.embedded.EmbeddedMongoAutoConfiguration; +import org.springframework.boot.test.autoconfigure.data.mongo.DataMongoTest; +import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import java.util.Optional; + import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; @RunWith(SpringJUnit4ClassRunner.class) -@SpringApplicationConfiguration(classes = AuthApplication.class) +@DataMongoTest public class UserRepositoryTest { @Autowired @@ -25,8 +30,9 @@ public void shouldSaveAndFindUserByName() { user.setPassword("password"); repository.save(user); - User found = repository.findOne(user.getUsername()); - assertEquals(user.getUsername(), found.getUsername()); - assertEquals(user.getPassword(), found.getPassword()); + Optional found = repository.findById(user.getUsername()); + assertTrue(found.isPresent()); + assertEquals(user.getUsername(), found.get().getUsername()); + assertEquals(user.getPassword(), found.get().getPassword()); } } diff --git a/auth-service/src/test/java/com/piggymetrics/auth/service/UserServiceTest.java b/auth-service/src/test/java/com/piggymetrics/auth/service/UserServiceTest.java index f0017efc7b..8b22e7636d 100644 --- a/auth-service/src/test/java/com/piggymetrics/auth/service/UserServiceTest.java +++ b/auth-service/src/test/java/com/piggymetrics/auth/service/UserServiceTest.java @@ -7,6 +7,8 @@ import org.mockito.InjectMocks; import org.mockito.Mock; +import java.util.Optional; + import static org.mockito.Mockito.*; import static org.mockito.MockitoAnnotations.initMocks; @@ -41,7 +43,7 @@ public void shouldFailWhenUserAlreadyExists() { user.setUsername("name"); user.setPassword("password"); - when(repository.findOne(user.getUsername())).thenReturn(new User()); + when(repository.findById(user.getUsername())).thenReturn(Optional.of(new User())); userService.create(user); } } diff --git a/auth-service/src/test/java/com/piggymetrics/auth/service/security/MongoUserDetailsServiceTest.java b/auth-service/src/test/java/com/piggymetrics/auth/service/security/MongoUserDetailsServiceTest.java index 2c0b450614..80f71cee3f 100644 --- a/auth-service/src/test/java/com/piggymetrics/auth/service/security/MongoUserDetailsServiceTest.java +++ b/auth-service/src/test/java/com/piggymetrics/auth/service/security/MongoUserDetailsServiceTest.java @@ -9,6 +9,8 @@ import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UsernameNotFoundException; +import java.util.Optional; + import static org.junit.Assert.assertEquals; import static org.mockito.Matchers.any; import static org.mockito.Mockito.when; @@ -32,7 +34,7 @@ public void shouldLoadByUsernameWhenUserExists() { final User user = new User(); - when(repository.findOne(any())).thenReturn(user); + when(repository.findById(any())).thenReturn(Optional.of(user)); UserDetails loaded = service.loadUserByUsername("name"); assertEquals(user, loaded); From a3a091feb94a761211f2a9e514fcd6ed6fb01bd3 Mon Sep 17 00:00:00 2001 From: Chi Dov Date: Sun, 15 Jul 2018 23:49:14 -0500 Subject: [PATCH 07/31] update auth server to spring boot 2.0.3 and spring cloud finchley --- auth-service/pom.xml | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/auth-service/pom.xml b/auth-service/pom.xml index 3eda31d012..17ef5afbe1 100644 --- a/auth-service/pom.xml +++ b/auth-service/pom.xml @@ -13,12 +13,13 @@ org.springframework.boot spring-boot-starter-parent - 1.3.5.RELEASE + 2.0.3.RELEASE UTF-8 + Finchley.RELEASE 1.8 @@ -35,18 +36,18 @@ org.springframework.boot spring-boot-starter-security - - org.springframework.security.oauth - spring-security-oauth2 - + + org.springframework.cloud + spring-cloud-starter-oauth2 + org.springframework.boot spring-boot-starter-web - - org.springframework.cloud - spring-cloud-starter-eureka - + + org.springframework.cloud + spring-cloud-starter-netflix-eureka-client + org.springframework.boot spring-boot-starter-test @@ -70,8 +71,8 @@ org.springframework.cloud - spring-cloud-starter-parent - Brixton.RELEASE + spring-cloud-dependencies + ${spring-cloud.version} pom import From 5c1522a6a43a5606a2a0886a023cc3c585cf67f9 Mon Sep 17 00:00:00 2001 From: Chi Dov Date: Mon, 16 Jul 2018 00:09:22 -0500 Subject: [PATCH 08/31] separate config from AccountApplication for loose coupling unit test purpose --- .../account/AccountApplication.java | 53 +--------------- .../account/config/ResourceServerConfig.java | 60 +++++++++++++++++++ 2 files changed, 62 insertions(+), 51 deletions(-) create mode 100644 account-service/src/main/java/com/piggymetrics/account/config/ResourceServerConfig.java diff --git a/account-service/src/main/java/com/piggymetrics/account/AccountApplication.java b/account-service/src/main/java/com/piggymetrics/account/AccountApplication.java index f47d3c2ed3..be45caee82 100644 --- a/account-service/src/main/java/com/piggymetrics/account/AccountApplication.java +++ b/account-service/src/main/java/com/piggymetrics/account/AccountApplication.java @@ -1,70 +1,21 @@ package com.piggymetrics.account; -import com.piggymetrics.account.service.security.CustomUserInfoTokenServices; -import feign.RequestInterceptor; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.autoconfigure.security.oauth2.resource.ResourceServerProperties; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; -import org.springframework.cloud.netflix.feign.EnableFeignClients; -import org.springframework.cloud.security.oauth2.client.feign.OAuth2FeignRequestInterceptor; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; +import org.springframework.cloud.openfeign.EnableFeignClients; import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; -import org.springframework.security.config.annotation.web.builders.HttpSecurity; -import org.springframework.security.oauth2.client.DefaultOAuth2ClientContext; -import org.springframework.security.oauth2.client.OAuth2RestTemplate; -import org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsResourceDetails; import org.springframework.security.oauth2.config.annotation.web.configuration.EnableOAuth2Client; -import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer; -import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter; -import org.springframework.security.oauth2.provider.token.ResourceServerTokenServices; @SpringBootApplication -@EnableResourceServer @EnableDiscoveryClient @EnableOAuth2Client @EnableFeignClients @EnableGlobalMethodSecurity(prePostEnabled = true) -@EnableConfigurationProperties -@Configuration -public class AccountApplication extends ResourceServerConfigurerAdapter { - - @Autowired - private ResourceServerProperties sso; +public class AccountApplication { public static void main(String[] args) { SpringApplication.run(AccountApplication.class, args); } - @Bean - @ConfigurationProperties(prefix = "security.oauth2.client") - public ClientCredentialsResourceDetails clientCredentialsResourceDetails() { - return new ClientCredentialsResourceDetails(); - } - - @Bean - public RequestInterceptor oauth2FeignRequestInterceptor(){ - return new OAuth2FeignRequestInterceptor(new DefaultOAuth2ClientContext(), clientCredentialsResourceDetails()); - } - - @Bean - public OAuth2RestTemplate clientCredentialsRestTemplate() { - return new OAuth2RestTemplate(clientCredentialsResourceDetails()); - } - - @Bean - public ResourceServerTokenServices tokenServices() { - return new CustomUserInfoTokenServices(sso.getUserInfoUri(), sso.getClientId()); - } - - @Override - public void configure(HttpSecurity http) throws Exception { - http.authorizeRequests() - .antMatchers("/" , "/demo").permitAll() - .anyRequest().authenticated(); - } } diff --git a/account-service/src/main/java/com/piggymetrics/account/config/ResourceServerConfig.java b/account-service/src/main/java/com/piggymetrics/account/config/ResourceServerConfig.java new file mode 100644 index 0000000000..f15284021b --- /dev/null +++ b/account-service/src/main/java/com/piggymetrics/account/config/ResourceServerConfig.java @@ -0,0 +1,60 @@ +package com.piggymetrics.account.config; + +import com.piggymetrics.account.service.security.CustomUserInfoTokenServices; +import feign.RequestInterceptor; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.security.oauth2.resource.ResourceServerProperties; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.cloud.security.oauth2.client.feign.OAuth2FeignRequestInterceptor; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.oauth2.client.DefaultOAuth2ClientContext; +import org.springframework.security.oauth2.client.OAuth2RestTemplate; +import org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsResourceDetails; +import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer; +import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter; +import org.springframework.security.oauth2.provider.token.ResourceServerTokenServices; + +/** + * @author cdov + */ +@Configuration +@EnableResourceServer +public class ResourceServerConfig extends ResourceServerConfigurerAdapter { + + private final ResourceServerProperties sso; + + @Autowired + public ResourceServerConfig(ResourceServerProperties sso) { + this.sso = sso; + } + + @Bean + @ConfigurationProperties(prefix = "security.oauth2.client") + public ClientCredentialsResourceDetails clientCredentialsResourceDetails() { + return new ClientCredentialsResourceDetails(); + } + + @Bean + public RequestInterceptor oauth2FeignRequestInterceptor(){ + return new OAuth2FeignRequestInterceptor(new DefaultOAuth2ClientContext(), clientCredentialsResourceDetails()); + } + + @Bean + public OAuth2RestTemplate clientCredentialsRestTemplate() { + return new OAuth2RestTemplate(clientCredentialsResourceDetails()); + } + + @Bean + public ResourceServerTokenServices tokenServices() { + return new CustomUserInfoTokenServices(sso.getUserInfoUri(), sso.getClientId()); + } + + @Override + public void configure(HttpSecurity http) throws Exception { + http.authorizeRequests() + .antMatchers("/" , "/demo").permitAll() + .anyRequest().authenticated(); + } +} From e9bc8d469e894449a8e580cb20b92f047343c9ac Mon Sep 17 00:00:00 2001 From: Chi Dov Date: Mon, 16 Jul 2018 00:09:50 -0500 Subject: [PATCH 09/31] fix openfeign import for account service --- .../java/com/piggymetrics/account/client/AuthServiceClient.java | 2 +- .../piggymetrics/account/client/StatisticsServiceClient.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/account-service/src/main/java/com/piggymetrics/account/client/AuthServiceClient.java b/account-service/src/main/java/com/piggymetrics/account/client/AuthServiceClient.java index 5be02f424b..e6a4a4da45 100644 --- a/account-service/src/main/java/com/piggymetrics/account/client/AuthServiceClient.java +++ b/account-service/src/main/java/com/piggymetrics/account/client/AuthServiceClient.java @@ -1,7 +1,7 @@ package com.piggymetrics.account.client; import com.piggymetrics.account.domain.User; -import org.springframework.cloud.netflix.feign.FeignClient; +import org.springframework.cloud.openfeign.FeignClient; import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; diff --git a/account-service/src/main/java/com/piggymetrics/account/client/StatisticsServiceClient.java b/account-service/src/main/java/com/piggymetrics/account/client/StatisticsServiceClient.java index b5ca93a2ac..e8de1564c6 100644 --- a/account-service/src/main/java/com/piggymetrics/account/client/StatisticsServiceClient.java +++ b/account-service/src/main/java/com/piggymetrics/account/client/StatisticsServiceClient.java @@ -1,7 +1,7 @@ package com.piggymetrics.account.client; import com.piggymetrics.account.domain.Account; -import org.springframework.cloud.netflix.feign.FeignClient; +import org.springframework.cloud.openfeign.FeignClient; import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; From afa572429ca41347f440c7618219f3c361ac1994 Mon Sep 17 00:00:00 2001 From: Chi Dov Date: Mon, 16 Jul 2018 00:10:19 -0500 Subject: [PATCH 10/31] fix unit test for account service --- .../account/AccountServiceApplicationTests.java | 6 ++---- .../account/controller/AccountControllerTest.java | 7 ++----- .../account/repository/AccountRepositoryTest.java | 11 +++++++---- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/account-service/src/test/java/com/piggymetrics/account/AccountServiceApplicationTests.java b/account-service/src/test/java/com/piggymetrics/account/AccountServiceApplicationTests.java index 00655fe673..9cc5451f36 100644 --- a/account-service/src/test/java/com/piggymetrics/account/AccountServiceApplicationTests.java +++ b/account-service/src/test/java/com/piggymetrics/account/AccountServiceApplicationTests.java @@ -2,13 +2,11 @@ import org.junit.Test; import org.junit.runner.RunWith; -import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.test.context.web.WebAppConfiguration; @RunWith(SpringJUnit4ClassRunner.class) -@SpringApplicationConfiguration(classes = AccountApplication.class) -@WebAppConfiguration +@SpringBootTest public class AccountServiceApplicationTests { @Test diff --git a/account-service/src/test/java/com/piggymetrics/account/controller/AccountControllerTest.java b/account-service/src/test/java/com/piggymetrics/account/controller/AccountControllerTest.java index 5a2377a5b4..caf5d088e0 100644 --- a/account-service/src/test/java/com/piggymetrics/account/controller/AccountControllerTest.java +++ b/account-service/src/test/java/com/piggymetrics/account/controller/AccountControllerTest.java @@ -2,7 +2,6 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.collect.ImmutableList; -import com.piggymetrics.account.AccountApplication; import com.piggymetrics.account.domain.*; import com.piggymetrics.account.service.AccountService; import com.sun.security.auth.UserPrincipal; @@ -11,10 +10,9 @@ import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; -import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.boot.test.context.SpringBootTest; import org.springframework.http.MediaType; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.setup.MockMvcBuilders; @@ -28,8 +26,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @RunWith(SpringJUnit4ClassRunner.class) -@SpringApplicationConfiguration(classes = AccountApplication.class) -@WebAppConfiguration +@SpringBootTest public class AccountControllerTest { private static final ObjectMapper mapper = new ObjectMapper(); diff --git a/account-service/src/test/java/com/piggymetrics/account/repository/AccountRepositoryTest.java b/account-service/src/test/java/com/piggymetrics/account/repository/AccountRepositoryTest.java index b876dcd926..aead8cffa9 100644 --- a/account-service/src/test/java/com/piggymetrics/account/repository/AccountRepositoryTest.java +++ b/account-service/src/test/java/com/piggymetrics/account/repository/AccountRepositoryTest.java @@ -1,11 +1,14 @@ package com.piggymetrics.account.repository; -import com.piggymetrics.account.AccountApplication; -import com.piggymetrics.account.domain.*; +import com.piggymetrics.account.domain.Account; +import com.piggymetrics.account.domain.Currency; +import com.piggymetrics.account.domain.Item; +import com.piggymetrics.account.domain.Saving; +import com.piggymetrics.account.domain.TimePeriod; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.boot.test.autoconfigure.data.mongo.DataMongoTest; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import java.math.BigDecimal; @@ -15,7 +18,7 @@ import static org.junit.Assert.assertEquals; @RunWith(SpringJUnit4ClassRunner.class) -@SpringApplicationConfiguration(classes = AccountApplication.class) +@DataMongoTest public class AccountRepositoryTest { @Autowired From 91eaaa8ec1687019ed68a10691b4d872723c087d Mon Sep 17 00:00:00 2001 From: Chi Dov Date: Mon, 16 Jul 2018 00:59:42 -0500 Subject: [PATCH 11/31] update statstic service to spring boot 2.0.3 and spring cloud finchley --- statistics-service/pom.xml | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/statistics-service/pom.xml b/statistics-service/pom.xml index e4d3f18c62..43346b4836 100644 --- a/statistics-service/pom.xml +++ b/statistics-service/pom.xml @@ -13,12 +13,13 @@ org.springframework.boot spring-boot-starter-parent - 1.3.5.RELEASE + 2.0.3.RELEASE UTF-8 + Finchley.RELEASE 1.8 @@ -26,8 +27,8 @@ org.springframework.cloud - spring-cloud-starter-parent - Brixton.RELEASE + spring-cloud-dependencies + ${spring-cloud.version} pom import @@ -44,8 +45,8 @@ spring-cloud-starter-config - org.springframework.security.oauth - spring-security-oauth2 + org.springframework.cloud + spring-cloud-starter-oauth2 org.springframework.boot @@ -53,11 +54,11 @@ org.springframework.cloud - spring-cloud-starter-feign + spring-cloud-starter-openfeign org.springframework.cloud - spring-cloud-starter-eureka + spring-cloud-starter-netflix-eureka-client org.springframework.boot @@ -78,6 +79,7 @@ com.google.guava guava + 19.0 From aa536d888b4c76ffc623592187110d2f500137b1 Mon Sep 17 00:00:00 2001 From: Chi Dov Date: Mon, 16 Jul 2018 01:01:17 -0500 Subject: [PATCH 12/31] separate config from Statistic Application for loose coupling unit test purpose --- .../statistics/StatisticsApplication.java | 12 +-------- .../config/ResourceServerConfig.java | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+), 11 deletions(-) create mode 100644 statistics-service/src/main/java/com/piggymetrics/statistics/config/ResourceServerConfig.java diff --git a/statistics-service/src/main/java/com/piggymetrics/statistics/StatisticsApplication.java b/statistics-service/src/main/java/com/piggymetrics/statistics/StatisticsApplication.java index 2d1edd9878..faa12e1d18 100644 --- a/statistics-service/src/main/java/com/piggymetrics/statistics/StatisticsApplication.java +++ b/statistics-service/src/main/java/com/piggymetrics/statistics/StatisticsApplication.java @@ -8,37 +8,27 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.security.oauth2.resource.ResourceServerProperties; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; -import org.springframework.cloud.netflix.feign.EnableFeignClients; +import org.springframework.cloud.openfeign.EnableFeignClients; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.data.mongodb.core.convert.CustomConversions; import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; import org.springframework.security.oauth2.config.annotation.web.configuration.EnableOAuth2Client; -import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer; import org.springframework.security.oauth2.provider.token.ResourceServerTokenServices; import java.util.Arrays; @SpringBootApplication -@EnableResourceServer @EnableDiscoveryClient @EnableOAuth2Client @EnableFeignClients @EnableGlobalMethodSecurity(prePostEnabled = true) public class StatisticsApplication { - @Autowired - private ResourceServerProperties sso; - public static void main(String[] args) { SpringApplication.run(StatisticsApplication.class, args); } - @Bean - public ResourceServerTokenServices tokenServices() { - return new CustomUserInfoTokenServices(sso.getUserInfoUri(), sso.getClientId()); - } - @Configuration static class CustomConversionsConfig { diff --git a/statistics-service/src/main/java/com/piggymetrics/statistics/config/ResourceServerConfig.java b/statistics-service/src/main/java/com/piggymetrics/statistics/config/ResourceServerConfig.java new file mode 100644 index 0000000000..a81e817625 --- /dev/null +++ b/statistics-service/src/main/java/com/piggymetrics/statistics/config/ResourceServerConfig.java @@ -0,0 +1,25 @@ +package com.piggymetrics.statistics.config; + +import com.piggymetrics.statistics.service.security.CustomUserInfoTokenServices; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.security.oauth2.resource.ResourceServerProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer; +import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter; +import org.springframework.security.oauth2.provider.token.ResourceServerTokenServices; + +/** + * @author cdov + */ +@EnableResourceServer +@Configuration +public class ResourceServerConfig extends ResourceServerConfigurerAdapter { + @Autowired + private ResourceServerProperties sso; + + @Bean + public ResourceServerTokenServices tokenServices() { + return new CustomUserInfoTokenServices(sso.getUserInfoUri(), sso.getClientId()); + } +} From c90fff1fb5b6a6a5335c903f8b960522b0d2b88c Mon Sep 17 00:00:00 2001 From: Chi Dov Date: Mon, 16 Jul 2018 01:01:40 -0500 Subject: [PATCH 13/31] fix openfeign import --- .../com/piggymetrics/statistics/client/ExchangeRatesClient.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/statistics-service/src/main/java/com/piggymetrics/statistics/client/ExchangeRatesClient.java b/statistics-service/src/main/java/com/piggymetrics/statistics/client/ExchangeRatesClient.java index a53d3fae71..8b18607d9c 100644 --- a/statistics-service/src/main/java/com/piggymetrics/statistics/client/ExchangeRatesClient.java +++ b/statistics-service/src/main/java/com/piggymetrics/statistics/client/ExchangeRatesClient.java @@ -2,7 +2,7 @@ import com.piggymetrics.statistics.domain.Currency; import com.piggymetrics.statistics.domain.ExchangeRatesContainer; -import org.springframework.cloud.netflix.feign.FeignClient; +import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; From 820c5d967ebc515834ec033fdda10dfe3e12ab56 Mon Sep 17 00:00:00 2001 From: Chi Dov Date: Mon, 16 Jul 2018 01:02:11 -0500 Subject: [PATCH 14/31] fix statistic service's unit test --- .../StatisticsServiceApplicationTests.java | 6 ++---- .../client/ExchangeRatesClientTest.java | 5 ++--- .../controller/StatisticsControllerTest.java | 21 +++++++++++-------- .../repository/DataPointRepositoryTest.java | 5 ++--- .../service/StatisticsServiceImplTest.java | 15 +++++++++---- 5 files changed, 29 insertions(+), 23 deletions(-) diff --git a/statistics-service/src/test/java/com/piggymetrics/statistics/StatisticsServiceApplicationTests.java b/statistics-service/src/test/java/com/piggymetrics/statistics/StatisticsServiceApplicationTests.java index 10a5831a36..1c5b2a6e06 100644 --- a/statistics-service/src/test/java/com/piggymetrics/statistics/StatisticsServiceApplicationTests.java +++ b/statistics-service/src/test/java/com/piggymetrics/statistics/StatisticsServiceApplicationTests.java @@ -2,13 +2,11 @@ import org.junit.Test; import org.junit.runner.RunWith; -import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.test.context.web.WebAppConfiguration; @RunWith(SpringJUnit4ClassRunner.class) -@SpringApplicationConfiguration(classes = StatisticsApplication.class) -@WebAppConfiguration +@SpringBootTest public class StatisticsServiceApplicationTests { @Test diff --git a/statistics-service/src/test/java/com/piggymetrics/statistics/client/ExchangeRatesClientTest.java b/statistics-service/src/test/java/com/piggymetrics/statistics/client/ExchangeRatesClientTest.java index 60a89a49ab..729b6574cd 100644 --- a/statistics-service/src/test/java/com/piggymetrics/statistics/client/ExchangeRatesClientTest.java +++ b/statistics-service/src/test/java/com/piggymetrics/statistics/client/ExchangeRatesClientTest.java @@ -1,12 +1,11 @@ package com.piggymetrics.statistics.client; -import com.piggymetrics.statistics.StatisticsApplication; import com.piggymetrics.statistics.domain.Currency; import com.piggymetrics.statistics.domain.ExchangeRatesContainer; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import java.time.LocalDate; @@ -16,7 +15,7 @@ import static org.junit.Assert.assertNotNull; @RunWith(SpringJUnit4ClassRunner.class) -@SpringApplicationConfiguration(classes = StatisticsApplication.class) +@SpringBootTest public class ExchangeRatesClientTest { @Autowired diff --git a/statistics-service/src/test/java/com/piggymetrics/statistics/controller/StatisticsControllerTest.java b/statistics-service/src/test/java/com/piggymetrics/statistics/controller/StatisticsControllerTest.java index e1e572501e..e20b252474 100644 --- a/statistics-service/src/test/java/com/piggymetrics/statistics/controller/StatisticsControllerTest.java +++ b/statistics-service/src/test/java/com/piggymetrics/statistics/controller/StatisticsControllerTest.java @@ -2,8 +2,11 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.collect.ImmutableList; -import com.piggymetrics.statistics.StatisticsApplication; -import com.piggymetrics.statistics.domain.*; +import com.piggymetrics.statistics.domain.Account; +import com.piggymetrics.statistics.domain.Currency; +import com.piggymetrics.statistics.domain.Item; +import com.piggymetrics.statistics.domain.Saving; +import com.piggymetrics.statistics.domain.TimePeriod; import com.piggymetrics.statistics.domain.timeseries.DataPoint; import com.piggymetrics.statistics.domain.timeseries.DataPointId; import com.piggymetrics.statistics.service.StatisticsService; @@ -13,28 +16,28 @@ import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; -import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.boot.test.context.SpringBootTest; import org.springframework.http.MediaType; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.setup.MockMvcBuilders; import java.math.BigDecimal; import java.util.Date; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyString; -import static org.mockito.Mockito.*; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.internal.verification.VerificationModeFactory.times; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @RunWith(SpringJUnit4ClassRunner.class) -@SpringApplicationConfiguration(classes = StatisticsApplication.class) -@WebAppConfiguration +@SpringBootTest public class StatisticsControllerTest { private static final ObjectMapper mapper = new ObjectMapper(); diff --git a/statistics-service/src/test/java/com/piggymetrics/statistics/repository/DataPointRepositoryTest.java b/statistics-service/src/test/java/com/piggymetrics/statistics/repository/DataPointRepositoryTest.java index fba25d5039..9c680ddab7 100644 --- a/statistics-service/src/test/java/com/piggymetrics/statistics/repository/DataPointRepositoryTest.java +++ b/statistics-service/src/test/java/com/piggymetrics/statistics/repository/DataPointRepositoryTest.java @@ -2,7 +2,6 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.Sets; -import com.piggymetrics.statistics.StatisticsApplication; import com.piggymetrics.statistics.domain.timeseries.DataPoint; import com.piggymetrics.statistics.domain.timeseries.DataPointId; import com.piggymetrics.statistics.domain.timeseries.ItemMetric; @@ -10,7 +9,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.boot.test.autoconfigure.data.mongo.DataMongoTest; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import java.math.BigDecimal; @@ -20,7 +19,7 @@ import static org.junit.Assert.assertEquals; @RunWith(SpringJUnit4ClassRunner.class) -@SpringApplicationConfiguration(classes = StatisticsApplication.class) +@DataMongoTest public class DataPointRepositoryTest { @Autowired diff --git a/statistics-service/src/test/java/com/piggymetrics/statistics/service/StatisticsServiceImplTest.java b/statistics-service/src/test/java/com/piggymetrics/statistics/service/StatisticsServiceImplTest.java index cbec17f3bf..beeef32a8c 100644 --- a/statistics-service/src/test/java/com/piggymetrics/statistics/service/StatisticsServiceImplTest.java +++ b/statistics-service/src/test/java/com/piggymetrics/statistics/service/StatisticsServiceImplTest.java @@ -2,7 +2,11 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; -import com.piggymetrics.statistics.domain.*; +import com.piggymetrics.statistics.domain.Account; +import com.piggymetrics.statistics.domain.Currency; +import com.piggymetrics.statistics.domain.Item; +import com.piggymetrics.statistics.domain.Saving; +import com.piggymetrics.statistics.domain.TimePeriod; import com.piggymetrics.statistics.domain.timeseries.DataPoint; import com.piggymetrics.statistics.domain.timeseries.ItemMetric; import com.piggymetrics.statistics.domain.timeseries.StatisticMetric; @@ -23,7 +27,10 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.mockito.AdditionalAnswers.returnsFirstArg; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.any; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; import static org.mockito.MockitoAnnotations.initMocks; public class StatisticsServiceImplTest { @@ -109,8 +116,8 @@ Currency.RUB, new BigDecimal("80"), */ when(ratesService.convert(any(Currency.class),any(Currency.class),any(BigDecimal.class))) - .then(i -> i.getArgumentAt(2, BigDecimal.class) - .divide(rates.get(i.getArgumentAt(0, Currency.class)), 4, RoundingMode.HALF_UP)); + .then(i -> ((BigDecimal)i.getArgument(2)) + .divide(rates.get(i.getArgument(0)), 4, RoundingMode.HALF_UP)); when(ratesService.getCurrentRates()).thenReturn(rates); From 801279a1b6844de75c1630b31b773b7e0e04352e Mon Sep 17 00:00:00 2001 From: Chi Dov Date: Mon, 16 Jul 2018 01:12:30 -0500 Subject: [PATCH 15/31] update gateway server to spring boot 2.0.3 and spring cloud finchley --- gateway/pom.xml | 31 ++++++++++--------- .../gateway/GatewayApplicationTests.java | 6 ++-- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/gateway/pom.xml b/gateway/pom.xml index 6c4fa330e2..3080c864c2 100644 --- a/gateway/pom.xml +++ b/gateway/pom.xml @@ -13,19 +13,32 @@ org.springframework.boot spring-boot-starter-parent - 1.3.5.RELEASE + 2.0.3.RELEASE UTF-8 + Finchley.RELEASE 1.8 + + + + org.springframework.cloud + spring-cloud-dependencies + ${spring-cloud.version} + pom + import + + + + org.springframework.cloud - spring-cloud-starter-zuul + spring-cloud-starter-netflix-zuul org.springframework.cloud @@ -37,7 +50,7 @@ org.springframework.cloud - spring-cloud-starter-eureka + spring-cloud-starter-netflix-eureka-client org.springframework.boot @@ -46,18 +59,6 @@ - - - - org.springframework.cloud - spring-cloud-starter-parent - Brixton.RELEASE - pom - import - - - - diff --git a/gateway/src/test/java/com/piggymetrics/gateway/GatewayApplicationTests.java b/gateway/src/test/java/com/piggymetrics/gateway/GatewayApplicationTests.java index a35d36af18..d11042b297 100644 --- a/gateway/src/test/java/com/piggymetrics/gateway/GatewayApplicationTests.java +++ b/gateway/src/test/java/com/piggymetrics/gateway/GatewayApplicationTests.java @@ -2,13 +2,11 @@ import org.junit.Test; import org.junit.runner.RunWith; -import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.test.context.web.WebAppConfiguration; @RunWith(SpringJUnit4ClassRunner.class) -@SpringApplicationConfiguration(classes = GatewayApplication.class) -@WebAppConfiguration +@SpringBootTest public class GatewayApplicationTests { @Test From 7358254d9402cd8be9a78f252d15c7b2d92fb070 Mon Sep 17 00:00:00 2001 From: Chi Dov Date: Mon, 16 Jul 2018 01:17:36 -0500 Subject: [PATCH 16/31] change server.context-path to server.servlet.context-path --- config/src/main/resources/shared/auth-service.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/config/src/main/resources/shared/auth-service.yml b/config/src/main/resources/shared/auth-service.yml index c437352cd6..137c067fbb 100644 --- a/config/src/main/resources/shared/auth-service.yml +++ b/config/src/main/resources/shared/auth-service.yml @@ -8,5 +8,6 @@ spring: port: 27017 server: - context-path: /uaa + servlet: + context-path: /uaa port: 5000 From fc69832ba56f904b29ca60e8d351528310f2b2e0 Mon Sep 17 00:00:00 2001 From: Chi Dov Date: Mon, 16 Jul 2018 01:18:53 -0500 Subject: [PATCH 17/31] update monitor server to spring boot 2.0.3 and spring cloud finchley --- monitoring/pom.xml | 31 ++++++++++--------- .../MonitoringApplicationTests.java | 4 +-- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/monitoring/pom.xml b/monitoring/pom.xml index dbc99b7d35..50a60a97ea 100644 --- a/monitoring/pom.xml +++ b/monitoring/pom.xml @@ -13,15 +13,28 @@ org.springframework.boot spring-boot-starter-parent - 1.3.5.RELEASE + 2.0.3.RELEASE UTF-8 + Finchley.RELEASE 1.8 + + + + org.springframework.cloud + spring-cloud-dependencies + ${spring-cloud.version} + pom + import + + + + org.springframework.cloud @@ -29,7 +42,7 @@ org.springframework.cloud - spring-cloud-starter-turbine-stream + spring-cloud-starter-netflix-turbine-stream org.springframework.cloud @@ -37,7 +50,7 @@ org.springframework.cloud - spring-cloud-starter-hystrix-dashboard + spring-cloud-starter-netflix-hystrix-dashboard @@ -47,18 +60,6 @@ - - - - org.springframework.cloud - spring-cloud-starter-parent - Brixton.RELEASE - pom - import - - - - diff --git a/monitoring/src/test/java/com/piggymetrics/monitoring/MonitoringApplicationTests.java b/monitoring/src/test/java/com/piggymetrics/monitoring/MonitoringApplicationTests.java index 3f025cd674..1f8dd34f32 100644 --- a/monitoring/src/test/java/com/piggymetrics/monitoring/MonitoringApplicationTests.java +++ b/monitoring/src/test/java/com/piggymetrics/monitoring/MonitoringApplicationTests.java @@ -2,11 +2,11 @@ import org.junit.Test; import org.junit.runner.RunWith; -import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @RunWith(SpringJUnit4ClassRunner.class) -@SpringApplicationConfiguration(classes = MonitoringApplication.class) +@SpringBootTest public class MonitoringApplicationTests { @Test From cda40fb26f5e39a214040b0263362732b6799cf3 Mon Sep 17 00:00:00 2001 From: Chi Dov Date: Mon, 16 Jul 2018 01:36:37 -0500 Subject: [PATCH 18/31] update notification server to spring boot 2.0.3 and spring cloud finchley --- notification-service/pom.xml | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/notification-service/pom.xml b/notification-service/pom.xml index bf033b2b91..dc035c7675 100644 --- a/notification-service/pom.xml +++ b/notification-service/pom.xml @@ -13,12 +13,13 @@ org.springframework.boot spring-boot-starter-parent - 1.3.5.RELEASE + 2.0.3.RELEASE UTF-8 + Finchley.RELEASE 1.8 @@ -26,8 +27,8 @@ org.springframework.cloud - spring-cloud-starter-parent - Brixton.RELEASE + spring-cloud-dependencies + ${spring-cloud.version} pom import @@ -47,21 +48,17 @@ org.springframework.cloud spring-cloud-starter-config - - org.springframework.security.oauth - spring-security-oauth2 - org.springframework.boot spring-boot-starter-web org.springframework.cloud - spring-cloud-starter-feign + spring-cloud-starter-openfeign org.springframework.cloud - spring-cloud-starter-eureka + spring-cloud-starter-netflix-eureka-client org.springframework.boot From 7ea73058d8e1d3b1ce4ce57b3a01aad5505a8c5b Mon Sep 17 00:00:00 2001 From: Chi Dov Date: Mon, 16 Jul 2018 01:37:34 -0500 Subject: [PATCH 19/31] separate config from NotificationApplication for loose coupling unit test purpose --- .../NotificationServiceApplication.java | 28 +-------------- .../config/ResourceServerConfig.java | 34 +++++++++++++++++++ 2 files changed, 35 insertions(+), 27 deletions(-) create mode 100644 notification-service/src/main/java/com/piggymetrics/notification/config/ResourceServerConfig.java diff --git a/notification-service/src/main/java/com/piggymetrics/notification/NotificationServiceApplication.java b/notification-service/src/main/java/com/piggymetrics/notification/NotificationServiceApplication.java index 6d861cea47..bacd5e9917 100644 --- a/notification-service/src/main/java/com/piggymetrics/notification/NotificationServiceApplication.java +++ b/notification-service/src/main/java/com/piggymetrics/notification/NotificationServiceApplication.java @@ -2,34 +2,24 @@ import com.piggymetrics.notification.repository.converter.FrequencyReaderConverter; import com.piggymetrics.notification.repository.converter.FrequencyWriterConverter; -import feign.RequestInterceptor; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; -import org.springframework.cloud.netflix.feign.EnableFeignClients; -import org.springframework.cloud.security.oauth2.client.feign.OAuth2FeignRequestInterceptor; +import org.springframework.cloud.openfeign.EnableFeignClients; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.data.mongodb.core.convert.CustomConversions; import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; -import org.springframework.security.oauth2.client.DefaultOAuth2ClientContext; -import org.springframework.security.oauth2.client.OAuth2RestTemplate; -import org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsResourceDetails; import org.springframework.security.oauth2.config.annotation.web.configuration.EnableOAuth2Client; -import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer; import java.util.Arrays; @SpringBootApplication @EnableDiscoveryClient -@EnableResourceServer @EnableOAuth2Client @EnableFeignClients @EnableGlobalMethodSecurity(prePostEnabled = true) -@EnableConfigurationProperties @EnableScheduling public class NotificationServiceApplication { @@ -37,22 +27,6 @@ public static void main(String[] args) { SpringApplication.run(NotificationServiceApplication.class, args); } - @Bean - @ConfigurationProperties(prefix = "security.oauth2.client") - public ClientCredentialsResourceDetails clientCredentialsResourceDetails() { - return new ClientCredentialsResourceDetails(); - } - - @Bean - public RequestInterceptor oauth2FeignRequestInterceptor(){ - return new OAuth2FeignRequestInterceptor(new DefaultOAuth2ClientContext(), clientCredentialsResourceDetails()); - } - - @Bean - public OAuth2RestTemplate clientCredentialsRestTemplate() { - return new OAuth2RestTemplate(clientCredentialsResourceDetails()); - } - @Configuration static class CustomConversionsConfig { diff --git a/notification-service/src/main/java/com/piggymetrics/notification/config/ResourceServerConfig.java b/notification-service/src/main/java/com/piggymetrics/notification/config/ResourceServerConfig.java new file mode 100644 index 0000000000..f64259042c --- /dev/null +++ b/notification-service/src/main/java/com/piggymetrics/notification/config/ResourceServerConfig.java @@ -0,0 +1,34 @@ +package com.piggymetrics.notification.config; + +import feign.RequestInterceptor; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.cloud.security.oauth2.client.feign.OAuth2FeignRequestInterceptor; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.oauth2.client.DefaultOAuth2ClientContext; +import org.springframework.security.oauth2.client.OAuth2RestTemplate; +import org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsResourceDetails; +import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer; +import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter; + +/** + * @author cdov + */ +@Configuration +@EnableResourceServer +public class ResourceServerConfig extends ResourceServerConfigurerAdapter { + @Bean + @ConfigurationProperties(prefix = "security.oauth2.client") + public ClientCredentialsResourceDetails clientCredentialsResourceDetails() { + return new ClientCredentialsResourceDetails(); + } + @Bean + public RequestInterceptor oauth2FeignRequestInterceptor(){ + return new OAuth2FeignRequestInterceptor(new DefaultOAuth2ClientContext(), clientCredentialsResourceDetails()); + } + + @Bean + public OAuth2RestTemplate clientCredentialsRestTemplate() { + return new OAuth2RestTemplate(clientCredentialsResourceDetails()); + } +} From 33fafc7df10b976cd534032e3cf48d5e9ccdd2cd Mon Sep 17 00:00:00 2001 From: Chi Dov Date: Mon, 16 Jul 2018 01:38:09 -0500 Subject: [PATCH 20/31] fix openfiegn import for accountServiceClient --- .../piggymetrics/notification/client/AccountServiceClient.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/notification-service/src/main/java/com/piggymetrics/notification/client/AccountServiceClient.java b/notification-service/src/main/java/com/piggymetrics/notification/client/AccountServiceClient.java index 279ae857b1..dd26acea65 100644 --- a/notification-service/src/main/java/com/piggymetrics/notification/client/AccountServiceClient.java +++ b/notification-service/src/main/java/com/piggymetrics/notification/client/AccountServiceClient.java @@ -1,6 +1,6 @@ package com.piggymetrics.notification.client; -import org.springframework.cloud.netflix.feign.FeignClient; +import org.springframework.cloud.openfeign.FeignClient; import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; From 3ecad94e24f410970ec01f27a2c42ffad2bd081e Mon Sep 17 00:00:00 2001 From: Chi Dov Date: Mon, 16 Jul 2018 01:39:07 -0500 Subject: [PATCH 21/31] add single quote for RecipientRepository --- .../notification/repository/RecipientRepository.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/notification-service/src/main/java/com/piggymetrics/notification/repository/RecipientRepository.java b/notification-service/src/main/java/com/piggymetrics/notification/repository/RecipientRepository.java index b99820b314..e24fd97618 100644 --- a/notification-service/src/main/java/com/piggymetrics/notification/repository/RecipientRepository.java +++ b/notification-service/src/main/java/com/piggymetrics/notification/repository/RecipientRepository.java @@ -12,11 +12,11 @@ public interface RecipientRepository extends CrudRepository { Recipient findByAccountName(String name); - @Query("{ $and: [ {scheduledNotifications.BACKUP.active: true }, { $where: 'this.scheduledNotifications.BACKUP.lastNotified < " + + @Query("{ $and: [ {'scheduledNotifications.BACKUP.active': true }, { $where: 'this.scheduledNotifications.BACKUP.lastNotified < " + "new Date(new Date().setDate(new Date().getDate() - this.scheduledNotifications.BACKUP.frequency ))' }] }") List findReadyForBackup(); - @Query("{ $and: [ {scheduledNotifications.REMIND.active: true }, { $where: 'this.scheduledNotifications.REMIND.lastNotified < " + + @Query("{ $and: [ {'scheduledNotifications.REMIND.active': true }, { $where: 'this.scheduledNotifications.REMIND.lastNotified < " + "new Date(new Date().setDate(new Date().getDate() - this.scheduledNotifications.REMIND.frequency ))' }] }") List findReadyForRemind(); From 73345731b0bd0824280debb3aa3d2a65366f85f8 Mon Sep 17 00:00:00 2001 From: Chi Dov Date: Mon, 16 Jul 2018 01:39:29 -0500 Subject: [PATCH 22/31] fix unit test --- .../NotificationServiceApplicationTests.java | 6 ++---- .../notification/controller/RecipientControllerTest.java | 7 ++----- .../notification/repository/RecipientRepositoryTest.java | 9 +++++---- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/notification-service/src/test/java/com/piggymetrics/notification/NotificationServiceApplicationTests.java b/notification-service/src/test/java/com/piggymetrics/notification/NotificationServiceApplicationTests.java index be1ee9b8ac..5f97b2f01d 100644 --- a/notification-service/src/test/java/com/piggymetrics/notification/NotificationServiceApplicationTests.java +++ b/notification-service/src/test/java/com/piggymetrics/notification/NotificationServiceApplicationTests.java @@ -2,13 +2,11 @@ import org.junit.Test; import org.junit.runner.RunWith; -import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.test.context.web.WebAppConfiguration; @RunWith(SpringJUnit4ClassRunner.class) -@SpringApplicationConfiguration(classes = NotificationServiceApplication.class) -@WebAppConfiguration +@SpringBootTest public class NotificationServiceApplicationTests { @Test diff --git a/notification-service/src/test/java/com/piggymetrics/notification/controller/RecipientControllerTest.java b/notification-service/src/test/java/com/piggymetrics/notification/controller/RecipientControllerTest.java index c249de2d48..36726c9666 100644 --- a/notification-service/src/test/java/com/piggymetrics/notification/controller/RecipientControllerTest.java +++ b/notification-service/src/test/java/com/piggymetrics/notification/controller/RecipientControllerTest.java @@ -2,7 +2,6 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.collect.ImmutableMap; -import com.piggymetrics.notification.NotificationServiceApplication; import com.piggymetrics.notification.domain.Frequency; import com.piggymetrics.notification.domain.NotificationSettings; import com.piggymetrics.notification.domain.NotificationType; @@ -14,10 +13,9 @@ import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; -import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.boot.test.context.SpringBootTest; import org.springframework.http.MediaType; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.setup.MockMvcBuilders; @@ -29,8 +27,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @RunWith(SpringJUnit4ClassRunner.class) -@SpringApplicationConfiguration(classes = NotificationServiceApplication.class) -@WebAppConfiguration +@SpringBootTest public class RecipientControllerTest { private static final ObjectMapper mapper = new ObjectMapper(); diff --git a/notification-service/src/test/java/com/piggymetrics/notification/repository/RecipientRepositoryTest.java b/notification-service/src/test/java/com/piggymetrics/notification/repository/RecipientRepositoryTest.java index d5ebdd16c5..747c7b7505 100644 --- a/notification-service/src/test/java/com/piggymetrics/notification/repository/RecipientRepositoryTest.java +++ b/notification-service/src/test/java/com/piggymetrics/notification/repository/RecipientRepositoryTest.java @@ -1,7 +1,6 @@ package com.piggymetrics.notification.repository; import com.google.common.collect.ImmutableMap; -import com.piggymetrics.notification.NotificationServiceApplication; import com.piggymetrics.notification.domain.Frequency; import com.piggymetrics.notification.domain.NotificationSettings; import com.piggymetrics.notification.domain.NotificationType; @@ -10,16 +9,18 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.boot.test.autoconfigure.data.mongo.DataMongoTest; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import java.util.Date; import java.util.List; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; @RunWith(SpringJUnit4ClassRunner.class) -@SpringApplicationConfiguration(classes = NotificationServiceApplication.class) +@DataMongoTest public class RecipientRepositoryTest { @Autowired From 0a71de6d6f3d4db97df469e47b72b6de7940752b Mon Sep 17 00:00:00 2001 From: Chi Dov Date: Mon, 16 Jul 2018 23:36:06 -0500 Subject: [PATCH 23/31] update default spring security user password in config server --- config/src/main/resources/application.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/config/src/main/resources/application.yml b/config/src/main/resources/application.yml index 2a932c7ca5..772c9049a2 100644 --- a/config/src/main/resources/application.yml +++ b/config/src/main/resources/application.yml @@ -6,10 +6,10 @@ spring: search-locations: classpath:/shared profiles: active: native + security: + user: + password: ${CONFIG_SERVICE_PASSWORD} server: port: 8888 -security: - user: - password: ${CONFIG_SERVICE_PASSWORD} \ No newline at end of file From f58f61b438d28e27419dc7d3cfde35314988d1c1 Mon Sep 17 00:00:00 2001 From: Chi Dov Date: Tue, 17 Jul 2018 00:49:59 -0500 Subject: [PATCH 24/31] spring security 5 always require password encoder id https://spring.io/blog/2017/11/01/spring-security-5-0-0-rc1-released#password-storage-format --- .../auth/config/OAuth2AuthorizationConfig.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/auth-service/src/main/java/com/piggymetrics/auth/config/OAuth2AuthorizationConfig.java b/auth-service/src/main/java/com/piggymetrics/auth/config/OAuth2AuthorizationConfig.java index 0ad464335c..6012c59ce6 100644 --- a/auth-service/src/main/java/com/piggymetrics/auth/config/OAuth2AuthorizationConfig.java +++ b/auth-service/src/main/java/com/piggymetrics/auth/config/OAuth2AuthorizationConfig.java @@ -13,6 +13,7 @@ import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerSecurityConfigurer; import org.springframework.security.oauth2.provider.token.TokenStore; import org.springframework.security.oauth2.provider.token.store.InMemoryTokenStore; +import org.springframework.util.StringUtils; /** * @author cdov @@ -22,6 +23,7 @@ public class OAuth2AuthorizationConfig extends AuthorizationServerConfigurerAdapter { private TokenStore tokenStore = new InMemoryTokenStore(); + private final String NOOP_PASSWORD_ENCODE = "{noop}"; @Autowired @Qualifier("authenticationManagerBean") @@ -41,21 +43,22 @@ public void configure(ClientDetailsServiceConfigurer clients) throws Exception { // @formatter:off clients.inMemory() .withClient("browser") + .secret(NOOP_PASSWORD_ENCODE) .authorizedGrantTypes("refresh_token", "password") .scopes("ui") .and() .withClient("account-service") - .secret(env.getProperty("ACCOUNT_SERVICE_PASSWORD")) + .secret(noOpPasswordEncoder(env.getProperty("ACCOUNT_SERVICE_PASSWORD"))) .authorizedGrantTypes("client_credentials", "refresh_token") .scopes("server") .and() .withClient("statistics-service") - .secret(env.getProperty("STATISTICS_SERVICE_PASSWORD")) + .secret(noOpPasswordEncoder(env.getProperty("STATISTICS_SERVICE_PASSWORD"))) .authorizedGrantTypes("client_credentials", "refresh_token") .scopes("server") .and() .withClient("notification-service") - .secret(env.getProperty("NOTIFICATION_SERVICE_PASSWORD")) + .secret(noOpPasswordEncoder(env.getProperty("NOTIFICATION_SERVICE_PASSWORD"))) .authorizedGrantTypes("client_credentials", "refresh_token") .scopes("server"); // @formatter:on @@ -75,4 +78,8 @@ public void configure(AuthorizationServerSecurityConfigurer oauthServer) throws .tokenKeyAccess("permitAll()") .checkTokenAccess("isAuthenticated()"); } + + private String noOpPasswordEncoder(String password) { + return StringUtils.isEmpty(password) ? NOOP_PASSWORD_ENCODE : NOOP_PASSWORD_ENCODE.concat(password); + } } From b2ff99fb11cba32390f372105c56e665f56b461f Mon Sep 17 00:00:00 2001 From: Chi Dov Date: Tue, 17 Jul 2018 01:21:46 -0500 Subject: [PATCH 25/31] specific password encoder instead of using id password encoder --- .../auth/config/OAuth2AuthorizationConfig.java | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/auth-service/src/main/java/com/piggymetrics/auth/config/OAuth2AuthorizationConfig.java b/auth-service/src/main/java/com/piggymetrics/auth/config/OAuth2AuthorizationConfig.java index 6012c59ce6..e084a9486b 100644 --- a/auth-service/src/main/java/com/piggymetrics/auth/config/OAuth2AuthorizationConfig.java +++ b/auth-service/src/main/java/com/piggymetrics/auth/config/OAuth2AuthorizationConfig.java @@ -6,6 +6,7 @@ import org.springframework.context.annotation.Configuration; import org.springframework.core.env.Environment; import org.springframework.security.authentication.AuthenticationManager; +import org.springframework.security.crypto.password.NoOpPasswordEncoder; import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer; import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter; import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer; @@ -13,7 +14,6 @@ import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerSecurityConfigurer; import org.springframework.security.oauth2.provider.token.TokenStore; import org.springframework.security.oauth2.provider.token.store.InMemoryTokenStore; -import org.springframework.util.StringUtils; /** * @author cdov @@ -48,17 +48,17 @@ public void configure(ClientDetailsServiceConfigurer clients) throws Exception { .scopes("ui") .and() .withClient("account-service") - .secret(noOpPasswordEncoder(env.getProperty("ACCOUNT_SERVICE_PASSWORD"))) + .secret(env.getProperty("ACCOUNT_SERVICE_PASSWORD")) .authorizedGrantTypes("client_credentials", "refresh_token") .scopes("server") .and() .withClient("statistics-service") - .secret(noOpPasswordEncoder(env.getProperty("STATISTICS_SERVICE_PASSWORD"))) + .secret(env.getProperty("STATISTICS_SERVICE_PASSWORD")) .authorizedGrantTypes("client_credentials", "refresh_token") .scopes("server") .and() .withClient("notification-service") - .secret(noOpPasswordEncoder(env.getProperty("NOTIFICATION_SERVICE_PASSWORD"))) + .secret(env.getProperty("NOTIFICATION_SERVICE_PASSWORD")) .authorizedGrantTypes("client_credentials", "refresh_token") .scopes("server"); // @formatter:on @@ -76,10 +76,8 @@ public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws E public void configure(AuthorizationServerSecurityConfigurer oauthServer) throws Exception { oauthServer .tokenKeyAccess("permitAll()") - .checkTokenAccess("isAuthenticated()"); + .checkTokenAccess("isAuthenticated()") + .passwordEncoder(NoOpPasswordEncoder.getInstance()); } - private String noOpPasswordEncoder(String password) { - return StringUtils.isEmpty(password) ? NOOP_PASSWORD_ENCODE : NOOP_PASSWORD_ENCODE.concat(password); - } } From 40be6ea9f7879d46eb50e07db2b168bd3da4ee23 Mon Sep 17 00:00:00 2001 From: Chi Dov Date: Tue, 17 Jul 2018 11:19:08 -0500 Subject: [PATCH 26/31] remove secret from browser client --- .../com/piggymetrics/auth/config/OAuth2AuthorizationConfig.java | 1 - 1 file changed, 1 deletion(-) diff --git a/auth-service/src/main/java/com/piggymetrics/auth/config/OAuth2AuthorizationConfig.java b/auth-service/src/main/java/com/piggymetrics/auth/config/OAuth2AuthorizationConfig.java index e084a9486b..d146df2a7e 100644 --- a/auth-service/src/main/java/com/piggymetrics/auth/config/OAuth2AuthorizationConfig.java +++ b/auth-service/src/main/java/com/piggymetrics/auth/config/OAuth2AuthorizationConfig.java @@ -43,7 +43,6 @@ public void configure(ClientDetailsServiceConfigurer clients) throws Exception { // @formatter:off clients.inMemory() .withClient("browser") - .secret(NOOP_PASSWORD_ENCODE) .authorizedGrantTypes("refresh_token", "password") .scopes("ui") .and() From f7f5a15c4c31c8684f41a6a9537b993a94b78934 Mon Sep 17 00:00:00 2001 From: Chi Dov Date: Wed, 18 Jul 2018 00:00:53 -0500 Subject: [PATCH 27/31] default stripPrefix=true in gateway --- config/src/main/resources/shared/gateway.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/config/src/main/resources/shared/gateway.yml b/config/src/main/resources/shared/gateway.yml index bceb918d78..48d1e1f9d6 100644 --- a/config/src/main/resources/shared/gateway.yml +++ b/config/src/main/resources/shared/gateway.yml @@ -20,25 +20,21 @@ zuul: auth-service: path: /uaa/** url: http://auth-service:5000 - stripPrefix: false sensitiveHeaders: account-service: path: /accounts/** serviceId: account-service - stripPrefix: false sensitiveHeaders: statistics-service: path: /statistics/** serviceId: statistics-service - stripPrefix: false sensitiveHeaders: notification-service: path: /notifications/** serviceId: notification-service - stripPrefix: false sensitiveHeaders: server: From 811e2792ba3e0f22f2f4dc8b168518004a03a403 Mon Sep 17 00:00:00 2001 From: Chi Dov Date: Wed, 18 Jul 2018 00:02:15 -0500 Subject: [PATCH 28/31] Revert "default stripPrefix=true in gateway" This reverts commit f7f5a15 --- config/src/main/resources/shared/gateway.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/config/src/main/resources/shared/gateway.yml b/config/src/main/resources/shared/gateway.yml index 48d1e1f9d6..bceb918d78 100644 --- a/config/src/main/resources/shared/gateway.yml +++ b/config/src/main/resources/shared/gateway.yml @@ -20,21 +20,25 @@ zuul: auth-service: path: /uaa/** url: http://auth-service:5000 + stripPrefix: false sensitiveHeaders: account-service: path: /accounts/** serviceId: account-service + stripPrefix: false sensitiveHeaders: statistics-service: path: /statistics/** serviceId: statistics-service + stripPrefix: false sensitiveHeaders: notification-service: path: /notifications/** serviceId: notification-service + stripPrefix: false sensitiveHeaders: server: From cbe50834e8ab327d20e7a709b0526ddd80aba425 Mon Sep 17 00:00:00 2001 From: Chi Dov Date: Wed, 18 Jul 2018 00:05:50 -0500 Subject: [PATCH 29/31] change context-path to servlet-context-path --- config/src/main/resources/shared/account-service.yml | 3 ++- config/src/main/resources/shared/notification-service.yml | 3 ++- config/src/main/resources/shared/statistics-service.yml | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/config/src/main/resources/shared/account-service.yml b/config/src/main/resources/shared/account-service.yml index 5d6359081f..55ea99c32e 100644 --- a/config/src/main/resources/shared/account-service.yml +++ b/config/src/main/resources/shared/account-service.yml @@ -17,5 +17,6 @@ spring: port: 27017 server: - context-path: /accounts + servlet: + context-path: /accounts port: 6000 diff --git a/config/src/main/resources/shared/notification-service.yml b/config/src/main/resources/shared/notification-service.yml index 7277206d68..4ab530252f 100644 --- a/config/src/main/resources/shared/notification-service.yml +++ b/config/src/main/resources/shared/notification-service.yml @@ -8,7 +8,8 @@ security: scope: server server: - context-path: /notifications + servlet: + context-path: /notifications port: 8000 remind: diff --git a/config/src/main/resources/shared/statistics-service.yml b/config/src/main/resources/shared/statistics-service.yml index a05449fdd0..37eac2d77b 100644 --- a/config/src/main/resources/shared/statistics-service.yml +++ b/config/src/main/resources/shared/statistics-service.yml @@ -17,7 +17,8 @@ spring: port: 27017 server: - context-path: /statistics + servlet: + context-path: /statistics port: 7000 rates: From 7772ef63067069e7fe4825d4981e6aaed1676bd6 Mon Sep 17 00:00:00 2001 From: Chi Dov Date: Wed, 18 Jul 2018 01:56:19 -0500 Subject: [PATCH 30/31] update exchange rate provider when init in frontend related to PR #24 --- gateway/src/main/resources/static/js/launch.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gateway/src/main/resources/static/js/launch.js b/gateway/src/main/resources/static/js/launch.js index bc45a5a176..52b32fae37 100644 --- a/gateway/src/main/resources/static/js/launch.js +++ b/gateway/src/main/resources/static/js/launch.js @@ -80,7 +80,7 @@ $(window).load(function(){ global.mobileClient = true; } - $.getJSON("http://api.fixer.io/latest?base=RUB", function( data ) { + $.getJSON("https://exchangeratesapi.io/api/latest?base=RUB", function( data ) { global.eur = 1 / data.rates.EUR; global.usd = 1 / data.rates.USD; }); From 667595e4716236464d77d7644b2942cbb821b4c3 Mon Sep 17 00:00:00 2001 From: Chi Dov Date: Wed, 18 Jul 2018 01:57:12 -0500 Subject: [PATCH 31/31] enable actuator security in config server --- config/Dockerfile | 2 +- .../piggymetrics/config/SecurityConfig.java | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 config/src/main/java/com/piggymetrics/config/SecurityConfig.java diff --git a/config/Dockerfile b/config/Dockerfile index 481c18dd28..335d81e00d 100644 --- a/config/Dockerfile +++ b/config/Dockerfile @@ -4,6 +4,6 @@ MAINTAINER Alexander Lukyanchikov ADD ./target/config.jar /app/ CMD ["java", "-Xmx200m", "-jar", "/app/config.jar"] -HEALTHCHECK --interval=10s --timeout=3s CMD curl -f http://localhost:8888/health || exit 1 +HEALTHCHECK --interval=10s --timeout=3s CMD curl -f http://localhost:8888/actuator/health || exit 1 EXPOSE 8888 \ No newline at end of file diff --git a/config/src/main/java/com/piggymetrics/config/SecurityConfig.java b/config/src/main/java/com/piggymetrics/config/SecurityConfig.java new file mode 100644 index 0000000000..c6fd3c7160 --- /dev/null +++ b/config/src/main/java/com/piggymetrics/config/SecurityConfig.java @@ -0,0 +1,24 @@ +package com.piggymetrics.config; + +import org.springframework.context.annotation.Configuration; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; + +/** + * @author cdov + */ +@Configuration +public class SecurityConfig extends WebSecurityConfigurerAdapter { + + @Override + protected void configure(HttpSecurity http) throws Exception { + http.csrf().disable(); + http + .authorizeRequests() + .antMatchers("/actuator/**").permitAll() + .anyRequest().authenticated() + .and() + .httpBasic() + ; + } +}