diff --git a/Vagrantfile b/Vagrantfile new file mode 100644 index 0000000..66eeec1 --- /dev/null +++ b/Vagrantfile @@ -0,0 +1,103 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : + +# All Vagrant configuration is done below. The "2" in Vagrant.configure +# configures the configuration version (we support older styles for +# backwards compatibility). Please don't change it unless you know what +# you're doing. +Vagrant.configure(2) do |config| + # The most common configuration options are documented and commented below. + # For a complete reference, please see the online documentation at + # https://docs.vagrantup.com. + + # Every Vagrant development environment requires a box. You can search for + # boxes at https://atlas.hashicorp.com/search. + config.vm.box = "ubuntu/trusty64" + + config.vm.provider "virtualbox" do |v| + v.memory = 2048 + v.cpus = 2 + end + + # Disable automatic box update checking. If you disable this, then + # boxes will only be checked for updates when the user runs + # `vagrant box outdated`. This is not recommended. + # config.vm.box_check_update = false + + # Create a forwarded port mapping which allows access to a specific port + # within the machine from a port on the host machine. In the example below, + # accessing "localhost:8080" will access port 80 on the guest machine. + # config.vm.network "forwarded_port", guest: 80, host: 8080 + + # Create a private network, which allows host-only access to the machine + # using a specific IP. + # config.vm.network "private_network", ip: "192.168.33.10" + + # Create a public network, which generally matched to bridged network. + # Bridged networks make the machine appear as another physical device on + # your network. + # config.vm.network "public_network" + + # Share an additional folder to the guest VM. The first argument is + # the path on the host to the actual folder. The second argument is + # the path on the guest to mount the folder. And the optional third + # argument is a set of non-required options. + # config.vm.synced_folder "../data", "/vagrant_data" + + # Provider-specific configuration so you can fine-tune various + # backing providers for Vagrant. These expose provider-specific options. + # Example for VirtualBox: + # + # config.vm.provider "virtualbox" do |vb| + # # Display the VirtualBox GUI when booting the machine + # vb.gui = true + # + # # Customize the amount of memory on the VM: + # vb.memory = "1024" + # end + # + # View the documentation for the provider you are using for more + # information on available options. + + # Define a Vagrant Push strategy for pushing to Atlas. Other push strategies + # such as FTP and Heroku are also available. See the documentation at + # https://docs.vagrantup.com/v2/push/atlas.html for more information. + # config.push.define "atlas" do |push| + # push.app = "YOUR_ATLAS_USERNAME/YOUR_APPLICATION_NAME" + # end + + # Enable provisioning with a shell script. Additional provisioners such as + # Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the + # documentation for more information about their specific syntax and use. + + config.vm.provision "shell", inline: <<-SHELL + #!/bin/sh + + # https://github.com/pussinboots/vagrant-devel/blob/master/provision/packages/java8.sh + + if which java >/dev/null; then + echo "skip java 8 installation" + else + echo "java 8 installation" + apt-get install --yes python-software-properties + add-apt-repository ppa:webupd8team/java + apt-get update -qq + echo debconf shared/accepted-oracle-license-v1-1 select true | /usr/bin/debconf-set-selections + echo debconf shared/accepted-oracle-license-v1-1 seen true | /usr/bin/debconf-set-selections + apt-get install --yes oracle-java8-installer + yes "" | apt-get -f install + fi +SHELL + + config.vm.provision "docker" do |d| + end + + config.vm.provision "shell", inline: <<-SHELL + if which docker-compose >/dev/null; then + echo "skip docker-compose installation" + else + sudo bash -c "curl -L https://github.com/docker/compose/releases/download/1.6.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose ; chmod +x /usr/local/bin/docker-compose" + fi +SHELL + +end diff --git a/_build-and-test-all.sh b/_build-and-test-all.sh index 5c1f2c4..8258cf0 100755 --- a/_build-and-test-all.sh +++ b/_build-and-test-all.sh @@ -16,8 +16,12 @@ fi ${DOCKER_COMPOSE?} up -d mongodb if [ -z "$DOCKER_HOST_IP" ] ; then - export DOCKER_HOST_IP=$(docker-machine ip default) - echo set DOCKER_HOST_IP $DOCKER_HOST_IP + if which docker-machine >/dev/null; then + export DOCKER_HOST_IP=$(docker-machine ip default) + else + export DOCKER_HOST_IP=localhost + fi + echo set DOCKER_HOST_IP $DOCKER_HOST_IP fi if [ -z "$SPRING_DATA_MONGODB_URI" ] ; then @@ -27,7 +31,7 @@ fi export SERVICE_HOST=$DOCKER_HOST_IP -./gradlew $* build +./gradlew $* build -x :e2e-test:test if [ -z "$EVENTUATE_API_KEY_ID" -o -z "$EVENTUATE_API_KEY_SECRET" ] ; then echo You must set EVENTUATE_API_KEY_ID and EVENTUATE_API_KEY_SECRET @@ -37,11 +41,11 @@ fi ${DOCKER_COMPOSE?} up -d -$DIR/wait-for-services.sh $DOCKER_HOST_IP +$DIR/wait-for-services.sh $DOCKER_HOST_IP 8080 8081 8082 set -e -./gradlew $* :e2e-test:cleanTest :e2e-test:test +./gradlew -a $* :e2e-test:cleanTest :e2e-test:test -P ignoreE2EFailures=false ${DOCKER_COMPOSE?} stop ${DOCKER_COMPOSE?} rm -v --force diff --git a/java-spring/backend-integration-tests/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/customers/CustomerQuerySideIntegrationTest.java b/java-spring/backend-integration-tests/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/customers/CustomerQuerySideIntegrationTest.java index 3398c51..2e6156f 100644 --- a/java-spring/backend-integration-tests/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/customers/CustomerQuerySideIntegrationTest.java +++ b/java-spring/backend-integration-tests/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/customers/CustomerQuerySideIntegrationTest.java @@ -5,10 +5,7 @@ import net.chrisrichardson.eventstore.EventStore; import net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.customers.Customer; import net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.customers.CustomerService; import net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.accounts.AccountInfo; -import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.Address; -import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.CustomerInfo; -import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.Name; -import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.ToAccountInfo; +import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.*; import net.chrisrichardson.eventstorestore.javaexamples.testutil.Producer; import net.chrisrichardson.eventstorestore.javaexamples.testutil.Verifier; import org.junit.Assert; diff --git a/java-spring/common-auth-controller/build.gradle b/java-spring/common-auth-controller/build.gradle deleted file mode 100644 index fe0d772..0000000 --- a/java-spring/common-auth-controller/build.gradle +++ /dev/null @@ -1,13 +0,0 @@ -apply plugin: 'java' - -dependencies { - compile project(":common-auth") - - compile "org.springframework.boot:spring-boot-starter-web:$springBootVersion" - - compile "org.springframework.security:spring-security-config:4.0.2.RELEASE" - compile "org.springframework.security:spring-security-web:4.0.2.RELEASE" - - - testCompile "junit:junit:4.11" -} diff --git a/java-spring/common-auth-controller/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/commonauth/model/AuthResponse.java b/java-spring/common-auth-controller/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/commonauth/model/AuthResponse.java deleted file mode 100644 index 0ef4336..0000000 --- a/java-spring/common-auth-controller/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/commonauth/model/AuthResponse.java +++ /dev/null @@ -1,23 +0,0 @@ -package net.chrisrichardson.eventstore.javaexamples.banking.commonauth.model; - -/** - * Created by popikyardo on 21.09.15. - */ -public class AuthResponse { - private String token; - - public AuthResponse() { - } - - public AuthResponse(String token) { - this.token = token; - } - - public String getToken() { - return token; - } - - public void setToken(String token) { - this.token = token; - } -} diff --git a/java-spring/common-auth-web/build.gradle b/java-spring/common-auth-web/build.gradle new file mode 100644 index 0000000..39dbd32 --- /dev/null +++ b/java-spring/common-auth-web/build.gradle @@ -0,0 +1,13 @@ +apply plugin: 'java' + +dependencies { + compile project(":common-auth") + compile project(":common-customers") + compile project(":common-web") + + compile "org.springframework.boot:spring-boot-starter-web:$springBootVersion" + compile "org.springframework.boot:spring-boot-starter-security:$springBootVersion" + compile "org.springframework.boot:spring-boot-starter-data-mongodb:$springBootVersion" + + testCompile "junit:junit:4.11" +} diff --git a/java-spring/common-auth-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/commonauth/CustomerAuthConfiguration.java b/java-spring/common-auth-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/commonauth/CustomerAuthConfiguration.java new file mode 100644 index 0000000..a16f3ba --- /dev/null +++ b/java-spring/common-auth-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/commonauth/CustomerAuthConfiguration.java @@ -0,0 +1,21 @@ +package net.chrisrichardson.eventstore.javaexamples.banking.commonauth; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.data.mongodb.repository.config.EnableMongoRepositories; + +/** + * Created by Main on 04.02.2016. + */ +@Configuration +@EnableMongoRepositories +@ComponentScan +public class CustomerAuthConfiguration { + + @Bean + public CustomerAuthService customerAuthService(CustomerAuthRepository customerAuthRepository) { + return new CustomerAuthService(customerAuthRepository); + } + +} diff --git a/java-spring/common-auth-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/commonauth/CustomerAuthRepository.java b/java-spring/common-auth-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/commonauth/CustomerAuthRepository.java new file mode 100644 index 0000000..e70d919 --- /dev/null +++ b/java-spring/common-auth-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/commonauth/CustomerAuthRepository.java @@ -0,0 +1,11 @@ +package net.chrisrichardson.eventstore.javaexamples.banking.commonauth; + +import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.QuerySideCustomer; +import org.springframework.data.mongodb.repository.MongoRepository; + +import java.util.List; + +interface CustomerAuthRepository extends MongoRepository { + + List findByEmail(String email); +} diff --git a/java-spring/common-auth-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/commonauth/CustomerAuthService.java b/java-spring/common-auth-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/commonauth/CustomerAuthService.java new file mode 100644 index 0000000..71f96f8 --- /dev/null +++ b/java-spring/common-auth-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/commonauth/CustomerAuthService.java @@ -0,0 +1,28 @@ +package net.chrisrichardson.eventstore.javaexamples.banking.commonauth; + +import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.QuerySideCustomer; +import org.springframework.dao.EmptyResultDataAccessException; +import org.springframework.dao.IncorrectResultSizeDataAccessException; + +import java.util.List; + +/** + * Created by Main on 15.02.2016. + */ +public class CustomerAuthService { + private CustomerAuthRepository customerAuthRepository; + + public CustomerAuthService(CustomerAuthRepository customerAuthRepository) { + this.customerAuthRepository = customerAuthRepository; + } + + public QuerySideCustomer findByEmail(String email){ + List customers = customerAuthRepository.findByEmail(email); + if (customers.isEmpty()) + throw new EmptyResultDataAccessException(1); + else if(customers.size()>1) + throw new IncorrectResultSizeDataAccessException(1, customers.size()); + else + return customers.get(0); + } +} diff --git a/java-spring/common-auth-controller/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/commonauth/controller/AuthController.java b/java-spring/common-auth-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/commonauth/controller/AuthController.java similarity index 66% rename from java-spring/common-auth-controller/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/commonauth/controller/AuthController.java rename to java-spring/common-auth-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/commonauth/controller/AuthController.java index 9af29fd..d7d1700 100644 --- a/java-spring/common-auth-controller/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/commonauth/controller/AuthController.java +++ b/java-spring/common-auth-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/commonauth/controller/AuthController.java @@ -1,8 +1,10 @@ package net.chrisrichardson.eventstore.javaexamples.banking.commonauth.controller; import com.fasterxml.jackson.databind.ObjectMapper; +import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.CustomerResponse; +import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.QuerySideCustomer; +import net.chrisrichardson.eventstore.javaexamples.banking.commonauth.CustomerAuthService; import net.chrisrichardson.eventstore.javaexamples.banking.commonauth.model.AuthRequest; -import net.chrisrichardson.eventstore.javaexamples.banking.commonauth.model.AuthResponse; import net.chrisrichardson.eventstore.javaexamples.banking.commonauth.model.User; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; @@ -29,16 +31,18 @@ public class AuthController { @Autowired private TokenService tokenService; + @Autowired + private CustomerAuthService customerAuthService; + private static ObjectMapper objectMapper = new ObjectMapper(); @RequestMapping(value = "/login", method = POST) - public ResponseEntity doAuth(@RequestBody @Valid AuthRequest request) throws IOException { - User user = new User(); - user.setEmail(request.getEmail()); + public ResponseEntity doAuth(@RequestBody @Valid AuthRequest request) throws IOException { + QuerySideCustomer customer = customerAuthService.findByEmail(request.getEmail()); - Token token = tokenService.allocateToken(objectMapper.writeValueAsString(user)); - return ResponseEntity.status(HttpStatus.OK) - .body(new AuthResponse(token.getKey())); + Token token = tokenService.allocateToken(objectMapper.writeValueAsString(new User(request.getEmail()))); + return ResponseEntity.status(HttpStatus.OK).header("access-token", token.getKey()) + .body(new CustomerResponse(customer.getId(), customer)); } diff --git a/java-spring/common-auth-controller/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/commonauth/model/AuthRequest.java b/java-spring/common-auth-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/commonauth/model/AuthRequest.java similarity index 100% rename from java-spring/common-auth-controller/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/commonauth/model/AuthRequest.java rename to java-spring/common-auth-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/commonauth/model/AuthRequest.java diff --git a/java-spring/common-auth/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/commonauth/AuthConfiguration.java b/java-spring/common-auth/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/commonauth/AuthConfiguration.java index 6a0808c..b8e2c1b 100755 --- a/java-spring/common-auth/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/commonauth/AuthConfiguration.java +++ b/java-spring/common-auth/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/commonauth/AuthConfiguration.java @@ -52,11 +52,10 @@ public class AuthConfiguration extends WebSecurityConfigurerAdapter { .antMatchers("/health").permitAll() .antMatchers("/swagger-ui.html").permitAll() .antMatchers("/v2/api-docs").permitAll() - .antMatchers("/js/**").permitAll() - .antMatchers("/styles/**").permitAll() - .antMatchers("/views/**").permitAll() - .antMatchers(HttpMethod.POST, "/register/step_1").permitAll() - .antMatchers(HttpMethod.POST, "/register/step_2").permitAll() + .antMatchers("/js*//**").permitAll() + .antMatchers("/styles*//**").permitAll() + .antMatchers("/views*//**").permitAll() + .antMatchers(HttpMethod.POST, "/customers").permitAll() .antMatchers(HttpMethod.POST, "/login").permitAll() .anyRequest().authenticated().and() .addFilterBefore(new StatelessAuthenticationFilter(tokenAuthenticationService), UsernamePasswordAuthenticationFilter.class); diff --git a/java-spring/common-auth/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/commonauth/model/User.java b/java-spring/common-auth/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/commonauth/model/User.java index 9e793b4..a5841d5 100755 --- a/java-spring/common-auth/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/commonauth/model/User.java +++ b/java-spring/common-auth/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/commonauth/model/User.java @@ -18,6 +18,13 @@ public class User implements UserDetails { private String email; + public User() { + } + + public User(String email) { + this.email = email; + } + public void setUsername(String username) { this.email = username; } diff --git a/java-spring/common-auth/src/main/resources/auth.properties b/java-spring/common-auth/src/main/resources/auth.properties new file mode 100644 index 0000000..f3bfa4a --- /dev/null +++ b/java-spring/common-auth/src/main/resources/auth.properties @@ -0,0 +1,2 @@ +auth.serverSecret=the_cake_is_a_lie +auth.serverInteger=1 \ No newline at end of file diff --git a/java-spring/customers-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/customers/QuerySideCustomer.java b/java-spring/common-customers/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/customers/QuerySideCustomer.java similarity index 58% rename from java-spring/customers-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/customers/QuerySideCustomer.java rename to java-spring/common-customers/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/customers/QuerySideCustomer.java index e5dde3c..3167d8b 100644 --- a/java-spring/customers-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/customers/QuerySideCustomer.java +++ b/java-spring/common-customers/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/customers/QuerySideCustomer.java @@ -1,9 +1,4 @@ -package net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.customers; - -import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.Address; -import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.CustomerInfo; -import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.Name; -import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.ToAccountInfo; +package net.chrisrichardson.eventstore.javaexamples.banking.common.customers; import java.util.Map; diff --git a/java-spring/customers-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/customers/CustomerInfoUpdateService.java b/java-spring/customers-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/customers/CustomerInfoUpdateService.java index f71b3ac..53250ca 100644 --- a/java-spring/customers-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/customers/CustomerInfoUpdateService.java +++ b/java-spring/customers-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/customers/CustomerInfoUpdateService.java @@ -1,6 +1,7 @@ package net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.customers; import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.CustomerInfo; +import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.QuerySideCustomer; import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.ToAccountInfo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/java-spring/customers-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/customers/CustomerQueryService.java b/java-spring/customers-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/customers/CustomerQueryService.java index e17b643..2a866e6 100644 --- a/java-spring/customers-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/customers/CustomerQueryService.java +++ b/java-spring/customers-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/customers/CustomerQueryService.java @@ -1,6 +1,7 @@ package net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.customers; import net.chrisrichardson.eventstore.EntityIdentifier; +import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.QuerySideCustomer; import org.springframework.dao.EmptyResultDataAccessException; import rx.Observable; diff --git a/java-spring/customers-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/customers/QuerySideCustomerRepository.java b/java-spring/customers-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/customers/QuerySideCustomerRepository.java index 258a33a..35bbfba 100644 --- a/java-spring/customers-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/customers/QuerySideCustomerRepository.java +++ b/java-spring/customers-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/customers/QuerySideCustomerRepository.java @@ -1,5 +1,6 @@ package net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.customers; +import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.QuerySideCustomer; import org.springframework.data.mongodb.repository.MongoRepository; import java.util.List; diff --git a/java-spring/customers-query-side-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/queryside/customers/CustomerQueryController.java b/java-spring/customers-query-side-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/queryside/customers/CustomerQueryController.java index 06e2a09..9b9ac85 100644 --- a/java-spring/customers-query-side-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/queryside/customers/CustomerQueryController.java +++ b/java-spring/customers-query-side-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/queryside/customers/CustomerQueryController.java @@ -2,8 +2,8 @@ package net.chrisrichardson.eventstore.javaexamples.banking.web.queryside.custom import net.chrisrichardson.eventstore.EntityIdentifier; import net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.customers.CustomerQueryService; -import net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.customers.QuerySideCustomer; import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.CustomerResponse; +import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.QuerySideCustomer; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.EmptyResultDataAccessException; import org.springframework.http.HttpStatus; diff --git a/java-spring/monolithic-service/build.gradle b/java-spring/monolithic-service/build.gradle index 0129c38..798a144 100644 --- a/java-spring/monolithic-service/build.gradle +++ b/java-spring/monolithic-service/build.gradle @@ -8,6 +8,7 @@ dependencies { compile project(":transactions-command-side-web") compile project(":customers-command-side-web") compile project(":customers-query-side-web") + compile project(":common-auth-web") compile "org.springframework.boot:spring-boot-starter-web" compile "org.springframework.boot:spring-boot-starter-actuator" diff --git a/java-spring/monolithic-service/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/BankingWebConfiguration.java b/java-spring/monolithic-service/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/BankingWebConfiguration.java index 8693281..e7aef83 100644 --- a/java-spring/monolithic-service/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/BankingWebConfiguration.java +++ b/java-spring/monolithic-service/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/BankingWebConfiguration.java @@ -1,5 +1,6 @@ package net.chrisrichardson.eventstore.javaexamples.banking.web; +import net.chrisrichardson.eventstore.javaexamples.banking.commonauth.CustomerAuthConfiguration; import net.chrisrichardson.eventstore.javaexamples.banking.web.commandside.accounts.CommandSideWebAccountsConfiguration; import net.chrisrichardson.eventstore.javaexamples.banking.web.commandside.customers.CustomersCommandSideWebConfiguration; import net.chrisrichardson.eventstore.javaexamples.banking.web.commandside.transactions.CommandSideWebTransactionsConfiguration; @@ -16,7 +17,7 @@ import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; @Configuration -@Import({CommandSideWebAccountsConfiguration.class, CommandSideWebTransactionsConfiguration.class, JdbcEventStoreConfiguration.class, QuerySideWebConfiguration.class, CustomersQuerySideWebConfiguration.class, CustomersCommandSideWebConfiguration.class}) +@Import({CommandSideWebAccountsConfiguration.class, CommandSideWebTransactionsConfiguration.class, JdbcEventStoreConfiguration.class, QuerySideWebConfiguration.class, CustomersQuerySideWebConfiguration.class, CustomersCommandSideWebConfiguration.class, CustomerAuthConfiguration.class}) @EnableAutoConfiguration @ComponentScan public class BankingWebConfiguration { diff --git a/java-spring/monolithic-service/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/web/BankingAuthTest.java b/java-spring/monolithic-service/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/web/BankingAuthTest.java new file mode 100644 index 0000000..489509f --- /dev/null +++ b/java-spring/monolithic-service/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/web/BankingAuthTest.java @@ -0,0 +1,92 @@ +package net.chrisrichardson.eventstore.javaexamples.banking.web; + +import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.Address; +import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.CustomerInfo; +import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.CustomerResponse; +import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.Name; +import net.chrisrichardson.eventstore.javaexamples.banking.commonauth.model.AuthRequest; +import net.chrisrichardson.eventstorestore.javaexamples.testutil.Producer; +import net.chrisrichardson.eventstorestore.javaexamples.testutil.Verifier; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.test.IntegrationTest; +import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.web.WebAppConfiguration; +import org.springframework.web.client.RestTemplate; +import rx.Observable; + +import static net.chrisrichardson.eventstorestore.javaexamples.testutil.TestUtil.eventually; + +/** + * Created by Main on 15.02.2016. + */ +@RunWith(SpringJUnit4ClassRunner.class) +@SpringApplicationConfiguration(classes = BankingWebTestConfiguration.class) +@WebAppConfiguration +@IntegrationTest({"server.port=0", "management.port=0"}) +public class BankingAuthTest { + + @Value("${local.server.port}") + private int port; + + @Autowired + RestTemplate restTemplate; + + private String baseUrl(String path) { + return "http://localhost:" + port + "/" + path; + } + + @Test + public void shouldCreateCustomerAndLogin() { + CustomerInfo customerInfo = generateCustomerInfo(); + + final CustomerResponse customerResponse = restTemplate.postForEntity(baseUrl("/customers"), customerInfo, CustomerResponse.class).getBody(); + final String customerId = customerResponse.getId(); + + Assert.assertNotNull(customerId); + Assert.assertEquals(customerInfo, customerResponse.getCustomerInfo()); + + assertCustomerResponse(customerId, customerInfo); + + AuthRequest authRequest = new AuthRequest("current@email.com"); + + final CustomerResponse loginCustomerResponse = restTemplate.postForEntity(baseUrl("/login"), authRequest, CustomerResponse.class).getBody(); + + Assert.assertEquals(customerResponse, loginCustomerResponse); + } + + private void assertCustomerResponse(final String customerId, final CustomerInfo customerInfo) { + eventually( + new Producer() { + @Override + public Observable produce() { + return Observable.just(restTemplate.getForEntity(baseUrl("/customers/" + customerId), CustomerResponse.class).getBody()); + } + }, + new Verifier() { + @Override + public void verify(CustomerResponse customerResponse) { + Assert.assertEquals(customerId, customerResponse.getId()); + Assert.assertEquals(customerInfo, customerResponse.getCustomerInfo()); + } + }); + } + + private CustomerInfo generateCustomerInfo() { + return new CustomerInfo( + new Name("John", "Doe"), + "current@email.com", + "000-00-0000", + "1-111-111-1111", + new Address("street 1", + "street 2", + "City", + "State", + "1111111") + ); + } +} diff --git a/java-spring/settings.gradle b/java-spring/settings.gradle index bd1aad8..17fac6e 100644 --- a/java-spring/settings.gradle +++ b/java-spring/settings.gradle @@ -32,5 +32,5 @@ include 'customers-query-side-web' include 'common-customers' include 'customers-command-side-service' include 'customers-query-side-service' -include 'common-auth-controller' +include 'common-auth-web' diff --git a/wait-for-services.sh b/wait-for-services.sh index d5afa85..304f097 100755 --- a/wait-for-services.sh +++ b/wait-for-services.sh @@ -1,11 +1,25 @@ #! /bin/bash -while [[ true ]]; do - nc -z -w 4 ${1?} 8080 && nc -z -w 4 ${1?} 8081 && nc -z -w 4 ${1?} 8082 - if [[ "$?" -eq "0" ]]; then +done=false + +host=$1 +shift +ports=$* + +while [[ "$done" = false ]]; do + for port in $ports; do + curl -q http://${host}:${port}/health >& /dev/null + if [[ "$?" -eq "0" ]]; then + done=true + else + done=false + fi + done + if [[ "$done" = true ]]; then echo connected - break - fi + break; + fi + #curl -q http://${1?}:8080/health >& /dev/null && curl -q http://${1?}:8081/health >& /dev/null && curl -q http://${1?}:8082/health >& /dev/null echo -n . sleep 1 done