├── vehicle-tracker ├── common-libs │ ├── src │ │ ├── main │ │ │ ├── resources │ │ │ │ └── application.properties │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── sk │ │ │ │ └── vtracker │ │ │ │ └── commons │ │ │ │ ├── models │ │ │ │ ├── VehicleCount.java │ │ │ │ ├── DriverInfo.java │ │ │ │ ├── Vehicle.java │ │ │ │ └── VehicleLocation.java │ │ │ │ └── CommonLibsApplication.java │ │ └── test │ │ │ └── java │ │ │ └── com │ │ │ └── sk │ │ │ └── vtracker │ │ │ └── commons │ │ │ └── CommonLibsApplicationTests.java │ ├── .gitignore │ └── pom.xml ├── images │ ├── model.png │ ├── streams.PNG │ ├── logs dir.png │ ├── response.png │ ├── stream-app.png │ ├── zookeeper.png │ ├── kafka server.png │ ├── kafka use case.png │ ├── stream processor.png │ ├── interactive queries.png │ ├── kafka create topic.png │ ├── processor-topology.png │ ├── interactive query code.png │ ├── kafka console consumer.png │ ├── kafka produce message.png │ ├── stream processor code.png │ └── stateful transformation.png ├── docs │ └── Real Time Analytics with KAFKA.pdf ├── tracker-dashboard │ ├── src │ │ ├── main │ │ │ ├── resources │ │ │ │ └── application.properties │ │ │ └── java │ │ │ │ └── org │ │ │ │ └── sk │ │ │ │ └── vtracker │ │ │ │ └── dashboard │ │ │ │ ├── TrackerDashboardApplication.java │ │ │ │ ├── web │ │ │ │ └── rest │ │ │ │ │ └── VehicleQueryService.java │ │ │ │ └── streams │ │ │ │ └── processor │ │ │ │ └── VehicleStatusCountProcessor.java │ │ └── test │ │ │ └── java │ │ │ └── org │ │ │ └── sk │ │ │ └── vtracker │ │ │ └── dashboard │ │ │ └── TrackerDashboardApplicationTests.java │ ├── .gitignore │ └── pom.xml ├── vehicle-simulator │ ├── src │ │ ├── main │ │ │ ├── java │ │ │ │ └── org │ │ │ │ │ └── sk │ │ │ │ │ └── vtracker │ │ │ │ │ └── simulator │ │ │ │ │ ├── services │ │ │ │ │ ├── SimulationService.java │ │ │ │ │ ├── ProducerService.java │ │ │ │ │ ├── KafkaProducer.java │ │ │ │ │ ├── ScheduledTasks.java │ │ │ │ │ └── CarSignalSimulator.java │ │ │ │ │ ├── VehicleSimulatorApplication.java │ │ │ │ │ ├── web │ │ │ │ │ └── rest │ │ │ │ │ │ └── VehicleSimulationController.java │ │ │ │ │ └── config │ │ │ │ │ └── SwaggerConfigurations.java │ │ │ └── resources │ │ │ │ └── application.properties │ │ └── test │ │ │ └── java │ │ │ └── org │ │ │ └── sk │ │ │ └── vtracker │ │ │ └── simulator │ │ │ └── VehicleSimulatorApplicationTests.java │ └── pom.xml ├── .gitignore ├── pom.xml └── README.md ├── awesomeProject ├── bin │ └── my_awesomw_ms.exe ├── DiscoveryManager.go ├── RegistrationManager.go ├── helper │ ├── utility.go │ └── HttpHelper.go ├── README.md ├── myawesomems.go └── EurekaRegistrationManager.go ├── idor-prevention ├── src │ ├── main │ │ ├── resources │ │ │ └── application.properties │ │ └── java │ │ │ └── org │ │ │ └── sk │ │ │ └── owasp │ │ │ └── api │ │ │ └── security │ │ │ └── idor │ │ │ ├── web │ │ │ ├── controller │ │ │ │ └── HomeController.java │ │ │ └── resources │ │ │ │ └── SampleAPI.java │ │ │ ├── IdorPreventionApplication.java │ │ │ ├── util │ │ │ └── IdorUtility.java │ │ │ ├── db │ │ │ └── mock │ │ │ │ └── DataBaseService.java │ │ │ └── config │ │ │ └── SwaggerConfigurations.java │ └── test │ │ └── java │ │ └── org │ │ └── sk │ │ └── owasp │ │ └── api │ │ └── security │ │ └── idor │ │ └── IdorPreventionApplicationTests.java ├── .gitignore ├── pom.xml ├── mvnw.cmd └── mvnw ├── centralized-swagger-docs ├── documentation-app │ ├── .mvn │ │ └── wrapper │ │ │ ├── maven-wrapper.properties │ │ │ └── maven-wrapper.jar │ ├── .gitignore │ ├── src │ │ ├── main │ │ │ ├── resources │ │ │ │ └── application.yml │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── satish │ │ │ │ └── central │ │ │ │ └── docs │ │ │ │ ├── DocumentationAppApplication.java │ │ │ │ ├── web │ │ │ │ └── ServiceDefinitionController.java │ │ │ │ └── config │ │ │ │ └── swagger │ │ │ │ ├── ServiceDefinitionsContext.java │ │ │ │ ├── SwaggerUIConfiguration.java │ │ │ │ └── ServiceDescriptionUpdater.java │ │ └── test │ │ │ └── java │ │ │ └── com │ │ │ └── satish │ │ │ └── central │ │ │ └── docs │ │ │ └── DocumentationAppApplicationTests.java │ ├── pom.xml │ ├── mvnw.cmd │ └── mvnw ├── employee-application │ ├── .mvn │ │ └── wrapper │ │ │ ├── maven-wrapper.properties │ │ │ └── maven-wrapper.jar │ ├── src │ │ ├── main │ │ │ ├── java │ │ │ │ └── com │ │ │ │ │ └── satish │ │ │ │ │ └── central │ │ │ │ │ └── docs │ │ │ │ │ └── employee │ │ │ │ │ ├── db │ │ │ │ │ ├── repository │ │ │ │ │ │ └── EmployeeRepository.java │ │ │ │ │ └── entities │ │ │ │ │ │ └── Employee.java │ │ │ │ │ ├── EmployeeApplication.java │ │ │ │ │ ├── web │ │ │ │ │ ├── controller │ │ │ │ │ │ └── HomeController.java │ │ │ │ │ └── rest │ │ │ │ │ │ └── resource │ │ │ │ │ │ └── EmployeeResource.java │ │ │ │ │ └── config │ │ │ │ │ └── SwaggerDocumentationConfiguration.java │ │ │ └── resources │ │ │ │ └── application-default.yml │ │ └── test │ │ │ └── java │ │ │ └── com │ │ │ └── satish │ │ │ └── central │ │ │ └── docs │ │ │ └── employee │ │ │ └── EmployeeApplicationTests.java │ ├── .gitignore │ ├── pom.xml │ ├── mvnw.cmd │ └── mvnw ├── person-application │ ├── .mvn │ │ └── wrapper │ │ │ ├── maven-wrapper.properties │ │ │ └── maven-wrapper.jar │ ├── src │ │ ├── main │ │ │ ├── java │ │ │ │ └── com │ │ │ │ │ └── satish │ │ │ │ │ └── central │ │ │ │ │ └── docs │ │ │ │ │ └── person │ │ │ │ │ ├── db │ │ │ │ │ ├── repository │ │ │ │ │ │ └── PersonRepository.java │ │ │ │ │ └── entities │ │ │ │ │ │ └── Person.java │ │ │ │ │ ├── web │ │ │ │ │ ├── controller │ │ │ │ │ │ └── HomeController.java │ │ │ │ │ └── rest │ │ │ │ │ │ └── resource │ │ │ │ │ │ └── PersonResource.java │ │ │ │ │ ├── PersonApplication.java │ │ │ │ │ └── config │ │ │ │ │ └── SwaggerDocumentationConfiguration.java │ │ │ └── resources │ │ │ │ └── application-default.yml │ │ └── test │ │ │ └── java │ │ │ └── com │ │ │ └── satish │ │ │ └── central │ │ │ └── docs │ │ │ └── person │ │ │ └── PersonApplicationTests.java │ ├── .gitignore │ ├── pom.xml │ ├── mvnw.cmd │ └── mvnw ├── central-docs-eureka-server │ ├── .mvn │ │ └── wrapper │ │ │ ├── maven-wrapper.properties │ │ │ └── maven-wrapper.jar │ ├── src │ │ ├── main │ │ │ ├── resources │ │ │ │ └── application.yml │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── satish │ │ │ │ └── central │ │ │ │ └── docs │ │ │ │ └── server │ │ │ │ └── CentralDocsEurekaServerApplication.java │ │ └── test │ │ │ └── java │ │ │ └── com │ │ │ └── satish │ │ │ └── central │ │ │ └── docs │ │ │ └── server │ │ │ └── CentralDocsEurekaServerApplicationTests.java │ ├── .gitignore │ ├── pom.xml │ ├── mvnw.cmd │ └── mvnw └── README.md ├── .gitignore ├── micro-frameworks ├── README.md ├── javalin-app │ ├── src │ │ └── main │ │ │ └── java │ │ │ └── org │ │ │ └── sk │ │ │ └── demo │ │ │ └── crud │ │ │ └── app │ │ │ ├── model │ │ │ └── Person.java │ │ │ ├── controller │ │ │ └── PersonController.java │ │ │ ├── db │ │ │ └── InMemoryDatabase.java │ │ │ └── PersonApp.java │ ├── pom.xml │ └── README.md └── sample-requests │ └── person-app.postman_collection.json ├── README.md └── LICENSE /vehicle-tracker/common-libs/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /vehicle-tracker/images/model.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hellosatish/microservice-patterns/HEAD/vehicle-tracker/images/model.png -------------------------------------------------------------------------------- /vehicle-tracker/images/streams.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hellosatish/microservice-patterns/HEAD/vehicle-tracker/images/streams.PNG -------------------------------------------------------------------------------- /awesomeProject/bin/my_awesomw_ms.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hellosatish/microservice-patterns/HEAD/awesomeProject/bin/my_awesomw_ms.exe -------------------------------------------------------------------------------- /vehicle-tracker/images/logs dir.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hellosatish/microservice-patterns/HEAD/vehicle-tracker/images/logs dir.png -------------------------------------------------------------------------------- /vehicle-tracker/images/response.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hellosatish/microservice-patterns/HEAD/vehicle-tracker/images/response.png -------------------------------------------------------------------------------- /vehicle-tracker/images/stream-app.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hellosatish/microservice-patterns/HEAD/vehicle-tracker/images/stream-app.png -------------------------------------------------------------------------------- /vehicle-tracker/images/zookeeper.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hellosatish/microservice-patterns/HEAD/vehicle-tracker/images/zookeeper.png -------------------------------------------------------------------------------- /vehicle-tracker/images/kafka server.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hellosatish/microservice-patterns/HEAD/vehicle-tracker/images/kafka server.png -------------------------------------------------------------------------------- /vehicle-tracker/images/kafka use case.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hellosatish/microservice-patterns/HEAD/vehicle-tracker/images/kafka use case.png -------------------------------------------------------------------------------- /vehicle-tracker/images/stream processor.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hellosatish/microservice-patterns/HEAD/vehicle-tracker/images/stream processor.png -------------------------------------------------------------------------------- /vehicle-tracker/images/interactive queries.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hellosatish/microservice-patterns/HEAD/vehicle-tracker/images/interactive queries.png -------------------------------------------------------------------------------- /vehicle-tracker/images/kafka create topic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hellosatish/microservice-patterns/HEAD/vehicle-tracker/images/kafka create topic.png -------------------------------------------------------------------------------- /vehicle-tracker/images/processor-topology.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hellosatish/microservice-patterns/HEAD/vehicle-tracker/images/processor-topology.png -------------------------------------------------------------------------------- /idor-prevention/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=IDOR-Prevention-Demo 2 | spring.main.banner-mode=off 3 | server.port=9999 4 | 5 | -------------------------------------------------------------------------------- /vehicle-tracker/images/interactive query code.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hellosatish/microservice-patterns/HEAD/vehicle-tracker/images/interactive query code.png -------------------------------------------------------------------------------- /vehicle-tracker/images/kafka console consumer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hellosatish/microservice-patterns/HEAD/vehicle-tracker/images/kafka console consumer.png -------------------------------------------------------------------------------- /vehicle-tracker/images/kafka produce message.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hellosatish/microservice-patterns/HEAD/vehicle-tracker/images/kafka produce message.png -------------------------------------------------------------------------------- /vehicle-tracker/images/stream processor code.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hellosatish/microservice-patterns/HEAD/vehicle-tracker/images/stream processor code.png -------------------------------------------------------------------------------- /vehicle-tracker/images/stateful transformation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hellosatish/microservice-patterns/HEAD/vehicle-tracker/images/stateful transformation.png -------------------------------------------------------------------------------- /vehicle-tracker/docs/Real Time Analytics with KAFKA.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hellosatish/microservice-patterns/HEAD/vehicle-tracker/docs/Real Time Analytics with KAFKA.pdf -------------------------------------------------------------------------------- /centralized-swagger-docs/documentation-app/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.4/apache-maven-3.5.4-bin.zip 2 | -------------------------------------------------------------------------------- /centralized-swagger-docs/employee-application/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.4/apache-maven-3.5.4-bin.zip 2 | -------------------------------------------------------------------------------- /centralized-swagger-docs/person-application/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.4/apache-maven-3.5.4-bin.zip 2 | -------------------------------------------------------------------------------- /centralized-swagger-docs/central-docs-eureka-server/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.4/apache-maven-3.5.4-bin.zip 2 | -------------------------------------------------------------------------------- /centralized-swagger-docs/documentation-app/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hellosatish/microservice-patterns/HEAD/centralized-swagger-docs/documentation-app/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /centralized-swagger-docs/person-application/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hellosatish/microservice-patterns/HEAD/centralized-swagger-docs/person-application/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /centralized-swagger-docs/employee-application/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hellosatish/microservice-patterns/HEAD/centralized-swagger-docs/employee-application/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /centralized-swagger-docs/central-docs-eureka-server/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hellosatish/microservice-patterns/HEAD/centralized-swagger-docs/central-docs-eureka-server/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /vehicle-tracker/tracker-dashboard/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.kafka.streams.application-id=dashboard 2 | server.port=9090 3 | 4 | spring.kafka.consumer.key-deserializer= org.apache.kafka.common.serialization.IntegerDeserializer 5 | spring.kafka.consumer.value-deserializer = org.springframework.kafka.support.serializer.JsonDeserializer -------------------------------------------------------------------------------- /vehicle-tracker/vehicle-simulator/src/main/java/org/sk/vtracker/simulator/services/SimulationService.java: -------------------------------------------------------------------------------- 1 | package org.sk.vtracker.simulator.services; 2 | 3 | import org.springframework.stereotype.Service; 4 | 5 | @Service 6 | public interface SimulationService { 7 | 8 | public void simulate(int numberOfVehicles, int emitInterval, int stopIndex); 9 | } 10 | -------------------------------------------------------------------------------- /vehicle-tracker/common-libs/src/main/java/com/sk/vtracker/commons/models/VehicleCount.java: -------------------------------------------------------------------------------- 1 | package com.sk.vtracker.commons.models; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | @Data 8 | @AllArgsConstructor 9 | @NoArgsConstructor 10 | public class VehicleCount { 11 | 12 | private long count; 13 | } 14 | -------------------------------------------------------------------------------- /idor-prevention/src/test/java/org/sk/owasp/api/security/idor/IdorPreventionApplicationTests.java: -------------------------------------------------------------------------------- 1 | package org.sk.owasp.api.security.idor; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class IdorPreventionApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /vehicle-tracker/vehicle-simulator/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | app.topic.name = gpslocation 2 | 3 | 4 | spring.kafka.producer.bootstrap-servers=localhost:9092 5 | spring.kafka.producer.key-serializer= org.apache.kafka.common.serialization.IntegerSerializer 6 | spring.kafka.producer.value-serializer= org.springframework.kafka.support.serializer.JsonSerializer 7 | 8 | 9 | -------------------------------------------------------------------------------- /centralized-swagger-docs/central-docs-eureka-server/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: central-doce-eureka-server 4 | server: 5 | port: 8761 6 | logging: 7 | level: 8 | com.netflix.eureka: false 9 | com.netflix.discovery: false 10 | 11 | 12 | eureka: 13 | client: 14 | fetch-registry: false 15 | register-with-eureka: false -------------------------------------------------------------------------------- /centralized-swagger-docs/person-application/src/main/java/com/satish/central/docs/person/db/repository/PersonRepository.java: -------------------------------------------------------------------------------- 1 | package com.satish.central.docs.person.db.repository; 2 | 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | 5 | import com.satish.central.docs.person.db.entities.Person; 6 | 7 | public interface PersonRepository extends JpaRepository { 8 | 9 | } 10 | -------------------------------------------------------------------------------- /centralized-swagger-docs/documentation-app/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /build/ 22 | /nbbuild/ 23 | /dist/ 24 | /nbdist/ 25 | /.nb-gradle/ -------------------------------------------------------------------------------- /centralized-swagger-docs/documentation-app/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 9093 3 | 4 | 5 | eureka: 6 | instance: 7 | appname: documentation-application 8 | client: 9 | enabled: true 10 | register-with-eureka: true 11 | fetch-registry: true 12 | service-url: 13 | defaultZone: http://localhost:8761/eureka/ 14 | 15 | swagger: 16 | config: 17 | refreshrate: 5000 -------------------------------------------------------------------------------- /centralized-swagger-docs/employee-application/src/main/java/com/satish/central/docs/employee/db/repository/EmployeeRepository.java: -------------------------------------------------------------------------------- 1 | package com.satish.central.docs.employee.db.repository; 2 | 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | 5 | import com.satish.central.docs.employee.db.entities.Employee; 6 | 7 | public interface EmployeeRepository extends JpaRepository { 8 | 9 | } 10 | -------------------------------------------------------------------------------- /centralized-swagger-docs/person-application/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /build/ 22 | /nbbuild/ 23 | /dist/ 24 | /nbdist/ 25 | /.nb-gradle/ -------------------------------------------------------------------------------- /centralized-swagger-docs/employee-application/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /build/ 22 | /nbbuild/ 23 | /dist/ 24 | /nbdist/ 25 | /.nb-gradle/ -------------------------------------------------------------------------------- /centralized-swagger-docs/central-docs-eureka-server/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /build/ 22 | /nbbuild/ 23 | /dist/ 24 | /nbdist/ 25 | /.nb-gradle/ -------------------------------------------------------------------------------- /idor-prevention/src/main/java/org/sk/owasp/api/security/idor/web/controller/HomeController.java: -------------------------------------------------------------------------------- 1 | package org.sk.owasp.api.security.idor.web.controller; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | 6 | @Controller 7 | public class HomeController { 8 | 9 | @GetMapping("/") 10 | public String redirectToSwagger() { 11 | return "redirect:/swagger-ui.html"; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /vehicle-tracker/vehicle-simulator/src/main/java/org/sk/vtracker/simulator/services/ProducerService.java: -------------------------------------------------------------------------------- 1 | package org.sk.vtracker.simulator.services; 2 | 3 | import org.springframework.stereotype.Service; 4 | 5 | import com.sk.vtracker.commons.models.VehicleLocation; 6 | 7 | @Service 8 | public interface ProducerService { 9 | 10 | public void produce(String key, String message); 11 | public void produce(int vehicleId, VehicleLocation location); 12 | } 13 | -------------------------------------------------------------------------------- /vehicle-tracker/common-libs/src/main/java/com/sk/vtracker/commons/models/DriverInfo.java: -------------------------------------------------------------------------------- 1 | package com.sk.vtracker.commons.models; 2 | 3 | import java.io.Serializable; 4 | 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | @Data 9 | @NoArgsConstructor 10 | public class DriverInfo implements Serializable { 11 | 12 | private int driverId; 13 | private String firstName; 14 | private String lastName; 15 | private int rating; 16 | 17 | } 18 | -------------------------------------------------------------------------------- /vehicle-tracker/common-libs/src/main/java/com/sk/vtracker/commons/CommonLibsApplication.java: -------------------------------------------------------------------------------- 1 | package com.sk.vtracker.commons; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class CommonLibsApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(CommonLibsApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /centralized-swagger-docs/person-application/src/main/java/com/satish/central/docs/person/web/controller/HomeController.java: -------------------------------------------------------------------------------- 1 | package com.satish.central.docs.person.web.controller; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | 6 | @Controller 7 | public class HomeController { 8 | 9 | @RequestMapping(value = "/") 10 | public String index() { 11 | return "redirect:swagger-ui.html"; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /awesomeProject/DiscoveryManager.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "log" 4 | 5 | func ManageDiscovery(configs RegistrationVariables) { 6 | 7 | switch configurations.RegistryType() { 8 | case NETFLIX_EUREKA: 9 | manager := new (EurekaRegistrationManager) 10 | manager.RegisterWithSerivceRegistry(configs) 11 | manager.SendHeartBeat(configs) 12 | case HASHICORP_CONSUL: 13 | log.Fatal("No manager found for Registry Type : " + configurations.RegistryType()) 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /centralized-swagger-docs/employee-application/src/main/java/com/satish/central/docs/employee/EmployeeApplication.java: -------------------------------------------------------------------------------- 1 | package com.satish.central.docs.employee; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class EmployeeApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(EmployeeApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /centralized-swagger-docs/employee-application/src/main/java/com/satish/central/docs/employee/web/controller/HomeController.java: -------------------------------------------------------------------------------- 1 | package com.satish.central.docs.employee.web.controller; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | 6 | @Controller 7 | public class HomeController { 8 | 9 | @RequestMapping(value = "/") 10 | public String index() { 11 | return "redirect:swagger-ui.html"; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /vehicle-tracker/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/** 5 | !**/src/test/** 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | 30 | ### VS Code ### 31 | .vscode/ 32 | -------------------------------------------------------------------------------- /vehicle-tracker/common-libs/src/test/java/com/sk/vtracker/commons/CommonLibsApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.sk.vtracker.commons; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class CommonLibsApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /vehicle-tracker/common-libs/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/** 5 | !**/src/test/** 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | 30 | ### VS Code ### 31 | .vscode/ 32 | -------------------------------------------------------------------------------- /vehicle-tracker/tracker-dashboard/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/** 5 | !**/src/test/** 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | 30 | ### VS Code ### 31 | .vscode/ 32 | -------------------------------------------------------------------------------- /centralized-swagger-docs/person-application/src/test/java/com/satish/central/docs/person/PersonApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.satish.central.docs.person; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class PersonApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /vehicle-tracker/tracker-dashboard/src/test/java/org/sk/vtracker/dashboard/TrackerDashboardApplicationTests.java: -------------------------------------------------------------------------------- 1 | package org.sk.vtracker.dashboard; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class TrackerDashboardApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /vehicle-tracker/vehicle-simulator/src/test/java/org/sk/vtracker/simulator/VehicleSimulatorApplicationTests.java: -------------------------------------------------------------------------------- 1 | package org.sk.vtracker.simulator; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class VehicleSimulatorApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /centralized-swagger-docs/documentation-app/src/test/java/com/satish/central/docs/DocumentationAppApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.satish.central.docs; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class DocumentationAppApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /centralized-swagger-docs/employee-application/src/test/java/com/satish/central/docs/employee/EmployeeApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.satish.central.docs.employee; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class EmployeeApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /centralized-swagger-docs/central-docs-eureka-server/src/test/java/com/satish/central/docs/server/CentralDocsEurekaServerApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.satish.central.docs.server; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class CentralDocsEurekaServerApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /idor-prevention/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /vehicle-tracker/common-libs/src/main/java/com/sk/vtracker/commons/models/Vehicle.java: -------------------------------------------------------------------------------- 1 | package com.sk.vtracker.commons.models; 2 | 3 | import java.io.Serializable; 4 | 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | /** 8 | * 9 | * @author satish-s 10 | * 11 | * Vehicle details 12 | */ 13 | @Data 14 | @NoArgsConstructor 15 | public class Vehicle implements Serializable{ 16 | 17 | private int vehicleId; 18 | private String vehilceNumber; 19 | //Current assumption is all the vehicles are CAR. 20 | private String vehicleType ="CAR"; 21 | 22 | } 23 | -------------------------------------------------------------------------------- /idor-prevention/src/main/java/org/sk/owasp/api/security/idor/IdorPreventionApplication.java: -------------------------------------------------------------------------------- 1 | package org.sk.owasp.api.security.idor; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | import springfox.documentation.swagger2.annotations.EnableSwagger2; 7 | 8 | @EnableSwagger2 9 | @SpringBootApplication 10 | public class IdorPreventionApplication { 11 | 12 | public static void main(String[] args) { 13 | SpringApplication.run(IdorPreventionApplication.class, args); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /vehicle-tracker/tracker-dashboard/src/main/java/org/sk/vtracker/dashboard/TrackerDashboardApplication.java: -------------------------------------------------------------------------------- 1 | package org.sk.vtracker.dashboard; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.kafka.annotation.EnableKafkaStreams; 6 | 7 | @SpringBootApplication 8 | @EnableKafkaStreams 9 | public class TrackerDashboardApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(TrackerDashboardApplication.class, args); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /centralized-swagger-docs/central-docs-eureka-server/src/main/java/com/satish/central/docs/server/CentralDocsEurekaServerApplication.java: -------------------------------------------------------------------------------- 1 | package com.satish.central.docs.server; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; 7 | 8 | @EnableEurekaServer 9 | @SpringBootApplication 10 | public class CentralDocsEurekaServerApplication { 11 | 12 | public static void main(String[] args) { 13 | SpringApplication.run(CentralDocsEurekaServerApplication.class, args); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /centralized-swagger-docs/person-application/src/main/java/com/satish/central/docs/person/PersonApplication.java: -------------------------------------------------------------------------------- 1 | package com.satish.central.docs.person; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 6 | 7 | import springfox.documentation.swagger2.annotations.EnableSwagger2; 8 | 9 | 10 | @EnableEurekaClient 11 | @SpringBootApplication 12 | public class PersonApplication { 13 | 14 | public static void main(String[] args) { 15 | SpringApplication.run(PersonApplication.class, args); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /centralized-swagger-docs/documentation-app/src/main/java/com/satish/central/docs/DocumentationAppApplication.java: -------------------------------------------------------------------------------- 1 | package com.satish.central.docs; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.scheduling.annotation.EnableScheduling; 6 | 7 | import springfox.documentation.swagger2.annotations.EnableSwagger2; 8 | /** 9 | * 10 | * @author satish sharma 11 | * 12 | */ 13 | @EnableSwagger2 14 | @EnableScheduling 15 | @SpringBootApplication 16 | public class DocumentationAppApplication { 17 | 18 | public static void main(String[] args) { 19 | SpringApplication.run(DocumentationAppApplication.class, args); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | 4 | # Log file 5 | *.log 6 | 7 | # BlueJ files 8 | *.ctxt 9 | 10 | # Mobile Tools for Java (J2ME) 11 | .mtj.tmp/ 12 | 13 | # Package Files # 14 | *.jar 15 | *.war 16 | *.ear 17 | *.zip 18 | *.tar.gz 19 | *.rar 20 | 21 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 22 | hs_err_pid* 23 | 24 | 25 | /target/ 26 | !.mvn/wrapper/maven-wrapper.jar 27 | 28 | ### STS ### 29 | .apt_generated 30 | .classpath 31 | .factorypath 32 | .project 33 | .settings 34 | .springBeans 35 | .sts4-cache 36 | 37 | ### IntelliJ IDEA ### 38 | .idea 39 | *.iws 40 | *.iml 41 | *.ipr 42 | 43 | ### NetBeans ### 44 | /nbproject/private/ 45 | /build/ 46 | /nbbuild/ 47 | /dist/ 48 | /nbdist/ 49 | /.nb-gradle/ -------------------------------------------------------------------------------- /vehicle-tracker/vehicle-simulator/src/main/java/org/sk/vtracker/simulator/VehicleSimulatorApplication.java: -------------------------------------------------------------------------------- 1 | package org.sk.vtracker.simulator; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.scheduling.annotation.EnableAsync; 6 | import org.springframework.scheduling.annotation.EnableScheduling; 7 | 8 | import springfox.documentation.swagger2.annotations.EnableSwagger2; 9 | 10 | @EnableAsync 11 | @EnableSwagger2 12 | @EnableScheduling 13 | @SpringBootApplication 14 | public class VehicleSimulatorApplication { 15 | 16 | public static void main(String[] args) { 17 | SpringApplication.run(VehicleSimulatorApplication.class, args); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /centralized-swagger-docs/person-application/src/main/java/com/satish/central/docs/person/db/entities/Person.java: -------------------------------------------------------------------------------- 1 | package com.satish.central.docs.person.db.entities; 2 | 3 | import javax.persistence.Entity; 4 | import javax.persistence.GeneratedValue; 5 | import javax.persistence.GenerationType; 6 | import javax.persistence.Id; 7 | import javax.persistence.Table; 8 | 9 | import lombok.Getter; 10 | import lombok.NoArgsConstructor; 11 | import lombok.Setter; 12 | 13 | @Getter 14 | @Setter 15 | @NoArgsConstructor 16 | @Entity 17 | @Table(name = "PERSON") 18 | public class Person { 19 | 20 | @Id 21 | @GeneratedValue(strategy=GenerationType.AUTO) 22 | private int id; 23 | 24 | private String firstName; 25 | private String lastName; 26 | private String email; 27 | } 28 | -------------------------------------------------------------------------------- /centralized-swagger-docs/employee-application/src/main/java/com/satish/central/docs/employee/db/entities/Employee.java: -------------------------------------------------------------------------------- 1 | package com.satish.central.docs.employee.db.entities; 2 | 3 | import javax.persistence.Entity; 4 | import javax.persistence.GeneratedValue; 5 | import javax.persistence.GenerationType; 6 | import javax.persistence.Id; 7 | import javax.persistence.Table; 8 | 9 | import lombok.Getter; 10 | import lombok.NoArgsConstructor; 11 | import lombok.Setter; 12 | 13 | @Getter 14 | @Setter 15 | @NoArgsConstructor 16 | @Entity 17 | @Table(name = "EMPLOYEE") 18 | public class Employee { 19 | 20 | @Id 21 | @GeneratedValue(strategy=GenerationType.AUTO) 22 | private int employeeId; 23 | 24 | private String employeeFirstName; 25 | private String employeeLastName; 26 | private String email; 27 | } 28 | -------------------------------------------------------------------------------- /centralized-swagger-docs/person-application/src/main/resources/application-default.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 9091 3 | 4 | spring: 5 | datasource: 6 | url: jdbc:h2:mem:person-db;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE 7 | driver-class-name: org.h2.Driver 8 | username: sa 9 | password: sa 10 | 11 | jpa: 12 | show-sql: true 13 | hibernate: 14 | ddl-auto: create-drop 15 | h2: 16 | console: 17 | path: /db-console 18 | application: 19 | name: person-application 20 | 21 | logging: 22 | level: 23 | com.netflix.eureka: OFF 24 | com.netflix.discovery: OFF 25 | 26 | eureka: 27 | instance: 28 | appname: person-application 29 | client: 30 | enabled: true 31 | register-with-eureka: true 32 | fetch-registry: true 33 | service-url: 34 | defaultZone: http://localhost:8761/eureka/ 35 | -------------------------------------------------------------------------------- /centralized-swagger-docs/employee-application/src/main/resources/application-default.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 9092 3 | 4 | 5 | 6 | spring: 7 | datasource: 8 | url: jdbc:h2:mem:employee-db;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE 9 | driver-class-name: org.h2.Driver 10 | username: sa 11 | password: sa 12 | 13 | jpa: 14 | show-sql: true 15 | hibernate: 16 | ddl-auto: create-drop 17 | h2: 18 | console: 19 | path: /db-console 20 | application: 21 | name: employee-application 22 | 23 | logging: 24 | level: 25 | com.netflix.eureka: OFF 26 | com.netflix.discovery: OFF 27 | 28 | eureka: 29 | instance: 30 | appname: employee-application 31 | client: 32 | enabled: true 33 | register-with-eureka: true 34 | fetch-registry: true 35 | service-url: 36 | defaultZone: http://localhost:8761/eureka/ 37 | -------------------------------------------------------------------------------- /awesomeProject/RegistrationManager.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | const ( 4 | NETFLIX_EUREKA = "NETFLIX_EUREKA" 5 | HASHICORP_CONSUL = "CONSUL" 6 | ) 7 | 8 | type RegistrationManager interface { 9 | Manage(configs RegistrationVariables) 10 | RegisterWithSerivceRegistry() 11 | SendHeartBeat(configs RegistrationVariables) 12 | DeRegisterFromServiceRegistry(configs RegistrationVariables) 13 | } 14 | 15 | type RegistrationVariables struct { 16 | registryType string 17 | serviceRegistryURL string 18 | userName string 19 | password string 20 | } 21 | 22 | func (rv RegistrationVariables) RegistryType() string { 23 | return rv.registryType 24 | } 25 | 26 | func (rv RegistrationVariables) ServiceRegistryURL() string { 27 | return rv.serviceRegistryURL 28 | } 29 | func (rv RegistrationVariables) UserName() string { 30 | return rv.userName 31 | } 32 | func (rv RegistrationVariables) Password() string { 33 | return rv.password 34 | } 35 | -------------------------------------------------------------------------------- /awesomeProject/helper/utility.go: -------------------------------------------------------------------------------- 1 | package helper 2 | 3 | import ( 4 | "net" 5 | "errors" 6 | ) 7 | 8 | func ExternalIP() (string, error) { 9 | ifaces, err := net.Interfaces() 10 | if err != nil { 11 | return "", err 12 | } 13 | for _, iface := range ifaces { 14 | if iface.Flags&net.FlagUp == 0 { 15 | continue // interface down 16 | } 17 | if iface.Flags&net.FlagLoopback != 0 { 18 | continue // loopback interface 19 | } 20 | addrs, err := iface.Addrs() 21 | if err != nil { 22 | return "", err 23 | } 24 | for _, addr := range addrs { 25 | var ip net.IP 26 | switch v := addr.(type) { 27 | case *net.IPNet: 28 | ip = v.IP 29 | case *net.IPAddr: 30 | ip = v.IP 31 | } 32 | if ip == nil || ip.IsLoopback() { 33 | continue 34 | } 35 | ip = ip.To4() 36 | if ip == nil { 37 | continue // not an ipv4 address 38 | } 39 | return ip.String(), nil 40 | } 41 | } 42 | return "", errors.New("are you connected to the network?") 43 | } 44 | -------------------------------------------------------------------------------- /micro-frameworks/README.md: -------------------------------------------------------------------------------- 1 | # This directory contains the CRUD application implemented in different microframeworks. 2 | 3 | 1. [javalin-app](https://github.com/hellosatish/microservice-patterns/tree/master/micro-frameworks/javalin-app) A sample CRUD application written in [javalin](http://javalin.io/) 4 | 5 | 2. [sapark](#) WIP. 6 | A sample CRUD application written in [spark](http://sparkjava.com/) framework 7 | 8 | # All application offer CRUD rest endpoints for below model (person) 9 | ``` JSON 10 | { 11 | "id":1, 12 | "firstName":"Satish", 13 | "lastName":"Sharma" 14 | } 15 | ``` 16 | # How to run 17 | These are simple java application. You can run the main class, or you can package this application and run that as jar 18 | 19 | # [sample-requests](https://github.com/hellosatish/microservice-patterns/tree/master/micro-frameworks/sample-requests) folder contains postman collection for the requests. You can import that in Postman and test this application 20 | 21 | -------------------------------------------------------------------------------- /vehicle-tracker/common-libs/src/main/java/com/sk/vtracker/commons/models/VehicleLocation.java: -------------------------------------------------------------------------------- 1 | package com.sk.vtracker.commons.models; 2 | 3 | import java.io.Serializable; 4 | 5 | import lombok.AllArgsConstructor; 6 | import lombok.Getter; 7 | import lombok.NoArgsConstructor; 8 | import lombok.Setter; 9 | 10 | 11 | /** 12 | * @author satish-s 13 | * 14 | * Model class for location of a vehicle 15 | */ 16 | @Getter 17 | @Setter 18 | @NoArgsConstructor 19 | @AllArgsConstructor 20 | public class VehicleLocation implements Serializable{ 21 | 22 | private int vehicleId; //unique id for each vehicle 23 | private boolean online; //weather vehilce is online or offline 24 | private boolean available; // is vehilcle ready to take bookings or not 25 | private double latitude; 26 | private double longitude; 27 | public VehicleLocation(boolean online, boolean available, double latitude, double longitude) { 28 | super(); 29 | this.online = online; 30 | this.available = available; 31 | this.latitude = latitude; 32 | this.longitude = longitude; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /centralized-swagger-docs/documentation-app/src/main/java/com/satish/central/docs/web/ServiceDefinitionController.java: -------------------------------------------------------------------------------- 1 | package com.satish.central.docs.web; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.PathVariable; 6 | import org.springframework.web.bind.annotation.RestController; 7 | 8 | import com.satish.central.docs.config.swagger.ServiceDefinitionsContext; 9 | 10 | /** 11 | * 12 | * @author satish sharma 13 | *
14 |  *  Controller to serve the JSON from our in-memory store. So that UI can render the API-Documentation	
15 |  * 
16 | */ 17 | @RestController 18 | public class ServiceDefinitionController { 19 | 20 | @Autowired 21 | private ServiceDefinitionsContext definitionContext; 22 | 23 | @GetMapping("/service/{servicename}") 24 | public String getServiceDefinition(@PathVariable("servicename") String serviceName){ 25 | 26 | return definitionContext.getSwaggerDefinition(serviceName); 27 | 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /awesomeProject/README.md: -------------------------------------------------------------------------------- 1 | # my_awesome_ms 2 | Sample project in GO to register *[GOlang](http://golang.org)* application as a service instance in service registry. 3 | Currently this application supports [Eureka Registry](https://github.com/Netflix/eureka/wiki) 4 | 5 | # Pre-Requisite to run binaries 6 | You need to set the following environment variables 7 | * REGISTRY_TYPE : This can contain one of the following values 8 | * NETFLIX_EUREKA 9 | * CONSUL (Work in Progress) 10 | * REGISTRY_URL : The URL of service registry to be used for registering the application. For ex. in case of Eureka which is running in my local machine in port 8761 "http://localhost:8761/eureka/apps/" 11 | 12 | * REGISTRY_USER : The username to be used while authentication. 13 | * REGISTRY_PASSWORD : Password to be used while authentication. 14 | 15 | REGISTRY_USER and REGISTRY_PASSWORD are required in case you have the security enabled in eureka instance. 16 | 17 | # TODO 18 | * Enable usage of username and password so that we can register with the secured service registries 19 | * Complete service registry with * consul * 20 | -------------------------------------------------------------------------------- /micro-frameworks/javalin-app/src/main/java/org/sk/demo/crud/app/model/Person.java: -------------------------------------------------------------------------------- 1 | package org.sk.demo.crud.app.model; 2 | 3 | import java.io.Serializable; 4 | 5 | 6 | public class Person implements Serializable { 7 | 8 | private int id; 9 | private String firstName; 10 | private String lastName; 11 | 12 | public Person() { 13 | super(); 14 | } 15 | 16 | public Person(int id, String firstName, String lastName) { 17 | super(); 18 | this.id = id; 19 | this.firstName = firstName; 20 | this.lastName = lastName; 21 | } 22 | 23 | public int getId() { 24 | return id; 25 | } 26 | 27 | public void setId(int id) { 28 | this.id = id; 29 | } 30 | 31 | public String getFirstName() { 32 | return firstName; 33 | } 34 | 35 | public void setFirstName(String firstName) { 36 | this.firstName = firstName; 37 | } 38 | 39 | public String getLastName() { 40 | return lastName; 41 | } 42 | 43 | public void setLastName(String lastName) { 44 | this.lastName = lastName; 45 | } 46 | 47 | @Override 48 | public String toString() { 49 | return "Person [id=" + id + ", firstName=" + firstName + ", lastName=" + lastName + "]"; 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /vehicle-tracker/common-libs/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | vehicle-tracker 7 | vehicle-tracker 8 | 0.0.1-SNAPSHOT 9 | ../../vehicle-tracker 10 | 11 | common-libs 12 | common-libs 13 | Common libraries for vehicle tracker 14 | 15 | 16 | 1.8 17 | 18 | 19 | 20 | 21 | 22 | 23 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /awesomeProject/myawesomems.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "os" 5 | "log" 6 | ) 7 | 8 | var configurations RegistrationVariables 9 | 10 | func init() { 11 | registryType := os.Getenv("REGISTRY_TYPE") 12 | if registryType == "" { 13 | log.Fatal("$REGISTRY_TYPE not set") 14 | } 15 | serviceRegistryURL := os.Getenv("REGISTRY_URL") 16 | if serviceRegistryURL == "" { 17 | log.Fatal("REGISTRY_URL not set. Exiting application") 18 | } 19 | userName := os.Getenv("REGISTRY_USER") 20 | if userName == "" { 21 | log.Print("REGISTRY_USER not set. Shall be proceeding without user name") 22 | } 23 | password := os.Getenv("REGISTRY_PASSWORD") 24 | if password == "" { 25 | log.Print("REGISTRY_PASSWORD not set. Shall be proceeding without password") 26 | } 27 | configurations = RegistrationVariables{registryType, serviceRegistryURL, userName, password} 28 | } 29 | 30 | func main() { 31 | log.Print("registryType : " + configurations.RegistryType()) 32 | log.Print("serviceRegistryURL : " + configurations.ServiceRegistryURL()) 33 | log.Print("userName : " + configurations.UserName()) 34 | log.Print("password : " + configurations.Password()) 35 | 36 | ManageDiscovery(configurations) 37 | } 38 | -------------------------------------------------------------------------------- /idor-prevention/src/main/java/org/sk/owasp/api/security/idor/util/IdorUtility.java: -------------------------------------------------------------------------------- 1 | package org.sk.owasp.api.security.idor.util; 2 | 3 | import java.util.Base64; 4 | 5 | import org.springframework.stereotype.Service; 6 | 7 | /** 8 | * FOR DEMONSTRATION ONLY, NOT TO BE USED IN PRODUCTION.
9 | * 10 | * As this code is for demonstration purpose only. {@link Base64} is used to encypt-decrypt the ID's. This algorithm is not considered safe and can be 11 | * decoded easily. 12 | * In real world scenario you shall be using more sophisticated algorithms like HMAC, RSA etc. 13 | * 14 | * @author Satish Sharma 15 | * 16 | */ 17 | @Service 18 | public class IdorUtility { 19 | 20 | // this could be externalized to configuration. 21 | private String saltString="S3cUr#d1Ds1L$"; 22 | 23 | public String computeObfuscatedId(String actualIdentifier) { 24 | String saltedString = actualIdentifier + saltString; 25 | return new String(Base64.getEncoder().encode(saltedString.getBytes())); 26 | } 27 | 28 | public String resolveObfuscatedId(String obfuscatedIdentifier) { 29 | var decodedBit = Base64.getDecoder().decode(obfuscatedIdentifier); 30 | String decodedSaltedString = new String(decodedBit); 31 | return decodedSaltedString.replace(saltString, ""); 32 | } 33 | } -------------------------------------------------------------------------------- /vehicle-tracker/tracker-dashboard/src/main/java/org/sk/vtracker/dashboard/web/rest/VehicleQueryService.java: -------------------------------------------------------------------------------- 1 | package org.sk.vtracker.dashboard.web.rest; 2 | 3 | 4 | import org.apache.kafka.streams.KeyValue; 5 | import org.apache.kafka.streams.state.KeyValueIterator; 6 | import org.apache.kafka.streams.state.QueryableStoreTypes; 7 | import org.apache.kafka.streams.state.ReadOnlyKeyValueStore; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.kafka.config.StreamsBuilderFactoryBean; 10 | import org.springframework.web.bind.annotation.GetMapping; 11 | import org.springframework.web.bind.annotation.PathVariable; 12 | import org.springframework.web.bind.annotation.RestController; 13 | 14 | 15 | @RestController 16 | public class VehicleQueryService { 17 | @Autowired 18 | private StreamsBuilderFactoryBean kStreamBuilderFactoryBean; 19 | 20 | @GetMapping("/count/{status}") 21 | public long getVehicleCoutnForStatus(@PathVariable("status") String status) { 22 | // Get the state-store 23 | ReadOnlyKeyValueStore keyValueStore= kStreamBuilderFactoryBean.getKafkaStreams() 24 | .store("statusCount", QueryableStoreTypes.keyValueStore()); 25 | return keyValueStore.get(status); //get the count for the key viz. Offline/Online 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /micro-frameworks/javalin-app/pom.xml: -------------------------------------------------------------------------------- 1 | 4 | 4.0.0 5 | micro-frameworks 6 | javalin-app 7 | 0.0.1-SNAPSHOT 8 | Demo app for CRUD using javalin 9 | 10 | 11 | UTF-8 12 | 1.8 13 | 14 | 15 | 16 | io.javalin 17 | javalin 18 | 3.1.0 19 | 20 | 21 | 22 | org.projectlombok 23 | lombok 24 | 1.18.8 25 | 26 | 27 | 28 | org.slf4j 29 | slf4j-simple 30 | 1.7.26 31 | 32 | 33 | com.fasterxml.jackson.core 34 | jackson-databind 35 | 2.9.10.5 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /vehicle-tracker/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | vehicle-tracker 4 | vehicle-tracker 5 | 0.0.1-SNAPSHOT 6 | pom 7 | 8 | 9 | org.springframework.boot 10 | spring-boot-starter-parent 11 | 2.1.6.RELEASE 12 | 13 | 14 | 15 | 16 | 17 | org.springframework.boot 18 | spring-boot-starter 19 | 20 | 21 | 22 | org.projectlombok 23 | lombok 24 | true 25 | 26 | 27 | org.springframework.boot 28 | spring-boot-starter-test 29 | test 30 | 31 | 32 | 33 | common-libs 34 | 35 | vehicle-simulator 36 | tracker-dashboard 37 | 38 | 39 | -------------------------------------------------------------------------------- /micro-frameworks/javalin-app/README.md: -------------------------------------------------------------------------------- 1 | # This is a sample CRUD application for a sample entity (Person) having below model 2 | 3 | ``` JSON 4 | { 5 | "id":1, 6 | "firstName":"Satish", 7 | "lastName":"Sharma" 8 | } 9 | ``` 10 | # How to run 11 | This is simple java application. You can run the main class, or you can package this application and run that as jar 12 | 13 | # [sample-requests](https://github.com/hellosatish/microservice-patterns/tree/master/micro-frameworks/sample-requests) folder contains postman collection for the requests. You can import that in Postman and test this application 14 | 15 | 16 | # My observations till now 17 | 18 | ## The javalin doesn't ship with inbuilt logger. so if you see any warning like below. 19 | 20 | ``` 21 | Missing dependency 'Slf4j simple'. Add the dependency. 22 | ``` 23 | you will need to add a logger in classpath. For Slf4J use below maven cordinates 24 | 25 | ``` 26 | 27 | org.slf4j 28 | slf4j-simple 29 | 1.7.26 30 | 31 | ``` 32 | 33 | ## By default it doesnt ships with JSON mappers so you need to add JSON mapper. For jackson mapper use belwo snippet 34 | 35 | ``` 36 | 37 | com.fasterxml.jackson.core 38 | jackson-databind 39 | 2.9.9 40 | 41 | ``` -------------------------------------------------------------------------------- /vehicle-tracker/vehicle-simulator/src/main/java/org/sk/vtracker/simulator/services/KafkaProducer.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.sk.vtracker.simulator.services; 5 | 6 | import javax.annotation.PostConstruct; 7 | 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.beans.factory.annotation.Value; 10 | import org.springframework.kafka.core.KafkaTemplate; 11 | import org.springframework.scheduling.annotation.Scheduled; 12 | import org.springframework.stereotype.Component; 13 | import org.springframework.stereotype.Service; 14 | 15 | import com.sk.vtracker.commons.models.VehicleLocation; 16 | 17 | import lombok.extern.log4j.Log4j2; 18 | 19 | /** 20 | * @author satish-s 21 | * 22 | */ 23 | @Component 24 | @Log4j2 25 | @Service 26 | public class KafkaProducer implements ProducerService { 27 | 28 | @Value("${app.topic.name}") 29 | private String topicName; 30 | 31 | @Autowired 32 | private KafkaTemplate kafkaTemplate; 33 | 34 | 35 | @Override 36 | public void produce(String key, String message) { 37 | log.debug("Sending message : {}", message); 38 | // this.kafkaTemplate.send(topicName, message); 39 | } 40 | 41 | @Override 42 | public void produce(int vehicleId, VehicleLocation location) { 43 | log.debug("Sending Location info : {}", location); 44 | this.kafkaTemplate.send(topicName,vehicleId, location); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /idor-prevention/src/main/java/org/sk/owasp/api/security/idor/db/mock/DataBaseService.java: -------------------------------------------------------------------------------- 1 | package org.sk.owasp.api.security.idor.db.mock; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | import java.util.stream.IntStream; 6 | 7 | import org.springframework.stereotype.Service; 8 | 9 | /** 10 | * Service class to mock the data flow from actual database.In real-world, one shall be using the some database interaction technology, for eg. JDBC, JPA. 11 | *
12 | * This class provides functionality to get records belonging to particular id. 13 | * 14 | * 15 | * @author Satish Sharma 16 | * 17 | */ 18 | @Service 19 | public class DataBaseService { 20 | 21 | /** 22 | * Dummy Data-Store. Ideally we shall be dealing with Objects. 23 | */ 24 | private final Map financialDataForUserId; 25 | 26 | /** 27 | * initialize data for 10 user. Having ID 1-10 28 | */ 29 | public DataBaseService() { 30 | financialDataForUserId = new HashMap<>(); 31 | 32 | IntStream.range(1, 10) 33 | .forEach(x ->{ 34 | financialDataForUserId.put("user_"+x, "Financial Record of User "+x); 35 | }); 36 | } 37 | 38 | /** 39 | * Get all the available data 40 | * 41 | * @return 42 | */ 43 | public Map getAllRecords(){ 44 | return this.financialDataForUserId; 45 | } 46 | 47 | /** 48 | * Dummy method to access Financial data belonging to particular ID 49 | */ 50 | public String getFinancialDaataForRecordId(String userId) { 51 | return this.financialDataForUserId.get(userId); 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /vehicle-tracker/vehicle-simulator/src/main/java/org/sk/vtracker/simulator/services/ScheduledTasks.java: -------------------------------------------------------------------------------- 1 | package org.sk.vtracker.simulator.services; 2 | 3 | import java.text.SimpleDateFormat; 4 | import java.util.Date; 5 | 6 | import javax.annotation.PostConstruct; 7 | 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.beans.factory.annotation.Value; 10 | import org.springframework.kafka.core.KafkaTemplate; 11 | import org.springframework.scheduling.annotation.Scheduled; 12 | import org.springframework.stereotype.Component; 13 | 14 | import com.sk.vtracker.commons.models.VehicleLocation; 15 | 16 | import lombok.extern.log4j.Log4j2; 17 | 18 | @Log4j2 19 | @Component 20 | public class ScheduledTasks { 21 | 22 | @Value("${app.topic.name}") 23 | private String topicName; 24 | 25 | @Autowired 26 | private KafkaTemplate kafkaTemplate; 27 | 28 | 29 | private static final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss"); 30 | 31 | // @PostConstruct 32 | public void reportCurrentTime() throws InterruptedException { 33 | log.info("The time is now {}", dateFormat.format(new Date())); 34 | 35 | VehicleLocation loc = new VehicleLocation(true, true, 11111111, 444444); 36 | while(true) { 37 | boolean on = loc.isOnline() == true ? false : true; 38 | loc.setOnline(on); 39 | log.info("Sending Location info : {}", loc); 40 | Thread.sleep(10000); 41 | this.kafkaTemplate.send(topicName,1, loc); 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /centralized-swagger-docs/person-application/src/main/java/com/satish/central/docs/person/config/SwaggerDocumentationConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.satish.central.docs.person.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | 6 | import springfox.documentation.builders.ApiInfoBuilder; 7 | import springfox.documentation.builders.RequestHandlerSelectors; 8 | import springfox.documentation.service.ApiInfo; 9 | import springfox.documentation.service.Contact; 10 | import springfox.documentation.spi.DocumentationType; 11 | import springfox.documentation.spring.web.plugins.Docket; 12 | import springfox.documentation.swagger2.annotations.EnableSwagger2; 13 | 14 | @Configuration 15 | @EnableSwagger2 16 | public class SwaggerDocumentationConfiguration { 17 | 18 | 19 | ApiInfo apiInfo() { 20 | return new ApiInfoBuilder().title("Person REST CRUD operations API in Spring-Boot 2") 21 | .description( 22 | "Sample REST API for centalized documentation using Spring Boot and spring-fox swagger 2 ") 23 | .termsOfServiceUrl("").version("0.0.1-SNAPSHOT").contact(new Contact("Satish Sharma", "https://github.com/hellosatish", "https://github.com/hellosatish")).build(); 24 | } 25 | 26 | @Bean 27 | public Docket configureControllerPackageAndConvertors() { 28 | return new Docket(DocumentationType.SWAGGER_2).select() 29 | .apis(RequestHandlerSelectors.basePackage("com.satish.central.docs.person.web.rest.resource")).build() 30 | .apiInfo(apiInfo()); 31 | } 32 | 33 | 34 | } 35 | -------------------------------------------------------------------------------- /centralized-swagger-docs/employee-application/src/main/java/com/satish/central/docs/employee/config/SwaggerDocumentationConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.satish.central.docs.employee.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | 6 | import springfox.documentation.builders.ApiInfoBuilder; 7 | import springfox.documentation.builders.RequestHandlerSelectors; 8 | import springfox.documentation.service.ApiInfo; 9 | import springfox.documentation.service.Contact; 10 | import springfox.documentation.spi.DocumentationType; 11 | import springfox.documentation.spring.web.plugins.Docket; 12 | import springfox.documentation.swagger2.annotations.EnableSwagger2; 13 | /** 14 | * 15 | * @author satish-s 16 | * 17 | */ 18 | @Configuration 19 | @EnableSwagger2 20 | public class SwaggerDocumentationConfiguration { 21 | 22 | 23 | ApiInfo apiInfo() { 24 | return new ApiInfoBuilder().title("Employee REST CRUD operations API in Spring-Boot 2") 25 | .description( 26 | "Sample REST API for centalized documentation using Spring Boot and spring-fox swagger 2 ") 27 | .termsOfServiceUrl("").version("0.0.1-SNAPSHOT").contact(new Contact("Satish Sharma", "https://github.com/hellosatish", "https://github.com/hellosatish")).build(); 28 | } 29 | 30 | @Bean 31 | public Docket configureControllerPackageAndConvertors() { 32 | return new Docket(DocumentationType.SWAGGER_2).select() 33 | .apis(RequestHandlerSelectors.basePackage("com.satish.central.docs.employee.web.rest.resource")).build() 34 | .apiInfo(apiInfo()); 35 | } 36 | 37 | 38 | } 39 | -------------------------------------------------------------------------------- /vehicle-tracker/vehicle-simulator/src/main/java/org/sk/vtracker/simulator/web/rest/VehicleSimulationController.java: -------------------------------------------------------------------------------- 1 | package org.sk.vtracker.simulator.web.rest; 2 | 3 | import java.util.Random; 4 | 5 | import org.sk.vtracker.simulator.services.SimulationService; 6 | import org.springframework.http.HttpStatus; 7 | import org.springframework.http.ResponseEntity; 8 | import org.springframework.web.bind.annotation.PathVariable; 9 | import org.springframework.web.bind.annotation.PostMapping; 10 | import org.springframework.web.bind.annotation.RestController; 11 | 12 | @RestController 13 | public class VehicleSimulationController { 14 | 15 | private final SimulationService simulatorService; 16 | 17 | public VehicleSimulationController(SimulationService simulatorService) { 18 | super(); 19 | this.simulatorService = simulatorService; 20 | } 21 | 22 | @PostMapping("/simulate/{number-of-vehicle}/{emit-interval}/{stop-index}") 23 | public ResponseEntity simulateSingnalEmission(@PathVariable("number-of-vehicle") int numberOfVehicles, 24 | int emitInterval, int stopIndex) { 25 | 26 | for(int vehicleId = 1 ; vehicleId <= numberOfVehicles ; vehicleId++) { 27 | simulatorService.simulate(vehicleId, emitInterval*getRandomNumberInRange(1,4), stopIndex); 28 | } 29 | 30 | return new ResponseEntity("Simulation Started for "+numberOfVehicles+" vehicles", HttpStatus.OK); 31 | } 32 | 33 | 34 | private static int getRandomNumberInRange(int min, int max) { 35 | 36 | if (min >= max) { 37 | throw new IllegalArgumentException("max must be greater than min"); 38 | } 39 | 40 | Random r = new Random(); 41 | return r.nextInt((max - min) + 1) + min; 42 | } 43 | 44 | 45 | } 46 | -------------------------------------------------------------------------------- /micro-frameworks/javalin-app/src/main/java/org/sk/demo/crud/app/controller/PersonController.java: -------------------------------------------------------------------------------- 1 | package org.sk.demo.crud.app.controller; 2 | 3 | import org.sk.demo.crud.app.db.InMemoryDatabase; 4 | import org.sk.demo.crud.app.model.Person; 5 | 6 | import io.javalin.apibuilder.CrudHandler; 7 | import io.javalin.http.Context; 8 | 9 | /** 10 | * 11 | * @author satish sharma 12 | * 13 | */ 14 | public class PersonController { 15 | 16 | InMemoryDatabase dbHelper = new InMemoryDatabase(); 17 | 18 | public void create(Context ctx) { 19 | Person person = ctx.bodyAsClass(Person.class); 20 | boolean isAdded = dbHelper.addPerson(person); 21 | if(isAdded) { 22 | ctx.status(201); 23 | ctx.json(person); 24 | }else { 25 | ctx.status(500); 26 | } 27 | 28 | } 29 | 30 | public void delete(Context ctx) { 31 | int personId = Integer.parseInt(ctx.pathParam("person-id")); 32 | boolean isDeleted= dbHelper.deletePerson(personId); 33 | if(isDeleted) { 34 | ctx.status(201); 35 | ctx.json("Deleted Person data for Id "+personId); 36 | }else { 37 | ctx.status(500); 38 | } 39 | 40 | } 41 | 42 | public void getAll(Context ctx) { 43 | ctx.json(dbHelper.getAllPersons()); 44 | } 45 | 46 | public void getOne(Context ctx) { 47 | int personId = Integer.parseInt(ctx.pathParam("person-id")); 48 | ctx.json(dbHelper.getPersonById(personId)); 49 | } 50 | 51 | public void update(Context ctx) { 52 | Person person = ctx.bodyAsClass(Person.class); 53 | boolean isUpdated = dbHelper.updatePerson(person); 54 | if(isUpdated) { 55 | ctx.status(201); 56 | ctx.json(person); 57 | }else { 58 | ctx.status(500); 59 | } 60 | 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /centralized-swagger-docs/documentation-app/src/main/java/com/satish/central/docs/config/swagger/ServiceDefinitionsContext.java: -------------------------------------------------------------------------------- 1 | package com.satish.central.docs.config.swagger; 2 | 3 | import java.util.List; 4 | import java.util.concurrent.ConcurrentHashMap; 5 | import java.util.stream.Collectors; 6 | 7 | import org.springframework.beans.factory.config.ConfigurableBeanFactory; 8 | import org.springframework.context.annotation.Scope; 9 | import org.springframework.stereotype.Component; 10 | 11 | import springfox.documentation.swagger.web.SwaggerResource; 12 | 13 | /** 14 | * 15 | * @author satish sharma 16 | *
17 |  *   	In-Memory store to hold API-Definition JSON
18 |  * 
19 | */ 20 | @Component 21 | @Scope(scopeName=ConfigurableBeanFactory.SCOPE_SINGLETON) 22 | public class ServiceDefinitionsContext { 23 | 24 | private final ConcurrentHashMap serviceDescriptions; 25 | 26 | private ServiceDefinitionsContext(){ 27 | serviceDescriptions = new ConcurrentHashMap(); 28 | } 29 | 30 | public void addServiceDefinition(String serviceName, String serviceDescription){ 31 | serviceDescriptions.put(serviceName, serviceDescription); 32 | } 33 | 34 | public String getSwaggerDefinition(String serviceId){ 35 | return this.serviceDescriptions.get(serviceId); 36 | } 37 | 38 | public List getSwaggerDefinitions(){ 39 | return serviceDescriptions.entrySet().stream().map( serviceDefinition -> { 40 | SwaggerResource resource = new SwaggerResource(); 41 | resource.setLocation("/service/"+serviceDefinition.getKey()); 42 | resource.setName(serviceDefinition.getKey()); 43 | resource.setSwaggerVersion("2.0"); 44 | return resource; 45 | }).collect(Collectors.toList()); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /centralized-swagger-docs/documentation-app/src/main/java/com/satish/central/docs/config/swagger/SwaggerUIConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.satish.central.docs.config.swagger; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.context.annotation.Configuration; 9 | import org.springframework.context.annotation.Lazy; 10 | import org.springframework.context.annotation.Primary; 11 | import org.springframework.web.client.RestTemplate; 12 | 13 | import springfox.documentation.swagger.web.InMemorySwaggerResourcesProvider; 14 | import springfox.documentation.swagger.web.SwaggerResource; 15 | import springfox.documentation.swagger.web.SwaggerResourcesProvider; 16 | 17 | /** 18 | * 19 | * @author satish sharma 20 | *
21 |  *  Swagger Ui configurations. Configure bean of the {@link SwaggerResourcesProvider} to
22 |  *   read data from in-memory contex 	
23 |  * 
24 | */ 25 | @Configuration 26 | public class SwaggerUIConfiguration { 27 | 28 | @Autowired 29 | private ServiceDefinitionsContext definitionContext; 30 | 31 | @Bean 32 | public RestTemplate configureTempalte(){ 33 | return new RestTemplate(); 34 | } 35 | 36 | @Primary 37 | @Bean 38 | @Lazy 39 | public SwaggerResourcesProvider swaggerResourcesProvider(InMemorySwaggerResourcesProvider defaultResourcesProvider, RestTemplate temp) { 40 | return () -> { 41 | List resources = new ArrayList<>(defaultResourcesProvider.get()); 42 | resources.clear(); 43 | resources.addAll(definitionContext.getSwaggerDefinitions()); 44 | return resources; 45 | }; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /centralized-swagger-docs/README.md: -------------------------------------------------------------------------------- 1 | # The Problem 2 | As we already know, it is very easy to document REST applications using the SpringFox Swagger-UI library, but a problem arises when we are working in an environment where we have multiple REST-based applications. Typically, we face this issue in a microservices environment. Most of us end up managing a separate Swagger-UI for each application, which means that each service will have its own endpoint and to access the Swagger-UI and we have to use a different URL for different applications. 3 | 4 | # Solution 5 | - Get the list of registered service instances from the service registry. 6 | - For each registered service instance, pull the Swagger definition JSON from the instance and store it locally. In our case, we are putting this JSON in the in-memory documentation context backed by a concurrent map. 7 | - Refresh the in-memory context at regular intervals to automatically remove/add the definitions as they are updated in the service registry. 8 | - Provide a single endpoint to serve Swagger definitions from our in-memory store on the basis of service instance name. 9 | 10 | ## This repositry contain below projects 11 | 12 | * **central-docs-eureka-server:** Service registry powered by Netflix Eureka 13 | * **employee-application** and **person-application:** REST applications with Swagger-UI enabled. You can follow [this article] (https://dzone.com/articles/monitoring-using-spring-boot-2-prometheus-amp-graf) for a step-by-step guide. 14 | * **documentation-service:** Spring Boot-based REST application consolidating all the Swagger JSON and offering it in a single endpoint. Please note that this component can be part of a gateway or the registry itself, but I have chosen to keep it separate. The final documentation shall be available at http://localhost:9093/swagger-ui.html. 15 | 16 | 17 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # microservice-patterns 2 | Code to share the knowledge I gained while designing and implementing micro services 3 | Below are the projects description 4 | 1. [awesome-project](https://github.com/hellosatish/microservice-patterns/tree/master/awesomeProject) : This project demonstrates the service registry pattern. how to register a non-java application. 5 | 2. [centralized-swagger-docs](https://github.com/hellosatish/microservice-patterns/tree/master/centralized-swagger-docs) : Swagger is un-doubtly the most used REST api documentation framework. And [swagger-ui](https://github.com/swagger-api/swagger-ui) is the implementation for Java. 6 | But, in case of microservices where you have multiple application and each exposes swagger document. This project is aimed at how do you consolidate all these swagger documents and expose them at one place. 7 | The [documentation-app](https://github.com/hellosatish/microservice-patterns/tree/master/centralized-swagger-docs/documentation-app) aggregates data(swagger docs JSON) from other services and exposes a single endpoint for outer world. This application could be ocnsidered as the implemenation of Aggregator microservice pattern. 8 | 9 | >Please note this implementation is specific to swagger-api and spring boot. However you can implement the same design in any language and tool 10 | 11 | 12 | 3. [vehicle-tracker](https://github.com/hellosatish/microservice-patterns/tree/master/vehicle-tracker) : An example of evnt based microservices. In this case we target real time event processing using [kafka-stream](https://kafka.apache.org/documentation/streams/) and spring boot. 13 | 14 | 4. [micro-frameworks](https://github.com/hellosatish/microservice-patterns/tree/master/micro-frameworks) : Playground with micro-frameworks for java 15 | 5. [IDOR Prevention](https://github.com/hellosatish/microservice-patterns/tree/master/idor-prevention) : An sample API demonstrating, one of the IDOR prevention strategy. 16 | -------------------------------------------------------------------------------- /vehicle-tracker/README.md: -------------------------------------------------------------------------------- 1 | # Real time analytics with kafka streams 2 | This projects demosntrates real time processing using kafka streams processing DSL 3 | 4 | 5 | 6 | ## Assumptions 7 | 1. you allready have the kafka cluster setup. if not please reffer to the docs directory. Refer the section 'How to Setup single node Kafka cluster' on page 7 8 | 2. The topic is created, which is requried by this application to function. You can use below command to create the topic 'gplsLocation' 9 | `kafka-topics.bat --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic gpslocation` 10 | 11 | ## Project 12 | ### vehicle-tracker: 13 | The overall project wrapping all other applications as Modules. 14 | 15 | ### common-libs: 16 | this will contain the POJO classes to model the different objects like Vehicle, VehicleCount, VehicleLocation. This application will be added as dependency to other two applications eliminating the concerns of model mismatch. 17 | ### vehicle-simulator: 18 | the responsibility of this application will be to simulate the behavior of GPS signals being emitted by the device fitted in each vehicle. 19 | ### tracker-dashboard: 20 | this application will be our stream processing component. Though we can have separate application for querying the state-stores of Kafka, but for the sake of simplicity we add this functionality in this application itself. 21 | 22 | ## How to run the application 23 | 24 | 1. start the zookeper server 25 | 2. start the kafka server 26 | 3. create topic 'gpslocation', if not already created 27 | 4. start the *vehicle-simulator* application and use below CURL command to simulate the GPS signal emission 28 | ` curl -X POST "http://localhost:8080/simulate/3/{emit-interval}/{stop-index}?emitInterval=1&stopIndex=1" -H "accept: */*" ` 29 | 5. start the *tracker-dashboard* application and use below CURL command to get the Online/Offline vehicle count 30 | ` curl http://localhost:9090/count/Online` 31 | ` curl http://localhost:9090/count/Offline` 32 | -------------------------------------------------------------------------------- /idor-prevention/src/main/java/org/sk/owasp/api/security/idor/web/resources/SampleAPI.java: -------------------------------------------------------------------------------- 1 | package org.sk.owasp.api.security.idor.web.resources; 2 | 3 | import java.util.List; 4 | import java.util.stream.Collectors; 5 | 6 | import org.sk.owasp.api.security.idor.db.mock.DataBaseService; 7 | import org.sk.owasp.api.security.idor.util.IdorUtility; 8 | import org.springframework.util.MimeTypeUtils; 9 | import org.springframework.web.bind.annotation.GetMapping; 10 | import org.springframework.web.bind.annotation.PathVariable; 11 | import org.springframework.web.bind.annotation.RestController; 12 | 13 | import lombok.RequiredArgsConstructor; 14 | 15 | /** 16 | * FOR DEMONSTRATION ONLY, NOT TO BE USED IN PRODUCTION.
17 | * Dummy controller exposing API to get data based on ID's 18 | * 19 | * 20 | * @author Satish Sharma 21 | * 22 | */ 23 | @RestController 24 | @RequiredArgsConstructor // auto-generate constructor 25 | public class SampleAPI { 26 | 27 | private final DataBaseService dbService; 28 | private final IdorUtility idorUtil; 29 | 30 | 31 | @GetMapping(value = "/getdata-IDOR-vulnerable/{user-id}") 32 | public String getDataForIDUnsecured(@PathVariable("user-id") String userId) { 33 | return dbService.getFinancialDaataForRecordId(userId); 34 | } 35 | 36 | @GetMapping(value ="/get-identifiers") 37 | public List getUserIDs(){ 38 | return dbService.getAllRecords().keySet().stream().collect(Collectors.toList()); 39 | } 40 | 41 | // --------------- Safer API's --------------- // 42 | 43 | @GetMapping(value = "/getdata-IDOR-secured/{user-id}") 44 | public String getDataForID_IDOR_SAFE(@PathVariable("user-id") String obfuscatedIdentifier) { 45 | String actualIdentifier = idorUtil.resolveObfuscatedId(obfuscatedIdentifier); 46 | return dbService.getFinancialDaataForRecordId(actualIdentifier); 47 | } 48 | 49 | @GetMapping(value ="/get-identifiers-IDOR-secured") 50 | public List getObfuscatedUserIDs(){ 51 | return dbService.getAllRecords().keySet().stream().map( userId -> { 52 | return idorUtil.computeObfuscatedId(userId); 53 | }).collect(Collectors.toList()); 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /idor-prevention/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | org.springframework.boot 8 | spring-boot-starter-parent 9 | 2.3.2.RELEASE 10 | 11 | 12 | org.sk.owasp.api.security 13 | idor-prevention 14 | 0.0.1-SNAPSHOT 15 | idor-prevention 16 | Demo for IDOR prevention 17 | 18 | 19 | 11 20 | 2.9.2 21 | 22 | 23 | 24 | 25 | 26 | org.springframework.boot 27 | spring-boot-starter-web 28 | 29 | 30 | 31 | org.projectlombok 32 | lombok 33 | true 34 | 35 | 36 | 37 | 38 | io.springfox 39 | springfox-swagger2 40 | ${swagger-version} 41 | 42 | 43 | io.springfox 44 | springfox-swagger-ui 45 | ${swagger-version} 46 | 47 | 48 | 49 | 50 | org.springframework.boot 51 | spring-boot-starter-test 52 | test 53 | 54 | 55 | org.junit.vintage 56 | junit-vintage-engine 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | org.springframework.boot 66 | spring-boot-maven-plugin 67 | 68 | 69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /centralized-swagger-docs/central-docs-eureka-server/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.satish 7 | central-docs-eureka-server 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | central-docs-eureka-server 12 | Eureka server 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 2.0.5.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | Finchley.SR1 26 | 27 | 28 | 29 | 30 | org.springframework.cloud 31 | spring-cloud-starter-netflix-eureka-server 32 | 33 | 34 | org.springframework.boot 35 | spring-boot-starter-web 36 | 37 | 38 | org.springframework.boot 39 | spring-boot-starter-test 40 | test 41 | 42 | 43 | 44 | 45 | 46 | 47 | org.springframework.cloud 48 | spring-cloud-dependencies 49 | ${spring-cloud.version} 50 | pom 51 | import 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | org.springframework.boot 60 | spring-boot-maven-plugin 61 | 62 | 63 | 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /vehicle-tracker/vehicle-simulator/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | vehicle-tracker 8 | vehicle-tracker 9 | 0.0.1-SNAPSHOT 10 | ../../vehicle-tracker 11 | 12 | vehicle-simulator 13 | vehicle-simulator 14 | vehicle simulator for application 15 | 16 | 17 | 1.8 18 | 2.9.2 19 | 20 | 21 | 22 | 23 | org.springframework.boot 24 | spring-boot-starter-web 25 | 26 | 27 | org.springframework.kafka 28 | spring-kafka 29 | 30 | 31 | 32 | org.projectlombok 33 | lombok 34 | true 35 | 36 | 37 | 38 | io.springfox 39 | springfox-swagger2 40 | ${swagger-version} 41 | 42 | 43 | io.springfox 44 | springfox-swagger-ui 45 | ${swagger-version} 46 | 47 | 48 | 49 | common-libs 50 | ${project.version} 51 | ${project.groupId} 52 | 53 | 54 | 55 | org.springframework.boot 56 | spring-boot-starter-test 57 | test 58 | 59 | 60 | 61 | 62 | 63 | 64 | org.springframework.boot 65 | spring-boot-maven-plugin 66 | 67 | 68 | 69 | 70 | 71 | -------------------------------------------------------------------------------- /vehicle-tracker/tracker-dashboard/src/main/java/org/sk/vtracker/dashboard/streams/processor/VehicleStatusCountProcessor.java: -------------------------------------------------------------------------------- 1 | package org.sk.vtracker.dashboard.streams.processor; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import org.apache.kafka.clients.consumer.ConsumerConfig; 7 | import org.apache.kafka.common.serialization.IntegerDeserializer; 8 | import org.apache.kafka.common.serialization.Serdes; 9 | import org.apache.kafka.streams.KeyValue; 10 | import org.apache.kafka.streams.StreamsBuilder; 11 | import org.apache.kafka.streams.StreamsConfig; 12 | import org.apache.kafka.streams.kstream.Consumed; 13 | import org.apache.kafka.streams.kstream.KStream; 14 | import org.apache.kafka.streams.kstream.Materialized; 15 | import org.apache.kafka.streams.kstream.Serialized; 16 | import org.springframework.beans.factory.annotation.Autowired; 17 | import org.springframework.boot.autoconfigure.kafka.KafkaProperties; 18 | import org.springframework.context.annotation.Bean; 19 | import org.springframework.kafka.support.serializer.JsonSerde; 20 | import org.springframework.stereotype.Component; 21 | 22 | import com.sk.vtracker.commons.models.VehicleLocation; 23 | 24 | @Component 25 | public class VehicleStatusCountProcessor { 26 | @Autowired 27 | private KafkaProperties kafkaProperties; //default properties 28 | 29 | @Bean //configure key-value serdes 30 | public Map consumerConfigs() { 31 | Map props = new HashMap<>(kafkaProperties.buildProducerProperties()); 32 | props.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, IntegerDeserializer.class); 33 | props.put(StreamsConfig.DEFAULT_VALUE_SERDE_CLASS_CONFIG, JsonSerde.class); 34 | return props; 35 | } 36 | 37 | @Bean 38 | public KStream statusCountStreamProcessor(StreamsBuilder streamsBuilder) { 39 | KStream stream = streamsBuilder.stream("gpslocation", //Read from topic 40 | Consumed.with(Serdes.Integer(), new JsonSerde<>(VehicleLocation.class))); //using Integer and JSON serde 41 | return stream.map((k,v)-> { // transform they key as Online/Offline based on status 42 | String online = v.isOnline() == true ? "Online" : "Offline"; 43 | return new KeyValue<>(online, v); 44 | }) 45 | .groupByKey(Serialized.with( //Group by the newly mapped key in previous step 46 | Serdes.String(), 47 | new JsonSerde<>(VehicleLocation.class)) 48 | ) 49 | .count(Materialized.as("statusCount")) // materialize this value to state store 50 | .toStream(); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /micro-frameworks/sample-requests/person-app.postman_collection.json: -------------------------------------------------------------------------------- 1 | { 2 | "info": { 3 | "_postman_id": "f961173f-10c2-4ad3-92c7-71a3c43ae3a8", 4 | "name": "person-app", 5 | "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" 6 | }, 7 | "item": [ 8 | { 9 | "name": "http://localhost:7000/persons", 10 | "request": { 11 | "method": "GET", 12 | "header": [], 13 | "url": { 14 | "raw": "http://localhost:7000/persons", 15 | "protocol": "http", 16 | "host": [ 17 | "localhost" 18 | ], 19 | "port": "7000", 20 | "path": [ 21 | "persons" 22 | ] 23 | }, 24 | "description": "get all parsons" 25 | }, 26 | "response": [] 27 | }, 28 | { 29 | "name": "create person", 30 | "request": { 31 | "method": "POST", 32 | "header": [ 33 | { 34 | "key": "Content-Type", 35 | "value": "application/json", 36 | "type": "text" 37 | } 38 | ], 39 | "body": { 40 | "mode": "raw", 41 | "raw": "{\n\t\"id\":1,\n\t\"firstName\":\"Satish\",\n\t\"lastName\":\"Sharma\"\n}" 42 | }, 43 | "url": { 44 | "raw": "http://localhost:7000/persons", 45 | "protocol": "http", 46 | "host": [ 47 | "localhost" 48 | ], 49 | "port": "7000", 50 | "path": [ 51 | "persons" 52 | ] 53 | } 54 | }, 55 | "response": [] 56 | }, 57 | { 58 | "name": "update person", 59 | "request": { 60 | "method": "PUT", 61 | "header": [ 62 | { 63 | "key": "Content-Type", 64 | "value": "application/json", 65 | "type": "text" 66 | } 67 | ], 68 | "body": { 69 | "mode": "raw", 70 | "raw": "{\n\t\"id\":2,\n\t\"firstName\":\"sidhhant\",\n\t\"lastName\":\"mishra\"\n}" 71 | }, 72 | "url": { 73 | "raw": "http://localhost:7000/persons", 74 | "protocol": "http", 75 | "host": [ 76 | "localhost" 77 | ], 78 | "port": "7000", 79 | "path": [ 80 | "persons" 81 | ] 82 | } 83 | }, 84 | "response": [] 85 | }, 86 | { 87 | "name": "delete person", 88 | "request": { 89 | "method": "DELETE", 90 | "header": [], 91 | "url": { 92 | "raw": "http://localhost:7000/persons/2", 93 | "protocol": "http", 94 | "host": [ 95 | "localhost" 96 | ], 97 | "port": "7000", 98 | "path": [ 99 | "persons", 100 | "2" 101 | ] 102 | } 103 | }, 104 | "response": [] 105 | } 106 | ] 107 | } -------------------------------------------------------------------------------- /vehicle-tracker/vehicle-simulator/src/main/java/org/sk/vtracker/simulator/config/SwaggerConfigurations.java: -------------------------------------------------------------------------------- 1 | package org.sk.vtracker.simulator.config; 2 | 3 | 4 | import java.util.Collections; 5 | 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.context.annotation.Configuration; 8 | 9 | import springfox.documentation.builders.PathSelectors; 10 | import springfox.documentation.builders.RequestHandlerSelectors; 11 | import springfox.documentation.service.ApiInfo; 12 | import springfox.documentation.service.Contact; 13 | import springfox.documentation.spi.DocumentationType; 14 | import springfox.documentation.spring.web.plugins.Docket; 15 | import springfox.documentation.swagger.web.DocExpansion; 16 | import springfox.documentation.swagger.web.ModelRendering; 17 | import springfox.documentation.swagger.web.OperationsSorter; 18 | import springfox.documentation.swagger.web.TagsSorter; 19 | import springfox.documentation.swagger.web.UiConfiguration; 20 | import springfox.documentation.swagger.web.UiConfigurationBuilder; 21 | 22 | 23 | @Configuration 24 | public class SwaggerConfigurations { 25 | 26 | @Bean 27 | public Docket api() { 28 | return new Docket(DocumentationType.SWAGGER_2) 29 | .select() 30 | .apis(RequestHandlerSelectors.basePackage("org.sk.vtracker.simulator.web.rest")) 31 | .paths(PathSelectors.any()) 32 | .build() 33 | .apiInfo(apiInfo()); 34 | } 35 | 36 | private ApiInfo apiInfo() { 37 | return new ApiInfo( 38 | "Booking API", 39 | "API. Offering cab booking service", 40 | "API TOS", 41 | "Terms of service", 42 | new Contact("Satish Sharma", "https://github.com/hellosatish", "myeaddress@abc.com"), 43 | "License of API", "API license URL", Collections.emptyList()); 44 | } 45 | 46 | @Bean 47 | UiConfiguration uiConfig() { 48 | return UiConfigurationBuilder.builder() 49 | .deepLinking(true) 50 | .displayOperationId(false) 51 | .defaultModelsExpandDepth(1) 52 | .defaultModelExpandDepth(1) 53 | .defaultModelRendering(ModelRendering.EXAMPLE) 54 | .displayRequestDuration(false) 55 | .docExpansion(DocExpansion.NONE) 56 | .filter(false) 57 | .maxDisplayedTags(null) 58 | .operationsSorter(OperationsSorter.ALPHA) 59 | .showExtensions(false) 60 | .tagsSorter(TagsSorter.ALPHA) 61 | .supportedSubmitMethods(UiConfiguration.Constants.DEFAULT_SUBMIT_METHODS) 62 | .validatorUrl(null) 63 | .build(); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /centralized-swagger-docs/person-application/src/main/java/com/satish/central/docs/person/web/rest/resource/PersonResource.java: -------------------------------------------------------------------------------- 1 | package com.satish.central.docs.person.web.rest.resource; 2 | 3 | import java.util.List; 4 | import java.util.Optional; 5 | 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.http.HttpStatus; 8 | import org.springframework.http.ResponseEntity; 9 | import org.springframework.web.bind.annotation.GetMapping; 10 | import org.springframework.web.bind.annotation.PathVariable; 11 | import org.springframework.web.bind.annotation.PostMapping; 12 | import org.springframework.web.bind.annotation.PutMapping; 13 | import org.springframework.web.bind.annotation.RequestBody; 14 | import org.springframework.web.bind.annotation.RequestMapping; 15 | import org.springframework.web.bind.annotation.RestController; 16 | 17 | import com.satish.central.docs.person.db.entities.Person; 18 | import com.satish.central.docs.person.db.repository.PersonRepository; 19 | 20 | @RestController 21 | @RequestMapping(value="/person") 22 | public class PersonResource { 23 | 24 | 25 | //Ideally you shall be using Service classes 26 | @Autowired 27 | PersonRepository personRepo; 28 | 29 | 30 | @GetMapping 31 | public ResponseEntity< List> getAllPersons(){ 32 | return ResponseEntity.ok(personRepo.findAll()); 33 | } 34 | 35 | @GetMapping("/{personid}") 36 | public ResponseEntity getPersonById(@PathVariable("personId") int personID){ 37 | Optional personInDB = personRepo.findById(personID); 38 | if(personInDB.isPresent()){ 39 | return ResponseEntity.ok(personInDB.get()); 40 | }else{ 41 | return new ResponseEntity(HttpStatus.NOT_FOUND); 42 | } 43 | } 44 | 45 | @PostMapping 46 | public ResponseEntity storePerson(@RequestBody Person person ){ 47 | Person personInDB = personRepo.save(person); 48 | return new ResponseEntity(personInDB,HttpStatus.CREATED); 49 | } 50 | 51 | @PutMapping("/{personId}") 52 | public ResponseEntity updatePersonDetails(@PathVariable("personId") int personID,@RequestBody(required=true) Person personDataToBeUpdated ){ 53 | 54 | if(personID != personDataToBeUpdated.getId() ){ //Just to make sure we have same person_id in path param and body. 55 | return new ResponseEntity(HttpStatus.BAD_REQUEST); 56 | } 57 | 58 | Optional personInDB = personRepo.findById(personID); 59 | if(personInDB.isPresent()){ 60 | Person person = personRepo.saveAndFlush(personDataToBeUpdated); 61 | return ResponseEntity.ok(person); 62 | }else{ 63 | return new ResponseEntity(HttpStatus.NOT_FOUND); 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /idor-prevention/src/main/java/org/sk/owasp/api/security/idor/config/SwaggerConfigurations.java: -------------------------------------------------------------------------------- 1 | package org.sk.owasp.api.security.idor.config; 2 | 3 | import java.util.Collections; 4 | 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | 8 | import springfox.documentation.builders.PathSelectors; 9 | import springfox.documentation.builders.RequestHandlerSelectors; 10 | import springfox.documentation.service.ApiInfo; 11 | import springfox.documentation.service.Contact; 12 | import springfox.documentation.spi.DocumentationType; 13 | import springfox.documentation.spring.web.plugins.Docket; 14 | import springfox.documentation.swagger.web.DocExpansion; 15 | import springfox.documentation.swagger.web.ModelRendering; 16 | import springfox.documentation.swagger.web.OperationsSorter; 17 | import springfox.documentation.swagger.web.TagsSorter; 18 | import springfox.documentation.swagger.web.UiConfiguration; 19 | import springfox.documentation.swagger.web.UiConfigurationBuilder; 20 | 21 | 22 | /** 23 | * Configura Swagger-UI 24 | * 25 | * @author Satish Sharma 26 | * 27 | */ 28 | @Configuration 29 | public class SwaggerConfigurations { 30 | 31 | @Bean 32 | public Docket api() { 33 | return new Docket(DocumentationType.SWAGGER_2) 34 | .select() 35 | .apis(RequestHandlerSelectors.basePackage("org.sk.owasp.api.security.idor.web.resources")) 36 | .paths(PathSelectors.any()) 37 | .build() 38 | .apiInfo(apiInfo()); 39 | } 40 | 41 | private ApiInfo apiInfo() { 42 | return new ApiInfo( 43 | "Sample code for IDOR prevention", 44 | "Sample code to demonstrate IDOR prevention. This is PSEUDO code only, not to be used in production ", 45 | "IDOR Prevention", 46 | "IDOR", 47 | new Contact("Satish Sharma", "https://github.com/hellosatish", "https://linkedin.com/in/satish-sharma-49065226"), 48 | "License of API", "API license URL", Collections.emptyList()); 49 | } 50 | 51 | @Bean 52 | UiConfiguration uiConfig() { 53 | return UiConfigurationBuilder.builder() 54 | .deepLinking(true) 55 | .displayOperationId(false) 56 | .defaultModelsExpandDepth(1) 57 | .defaultModelExpandDepth(1) 58 | .defaultModelRendering(ModelRendering.EXAMPLE) 59 | .displayRequestDuration(false) 60 | .docExpansion(DocExpansion.NONE) 61 | .filter(false) 62 | .maxDisplayedTags(null) 63 | .operationsSorter(OperationsSorter.ALPHA) 64 | .showExtensions(false) 65 | .tagsSorter(TagsSorter.ALPHA) 66 | .supportedSubmitMethods(UiConfiguration.Constants.DEFAULT_SUBMIT_METHODS) 67 | .validatorUrl(null) 68 | .build(); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /centralized-swagger-docs/employee-application/src/main/java/com/satish/central/docs/employee/web/rest/resource/EmployeeResource.java: -------------------------------------------------------------------------------- 1 | package com.satish.central.docs.employee.web.rest.resource; 2 | 3 | import java.util.List; 4 | import java.util.Optional; 5 | 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.http.HttpStatus; 8 | import org.springframework.http.ResponseEntity; 9 | import org.springframework.web.bind.annotation.GetMapping; 10 | import org.springframework.web.bind.annotation.PathVariable; 11 | import org.springframework.web.bind.annotation.PostMapping; 12 | import org.springframework.web.bind.annotation.PutMapping; 13 | import org.springframework.web.bind.annotation.RequestBody; 14 | import org.springframework.web.bind.annotation.RequestMapping; 15 | import org.springframework.web.bind.annotation.RestController; 16 | 17 | import com.satish.central.docs.employee.db.entities.Employee; 18 | import com.satish.central.docs.employee.db.repository.EmployeeRepository; 19 | 20 | @RestController 21 | @RequestMapping(value="/employee") 22 | public class EmployeeResource { 23 | 24 | 25 | //Ideally you shall be using Service classes 26 | @Autowired 27 | EmployeeRepository employeeRepository; 28 | 29 | 30 | @GetMapping 31 | public ResponseEntity< List> getAllEmployees(){ 32 | return ResponseEntity.ok(employeeRepository.findAll()); 33 | } 34 | 35 | @GetMapping("/{employeeid}") 36 | public ResponseEntity getEmployeeByEmployeeId(@PathVariable("employeeid") int employeeid){ 37 | Optional personInDB = employeeRepository.findById(employeeid); 38 | if(personInDB.isPresent()){ 39 | return ResponseEntity.ok(personInDB.get()); 40 | }else{ 41 | return new ResponseEntity(HttpStatus.NOT_FOUND); 42 | } 43 | } 44 | 45 | @PostMapping 46 | public ResponseEntity createNewEmployee(@RequestBody Employee person ){ 47 | Employee personInDB = employeeRepository.save(person); 48 | return new ResponseEntity(personInDB,HttpStatus.CREATED); 49 | } 50 | 51 | @PutMapping("/{employeeid}") 52 | public ResponseEntity updateEmployeeById(@PathVariable("employeeid") int employeeid,@RequestBody(required=true) Employee employeeDataToBeUpdated ){ 53 | 54 | if(employeeid != employeeDataToBeUpdated.getEmployeeId() ){ //Just to make sure we have same person_id in path param and body. 55 | return new ResponseEntity(HttpStatus.BAD_REQUEST); 56 | } 57 | 58 | Optional personInDB = employeeRepository.findById(employeeid); 59 | if(personInDB.isPresent()){ 60 | Employee person = employeeRepository.saveAndFlush(employeeDataToBeUpdated); 61 | return ResponseEntity.ok(person); 62 | }else{ 63 | return new ResponseEntity(HttpStatus.NOT_FOUND); 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /centralized-swagger-docs/documentation-app/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.satish 7 | documentation-apps 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | documentation-app 12 | Centralized REST API documentation using Swagger and Eureka 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 2.0.5.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | Finchley.SR1 26 | 2.9.2 27 | 28 | 29 | 30 | 31 | org.springframework.boot 32 | spring-boot-starter-web 33 | 34 | 35 | org.springframework.cloud 36 | spring-cloud-starter-netflix-eureka-client 37 | 38 | 39 | io.springfox 40 | springfox-swagger2 41 | ${springfox.swagger.version} 42 | 43 | 44 | io.springfox 45 | springfox-swagger-ui 46 | ${springfox.swagger.version} 47 | 48 | 49 | org.projectlombok 50 | lombok 51 | true 52 | 53 | 54 | org.springframework.boot 55 | spring-boot-starter-test 56 | test 57 | 58 | 59 | 60 | 61 | 62 | 63 | org.springframework.cloud 64 | spring-cloud-dependencies 65 | ${spring-cloud.version} 66 | pom 67 | import 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | org.springframework.boot 76 | spring-boot-maven-plugin 77 | 78 | 79 | 80 | 81 | 82 | 83 | -------------------------------------------------------------------------------- /micro-frameworks/javalin-app/src/main/java/org/sk/demo/crud/app/db/InMemoryDatabase.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.sk.demo.crud.app.db; 5 | 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | import java.util.Optional; 9 | 10 | import org.sk.demo.crud.app.model.Person; 11 | 12 | /** 13 | * @author satish sharma 14 | * 15 | * There could be mulitple implementations conidering different ascpects 16 | * like performance, but our target is to mimic the operations 17 | * in-memory instead of goind to database 18 | * 19 | */ 20 | public class InMemoryDatabase { 21 | 22 | private List allPersons = new ArrayList(); 23 | 24 | 25 | /** 26 | * 27 | * @return {@link List} of all persons available 28 | */ 29 | public List getAllPersons() { 30 | return allPersons; 31 | } 32 | 33 | /** 34 | * 35 | * @param personId Id of the person to be searched 36 | * @return {@link Optional#empty()} if the person is not found with the supplied id else return the person id 37 | */ 38 | public Optional getPersonById(final int personId) { 39 | return allPersons.stream().filter(p -> p.getId() == personId).findFirst(); 40 | } 41 | 42 | /** 43 | * 44 | * @param personId The id of the person 45 | * @return true or false denotig success or failur of the operation 46 | */ 47 | public boolean deletePerson(final int personId) { 48 | Optional personExit = allPersons.stream().filter(p -> p.getId() == personId).findFirst(); 49 | if (personExit.isPresent()) { 50 | allPersons.remove(personExit.get()); 51 | return true; 52 | } 53 | return false; 54 | } 55 | 56 | /** 57 | * 58 | * @param personToBeAdded Data for person 59 | * @return true or false denotig success or failur of the operation 60 | */ 61 | public boolean addPerson(Person personToBeAdded) { 62 | return allPersons.add(personToBeAdded); 63 | } 64 | 65 | /** 66 | * 67 | * @param personDataTobBeUpdated Person data to be updated 68 | * @return true or false denotig success or failur of the operation 69 | */ 70 | public boolean updatePerson(Person personDataTobBeUpdated) { 71 | 72 | Optional personInDb =allPersons.stream().filter(p -> p.getId() == personDataTobBeUpdated.getId()).findFirst(); 73 | 74 | if(personInDb.isPresent()) { 75 | Person p = personInDb.get(); 76 | p.setFirstName(personDataTobBeUpdated.getFirstName()); 77 | p.setLastName(personDataTobBeUpdated.getLastName()); 78 | return true; 79 | }else { 80 | return false; 81 | } 82 | /*allPersons.stream().filter(p -> p.getId() == personDataTobBeUpdated.getId()).map(p -> { 83 | p.setFirstName(personDataTobBeUpdated.getFirstName()); 84 | p.setLastName(personDataTobBeUpdated.getLastName()); 85 | return p; 86 | }); 87 | return false;*/ 88 | } 89 | 90 | } 91 | -------------------------------------------------------------------------------- /vehicle-tracker/tracker-dashboard/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | vehicle-tracker 8 | vehicle-tracker 9 | 0.0.1-SNAPSHOT 10 | ../../vehicle-tracker 11 | 12 | tracker-dashboard 13 | tracker-dashboard 14 | vehicle dashboard offering details 15 | 16 | 17 | 1.8 18 | 2.9.2 19 | 20 | 21 | 22 | 23 | org.springframework.boot 24 | spring-boot-starter-web 25 | 26 | 27 | 28 | io.springfox 29 | springfox-swagger2 30 | ${swagger-version} 31 | 32 | 33 | io.springfox 34 | springfox-swagger-ui 35 | ${swagger-version} 36 | 37 | 38 | 39 | common-libs 40 | ${project.version} 41 | ${project.groupId} 42 | 43 | 44 | 45 | 46 | org.springframework.boot 47 | spring-boot-starter-test 48 | test 49 | 50 | 51 | org.springframework.kafka 52 | spring-kafka 53 | 54 | 55 | org.apache.kafka 56 | kafka-streams 57 | 58 | 59 | 60 | org.apache.kafka 61 | kafka-clients 62 | 63 | 64 | org.springframework.cloud 65 | spring-cloud-stream-test-support 66 | test 67 | 68 | 69 | 70 | 71 | 72 | 73 | org.springframework.boot 74 | spring-boot-maven-plugin 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | org.springframework.cloud 83 | spring-cloud-dependencies 84 | Greenwich.SR1 85 | pom 86 | import 87 | 88 | 89 | 90 | 91 | -------------------------------------------------------------------------------- /awesomeProject/helper/HttpHelper.go: -------------------------------------------------------------------------------- 1 | package helper 2 | 3 | import ( 4 | "net/http" 5 | "log" 6 | "encoding/json" 7 | "bytes" 8 | "time" 9 | "errors" 10 | ) 11 | 12 | type OperationBody interface { 13 | } 14 | 15 | //MakePostCall 16 | func MakePostCall(urlToPost string, body OperationBody, headers map[string]string) (error, *http.Response) { 17 | log.Printf("In MakePostCall to %s with body %s",urlToPost,body) 18 | tr := &http.Transport{ 19 | MaxIdleConns: 10, 20 | IdleConnTimeout: 30 * time.Second, 21 | DisableCompression: true, 22 | } 23 | var buffer bytes.Buffer 24 | encoder := json.NewEncoder(&buffer) 25 | //encoder.SetIndent(" ", "\t") 26 | err := encoder.Encode(body) 27 | if err != nil { 28 | log.Print("error while encoding "+err.Error()) 29 | } 30 | 31 | log.Printf("Request body %+v",buffer.String()) 32 | 33 | client := &http.Client{Transport: tr} 34 | req, err := http.NewRequest(http.MethodPost, urlToPost, &buffer) 35 | if err != nil { 36 | log.Print("Error while creating the http request " + err.Error()) 37 | return errors.New("Error while creating http request " + err.Error()), nil 38 | } 39 | 40 | req.Header.Add("Content-Type", "application/json") 41 | for key, value := range headers { 42 | req.Header.Add(key, value) 43 | } 44 | 45 | resp, err := client.Do(req) 46 | if err != nil { 47 | log.Print("Error while making post call " + err.Error()) 48 | return errors.New("Error while making post call " + err.Error()), nil 49 | } 50 | log.Print("Successfull POST call with HTTP Status : " + resp.Status) 51 | 52 | return nil, resp 53 | } 54 | 55 | 56 | func MakePutCall(urlToPost string, body OperationBody, headers map[string]string) (error, *http.Response) { 57 | log.Printf("In MakePostCall to %s with body %s",urlToPost,body) 58 | tr := &http.Transport{ 59 | MaxIdleConns: 10, 60 | IdleConnTimeout: 30 * time.Second, 61 | DisableCompression: true, 62 | } 63 | 64 | var buffer bytes.Buffer 65 | if body != nil{ 66 | encoder := json.NewEncoder(&buffer) 67 | //encoder.SetIndent(" ", "\t") 68 | err := encoder.Encode(body) 69 | if err != nil { 70 | log.Print("error while encoding "+err.Error()) 71 | } 72 | log.Printf("Prepared Request body %+v",buffer.String()) 73 | } 74 | 75 | client := &http.Client{Transport: tr} 76 | req, err := http.NewRequest(http.MethodPut, urlToPost, &buffer) 77 | if err != nil { 78 | log.Print("Error while creating the http request " + err.Error()) 79 | return errors.New("Error while creating http request " + err.Error()), nil 80 | } 81 | 82 | req.Header.Add("Content-Type", "application/json") 83 | for key, value := range headers { 84 | req.Header.Add(key, value) 85 | } 86 | 87 | resp, err := client.Do(req) 88 | if err != nil { 89 | log.Print("Error while making PUT call " + err.Error()) 90 | return errors.New("Error while making PUT call " + err.Error()), nil 91 | } 92 | log.Print("Successfull POST call with HTTP Status : " + resp.Status) 93 | 94 | return nil, resp 95 | } -------------------------------------------------------------------------------- /centralized-swagger-docs/employee-application/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.satish 7 | employee-application 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | employee-application 12 | Eureka server 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 2.0.5.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | Finchley.SR1 26 | 2.9.2 27 | 28 | 29 | 30 | 31 | org.springframework.boot 32 | spring-boot-starter-data-jpa 33 | 34 | 35 | org.springframework.boot 36 | spring-boot-starter-web 37 | 38 | 39 | org.springframework.cloud 40 | spring-cloud-starter-netflix-eureka-client 41 | 42 | 43 | 44 | io.springfox 45 | springfox-swagger2 46 | ${springfox.swagger.version} 47 | 48 | 49 | io.springfox 50 | springfox-swagger-ui 51 | ${springfox.swagger.version} 52 | 53 | 54 | 55 | com.h2database 56 | h2 57 | runtime 58 | 59 | 60 | org.projectlombok 61 | lombok 62 | true 63 | 64 | 65 | org.springframework.boot 66 | spring-boot-starter-test 67 | test 68 | 69 | 70 | 71 | 72 | 73 | 74 | org.springframework.cloud 75 | spring-cloud-dependencies 76 | ${spring-cloud.version} 77 | pom 78 | import 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | org.springframework.boot 87 | spring-boot-maven-plugin 88 | 89 | 90 | 91 | 92 | 93 | 94 | -------------------------------------------------------------------------------- /centralized-swagger-docs/person-application/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.satish 7 | person-application 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | person-application 12 | REST application for person 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 2.0.5.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | Finchley.SR1 26 | 2.9.2 27 | 28 | 29 | 30 | 31 | org.springframework.boot 32 | spring-boot-starter-data-jpa 33 | 34 | 35 | org.springframework.boot 36 | spring-boot-starter-web 37 | 38 | 39 | org.springframework.cloud 40 | spring-cloud-starter-netflix-eureka-client 41 | 42 | 43 | 44 | io.springfox 45 | springfox-swagger2 46 | ${springfox.swagger.version} 47 | 48 | 49 | io.springfox 50 | springfox-swagger-ui 51 | ${springfox.swagger.version} 52 | 53 | 54 | 55 | com.h2database 56 | h2 57 | runtime 58 | 59 | 60 | org.projectlombok 61 | lombok 62 | true 63 | 64 | 65 | 66 | org.springframework.boot 67 | spring-boot-starter-test 68 | test 69 | 70 | 71 | 72 | 73 | 74 | 75 | org.springframework.cloud 76 | spring-cloud-dependencies 77 | ${spring-cloud.version} 78 | pom 79 | import 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | org.springframework.boot 88 | spring-boot-maven-plugin 89 | 90 | 91 | 92 | 93 | 94 | 95 | -------------------------------------------------------------------------------- /micro-frameworks/javalin-app/src/main/java/org/sk/demo/crud/app/PersonApp.java: -------------------------------------------------------------------------------- 1 | package org.sk.demo.crud.app; 2 | 3 | import org.sk.demo.crud.app.db.InMemoryDatabase; 4 | import org.sk.demo.crud.app.model.Person; 5 | 6 | import com.fasterxml.jackson.databind.ObjectMapper; 7 | 8 | import io.javalin.Javalin; 9 | import io.javalin.core.validation.JavalinValidation; 10 | /** 11 | * 12 | * @author satish sharma 13 | * 14 | * REST interface offering CRUD opeartion on {@link Person} object. 15 | * 16 | * The purpose of this application is to demonstrate a CRUD operation. 17 | * So we are not implmenting some of the features that you will consider while writing code for production. 18 | * some of which are as follows 19 | *
    20 | *
  1. We are not adding any validation. This can be implemented using Validator
  2. 21 | *
  3. No adding error handlers. Which can be done using {@link JavalinValidation#validate()}
  4. 22 | *
  5. Each of the method could be packaged as separate handler and then can be used as reference
  6. 23 | *
  7. Some other points that are supported by Javalin and you may consider
  8. 24 | *