diff --git a/PhotoAppAPIConfigServer/UnlimitedJCEPolicyJDK8/README.txt b/PhotoAppAPIConfigServer/UnlimitedJCEPolicyJDK8/README.txt deleted file mode 100644 index c0d9942..0000000 --- a/PhotoAppAPIConfigServer/UnlimitedJCEPolicyJDK8/README.txt +++ /dev/null @@ -1,196 +0,0 @@ - - Unlimited Strength Java(TM) Cryptography Extension Policy Files - for the Java(TM) Platform, Standard Edition Runtime Environment 8 - - README - ----------------------------------------------------------------------- -CONTENTS ----------------------------------------------------------------------- - - o Introduction - o License and Terms - o Understanding The Export/Import Issues - o Where To Find Documentation - o Installation - o Questions, Support, Reporting Bugs - - ----------------------------------------------------------------------- -Introduction ----------------------------------------------------------------------- - -Thank you for downloading the Unlimited Strength Java(TM) Cryptography -Extension (JCE) Policy Files for the Java(TM) Platform, Standard -Edition (Java SE) Runtime Environment 8. - -Due to import control restrictions of some countries, the version of -the JCE policy files that are bundled in the Java Runtime Environment, -or JRE(TM), 8 environment allow "strong" but limited cryptography to be -used. This download bundle (the one including this README file) -provides "unlimited strength" policy files which contain no -restrictions on cryptographic strengths. - -Please note that this download file does NOT contain any encryption -functionality as all such functionality is contained within Oracle's -JRE 8. This bundles assumes that the JRE 8 has already been installed. - - ----------------------------------------------------------------------- -License and Terms ----------------------------------------------------------------------- - -This download bundle is part of the Java SE Platform products and is -governed by same License and Terms notices. These notices can be found -on the Java SE download site: - - http://www.oracle.com/technetwork/java/javase/documentation/index.html - - ----------------------------------------------------------------------- -Understanding The Export/Import Issues ----------------------------------------------------------------------- - -JCE for Java SE 8 has been through the U.S. export review process. The -JCE framework, along with the various JCE providers that come standard -with it (SunJCE, SunEC, SunPKCS11, SunMSCAPI, etc), is exportable. - -The JCE architecture allows flexible cryptographic strength to be -configured via jurisdiction policy files. Due to the import -restrictions of some countries, the jurisdiction policy files -distributed with the Java SE 8 software have built-in restrictions on -available cryptographic strength. The jurisdiction policy files in this -download bundle (the bundle including this README file) contain no -restrictions on cryptographic strengths. This is appropriate for most -countries. Framework vendors can create download bundles that include -jurisdiction policy files that specify cryptographic restrictions -appropriate for countries whose governments mandate restrictions. Users -in those countries can download an appropriate bundle, and the JCE -framework will enforce the specified restrictions. - -You are advised to consult your export/import control counsel or -attorney to determine the exact requirements. - - ----------------------------------------------------------------------- -Where To Find Documentation ----------------------------------------------------------------------- - -The following documents may be of interest to you: - - o The Java(TM) Cryptography Architecture (JCA) Reference Guide at: - - http://docs.oracle.com/javase/8/docs/technotes/guides/security - - o The Java SE Security web site has more information about JCE, - plus additional information about the Java SE Security Model. - Please see: - - http://www.oracle.com/technetwork/java/javase/tech/index-jsp-136007.html - - ----------------------------------------------------------------------- -Installation ----------------------------------------------------------------------- - -Notes: - - o Unix (Solaris/Linux/Mac OS X) and Windows use different pathname - separators, so please use the appropriate one ("\", "/") for your - environment. - - o (below) refers to the directory where the JRE was - installed. It is determined based on whether you are running JCE - on a JRE or a JRE contained within the Java Development Kit, or - JDK(TM). The JDK contains the JRE, but at a different level in the - file hierarchy. For example, if the JDK is installed in - /home/user1/jdk1.8.0 on Unix or in C:\jdk1.8.0 on Windows, then - is: - - /home/user1/jdk1.8.0/jre [Unix] - C:\jdk1.8.0\jre [Windows] - - If on the other hand the JRE is installed in /home/user1/jre1.8.0 - on Unix or in C:\jre1.8.0 on Windows, and the JDK is not - installed, then is: - - /home/user1/jre1.8.0 [Unix] - C:\jre1.8.0 [Windows] - - o On Windows, for each JDK installation, there may be additional - JREs installed under the "Program Files" directory. Please make - sure that you install the unlimited strength policy JAR files - for all JREs that you plan to use. - - -Here are the installation instructions: - -1) Download the unlimited strength JCE policy files. - -2) Uncompress and extract the downloaded file. - - This will create a subdirectory called jce. - This directory contains the following files: - - README.txt This file - local_policy.jar Unlimited strength local policy file - US_export_policy.jar Unlimited strength US export policy file - -3) Install the unlimited strength policy JAR files. - - In case you later decide to revert to the original "strong" but - limited policy versions, first make a copy of the original JCE - policy files (US_export_policy.jar and local_policy.jar). Then - replace the strong policy files with the unlimited strength - versions extracted in the previous step. - - The standard place for JCE jurisdiction policy JAR files is: - - /lib/security [Unix] - \lib\security [Windows] - - ------------------------------------------------------------------------ -Questions, Support, Reporting Bugs ------------------------------------------------------------------------ - -Questions ---------- - -For miscellaneous questions about JCE usage and deployment, we -encourage you to read: - - o Information on the Java SE Security web site - - http://www.oracle.com/technetwork/java/javase/tech/index-jsp-136007.html - - o The Oracle Online Community Forums, specifically the Java - Cryptography forum. The forums allow you to tap into the - experience of other users, ask questions, or offer tips to others - on a variety of Java-related topics, including JCE. There is no - fee to participate. - - http://forums.oracle.com/ - http://forums.oracle.com/forums/forum.jspa?forumID=964 (JCE - forum) - - -Support -------- - -For more extensive JCE questions or deployment issues, please contact -our Technical Support staff at: - - http://support.oracle.com - - -Reporting Bugs --------------- - -To report bugs (with sample code) or request a feature, please see: - - http://bugs.sun.com/ - http://bugreport.sun.com/bugreport/ - -Bug reports with specific, reproducible test cases are greatly -appreciated! diff --git a/PhotoAppAPIConfigServer/UnlimitedJCEPolicyJDK8/US_export_policy.jar b/PhotoAppAPIConfigServer/UnlimitedJCEPolicyJDK8/US_export_policy.jar deleted file mode 100644 index 251b102..0000000 Binary files a/PhotoAppAPIConfigServer/UnlimitedJCEPolicyJDK8/US_export_policy.jar and /dev/null differ diff --git a/PhotoAppAPIConfigServer/UnlimitedJCEPolicyJDK8/local_policy.jar b/PhotoAppAPIConfigServer/UnlimitedJCEPolicyJDK8/local_policy.jar deleted file mode 100644 index 1c58939..0000000 Binary files a/PhotoAppAPIConfigServer/UnlimitedJCEPolicyJDK8/local_policy.jar and /dev/null differ diff --git a/PhotoAppAPIConfigServer/apiEncryptionKey.jks b/PhotoAppAPIConfigServer/apiEncryptionKey.jks index dca3810..925478f 100644 Binary files a/PhotoAppAPIConfigServer/apiEncryptionKey.jks and b/PhotoAppAPIConfigServer/apiEncryptionKey.jks differ diff --git a/PhotoAppAPIConfigServer/dockerfile b/PhotoAppAPIConfigServer/dockerfile index 6e8f070..55f2e0f 100644 --- a/PhotoAppAPIConfigServer/dockerfile +++ b/PhotoAppAPIConfigServer/dockerfile @@ -1,6 +1,7 @@ -FROM openjdk:8-jdk-alpine +FROM openjdk:11 VOLUME /tmp COPY apiEncryptionKey.jks apiEncryptionKey.jks -COPY UnlimitedJCEPolicyJDK8/* /usr/lib/jvm/java-1.8-openjdk/jre/lib/security/ +# this is no longer needed as with jdk11 unlimited crypto policies are installed by default: +#COPY UnlimitedJCEPolicyJDK8/* /usr/lib/jvm/java-1.8-openjdk/jre/lib/security/ COPY target/PhotoAppAPIConfigServer-0.0.1-SNAPSHOT.jar ConfigServer.jar ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","ConfigServer.jar"] \ No newline at end of file diff --git a/PhotoAppAPIConfigServer/pom.xml b/PhotoAppAPIConfigServer/pom.xml index e0c7bc8..e33f882 100644 --- a/PhotoAppAPIConfigServer/pom.xml +++ b/PhotoAppAPIConfigServer/pom.xml @@ -6,7 +6,7 @@ org.springframework.boot spring-boot-starter-parent - 2.1.3.RELEASE + 2.3.12.RELEASE com.appsdeveloperblog.photoapp.api @@ -16,8 +16,8 @@ Config Server - 1.8 - Greenwich.SR1 + 11 + Hoxton.SR8 @@ -31,8 +31,7 @@ spring-boot-starter-test test - - + org.springframework.cloud spring-cloud-starter-bus-amqp diff --git a/PhotoAppAPIConfigServer/src/main/java/com/appsdeveloperblog/photoapp/api/PhotoAppApiConfigServerApplication.java b/PhotoAppAPIConfigServer/src/main/java/com/appsdeveloperblog/photoapp/api/PhotoAppApiConfigServerApplication.java index af60c13..a5d2d0a 100644 --- a/PhotoAppAPIConfigServer/src/main/java/com/appsdeveloperblog/photoapp/api/PhotoAppApiConfigServerApplication.java +++ b/PhotoAppAPIConfigServer/src/main/java/com/appsdeveloperblog/photoapp/api/PhotoAppApiConfigServerApplication.java @@ -8,8 +8,8 @@ @EnableConfigServer public class PhotoAppApiConfigServerApplication { - public static void main(String[] args) { - SpringApplication.run(PhotoAppApiConfigServerApplication.class, args); - } + public static void main(String[] args) { + SpringApplication.run(PhotoAppApiConfigServerApplication.class, args); + } } diff --git a/PhotoAppAPIConfigServer/src/main/resources/application.properties b/PhotoAppAPIConfigServer/src/main/resources/application.properties index 892f1c7..ba89354 100644 --- a/PhotoAppAPIConfigServer/src/main/resources/application.properties +++ b/PhotoAppAPIConfigServer/src/main/resources/application.properties @@ -1,15 +1,31 @@ spring.application.name=PhotoAppAPIConfigServer server.port=8012 -spring.profiles.active=native +# Use this GET request to list fetched properties http://localhost:8012/PhotoAppAPIConfigServer/git +spring.profiles.active=git -spring.cloud.config.server.native.searchLocations=file://${user.home}/Desktop/dev/config-server-nfs +#spring.cloud.config.server.native.searchLocations=file://${user.home}/Desktop/dev/config-server-nfs -spring.cloud.config.server.git.uri=https://github.com/simplyi/PhotoAppConfiguration -spring.cloud.config.server.git.username=simplyi -spring.cloud.config.server.git.password= +spring.cloud.config.server.git.uri=git@github.com:zkvarz/PhotoAppConfiguration.git spring.cloud.config.server.git.clone-on-start=true spring.cloud.config.server.git.force-pull=true -spring.cloud.config.server.git.searchPaths=usersws,zuul +spring.cloud.config.server.git.default-label=main +#spring.cloud.config.server.git.searchPaths=usersws,zuul +spring.cloud.config.server.git.ignore-local-ssh-settings=true + +#Make sure to generate RSA keys in PEM format! Here is the command I used: ssh-keygen -m PEM -t rsa -b 4096 +spring.cloud.config.server.git.private-key=\ +-----BEGIN RSA PRIVATE KEY-----\n\ +YOURKEY3\n\ +YOURKEY3\n\ +-----END RSA PRIVATE KEY----- + +# You can use public cloud config example for testing purposes, just uncommenting: +#spring.cloud.config.server.git.uri=https://github.com/spring-cloud-samples/config-repo +#Location where properties will be stored: +#spring.cloud.config.server.git.basedir=target/config +#spring.cloud.config.server.git.default-label=main +#spring.cloud.config.server.git.clone-on-start=true +#spring.cloud.config.server.git.force-pull=true management.endpoints.web.exposure.include=bus-refresh @@ -17,3 +33,6 @@ spring.rabbitmq.host=localhost spring.rabbitmq.port=5672 spring.rabbitmq.username=guest spring.rabbitmq.password=guest + +logging.level.root=INFO +logging.level.org.springframework.cloud=TRACE \ No newline at end of file diff --git a/PhotoAppAPIConfigServer/src/main/resources/bootstrap.properties b/PhotoAppAPIConfigServer/src/main/resources/bootstrap.properties index db5c1ac..9e71f87 100644 --- a/PhotoAppAPIConfigServer/src/main/resources/bootstrap.properties +++ b/PhotoAppAPIConfigServer/src/main/resources/bootstrap.properties @@ -1,5 +1,10 @@ +# Uncomment to use symmetric encrypted properties. +# You can encrypt sending text in request body with POST http://localhost:8012/encrypt +# You can also decrypt sending encrypted text in request body with POST http://localhost:8012/decrypt #encrypt.key=fhf73odjsjkhHld98yurH983ndksku48slfhcflfdjG -encrypt.key-store.location=file://${user.home}/Desktop/dev/apiEncryptionKey.jks -encrypt.key-store.password=1q2w3e4r +# Generated encryption key for asymmetric encryption via command, e.g.: +# keytool -genkeypair -alias apiEncryptionKey -keyalg RSA -dname "CN=Kirill,OU=API Development,O=kirill.com,L=Kherson,S=Kherson,C=Ukraine" -keypass 1asdfasdf -keystore apiEncryptionKey.jks -storepass 1asdfasdf +encrypt.key-store.location=file:///C:/Users/kvarivoda/apiEncryptionKey.jks +encrypt.key-store.password=1asdfasdf encrypt.key-store.alias=apiEncryptionKey \ No newline at end of file diff --git a/PhotoAppApiAccountManagement/pom.xml b/PhotoAppApiAccountManagement/pom.xml index 79331ed..512262e 100644 --- a/PhotoAppApiAccountManagement/pom.xml +++ b/PhotoAppApiAccountManagement/pom.xml @@ -6,7 +6,7 @@ org.springframework.boot spring-boot-starter-parent - 2.1.3.RELEASE + 2.3.12.RELEASE com.appsdeveloperblog.photoapp.api.account @@ -16,8 +16,8 @@ Account Management microservice - 1.8 - Greenwich.RELEASE + 11 + Hoxton.SR12 diff --git a/PhotoAppApiAccountManagement/src/main/resources/application.properties b/PhotoAppApiAccountManagement/src/main/resources/application.properties index 86465c6..1c1865d 100644 --- a/PhotoAppApiAccountManagement/src/main/resources/application.properties +++ b/PhotoAppApiAccountManagement/src/main/resources/application.properties @@ -1,7 +1,7 @@ server.port=0 spring.application.name=account-ws -eureka.client.serviceUrl.defaultZone = http://localhost:8010/eureka -spring.devtools.restart.enabled = true +eureka.client.serviceUrl.defaultZone=http://test:test@localhost:8010/eureka +spring.devtools.restart.enabled=true spring.rabbitmq.host=localhost spring.rabbitmq.port=5672 diff --git a/PhotoAppApiAlbums/dockerfile b/PhotoAppApiAlbums/dockerfile index e6cb83f..b31bb50 100644 --- a/PhotoAppApiAlbums/dockerfile +++ b/PhotoAppApiAlbums/dockerfile @@ -1,4 +1,4 @@ -FROM openjdk:8-jdk-alpine +FROM openjdk:11 VOLUME /tmp COPY target/PhotoAppApiAlbums-0.0.1-SNAPSHOT.jar PhotoAppApiAlbums.jar ENTRYPOINT ["java","-jar","PhotoAppApiAlbums.jar"] \ No newline at end of file diff --git a/PhotoAppApiAlbums/pom.xml b/PhotoAppApiAlbums/pom.xml index 910cdf9..f38b6e1 100644 --- a/PhotoAppApiAlbums/pom.xml +++ b/PhotoAppApiAlbums/pom.xml @@ -5,7 +5,7 @@ org.springframework.boot spring-boot-starter-parent - 2.1.2.RELEASE + 2.3.12.RELEASE com.appsdeveloperblog.photoapp.api.albums @@ -15,8 +15,8 @@ Demo project for Spring Boot - 1.8 - Greenwich.RELEASE + 11 + Hoxton.SR12 @@ -44,7 +44,7 @@ org.modelmapper modelmapper - 2.0.0 + 2.4.4 diff --git a/PhotoAppApiAlbums/src/main/resources/application.properties b/PhotoAppApiAlbums/src/main/resources/application.properties index 58920d0..cc4758a 100644 --- a/PhotoAppApiAlbums/src/main/resources/application.properties +++ b/PhotoAppApiAlbums/src/main/resources/application.properties @@ -1,7 +1,7 @@ server.port=${PORT:0} spring.application.name=albums-ws -eureka.client.serviceUrl.defaultZone = http://localhost:8010/eureka +eureka.client.serviceUrl.defaultZone=http://test:test@localhost:8010/eureka eureka.instance.instance-id=${spring.application.name}:${spring.application.instance_id:${random.value}} spring.devtools.restart.enabled = true diff --git a/PhotoAppApiUsers/dockerfile b/PhotoAppApiUsers/dockerfile index 681057d..ab219ea 100644 --- a/PhotoAppApiUsers/dockerfile +++ b/PhotoAppApiUsers/dockerfile @@ -1,4 +1,4 @@ -FROM openjdk:8-jdk-alpine +FROM openjdk:11 VOLUME /tmp COPY target/PhotoAppApiUsers-0.0.1-SNAPSHOT.jar users-microservice.jar ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/users-microservice.jar"] \ No newline at end of file diff --git a/PhotoAppApiUsers/pom.xml b/PhotoAppApiUsers/pom.xml index 614c729..fb8322e 100644 --- a/PhotoAppApiUsers/pom.xml +++ b/PhotoAppApiUsers/pom.xml @@ -6,7 +6,7 @@ org.springframework.boot spring-boot-starter-parent - 2.1.4.RELEASE + 2.3.12.RELEASE com.appsdeveloperblog.photoapp.api.users @@ -16,8 +16,8 @@ Users microservice - 1.8 - Greenwich.RELEASE + 11 + Hoxton.SR12 @@ -58,7 +58,7 @@ org.modelmapper modelmapper - 2.3.2 + 2.4.4 diff --git a/PhotoAppApiUsers/src/main/java/com/appsdeveloperblog/photoapp/api/users/PhotoAppApiUsersApplication.java b/PhotoAppApiUsers/src/main/java/com/appsdeveloperblog/photoapp/api/users/PhotoAppApiUsersApplication.java index d8ec5f4..3461123 100644 --- a/PhotoAppApiUsers/src/main/java/com/appsdeveloperblog/photoapp/api/users/PhotoAppApiUsersApplication.java +++ b/PhotoAppApiUsers/src/main/java/com/appsdeveloperblog/photoapp/api/users/PhotoAppApiUsersApplication.java @@ -13,8 +13,6 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.web.client.RestTemplate; -import com.appsdeveloperblog.photoapp.api.users.shared.FeignErrorDecoder; - import feign.Logger; @SpringBootApplication @@ -77,7 +75,8 @@ public String createDevelopmentBean() { System.out.println("Development bean created. myapplication.environment = " + environment.getProperty("myapplication.environment")); return "Development bean"; } - + + //As FeignErrorDecoder class is annotated with Component this is not needed, left for reference. /* @Bean public FeignErrorDecoder getFeignErrorDecoder() diff --git a/PhotoAppApiUsers/src/main/java/com/appsdeveloperblog/photoapp/api/users/security/WebSecurity.java b/PhotoAppApiUsers/src/main/java/com/appsdeveloperblog/photoapp/api/users/security/WebSecurity.java index 27982a3..e0d78ea 100644 --- a/PhotoAppApiUsers/src/main/java/com/appsdeveloperblog/photoapp/api/users/security/WebSecurity.java +++ b/PhotoAppApiUsers/src/main/java/com/appsdeveloperblog/photoapp/api/users/security/WebSecurity.java @@ -15,7 +15,7 @@ @Configuration @EnableWebSecurity public class WebSecurity extends WebSecurityConfigurerAdapter { - + private Environment environment; private UsersService usersService; private BCryptPasswordEncoder bCryptPasswordEncoder; @@ -31,20 +31,21 @@ public WebSecurity(Environment environment, UsersService usersService, BCryptPas @Override protected void configure(HttpSecurity http) throws Exception { http.csrf().disable(); + //if you want to permit to all for testing: + //http.authorizeRequests().antMatchers("/users/**").permitAll() http.authorizeRequests().antMatchers("/**").hasIpAddress(environment.getProperty("gateway.ip")) .and() .addFilter(getAuthenticationFilter()); http.headers().frameOptions().disable(); } - + private AuthenticationFilter getAuthenticationFilter() throws Exception { AuthenticationFilter authenticationFilter = new AuthenticationFilter(usersService, environment, authenticationManager()); - //authenticationFilter.setAuthenticationManager(authenticationManager()); authenticationFilter.setFilterProcessesUrl(environment.getProperty("login.url.path")); return authenticationFilter; } - + @Override protected void configure(AuthenticationManagerBuilder auth) throws Exception { auth.userDetailsService(usersService).passwordEncoder(bCryptPasswordEncoder); diff --git a/PhotoAppApiUsers/src/main/java/com/appsdeveloperblog/photoapp/api/users/service/UsersServiceImpl.java b/PhotoAppApiUsers/src/main/java/com/appsdeveloperblog/photoapp/api/users/service/UsersServiceImpl.java index 6e55eb3..129eeb3 100644 --- a/PhotoAppApiUsers/src/main/java/com/appsdeveloperblog/photoapp/api/users/service/UsersServiceImpl.java +++ b/PhotoAppApiUsers/src/main/java/com/appsdeveloperblog/photoapp/api/users/service/UsersServiceImpl.java @@ -1,31 +1,25 @@ package com.appsdeveloperblog.photoapp.api.users.service; -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; - +import com.appsdeveloperblog.photoapp.api.users.data.AlbumsServiceClient; +import com.appsdeveloperblog.photoapp.api.users.data.UserEntity; +import com.appsdeveloperblog.photoapp.api.users.data.UsersRepository; +import com.appsdeveloperblog.photoapp.api.users.shared.UserDto; +import com.appsdeveloperblog.photoapp.api.users.ui.model.AlbumResponseModel; import org.modelmapper.ModelMapper; import org.modelmapper.convention.MatchingStrategies; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.core.ParameterizedTypeReference; import org.springframework.core.env.Environment; -import org.springframework.http.HttpMethod; -import org.springframework.http.ResponseEntity; import org.springframework.security.core.userdetails.User; import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UsernameNotFoundException; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.stereotype.Service; -import org.springframework.web.client.RestTemplate; -import com.appsdeveloperblog.photoapp.api.users.shared.UserDto; -import com.appsdeveloperblog.photoapp.api.users.ui.model.AlbumResponseModel; - -import feign.FeignException; - -import com.appsdeveloperblog.photoapp.api.users.data.*; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; @Service public class UsersServiceImpl implements UsersService { @@ -95,7 +89,8 @@ public UserDto getUserByUserId(String userId) { if(userEntity == null) throw new UsernameNotFoundException("User not found"); UserDto userDto = new ModelMapper().map(userEntity, UserDto.class); - + + //Uncomment to use RestTemplate with client side load balancing /* String albumsUrl = String.format(environment.getProperty("albums.url"), userId); diff --git a/PhotoAppApiUsers/src/main/java/com/appsdeveloperblog/photoapp/api/users/ui/controllers/UsersController.java b/PhotoAppApiUsers/src/main/java/com/appsdeveloperblog/photoapp/api/users/ui/controllers/UsersController.java index 358a128..e298474 100644 --- a/PhotoAppApiUsers/src/main/java/com/appsdeveloperblog/photoapp/api/users/ui/controllers/UsersController.java +++ b/PhotoAppApiUsers/src/main/java/com/appsdeveloperblog/photoapp/api/users/ui/controllers/UsersController.java @@ -1,9 +1,13 @@ package com.appsdeveloperblog.photoapp.api.users.ui.controllers; - import org.modelmapper.ModelMapper; +import com.appsdeveloperblog.photoapp.api.users.service.UsersService; +import com.appsdeveloperblog.photoapp.api.users.shared.UserDto; +import com.appsdeveloperblog.photoapp.api.users.ui.model.CreateUserRequestModel; +import com.appsdeveloperblog.photoapp.api.users.ui.model.CreateUserResponseModel; +import com.appsdeveloperblog.photoapp.api.users.ui.model.UserResponseModel; +import org.modelmapper.ModelMapper; import org.modelmapper.convention.MatchingStrategies; import org.springframework.beans.factory.annotation.Autowired; - import org.springframework.core.env.Environment; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; @@ -15,54 +19,46 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import com.appsdeveloperblog.photoapp.api.users.ui.model.CreateUserRequestModel; -import com.appsdeveloperblog.photoapp.api.users.ui.model.CreateUserResponseModel; -import com.appsdeveloperblog.photoapp.api.users.ui.model.UserResponseModel; -import com.appsdeveloperblog.photoapp.api.users.service.*; -import com.appsdeveloperblog.photoapp.api.users.shared.*; - @RestController @RequestMapping("/users") public class UsersController { - - @Autowired - private Environment env; - - @Autowired - UsersService usersService; - @GetMapping("/status/check") - public String status() - { - return "Working on port " + env.getProperty("local.server.port") + ", with token = " + env.getProperty("token.secret"); - } - - @PostMapping( - consumes = { MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE }, - produces = { MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE } - ) - public ResponseEntity createUser(@RequestBody CreateUserRequestModel userDetails) - { - ModelMapper modelMapper = new ModelMapper(); - modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT); - - UserDto userDto = modelMapper.map(userDetails, UserDto.class); - - UserDto createdUser = usersService.createUser(userDto); - - CreateUserResponseModel returnValue = modelMapper.map(createdUser, CreateUserResponseModel.class); - - return ResponseEntity.status(HttpStatus.CREATED).body(returnValue); - } - - @GetMapping(value="/{userId}", produces = { MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE }) + @Autowired + private Environment env; + + @Autowired + UsersService usersService; + + @GetMapping("/status/check") + public String status() { + return "Working on port " + env.getProperty("local.server.port") + ", with token = " + env.getProperty("token.secret") + + ", token.expiration_time = " + env.getProperty("token.expiration_time"); + } + + @PostMapping( + consumes = {MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE}, + produces = {MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE} + ) + public ResponseEntity createUser(@RequestBody CreateUserRequestModel userDetails) { + ModelMapper modelMapper = new ModelMapper(); + modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT); + + UserDto userDto = modelMapper.map(userDetails, UserDto.class); + + UserDto createdUser = usersService.createUser(userDto); + + CreateUserResponseModel returnValue = modelMapper.map(createdUser, CreateUserResponseModel.class); + + return ResponseEntity.status(HttpStatus.CREATED).body(returnValue); + } + + @GetMapping(value = "/{userId}", produces = {MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE}) public ResponseEntity getUser(@PathVariable("userId") String userId) { - - UserDto userDto = usersService.getUserByUserId(userId); + + UserDto userDto = usersService.getUserByUserId(userId); UserResponseModel returnValue = new ModelMapper().map(userDto, UserResponseModel.class); - + return ResponseEntity.status(HttpStatus.OK).body(returnValue); } - - + } diff --git a/PhotoAppApiUsers/src/main/resources/application-production.properties b/PhotoAppApiUsers/src/main/resources/application-production.properties index c18fe27..6193ad2 100644 --- a/PhotoAppApiUsers/src/main/resources/application-production.properties +++ b/PhotoAppApiUsers/src/main/resources/application-production.properties @@ -4,6 +4,10 @@ eureka.client.serviceUrl.defaultZone = http://localhost:8010/eureka spring.devtools.restart.enabled = true eureka.instance.instance-id=${spring.application.name}:${spring.application.instance_id:${random.value}} +#Used if RestTemplate is used to call albums microservice +albums.url=http://ALBUMS-WS/users/%s/albums +albums.exceptions.albums-not-found=Users albums are not found + spring.h2.console.enabled=true spring.h2.console.settings.web-allow-others=true diff --git a/PhotoAppApiUsers/src/main/resources/application.properties b/PhotoAppApiUsers/src/main/resources/application.properties index 05ccc2b..2df3d7e 100644 --- a/PhotoAppApiUsers/src/main/resources/application.properties +++ b/PhotoAppApiUsers/src/main/resources/application.properties @@ -1,9 +1,15 @@ server.port=${PORT:0} spring.application.name=users-ws -eureka.client.serviceUrl.defaultZone = http://localhost:8010/eureka -spring.devtools.restart.enabled = true +eureka.client.serviceUrl.defaultZone=http://test:test@localhost:8010/eureka +spring.devtools.restart.enabled=true eureka.instance.instance-id=${spring.application.name}:${spring.application.instance_id:${random.value}} +#Used if RestTemplate is used to call albums microservice +albums.url=http://ALBUMS-WS/users/%s/albums +albums.exceptions.albums-not-found=Users albums are not found + +# From boot 2.3.0 onwards if url is not mentioned it will auto generate database name. Let's specify explicitly instead: +spring.datasource.url=jdbc:h2:mem:testdb spring.h2.console.enabled=true spring.h2.console.settings.web-allow-others=true @@ -12,10 +18,10 @@ spring.h2.console.settings.web-allow-others=true #spring.datasource.password=sergey spring.jpa.hibernate.ddl-auto=update -gateway.ip = 192.168.1.131 -token.expiration_time = 864000000 -token.secret = hfgry463hf746hf573ydh475fhy5739 -login.url.path = /users/login +gateway.ip=192.168.0.105 +token.expiration_time=864000000 +token.secret=hfgry463hf746hf573ydh475fhy5739 +login.url.path=/users/login spring.rabbitmq.host=localhost diff --git a/PhotoAppApiZuulAPIGateway/dockerfile b/PhotoAppApiZuulAPIGateway/dockerfile index 1b39a5b..3a4f570 100644 --- a/PhotoAppApiZuulAPIGateway/dockerfile +++ b/PhotoAppApiZuulAPIGateway/dockerfile @@ -1,4 +1,4 @@ -FROM openjdk:8-jdk-alpine +FROM openjdk:11 VOLUME /tmp COPY target/PhotoAppApiZuulAPIGateway-0.0.1-SNAPSHOT.jar ZuulApiGateway.jar ENTRYPOINT ["java","-jar","ZuulApiGateway.jar"] \ No newline at end of file diff --git a/PhotoAppApiZuulAPIGateway/pom.xml b/PhotoAppApiZuulAPIGateway/pom.xml index b1fa7b4..8123fc7 100644 --- a/PhotoAppApiZuulAPIGateway/pom.xml +++ b/PhotoAppApiZuulAPIGateway/pom.xml @@ -6,7 +6,7 @@ org.springframework.boot spring-boot-starter-parent - 2.1.3.RELEASE + 2.3.12.RELEASE com.appsdeveloperblog.photoapp.api.gateway @@ -16,8 +16,8 @@ Zuul API Gateway microservice - 1.8 - Greenwich.RELEASE + 11 + Hoxton.SR12 @@ -45,6 +45,11 @@ jjwt 0.9.1 + + javax.xml.bind + jaxb-api + 2.3.1 + org.springframework.boot diff --git a/PhotoAppApiZuulAPIGateway/src/main/resources/application.properties b/PhotoAppApiZuulAPIGateway/src/main/resources/application.properties index adce8fa..829cca8 100644 --- a/PhotoAppApiZuulAPIGateway/src/main/resources/application.properties +++ b/PhotoAppApiZuulAPIGateway/src/main/resources/application.properties @@ -1,6 +1,6 @@ spring.application.name=zuul server.port=8011 -eureka.client.serviceUrl.defaultZone = http://localhost:8010/eureka +eureka.client.serviceUrl.defaultZone=http://test:test@localhost:8010/eureka api.h2console.url.path = /users-ws/h2-console/** api.registration.url.path = /users-ws/users diff --git a/PhotoAppDiscoveryService/dockerfile b/PhotoAppDiscoveryService/dockerfile index e99b324..b57bc24 100644 --- a/PhotoAppDiscoveryService/dockerfile +++ b/PhotoAppDiscoveryService/dockerfile @@ -1,3 +1,3 @@ -FROM openjdk:8-jdk-alpine +FROM openjdk:11 COPY target/PhotoAppDiscoveryService-0.0.1-SNAPSHOT.jar DiscoveryService.jar ENTRYPOINT ["java","-jar","DiscoveryService.jar"] \ No newline at end of file diff --git a/PhotoAppDiscoveryService/pom.xml b/PhotoAppDiscoveryService/pom.xml index 967eafc..5ac0681 100644 --- a/PhotoAppDiscoveryService/pom.xml +++ b/PhotoAppDiscoveryService/pom.xml @@ -6,7 +6,7 @@ org.springframework.boot spring-boot-starter-parent - 2.1.3.RELEASE + 2.3.12.RELEASE @@ -17,8 +17,8 @@ Photo App Eureka Discovery Server - 1.8 - Greenwich.RELEASE + 11 + Hoxton.SR12 diff --git a/PhotoAppDiscoveryService/src/main/resources/application.properties b/PhotoAppDiscoveryService/src/main/resources/application.properties index a7732c8..c884d3f 100644 --- a/PhotoAppDiscoveryService/src/main/resources/application.properties +++ b/PhotoAppDiscoveryService/src/main/resources/application.properties @@ -2,4 +2,8 @@ server.port=8010 spring.application.name=discoveryservice eureka.client.registerWithEureka=false eureka.client.fetchRegistry=false -eureka.client.serviceUrl.defaultZone = http://localhost:8010/eureka \ No newline at end of file +eureka.client.serviceUrl.defaultZone = http://localhost:8010/eureka + +#Let's enable logs for debugging purposes. Note, package-specific log level can be enabled or log level for all: +logging.level.org.springframework.security=INFO +#logging.level.root=DEBUG \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..941a394 --- /dev/null +++ b/README.md @@ -0,0 +1,49 @@ +## README + +ANSI terminal coloring wasn't working for in Intellj Idea. To enable it environment variable can be used: +`spring.output.ansi.enabled=always` + +JCE comes bundled with JDK11 so we don't need to install it separately: +`https://www.oracle.com/java/technologies/javase/jdk11-readme.html` + +To run rabbitmq I use docker image instead of installing it manually. Pulling an image: + +`docker pull rabbitmq:management` + +Then running: + +`docker run –d --hostname my-rabbit --name some-rabbit –p 15672:15672 –p 5672:5672 rabbitmq:management` + +**Other useful docker commands.** + +Show all running containers: + +`docker ps` + +And then stop container: + +`docker stop YOUR_CONTAINER_ID` + +Or stop all running containers: + +`docker stop $(docker ps -aq)` + +Before trying running anything in Docker use for each project: + +`mvn clean install` + +Check compose file for syntax-errors: + +`docker-compose config` + +Build our images, create the defined containers, and start in detached mode via one command: +`docker-compose up --build -d` + +To stop the containers, remove them from Docker and remove the connected networks from it: + +`docker-compose down` + + + + + diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..047b549 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,107 @@ +version: '3' +services: + rabbitmq-container: + image: rabbitmq:3-management + ports: + - 5672:5672 + - 15672:15672 + volumes: + - ./rabbitmq/definitions.json:/etc/rabbitmq/definitions.json:ro + - ./rabbitmq/rabbitmq.config:/etc/rabbitmq/rabbitmq.config:ro + + photo-app-cloud-config: + image: photo-app-cloud/config + container_name: photo-app-cloud-config + build: + context: PhotoAppAPIConfigServer + dockerfile: dockerfile + ports: + - 8012:8012 + environment: + - ENCRYPT.KEY-STORE.LOCATION=file:///apiEncryptionKey.jks + - SPRING.RABBITMQ.HOST=rabbitmq-container + depends_on: + - rabbitmq-container + + photo-app-cloud-discovery: + image: photo-app-cloud/discovery + container_name: photo-app-cloud-discovery + build: + context: PhotoAppDiscoveryService + dockerfile: dockerfile + ports: + - 8010:8010 + environment: + - SPRING.CLOUD.CONFIG.URI=http://photo-app-cloud-config:8012 + depends_on: + - rabbitmq-container + - photo-app-cloud-config + + photo-app-cloud-zuul: + image: photo-app-cloud/zuul + container_name: photo-app-cloud-zuul + build: + context: PhotoAppApiZuulAPIGateway + dockerfile: dockerfile + ports: + - 8011:8011 + environment: + - SPRING.CLOUD.CONFIG.URI=http://photo-app-cloud-config:8012 + - SPRING.RABBITMQ.HOST=rabbitmq-container + - EUREKA.CLIENT.SERVICEURL.DEFAULTZONE=http://test:test@photo-app-cloud-discovery:8010/eureka + depends_on: + - rabbitmq-container + - photo-app-cloud-config + - photo-app-cloud-discovery + + photo-app-cloud-users: + image: photo-app-cloud/users + container_name: photo-app-cloud-users + build: + context: PhotoAppApiUsers + dockerfile: dockerfile + ports: + - 8000:8000 + environment: + - SPRING.CLOUD.CONFIG.URI=http://photo-app-cloud-config:8012 + - SPRING.RABBITMQ.HOST=rabbitmq-container + - EUREKA.CLIENT.SERVICEURL.DEFAULTZONE=http://test:test@photo-app-cloud-discovery:8010/eureka + - SERVER.PORT=8000 + # You can use container as name instead of ip, docker will automatically determine what the right ip: + - GATEWAY.IP=photo-app-cloud-zuul + # Make application resilient to config-server failure and able config-client to retry the connection on startup: + - SPRING.CLOUD.CONFIG.FAIL-FAST=true + - SPRING.CLOUD.CONFIG.RETRY.MAX-ATTEMPTS=20 + - SPRING.CLOUD.CONFIG.RETRY.MAX-INTERVAL=2000 + - SPRING.CLOUD.CONFIG.RETRY.INITIAL-INTERVAL=2000 + - SPRING.ZIPKIN.BASE-URL=http://zipkin:9411 + depends_on: + - rabbitmq-container + - photo-app-cloud-config + - photo-app-cloud-discovery + - zipkin + + photo-app-cloud-albums: + image: photo-app-cloud/albums + container_name: photo-app-cloud-albums + build: + context: PhotoAppApiAlbums + dockerfile: dockerfile + ports: + - 8001:8001 + environment: + - SPRING.RABBITMQ.HOST=rabbitmq-container + - EUREKA.CLIENT.SERVICEURL.DEFAULTZONE=http://test:test@photo-app-cloud-discovery:8010/eureka + - SERVER.PORT=8001 + depends_on: + - rabbitmq-container + - photo-app-cloud-discovery + + # For reference: https://github.com/openzipkin/zipkin/blob/master/docker/examples/docker-compose-example.yml + zipkin: + image: ghcr.io/openzipkin/zipkin-slim:${TAG:-latest} + container_name: zipkin + ports: + - 9411:9411 + # Uncomment to enable debug logging + # command: --logging.level.zipkin2=DEBUG \ No newline at end of file