├── .gitignore ├── LICENSE ├── README.md ├── basics ├── pom.xml └── spring-conditional-demo │ ├── pom.xml │ └── src │ ├── main │ └── java │ │ └── com │ │ └── sivalabs │ │ └── demo │ │ ├── AppConfig.java │ │ ├── DatabaseType.java │ │ ├── DatabaseTypeCondition.java │ │ ├── JdbcUserDAO.java │ │ ├── MongoDBDatabaseTypeCondition.java │ │ ├── MongoDbTypePropertyCondition.java │ │ ├── MongoDriverNotPresentsCondition.java │ │ ├── MongoDriverPresentsCondition.java │ │ ├── MongoUserDAO.java │ │ ├── MySQLDatabaseTypeCondition.java │ │ ├── UserDAO.java │ │ └── UserDAOBeanNotPresentsCondition.java │ └── test │ └── java │ └── com │ └── sivalabs │ └── demo │ └── ConditionalTest.java ├── database ├── pom.xml ├── springboot-jdbc-demo │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── sivalabs │ │ │ │ └── demo │ │ │ │ ├── SpringbootJdbcDemoApplication.java │ │ │ │ ├── User.java │ │ │ │ └── UserRepository.java │ │ └── resources │ │ │ ├── application-prod.properties │ │ │ ├── application.properties │ │ │ ├── data.sql │ │ │ └── schema.sql │ │ └── test │ │ └── java │ │ └── com │ │ └── sivalabs │ │ └── demo │ │ └── SpringbootJdbcDemoApplicationTests.java ├── springboot-jooq-demo │ ├── gensrc │ │ └── main │ │ │ └── java │ │ │ └── com │ │ │ └── sivalabs │ │ │ └── demo │ │ │ └── jooq │ │ │ └── domain │ │ │ ├── Keys.java │ │ │ ├── Public.java │ │ │ ├── Sequences.java │ │ │ ├── Tables.java │ │ │ └── tables │ │ │ ├── Comments.java │ │ │ ├── Posts.java │ │ │ └── records │ │ │ ├── CommentsRecord.java │ │ │ └── PostsRecord.java │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── sivalabs │ │ │ │ └── demo │ │ │ │ ├── BlogService.java │ │ │ │ ├── SpringbootJooqDemoApplication.java │ │ │ │ └── entities │ │ │ │ ├── Comment.java │ │ │ │ └── Post.java │ │ └── resources │ │ │ ├── application-prod.properties │ │ │ ├── application.properties │ │ │ ├── data.sql │ │ │ ├── reset.sql │ │ │ └── schema.sql │ │ └── test │ │ └── java │ │ └── com │ │ └── sivalabs │ │ └── demo │ │ └── SpringbootJooqDemoApplicationTests.java └── springboot-mybatis-demo │ ├── pom.xml │ └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── sivalabs │ │ │ └── demo │ │ │ ├── SpringbootMyBatisDemoApplication.java │ │ │ ├── domain │ │ │ └── User.java │ │ │ └── mappers │ │ │ ├── UserAnnotationMapper.java │ │ │ └── UserMapper.java │ └── resources │ │ ├── application-prod.properties │ │ ├── application.properties │ │ ├── com │ │ └── sivalabs │ │ │ └── demo │ │ │ └── mappers │ │ │ └── UserMapper.xml │ │ ├── data.sql │ │ └── schema.sql │ └── test │ └── java │ └── com │ └── sivalabs │ └── demo │ └── SpringbootMyBatisDemoApplicationTests.java ├── integration └── spring-boot-integration-demo │ ├── .gitignore │ ├── .mvn │ └── wrapper │ │ ├── MavenWrapperDownloader.java │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties │ ├── mvnw │ ├── mvnw.cmd │ ├── pom.xml │ └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── sivalabs │ │ │ └── sbidemo │ │ │ ├── IntegrationConfig.java │ │ │ ├── Order.java │ │ │ ├── OrderGenerator.java │ │ │ ├── OrderRepository.java │ │ │ ├── OrdersProcessingFlowConfig.java │ │ │ └── SpringBootIntegrationDemoApplication.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── com │ └── sivalabs │ └── sbidemo │ └── SpringBootIntegrationDemoApplicationTests.java ├── nosql ├── pom.xml ├── spring-boot-mongodb-demo │ ├── .gitignore │ ├── .mvn │ │ └── wrapper │ │ │ ├── MavenWrapperDownloader.java │ │ │ ├── maven-wrapper.jar │ │ │ └── maven-wrapper.properties │ ├── docker-compose.yml │ ├── logs │ │ └── myapp.log │ ├── mvnw │ ├── mvnw.cmd │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── sivalabs │ │ │ │ └── springmongodbdemo │ │ │ │ ├── SpringMongodbDemoApplication.java │ │ │ │ ├── config │ │ │ │ ├── ApplicationProperties.java │ │ │ │ ├── MongoConfig.java │ │ │ │ ├── SpringSecurityAuditorAware.java │ │ │ │ └── WebSecurityConfig.java │ │ │ │ ├── documents │ │ │ │ ├── Address.java │ │ │ │ └── Person.java │ │ │ │ ├── models │ │ │ │ └── GithubUser.java │ │ │ │ ├── repositories │ │ │ │ └── PersonRepository.java │ │ │ │ ├── services │ │ │ │ ├── GithubService.java │ │ │ │ └── PersonService.java │ │ │ │ └── web │ │ │ │ └── controllers │ │ │ │ └── PersonController.java │ │ └── resources │ │ │ ├── application.properties │ │ │ ├── logback-spring.xml │ │ │ └── people-sample.json │ │ └── test │ │ └── java │ │ └── com │ │ └── sivalabs │ │ └── springmongodbdemo │ │ ├── SpringMongodbDemoApplicationTests.java │ │ ├── common │ │ ├── BaseIntegrationTest.java │ │ ├── BaseMongoDBTest.java │ │ ├── MockServerContainerInitializer.java │ │ └── MongoDBContainerInitializer.java │ │ ├── repositories │ │ ├── MongoPersonRepositoryTest.java │ │ └── PersonRepositoryTest.java │ │ └── web │ │ └── controllers │ │ ├── PersonControllerIT.java │ │ └── PersonControllerTest.java └── spring-boot-redis-demo │ ├── .gitignore │ ├── .mvn │ └── wrapper │ │ ├── MavenWrapperDownloader.java │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties │ ├── docker-compose.yml │ ├── mvnw │ ├── mvnw.cmd │ ├── pom.xml │ └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── sivalabs │ │ │ └── bootredisdemo │ │ │ ├── Initializer.java │ │ │ ├── RedisRestController.java │ │ │ ├── RedisService.java │ │ │ └── SpringBootRedisDemoApplication.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── com │ └── sivalabs │ └── bootredisdemo │ └── SpringBootRedisDemoApplicationTests.java ├── pom.xml ├── search ├── pom.xml └── springboot-solr-demo │ ├── pom.xml │ └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── sivalabs │ │ │ └── demo │ │ │ ├── HomeController.java │ │ │ ├── Product.java │ │ │ ├── ProductRepository.java │ │ │ └── SpringBootSolrApplication.java │ └── resources │ │ ├── application.properties │ │ ├── demo │ │ └── solr │ │ │ ├── core1 │ │ │ ├── conf │ │ │ │ ├── lang │ │ │ │ │ └── stopwords_en.txt │ │ │ │ ├── protwords.txt │ │ │ │ ├── schema.xml │ │ │ │ ├── solrconfig.xml │ │ │ │ ├── stopwords.txt │ │ │ │ └── synonyms.txt │ │ │ └── core.properties │ │ │ └── solr.xml │ │ └── templates │ │ └── index.html │ └── test │ └── java │ └── com │ └── sivalabs │ └── demo │ └── SpringBootSolrApplicationTests.java ├── security ├── custom-security-expressions │ ├── .gitignore │ ├── .mvn │ │ └── wrapper │ │ │ ├── MavenWrapperDownloader.java │ │ │ ├── maven-wrapper.jar │ │ │ └── maven-wrapper.properties │ ├── mvnw │ ├── mvnw.cmd │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── sivalabs │ │ │ │ └── demo │ │ │ │ ├── AppConfig.java │ │ │ │ ├── BootCustomSecurityExpressionsApplication.java │ │ │ │ ├── MyUserDetailsService.java │ │ │ │ ├── MyUserPrincipal.java │ │ │ │ ├── WebSecurityConfig.java │ │ │ │ ├── controller │ │ │ │ └── DemoController.java │ │ │ │ ├── entities │ │ │ │ ├── Privilege.java │ │ │ │ ├── Role.java │ │ │ │ └── User.java │ │ │ │ ├── repo │ │ │ │ ├── PrivilegeRepository.java │ │ │ │ ├── RoleRepository.java │ │ │ │ └── UserRepository.java │ │ │ │ └── security │ │ │ │ ├── CustomMethodSecurityExpressionHandler.java │ │ │ │ ├── CustomMethodSecurityExpressionRoot.java │ │ │ │ ├── CustomPermissionEvaluator.java │ │ │ │ └── MethodSecurityConfig.java │ │ └── resources │ │ │ ├── application.properties │ │ │ └── data.sql │ │ └── test │ │ └── java │ │ └── com │ │ └── sivalabs │ │ └── demo │ │ └── BootCustomSecurityExpressionsApplicationTests.java ├── pom.xml ├── spring-boot-okta-demo │ ├── .gitignore │ ├── .mvn │ │ └── wrapper │ │ │ ├── maven-wrapper.jar │ │ │ └── maven-wrapper.properties │ ├── mvnw │ ├── mvnw.cmd │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── sivalabs │ │ │ │ └── oktademo │ │ │ │ ├── HomeController.java │ │ │ │ ├── SecurityConfiguration.java │ │ │ │ └── SpringBootOktaDemoApplication.java │ │ └── resources │ │ │ ├── application.properties │ │ │ └── templates │ │ │ ├── footer.html │ │ │ ├── head.html │ │ │ ├── home.html │ │ │ ├── menu.html │ │ │ └── userProfile.html │ │ └── test │ │ └── java │ │ └── com │ │ └── sivalabs │ │ └── oktademo │ │ └── SpringBootOktaDemoApplicationTests.java ├── spring-boot-social-login │ ├── .gitignore │ ├── .mvn │ │ └── wrapper │ │ │ ├── MavenWrapperDownloader.java │ │ │ ├── maven-wrapper.jar │ │ │ └── maven-wrapper.properties │ ├── mvnw │ ├── mvnw.cmd │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── sivalabs │ │ │ │ └── bookmarker │ │ │ │ ├── BookmarkerApplication.java │ │ │ │ ├── config │ │ │ │ ├── AppConfig.java │ │ │ │ ├── BookmarkerProperties.java │ │ │ │ ├── WebMvcConfig.java │ │ │ │ └── security │ │ │ │ │ ├── CustomUserDetailsService.java │ │ │ │ │ ├── SecurityUser.java │ │ │ │ │ ├── WebSecurityConfig.java │ │ │ │ │ └── oauth │ │ │ │ │ ├── AuthenticatedPrincipal.java │ │ │ │ │ ├── CustomOidcUserService.java │ │ │ │ │ ├── GithubOAuth2User.java │ │ │ │ │ ├── Oauth2AuthenticationSuccessHandler.java │ │ │ │ │ └── OidcUser.java │ │ │ │ ├── domain │ │ │ │ ├── entity │ │ │ │ │ ├── BaseEntity.java │ │ │ │ │ ├── Bookmark.java │ │ │ │ │ ├── Role.java │ │ │ │ │ ├── User.java │ │ │ │ │ └── UserType.java │ │ │ │ ├── mappers │ │ │ │ │ └── BookmarkMapper.java │ │ │ │ ├── model │ │ │ │ │ ├── BookmarkDTO.java │ │ │ │ │ ├── CreateUserRequest.java │ │ │ │ │ └── UserDTO.java │ │ │ │ ├── repository │ │ │ │ │ ├── BookmarkRepository.java │ │ │ │ │ ├── RoleRepository.java │ │ │ │ │ └── UserRepository.java │ │ │ │ ├── service │ │ │ │ │ ├── BookmarkService.java │ │ │ │ │ ├── SecurityService.java │ │ │ │ │ └── UserService.java │ │ │ │ └── utils │ │ │ │ │ └── Constants.java │ │ │ │ └── web │ │ │ │ └── controller │ │ │ │ ├── BookmarkController.java │ │ │ │ └── UserController.java │ │ └── resources │ │ │ ├── application-docker.properties │ │ │ ├── application-heroku.properties │ │ │ ├── application-local.properties │ │ │ ├── application.properties │ │ │ ├── db │ │ │ └── migration │ │ │ │ ├── h2 │ │ │ │ ├── V1__create_tables.sql │ │ │ │ └── V2__insert_sample_data.sql │ │ │ │ └── postgresql │ │ │ │ ├── V1__create_tables.sql │ │ │ │ └── V2__insert_sample_data.sql │ │ │ ├── static │ │ │ ├── bootswatch │ │ │ │ ├── cosmo │ │ │ │ │ ├── bootstrap.css │ │ │ │ │ └── bootstrap.min.css │ │ │ │ ├── litera │ │ │ │ │ ├── bootstrap.css │ │ │ │ │ └── bootstrap.min.css │ │ │ │ └── yeti │ │ │ │ │ ├── bootstrap.css │ │ │ │ │ └── bootstrap.min.css │ │ │ ├── css │ │ │ │ └── styles.css │ │ │ ├── favicon.ico │ │ │ └── js │ │ │ │ ├── app.js │ │ │ │ └── common.js │ │ │ └── templates │ │ │ ├── add-bookmark.html │ │ │ ├── error.html │ │ │ ├── home.html │ │ │ ├── login.html │ │ │ └── mainLayout.html │ │ └── test │ │ ├── java │ │ └── com │ │ │ └── sivalabs │ │ │ └── bookmarker │ │ │ └── web │ │ │ └── controller │ │ │ └── BookmarkControllerIT.java │ │ └── resources │ │ ├── application-integration-test.properties │ │ ├── bootstrap-integration-test.properties │ │ ├── bootstrap.properties │ │ └── data │ │ └── tags.csv ├── spring-security-multi-config │ ├── .gitignore │ ├── .mvn │ │ └── wrapper │ │ │ ├── MavenWrapperDownloader.java │ │ │ ├── maven-wrapper.jar │ │ │ └── maven-wrapper.properties │ ├── .travis.yml │ ├── Dockerfile │ ├── Jenkinsfile │ ├── README.md │ ├── docker-compose.yml │ ├── mvnw │ ├── mvnw.cmd │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── sivalabs │ │ │ │ └── todolist │ │ │ │ ├── TodoListApplication.java │ │ │ │ ├── config │ │ │ │ ├── SecurityConfig.java │ │ │ │ └── security │ │ │ │ │ └── HttpStatusReturningLoginSuccessHandler.java │ │ │ │ ├── entity │ │ │ │ ├── Role.java │ │ │ │ ├── Todo.java │ │ │ │ └── User.java │ │ │ │ ├── repo │ │ │ │ ├── TodoRepository.java │ │ │ │ └── UserRepository.java │ │ │ │ ├── service │ │ │ │ └── SecurityUserDetailsService.java │ │ │ │ └── web │ │ │ │ └── controller │ │ │ │ ├── HomeController.java │ │ │ │ └── TodoRestController.java │ │ └── resources │ │ │ ├── application-docker.properties │ │ │ ├── application-heroku.properties │ │ │ ├── application-local.properties │ │ │ ├── application.properties │ │ │ ├── db │ │ │ └── migration │ │ │ │ ├── h2 │ │ │ │ ├── V1__create_tables.sql │ │ │ │ └── V2__insert_sample_data.sql │ │ │ │ └── postgresql │ │ │ │ ├── V1__create_tables.sql │ │ │ │ └── V2__insert_sample_data.sql │ │ │ ├── static │ │ │ ├── css │ │ │ │ └── styles.css │ │ │ └── js │ │ │ │ └── app.js │ │ │ └── templates │ │ │ ├── home.html │ │ │ ├── login.html │ │ │ └── mainLayout.html │ │ └── test │ │ └── java │ │ └── com │ │ └── sivalabs │ │ └── todolist │ │ ├── AbstractIntegrationTest.java │ │ ├── TodoListApplicationTests.java │ │ └── utils │ │ └── BCryptUtil.java └── spring-security-oauth2-demo │ ├── README.md │ ├── auth-server │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── sivalabs │ │ │ │ └── authserver │ │ │ │ ├── OAuth2ServerApplication.java │ │ │ │ ├── UserController.java │ │ │ │ ├── config │ │ │ │ ├── JwtTokenEnhancer.java │ │ │ │ ├── JwtTokenStoreConfig.java │ │ │ │ ├── OAuth2AuthorizationServerConfig.java │ │ │ │ ├── WebMvcConfig.java │ │ │ │ └── WebSecurityConfig.java │ │ │ │ ├── entity │ │ │ │ └── UserAccount.java │ │ │ │ ├── repository │ │ │ │ └── UserRepository.java │ │ │ │ └── service │ │ │ │ └── SecurityUserDetailsService.java │ │ └── resources │ │ │ ├── application.properties │ │ │ ├── data.sql │ │ │ ├── schema.sql │ │ │ └── templates │ │ │ └── login.html │ │ └── test │ │ └── java │ │ └── com │ │ └── sivalabs │ │ └── authserver │ │ ├── OAuth2ServerApplicationTests.java │ │ └── Utils.java │ ├── catalog-service │ ├── .gitignore │ ├── .mvn │ │ └── wrapper │ │ │ ├── maven-wrapper.jar │ │ │ └── maven-wrapper.properties │ ├── mvnw │ ├── mvnw.cmd │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── sivalabs │ │ │ │ └── catalogservice │ │ │ │ ├── CatalogController.java │ │ │ │ ├── CatalogServiceApplication.java │ │ │ │ ├── JwtTokenStoreConfig.java │ │ │ │ ├── OAuthResourceServerConfig.java │ │ │ │ ├── Product.java │ │ │ │ ├── ProductDTO.java │ │ │ │ └── PromotionServiceClient.java │ │ └── resources │ │ │ └── application.properties │ │ └── test │ │ └── java │ │ └── com │ │ └── sivalabs │ │ └── catalogservice │ │ └── CatalogServiceApplicationTests.java │ ├── pom.xml │ ├── promotion-service │ ├── .gitignore │ ├── .mvn │ │ └── wrapper │ │ │ ├── maven-wrapper.jar │ │ │ └── maven-wrapper.properties │ ├── mvnw │ ├── mvnw.cmd │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── sivalabs │ │ │ │ └── promotionservice │ │ │ │ ├── JwtTokenStoreConfig.java │ │ │ │ ├── OAuthResourceServerConfig.java │ │ │ │ ├── Promotion.java │ │ │ │ ├── PromotionController.java │ │ │ │ └── PromotionServiceApplication.java │ │ └── resources │ │ │ └── application.properties │ │ └── test │ │ └── java │ │ └── com │ │ └── sivalabs │ │ └── promotionservice │ │ └── PromotionServiceApplicationTests.java │ └── ui-zuul-app │ ├── .gitignore │ ├── .mvn │ └── wrapper │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties │ ├── mvnw │ ├── mvnw.cmd │ ├── pom.xml │ └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── sivalabs │ │ │ └── uizuulapp │ │ │ ├── HomeController.java │ │ │ └── UiZuulAppApplication.java │ └── resources │ │ ├── application.properties │ │ ├── public │ │ ├── app.js │ │ ├── index.vue.html │ │ ├── jquery.min.js │ │ └── vue.min.js │ │ └── templates │ │ └── index.html │ └── test │ └── java │ └── com │ └── sivalabs │ └── uizuulapp │ └── UiZuulAppApplicationTests.java ├── spring-boot-aws-demo ├── .gitignore ├── .mvn │ └── wrapper │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties ├── Dockerfile ├── Jenkinsfile ├── README.md ├── docker-compose.yml ├── mvnw ├── mvnw.cmd ├── pom.xml ├── run.sh └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── sivalabs │ │ │ └── myapp │ │ │ ├── SpringBootAwsDemoApplication.java │ │ │ ├── config │ │ │ └── LocalStackConfig.java │ │ │ ├── entity │ │ │ └── Message.java │ │ │ ├── repo │ │ │ └── MessageRepository.java │ │ │ ├── service │ │ │ ├── KinesisStreamService.java │ │ │ ├── S3Service.java │ │ │ ├── SQSService.java │ │ │ ├── TweetProducer.java │ │ │ ├── TweetRecordProcessor.java │ │ │ ├── TweetRecordProcessorFactory.java │ │ │ ├── TweetStreamListener.java │ │ │ └── TweetStreamWorker.java │ │ │ └── web │ │ │ └── controller │ │ │ └── MessageController.java │ └── resources │ │ ├── application-docker.properties │ │ ├── application.properties │ │ ├── static │ │ └── css │ │ │ └── styles.css │ │ └── templates │ │ └── index.html │ └── test │ ├── java │ └── com │ │ └── sivalabs │ │ └── myapp │ │ ├── AbstractIntegrationTest.java │ │ ├── AmazonKinesisConsumerApplicationSample.java │ │ ├── DynamoDBSample.java │ │ ├── SpringBootAwsDemoApplicationTests.java │ │ └── service │ │ ├── KinesisStreamServiceIT.java │ │ ├── S3ServiceIT.java │ │ └── SQSServiceIT.java │ └── resources │ └── moviedata.json ├── spring-boot-grpc-demo ├── .gitignore ├── grpc-interfaces │ ├── pom.xml │ └── src │ │ └── main │ │ └── proto │ │ └── helloworld.proto ├── pom.xml ├── spring-boot-grpc-client │ ├── .gitignore │ ├── .mvn │ │ └── wrapper │ │ │ ├── MavenWrapperDownloader.java │ │ │ ├── maven-wrapper.jar │ │ │ └── maven-wrapper.properties │ ├── mvnw │ ├── mvnw.cmd │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── sivalabs │ │ │ └── grpcclient │ │ │ ├── GrpcClientController.java │ │ │ ├── GrpcClientService.java │ │ │ └── SpringBootGrpcClientApplication.java │ │ └── resources │ │ └── application.yml └── spring-boot-grpc-server │ ├── .gitignore │ ├── .mvn │ └── wrapper │ │ ├── MavenWrapperDownloader.java │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties │ ├── mvnw │ ├── mvnw.cmd │ ├── pom.xml │ └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── sivalabs │ │ │ └── grpcserver │ │ │ ├── HelloServiceImpl.java │ │ │ └── SpringBootGrpcServerApplication.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── com │ └── sivalabs │ └── grpcserver │ └── SpringBootGrpcServerApplicationTests.java ├── spring-boot-k8s-demo ├── .gitignore ├── .mvn │ └── wrapper │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties ├── .travis.yml ├── Dockerfile ├── Jenkinsfile ├── Procfile ├── README.md ├── docker-compose-platform.yml ├── docker-compose.yml ├── docs │ └── images │ │ ├── App-metrics-grafana.png │ │ └── JVM-Micrometer-grafana.png ├── gc.sh ├── gcp.sh ├── k8s │ ├── app-mysql.yml │ ├── app-postgres.yml │ ├── config.yml │ ├── mysql.yml │ └── postgres.yml ├── manifest.yml ├── mvnw ├── mvnw.cmd ├── pom.xml ├── src │ ├── integration-test │ │ ├── kotlin │ │ │ └── com │ │ │ │ └── sivalabs │ │ │ │ └── geeksclub │ │ │ │ ├── MockitoHelpers.kt │ │ │ │ ├── techfeed │ │ │ │ └── TechFeedControllerIT.kt │ │ │ │ └── users │ │ │ │ └── UserControllerIT.kt │ │ └── resources │ │ │ └── application-it.properties │ ├── main │ │ ├── kotlin │ │ │ └── com │ │ │ │ └── sivalabs │ │ │ │ └── geeksclub │ │ │ │ ├── GeeksClubApplication.kt │ │ │ │ ├── config │ │ │ │ ├── CloudFoundryConfig.kt │ │ │ │ ├── SpringApplicationContextInitializer.kt │ │ │ │ └── WebMvcConfig.kt │ │ │ │ ├── entities │ │ │ │ ├── Category.kt │ │ │ │ ├── Link.kt │ │ │ │ ├── Tag.kt │ │ │ │ └── User.kt │ │ │ │ ├── security │ │ │ │ ├── SecurityUser.kt │ │ │ │ ├── SecurityUserDetailsService.kt │ │ │ │ ├── SecurityUtils.kt │ │ │ │ └── WebSecurityConfig.kt │ │ │ │ ├── techfeed │ │ │ │ ├── CategoryRepository.kt │ │ │ │ ├── LinkDTO.kt │ │ │ │ ├── LinkRepository.kt │ │ │ │ ├── NewLinkDTO.kt │ │ │ │ ├── TagRepository.kt │ │ │ │ ├── TechFeedController.kt │ │ │ │ └── TechFeedService.kt │ │ │ │ └── users │ │ │ │ ├── UserController.kt │ │ │ │ ├── UserProfile.kt │ │ │ │ ├── UserRepository.kt │ │ │ │ └── UserService.kt │ │ └── resources │ │ │ ├── application.yml │ │ │ ├── data.sql │ │ │ ├── static │ │ │ ├── images │ │ │ │ ├── user.jpg │ │ │ │ └── user.png │ │ │ └── styles.css │ │ │ └── templates │ │ │ ├── category.html │ │ │ ├── index.html │ │ │ ├── layout.html │ │ │ ├── login.html │ │ │ ├── newlink.html │ │ │ ├── registration.html │ │ │ ├── registration_status.html │ │ │ └── userprofile.html │ └── test │ │ ├── kotlin │ │ └── com │ │ │ └── sivalabs │ │ │ └── geeksclub │ │ │ ├── RssReader.kt │ │ │ └── SampleTest.kt │ │ └── resources │ │ └── application-test.properties └── support │ ├── jvm-micrometer_rev2.json │ ├── micrometer-spring-throughput_rev2.json │ └── prometheus.yml ├── spring-boot-quartz-demo ├── .gitignore ├── .mvn │ └── wrapper │ │ ├── MavenWrapperDownloader.java │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties ├── mvnw ├── mvnw.cmd ├── nohup.out ├── pom.xml ├── run.sh └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── example │ │ │ └── demo │ │ │ ├── DemoApplication.java │ │ │ ├── Person.java │ │ │ ├── PersonRepo.java │ │ │ └── SampleJob.java │ └── resources │ │ ├── application.properties │ │ └── quartz.properties.bak │ └── test │ └── java │ └── com │ └── example │ └── demo │ └── DemoApplicationTests.java ├── spring-cloud ├── README.md ├── catalog-service │ ├── .gitignore │ ├── .mvn │ │ └── wrapper │ │ │ ├── maven-wrapper.jar │ │ │ └── maven-wrapper.properties │ ├── mvnw │ ├── mvnw.cmd │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── sivalabs │ │ │ │ └── catalogservice │ │ │ │ ├── CatalogServiceApplication.java │ │ │ │ └── HomeController.java │ │ └── resources │ │ │ └── bootstrap.properties │ │ └── test │ │ └── java │ │ └── com │ │ └── sivalabs │ │ └── catalogservice │ │ └── CatalogServiceApplicationTests.java ├── docker-compose.yml ├── order-service │ ├── .gitignore │ ├── .mvn │ │ └── wrapper │ │ │ ├── maven-wrapper.jar │ │ │ └── maven-wrapper.properties │ ├── mvnw │ ├── mvnw.cmd │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── sivalabs │ │ │ │ └── orderservice │ │ │ │ └── OrderServiceApplication.java │ │ └── resources │ │ │ └── bootstrap.properties │ │ └── test │ │ └── java │ │ └── com │ │ └── sivalabs │ │ └── orderservice │ │ └── OrderServiceApplicationTests.java ├── pom.xml └── spring-cloud-config-server │ ├── .mvn │ └── wrapper │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties │ ├── build.gradle │ ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ ├── mvnw │ ├── mvnw.cmd │ ├── pom.xml │ └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── sivalabs │ │ │ └── configserver │ │ │ └── ConfigServerApplication.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── com │ └── sivalabs │ └── configserver │ └── ConfigServerApplicationTests.java ├── spring-session ├── README.md ├── pom.xml ├── springboot-spring-session-jdbc-demo │ ├── .gitignore │ ├── .mvn │ │ └── wrapper │ │ │ ├── maven-wrapper.jar │ │ │ └── maven-wrapper.properties │ ├── Dockerfile │ ├── docker-compose.yml │ ├── mvnw │ ├── mvnw.cmd │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── in │ │ │ │ └── sivalabs │ │ │ │ └── ssdemo │ │ │ │ ├── MessagesController.java │ │ │ │ ├── SecurityConfig.java │ │ │ │ └── SpringSessionJdbcDemoApplication.java │ │ └── resources │ │ │ ├── application-docker.properties │ │ │ ├── application.properties │ │ │ └── templates │ │ │ └── index.html │ │ └── test │ │ └── java │ │ └── in │ │ └── sivalabs │ │ └── ssdemo │ │ └── SpringSessionJdbcDemoApplicationTests.java └── springboot-spring-session-redis-demo │ ├── .gitignore │ ├── .mvn │ └── wrapper │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties │ ├── Dockerfile │ ├── docker-compose.yml │ ├── mvnw │ ├── mvnw.cmd │ ├── pom.xml │ └── src │ ├── main │ ├── java │ │ └── in │ │ │ └── sivalabs │ │ │ └── ssdemo │ │ │ ├── MessagesController.java │ │ │ ├── SecurityConfig.java │ │ │ └── SpringSessionRedisDemoApplication.java │ └── resources │ │ ├── application-docker.properties │ │ ├── application.properties │ │ └── templates │ │ └── index.html │ └── test │ └── java │ └── in │ └── sivalabs │ └── ssdemo │ └── SpringSessionRedisDemoApplicationTests.java ├── testing ├── pom.xml └── springboot-testing-demo │ ├── .gitignore │ ├── .mvn │ └── wrapper │ │ ├── MavenWrapperDownloader.java │ │ └── maven-wrapper.properties │ ├── README.md │ ├── mvnw │ ├── mvnw.cmd │ ├── pom.xml │ └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── sivalabs │ │ │ └── myservice │ │ │ ├── Application.java │ │ │ ├── config │ │ │ ├── ApplicationProperties.java │ │ │ └── WebMvcConfig.java │ │ │ ├── entities │ │ │ └── User.java │ │ │ ├── exception │ │ │ └── UserRegistrationException.java │ │ │ ├── model │ │ │ └── GithubUser.java │ │ │ ├── repositories │ │ │ └── UserRepository.java │ │ │ ├── services │ │ │ ├── GithubService.java │ │ │ └── UserService.java │ │ │ └── web │ │ │ └── controllers │ │ │ ├── GithubController.java │ │ │ └── UserController.java │ └── resources │ │ ├── application-test.properties │ │ ├── application.properties │ │ └── db │ │ └── migration │ │ ├── h2 │ │ └── V1__01_init.sql │ │ └── postgresql │ │ └── V1__01_init.sql │ └── test │ └── java │ └── com │ └── sivalabs │ └── myservice │ ├── ApplicationTests.java │ ├── common │ ├── AbstractIntegrationTest.java │ ├── ExceptionHandling.java │ └── PostgreSQLContainerInitializer.java │ ├── repositories │ └── UserRepositoryTest.java │ ├── services │ ├── UserServiceAnnotatedTest.java │ └── UserServiceTest.java │ └── web │ └── controllers │ ├── GithubControllerIT.java │ ├── UserControllerIT.java │ └── UserControllerTest.java └── web ├── pom.xml ├── spring-data-rest-demo ├── .gitignore ├── .gitlab-ci.yml ├── .mvn │ └── wrapper │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties ├── .travis.yml ├── Dockerfile ├── Jenkinsfile ├── LICENSE ├── README.md ├── config │ ├── jvm-micrometer_rev2.json │ ├── logstash.conf │ ├── micrometer-spring-throughput_rev2.json │ └── prometheus.yml ├── docker-compose.yml ├── mvnw ├── mvnw.cmd ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── sivalabs │ │ │ └── ebuddy │ │ │ ├── EbuddyApiApplication.java │ │ │ ├── config │ │ │ ├── AppConfiguration.java │ │ │ ├── SpringDataRestConfig.java │ │ │ ├── SwaggerConfig.java │ │ │ ├── TimeProvider.java │ │ │ ├── WebMvcConfig.java │ │ │ └── WebSecurityConfig.java │ │ │ ├── entity │ │ │ ├── BaseEntity.java │ │ │ ├── Bookmark.java │ │ │ ├── Note.java │ │ │ ├── Role.java │ │ │ ├── Todo.java │ │ │ ├── Transaction.java │ │ │ └── User.java │ │ │ ├── model │ │ │ ├── AuthenticationRequest.java │ │ │ ├── AuthenticationResponse.java │ │ │ ├── ChangePassword.java │ │ │ └── ErrorMessage.java │ │ │ ├── repo │ │ │ ├── BookmarkRepository.java │ │ │ ├── EntityEventHandler.java │ │ │ ├── NoteRepository.java │ │ │ ├── TodoRepository.java │ │ │ ├── TransactionRepository.java │ │ │ └── UserRepository.java │ │ │ ├── security │ │ │ ├── CustomUserDetailsService.java │ │ │ ├── SecurityUser.java │ │ │ ├── SecurityUtils.java │ │ │ ├── TokenHelper.java │ │ │ └── auth │ │ │ │ ├── RestAuthenticationEntryPoint.java │ │ │ │ ├── TokenAuthenticationFilter.java │ │ │ │ └── TokenBasedAuthentication.java │ │ │ └── web │ │ │ ├── GlobalExceptionHandler.java │ │ │ └── controller │ │ │ └── AuthenticationController.java │ └── resources │ │ ├── application-docker.properties │ │ ├── application-local.properties │ │ ├── application.properties │ │ ├── db │ │ └── migration │ │ │ ├── h2 │ │ │ ├── V1__create_tables.sql │ │ │ └── V2__insert_sample_data.sql │ │ │ └── postgresql │ │ │ ├── V1__create_tables.sql │ │ │ └── V2__insert_sample_data.sql │ │ └── logback-spring.xml │ └── test │ └── java │ └── com │ └── sivalabs │ └── ebuddy │ ├── security │ └── TokenHelperTest.java │ ├── utils │ └── TestHelper.java │ └── web │ └── controller │ ├── AuthenticationControllerIT.java │ ├── BaseIntegrationTest.java │ ├── BookmarkControllerIT.java │ └── UserControllerIT.java ├── springboot-rest-api-design ├── .gitignore ├── README.md ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── sivalabs │ │ │ └── blog │ │ │ ├── BlogApplication.java │ │ │ ├── config │ │ │ ├── SwaggerConfig.java │ │ │ ├── WebMvcConfig.java │ │ │ └── WebSecurityConfig.java │ │ │ ├── entities │ │ │ ├── Comment.java │ │ │ ├── Post.java │ │ │ ├── Role.java │ │ │ └── User.java │ │ │ ├── exceptions │ │ │ ├── UnauthorizedAccessException.java │ │ │ └── ValidationFailureException.java │ │ │ ├── model │ │ │ ├── CommentDTO.java │ │ │ ├── EmailEvent.java │ │ │ ├── PostDTO.java │ │ │ ├── RoleDTO.java │ │ │ ├── ServiceResponse.java │ │ │ └── UserDTO.java │ │ │ ├── repositories │ │ │ ├── CommentRepository.java │ │ │ ├── PostRepository.java │ │ │ └── UserRepository.java │ │ │ ├── resources │ │ │ ├── AbstractCollectionResource.java │ │ │ ├── CommentsResource.java │ │ │ ├── PostsResource.java │ │ │ └── UserResource.java │ │ │ ├── security │ │ │ ├── CustomUserDetailsService.java │ │ │ ├── HttpAuthenticationEntryPoint.java │ │ │ ├── SecurityUser.java │ │ │ ├── SecurityUtils.java │ │ │ ├── Token.java │ │ │ ├── TokenProvider.java │ │ │ ├── XAuthConfiguration.java │ │ │ ├── XAuthTokenConfigurer.java │ │ │ └── XAuthTokenFilter.java │ │ │ ├── services │ │ │ ├── BlogService.java │ │ │ ├── EmailService.java │ │ │ └── UserService.java │ │ │ ├── utils │ │ │ └── BeanCopyUtils.java │ │ │ └── web │ │ │ ├── controllers │ │ │ ├── CommentsController.java │ │ │ ├── PostController.java │ │ │ └── UserController.java │ │ │ └── interceptors │ │ │ └── ExceptionControllerAdvice.java │ └── resources │ │ ├── application-dev.properties │ │ ├── application-prod.properties │ │ ├── application.properties │ │ ├── data.sql │ │ ├── logback.xml │ │ ├── messages.properties │ │ └── static │ │ └── swagger-ui │ │ ├── css │ │ ├── print.css │ │ ├── reset.css │ │ ├── screen.css │ │ ├── style.css │ │ └── typography.css │ │ ├── fonts │ │ ├── droid-sans-v6-latin-700.eot │ │ ├── droid-sans-v6-latin-700.svg │ │ ├── droid-sans-v6-latin-700.ttf │ │ ├── droid-sans-v6-latin-700.woff │ │ ├── droid-sans-v6-latin-700.woff2 │ │ ├── droid-sans-v6-latin-regular.eot │ │ ├── droid-sans-v6-latin-regular.svg │ │ ├── droid-sans-v6-latin-regular.ttf │ │ ├── droid-sans-v6-latin-regular.woff │ │ └── droid-sans-v6-latin-regular.woff2 │ │ ├── images │ │ ├── explorer_icons.png │ │ ├── favicon-16x16.png │ │ ├── favicon-32x32.png │ │ ├── favicon.ico │ │ ├── logo_small.png │ │ ├── pet_store_api.png │ │ ├── throbber.gif │ │ └── wordnik_api.png │ │ ├── index.html │ │ ├── lang │ │ ├── en.js │ │ ├── es.js │ │ ├── ja.js │ │ ├── pt.js │ │ ├── ru.js │ │ ├── tr.js │ │ ├── translator.js │ │ └── zh-cn.js │ │ ├── lib │ │ ├── backbone-min.js │ │ ├── handlebars-2.0.0.js │ │ ├── highlight.7.3.pack.js │ │ ├── jquery-1.8.0.min.js │ │ ├── jquery.ba-bbq.min.js │ │ ├── jquery.slideto.min.js │ │ ├── jquery.wiggle.min.js │ │ ├── marked.js │ │ ├── swagger-oauth.js │ │ ├── underscore-min.js │ │ └── underscore-min.map │ │ ├── o2c.html │ │ ├── swagger-ui.js │ │ └── swagger-ui.min.js │ └── test │ └── java │ └── com │ └── sivalabs │ └── blog │ ├── BlogApplicationTests.java │ └── TestUtil.java └── springboot-thymeleaf-demo ├── pom.xml └── src └── main ├── java └── com │ └── sivalabs │ └── demo │ ├── HomeController.java │ └── SpringBootThymeleafApplication.java └── resources └── templates └── index.html /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | .settings 3 | target 4 | .classpath 5 | .project 6 | .tern-project 7 | bin 8 | build 9 | .springBeans 10 | *.iml 11 | .idea 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # springboot-tutorials 2 | SpringBoot Tutorials 3 | -------------------------------------------------------------------------------- /basics/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.sivalabs 7 | spring-boot-basics-tutorial 8 | 1.0.0-SNAPSHOT 9 | pom 10 | 11 | spring-boot-basics-tutorial 12 | 13 | spring-conditional-demo 14 | 15 | 16 | -------------------------------------------------------------------------------- /basics/spring-conditional-demo/src/main/java/com/sivalabs/demo/DatabaseType.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.sivalabs.demo; 5 | 6 | import java.lang.annotation.ElementType; 7 | import java.lang.annotation.Retention; 8 | import java.lang.annotation.RetentionPolicy; 9 | import java.lang.annotation.Target; 10 | 11 | import org.springframework.context.annotation.Conditional; 12 | 13 | /** 14 | * @author Siva 15 | * 16 | */ 17 | @Target({ ElementType.TYPE, ElementType.METHOD }) 18 | @Retention(RetentionPolicy.RUNTIME) 19 | @Conditional(DatabaseTypeCondition.class) 20 | public @interface DatabaseType 21 | { 22 | String value(); 23 | } 24 | -------------------------------------------------------------------------------- /basics/spring-conditional-demo/src/main/java/com/sivalabs/demo/DatabaseTypeCondition.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.sivalabs.demo; 5 | 6 | import java.util.Map; 7 | 8 | import org.springframework.context.annotation.Condition; 9 | import org.springframework.context.annotation.ConditionContext; 10 | import org.springframework.core.type.AnnotatedTypeMetadata; 11 | 12 | /** 13 | * @author Siva 14 | * 15 | */ 16 | public class DatabaseTypeCondition implements Condition 17 | { 18 | public boolean matches(ConditionContext conditionContext, AnnotatedTypeMetadata metadata) 19 | { 20 | Map attributes = metadata.getAnnotationAttributes(DatabaseType.class.getName()); 21 | String type = (String) attributes.get("value"); 22 | String enabledDBType = System.getProperty("dbType","MYSQL"); 23 | return (enabledDBType != null && type != null && enabledDBType.equalsIgnoreCase(type)); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /basics/spring-conditional-demo/src/main/java/com/sivalabs/demo/JdbcUserDAO.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.sivalabs.demo; 5 | 6 | import java.util.Arrays; 7 | import java.util.List; 8 | 9 | /** 10 | * @author Siva 11 | * 12 | */ 13 | public class JdbcUserDAO implements UserDAO 14 | { 15 | 16 | public List getAllUserNames() 17 | { 18 | System.out.println("**** Getting usernames from RDBMS *****"); 19 | return Arrays.asList("Siva","Prasad","Reddy"); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /basics/spring-conditional-demo/src/main/java/com/sivalabs/demo/MongoDBDatabaseTypeCondition.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.sivalabs.demo; 5 | 6 | import org.springframework.context.annotation.Condition; 7 | import org.springframework.context.annotation.ConditionContext; 8 | import org.springframework.core.type.AnnotatedTypeMetadata; 9 | 10 | /** 11 | * @author Siva 12 | * 13 | */ 14 | public class MongoDBDatabaseTypeCondition implements Condition 15 | { 16 | 17 | public boolean matches(ConditionContext conditionContext, AnnotatedTypeMetadata metadata) 18 | { 19 | String enabledDBType = System.getProperty("dbType","MYSQL"); 20 | return (enabledDBType != null && enabledDBType.equalsIgnoreCase("MONGODB")); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /basics/spring-conditional-demo/src/main/java/com/sivalabs/demo/MongoDbTypePropertyCondition.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.sivalabs.demo; 5 | 6 | import org.springframework.context.annotation.Condition; 7 | import org.springframework.context.annotation.ConditionContext; 8 | import org.springframework.core.type.AnnotatedTypeMetadata; 9 | 10 | /** 11 | * @author Siva 12 | * 13 | */ 14 | public class MongoDbTypePropertyCondition implements Condition 15 | { 16 | 17 | public boolean matches(ConditionContext conditionContext, AnnotatedTypeMetadata metadata) 18 | { 19 | String dbType = conditionContext.getEnvironment().getProperty("app.dbType"); 20 | return "MONGO".equalsIgnoreCase(dbType); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /basics/spring-conditional-demo/src/main/java/com/sivalabs/demo/MongoDriverNotPresentsCondition.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.sivalabs.demo; 5 | 6 | import org.springframework.context.annotation.Condition; 7 | import org.springframework.context.annotation.ConditionContext; 8 | import org.springframework.core.type.AnnotatedTypeMetadata; 9 | 10 | /** 11 | * @author Siva 12 | * 13 | */ 14 | public class MongoDriverNotPresentsCondition implements Condition 15 | { 16 | 17 | public boolean matches(ConditionContext conditionContext, AnnotatedTypeMetadata metadata) 18 | { 19 | try 20 | { 21 | Class.forName("com.mongodb.Server"); 22 | return false; 23 | } catch (ClassNotFoundException e) 24 | { 25 | return true; 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /basics/spring-conditional-demo/src/main/java/com/sivalabs/demo/MongoDriverPresentsCondition.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.sivalabs.demo; 5 | 6 | import org.springframework.context.annotation.Condition; 7 | import org.springframework.context.annotation.ConditionContext; 8 | import org.springframework.core.type.AnnotatedTypeMetadata; 9 | 10 | /** 11 | * @author Siva 12 | * 13 | */ 14 | public class MongoDriverPresentsCondition implements Condition 15 | { 16 | 17 | public boolean matches(ConditionContext conditionContext, AnnotatedTypeMetadata metadata) 18 | { 19 | try 20 | { 21 | Class.forName("com.mongodb.Server"); 22 | return true; 23 | } catch (ClassNotFoundException e) 24 | { 25 | return false; 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /basics/spring-conditional-demo/src/main/java/com/sivalabs/demo/MongoUserDAO.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.sivalabs.demo; 5 | 6 | import java.util.Arrays; 7 | import java.util.List; 8 | 9 | /** 10 | * @author Siva 11 | * 12 | */ 13 | public class MongoUserDAO implements UserDAO 14 | { 15 | 16 | public List getAllUserNames() 17 | { 18 | System.out.println("**** Getting usernames from MongoDB *****"); 19 | return Arrays.asList("Bond","James","Bond"); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /basics/spring-conditional-demo/src/main/java/com/sivalabs/demo/MySQLDatabaseTypeCondition.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.sivalabs.demo; 5 | 6 | import org.springframework.context.annotation.Condition; 7 | import org.springframework.context.annotation.ConditionContext; 8 | import org.springframework.core.type.AnnotatedTypeMetadata; 9 | 10 | /** 11 | * @author Siva 12 | * 13 | */ 14 | public class MySQLDatabaseTypeCondition implements Condition 15 | { 16 | 17 | public boolean matches(ConditionContext conditionContext, AnnotatedTypeMetadata metadata) 18 | { 19 | String enabledDBType = System.getProperty("dbType","MYSQL"); 20 | return (enabledDBType != null && enabledDBType.equalsIgnoreCase("MYSQL")); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /basics/spring-conditional-demo/src/main/java/com/sivalabs/demo/UserDAO.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.sivalabs.demo; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * @author Siva 10 | * 11 | */ 12 | public interface UserDAO 13 | { 14 | List getAllUserNames(); 15 | } 16 | -------------------------------------------------------------------------------- /basics/spring-conditional-demo/src/main/java/com/sivalabs/demo/UserDAOBeanNotPresentsCondition.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.sivalabs.demo; 5 | 6 | import org.springframework.context.annotation.Condition; 7 | import org.springframework.context.annotation.ConditionContext; 8 | import org.springframework.core.type.AnnotatedTypeMetadata; 9 | 10 | /** 11 | * @author Siva 12 | * 13 | */ 14 | public class UserDAOBeanNotPresentsCondition implements Condition 15 | { 16 | 17 | public boolean matches(ConditionContext conditionContext, AnnotatedTypeMetadata metadata) 18 | { 19 | UserDAO userDAO = conditionContext.getBeanFactory().getBean(UserDAO.class); 20 | return (userDAO == null); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /basics/spring-conditional-demo/src/test/java/com/sivalabs/demo/ConditionalTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.sivalabs.demo; 5 | 6 | import java.util.List; 7 | 8 | import org.junit.Test; 9 | import org.junit.runner.RunWith; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.test.context.ContextConfiguration; 12 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 13 | 14 | /** 15 | * @author Siva 16 | * 17 | */ 18 | @RunWith(SpringJUnit4ClassRunner.class) 19 | @ContextConfiguration(classes=AppConfig.class) 20 | public class ConditionalTest 21 | { 22 | @Autowired 23 | private UserDAO userDAO; 24 | 25 | @Test 26 | public void test_get_all_usernames() 27 | { 28 | List userNames = userDAO.getAllUserNames(); 29 | System.err.println(userNames); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /database/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.sivalabs 7 | spring-boot-database-tutorial 8 | 1.0.0-SNAPSHOT 9 | pom 10 | 11 | spring-boot-database-tutorial 12 | 13 | springboot-jdbc-demo 14 | springboot-mybatis-demo 15 | springboot-jooq-demo 16 | 17 | 18 | -------------------------------------------------------------------------------- /database/springboot-jdbc-demo/src/main/java/com/sivalabs/demo/SpringbootJdbcDemoApplication.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.demo; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * @author Siva 8 | * 9 | */ 10 | 11 | @SpringBootApplication 12 | public class SpringbootJdbcDemoApplication 13 | { 14 | 15 | public static void main(String[] args) 16 | { 17 | SpringApplication.run(SpringbootJdbcDemoApplication.class, args); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /database/springboot-jdbc-demo/src/main/java/com/sivalabs/demo/User.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.sivalabs.demo; 5 | 6 | /** 7 | * @author Siva 8 | * 9 | */ 10 | public class User 11 | { 12 | private Integer id; 13 | private String name; 14 | private String email; 15 | 16 | public User() 17 | { 18 | } 19 | 20 | public User(Integer id, String name, String email) 21 | { 22 | this.id = id; 23 | this.name = name; 24 | this.email = email; 25 | } 26 | 27 | public Integer getId() 28 | { 29 | return id; 30 | } 31 | 32 | public void setId(Integer id) 33 | { 34 | this.id = id; 35 | } 36 | 37 | public String getName() 38 | { 39 | return name; 40 | } 41 | 42 | public void setName(String name) 43 | { 44 | this.name = name; 45 | } 46 | 47 | public String getEmail() 48 | { 49 | return email; 50 | } 51 | 52 | public void setEmail(String email) 53 | { 54 | this.email = email; 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /database/springboot-jdbc-demo/src/main/resources/application-prod.properties: -------------------------------------------------------------------------------- 1 | 2 | logging.level.org.springframework=DEBUG 3 | 4 | ################### DataSource Configuration ########################## 5 | spring.datasource.driver-class-name=com.mysql.jdbc.Driver 6 | spring.datasource.url=jdbc:mysql://localhost:3306/test 7 | spring.datasource.username=root 8 | spring.datasource.password=admin 9 | 10 | spring.datasource.initialize=true 11 | 12 | ################### Hibernate Configuration ########################## 13 | 14 | spring.jpa.hibernate.ddl-auto=update 15 | spring.jpa.show-sql=true 16 | 17 | -------------------------------------------------------------------------------- /database/springboot-jdbc-demo/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | logging.level.org.springframework=INFO -------------------------------------------------------------------------------- /database/springboot-jdbc-demo/src/main/resources/data.sql: -------------------------------------------------------------------------------- 1 | 2 | 3 | insert into users(id, name, email) values(1,'Siva','siva@gmail.com'); 4 | insert into users(id, name, email) values(2,'Prasad','prasad@gmail.com'); 5 | insert into users(id, name, email) values(3,'Reddy','reddy@gmail.com'); 6 | -------------------------------------------------------------------------------- /database/springboot-jdbc-demo/src/main/resources/schema.sql: -------------------------------------------------------------------------------- 1 | 2 | 3 | CREATE TABLE users ( 4 | id int(11) NOT NULL AUTO_INCREMENT, 5 | name varchar(100) NOT NULL, 6 | email varchar(100) DEFAULT NULL, 7 | PRIMARY KEY (id) 8 | ); 9 | 10 | -------------------------------------------------------------------------------- /database/springboot-jooq-demo/src/main/java/com/sivalabs/demo/SpringbootJooqDemoApplication.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.demo; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * @author Siva 8 | * 9 | */ 10 | @SpringBootApplication 11 | public class SpringbootJooqDemoApplication 12 | { 13 | 14 | public static void main(String[] args) 15 | { 16 | SpringApplication.run(SpringbootJooqDemoApplication.class, args); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /database/springboot-jooq-demo/src/main/resources/application-prod.properties: -------------------------------------------------------------------------------- 1 | 2 | logging.level.org.springframework=INFO 3 | 4 | ################### DataSource Configuration ########################## 5 | spring.datasource.driver-class-name=com.mysql.jdbc.Driver 6 | spring.datasource.url=jdbc:mysql://localhost:3306/test 7 | spring.datasource.username=root 8 | spring.datasource.password=admin 9 | 10 | spring.datasource.initialize=true 11 | 12 | spring.jooq.sql-dialect=MYSQL -------------------------------------------------------------------------------- /database/springboot-jooq-demo/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | #spring.profiles.active=prod 3 | logging.level.org.springframework=INFO -------------------------------------------------------------------------------- /database/springboot-jooq-demo/src/main/resources/data.sql: -------------------------------------------------------------------------------- 1 | 2 | insert into posts(id, title, content, created_on) values(1, 'Post 1', 'This is post 1', '2016-01-03'); 3 | insert into posts(id, title, content, created_on) values(2, 'Post 2', 'This is post 2', '2016-01-05'); 4 | insert into posts(id, title, content, created_on) values(3, 'Post 3', 'This is post 3', '2016-01-07'); 5 | 6 | insert into comments(id, post_id, name, email, content, created_on) values(1,1, 'User1', 'user1@gmail.com', 'This is comment 1 on post 1', '2016-01-07'); 7 | insert into comments(id, post_id, name, email, content, created_on) values(2,1, 'User2', 'user2@gmail.com', 'This is comment 2 on post 1', '2016-01-07'); 8 | insert into comments(id, post_id, name, email, content, created_on) values(3,2, 'User1', 'user1@gmail.com', 'This is comment 1 on post 2', '2016-01-07'); 9 | 10 | -------------------------------------------------------------------------------- /database/springboot-jooq-demo/src/main/resources/reset.sql: -------------------------------------------------------------------------------- 1 | DROP ALL OBJECTS; -------------------------------------------------------------------------------- /database/springboot-jooq-demo/src/main/resources/schema.sql: -------------------------------------------------------------------------------- 1 | 2 | DROP TABLE IF EXISTS COMMENTS; 3 | DROP TABLE IF EXISTS POSTS; 4 | 5 | CREATE TABLE POSTS ( 6 | ID int(11) NOT NULL AUTO_INCREMENT, 7 | TITLE varchar(200) NOT NULL, 8 | CONTENT LONGTEXT DEFAULT NULL, 9 | CREATED_ON datetime DEFAULT NULL, 10 | PRIMARY KEY (ID) 11 | ); 12 | 13 | CREATE TABLE COMMENTS ( 14 | ID int(11) NOT NULL AUTO_INCREMENT, 15 | POST_ID int(11) NOT NULL, 16 | NAME varchar(200) NOT NULL, 17 | EMAIL varchar(200) NOT NULL, 18 | CONTENT LONGTEXT DEFAULT NULL, 19 | CREATED_ON datetime DEFAULT NULL, 20 | PRIMARY KEY (ID), 21 | FOREIGN KEY (POST_ID) REFERENCES POSTS(ID) 22 | ); 23 | 24 | -------------------------------------------------------------------------------- /database/springboot-mybatis-demo/src/main/java/com/sivalabs/demo/SpringbootMyBatisDemoApplication.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.demo; 2 | 3 | import org.mybatis.spring.annotation.MapperScan; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | 7 | /** 8 | * @author Siva 9 | * 10 | */ 11 | 12 | @SpringBootApplication 13 | @MapperScan("com.sivalabs.demo.mappers") 14 | public class SpringbootMyBatisDemoApplication 15 | { 16 | 17 | public static void main(String[] args) 18 | { 19 | SpringApplication.run(SpringbootMyBatisDemoApplication.class, args); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /database/springboot-mybatis-demo/src/main/java/com/sivalabs/demo/domain/User.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.sivalabs.demo.domain; 5 | 6 | /** 7 | * @author Siva 8 | * 9 | */ 10 | public class User 11 | { 12 | private Integer id; 13 | private String name; 14 | private String email; 15 | 16 | public User() 17 | { 18 | } 19 | 20 | public User(Integer id, String name, String email) 21 | { 22 | this.id = id; 23 | this.name = name; 24 | this.email = email; 25 | } 26 | 27 | public Integer getId() 28 | { 29 | return id; 30 | } 31 | 32 | public void setId(Integer id) 33 | { 34 | this.id = id; 35 | } 36 | 37 | public String getName() 38 | { 39 | return name; 40 | } 41 | 42 | public void setName(String name) 43 | { 44 | this.name = name; 45 | } 46 | 47 | public String getEmail() 48 | { 49 | return email; 50 | } 51 | 52 | public void setEmail(String email) 53 | { 54 | this.email = email; 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /database/springboot-mybatis-demo/src/main/java/com/sivalabs/demo/mappers/UserAnnotationMapper.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.sivalabs.demo.mappers; 5 | 6 | import java.util.List; 7 | 8 | import org.apache.ibatis.annotations.Insert; 9 | import org.apache.ibatis.annotations.Select; 10 | import org.apache.ibatis.annotations.SelectKey; 11 | 12 | import com.sivalabs.demo.domain.User; 13 | 14 | /** 15 | * @author Siva 16 | * 17 | */ 18 | public interface UserAnnotationMapper 19 | { 20 | @Insert("insert into users(name,email) values(#{name},#{email})") 21 | @SelectKey(statement="call identity()", keyProperty="id", before=false, resultType=Integer.class) 22 | void insertUser(User user); 23 | 24 | @Select("select id, name, email from users WHERE id=#{id}") 25 | User findUserById(Integer id); 26 | 27 | @Select("select id, name, email from users") 28 | List findAllUsers(); 29 | 30 | } 31 | -------------------------------------------------------------------------------- /database/springboot-mybatis-demo/src/main/java/com/sivalabs/demo/mappers/UserMapper.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.sivalabs.demo.mappers; 5 | 6 | import java.util.List; 7 | 8 | import com.sivalabs.demo.domain.User; 9 | 10 | /** 11 | * @author Siva 12 | * 13 | */ 14 | public interface UserMapper 15 | { 16 | 17 | void insertUser(User user); 18 | 19 | User findUserById(Integer id); 20 | 21 | List findAllUsers(); 22 | 23 | } 24 | -------------------------------------------------------------------------------- /database/springboot-mybatis-demo/src/main/resources/application-prod.properties: -------------------------------------------------------------------------------- 1 | 2 | logging.level.org.springframework=INFO 3 | 4 | ################### DataSource Configuration ########################## 5 | spring.datasource.driver-class-name=com.mysql.jdbc.Driver 6 | spring.datasource.url=jdbc:mysql://localhost:3306/test 7 | spring.datasource.username=root 8 | spring.datasource.password=admin 9 | 10 | spring.datasource.initialize=true 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /database/springboot-mybatis-demo/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | #spring.profiles.active=prod 3 | 4 | logging.level.org.springframework=INFO 5 | 6 | #mybatis.config= # mybatis config file 7 | #mybatis.mapperLocations= # mappers file 8 | #mybatis.typeAliasesPackage= # domain object's package 9 | #mybatis.typeHandlersPackage= # handler's package 10 | #mybatis.check-config-location= # check the mybatis configuration exists 11 | #mybatis.executorType= # mode of execution. Default is SIMPLE 12 | 13 | mybatis.typeAliasesPackage=com.sivalabs.demo.domain 14 | mybatis.mapperLocations=classpath*:**/mappers/*.xml -------------------------------------------------------------------------------- /database/springboot-mybatis-demo/src/main/resources/com/sivalabs/demo/mappers/UserMapper.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 16 | 17 | 20 | 21 | 22 | insert into users(name,email) values(#{name},#{email}) 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /database/springboot-mybatis-demo/src/main/resources/data.sql: -------------------------------------------------------------------------------- 1 | 2 | 3 | insert into users(id, name, email) values(1,'Siva','siva@gmail.com'); 4 | insert into users(id, name, email) values(2,'Prasad','prasad@gmail.com'); 5 | insert into users(id, name, email) values(3,'Reddy','reddy@gmail.com'); 6 | -------------------------------------------------------------------------------- /database/springboot-mybatis-demo/src/main/resources/schema.sql: -------------------------------------------------------------------------------- 1 | 2 | DROP TABLE IF EXISTS USERS; 3 | 4 | CREATE TABLE users ( 5 | id int(11) NOT NULL AUTO_INCREMENT, 6 | name varchar(100) NOT NULL, 7 | email varchar(100) DEFAULT NULL, 8 | PRIMARY KEY (id) 9 | ); 10 | 11 | -------------------------------------------------------------------------------- /integration/spring-boot-integration-demo/.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 | -------------------------------------------------------------------------------- /integration/spring-boot-integration-demo/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sivaprasadreddy/spring-boot-tutorials/11b6fdbc89397122b61353c07c4b9eb34ee1a703/integration/spring-boot-integration-demo/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /integration/spring-boot-integration-demo/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.0/apache-maven-3.6.0-bin.zip 2 | -------------------------------------------------------------------------------- /integration/spring-boot-integration-demo/src/main/java/com/sivalabs/sbidemo/Order.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.sbidemo; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | import javax.persistence.*; 8 | import java.util.Date; 9 | 10 | @Data 11 | @NoArgsConstructor 12 | @AllArgsConstructor 13 | @Entity 14 | @Table(name = "orders") 15 | public class Order { 16 | @Id @GeneratedValue(strategy = GenerationType.AUTO) 17 | private Long id; 18 | private String details; 19 | @Enumerated(EnumType.STRING) 20 | private Status status = Status.CREATED; 21 | private Date createdDate = new Date(); 22 | 23 | enum Status { 24 | CREATED, DELIVERED, CANCELLED 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /integration/spring-boot-integration-demo/src/main/java/com/sivalabs/sbidemo/OrderGenerator.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.sbidemo; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.scheduling.annotation.Scheduled; 6 | import org.springframework.stereotype.Component; 7 | 8 | import java.util.Date; 9 | 10 | @Component 11 | @Slf4j 12 | public class OrderGenerator { 13 | 14 | @Autowired 15 | OrderRepository orderRepository; 16 | 17 | @Scheduled(fixedDelay = 3000L) 18 | public void generateOrder() { 19 | Order order = orderRepository.save(new Order(null, "order-" + new Date(), Order.Status.CREATED, new Date())); 20 | log.info("Order Id: "+order.getId()); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /integration/spring-boot-integration-demo/src/main/java/com/sivalabs/sbidemo/OrderRepository.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.sbidemo; 2 | 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | 5 | import java.util.List; 6 | 7 | public interface OrderRepository extends JpaRepository { 8 | 9 | List findByStatus(Order.Status status); 10 | 11 | } 12 | -------------------------------------------------------------------------------- /integration/spring-boot-integration-demo/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /integration/spring-boot-integration-demo/src/test/java/com/sivalabs/sbidemo/SpringBootIntegrationDemoApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.sbidemo; 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 SpringBootIntegrationDemoApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /nosql/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.sivalabs 7 | spring-boot-nosql-tutorial 8 | 1.0.0-SNAPSHOT 9 | pom 10 | 11 | spring-boot-nosql-tutorial 12 | 13 | spring-boot-redis-demo 14 | spring-boot-mongodb-demo 15 | 16 | 17 | -------------------------------------------------------------------------------- /nosql/spring-boot-mongodb-demo/.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 | -------------------------------------------------------------------------------- /nosql/spring-boot-mongodb-demo/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sivaprasadreddy/spring-boot-tutorials/11b6fdbc89397122b61353c07c4b9eb34ee1a703/nosql/spring-boot-mongodb-demo/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /nosql/spring-boot-mongodb-demo/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.1/apache-maven-3.8.1-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar 3 | -------------------------------------------------------------------------------- /nosql/spring-boot-mongodb-demo/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3.1' 2 | services: 3 | mongodb: 4 | image: mongo:4.2 5 | restart: always 6 | ports: 7 | - 27017:27017 8 | environment: 9 | MONGO_INITDB_ROOT_USERNAME: mongo 10 | MONGO_INITDB_ROOT_PASSWORD: mongo 11 | 12 | mongo-express: 13 | image: mongo-express 14 | restart: always 15 | ports: 16 | - 8081:8081 17 | environment: 18 | ME_CONFIG_MONGODB_SERVER: mongodb 19 | ME_CONFIG_MONGODB_ADMINUSERNAME: mongo 20 | ME_CONFIG_MONGODB_ADMINPASSWORD: mongo -------------------------------------------------------------------------------- /nosql/spring-boot-mongodb-demo/src/main/java/com/sivalabs/springmongodbdemo/SpringMongodbDemoApplication.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.springmongodbdemo; 2 | 3 | import com.sivalabs.springmongodbdemo.config.ApplicationProperties; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.web.client.RestTemplate; 9 | 10 | @SpringBootApplication 11 | @EnableConfigurationProperties({ApplicationProperties.class}) 12 | public class SpringMongodbDemoApplication { 13 | 14 | public static void main(String[] args) { 15 | SpringApplication.run(SpringMongodbDemoApplication.class, args); 16 | } 17 | 18 | @Bean 19 | public RestTemplate restTemplate() { 20 | return new RestTemplate(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /nosql/spring-boot-mongodb-demo/src/main/java/com/sivalabs/springmongodbdemo/config/ApplicationProperties.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.springmongodbdemo.config; 2 | 3 | import lombok.Data; 4 | import org.springframework.boot.context.properties.ConfigurationProperties; 5 | 6 | @Data 7 | @ConfigurationProperties(prefix = "myapp") 8 | public class ApplicationProperties { 9 | private String githubBaseUrl; 10 | } 11 | -------------------------------------------------------------------------------- /nosql/spring-boot-mongodb-demo/src/main/java/com/sivalabs/springmongodbdemo/documents/Address.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.springmongodbdemo.documents; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Getter; 5 | import lombok.NoArgsConstructor; 6 | import lombok.Setter; 7 | 8 | @Setter 9 | @Getter 10 | @NoArgsConstructor 11 | @AllArgsConstructor 12 | public class Address { 13 | private String street; 14 | private String city; 15 | private String state; 16 | private String zip; 17 | private String country; 18 | } 19 | -------------------------------------------------------------------------------- /nosql/spring-boot-mongodb-demo/src/main/java/com/sivalabs/springmongodbdemo/models/GithubUser.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.springmongodbdemo.models; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | import lombok.Data; 5 | 6 | @Data 7 | public class GithubUser { 8 | private Long id; 9 | private String login; 10 | private String url; 11 | private String name; 12 | @JsonProperty("public_repos") 13 | private int publicRepos; 14 | private int followers; 15 | private int following; 16 | } -------------------------------------------------------------------------------- /nosql/spring-boot-mongodb-demo/src/main/java/com/sivalabs/springmongodbdemo/repositories/PersonRepository.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.springmongodbdemo.repositories; 2 | 3 | import com.sivalabs.springmongodbdemo.documents.Person; 4 | import org.springframework.data.mongodb.repository.MongoRepository; 5 | 6 | public interface PersonRepository extends MongoRepository { 7 | 8 | } 9 | -------------------------------------------------------------------------------- /nosql/spring-boot-mongodb-demo/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=9001 2 | 3 | #log4j.category.org.springframework.data.mongodb=DEBUG 4 | #log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %40.40c:%4L - %m%n 5 | 6 | logging.file.path=./logs/myapp.log 7 | 8 | logging.level.org.springframework.data.mongodb=DEBUG 9 | 10 | spring.data.mongodb.uri=mongodb://mongo:mongo@localhost/test?authSource=admin 11 | #spring.data.mongodb.host=localhost 12 | #spring.data.mongodb.port=27017 13 | #spring.data.mongodb.database=test 14 | #spring.data.mongodb.username=mongo 15 | #spring.data.mongodb.password=mongo 16 | #spring.data.mongodb.authentication-database=admin 17 | 18 | #spring.data.mongodb.uri=mongodb://mongo:mongo@localhost/test 19 | 20 | myapp.githubBaseUrl=https://api.github.com -------------------------------------------------------------------------------- /nosql/spring-boot-mongodb-demo/src/test/java/com/sivalabs/springmongodbdemo/SpringMongodbDemoApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.springmongodbdemo; 2 | 3 | import com.sivalabs.springmongodbdemo.common.BaseIntegrationTest; 4 | import org.junit.jupiter.api.Test; 5 | 6 | class SpringMongodbDemoApplicationTests extends BaseIntegrationTest { 7 | 8 | @Test 9 | void contextLoads() { 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /nosql/spring-boot-redis-demo/.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 | -------------------------------------------------------------------------------- /nosql/spring-boot-redis-demo/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sivaprasadreddy/spring-boot-tutorials/11b6fdbc89397122b61353c07c4b9eb34ee1a703/nosql/spring-boot-redis-demo/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /nosql/spring-boot-redis-demo/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar 3 | -------------------------------------------------------------------------------- /nosql/spring-boot-redis-demo/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3.5' 2 | 3 | services: 4 | 5 | redis: 6 | image: redis:6.0.9 7 | ports: 8 | - "6379:6379" 9 | environment: 10 | - REDIS_REPLICATION_MODE=master 11 | restart: unless-stopped 12 | -------------------------------------------------------------------------------- /nosql/spring-boot-redis-demo/src/main/java/com/sivalabs/bootredisdemo/SpringBootRedisDemoApplication.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.bootredisdemo; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SpringBootRedisDemoApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SpringBootRedisDemoApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /nosql/spring-boot-redis-demo/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /nosql/spring-boot-redis-demo/src/test/java/com/sivalabs/bootredisdemo/SpringBootRedisDemoApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.bootredisdemo; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class SpringBootRedisDemoApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /search/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.sivalabs 7 | spring-boot-search-tutorial 8 | 1.0.0-SNAPSHOT 9 | pom 10 | 11 | spring-boot-search-tutorial 12 | 13 | springboot-solr-demo 14 | 15 | 16 | -------------------------------------------------------------------------------- /search/springboot-solr-demo/src/main/java/com/sivalabs/demo/HomeController.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.demo; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | 6 | /** 7 | * Created by Siva on 18-02-2016. 8 | */ 9 | @Controller 10 | public class HomeController { 11 | 12 | @RequestMapping("/") 13 | public String index(){ 14 | return "index"; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /search/springboot-solr-demo/src/main/java/com/sivalabs/demo/ProductRepository.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.sivalabs.demo; 5 | 6 | import java.util.List; 7 | 8 | import org.springframework.data.solr.repository.SolrCrudRepository; 9 | 10 | /** 11 | * @author Siva 12 | * 13 | */ 14 | public interface ProductRepository extends SolrCrudRepository 15 | { 16 | 17 | List findByName(String name); 18 | 19 | 20 | } 21 | -------------------------------------------------------------------------------- /search/springboot-solr-demo/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.profiles.active=dev 2 | spring.data.solr.repositories.enabled=true -------------------------------------------------------------------------------- /search/springboot-solr-demo/src/main/resources/demo/solr/core1/conf/stopwords.txt: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | -------------------------------------------------------------------------------- /search/springboot-solr-demo/src/main/resources/demo/solr/core1/core.properties: -------------------------------------------------------------------------------- 1 | name=core1 2 | shard=${shard:} 3 | collection=${collection:core1} 4 | config=${solrconfig:solrconfig.xml} 5 | schema=${schema:schema.xml} 6 | coreNodeName=${coreNodeName:} -------------------------------------------------------------------------------- /search/springboot-solr-demo/src/main/resources/demo/solr/solr.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 127.0.0.1 4 | ${hostPort:8983} 5 | ${hostContext:solr} 6 | ${solr.zkclienttimeout:30000} 7 | 8 | ${genericCoreNodeNames:true} 9 | 10 | 11 | 12 | ${socketTimeout:120000} 13 | ${connTimeout:15000} 14 | 15 | -------------------------------------------------------------------------------- /search/springboot-solr-demo/src/main/resources/templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Home 6 | 7 | 8 | Welcome 9 | 10 | -------------------------------------------------------------------------------- /security/custom-security-expressions/.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 | -------------------------------------------------------------------------------- /security/custom-security-expressions/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sivaprasadreddy/spring-boot-tutorials/11b6fdbc89397122b61353c07c4b9eb34ee1a703/security/custom-security-expressions/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /security/custom-security-expressions/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar 3 | -------------------------------------------------------------------------------- /security/custom-security-expressions/src/main/java/com/sivalabs/demo/AppConfig.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.demo; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.security.crypto.password.NoOpPasswordEncoder; 6 | import org.springframework.security.crypto.password.PasswordEncoder; 7 | 8 | @Configuration 9 | public class AppConfig { 10 | 11 | @Bean 12 | public PasswordEncoder passwordEncoder() { 13 | return NoOpPasswordEncoder.getInstance(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /security/custom-security-expressions/src/main/java/com/sivalabs/demo/BootCustomSecurityExpressionsApplication.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.demo; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class BootCustomSecurityExpressionsApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(BootCustomSecurityExpressionsApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /security/custom-security-expressions/src/main/java/com/sivalabs/demo/controller/DemoController.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.demo.controller; 2 | 3 | import org.springframework.security.access.prepost.PreAuthorize; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.RestController; 6 | 7 | @RestController 8 | public class DemoController { 9 | 10 | @GetMapping("/ping") 11 | public String ping() { 12 | return "Pong"; 13 | } 14 | 15 | @GetMapping("/mping") 16 | @PreAuthorize("hasRole('ROLE_MODERATOR')") 17 | public String moderatorPing() { 18 | return "Moderator Pong"; 19 | } 20 | 21 | @GetMapping("/deletePost") 22 | @PreAuthorize("hasPrivilege('DELETE_POST')") 23 | public String deletePost() { 24 | return "Post deleted"; 25 | } 26 | 27 | 28 | } 29 | -------------------------------------------------------------------------------- /security/custom-security-expressions/src/main/java/com/sivalabs/demo/entities/Privilege.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.demo.entities; 2 | 3 | import lombok.Getter; 4 | import lombok.Setter; 5 | 6 | import javax.persistence.*; 7 | import java.util.Set; 8 | 9 | @Entity 10 | @Table(name = "privileges") 11 | @Setter 12 | @Getter 13 | public class Privilege { 14 | @Id @GeneratedValue(strategy = GenerationType.IDENTITY) 15 | private Long id; 16 | 17 | @Column(nullable = false, unique = true) 18 | private String name; 19 | 20 | @ManyToMany(mappedBy = "privileges") 21 | private Set roles; 22 | 23 | } 24 | -------------------------------------------------------------------------------- /security/custom-security-expressions/src/main/java/com/sivalabs/demo/entities/User.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.demo.entities; 2 | 3 | import lombok.Getter; 4 | import lombok.Setter; 5 | 6 | import javax.persistence.*; 7 | import java.util.Set; 8 | 9 | @Entity 10 | @Table(name = "users") 11 | @Setter 12 | @Getter 13 | public class User { 14 | @Id @GeneratedValue(strategy = GenerationType.IDENTITY) 15 | private Long id; 16 | @Column(nullable = false, unique = true) 17 | private String email; 18 | @Column(nullable = false) 19 | private String password; 20 | 21 | @ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.MERGE) 22 | @JoinTable( 23 | name = "user_role", 24 | joinColumns = {@JoinColumn(name = "USER_ID", referencedColumnName = "ID")}, 25 | inverseJoinColumns = {@JoinColumn(name = "ROLE_ID", referencedColumnName = "ID")}) 26 | private Set roles; 27 | } 28 | -------------------------------------------------------------------------------- /security/custom-security-expressions/src/main/java/com/sivalabs/demo/repo/PrivilegeRepository.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.demo.repo; 2 | 3 | import com.sivalabs.demo.entities.Privilege; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | 6 | public interface PrivilegeRepository extends JpaRepository { 7 | } 8 | -------------------------------------------------------------------------------- /security/custom-security-expressions/src/main/java/com/sivalabs/demo/repo/RoleRepository.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.demo.repo; 2 | 3 | import com.sivalabs.demo.entities.Role; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | 6 | public interface RoleRepository extends JpaRepository { 7 | } 8 | -------------------------------------------------------------------------------- /security/custom-security-expressions/src/main/java/com/sivalabs/demo/repo/UserRepository.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.demo.repo; 2 | 3 | import com.sivalabs.demo.entities.User; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | 6 | public interface UserRepository extends JpaRepository { 7 | User findByEmail(String username); 8 | } 9 | -------------------------------------------------------------------------------- /security/custom-security-expressions/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.main.allow-bean-definition-overriding=true 2 | spring.jpa.show-sql=true -------------------------------------------------------------------------------- /security/custom-security-expressions/src/main/resources/data.sql: -------------------------------------------------------------------------------- 1 | insert into privileges(id, name) values 2 | (1, 'CREATE_POST'), 3 | (2, 'MODERATE_POST'), 4 | (3, 'DELETE_POST') 5 | ; 6 | 7 | insert into roles(id, name) values 8 | (1, 'ROLE_USER'), 9 | (2, 'ROLE_MODERATOR'), 10 | (3, 'ROLE_ADMIN') 11 | ; 12 | 13 | insert into users(id, email, password) values 14 | (1, 'siva', 'siva'), 15 | (2, 'prasad', 'prasad'), 16 | (3, 'admin', 'admin') 17 | ; 18 | 19 | insert into role_privilege(role_id, privilege_id) values 20 | (1, 1), 21 | (2, 1), 22 | (2, 2), 23 | (3, 1), 24 | (3, 2), 25 | (3, 3) 26 | ; 27 | 28 | insert into user_role(user_id, role_id) values 29 | (1, 1), 30 | (2, 2), 31 | (3, 3) 32 | ; -------------------------------------------------------------------------------- /security/custom-security-expressions/src/test/java/com/sivalabs/demo/BootCustomSecurityExpressionsApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.demo; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class BootCustomSecurityExpressionsApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /security/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.sivalabs 7 | spring-boot-security-tutorial 8 | 1.0.0-SNAPSHOT 9 | pom 10 | 11 | spring-boot-security-tutorial 12 | 13 | spring-security-multi-config 14 | spring-security-oauth2-demo 15 | custom-security-expressions 16 | spring-boot-social-login 17 | 18 | 19 | -------------------------------------------------------------------------------- /security/spring-boot-okta-demo/.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 | .okta.env 16 | .env 17 | 18 | ### IntelliJ IDEA ### 19 | .idea 20 | *.iws 21 | *.iml 22 | *.ipr 23 | 24 | ### NetBeans ### 25 | /nbproject/private/ 26 | /nbbuild/ 27 | /dist/ 28 | /nbdist/ 29 | /.nb-gradle/ 30 | build/ 31 | !**/src/main/**/build/ 32 | !**/src/test/**/build/ 33 | 34 | ### VS Code ### 35 | .vscode/ 36 | -------------------------------------------------------------------------------- /security/spring-boot-okta-demo/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sivaprasadreddy/spring-boot-tutorials/11b6fdbc89397122b61353c07c4b9eb34ee1a703/security/spring-boot-okta-demo/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /security/spring-boot-okta-demo/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.6/apache-maven-3.8.6-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar 3 | -------------------------------------------------------------------------------- /security/spring-boot-okta-demo/src/main/java/com/sivalabs/oktademo/SpringBootOktaDemoApplication.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.oktademo; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SpringBootOktaDemoApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SpringBootOktaDemoApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /security/spring-boot-okta-demo/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | okta.oauth2.issuer=${env.ISSUER} 2 | okta.oauth2.client-id=${env.CLIENT_ID} 3 | okta.oauth2.client-secret=${env.CLIENT_SECRET} 4 | okta.oauth2.scopes=openid,email,profile 5 | 6 | spring.security.oauth2.client.provider.okta.user-name-attribute=email -------------------------------------------------------------------------------- /security/spring-boot-okta-demo/src/main/resources/templates/footer.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 |

Nothing to see here, move along.

6 | 7 |
8 | 11 |
12 | 13 | -------------------------------------------------------------------------------- /security/spring-boot-okta-demo/src/main/resources/templates/head.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11 |

Nothing to see here, move along.

12 | 13 | -------------------------------------------------------------------------------- /security/spring-boot-okta-demo/src/test/java/com/sivalabs/oktademo/SpringBootOktaDemoApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.oktademo; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class SpringBootOktaDemoApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /security/spring-boot-social-login/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | /target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | 5 | application-prod.properties 6 | secure.properties 7 | 8 | ### STS ### 9 | .apt_generated 10 | .classpath 11 | .factorypath 12 | .project 13 | .settings 14 | .springBeans 15 | .sts4-cache 16 | 17 | ### IntelliJ IDEA ### 18 | .idea 19 | *.iws 20 | *.iml 21 | *.ipr 22 | 23 | ### NetBeans ### 24 | /nbproject/private/ 25 | /nbbuild/ 26 | /dist/ 27 | /nbdist/ 28 | /.nb-gradle/ 29 | /build/ 30 | 31 | ### VS Code ### 32 | .vscode/ 33 | -------------------------------------------------------------------------------- /security/spring-boot-social-login/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sivaprasadreddy/spring-boot-tutorials/11b6fdbc89397122b61353c07c4b9eb34ee1a703/security/spring-boot-social-login/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /security/spring-boot-social-login/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.0/apache-maven-3.6.0-bin.zip 2 | -------------------------------------------------------------------------------- /security/spring-boot-social-login/src/main/java/com/sivalabs/bookmarker/BookmarkerApplication.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.bookmarker; 2 | 3 | import com.sivalabs.bookmarker.config.BookmarkerProperties; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 7 | import org.springframework.cache.annotation.EnableCaching; 8 | import org.springframework.context.annotation.EnableAspectJAutoProxy; 9 | 10 | @SpringBootApplication 11 | @EnableConfigurationProperties(value = {BookmarkerProperties.class}) 12 | @EnableAspectJAutoProxy 13 | @EnableCaching 14 | public class BookmarkerApplication { 15 | 16 | public static void main(String[] args) { 17 | SpringApplication.run(BookmarkerApplication.class, args); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /security/spring-boot-social-login/src/main/java/com/sivalabs/bookmarker/config/BookmarkerProperties.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.bookmarker.config; 2 | 3 | import lombok.Data; 4 | import org.springframework.boot.context.properties.ConfigurationProperties; 5 | 6 | @ConfigurationProperties(prefix = "bookmarker") 7 | @Data 8 | public class BookmarkerProperties { 9 | } 10 | -------------------------------------------------------------------------------- /security/spring-boot-social-login/src/main/java/com/sivalabs/bookmarker/config/security/oauth/AuthenticatedPrincipal.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.bookmarker.config.security.oauth; 2 | 3 | public interface AuthenticatedPrincipal { 4 | String getId(); 5 | String getName(); 6 | String getEmail(); 7 | String getImageUrl(); 8 | } 9 | -------------------------------------------------------------------------------- /security/spring-boot-social-login/src/main/java/com/sivalabs/bookmarker/config/security/oauth/OidcUser.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.bookmarker.config.security.oauth; 2 | 3 | import org.springframework.security.oauth2.core.oidc.user.DefaultOidcUser; 4 | 5 | public class OidcUser extends DefaultOidcUser implements AuthenticatedPrincipal { 6 | 7 | public OidcUser(org.springframework.security.oauth2.core.oidc.user.OidcUser user) { 8 | super(user.getAuthorities(), user.getIdToken(), "name"); 9 | } 10 | 11 | @Override 12 | public String getId() { 13 | return super.getClaimAsString("id"); 14 | } 15 | 16 | @Override 17 | public String getImageUrl() { 18 | return super.getPicture(); 19 | } 20 | 21 | @Override 22 | public String getEmail() { 23 | return super.getEmail(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /security/spring-boot-social-login/src/main/java/com/sivalabs/bookmarker/domain/entity/Role.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.bookmarker.domain.entity; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnore; 4 | import lombok.Getter; 5 | import lombok.Setter; 6 | 7 | import javax.persistence.*; 8 | import javax.validation.constraints.NotEmpty; 9 | import java.io.Serializable; 10 | import java.util.List; 11 | 12 | @Entity 13 | @Table(name="roles") 14 | @Setter 15 | @Getter 16 | public class Role extends BaseEntity implements Serializable 17 | { 18 | 19 | @Id 20 | @SequenceGenerator(name = "role_id_generator", sequenceName = "role_id_seq", allocationSize = 1) 21 | @GeneratedValue(generator = "role_id_generator") 22 | private Long id; 23 | 24 | @Column(nullable=false, unique=true) 25 | @NotEmpty 26 | private String name; 27 | 28 | @JsonIgnore 29 | @ManyToMany(mappedBy = "roles") 30 | private List users; 31 | 32 | } 33 | -------------------------------------------------------------------------------- /security/spring-boot-social-login/src/main/java/com/sivalabs/bookmarker/domain/entity/UserType.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.bookmarker.domain.entity; 2 | 3 | public enum UserType { 4 | LOCAL, 5 | GOOGLE, 6 | GITHUB 7 | } 8 | -------------------------------------------------------------------------------- /security/spring-boot-social-login/src/main/java/com/sivalabs/bookmarker/domain/model/BookmarkDTO.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.bookmarker.domain.model; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | import lombok.Data; 5 | 6 | import javax.validation.constraints.NotBlank; 7 | import java.time.LocalDateTime; 8 | import java.util.ArrayList; 9 | import java.util.List; 10 | 11 | @Data 12 | public class BookmarkDTO { 13 | private Long id; 14 | 15 | @NotBlank(message = "URL cannot be blank") 16 | private String url; 17 | 18 | private String title; 19 | 20 | @JsonProperty("created_user_id") 21 | private Long createdUserId; 22 | 23 | @JsonProperty("created_user_name") 24 | private String createdUserName; 25 | 26 | @JsonProperty("created_at") 27 | private LocalDateTime createdAt; 28 | 29 | @JsonProperty("updated_at") 30 | private LocalDateTime updatedAt; 31 | } 32 | -------------------------------------------------------------------------------- /security/spring-boot-social-login/src/main/java/com/sivalabs/bookmarker/domain/model/CreateUserRequest.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.bookmarker.domain.model; 2 | 3 | import lombok.Data; 4 | 5 | import javax.validation.constraints.Email; 6 | import javax.validation.constraints.NotBlank; 7 | 8 | @Data 9 | public class CreateUserRequest { 10 | @NotBlank(message = "Name cannot be blank") 11 | String name; 12 | 13 | @NotBlank(message = "Email cannot be blank") 14 | @Email(message = "Invalid email address") 15 | String email; 16 | 17 | @NotBlank(message = "Password cannot be blank") 18 | String password; 19 | } 20 | -------------------------------------------------------------------------------- /security/spring-boot-social-login/src/main/java/com/sivalabs/bookmarker/domain/repository/BookmarkRepository.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.bookmarker.domain.repository; 2 | 3 | import com.sivalabs.bookmarker.domain.entity.Bookmark; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | import org.springframework.stereotype.Repository; 6 | 7 | @Repository 8 | public interface BookmarkRepository extends JpaRepository { 9 | } 10 | -------------------------------------------------------------------------------- /security/spring-boot-social-login/src/main/java/com/sivalabs/bookmarker/domain/repository/RoleRepository.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.bookmarker.domain.repository; 2 | 3 | import com.sivalabs.bookmarker.domain.entity.Role; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | import java.util.Optional; 6 | 7 | public interface RoleRepository extends JpaRepository { 8 | Optional findByName(String name); 9 | } 10 | -------------------------------------------------------------------------------- /security/spring-boot-social-login/src/main/java/com/sivalabs/bookmarker/domain/repository/UserRepository.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.bookmarker.domain.repository; 2 | 3 | import com.sivalabs.bookmarker.domain.entity.User; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | import org.springframework.stereotype.Repository; 6 | 7 | import java.util.Optional; 8 | 9 | @Repository 10 | public interface UserRepository extends JpaRepository { 11 | 12 | Optional findByEmail(String email); 13 | 14 | boolean existsByEmail(String email); 15 | } 16 | -------------------------------------------------------------------------------- /security/spring-boot-social-login/src/main/java/com/sivalabs/bookmarker/domain/utils/Constants.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.bookmarker.domain.utils; 2 | 3 | import lombok.experimental.UtilityClass; 4 | 5 | @UtilityClass 6 | public class Constants { 7 | public static final String ROLE_USER = "ROLE_USER"; 8 | } 9 | -------------------------------------------------------------------------------- /security/spring-boot-social-login/src/main/resources/application-docker.properties: -------------------------------------------------------------------------------- 1 | spring.datasource.driver-class-name=org.postgresql.Driver 2 | spring.datasource.url=jdbc:postgresql://bm-postgresdb:5432/appdb 3 | spring.datasource.username=siva 4 | spring.datasource.password=secret 5 | -------------------------------------------------------------------------------- /security/spring-boot-social-login/src/main/resources/application-local.properties: -------------------------------------------------------------------------------- 1 | spring.datasource.driver-class-name=org.postgresql.Driver 2 | spring.datasource.url=jdbc:postgresql://localhost:5432/appdb 3 | spring.datasource.username=siva 4 | spring.datasource.password=secret 5 | -------------------------------------------------------------------------------- /security/spring-boot-social-login/src/main/resources/db/migration/h2/V2__insert_sample_data.sql: -------------------------------------------------------------------------------- 1 | 2 | INSERT INTO roles (id, name, created_at) VALUES 3 | (1, 'ROLE_ADMIN', CURRENT_TIMESTAMP()), 4 | (2, 'ROLE_MODERATOR', CURRENT_TIMESTAMP()), 5 | (3, 'ROLE_USER', CURRENT_TIMESTAMP()) 6 | ; 7 | 8 | INSERT INTO users (email, password, name, user_type, created_at) VALUES 9 | ('sivaprasadreddy.k@gmail.com', '$2a$10$qW08MYCgzkYNoFFXYHUqluGGyLtBJK/XAQtu0lmsjD2mWaUiPQeZ2', 'K Siva Prasad Reddy', 'LOCAL', CURRENT_TIMESTAMP()) 10 | ; 11 | 12 | INSERT INTO user_role (user_id, role_id) VALUES 13 | (1, 1), 14 | (1, 2), 15 | (1, 3) 16 | ; 17 | -------------------------------------------------------------------------------- /security/spring-boot-social-login/src/main/resources/db/migration/postgresql/V2__insert_sample_data.sql: -------------------------------------------------------------------------------- 1 | 2 | INSERT INTO roles (id, name, created_at) VALUES 3 | (1, 'ROLE_ADMIN', CURRENT_TIMESTAMP), 4 | (2, 'ROLE_MODERATOR', CURRENT_TIMESTAMP), 5 | (3, 'ROLE_USER', CURRENT_TIMESTAMP) 6 | ; 7 | 8 | INSERT INTO users (email, password, name, user_type, created_at) VALUES 9 | ('sivaprasadreddy.k@gmail.com', '$2a$10$qW08MYCgzkYNoFFXYHUqluGGyLtBJK/XAQtu0lmsjD2mWaUiPQeZ2', 'K Siva Prasad Reddy', 'LOCAL', CURRENT_TIMESTAMP) 10 | ; 11 | 12 | INSERT INTO user_role (user_id, role_id) VALUES 13 | (1, 1), 14 | (1, 2), 15 | (1, 3) 16 | ; 17 | -------------------------------------------------------------------------------- /security/spring-boot-social-login/src/main/resources/static/css/styles.css: -------------------------------------------------------------------------------- 1 | /* Sticky footer styles 2 | -------------------------------------------------- */ 3 | html { 4 | position: relative; 5 | min-height: 100%; 6 | } 7 | body { 8 | /* Margin bottom by footer height */ 9 | padding-top: 80px; 10 | margin-bottom: 80px; 11 | } 12 | .footer { 13 | position: absolute; 14 | bottom: 0; 15 | width: 100%; 16 | /* Set the fixed height of the footer here */ 17 | height: 60px; 18 | line-height: 60px; /* Vertically center the text there */ 19 | background-color: #f5f5f5; 20 | } 21 | 22 | a:link { 23 | text-decoration: none; 24 | font-weight: bolder; 25 | } -------------------------------------------------------------------------------- /security/spring-boot-social-login/src/main/resources/static/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sivaprasadreddy/spring-boot-tutorials/11b6fdbc89397122b61353c07c4b9eb34ee1a703/security/spring-boot-social-login/src/main/resources/static/favicon.ico -------------------------------------------------------------------------------- /security/spring-boot-social-login/src/main/resources/static/js/common.js: -------------------------------------------------------------------------------- 1 | $(function () { 2 | $('[data-toggle="tooltip"]').tooltip() 3 | }); 4 | -------------------------------------------------------------------------------- /security/spring-boot-social-login/src/main/resources/templates/error.html: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | Error 8 | 9 | 10 |
11 | 12 | 18 | 19 |
20 | 21 | 22 | -------------------------------------------------------------------------------- /security/spring-boot-social-login/src/test/resources/application-integration-test.properties: -------------------------------------------------------------------------------- 1 | spring.mail.password=pwd 2 | -------------------------------------------------------------------------------- /security/spring-boot-social-login/src/test/resources/bootstrap.properties: -------------------------------------------------------------------------------- 1 | embedded.postgresql.enabled=false 2 | -------------------------------------------------------------------------------- /security/spring-boot-social-login/src/test/resources/data/tags.csv: -------------------------------------------------------------------------------- 1 | tag 2 | java 3 | jpa 4 | spring 5 | -------------------------------------------------------------------------------- /security/spring-security-multi-config/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | /target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | 5 | ### STS ### 6 | .apt_generated 7 | .classpath 8 | .factorypath 9 | .project 10 | .settings 11 | .springBeans 12 | .sts4-cache 13 | 14 | ### IntelliJ IDEA ### 15 | .idea 16 | *.iws 17 | *.iml 18 | *.ipr 19 | 20 | ### NetBeans ### 21 | /nbproject/private/ 22 | /nbbuild/ 23 | /dist/ 24 | /nbdist/ 25 | /.nb-gradle/ 26 | /build/ 27 | 28 | ### VS Code ### 29 | .vscode/ 30 | -------------------------------------------------------------------------------- /security/spring-security-multi-config/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sivaprasadreddy/spring-boot-tutorials/11b6fdbc89397122b61353c07c4b9eb34ee1a703/security/spring-security-multi-config/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /security/spring-security-multi-config/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.0/apache-maven-3.6.0-bin.zip 2 | -------------------------------------------------------------------------------- /security/spring-security-multi-config/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM fabric8/java-alpine-openjdk8-jre 2 | VOLUME /tmp 3 | ADD target/spring-security-multi-config-0.0.1.jar app.jar 4 | RUN sh -c 'touch /app.jar' 5 | ENV JAVA_OPTS="-Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=8787,suspend=n" 6 | ENV SPRING_PROFILES_ACTIVE "docker" 7 | EXPOSE 8080 8787 8 | ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -Dspring.profiles.active=$SPRING_PROFILES_ACTIVE -jar /app.jar" ] 9 | -------------------------------------------------------------------------------- /security/spring-security-multi-config/README.md: -------------------------------------------------------------------------------- 1 | # todolist 2 | 3 | https://sivalabs-todolist.herokuapp.com 4 | -------------------------------------------------------------------------------- /security/spring-security-multi-config/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3.1' 2 | services: 3 | 4 | spring-security-multi-config: 5 | build: . 6 | container_name: spring-security-multi-config 7 | ports: 8 | - "8080:8080" 9 | - "8787:8787" 10 | restart: always 11 | depends_on: 12 | - todolist-db 13 | 14 | todolist-db: 15 | image: postgres:10.7 16 | container_name: todolist-db 17 | environment: 18 | - POSTGRES_USER=siva 19 | - POSTGRES_PASSWORD=secret 20 | - POSTGRES_DB=appdb 21 | - PGDATA=/data/postgres 22 | volumes: 23 | - ~/data/todolist-db:/data/postgres 24 | ports: 25 | - "5432:5432" 26 | restart: unless-stopped 27 | 28 | localstack: 29 | image: "localstack/localstack:0.8.7" 30 | environment: 31 | - SERVICES=dynamodb,kinesis,sqs,s3 32 | - DEFAULT_REGION=moon-central-1 33 | - DEBUG=1 34 | ports: 35 | - "4567-4583:4567-4583" 36 | -------------------------------------------------------------------------------- /security/spring-security-multi-config/src/main/java/com/sivalabs/todolist/TodoListApplication.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.todolist; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class TodoListApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(TodoListApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /security/spring-security-multi-config/src/main/java/com/sivalabs/todolist/entity/Role.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.todolist.entity; 2 | 3 | import lombok.Data; 4 | 5 | import javax.persistence.*; 6 | import javax.validation.constraints.NotEmpty; 7 | import java.io.Serializable; 8 | import java.util.List; 9 | 10 | @Entity 11 | @Table(name="roles") 12 | @Data 13 | public class Role implements Serializable 14 | { 15 | 16 | @Id 17 | @SequenceGenerator(name="role_generator", sequenceName="role_sequence", allocationSize = 1) 18 | @GeneratedValue(generator = "role_generator") 19 | private Long id; 20 | 21 | @Column(nullable=false, unique=true) 22 | @NotEmpty 23 | private String name; 24 | 25 | @ManyToMany(mappedBy="roles") 26 | private List users; 27 | 28 | } 29 | -------------------------------------------------------------------------------- /security/spring-security-multi-config/src/main/java/com/sivalabs/todolist/repo/TodoRepository.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.todolist.repo; 2 | 3 | import com.sivalabs.todolist.entity.Todo; 4 | import org.springframework.data.domain.Sort; 5 | import org.springframework.data.jpa.repository.JpaRepository; 6 | 7 | import java.util.List; 8 | 9 | public interface TodoRepository extends JpaRepository { 10 | List findByCreatedById(Long userId, Sort sort); 11 | } 12 | -------------------------------------------------------------------------------- /security/spring-security-multi-config/src/main/java/com/sivalabs/todolist/repo/UserRepository.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.todolist.repo; 2 | 3 | import com.sivalabs.todolist.entity.User; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | 6 | import java.util.Optional; 7 | 8 | public interface UserRepository extends JpaRepository { 9 | Optional findByEmail(String email); 10 | } 11 | -------------------------------------------------------------------------------- /security/spring-security-multi-config/src/main/java/com/sivalabs/todolist/web/controller/HomeController.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.todolist.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 index() { 11 | return "home"; 12 | } 13 | 14 | @GetMapping("/login") 15 | public String loginForm() { 16 | return "login"; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /security/spring-security-multi-config/src/main/resources/application-docker.properties: -------------------------------------------------------------------------------- 1 | spring.datasource.driver-class-name=org.postgresql.Driver 2 | spring.datasource.url=jdbc:postgresql://todolist-db:5432/appdb 3 | spring.datasource.username=siva 4 | spring.datasource.password=secret 5 | -------------------------------------------------------------------------------- /security/spring-security-multi-config/src/main/resources/application-heroku.properties: -------------------------------------------------------------------------------- 1 | spring.datasource.driver-class-name=org.postgresql.Driver 2 | spring.datasource.url=${JDBC_DATABASE_URL} 3 | -------------------------------------------------------------------------------- /security/spring-security-multi-config/src/main/resources/application-local.properties: -------------------------------------------------------------------------------- 1 | spring.datasource.driver-class-name=org.postgresql.Driver 2 | spring.datasource.url=jdbc:postgresql://localhost:5432/appdb 3 | spring.datasource.username=siva 4 | spring.datasource.password=secret 5 | -------------------------------------------------------------------------------- /security/spring-security-multi-config/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=TodoList 2 | logging.level.com.sivalabs=debug 3 | #logging.level.org.springframework.web.servlet.mvc.method.annotation=TRACE 4 | #logging.level.web=debug 5 | #spring.http.log-request-details=true 6 | management.endpoints.web.exposure.include=* 7 | spring.h2.console.enabled=true 8 | spring.jpa.show-sql=true 9 | spring.flyway.locations=classpath:/db/migration/{vendor} 10 | -------------------------------------------------------------------------------- /security/spring-security-multi-config/src/main/resources/db/migration/h2/V2__insert_sample_data.sql: -------------------------------------------------------------------------------- 1 | 2 | INSERT INTO roles (id, name, created_at) VALUES 3 | (1, 'ROLE_ADMIN', CURRENT_TIMESTAMP()), 4 | (2, 'ROLE_USER', CURRENT_TIMESTAMP()) 5 | ; 6 | 7 | INSERT INTO users (email, password, name, created_at) VALUES 8 | ('admin@gmail.com', '$2a$10$dPLX6R2rnU94KWmNokNILuxmxwkgPLM01/kbWWqb7ULIuG4qIJmpC', 'Admin', CURRENT_TIMESTAMP()), 9 | ('siva@gmail.com', '$2a$10$Ib73a9lzoX60I3UIlwm.8OSfbM8WQDaggieVDjxb1zoC6W/tJAA62', 'Siva', CURRENT_TIMESTAMP()) 10 | ; 11 | 12 | INSERT INTO user_role (user_id, role_id) VALUES 13 | (1, 1), 14 | (1, 2), 15 | (2, 2) 16 | ; 17 | 18 | 19 | INSERT INTO todos(content, created_by,created_at) VALUES 20 | ('Learn AWS',1,CURRENT_TIMESTAMP()), 21 | ('Learn SpringBoot',2,CURRENT_TIMESTAMP()) 22 | ; 23 | -------------------------------------------------------------------------------- /security/spring-security-multi-config/src/main/resources/db/migration/postgresql/V2__insert_sample_data.sql: -------------------------------------------------------------------------------- 1 | 2 | INSERT INTO roles (id, name, created_at) VALUES 3 | (1, 'ROLE_ADMIN', CURRENT_TIMESTAMP), 4 | (2, 'ROLE_USER', CURRENT_TIMESTAMP) 5 | ; 6 | 7 | INSERT INTO users (email, password, name, created_at) VALUES 8 | ('admin@gmail.com', '$2a$10$dPLX6R2rnU94KWmNokNILuxmxwkgPLM01/kbWWqb7ULIuG4qIJmpC', 'Admin', CURRENT_TIMESTAMP), 9 | ('siva@gmail.com', '$2a$10$Ib73a9lzoX60I3UIlwm.8OSfbM8WQDaggieVDjxb1zoC6W/tJAA62', 'Siva', CURRENT_TIMESTAMP) 10 | ; 11 | 12 | INSERT INTO user_role (user_id, role_id) VALUES 13 | (1, 1), 14 | (1, 2), 15 | (2, 2) 16 | ; 17 | 18 | INSERT INTO todos(content, created_by,created_at) VALUES 19 | ('Learn AWS',1,CURRENT_TIMESTAMP), 20 | ('Learn Spring',2,CURRENT_TIMESTAMP) 21 | ; 22 | -------------------------------------------------------------------------------- /security/spring-security-multi-config/src/main/resources/static/css/styles.css: -------------------------------------------------------------------------------- 1 | /* Sticky footer styles 2 | -------------------------------------------------- */ 3 | html { 4 | position: relative; 5 | min-height: 100%; 6 | } 7 | body { 8 | /* Margin bottom by footer height */ 9 | padding-top: 80px; 10 | margin-bottom: 80px; 11 | } 12 | .footer { 13 | position: absolute; 14 | bottom: 0; 15 | width: 100%; 16 | /* Set the fixed height of the footer here */ 17 | height: 60px; 18 | line-height: 60px; /* Vertically center the text there */ 19 | background-color: #f5f5f5; 20 | } 21 | -------------------------------------------------------------------------------- /security/spring-security-multi-config/src/test/java/com/sivalabs/todolist/TodoListApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.todolist; 2 | 3 | import org.junit.Test; 4 | 5 | public class TodoListApplicationTests extends AbstractIntegrationTest { 6 | 7 | @Test 8 | public void contextLoads() { 9 | } 10 | 11 | } 12 | -------------------------------------------------------------------------------- /security/spring-security-multi-config/src/test/java/com/sivalabs/todolist/utils/BCryptUtil.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.todolist.utils; 2 | 3 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; 4 | 5 | public class BCryptUtil { 6 | 7 | public static void main(String[] args) { 8 | BCryptPasswordEncoder encoder = new BCryptPasswordEncoder(); 9 | String[] secrets = { "admin", "siva"}; 10 | for (String secret : secrets) { 11 | System.out.println(secret+":"+encoder.encode(secret)); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /security/spring-security-oauth2-demo/README.md: -------------------------------------------------------------------------------- 1 | # spring-security-oauth2-demo 2 | Spring Security OAuth2 Demo application 3 | -------------------------------------------------------------------------------- /security/spring-security-oauth2-demo/auth-server/src/main/java/com/sivalabs/authserver/OAuth2ServerApplication.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.authserver; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class OAuth2ServerApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(OAuth2ServerApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /security/spring-security-oauth2-demo/auth-server/src/main/java/com/sivalabs/authserver/config/WebMvcConfig.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.authserver.config; 2 | 3 | import org.springframework.context.annotation.Configuration; 4 | import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; 5 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; 6 | 7 | @Configuration 8 | public class WebMvcConfig extends WebMvcConfigurerAdapter { 9 | @Override 10 | public void addViewControllers(ViewControllerRegistry registry) { 11 | registry.addViewController("login").setViewName("login"); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /security/spring-security-oauth2-demo/auth-server/src/main/java/com/sivalabs/authserver/repository/UserRepository.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.authserver.repository; 2 | 3 | import com.sivalabs.authserver.entity.UserAccount; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | 6 | import java.util.Optional; 7 | 8 | public interface UserRepository extends JpaRepository { 9 | Optional findByEmail(String email); 10 | } 11 | -------------------------------------------------------------------------------- /security/spring-security-oauth2-demo/auth-server/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=9090 2 | server.context-path=/authserver 3 | spring.h2.console.enabled=true 4 | spring.jpa.hibernate.ddl-auto=update 5 | spring.jpa.show-sql=true -------------------------------------------------------------------------------- /security/spring-security-oauth2-demo/auth-server/src/main/resources/data.sql: -------------------------------------------------------------------------------- 1 | 2 | INSERT INTO user_accounts(id, email, password,name, role) VALUES 3 | (1, 'admin@gmail.com', '$2a$10$Dtg53WwZQKElBGxc2.LbCO3Pcksiza4UlODNlx26HWKwKeiAPbMHi', 'Administrator', 'ROLE_ADMIN'), 4 | (2, 'siva@gmail.com', '$2a$10$PVtQlBOYqz53qZ.HDSW0JOBAZLUDLkmdPZ.wMCPM2euydVX3dyVfa', 'Siva', 'ROLE_USER') 5 | ; 6 | 7 | INSERT INTO oauth_client_details ( 8 | client_id, resource_ids, client_secret, scope, 9 | authorized_grant_types, web_server_redirect_uri, authorities, access_token_validity, 10 | refresh_token_validity, additional_information, autoapprove) 11 | VALUES 12 | ('client1', null, '$2a$10$bBxQ.2i7vzNEzfzd54W5j.e94C7/82EOtjhtmgj3qj7lCCHi8W8AW','read_catalog,read_promos', 13 | 'authorization_code,implicit,password,client_credentials,refresh_token','http://localhost:8080/ui/',null, 3000, -1, null, 'false'); -------------------------------------------------------------------------------- /security/spring-security-oauth2-demo/auth-server/src/test/java/com/sivalabs/authserver/OAuth2ServerApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.authserver; 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 OAuth2ServerApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /security/spring-security-oauth2-demo/auth-server/src/test/java/com/sivalabs/authserver/Utils.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.authserver; 2 | 3 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; 4 | 5 | import java.util.Arrays; 6 | import java.util.List; 7 | 8 | public class Utils { 9 | public static void main(String[] args) { 10 | List strings = Arrays.asList("client1secret", "siva","admin"); 11 | BCryptPasswordEncoder encoder = new BCryptPasswordEncoder(); 12 | strings.forEach( str -> { 13 | System.out.println("Plain: "+str+", encoded: "+encoder.encode(str)); 14 | }); 15 | 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /security/spring-security-oauth2-demo/catalog-service/.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/ -------------------------------------------------------------------------------- /security/spring-security-oauth2-demo/catalog-service/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sivaprasadreddy/spring-boot-tutorials/11b6fdbc89397122b61353c07c4b9eb34ee1a703/security/spring-security-oauth2-demo/catalog-service/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /security/spring-security-oauth2-demo/catalog-service/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.3/apache-maven-3.5.3-bin.zip 2 | -------------------------------------------------------------------------------- /security/spring-security-oauth2-demo/catalog-service/src/main/java/com/sivalabs/catalogservice/Product.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.catalogservice; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | @Data 8 | @NoArgsConstructor 9 | @AllArgsConstructor 10 | public class Product { 11 | private Long id; 12 | private String name; 13 | private double price; 14 | } 15 | -------------------------------------------------------------------------------- /security/spring-security-oauth2-demo/catalog-service/src/main/java/com/sivalabs/catalogservice/ProductDTO.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.catalogservice; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | @Data 8 | @NoArgsConstructor 9 | @AllArgsConstructor 10 | public class ProductDTO { 11 | private Long id; 12 | private String name; 13 | private double price; 14 | private String promotion; 15 | } 16 | -------------------------------------------------------------------------------- /security/spring-security-oauth2-demo/catalog-service/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=8181 2 | server.context-path=/catalog 3 | 4 | auth-server=http://localhost:9090/authserver 5 | security.oauth2.client.client-id=client1 6 | security.oauth2.client.client-secret=client1secret 7 | security.oauth2.client.scope=read_catalog 8 | security.oauth2.client.access-token-uri=${auth-server}/oauth/token 9 | security.oauth2.client.user-authorization-uri=${auth-server}/oauth/authorize 10 | security.oauth2.resource.user-info-uri=${auth-server}/userInfo 11 | -------------------------------------------------------------------------------- /security/spring-security-oauth2-demo/catalog-service/src/test/java/com/sivalabs/catalogservice/CatalogServiceApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.catalogservice; 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 CatalogServiceApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /security/spring-security-oauth2-demo/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.sivalabs 8 | spring-security-oauth2-demo 9 | 1.0-SNAPSHOT 10 | pom 11 | 12 | 13 | auth-server 14 | promotion-service 15 | catalog-service 16 | ui-zuul-app 17 | 18 | -------------------------------------------------------------------------------- /security/spring-security-oauth2-demo/promotion-service/.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/ -------------------------------------------------------------------------------- /security/spring-security-oauth2-demo/promotion-service/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sivaprasadreddy/spring-boot-tutorials/11b6fdbc89397122b61353c07c4b9eb34ee1a703/security/spring-security-oauth2-demo/promotion-service/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /security/spring-security-oauth2-demo/promotion-service/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.3/apache-maven-3.5.3-bin.zip 2 | -------------------------------------------------------------------------------- /security/spring-security-oauth2-demo/promotion-service/src/main/java/com/sivalabs/promotionservice/Promotion.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.promotionservice; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | @Data 8 | @NoArgsConstructor 9 | @AllArgsConstructor 10 | public class Promotion { 11 | private Long id; 12 | private Long productId; 13 | private String promoText; 14 | } 15 | -------------------------------------------------------------------------------- /security/spring-security-oauth2-demo/promotion-service/src/main/java/com/sivalabs/promotionservice/PromotionServiceApplication.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.promotionservice; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class PromotionServiceApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(PromotionServiceApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /security/spring-security-oauth2-demo/promotion-service/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=8282 2 | server.context-path=/promotions 3 | security.oauth2.resource.user-info-uri=http://localhost:9090/authserver/userInfo 4 | -------------------------------------------------------------------------------- /security/spring-security-oauth2-demo/promotion-service/src/test/java/com/sivalabs/promotionservice/PromotionServiceApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.promotionservice; 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 PromotionServiceApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /security/spring-security-oauth2-demo/ui-zuul-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/ -------------------------------------------------------------------------------- /security/spring-security-oauth2-demo/ui-zuul-app/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sivaprasadreddy/spring-boot-tutorials/11b6fdbc89397122b61353c07c4b9eb34ee1a703/security/spring-security-oauth2-demo/ui-zuul-app/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /security/spring-security-oauth2-demo/ui-zuul-app/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.3/apache-maven-3.5.3-bin.zip 2 | -------------------------------------------------------------------------------- /security/spring-security-oauth2-demo/ui-zuul-app/src/main/resources/templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | ShoppingCart 6 | 7 | 8 |
9 |
10 |

Product Name: name

11 |
12 |
13 | 14 | 26 | 27 | -------------------------------------------------------------------------------- /security/spring-security-oauth2-demo/ui-zuul-app/src/test/java/com/sivalabs/uizuulapp/UiZuulAppApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.uizuulapp; 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 UiZuulAppApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /spring-boot-aws-demo/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | .gradle 3 | /build/ 4 | !gradle/wrapper/gradle-wrapper.jar 5 | 6 | ### STS ### 7 | .apt_generated 8 | .classpath 9 | .factorypath 10 | .project 11 | .settings 12 | .springBeans 13 | .sts4-cache 14 | 15 | ### IntelliJ IDEA ### 16 | .idea 17 | *.iws 18 | *.iml 19 | *.ipr 20 | /out/ 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | 29 | ### VS Code ### 30 | .vscode/ 31 | -------------------------------------------------------------------------------- /spring-boot-aws-demo/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sivaprasadreddy/spring-boot-tutorials/11b6fdbc89397122b61353c07c4b9eb34ee1a703/spring-boot-aws-demo/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /spring-boot-aws-demo/.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 | -------------------------------------------------------------------------------- /spring-boot-aws-demo/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM fabric8/java-alpine-openjdk8-jre 2 | VOLUME /tmp 3 | ADD target/spring-boot-aws-demo-0.0.1.jar app.jar 4 | RUN sh -c 'touch /app.jar' 5 | ENV JAVA_OPTS="-Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=8787,suspend=n" 6 | ENV SPRING_PROFILES_ACTIVE "docker" 7 | EXPOSE 8080 8787 8 | ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -Dspring.profiles.active=$SPRING_PROFILES_ACTIVE -jar /app.jar" ] 9 | -------------------------------------------------------------------------------- /spring-boot-aws-demo/README.md: -------------------------------------------------------------------------------- 1 | # Demo Application 2 | 3 | Start localstck using docker on MacOS: 4 | 5 | `TMPDIR=/private$TMPDIR docker-compose up` -------------------------------------------------------------------------------- /spring-boot-aws-demo/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3.1' 2 | services: 3 | 4 | spring-boot-aws-demo: 5 | build: . 6 | container_name: spring-boot-aws-demo 7 | ports: 8 | - "8080:8080" 9 | - "8787:8787" 10 | restart: always 11 | depends_on: 12 | - postgresdb 13 | 14 | postgresdb: 15 | image: postgres:10.7 16 | container_name: postgresdb 17 | environment: 18 | - POSTGRES_USER=siva 19 | - POSTGRES_PASSWORD=secret 20 | - POSTGRES_DB=appdb 21 | - PGDATA=/data/postgres 22 | volumes: 23 | - ~/data/demo-postgres:/data/postgres 24 | ports: 25 | - "5432:5432" 26 | restart: unless-stopped 27 | 28 | localstack: 29 | image: "localstack/localstack:0.8.7" 30 | environment: 31 | - SERVICES=dynamodb,kinesis,sqs,s3 32 | - DEFAULT_REGION=moon-central-1 33 | - DEBUG=1 34 | ports: 35 | - "4567-4583:4567-4583" 36 | -------------------------------------------------------------------------------- /spring-boot-aws-demo/src/main/java/com/sivalabs/myapp/SpringBootAwsDemoApplication.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.myapp; 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 | @SpringBootApplication 9 | @EnableScheduling 10 | @EnableAsync 11 | public class SpringBootAwsDemoApplication { 12 | 13 | public static void main(String[] args) { 14 | SpringApplication.run(SpringBootAwsDemoApplication.class, args); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /spring-boot-aws-demo/src/main/java/com/sivalabs/myapp/entity/Message.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.myapp.entity; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Getter; 5 | import lombok.NoArgsConstructor; 6 | import lombok.Setter; 7 | 8 | import javax.persistence.*; 9 | import java.time.LocalDateTime; 10 | 11 | @Entity 12 | @Setter 13 | @Getter 14 | @NoArgsConstructor 15 | @AllArgsConstructor 16 | public class Message { 17 | @Id @GeneratedValue(strategy = GenerationType.AUTO) 18 | private Long id; 19 | @Column(nullable = false) 20 | private String text; 21 | private LocalDateTime createdOn = LocalDateTime.now(); 22 | 23 | } 24 | -------------------------------------------------------------------------------- /spring-boot-aws-demo/src/main/java/com/sivalabs/myapp/repo/MessageRepository.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.myapp.repo; 2 | 3 | import com.sivalabs.myapp.entity.Message; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | 6 | public interface MessageRepository extends JpaRepository { 7 | } 8 | -------------------------------------------------------------------------------- /spring-boot-aws-demo/src/main/java/com/sivalabs/myapp/service/TweetRecordProcessorFactory.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.myapp.service; 2 | 3 | import com.amazonaws.services.kinesis.clientlibrary.interfaces.v2.IRecordProcessor; 4 | import com.amazonaws.services.kinesis.clientlibrary.interfaces.v2.IRecordProcessorFactory; 5 | 6 | public class TweetRecordProcessorFactory implements IRecordProcessorFactory { 7 | 8 | @Override 9 | public IRecordProcessor createProcessor() { 10 | return new TweetRecordProcessor(); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /spring-boot-aws-demo/src/main/java/com/sivalabs/myapp/service/TweetStreamListener.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.myapp.service; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.stereotype.Component; 5 | 6 | import javax.annotation.PostConstruct; 7 | import javax.annotation.PreDestroy; 8 | import java.net.UnknownHostException; 9 | 10 | @Component 11 | public class TweetStreamListener { 12 | private final TweetStreamWorker tweetStreamWorker; 13 | 14 | @Autowired 15 | public TweetStreamListener(TweetStreamWorker tweetStreamWorker) { 16 | this.tweetStreamWorker = tweetStreamWorker; 17 | } 18 | 19 | @PostConstruct 20 | public void init() throws UnknownHostException { 21 | tweetStreamWorker.startTweetConsumer(); 22 | } 23 | 24 | @PreDestroy 25 | public void destroy() { 26 | tweetStreamWorker.destroyTweetConsumer(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /spring-boot-aws-demo/src/main/resources/application-docker.properties: -------------------------------------------------------------------------------- 1 | spring.datasource.driver-class-name=org.postgresql.Driver 2 | spring.datasource.url=jdbc:postgresql://postgresdb:5432/appdb 3 | spring.datasource.username=siva 4 | spring.datasource.password=secret 5 | -------------------------------------------------------------------------------- /spring-boot-aws-demo/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.thymeleaf.cache=false 2 | spring.datasource.initialization-mode=always 3 | spring.jpa.hibernate.ddl-auto=update 4 | spring.jpa.show-sql=true 5 | 6 | #cloud.aws.credentials.access-key=************** 7 | #cloud.aws.credentials.secret-key=***************** 8 | #cloud.aws.region.static=ap-south-1 9 | #cloud.aws.stack.auto=false 10 | 11 | #cloud.aws.rds.springawsdemodb.readReplicaSupport=false 12 | #cloud.aws.rds.springawsdemodb.username=sivalabs 13 | #cloud.aws.rds.springawsdemodb.password=Dreams2019 14 | #cloud.aws.rds.springawsdemodb.databaseName=mydemopgdb 15 | 16 | #debug=true 17 | 18 | server.port=9090 19 | 20 | localstack.sqs.port=4576 21 | localstack.s3.port=4572 22 | localstack.dynamodb.port=4569 23 | localstack.kinesis.port=4568 24 | localstack.sns.port=4575 25 | localstack.cloudwatch.port=4582 26 | 27 | localstack.aws.region=india-east-1 28 | -------------------------------------------------------------------------------- /spring-boot-aws-demo/src/main/resources/static/css/styles.css: -------------------------------------------------------------------------------- 1 | body { 2 | padding-top: 80px; 3 | } 4 | -------------------------------------------------------------------------------- /spring-boot-aws-demo/src/test/java/com/sivalabs/myapp/AbstractIntegrationTest.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.myapp; 2 | 3 | import org.junit.runner.RunWith; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | import org.springframework.test.context.junit4.SpringRunner; 6 | 7 | import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; 8 | 9 | @RunWith(SpringRunner.class) 10 | @SpringBootTest(webEnvironment = RANDOM_PORT) 11 | public abstract class AbstractIntegrationTest { 12 | 13 | 14 | } 15 | -------------------------------------------------------------------------------- /spring-boot-aws-demo/src/test/java/com/sivalabs/myapp/SpringBootAwsDemoApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.myapp; 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 SpringBootAwsDemoApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /spring-boot-grpc-demo/.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 | -------------------------------------------------------------------------------- /spring-boot-grpc-demo/grpc-interfaces/src/main/proto/helloworld.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package com.sivalabs.grpc.demo; 4 | 5 | option java_multiple_files = true; 6 | option java_package = "com.sivalabs.grpc.demo"; 7 | option java_outer_classname = "HelloWorldProto"; 8 | 9 | // The greeting service definition. 10 | service HelloService { 11 | // Sends a greeting 12 | rpc sayHello (HelloRequest) returns (HelloResponse) { 13 | } 14 | } 15 | 16 | // The request message containing the user's name. 17 | message HelloRequest { 18 | string name = 1; 19 | } 20 | 21 | // The response message containing the greetings 22 | message HelloResponse { 23 | string message = 1; 24 | } -------------------------------------------------------------------------------- /spring-boot-grpc-demo/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.sivalabs 8 | spring-boot-grpc-demo 9 | 1.0.0 10 | pom 11 | 12 | grpc-interfaces 13 | spring-boot-grpc-server 14 | spring-boot-grpc-client 15 | 16 | 17 | -------------------------------------------------------------------------------- /spring-boot-grpc-demo/spring-boot-grpc-client/.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 | -------------------------------------------------------------------------------- /spring-boot-grpc-demo/spring-boot-grpc-client/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sivaprasadreddy/spring-boot-tutorials/11b6fdbc89397122b61353c07c4b9eb34ee1a703/spring-boot-grpc-demo/spring-boot-grpc-client/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /spring-boot-grpc-demo/spring-boot-grpc-client/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.1/apache-maven-3.8.1-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar 3 | -------------------------------------------------------------------------------- /spring-boot-grpc-demo/spring-boot-grpc-client/src/main/java/com/sivalabs/grpcclient/GrpcClientController.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.grpcclient; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | import org.springframework.web.bind.annotation.RequestParam; 6 | import org.springframework.web.bind.annotation.RestController; 7 | 8 | import java.util.Map; 9 | 10 | @RestController 11 | public class GrpcClientController { 12 | 13 | @Autowired 14 | private GrpcClientService grpcClientService; 15 | 16 | @RequestMapping("/") 17 | public Map printMessage(@RequestParam(defaultValue = "Siva") String name) { 18 | return Map.of("reply", grpcClientService.receiveGreeting(name).getMessage()); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /spring-boot-grpc-demo/spring-boot-grpc-client/src/main/java/com/sivalabs/grpcclient/GrpcClientService.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.grpcclient; 2 | 3 | 4 | import com.sivalabs.grpc.demo.HelloRequest; 5 | import com.sivalabs.grpc.demo.HelloResponse; 6 | import com.sivalabs.grpc.demo.HelloServiceGrpc; 7 | import net.devh.boot.grpc.client.inject.GrpcClient; 8 | import org.springframework.stereotype.Service; 9 | 10 | @Service 11 | public class GrpcClientService { 12 | 13 | @GrpcClient("local-grpc-server") 14 | private HelloServiceGrpc.HelloServiceBlockingStub helloServiceStub; 15 | 16 | public HelloResponse receiveGreeting(String name) { 17 | HelloRequest request = HelloRequest.newBuilder() 18 | .setName(name) 19 | .build(); 20 | return helloServiceStub.sayHello(request); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /spring-boot-grpc-demo/spring-boot-grpc-client/src/main/java/com/sivalabs/grpcclient/SpringBootGrpcClientApplication.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.grpcclient; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SpringBootGrpcClientApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SpringBootGrpcClientApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /spring-boot-grpc-demo/spring-boot-grpc-client/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8080 3 | spring: 4 | application: 5 | name: spring-boot--grpc-client 6 | 7 | grpc: 8 | client: 9 | local-grpc-server: 10 | address: 'static://127.0.0.1:9898' 11 | enableKeepAlive: true 12 | keepAliveWithoutCalls: true 13 | negotiationType: plaintext -------------------------------------------------------------------------------- /spring-boot-grpc-demo/spring-boot-grpc-server/.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 | -------------------------------------------------------------------------------- /spring-boot-grpc-demo/spring-boot-grpc-server/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sivaprasadreddy/spring-boot-tutorials/11b6fdbc89397122b61353c07c4b9eb34ee1a703/spring-boot-grpc-demo/spring-boot-grpc-server/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /spring-boot-grpc-demo/spring-boot-grpc-server/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.1/apache-maven-3.8.1-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar 3 | -------------------------------------------------------------------------------- /spring-boot-grpc-demo/spring-boot-grpc-server/src/main/java/com/sivalabs/grpcserver/HelloServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.grpcserver; 2 | 3 | import com.sivalabs.grpc.demo.HelloRequest; 4 | import com.sivalabs.grpc.demo.HelloResponse; 5 | import com.sivalabs.grpc.demo.HelloServiceGrpc; 6 | import io.grpc.stub.StreamObserver; 7 | import net.devh.boot.grpc.server.service.GrpcService; 8 | 9 | @GrpcService 10 | public class HelloServiceImpl extends HelloServiceGrpc.HelloServiceImplBase { 11 | 12 | @Override 13 | public void sayHello(HelloRequest request, StreamObserver responseObserver) { 14 | HelloResponse reply = HelloResponse.newBuilder() 15 | .setMessage("Hello ==> " + request.getName()) 16 | .build(); 17 | responseObserver.onNext(reply); 18 | responseObserver.onCompleted(); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /spring-boot-grpc-demo/spring-boot-grpc-server/src/main/java/com/sivalabs/grpcserver/SpringBootGrpcServerApplication.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.grpcserver; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SpringBootGrpcServerApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SpringBootGrpcServerApplication.class, args); 11 | 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /spring-boot-grpc-demo/spring-boot-grpc-server/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | grpc.server.port=9898 2 | -------------------------------------------------------------------------------- /spring-boot-grpc-demo/spring-boot-grpc-server/src/test/java/com/sivalabs/grpcserver/SpringBootGrpcServerApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.grpcserver; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class SpringBootGrpcServerApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /spring-boot-k8s-demo/.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/ -------------------------------------------------------------------------------- /spring-boot-k8s-demo/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sivaprasadreddy/spring-boot-tutorials/11b6fdbc89397122b61353c07c4b9eb34ee1a703/spring-boot-k8s-demo/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /spring-boot-k8s-demo/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.3/apache-maven-3.5.3-bin.zip 2 | -------------------------------------------------------------------------------- /spring-boot-k8s-demo/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM frolvlad/alpine-oraclejdk8:slim 2 | VOLUME /tmp 3 | ADD target/spring-boot-k8s-demo-1.0.0-SNAPSHOT-exec.jar app.jar 4 | RUN sh -c 'touch /app.jar' 5 | ENV JAVA_OPTS="-Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=8787,suspend=n" 6 | ENV SPRING_PROFILES_ACTIVE "docker" 7 | EXPOSE 8080 8787 8 | ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -Dspring.profiles.active=$SPRING_PROFILES_ACTIVE -jar /app.jar" ] 9 | -------------------------------------------------------------------------------- /spring-boot-k8s-demo/Procfile: -------------------------------------------------------------------------------- 1 | web java -Dserver.port=$PORT -Dspring.profiles.active=heroku $JAVA_OPTS -jar target/spring-boot-k8s-demo-1.0.0-SNAPSHOT-exec.jar 2 | -------------------------------------------------------------------------------- /spring-boot-k8s-demo/docker-compose-platform.yml: -------------------------------------------------------------------------------- 1 | version: '3.1' 2 | services: 3 | jenkins-blueocean: 4 | image: jenkinsci/blueocean 5 | container_name: jenkins-blueocean 6 | ports: 7 | - "7070:8080" 8 | - "50000:50000" 9 | volumes: 10 | - ~/docker/jenkins_home:/var/jenkins_home 11 | - /var/run/docker.sock:/var/run/docker.sock -------------------------------------------------------------------------------- /spring-boot-k8s-demo/docs/images/App-metrics-grafana.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sivaprasadreddy/spring-boot-tutorials/11b6fdbc89397122b61353c07c4b9eb34ee1a703/spring-boot-k8s-demo/docs/images/App-metrics-grafana.png -------------------------------------------------------------------------------- /spring-boot-k8s-demo/docs/images/JVM-Micrometer-grafana.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sivaprasadreddy/spring-boot-tutorials/11b6fdbc89397122b61353c07c4b9eb34ee1a703/spring-boot-k8s-demo/docs/images/JVM-Micrometer-grafana.png -------------------------------------------------------------------------------- /spring-boot-k8s-demo/gc.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | declare project_dir=$(dirname $0) 4 | declare docker_compose_file=${project_dir}/docker-compose.yml 5 | declare geeksclub="geeksclub" 6 | 7 | function start() { 8 | echo 'Starting GeeksClub....' 9 | build_api 10 | docker-compose -f ${docker_compose_file} up --build --force-recreate -d ${geeksclub} 11 | docker-compose -f ${docker_compose_file} logs -f 12 | } 13 | 14 | function stop() { 15 | echo 'Stopping GeeksClub....' 16 | docker-compose -f ${docker_compose_file} stop 17 | docker-compose -f ${docker_compose_file} rm -f 18 | } 19 | 20 | function build_api() { 21 | ./mvnw clean package -DskipTests 22 | } 23 | 24 | action="start" 25 | 26 | if [ $1 != "0" ] 27 | then 28 | action=$@ 29 | fi 30 | 31 | eval ${action} -------------------------------------------------------------------------------- /spring-boot-k8s-demo/gcp.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | declare project_dir=$(dirname $0) 4 | declare docker_compose_file=${project_dir}/docker-compose-platform.yml 5 | 6 | 7 | function start() { 8 | echo 'Starting GeeksClub Platform....' 9 | docker-compose -f ${docker_compose_file} up -d 10 | docker-compose -f ${docker_compose_file} logs -f 11 | } 12 | 13 | function stop() { 14 | echo 'Stopping GeeksClub Platform....' 15 | docker-compose -f ${docker_compose_file} stop 16 | docker-compose -f ${docker_compose_file} rm -f 17 | } 18 | 19 | action="start" 20 | 21 | if [ $1 != "0" ] 22 | then 23 | action=$@ 24 | fi 25 | 26 | eval ${action} -------------------------------------------------------------------------------- /spring-boot-k8s-demo/manifest.yml: -------------------------------------------------------------------------------- 1 | --- 2 | applications: 3 | - name: spring-boot-k8s-demo 4 | buildpack: java_buildpack 5 | path: target/spring-boot-k8s-demo-1.0.0-SNAPSHOT-exec.jar 6 | services: 7 | - geeksclubdb 8 | -------------------------------------------------------------------------------- /spring-boot-k8s-demo/src/integration-test/resources/application-it.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sivaprasadreddy/spring-boot-tutorials/11b6fdbc89397122b61353c07c4b9eb34ee1a703/spring-boot-k8s-demo/src/integration-test/resources/application-it.properties -------------------------------------------------------------------------------- /spring-boot-k8s-demo/src/main/kotlin/com/sivalabs/geeksclub/config/CloudFoundryConfig.kt: -------------------------------------------------------------------------------- 1 | package com.sivalabs.geeksclub.config 2 | 3 | import org.springframework.cloud.config.java.AbstractCloudConfig 4 | import org.springframework.context.annotation.Bean 5 | import org.springframework.context.annotation.Configuration 6 | import org.springframework.context.annotation.Profile 7 | import javax.sql.DataSource 8 | 9 | @Configuration 10 | @Profile("cloud") 11 | class CloudFoundryConfig : AbstractCloudConfig() { 12 | @Bean 13 | fun dataSource(): DataSource { 14 | return connectionFactory().dataSource() 15 | } 16 | } -------------------------------------------------------------------------------- /spring-boot-k8s-demo/src/main/kotlin/com/sivalabs/geeksclub/config/WebMvcConfig.kt: -------------------------------------------------------------------------------- 1 | package com.sivalabs.geeksclub.config 2 | 3 | import org.springframework.context.annotation.Bean 4 | import org.springframework.context.annotation.Configuration 5 | import org.springframework.web.servlet.config.annotation.ViewControllerRegistry 6 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer 7 | import org.thymeleaf.extras.springsecurity4.dialect.SpringSecurityDialect 8 | 9 | @Configuration 10 | class WebMvcConfig : WebMvcConfigurer { 11 | 12 | override fun addViewControllers(registry: ViewControllerRegistry) { 13 | registry.addViewController("/login").setViewName("login") 14 | registry.addViewController("/registration_status").setViewName("registration_status") 15 | } 16 | 17 | @Bean 18 | fun securityDialect(): SpringSecurityDialect { 19 | return SpringSecurityDialect() 20 | } 21 | } -------------------------------------------------------------------------------- /spring-boot-k8s-demo/src/main/kotlin/com/sivalabs/geeksclub/entities/Category.kt: -------------------------------------------------------------------------------- 1 | package com.sivalabs.geeksclub.entities 2 | 3 | import javax.persistence.* 4 | 5 | @Entity 6 | @Table(name = "categories") 7 | class Category { 8 | @Id 9 | @SequenceGenerator(name = "cat_generator", sequenceName = "cat_sequence", initialValue = 100) 10 | @GeneratedValue(generator = "cat_generator") 11 | var id: Long? = null 12 | 13 | @Column(nullable = false, unique = true) 14 | var name: String = "" 15 | 16 | @Column(nullable = false, unique = true) 17 | var label: String = "" 18 | 19 | override fun toString(): String { 20 | return "Category(id=$id, name='$name', label='$label')" 21 | } 22 | 23 | } -------------------------------------------------------------------------------- /spring-boot-k8s-demo/src/main/kotlin/com/sivalabs/geeksclub/security/SecurityUser.kt: -------------------------------------------------------------------------------- 1 | package com.sivalabs.geeksclub.security 2 | 3 | import com.sivalabs.geeksclub.entities.User 4 | import org.springframework.security.core.GrantedAuthority 5 | import org.springframework.security.core.authority.AuthorityUtils 6 | import org.springframework.security.core.userdetails.UserDetails 7 | 8 | class SecurityUser(val user: User) : UserDetails { 9 | 10 | override fun getUsername() = user.email 11 | 12 | override fun getPassword()= user.password 13 | 14 | override fun getAuthorities(): MutableList = AuthorityUtils.createAuthorityList(user.role) 15 | 16 | override fun isEnabled() = true 17 | override fun isCredentialsNonExpired() = true 18 | override fun isAccountNonExpired() = true 19 | override fun isAccountNonLocked() = true 20 | } -------------------------------------------------------------------------------- /spring-boot-k8s-demo/src/main/kotlin/com/sivalabs/geeksclub/security/SecurityUtils.kt: -------------------------------------------------------------------------------- 1 | package com.sivalabs.geeksclub.security 2 | 3 | import org.springframework.security.core.context.SecurityContextHolder 4 | import org.springframework.security.core.userdetails.UserDetails 5 | import java.util.* 6 | 7 | object SecurityUtils { 8 | 9 | fun loggedinUser() : Optional { 10 | val authentication = SecurityContextHolder.getContext().authentication 11 | return if (authentication != null && authentication.principal is UserDetails) { 12 | Optional.of(authentication.principal as UserDetails) 13 | } else Optional.empty() 14 | } 15 | } -------------------------------------------------------------------------------- /spring-boot-k8s-demo/src/main/kotlin/com/sivalabs/geeksclub/techfeed/CategoryRepository.kt: -------------------------------------------------------------------------------- 1 | package com.sivalabs.geeksclub.techfeed 2 | 3 | import com.sivalabs.geeksclub.entities.Category 4 | import org.springframework.data.jpa.repository.JpaRepository 5 | import java.util.* 6 | 7 | interface CategoryRepository : JpaRepository { 8 | 9 | fun findByName(name: String): Optional 10 | } -------------------------------------------------------------------------------- /spring-boot-k8s-demo/src/main/kotlin/com/sivalabs/geeksclub/techfeed/LinkDTO.kt: -------------------------------------------------------------------------------- 1 | package com.sivalabs.geeksclub.techfeed 2 | 3 | import com.sivalabs.geeksclub.entities.Link 4 | import java.time.LocalDateTime 5 | 6 | data class LinkDTO (val id : Long?, 7 | val title : String, 8 | val url : String, 9 | val createdOn : LocalDateTime, 10 | val createdUserId: Long?, 11 | val createdUserName: String, 12 | val createdUserEmail: String, 13 | val tags: List 14 | ) 15 | { 16 | constructor(link: Link) : this( 17 | link.id, 18 | link.title, 19 | link.url, 20 | link.createdOn, 21 | link.createdBy.id, 22 | link.createdBy.name, 23 | link.createdBy.email, 24 | link.tags.map { it.name } 25 | ) 26 | } -------------------------------------------------------------------------------- /spring-boot-k8s-demo/src/main/kotlin/com/sivalabs/geeksclub/techfeed/LinkRepository.kt: -------------------------------------------------------------------------------- 1 | package com.sivalabs.geeksclub.techfeed 2 | 3 | import com.sivalabs.geeksclub.entities.Link 4 | import org.springframework.data.domain.Sort 5 | import org.springframework.data.jpa.repository.JpaRepository 6 | 7 | interface LinkRepository : JpaRepository { 8 | 9 | fun findByTitleContainingIgnoreCase(q: String, sort: Sort): List 10 | 11 | fun findByCreatedById(userId: Long): List 12 | 13 | fun findByCategoryIdAndTitleContainingIgnoreCase(catId: Long, query: String): List 14 | } -------------------------------------------------------------------------------- /spring-boot-k8s-demo/src/main/kotlin/com/sivalabs/geeksclub/techfeed/NewLinkDTO.kt: -------------------------------------------------------------------------------- 1 | package com.sivalabs.geeksclub.techfeed 2 | 3 | import com.sivalabs.geeksclub.entities.Category 4 | import com.sivalabs.geeksclub.entities.User 5 | 6 | class NewLinkDTO { 7 | var title : String = "" 8 | var url : String = "" 9 | var tags: String = "" 10 | var category: Category = Category() 11 | var createdBy : User = User() 12 | } -------------------------------------------------------------------------------- /spring-boot-k8s-demo/src/main/kotlin/com/sivalabs/geeksclub/techfeed/TagRepository.kt: -------------------------------------------------------------------------------- 1 | package com.sivalabs.geeksclub.techfeed 2 | 3 | import com.sivalabs.geeksclub.entities.Tag 4 | import org.springframework.data.jpa.repository.JpaRepository 5 | import java.util.* 6 | 7 | interface TagRepository : JpaRepository { 8 | fun findByName(tag: String): Optional 9 | } -------------------------------------------------------------------------------- /spring-boot-k8s-demo/src/main/kotlin/com/sivalabs/geeksclub/users/UserProfile.kt: -------------------------------------------------------------------------------- 1 | package com.sivalabs.geeksclub.users 2 | 3 | import com.sivalabs.geeksclub.entities.Link 4 | 5 | data class UserProfile ( 6 | val id: Long, 7 | val name: String, 8 | val email: String, 9 | val website: String = "", 10 | val bio: String = "", 11 | val postedLinks: List = listOf() 12 | ) -------------------------------------------------------------------------------- /spring-boot-k8s-demo/src/main/kotlin/com/sivalabs/geeksclub/users/UserRepository.kt: -------------------------------------------------------------------------------- 1 | package com.sivalabs.geeksclub.users 2 | 3 | import com.sivalabs.geeksclub.entities.User 4 | import org.springframework.data.jpa.repository.JpaRepository 5 | import java.util.* 6 | 7 | interface UserRepository : JpaRepository { 8 | fun findByEmail(username: String): Optional 9 | } -------------------------------------------------------------------------------- /spring-boot-k8s-demo/src/main/resources/static/images/user.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sivaprasadreddy/spring-boot-tutorials/11b6fdbc89397122b61353c07c4b9eb34ee1a703/spring-boot-k8s-demo/src/main/resources/static/images/user.jpg -------------------------------------------------------------------------------- /spring-boot-k8s-demo/src/main/resources/static/images/user.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sivaprasadreddy/spring-boot-tutorials/11b6fdbc89397122b61353c07c4b9eb34ee1a703/spring-boot-k8s-demo/src/main/resources/static/images/user.png -------------------------------------------------------------------------------- /spring-boot-k8s-demo/src/main/resources/static/styles.css: -------------------------------------------------------------------------------- 1 | body { 2 | padding-top: 75px; 3 | } 4 | 5 | .link-author { 6 | font-size: 14px; 7 | } -------------------------------------------------------------------------------- /spring-boot-k8s-demo/src/main/resources/templates/registration_status.html: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | Registration 10 | 11 | 12 | 13 |
14 |
15 | 19 |
20 |
21 | 22 | -------------------------------------------------------------------------------- /spring-boot-k8s-demo/src/test/kotlin/com/sivalabs/geeksclub/SampleTest.kt: -------------------------------------------------------------------------------- 1 | package com.sivalabs.geeksclub 2 | 3 | import org.junit.Test 4 | 5 | import org.junit.Assert.assertTrue 6 | 7 | class SampleTest { 8 | @Test 9 | fun dummyTest() { 10 | assertTrue(true) 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /spring-boot-k8s-demo/src/test/resources/application-test.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sivaprasadreddy/spring-boot-tutorials/11b6fdbc89397122b61353c07c4b9eb34ee1a703/spring-boot-k8s-demo/src/test/resources/application-test.properties -------------------------------------------------------------------------------- /spring-boot-k8s-demo/support/prometheus.yml: -------------------------------------------------------------------------------- 1 | scrape_configs: 2 | - job_name: 'prometheus' 3 | scrape_interval: 10s 4 | static_configs: 5 | - targets: ['localhost:9090'] 6 | 7 | - job_name: 'geeksclub-local' 8 | scrape_interval: 10s 9 | metrics_path: '/actuator/prometheus' 10 | static_configs: 11 | - targets: ['ks-macbook-pro.local:18080'] 12 | 13 | - job_name: 'geeksclub-docker' 14 | scrape_interval: 10s 15 | metrics_path: '/actuator/prometheus' 16 | static_configs: 17 | - targets: ['geeksclub:8080'] 18 | -------------------------------------------------------------------------------- /spring-boot-quartz-demo/.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 | -------------------------------------------------------------------------------- /spring-boot-quartz-demo/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sivaprasadreddy/spring-boot-tutorials/11b6fdbc89397122b61353c07c4b9eb34ee1a703/spring-boot-quartz-demo/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /spring-boot-quartz-demo/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar 3 | -------------------------------------------------------------------------------- /spring-boot-quartz-demo/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | vmargs="-Duser.timezone=GMT" 4 | nohup java $vmargs -jar target/demo-0.0.1-SNAPSHOT.jar -Xms1G -Xmx3G > nohup.out & -------------------------------------------------------------------------------- /spring-boot-quartz-demo/src/main/java/com/example/demo/Person.java: -------------------------------------------------------------------------------- 1 | package com.example.demo; 2 | 3 | import javax.persistence.Entity; 4 | import javax.persistence.GeneratedValue; 5 | import javax.persistence.GenerationType; 6 | import javax.persistence.Id; 7 | import lombok.Getter; 8 | import lombok.Setter; 9 | 10 | @Entity 11 | @Setter 12 | @Getter 13 | public class Person { 14 | @Id 15 | @GeneratedValue(strategy = GenerationType.IDENTITY) 16 | private Long id; 17 | 18 | private int age; 19 | } 20 | -------------------------------------------------------------------------------- /spring-boot-quartz-demo/src/main/java/com/example/demo/PersonRepo.java: -------------------------------------------------------------------------------- 1 | package com.example.demo; 2 | 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | 5 | public interface PersonRepo extends JpaRepository { 6 | 7 | } 8 | -------------------------------------------------------------------------------- /spring-boot-quartz-demo/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.datasource.driver-class-name=org.postgresql.Driver 2 | spring.datasource.url=jdbc:postgresql://localhost:5432/postgres 3 | spring.datasource.username=postgres 4 | spring.datasource.password=postgres 5 | spring.jpa.show-sql=true 6 | spring.datasource.initialization-mode=always 7 | 8 | ## QuartzProperties 9 | spring.quartz.job-store-type=jdbc 10 | spring.quartz.jdbc.schema=classpath:org/quartz/impl/jdbcjobstore/tables_postgres.sql 11 | spring.quartz.jdbc.initialize-schema=always 12 | spring.quartz.properties.org.quartz.threadPool.threadCount=5 13 | spring.quartz.properties.org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.PostgreSQLDelegate 14 | spring.quartz.properties.org.quartz.jobStore.isClustered=true 15 | spring.quartz.properties.org.quartz.scheduler.instanceId=AUTO 16 | spring.quartz.properties.org.quartz.jobStore.clusterCheckinInterval=20000 17 | 18 | -------------------------------------------------------------------------------- /spring-boot-quartz-demo/src/test/java/com/example/demo/DemoApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.example.demo; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class DemoApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /spring-cloud/README.md: -------------------------------------------------------------------------------- 1 | # Spring Cloud Tutorial 2 | 3 | Config Repository: https://github.com/sivaprasadreddy/config-repo.git 4 | 5 | ### Spring Cloud Config Server 6 | 7 | `> cd spring-cloud-config-server` 8 | 9 | `> mvn spring-boot:run` 10 | 11 | Access http://localhost:8888/catalogservice/default or http://localhost:8888/catalogservice/prod 12 | 13 | 14 | ### Catalog Service 15 | 16 | `> cd catalog-service` 17 | 18 | `> mvn spring-boot:run` 19 | 20 | Access http://localhost:8181/env 21 | 22 | ### Order Service 23 | 24 | `> cd order-service` 25 | 26 | `> mvn spring-boot:run` 27 | 28 | Access http://localhost:8282/env 29 | 30 | 31 | To reload configuration changes you can trigger POST - http://localhost:8181/bus/refresh or http://localhost:8282/bus/refresh 32 | -------------------------------------------------------------------------------- /spring-cloud/catalog-service/.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 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | 18 | ### NetBeans ### 19 | nbproject/private/ 20 | build/ 21 | nbbuild/ 22 | dist/ 23 | nbdist/ 24 | .nb-gradle/ -------------------------------------------------------------------------------- /spring-cloud/catalog-service/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sivaprasadreddy/spring-boot-tutorials/11b6fdbc89397122b61353c07c4b9eb34ee1a703/spring-cloud/catalog-service/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /spring-cloud/catalog-service/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.0/apache-maven-3.5.0-bin.zip 2 | -------------------------------------------------------------------------------- /spring-cloud/catalog-service/src/main/java/com/sivalabs/catalogservice/CatalogServiceApplication.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.catalogservice; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class CatalogServiceApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(CatalogServiceApplication.class, args); 11 | } 12 | } 13 | 14 | -------------------------------------------------------------------------------- /spring-cloud/catalog-service/src/main/java/com/sivalabs/catalogservice/HomeController.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.catalogservice; 2 | 3 | 4 | import org.springframework.beans.factory.annotation.Value; 5 | import org.springframework.cloud.context.config.annotation.RefreshScope; 6 | import org.springframework.web.bind.annotation.GetMapping; 7 | import org.springframework.web.bind.annotation.RestController; 8 | 9 | @RestController 10 | @RefreshScope 11 | public class HomeController 12 | { 13 | @Value("${name}") 14 | String name; 15 | 16 | @GetMapping("/name") 17 | public String name() 18 | { 19 | return name; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /spring-cloud/catalog-service/src/main/resources/bootstrap.properties: -------------------------------------------------------------------------------- 1 | server.port=8181 2 | spring.application.name=catalogservice 3 | spring.cloud.config.uri=http://localhost:8888 4 | management.security.enabled=false 5 | -------------------------------------------------------------------------------- /spring-cloud/catalog-service/src/test/java/com/sivalabs/catalogservice/CatalogServiceApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.catalogservice; 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 CatalogServiceApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /spring-cloud/docker-compose.yml: -------------------------------------------------------------------------------- 1 | 2 | version: '2' 3 | 4 | services: 5 | rabbitmq: 6 | container_name: rabbitmq-server 7 | image: 'rabbitmq:management' 8 | environment: 9 | - RABBITMQ_DEFAULT_USER=guest 10 | - RABBITMQ_DEFAULT_PASS=guest 11 | ports: 12 | - "5672:5672" 13 | - "15672:15672" 14 | -------------------------------------------------------------------------------- /spring-cloud/order-service/.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 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | 18 | ### NetBeans ### 19 | nbproject/private/ 20 | build/ 21 | nbbuild/ 22 | dist/ 23 | nbdist/ 24 | .nb-gradle/ -------------------------------------------------------------------------------- /spring-cloud/order-service/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sivaprasadreddy/spring-boot-tutorials/11b6fdbc89397122b61353c07c4b9eb34ee1a703/spring-cloud/order-service/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /spring-cloud/order-service/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.0/apache-maven-3.5.0-bin.zip 2 | -------------------------------------------------------------------------------- /spring-cloud/order-service/src/main/resources/bootstrap.properties: -------------------------------------------------------------------------------- 1 | server.port=8282 2 | spring.application.name=orderservice 3 | spring.cloud.config.uri=http://localhost:8888 4 | management.security.enabled=false 5 | -------------------------------------------------------------------------------- /spring-cloud/order-service/src/test/java/com/sivalabs/orderservice/OrderServiceApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.orderservice; 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 OrderServiceApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /spring-cloud/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.sivalabs 7 | spring-cloud-tutorial 8 | 1.0.0-SNAPSHOT 9 | pom 10 | 11 | spring-cloud-tutorial 12 | 13 | spring-cloud-config-server 14 | catalog-service 15 | order-service 16 | 17 | 18 | -------------------------------------------------------------------------------- /spring-cloud/spring-cloud-config-server/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sivaprasadreddy/spring-boot-tutorials/11b6fdbc89397122b61353c07c4b9eb34ee1a703/spring-cloud/spring-cloud-config-server/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /spring-cloud/spring-cloud-config-server/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.0/apache-maven-3.5.0-bin.zip 2 | -------------------------------------------------------------------------------- /spring-cloud/spring-cloud-config-server/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sivaprasadreddy/spring-boot-tutorials/11b6fdbc89397122b61353c07c4b9eb34ee1a703/spring-cloud/spring-cloud-config-server/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /spring-cloud/spring-cloud-config-server/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | zipStoreBase=GRADLE_USER_HOME 4 | zipStorePath=wrapper/dists 5 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.5.1-bin.zip 6 | -------------------------------------------------------------------------------- /spring-cloud/spring-cloud-config-server/src/main/java/com/sivalabs/configserver/ConfigServerApplication.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.configserver; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.config.server.EnableConfigServer; 6 | 7 | @EnableConfigServer 8 | @SpringBootApplication 9 | public class ConfigServerApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(ConfigServerApplication.class, args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /spring-cloud/spring-cloud-config-server/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=8888 2 | spring.cloud.config.server.git.uri=https://github.com/sivaprasadreddy/config-repo.git 3 | management.security.enabled=false 4 | -------------------------------------------------------------------------------- /spring-cloud/spring-cloud-config-server/src/test/java/com/sivalabs/configserver/ConfigServerApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.configserver; 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 ConfigServerApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /spring-session/README.md: -------------------------------------------------------------------------------- 1 | # spring-session-samples 2 | Spring Session Sample applications 3 | -------------------------------------------------------------------------------- /spring-session/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 4.0.0 7 | in.sivalabs 8 | spring-session-samples 9 | pom 10 | 1.0-SNAPSHOT 11 | 12 | 13 | UTF-8 14 | 15 | 16 | 17 | springboot-spring-session-jdbc-demo 18 | springboot-spring-session-redis-demo 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /spring-session/springboot-spring-session-jdbc-demo/.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 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | 18 | ### NetBeans ### 19 | nbproject/private/ 20 | build/ 21 | nbbuild/ 22 | dist/ 23 | nbdist/ 24 | .nb-gradle/ -------------------------------------------------------------------------------- /spring-session/springboot-spring-session-jdbc-demo/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sivaprasadreddy/spring-boot-tutorials/11b6fdbc89397122b61353c07c4b9eb34ee1a703/spring-session/springboot-spring-session-jdbc-demo/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /spring-session/springboot-spring-session-jdbc-demo/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.2/apache-maven-3.5.2-bin.zip 2 | -------------------------------------------------------------------------------- /spring-session/springboot-spring-session-jdbc-demo/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM frolvlad/alpine-oraclejdk8:slim 2 | ADD ["target/springboot-spring-session-jdbc-demo-0.0.1-SNAPSHOT.jar", "app.jar"] 3 | RUN sh -c 'touch /app.jar' 4 | ENV JAVA_OPTS "-Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=8787,suspend=n" 5 | EXPOSE 8080 8787 6 | ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -Dspring.profiles.active=docker -jar /app.jar" ] 7 | -------------------------------------------------------------------------------- /spring-session/springboot-spring-session-jdbc-demo/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | 3 | services: 4 | db: 5 | image: mysql:5.7 6 | container_name: db 7 | environment: 8 | MYSQL_ROOT_PASSWORD: admin 9 | MYSQL_DATABASE: demo 10 | MYSQL_USER: admin 11 | MYSQL_PASSWORD: admin 12 | 13 | app: 14 | build: . 15 | container_name: ss-jdbc-demo 16 | ports: 17 | - "9090:8080" 18 | - '9797:8787' 19 | depends_on: 20 | - db -------------------------------------------------------------------------------- /spring-session/springboot-spring-session-jdbc-demo/src/main/java/in/sivalabs/ssdemo/SecurityConfig.java: -------------------------------------------------------------------------------- 1 | package in.sivalabs.ssdemo; 2 | 3 | import org.springframework.context.annotation.Configuration; 4 | import org.springframework.security.config.annotation.web.builders.WebSecurity; 5 | import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; 6 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; 7 | 8 | @Configuration 9 | @EnableWebSecurity 10 | public class SecurityConfig extends WebSecurityConfigurerAdapter { 11 | 12 | @Override 13 | public void configure(WebSecurity web) { 14 | web.ignoring().antMatchers("/h2-console/**"); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /spring-session/springboot-spring-session-jdbc-demo/src/main/java/in/sivalabs/ssdemo/SpringSessionJdbcDemoApplication.java: -------------------------------------------------------------------------------- 1 | package in.sivalabs.ssdemo; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SpringSessionJdbcDemoApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SpringSessionJdbcDemoApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /spring-session/springboot-spring-session-jdbc-demo/src/main/resources/application-docker.properties: -------------------------------------------------------------------------------- 1 | spring.datasource.driver-class-name=com.mysql.jdbc.Driver 2 | spring.datasource.url=jdbc:mysql://db:3306/demo 3 | spring.datasource.username=root 4 | spring.datasource.password=admin 5 | 6 | #spring.datasource.initialization-mode=always 7 | spring.session.jdbc.initialize-schema=always 8 | -------------------------------------------------------------------------------- /spring-session/springboot-spring-session-jdbc-demo/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.h2.console.enabled=true 2 | 3 | spring.session.store-type=jdbc 4 | 5 | spring.security.user.name=admin 6 | spring.security.user.password=secret -------------------------------------------------------------------------------- /spring-session/springboot-spring-session-jdbc-demo/src/main/resources/templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Spring Session + JDBC Demo 6 | 7 | 8 |
9 |
10 | 11 | 12 |
13 |
14 |
15 |

Messages

16 |
    17 |
  • msg
  • 18 |
19 |
20 | 21 | -------------------------------------------------------------------------------- /spring-session/springboot-spring-session-jdbc-demo/src/test/java/in/sivalabs/ssdemo/SpringSessionJdbcDemoApplicationTests.java: -------------------------------------------------------------------------------- 1 | package in.sivalabs.ssdemo; 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 SpringSessionJdbcDemoApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /spring-session/springboot-spring-session-redis-demo/.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 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | 18 | ### NetBeans ### 19 | nbproject/private/ 20 | build/ 21 | nbbuild/ 22 | dist/ 23 | nbdist/ 24 | .nb-gradle/ -------------------------------------------------------------------------------- /spring-session/springboot-spring-session-redis-demo/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sivaprasadreddy/spring-boot-tutorials/11b6fdbc89397122b61353c07c4b9eb34ee1a703/spring-session/springboot-spring-session-redis-demo/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /spring-session/springboot-spring-session-redis-demo/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.2/apache-maven-3.5.2-bin.zip 2 | -------------------------------------------------------------------------------- /spring-session/springboot-spring-session-redis-demo/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM frolvlad/alpine-oraclejdk8:slim 2 | ADD ["target/springboot-spring-session-redis-demo-0.0.1-SNAPSHOT.jar", "app.jar"] 3 | RUN sh -c 'touch /app.jar' 4 | ENV JAVA_OPTS "-Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=8787,suspend=n" 5 | EXPOSE 8080 8787 6 | ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -Dspring.profiles.active=docker -jar /app.jar" ] 7 | -------------------------------------------------------------------------------- /spring-session/springboot-spring-session-redis-demo/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | 3 | services: 4 | redis: 5 | image: "redis:alpine" 6 | command: redis-server --appendonly yes 7 | container_name: redisserver 8 | ports: 9 | - "6379:6379" 10 | 11 | app: 12 | build: . 13 | container_name: ss-redis-demo 14 | ports: 15 | - "9090:8080" 16 | - '9797:8787' 17 | depends_on: 18 | - redis -------------------------------------------------------------------------------- /spring-session/springboot-spring-session-redis-demo/src/main/java/in/sivalabs/ssdemo/SpringSessionRedisDemoApplication.java: -------------------------------------------------------------------------------- 1 | package in.sivalabs.ssdemo; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SpringSessionRedisDemoApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SpringSessionRedisDemoApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /spring-session/springboot-spring-session-redis-demo/src/main/resources/application-docker.properties: -------------------------------------------------------------------------------- 1 | 2 | spring.redis.host=redisserver 3 | spring.redis.port=6379 -------------------------------------------------------------------------------- /spring-session/springboot-spring-session-redis-demo/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.session.store-type=redis -------------------------------------------------------------------------------- /spring-session/springboot-spring-session-redis-demo/src/main/resources/templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Spring Session + Redis Demo 6 | 7 | 8 |
9 |
10 | 11 | 12 |
13 |
14 |
15 |

Messages

16 |
    17 |
  • msg
  • 18 |
19 |
20 | 21 | -------------------------------------------------------------------------------- /spring-session/springboot-spring-session-redis-demo/src/test/java/in/sivalabs/ssdemo/SpringSessionRedisDemoApplicationTests.java: -------------------------------------------------------------------------------- 1 | package in.sivalabs.ssdemo; 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 SpringSessionRedisDemoApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /testing/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.sivalabs 7 | spring-boot-testing-tutorial 8 | 1.0.0-SNAPSHOT 9 | pom 10 | 11 | spring-boot-testing-tutorial 12 | 13 | springboot-testing-demo 14 | 15 | 16 | -------------------------------------------------------------------------------- /testing/springboot-testing-demo/.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | 3 | # Package Files # 4 | *.jar 5 | *.war 6 | *.ear 7 | 8 | .settings 9 | target 10 | .classpath 11 | .project 12 | .springBeans 13 | .tern-project 14 | 15 | bin 16 | build 17 | .gradle 18 | .idea 19 | *.iml -------------------------------------------------------------------------------- /testing/springboot-testing-demo/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.0/apache-maven-3.6.0-bin.zip 2 | -------------------------------------------------------------------------------- /testing/springboot-testing-demo/README.md: -------------------------------------------------------------------------------- 1 | # Unit and Integration Testing in SpringBoot Applications 2 | 3 | -------------------------------------------------------------------------------- /testing/springboot-testing-demo/src/main/java/com/sivalabs/myservice/Application.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.myservice; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker; 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.web.client.RestTemplate; 8 | 9 | @SpringBootApplication 10 | @EnableCircuitBreaker 11 | public class Application 12 | { 13 | public static void main(String[] args) { 14 | SpringApplication.run(Application.class, args); 15 | } 16 | 17 | @Bean 18 | public RestTemplate restTemplate() { 19 | return new RestTemplate(); 20 | } 21 | } 22 | 23 | -------------------------------------------------------------------------------- /testing/springboot-testing-demo/src/main/java/com/sivalabs/myservice/config/ApplicationProperties.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.myservice.config; 2 | 3 | import lombok.Data; 4 | import org.springframework.beans.factory.annotation.Value; 5 | import org.springframework.stereotype.Component; 6 | 7 | @Component 8 | @Data 9 | public class ApplicationProperties { 10 | 11 | @Value("${githuub.api.base-url}") 12 | private String githubBaseUrl; 13 | } 14 | -------------------------------------------------------------------------------- /testing/springboot-testing-demo/src/main/java/com/sivalabs/myservice/config/WebMvcConfig.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.sivalabs.myservice.config; 5 | 6 | import org.springframework.context.annotation.Configuration; 7 | import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; 8 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; 9 | 10 | /** 11 | * @author Siva 12 | * 13 | */ 14 | @Configuration 15 | public class WebMvcConfig extends WebMvcConfigurerAdapter 16 | { 17 | @Override 18 | public void addViewControllers(ViewControllerRegistry registry) { 19 | registry.addViewController("/").setViewName("index.html"); 20 | //registry.addViewController("/admin").setViewName("admin/index.html"); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /testing/springboot-testing-demo/src/main/java/com/sivalabs/myservice/entities/User.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.myservice.entities; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Getter; 5 | import lombok.NoArgsConstructor; 6 | import lombok.Setter; 7 | 8 | import javax.persistence.*; 9 | import javax.validation.constraints.NotEmpty; 10 | import java.io.Serializable; 11 | 12 | @Entity 13 | @Table(name = "users") 14 | @Setter 15 | @Getter 16 | @NoArgsConstructor 17 | @AllArgsConstructor 18 | public class User implements Serializable 19 | { 20 | @Id 21 | @GeneratedValue(strategy = GenerationType.IDENTITY) 22 | private Long id; 23 | 24 | @NotEmpty(message = "Email should not be empty") 25 | @Column(nullable = false, unique = true, length = 100) 26 | private String email; 27 | 28 | @Column(nullable = false, length = 100) 29 | private String password; 30 | 31 | @Column(nullable = false, length = 100) 32 | private String name; 33 | 34 | } 35 | -------------------------------------------------------------------------------- /testing/springboot-testing-demo/src/main/java/com/sivalabs/myservice/exception/UserRegistrationException.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.myservice.exception; 2 | 3 | public class UserRegistrationException extends RuntimeException { 4 | public UserRegistrationException(String message) { 5 | super(message); 6 | } 7 | 8 | public UserRegistrationException(String message, Throwable cause) { 9 | super(message, cause); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /testing/springboot-testing-demo/src/main/java/com/sivalabs/myservice/model/GithubUser.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.myservice.model; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | import lombok.Data; 5 | 6 | @Data 7 | public class GithubUser { 8 | private Long id; 9 | private String login; 10 | private String url; 11 | private String name; 12 | @JsonProperty("public_repos") 13 | private int publicRepos; 14 | private int followers; 15 | private int following; 16 | } 17 | -------------------------------------------------------------------------------- /testing/springboot-testing-demo/src/main/java/com/sivalabs/myservice/repositories/UserRepository.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.myservice.repositories; 2 | 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | 5 | import com.sivalabs.myservice.entities.User; 6 | import org.springframework.data.jpa.repository.Query; 7 | 8 | import java.util.Optional; 9 | 10 | public interface UserRepository extends JpaRepository 11 | { 12 | @Query("select u from User u where u.email=?1 and u.password=?2") 13 | Optional login(String email, String password); 14 | 15 | Optional findByEmail(String email); 16 | } 17 | -------------------------------------------------------------------------------- /testing/springboot-testing-demo/src/main/resources/application-test.properties: -------------------------------------------------------------------------------- 1 | githuub.api.base-url=http://localhost:1080 2 | -------------------------------------------------------------------------------- /testing/springboot-testing-demo/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | ################### DB Configuration ########################## 3 | spring.jpa.show-sql=true 4 | spring.jpa.hibernate.ddl-auto=none 5 | spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true 6 | spring.flyway.locations=classpath:/db/migration/{vendor} 7 | 8 | githuub.api.base-url=https://api.github.com 9 | 10 | -------------------------------------------------------------------------------- /testing/springboot-testing-demo/src/main/resources/db/migration/h2/V1__01_init.sql: -------------------------------------------------------------------------------- 1 | create sequence user_id_seq start with 1 increment by 1; 2 | 3 | create table users ( 4 | id bigint DEFAULT nextval('user_id_seq') not null, 5 | email varchar(100) not null UNIQUE, 6 | password varchar(100) not null, 7 | name varchar(100) not null, 8 | primary key (id) 9 | ); 10 | -------------------------------------------------------------------------------- /testing/springboot-testing-demo/src/main/resources/db/migration/postgresql/V1__01_init.sql: -------------------------------------------------------------------------------- 1 | create sequence user_id_seq start with 1 increment by 1; 2 | 3 | create table users ( 4 | id bigint DEFAULT nextval('user_id_seq') not null, 5 | email varchar(100) not null UNIQUE, 6 | password varchar(100) not null, 7 | name varchar(100) not null, 8 | primary key (id) 9 | ); 10 | -------------------------------------------------------------------------------- /testing/springboot-testing-demo/src/test/java/com/sivalabs/myservice/ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.myservice; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | public class ApplicationTests { 8 | 9 | @Test 10 | public void contextLoads() { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /testing/springboot-testing-demo/src/test/java/com/sivalabs/myservice/common/ExceptionHandling.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.myservice.common; 2 | 3 | import org.springframework.context.annotation.Profile; 4 | import org.springframework.web.bind.annotation.ControllerAdvice; 5 | import org.zalando.problem.spring.web.advice.ProblemHandling; 6 | 7 | @Profile("test") 8 | @ControllerAdvice 9 | public final class ExceptionHandling implements ProblemHandling { 10 | 11 | } 12 | -------------------------------------------------------------------------------- /web/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.sivalabs 7 | spring-boot-web-tutorial 8 | 1.0.0-SNAPSHOT 9 | pom 10 | 11 | spring-boot-web-tutorial 12 | 13 | springboot-thymeleaf-demo 14 | springboot-rest-api-design 15 | spring-data-rest-demo 16 | 17 | 18 | -------------------------------------------------------------------------------- /web/spring-data-rest-demo/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .classpath 6 | .factorypath 7 | .project 8 | .settings 9 | .springBeans 10 | 11 | ### IntelliJ IDEA ### 12 | .idea 13 | *.iws 14 | *.iml 15 | *.ipr 16 | 17 | ### NetBeans ### 18 | nbproject/private/ 19 | build/ 20 | nbbuild/ 21 | dist/ 22 | nbdist/ 23 | .nb-gradle/ 24 | -------------------------------------------------------------------------------- /web/spring-data-rest-demo/.gitlab-ci.yml: -------------------------------------------------------------------------------- 1 | image: docker:latest 2 | services: 3 | - docker:dind 4 | 5 | variables: 6 | DOCKER_DRIVER: overlay2 7 | SPRING_PROFILES_ACTIVE: gitlab-ci 8 | 9 | stages: 10 | - build 11 | 12 | maven-build: 13 | stage: build 14 | script: 15 | - docker run -t --rm -v /var/run/docker.sock:/var/run/docker.sock -v "$(pwd)":"$(pwd)" -w "$(pwd)" -u 0:0 maven:3.5.4-jdk-8-alpine mvn clean verify -B 16 | -------------------------------------------------------------------------------- /web/spring-data-rest-demo/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sivaprasadreddy/spring-boot-tutorials/11b6fdbc89397122b61353c07c4b9eb34ee1a703/web/spring-data-rest-demo/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /web/spring-data-rest-demo/.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 | -------------------------------------------------------------------------------- /web/spring-data-rest-demo/.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: required 2 | language: java 3 | jdk: oraclejdk8 4 | 5 | script: 6 | - ./mvnw clean verify 7 | 8 | cache: 9 | directories: 10 | - '$HOME/.m2/repository' 11 | -------------------------------------------------------------------------------- /web/spring-data-rest-demo/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM frolvlad/alpine-oraclejdk8:slim 2 | VOLUME /tmp 3 | ADD target/ebuddy-api-0.0.1-SNAPSHOT-exec.jar app.jar 4 | RUN sh -c 'touch /app.jar' 5 | ENV JAVA_OPTS="-Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=8787,suspend=n" 6 | ENV SPRING_PROFILES_ACTIVE "docker" 7 | EXPOSE 8080 8787 8 | ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -Dspring.profiles.active=$SPRING_PROFILES_ACTIVE -jar /app.jar" ] 9 | -------------------------------------------------------------------------------- /web/spring-data-rest-demo/README.md: -------------------------------------------------------------------------------- 1 | # eBuddy REST API 2 | 3 | ### Authenticate User 4 | 5 | `curl -H "Content-Type: application/json" -X POST -d '{"username":"admin@gmail.com","password":"admin"}' http://localhost:8080/api/auth/login` 6 | 7 | `curl -H "Content-Type: application/json" -X POST -d '{"username":"siva@gmail.com","password":"siva"}' http://localhost:8080/api/auth/login` 8 | 9 | 10 | ### API Endpoints 11 | 12 | `curl -H "Authorization: Bearer TOKEN_HERE" -X GET http://localhost:8080/api/me` 13 | 14 | `curl -H "Authorization: Bearer TOKEN_HERE" -X GET http://localhost:8080/api/bookmarks` 15 | 16 | `curl -H "Authorization: Bearer TOKEN_HERE" -X GET http://localhost:8080/api/todos` 17 | 18 | `curl -H "Authorization: Bearer TOKEN_HERE" -X GET http://localhost:8080/api/notes` 19 | -------------------------------------------------------------------------------- /web/spring-data-rest-demo/config/logstash.conf: -------------------------------------------------------------------------------- 1 | input { 2 | tcp { 3 | port => 5000 4 | codec => json_lines 5 | } 6 | } 7 | 8 | ## Add your filters / logstash plugins configuration here 9 | 10 | output { 11 | elasticsearch { 12 | hosts => "elasticsearch:9200" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /web/spring-data-rest-demo/src/main/java/com/sivalabs/ebuddy/EbuddyApiApplication.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.ebuddy; 2 | 3 | import com.sivalabs.ebuddy.config.AppConfiguration; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 7 | 8 | @SpringBootApplication 9 | @EnableConfigurationProperties(AppConfiguration.class) 10 | public class EbuddyApiApplication { 11 | 12 | public static void main(String[] args) { 13 | SpringApplication.run(EbuddyApiApplication.class, args); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /web/spring-data-rest-demo/src/main/java/com/sivalabs/ebuddy/config/AppConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.ebuddy.config; 2 | 3 | import lombok.Data; 4 | import org.springframework.boot.context.properties.ConfigurationProperties; 5 | 6 | @ConfigurationProperties(prefix = "ebuddy") 7 | @Data 8 | public class AppConfiguration { 9 | private String logstashHost = "localhost"; 10 | private JwtConfig jwt = new JwtConfig(); 11 | 12 | @Data 13 | public static class JwtConfig { 14 | private String header = ""; 15 | private String issuer = "sivalabs"; 16 | private Long expiresIn = 604800L; 17 | private String secret = "secret"; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /web/spring-data-rest-demo/src/main/java/com/sivalabs/ebuddy/config/TimeProvider.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.ebuddy.config; 2 | 3 | import org.springframework.stereotype.Component; 4 | 5 | import java.util.Date; 6 | 7 | @Component 8 | public class TimeProvider { 9 | 10 | public Date now() { 11 | return new Date(); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /web/spring-data-rest-demo/src/main/java/com/sivalabs/ebuddy/config/WebMvcConfig.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.ebuddy.config; 2 | 3 | import org.springframework.context.annotation.Configuration; 4 | import org.springframework.web.servlet.config.annotation.CorsRegistry; 5 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; 6 | 7 | @Configuration 8 | public class WebMvcConfig implements WebMvcConfigurer { 9 | 10 | @Override 11 | public void addCorsMappings(CorsRegistry registry) { 12 | registry.addMapping("/**") 13 | .allowedOrigins("*") 14 | .allowedMethods("*") 15 | .allowedHeaders("*") 16 | .allowCredentials(false) 17 | ; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /web/spring-data-rest-demo/src/main/java/com/sivalabs/ebuddy/entity/BaseEntity.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.ebuddy.entity; 2 | 3 | import lombok.Getter; 4 | import lombok.Setter; 5 | 6 | import javax.persistence.MappedSuperclass; 7 | import javax.persistence.Temporal; 8 | import javax.persistence.TemporalType; 9 | import java.util.Date; 10 | 11 | @MappedSuperclass 12 | @Setter 13 | @Getter 14 | abstract class BaseEntity { 15 | 16 | @Temporal(TemporalType.TIMESTAMP) 17 | private Date createdOn = new Date(); 18 | 19 | @Temporal(TemporalType.TIMESTAMP) 20 | private Date updatedOn = new Date(); 21 | 22 | } 23 | -------------------------------------------------------------------------------- /web/spring-data-rest-demo/src/main/java/com/sivalabs/ebuddy/entity/Bookmark.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.ebuddy.entity; 2 | 3 | import lombok.Data; 4 | import lombok.NoArgsConstructor; 5 | 6 | import javax.persistence.*; 7 | import javax.validation.constraints.NotEmpty; 8 | 9 | @Data 10 | @NoArgsConstructor 11 | @Entity 12 | @Table(name = "bookmarks") 13 | public class Bookmark extends BaseEntity { 14 | 15 | @Id 16 | @SequenceGenerator(name = "bm_id_generator", sequenceName = "bm_id_seq") 17 | @GeneratedValue(generator = "bm_id_generator") 18 | private Long id; 19 | 20 | @NotEmpty(message = "Title should not be empty") 21 | @Column(nullable = false) 22 | private String title; 23 | 24 | @NotEmpty(message = "URL should not be empty") 25 | @Column(nullable = false) 26 | private String url; 27 | 28 | @ManyToOne 29 | @JoinColumn(name = "created_by", nullable = false) 30 | private User createdBy; 31 | } 32 | -------------------------------------------------------------------------------- /web/spring-data-rest-demo/src/main/java/com/sivalabs/ebuddy/entity/Note.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.ebuddy.entity; 2 | 3 | 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | import javax.persistence.*; 8 | import javax.validation.constraints.NotEmpty; 9 | 10 | @Data 11 | @NoArgsConstructor 12 | @Entity 13 | @Table(name = "notes") 14 | public class Note extends BaseEntity { 15 | 16 | @Id 17 | @SequenceGenerator(name = "note_id_generator", sequenceName = "note_id_seq") 18 | @GeneratedValue(generator = "note_id_generator") 19 | private Long id; 20 | @NotEmpty(message = "Text should not be empty") 21 | @Column(nullable = false) 22 | private String text; 23 | 24 | @ManyToOne 25 | @JoinColumn(name = "created_by", nullable = false) 26 | private User createdBy; 27 | } 28 | -------------------------------------------------------------------------------- /web/spring-data-rest-demo/src/main/java/com/sivalabs/ebuddy/entity/Role.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.ebuddy.entity; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Builder; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | import javax.persistence.*; 9 | 10 | @Data 11 | @NoArgsConstructor 12 | @Entity 13 | @Table(name = "roles") 14 | public class Role extends BaseEntity { 15 | 16 | @Id 17 | @SequenceGenerator(name = "role_id_generator", sequenceName = "role_id_seq") 18 | @GeneratedValue(generator = "role_id_generator") 19 | private Long id; 20 | 21 | @Column(name = "name", unique = true) 22 | private String name; 23 | 24 | } 25 | -------------------------------------------------------------------------------- /web/spring-data-rest-demo/src/main/java/com/sivalabs/ebuddy/entity/Todo.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.ebuddy.entity; 2 | 3 | 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | import javax.persistence.*; 8 | import javax.validation.constraints.NotEmpty; 9 | 10 | @Data 11 | @NoArgsConstructor 12 | @Entity 13 | @Table(name = "todos") 14 | public class Todo extends BaseEntity { 15 | 16 | @Id 17 | @SequenceGenerator(name = "todo_id_generator", sequenceName = "todo_id_seq") 18 | @GeneratedValue(generator = "todo_id_generator") 19 | private Long id; 20 | 21 | @NotEmpty(message = "Text should not be empty") 22 | @Column(nullable = false) 23 | private String text; 24 | 25 | @Column(nullable = false) 26 | private boolean done; 27 | 28 | @ManyToOne 29 | @JoinColumn(name = "created_by", nullable = false) 30 | private User createdBy; 31 | } 32 | -------------------------------------------------------------------------------- /web/spring-data-rest-demo/src/main/java/com/sivalabs/ebuddy/entity/Transaction.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.ebuddy.entity; 2 | 3 | import lombok.Data; 4 | import lombok.NoArgsConstructor; 5 | 6 | import javax.persistence.*; 7 | import java.math.BigDecimal; 8 | 9 | @Data 10 | @NoArgsConstructor 11 | @Entity 12 | @Table(name = "transactions") 13 | public class Transaction extends BaseEntity { 14 | 15 | @Id 16 | @SequenceGenerator(name = "txn_id_generator", sequenceName = "txn_id_seq") 17 | @GeneratedValue(generator = "txn_id_generator") 18 | private Long id; 19 | 20 | @Column(nullable = false) 21 | private BigDecimal amount; 22 | 23 | @Enumerated(EnumType.STRING) 24 | private Type type; 25 | 26 | @ManyToOne 27 | @JoinColumn(name = "created_by", nullable = false) 28 | private User createdBy; 29 | 30 | public enum Type { 31 | INCOME, 32 | EXPENSE 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /web/spring-data-rest-demo/src/main/java/com/sivalabs/ebuddy/model/AuthenticationRequest.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.ebuddy.model; 2 | 3 | import lombok.Data; 4 | 5 | @Data 6 | public class AuthenticationRequest { 7 | private String username; 8 | private String password; 9 | } 10 | -------------------------------------------------------------------------------- /web/spring-data-rest-demo/src/main/java/com/sivalabs/ebuddy/model/AuthenticationResponse.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.ebuddy.model; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Data; 6 | 7 | @Data 8 | @AllArgsConstructor 9 | public class AuthenticationResponse { 10 | 11 | @JsonProperty("access_token") 12 | private String accessToken; 13 | 14 | @JsonProperty("expires_in") 15 | private Long expiresIn; 16 | } 17 | -------------------------------------------------------------------------------- /web/spring-data-rest-demo/src/main/java/com/sivalabs/ebuddy/model/ChangePassword.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.ebuddy.model; 2 | 3 | import lombok.Data; 4 | 5 | @Data 6 | public class ChangePassword { 7 | private String oldPassword; 8 | private String newPassword; 9 | } 10 | -------------------------------------------------------------------------------- /web/spring-data-rest-demo/src/main/java/com/sivalabs/ebuddy/model/ErrorMessage.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.ebuddy.model; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | @Data 8 | @AllArgsConstructor 9 | @NoArgsConstructor 10 | public class ErrorMessage { 11 | private String field; 12 | private String message; 13 | } 14 | -------------------------------------------------------------------------------- /web/spring-data-rest-demo/src/main/java/com/sivalabs/ebuddy/repo/BookmarkRepository.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.ebuddy.repo; 2 | 3 | import com.sivalabs.ebuddy.entity.Bookmark; 4 | import org.springframework.data.domain.Page; 5 | import org.springframework.data.domain.Pageable; 6 | import org.springframework.data.jpa.repository.JpaRepository; 7 | import org.springframework.data.jpa.repository.Query; 8 | import org.springframework.security.access.prepost.PreAuthorize; 9 | 10 | @PreAuthorize("!isAnonymous() and isAuthenticated()") 11 | public interface BookmarkRepository extends JpaRepository { 12 | @Override 13 | @Query("select b from Bookmark b where b.createdBy.email=?#{principal.username}") 14 | Page findAll(Pageable pageable); 15 | } 16 | -------------------------------------------------------------------------------- /web/spring-data-rest-demo/src/main/java/com/sivalabs/ebuddy/repo/NoteRepository.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.ebuddy.repo; 2 | 3 | import com.sivalabs.ebuddy.entity.Note; 4 | import org.springframework.data.domain.Page; 5 | import org.springframework.data.domain.Pageable; 6 | import org.springframework.data.jpa.repository.JpaRepository; 7 | import org.springframework.data.jpa.repository.Query; 8 | import org.springframework.security.access.prepost.PreAuthorize; 9 | 10 | @PreAuthorize("!isAnonymous() and isAuthenticated()") 11 | public interface NoteRepository extends JpaRepository { 12 | @Override 13 | @Query("select n from Note n where n.createdBy.email=?#{principal.username}") 14 | Page findAll(Pageable pageable); 15 | } 16 | -------------------------------------------------------------------------------- /web/spring-data-rest-demo/src/main/java/com/sivalabs/ebuddy/repo/TodoRepository.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.ebuddy.repo; 2 | 3 | import com.sivalabs.ebuddy.entity.Todo; 4 | import org.springframework.data.domain.Page; 5 | import org.springframework.data.domain.Pageable; 6 | import org.springframework.data.jpa.repository.JpaRepository; 7 | import org.springframework.data.jpa.repository.Query; 8 | import org.springframework.security.access.prepost.PreAuthorize; 9 | 10 | @PreAuthorize("!isAnonymous() and isAuthenticated()") 11 | public interface TodoRepository extends JpaRepository { 12 | @Override 13 | @Query("select t from Todo t where t.createdBy.email=?#{principal.username}") 14 | Page findAll(Pageable pageable); 15 | } 16 | -------------------------------------------------------------------------------- /web/spring-data-rest-demo/src/main/java/com/sivalabs/ebuddy/repo/TransactionRepository.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.ebuddy.repo; 2 | 3 | import com.sivalabs.ebuddy.entity.Transaction; 4 | import org.springframework.data.domain.Page; 5 | import org.springframework.data.domain.Pageable; 6 | import org.springframework.data.jpa.repository.JpaRepository; 7 | import org.springframework.data.jpa.repository.Query; 8 | import org.springframework.security.access.prepost.PreAuthorize; 9 | 10 | @PreAuthorize("!isAnonymous() and isAuthenticated()") 11 | public interface TransactionRepository extends JpaRepository { 12 | @Override 13 | @Query("select t from Transaction t where t.createdBy.email=?#{principal.username}") 14 | Page findAll(Pageable pageable); 15 | } 16 | -------------------------------------------------------------------------------- /web/spring-data-rest-demo/src/main/java/com/sivalabs/ebuddy/repo/UserRepository.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.ebuddy.repo; 2 | 3 | import com.sivalabs.ebuddy.entity.User; 4 | import org.springframework.data.repository.CrudRepository; 5 | 6 | public interface UserRepository extends CrudRepository { 7 | User findByEmail(String username); 8 | } 9 | -------------------------------------------------------------------------------- /web/spring-data-rest-demo/src/main/java/com/sivalabs/ebuddy/security/SecurityUser.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.ebuddy.security; 2 | 3 | import org.springframework.security.core.authority.SimpleGrantedAuthority; 4 | import org.springframework.security.core.userdetails.User; 5 | 6 | import java.util.stream.Collectors; 7 | 8 | public class SecurityUser extends User { 9 | private com.sivalabs.ebuddy.entity.User user; 10 | 11 | public SecurityUser(com.sivalabs.ebuddy.entity.User user) { 12 | super(user.getEmail(), 13 | user.getPassword(), 14 | user.getRoles().stream().map(r -> new SimpleGrantedAuthority(r.getName())).collect(Collectors.toList())); 15 | this.user = user; 16 | } 17 | 18 | public com.sivalabs.ebuddy.entity.User getUser() { 19 | return user; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /web/spring-data-rest-demo/src/main/java/com/sivalabs/ebuddy/security/auth/RestAuthenticationEntryPoint.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.ebuddy.security.auth; 2 | 3 | import org.springframework.security.core.AuthenticationException; 4 | import org.springframework.security.web.AuthenticationEntryPoint; 5 | import org.springframework.stereotype.Component; 6 | 7 | import javax.servlet.http.HttpServletRequest; 8 | import javax.servlet.http.HttpServletResponse; 9 | import java.io.IOException; 10 | 11 | @Component 12 | public class RestAuthenticationEntryPoint implements AuthenticationEntryPoint { 13 | 14 | @Override 15 | public void commence(HttpServletRequest request, 16 | HttpServletResponse response, 17 | AuthenticationException authException) throws IOException { 18 | response.sendError(HttpServletResponse.SC_UNAUTHORIZED, authException.getMessage()); 19 | } 20 | } 21 | 22 | -------------------------------------------------------------------------------- /web/spring-data-rest-demo/src/main/resources/application-docker.properties: -------------------------------------------------------------------------------- 1 | spring.datasource.driver-class-name=org.postgresql.Driver 2 | spring.datasource.url=jdbc:postgresql://postgresdb:5432/appdb 3 | spring.datasource.username=siva 4 | spring.datasource.password=secret 5 | logstash.host=logstash 6 | -------------------------------------------------------------------------------- /web/spring-data-rest-demo/src/main/resources/application-local.properties: -------------------------------------------------------------------------------- 1 | spring.datasource.driver-class-name=org.postgresql.Driver 2 | spring.datasource.url=jdbc:postgresql://localhost:5432/postgres 3 | spring.datasource.username=postgres 4 | spring.datasource.password= 5 | spring.datasource.initialization-mode=never 6 | spring.flyway.enabled=true 7 | spring.flyway.locations=classpath:/db/migration/{vendor} 8 | -------------------------------------------------------------------------------- /web/spring-data-rest-demo/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=ebuddy 2 | #spring.profiles.active=local 3 | logging.level.com.sivalabs=debug 4 | spring.jackson.serialization.WRITE_DATES_AS_TIMESTAMPS=false 5 | management.endpoints.web.exposure.include=* 6 | management.metrics.distribution.percentiles-histogram.http.server.requests=true 7 | spring.h2.console.enabled=true 8 | spring.jpa.show-sql=true 9 | spring.flyway.locations=classpath:/db/migration/{vendor} 10 | spring.main.allow-bean-definition-overriding=true 11 | ebuddy.logstash.host=localhost 12 | ebuddy.jwt.issuer=ebuddy 13 | ebuddy.jwt.header=Authorization 14 | ebuddy.jwt.expires_in=604800 15 | ebuddy.jwt.secret=mysecret 16 | spring.data.rest.base-path=/api 17 | -------------------------------------------------------------------------------- /web/springboot-rest-api-design/.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | 3 | # Package Files # 4 | *.jar 5 | *.war 6 | *.ear 7 | 8 | .settings 9 | target 10 | .classpath 11 | .project 12 | .springBeans 13 | .tern-project 14 | 15 | bin 16 | build 17 | .gradle 18 | .idea 19 | *.iml -------------------------------------------------------------------------------- /web/springboot-rest-api-design/README.md: -------------------------------------------------------------------------------- 1 | # REST API Design using SpringBoot 2 | 3 | ### This application is a sample project demonstrating how to build a REST API using SpringBoot, SpringSecurity, Spring Data JPA. 4 | 5 | ### How to Run? 6 | Run BlogApplication.java as a Java application. 7 | 8 | To explore and invoke the REST endpoints go to http://localhost:8080/swagger-ui/index.html 9 | 10 | Some of the endpoints needs authentication. Authenticate using POST /api/authenticate endpoint using credentials admin@gmail.com/admin. 11 | 12 | TODO: Planning to add a front-end using angularjs, but as of now play with SwaggerUI :-) 13 | 14 | -------------------------------------------------------------------------------- /web/springboot-rest-api-design/src/main/java/com/sivalabs/blog/BlogApplication.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.sivalabs.blog; 5 | 6 | import org.modelmapper.ModelMapper; 7 | import org.springframework.boot.SpringApplication; 8 | import org.springframework.boot.autoconfigure.SpringBootApplication; 9 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 10 | import org.springframework.context.annotation.Bean; 11 | 12 | /** 13 | * @author Siva 14 | * 15 | */ 16 | @SpringBootApplication 17 | @EnableConfigurationProperties 18 | public class BlogApplication 19 | { 20 | public static void main(String[] args) { 21 | SpringApplication.run(BlogApplication.class, args); 22 | } 23 | 24 | @Bean 25 | public ModelMapper modelMapper() { 26 | return new ModelMapper(); 27 | } 28 | } 29 | 30 | -------------------------------------------------------------------------------- /web/springboot-rest-api-design/src/main/java/com/sivalabs/blog/config/WebMvcConfig.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.sivalabs.blog.config; 5 | 6 | import org.springframework.context.annotation.Configuration; 7 | import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; 8 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; 9 | 10 | /** 11 | * @author Siva 12 | * 13 | */ 14 | @Configuration 15 | public class WebMvcConfig extends WebMvcConfigurerAdapter 16 | { 17 | @Override 18 | public void addViewControllers(ViewControllerRegistry registry) { 19 | registry.addViewController("/").setViewName("index.html"); 20 | //registry.addViewController("/admin").setViewName("admin/index.html"); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /web/springboot-rest-api-design/src/main/java/com/sivalabs/blog/exceptions/UnauthorizedAccessException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.sivalabs.blog.exceptions; 5 | 6 | /** 7 | * @author Siva 8 | * 9 | */ 10 | public class UnauthorizedAccessException extends RuntimeException { 11 | 12 | private static final long serialVersionUID = 1L; 13 | 14 | public UnauthorizedAccessException() { 15 | } 16 | 17 | public UnauthorizedAccessException(String message, Throwable cause) { 18 | super(message, cause); 19 | } 20 | 21 | public UnauthorizedAccessException(String message) { 22 | super(message); 23 | } 24 | 25 | public UnauthorizedAccessException(Throwable cause) { 26 | super(cause); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /web/springboot-rest-api-design/src/main/java/com/sivalabs/blog/exceptions/ValidationFailureException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.sivalabs.blog.exceptions; 5 | 6 | /** 7 | * @author Siva 8 | * 9 | */ 10 | import org.springframework.validation.Errors; 11 | 12 | public class ValidationFailureException extends RuntimeException 13 | { 14 | private static final long serialVersionUID = 1L; 15 | private Errors errors; 16 | public ValidationFailureException(Errors errors) 17 | { 18 | this.errors = errors; 19 | } 20 | public Errors getErrors() 21 | { 22 | return errors; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /web/springboot-rest-api-design/src/main/java/com/sivalabs/blog/model/RoleDTO.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.blog.model; 2 | 3 | import java.io.Serializable; 4 | 5 | public class RoleDTO implements Serializable 6 | { 7 | 8 | private static final long serialVersionUID = 1L; 9 | 10 | private Long id; 11 | 12 | private String name; 13 | 14 | public Long getId() 15 | { 16 | return id; 17 | } 18 | 19 | public void setId(Long id) 20 | { 21 | this.id = id; 22 | } 23 | 24 | public String getName() 25 | { 26 | return name; 27 | } 28 | 29 | public void setName(String name) 30 | { 31 | this.name = name; 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /web/springboot-rest-api-design/src/main/java/com/sivalabs/blog/repositories/CommentRepository.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.blog.repositories; 2 | 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | 5 | import com.sivalabs.blog.entities.Comment; 6 | 7 | /** 8 | * @author Siva 9 | * 10 | */ 11 | public interface CommentRepository extends JpaRepository 12 | { 13 | 14 | } 15 | -------------------------------------------------------------------------------- /web/springboot-rest-api-design/src/main/java/com/sivalabs/blog/repositories/PostRepository.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.blog.repositories; 2 | 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | 5 | import com.sivalabs.blog.entities.Post; 6 | 7 | /** 8 | * @author Siva 9 | * 10 | */ 11 | public interface PostRepository extends JpaRepository 12 | { 13 | 14 | } 15 | -------------------------------------------------------------------------------- /web/springboot-rest-api-design/src/main/java/com/sivalabs/blog/repositories/UserRepository.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.blog.repositories; 2 | 3 | import org.springframework.data.jpa.repository.JpaRepository; 4 | 5 | import com.sivalabs.blog.entities.User; 6 | 7 | /** 8 | * @author Siva 9 | * 10 | */ 11 | public interface UserRepository extends JpaRepository 12 | { 13 | 14 | User findByEmail(String email); 15 | 16 | User findByEmailAndPassword(String email, String password); 17 | 18 | } 19 | -------------------------------------------------------------------------------- /web/springboot-rest-api-design/src/main/java/com/sivalabs/blog/resources/UserResource.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.sivalabs.blog.resources; 5 | 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | /** 10 | * @author Siva 11 | * 12 | */ 13 | public class UserResource 14 | { 15 | 16 | private String email; 17 | private String password; 18 | private List roles = new ArrayList(); 19 | 20 | public String getEmail() 21 | { 22 | return email; 23 | } 24 | public void setEmail(String email) 25 | { 26 | this.email = email; 27 | } 28 | public String getPassword() 29 | { 30 | return password; 31 | } 32 | public void setPassword(String password) 33 | { 34 | this.password = password; 35 | } 36 | public List getRoles() 37 | { 38 | return roles; 39 | } 40 | public void setRoles(List roles) 41 | { 42 | this.roles = roles; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /web/springboot-rest-api-design/src/main/java/com/sivalabs/blog/security/HttpAuthenticationEntryPoint.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.sivalabs.blog.security; 5 | 6 | import java.io.IOException; 7 | 8 | import javax.servlet.http.HttpServletRequest; 9 | import javax.servlet.http.HttpServletResponse; 10 | 11 | import org.springframework.security.core.AuthenticationException; 12 | import org.springframework.security.web.AuthenticationEntryPoint; 13 | import org.springframework.stereotype.Component; 14 | 15 | /** 16 | * @author Siva 17 | * 18 | */ 19 | @Component 20 | public class HttpAuthenticationEntryPoint implements AuthenticationEntryPoint { 21 | @Override 22 | public void commence(HttpServletRequest request, HttpServletResponse response, 23 | AuthenticationException authException) throws IOException { 24 | response.sendError(HttpServletResponse.SC_UNAUTHORIZED, authException.getMessage()); 25 | } 26 | } 27 | 28 | -------------------------------------------------------------------------------- /web/springboot-rest-api-design/src/main/java/com/sivalabs/blog/security/Token.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.blog.security; 2 | 3 | /** 4 | * The security token. 5 | */ 6 | public class Token { 7 | 8 | String token; 9 | long expires; 10 | 11 | public Token(String token, long expires){ 12 | this.token = token; 13 | this.expires = expires; 14 | } 15 | 16 | public String getToken() { 17 | return token; 18 | } 19 | 20 | public long getExpires() { 21 | return expires; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /web/springboot-rest-api-design/src/main/java/com/sivalabs/blog/services/UserService.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.sivalabs.blog.services; 5 | 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Service; 8 | import org.springframework.transaction.annotation.Transactional; 9 | 10 | import com.sivalabs.blog.entities.User; 11 | import com.sivalabs.blog.repositories.UserRepository; 12 | 13 | /** 14 | * @author Siva 15 | * 16 | */ 17 | @Service 18 | @Transactional 19 | public class UserService 20 | { 21 | 22 | @Autowired UserRepository userRepository; 23 | 24 | public User login(String email, String password) 25 | { 26 | return userRepository.findByEmailAndPassword(email, password); 27 | } 28 | 29 | public User createUser(User user) 30 | { 31 | return userRepository.save(user); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /web/springboot-rest-api-design/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | ################### Web Configuration ########################## 2 | 3 | #server.port=9090 4 | #server.context-path=/blog 5 | #server.servlet-path=/api/* 6 | 7 | spring.profiles.active=dev 8 | -------------------------------------------------------------------------------- /web/springboot-rest-api-design/src/main/resources/messages.properties: -------------------------------------------------------------------------------- 1 | appTitle=SivaLabs 2 | typeMismatch.user.dob=Invalid Date Of Birth value -------------------------------------------------------------------------------- /web/springboot-rest-api-design/src/main/resources/static/swagger-ui/fonts/droid-sans-v6-latin-700.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sivaprasadreddy/spring-boot-tutorials/11b6fdbc89397122b61353c07c4b9eb34ee1a703/web/springboot-rest-api-design/src/main/resources/static/swagger-ui/fonts/droid-sans-v6-latin-700.eot -------------------------------------------------------------------------------- /web/springboot-rest-api-design/src/main/resources/static/swagger-ui/fonts/droid-sans-v6-latin-700.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sivaprasadreddy/spring-boot-tutorials/11b6fdbc89397122b61353c07c4b9eb34ee1a703/web/springboot-rest-api-design/src/main/resources/static/swagger-ui/fonts/droid-sans-v6-latin-700.ttf -------------------------------------------------------------------------------- /web/springboot-rest-api-design/src/main/resources/static/swagger-ui/fonts/droid-sans-v6-latin-700.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sivaprasadreddy/spring-boot-tutorials/11b6fdbc89397122b61353c07c4b9eb34ee1a703/web/springboot-rest-api-design/src/main/resources/static/swagger-ui/fonts/droid-sans-v6-latin-700.woff -------------------------------------------------------------------------------- /web/springboot-rest-api-design/src/main/resources/static/swagger-ui/fonts/droid-sans-v6-latin-700.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sivaprasadreddy/spring-boot-tutorials/11b6fdbc89397122b61353c07c4b9eb34ee1a703/web/springboot-rest-api-design/src/main/resources/static/swagger-ui/fonts/droid-sans-v6-latin-700.woff2 -------------------------------------------------------------------------------- /web/springboot-rest-api-design/src/main/resources/static/swagger-ui/fonts/droid-sans-v6-latin-regular.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sivaprasadreddy/spring-boot-tutorials/11b6fdbc89397122b61353c07c4b9eb34ee1a703/web/springboot-rest-api-design/src/main/resources/static/swagger-ui/fonts/droid-sans-v6-latin-regular.eot -------------------------------------------------------------------------------- /web/springboot-rest-api-design/src/main/resources/static/swagger-ui/fonts/droid-sans-v6-latin-regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sivaprasadreddy/spring-boot-tutorials/11b6fdbc89397122b61353c07c4b9eb34ee1a703/web/springboot-rest-api-design/src/main/resources/static/swagger-ui/fonts/droid-sans-v6-latin-regular.ttf -------------------------------------------------------------------------------- /web/springboot-rest-api-design/src/main/resources/static/swagger-ui/fonts/droid-sans-v6-latin-regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sivaprasadreddy/spring-boot-tutorials/11b6fdbc89397122b61353c07c4b9eb34ee1a703/web/springboot-rest-api-design/src/main/resources/static/swagger-ui/fonts/droid-sans-v6-latin-regular.woff -------------------------------------------------------------------------------- /web/springboot-rest-api-design/src/main/resources/static/swagger-ui/fonts/droid-sans-v6-latin-regular.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sivaprasadreddy/spring-boot-tutorials/11b6fdbc89397122b61353c07c4b9eb34ee1a703/web/springboot-rest-api-design/src/main/resources/static/swagger-ui/fonts/droid-sans-v6-latin-regular.woff2 -------------------------------------------------------------------------------- /web/springboot-rest-api-design/src/main/resources/static/swagger-ui/images/explorer_icons.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sivaprasadreddy/spring-boot-tutorials/11b6fdbc89397122b61353c07c4b9eb34ee1a703/web/springboot-rest-api-design/src/main/resources/static/swagger-ui/images/explorer_icons.png -------------------------------------------------------------------------------- /web/springboot-rest-api-design/src/main/resources/static/swagger-ui/images/favicon-16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sivaprasadreddy/spring-boot-tutorials/11b6fdbc89397122b61353c07c4b9eb34ee1a703/web/springboot-rest-api-design/src/main/resources/static/swagger-ui/images/favicon-16x16.png -------------------------------------------------------------------------------- /web/springboot-rest-api-design/src/main/resources/static/swagger-ui/images/favicon-32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sivaprasadreddy/spring-boot-tutorials/11b6fdbc89397122b61353c07c4b9eb34ee1a703/web/springboot-rest-api-design/src/main/resources/static/swagger-ui/images/favicon-32x32.png -------------------------------------------------------------------------------- /web/springboot-rest-api-design/src/main/resources/static/swagger-ui/images/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sivaprasadreddy/spring-boot-tutorials/11b6fdbc89397122b61353c07c4b9eb34ee1a703/web/springboot-rest-api-design/src/main/resources/static/swagger-ui/images/favicon.ico -------------------------------------------------------------------------------- /web/springboot-rest-api-design/src/main/resources/static/swagger-ui/images/logo_small.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sivaprasadreddy/spring-boot-tutorials/11b6fdbc89397122b61353c07c4b9eb34ee1a703/web/springboot-rest-api-design/src/main/resources/static/swagger-ui/images/logo_small.png -------------------------------------------------------------------------------- /web/springboot-rest-api-design/src/main/resources/static/swagger-ui/images/pet_store_api.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sivaprasadreddy/spring-boot-tutorials/11b6fdbc89397122b61353c07c4b9eb34ee1a703/web/springboot-rest-api-design/src/main/resources/static/swagger-ui/images/pet_store_api.png -------------------------------------------------------------------------------- /web/springboot-rest-api-design/src/main/resources/static/swagger-ui/images/throbber.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sivaprasadreddy/spring-boot-tutorials/11b6fdbc89397122b61353c07c4b9eb34ee1a703/web/springboot-rest-api-design/src/main/resources/static/swagger-ui/images/throbber.gif -------------------------------------------------------------------------------- /web/springboot-rest-api-design/src/main/resources/static/swagger-ui/images/wordnik_api.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sivaprasadreddy/spring-boot-tutorials/11b6fdbc89397122b61353c07c4b9eb34ee1a703/web/springboot-rest-api-design/src/main/resources/static/swagger-ui/images/wordnik_api.png -------------------------------------------------------------------------------- /web/springboot-rest-api-design/src/main/resources/static/swagger-ui/lib/jquery.slideto.min.js: -------------------------------------------------------------------------------- 1 | (function(b){b.fn.slideto=function(a){a=b.extend({slide_duration:"slow",highlight_duration:3E3,highlight:true,highlight_color:"#FFFF99"},a);return this.each(function(){obj=b(this);b("body").animate({scrollTop:obj.offset().top},a.slide_duration,function(){a.highlight&&b.ui.version&&obj.effect("highlight",{color:a.highlight_color},a.highlight_duration)})})}})(jQuery); 2 | -------------------------------------------------------------------------------- /web/springboot-rest-api-design/src/main/resources/static/swagger-ui/lib/jquery.wiggle.min.js: -------------------------------------------------------------------------------- 1 | /* 2 | jQuery Wiggle 3 | Author: WonderGroup, Jordan Thomas 4 | URL: http://labs.wondergroup.com/demos/mini-ui/index.html 5 | License: MIT (http://en.wikipedia.org/wiki/MIT_License) 6 | */ 7 | jQuery.fn.wiggle=function(o){var d={speed:50,wiggles:3,travel:5,callback:null};var o=jQuery.extend(d,o);return this.each(function(){var cache=this;var wrap=jQuery(this).wrap('
').css("position","relative");var calls=0;for(i=1;i<=o.wiggles;i++){jQuery(this).animate({left:"-="+o.travel},o.speed).animate({left:"+="+o.travel*2},o.speed*2).animate({left:"-="+o.travel},o.speed,function(){calls++;if(jQuery(cache).parent().hasClass('wiggle-wrap')){jQuery(cache).parent().replaceWith(cache);} 8 | if(calls==o.wiggles&&jQuery.isFunction(o.callback)){o.callback();}});}});}; -------------------------------------------------------------------------------- /web/springboot-rest-api-design/src/main/resources/static/swagger-ui/o2c.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /web/springboot-rest-api-design/src/test/java/com/sivalabs/blog/TestUtil.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.sivalabs.blog; 5 | 6 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; 7 | 8 | /** 9 | * @author Siva 10 | * 11 | */ 12 | public class TestUtil 13 | { 14 | 15 | /** 16 | * @param args 17 | */ 18 | public static void main(String[] args) 19 | { 20 | BCryptPasswordEncoder encoder = new BCryptPasswordEncoder(); 21 | System.out.println("admin: "+encoder.encode("admin")); 22 | System.out.println("siva: "+encoder.encode("siva")); 23 | 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /web/springboot-thymeleaf-demo/src/main/java/com/sivalabs/demo/HomeController.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.demo; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | 6 | /** 7 | * Created by Siva on 18-02-2016. 8 | */ 9 | @Controller 10 | public class HomeController { 11 | 12 | @RequestMapping("/") 13 | public String index(){ 14 | return "index"; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /web/springboot-thymeleaf-demo/src/main/java/com/sivalabs/demo/SpringBootThymeleafApplication.java: -------------------------------------------------------------------------------- 1 | package com.sivalabs.demo; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * Created by Siva on 18-02-2016. 8 | */ 9 | @SpringBootApplication 10 | public class SpringBootThymeleafApplication { 11 | 12 | public static void main(String[] args) { 13 | SpringApplication.run(SpringBootThymeleafApplication.class, args); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /web/springboot-thymeleaf-demo/src/main/resources/templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Home 6 | 7 | 8 | Welcome 9 | 10 | --------------------------------------------------------------------------------