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
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/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;
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();
+ }
+}
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
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
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..d146df2a7e
--- /dev/null
+++ b/auth-service/src/main/java/com/piggymetrics/auth/config/OAuth2AuthorizationConfig.java
@@ -0,0 +1,82 @@
+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.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;
+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();
+ private final String NOOP_PASSWORD_ENCODE = "{noop}";
+
+ @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()")
+ .passwordEncoder(NoOpPasswordEncoder.getInstance());
+ }
+
+}
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
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));
}
}
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);
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/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
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()
+ ;
+ }
+}
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
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/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
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:
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/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;
});
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
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
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
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/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;
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());
+ }
+}
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();
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
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
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
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/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;
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());
+ }
+}
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);