├── firstapp
├── src
│ ├── main
│ │ ├── resources
│ │ │ └── application.properties
│ │ └── java
│ │ │ └── com
│ │ │ └── bharath
│ │ │ └── spring
│ │ │ └── security
│ │ │ ├── HelloController.java
│ │ │ ├── FirstappApplication.java
│ │ │ ├── MyAuthenticationProvider.java
│ │ │ └── MySecurityConfig.java
│ └── test
│ │ └── java
│ │ └── com
│ │ └── bharath
│ │ └── spring
│ │ └── security
│ │ └── FirstappApplicationTests.java
├── .DS_Store
├── .mvn
│ └── wrapper
│ │ ├── maven-wrapper.jar
│ │ ├── maven-wrapper.properties
│ │ └── MavenWrapperDownloader.java
├── .gitignore
└── pom.xml
├── .DS_Store
├── couponreactclient
├── public
│ ├── robots.txt
│ ├── favicon.ico
│ ├── logo192.png
│ ├── logo512.png
│ ├── manifest.json
│ └── index.html
├── src
│ ├── setupTests.js
│ ├── App.test.js
│ ├── index.css
│ ├── index.js
│ ├── App.js
│ ├── App.css
│ ├── logo.svg
│ └── serviceWorker.js
├── .gitignore
└── package.json
├── authserver
├── .DS_Store
├── .mvn
│ └── wrapper
│ │ ├── maven-wrapper.jar
│ │ ├── maven-wrapper.properties
│ │ └── MavenWrapperDownloader.java
├── src
│ ├── main
│ │ ├── resources
│ │ │ ├── jwtiscool.jks
│ │ │ └── application.properties
│ │ └── java
│ │ │ └── com
│ │ │ └── bharath
│ │ │ └── springcloud
│ │ │ └── security
│ │ │ ├── RoleRepo.java
│ │ │ ├── UserRepo.java
│ │ │ ├── AuthserverApplication.java
│ │ │ ├── OAuth2SecurityConfig.java
│ │ │ ├── UserDetailsServiceImpl.java
│ │ │ ├── Role.java
│ │ │ ├── User.java
│ │ │ └── AuthorizationServerConfig.java
│ └── test
│ │ └── java
│ │ └── com
│ │ └── bharath
│ │ └── springcloud
│ │ └── security
│ │ └── AuthserverApplicationTests.java
├── .gitignore
└── pom.xml
├── couponservice
├── .DS_Store
├── src
│ ├── .DS_Store
│ ├── main
│ │ ├── .DS_Store
│ │ ├── java
│ │ │ ├── .DS_Store
│ │ │ └── com
│ │ │ │ ├── .DS_Store
│ │ │ │ └── bharath
│ │ │ │ ├── .DS_Store
│ │ │ │ └── springcloud
│ │ │ │ ├── .DS_Store
│ │ │ │ ├── security
│ │ │ │ ├── SecurityService.java
│ │ │ │ ├── config
│ │ │ │ │ ├── OAuth2SecurityConfig.java
│ │ │ │ │ ├── ResouceServerConfig.java
│ │ │ │ │ └── WebSecurityConfig.java
│ │ │ │ ├── UserDetailsServiceImpl.java
│ │ │ │ └── SecurityServiceImpl.java
│ │ │ │ ├── repos
│ │ │ │ ├── RoleRepo.java
│ │ │ │ ├── UserRepo.java
│ │ │ │ └── CouponRepo.java
│ │ │ │ ├── CouponserviceApplication.java
│ │ │ │ ├── model
│ │ │ │ ├── Role.java
│ │ │ │ ├── Coupon.java
│ │ │ │ └── User.java
│ │ │ │ └── controllers
│ │ │ │ ├── CouponRestController.java
│ │ │ │ ├── CouponController.java
│ │ │ │ └── UserController.java
│ │ └── resources
│ │ │ ├── .jks
│ │ │ ├── jwtiscool.jks
│ │ │ ├── templates
│ │ │ ├── createResponse.html
│ │ │ ├── index.html
│ │ │ ├── getCoupon.html
│ │ │ ├── couponDetails.html
│ │ │ ├── testcors.html
│ │ │ ├── createCoupon.html
│ │ │ ├── login.html
│ │ │ └── registerUser.html
│ │ │ └── application.properties
│ └── test
│ │ ├── .DS_Store
│ │ └── java
│ │ ├── .DS_Store
│ │ └── com
│ │ ├── .DS_Store
│ │ └── bharath
│ │ ├── .DS_Store
│ │ └── springcloud
│ │ └── CouponserviceApplicationTests.java
├── .mvn
│ └── wrapper
│ │ ├── maven-wrapper.jar
│ │ ├── maven-wrapper.properties
│ │ └── MavenWrapperDownloader.java
├── sql
│ └── tables.sql
├── .gitignore
└── pom.xml
└── productservice
├── .DS_Store
├── src
├── .DS_Store
├── main
│ ├── .DS_Store
│ ├── java
│ │ ├── .DS_Store
│ │ └── com
│ │ │ ├── .DS_Store
│ │ │ └── bharath
│ │ │ ├── .DS_Store
│ │ │ └── springcloud
│ │ │ ├── repos
│ │ │ └── ProductRepo.java
│ │ │ ├── ProductserviceApplication.java
│ │ │ ├── dto
│ │ │ └── Coupon.java
│ │ │ ├── controllers
│ │ │ └── ProductRestController.java
│ │ │ └── model
│ │ │ └── Product.java
│ └── resources
│ │ └── application.properties
└── test
│ └── java
│ └── com
│ └── bharath
│ └── springcloud
│ └── ProductserviceApplicationTests.java
├── .mvn
└── wrapper
│ ├── maven-wrapper.jar
│ ├── maven-wrapper.properties
│ └── MavenWrapperDownloader.java
├── .gitignore
└── pom.xml
/firstapp/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bharaththippireddy/springsecurityfundamentals/HEAD/.DS_Store
--------------------------------------------------------------------------------
/couponreactclient/public/robots.txt:
--------------------------------------------------------------------------------
1 | # https://www.robotstxt.org/robotstxt.html
2 | User-agent: *
3 | Disallow:
4 |
--------------------------------------------------------------------------------
/firstapp/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bharaththippireddy/springsecurityfundamentals/HEAD/firstapp/.DS_Store
--------------------------------------------------------------------------------
/authserver/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bharaththippireddy/springsecurityfundamentals/HEAD/authserver/.DS_Store
--------------------------------------------------------------------------------
/couponservice/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bharaththippireddy/springsecurityfundamentals/HEAD/couponservice/.DS_Store
--------------------------------------------------------------------------------
/productservice/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bharaththippireddy/springsecurityfundamentals/HEAD/productservice/.DS_Store
--------------------------------------------------------------------------------
/couponservice/src/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bharaththippireddy/springsecurityfundamentals/HEAD/couponservice/src/.DS_Store
--------------------------------------------------------------------------------
/productservice/src/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bharaththippireddy/springsecurityfundamentals/HEAD/productservice/src/.DS_Store
--------------------------------------------------------------------------------
/couponservice/src/main/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bharaththippireddy/springsecurityfundamentals/HEAD/couponservice/src/main/.DS_Store
--------------------------------------------------------------------------------
/couponservice/src/test/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bharaththippireddy/springsecurityfundamentals/HEAD/couponservice/src/test/.DS_Store
--------------------------------------------------------------------------------
/productservice/src/main/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bharaththippireddy/springsecurityfundamentals/HEAD/productservice/src/main/.DS_Store
--------------------------------------------------------------------------------
/couponreactclient/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bharaththippireddy/springsecurityfundamentals/HEAD/couponreactclient/public/favicon.ico
--------------------------------------------------------------------------------
/couponreactclient/public/logo192.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bharaththippireddy/springsecurityfundamentals/HEAD/couponreactclient/public/logo192.png
--------------------------------------------------------------------------------
/couponreactclient/public/logo512.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bharaththippireddy/springsecurityfundamentals/HEAD/couponreactclient/public/logo512.png
--------------------------------------------------------------------------------
/couponservice/src/main/java/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bharaththippireddy/springsecurityfundamentals/HEAD/couponservice/src/main/java/.DS_Store
--------------------------------------------------------------------------------
/couponservice/src/main/resources/.jks:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bharaththippireddy/springsecurityfundamentals/HEAD/couponservice/src/main/resources/.jks
--------------------------------------------------------------------------------
/couponservice/src/test/java/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bharaththippireddy/springsecurityfundamentals/HEAD/couponservice/src/test/java/.DS_Store
--------------------------------------------------------------------------------
/productservice/src/main/java/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bharaththippireddy/springsecurityfundamentals/HEAD/productservice/src/main/java/.DS_Store
--------------------------------------------------------------------------------
/authserver/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bharaththippireddy/springsecurityfundamentals/HEAD/authserver/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/couponservice/src/main/java/com/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bharaththippireddy/springsecurityfundamentals/HEAD/couponservice/src/main/java/com/.DS_Store
--------------------------------------------------------------------------------
/couponservice/src/test/java/com/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bharaththippireddy/springsecurityfundamentals/HEAD/couponservice/src/test/java/com/.DS_Store
--------------------------------------------------------------------------------
/firstapp/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bharaththippireddy/springsecurityfundamentals/HEAD/firstapp/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/authserver/src/main/resources/jwtiscool.jks:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bharaththippireddy/springsecurityfundamentals/HEAD/authserver/src/main/resources/jwtiscool.jks
--------------------------------------------------------------------------------
/productservice/src/main/java/com/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bharaththippireddy/springsecurityfundamentals/HEAD/productservice/src/main/java/com/.DS_Store
--------------------------------------------------------------------------------
/couponservice/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bharaththippireddy/springsecurityfundamentals/HEAD/couponservice/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/couponservice/.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 |
--------------------------------------------------------------------------------
/couponservice/src/main/resources/jwtiscool.jks:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bharaththippireddy/springsecurityfundamentals/HEAD/couponservice/src/main/resources/jwtiscool.jks
--------------------------------------------------------------------------------
/productservice/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bharaththippireddy/springsecurityfundamentals/HEAD/productservice/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/productservice/.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 |
--------------------------------------------------------------------------------
/couponservice/src/main/java/com/bharath/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bharaththippireddy/springsecurityfundamentals/HEAD/couponservice/src/main/java/com/bharath/.DS_Store
--------------------------------------------------------------------------------
/couponservice/src/test/java/com/bharath/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bharaththippireddy/springsecurityfundamentals/HEAD/couponservice/src/test/java/com/bharath/.DS_Store
--------------------------------------------------------------------------------
/productservice/src/main/java/com/bharath/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bharaththippireddy/springsecurityfundamentals/HEAD/productservice/src/main/java/com/bharath/.DS_Store
--------------------------------------------------------------------------------
/couponservice/src/main/java/com/bharath/springcloud/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bharaththippireddy/springsecurityfundamentals/HEAD/couponservice/src/main/java/com/bharath/springcloud/.DS_Store
--------------------------------------------------------------------------------
/couponservice/src/main/java/com/bharath/springcloud/security/SecurityService.java:
--------------------------------------------------------------------------------
1 | package com.bharath.springcloud.security;
2 |
3 | public interface SecurityService {
4 |
5 | boolean login(String userName,String password);
6 | }
7 |
--------------------------------------------------------------------------------
/couponservice/src/main/resources/templates/createResponse.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Create Response
6 |
7 |
8 | Coupon got created successfully!!
9 |
10 |
--------------------------------------------------------------------------------
/firstapp/.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 |
--------------------------------------------------------------------------------
/authserver/.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 |
--------------------------------------------------------------------------------
/authserver/src/main/java/com/bharath/springcloud/security/RoleRepo.java:
--------------------------------------------------------------------------------
1 | package com.bharath.springcloud.security;
2 |
3 | import org.springframework.data.jpa.repository.JpaRepository;
4 |
5 |
6 | public interface RoleRepo extends JpaRepository {
7 |
8 | }
9 |
--------------------------------------------------------------------------------
/productservice/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | spring.datasource.url=jdbc:mysql://localhost:3306/mydb
2 | spring.datasource.username=root
3 | spring.datasource.password=test1234
4 |
5 | server.port=9090
6 |
7 | couponService.url=http://localhost:9091/couponapi/coupons/
--------------------------------------------------------------------------------
/authserver/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | spring.datasource.url=jdbc:mysql://localhost:3306/mydb
2 | spring.datasource.username=root
3 | spring.datasource.password=test1234
4 |
5 | server.port=9092
6 |
7 |
8 | keyFile=jwtiscool.jks
9 | password=jwtiscool
10 | alias=jwtiscool
--------------------------------------------------------------------------------
/authserver/src/main/java/com/bharath/springcloud/security/UserRepo.java:
--------------------------------------------------------------------------------
1 | package com.bharath.springcloud.security;
2 |
3 | import org.springframework.data.jpa.repository.JpaRepository;
4 |
5 | public interface UserRepo extends JpaRepository {
6 | User findByEmail(String email);
7 | }
8 |
--------------------------------------------------------------------------------
/couponreactclient/src/setupTests.js:
--------------------------------------------------------------------------------
1 | // jest-dom adds custom jest matchers for asserting on DOM nodes.
2 | // allows you to do things like:
3 | // expect(element).toHaveTextContent(/react/i)
4 | // learn more: https://github.com/testing-library/jest-dom
5 | import '@testing-library/jest-dom/extend-expect';
6 |
--------------------------------------------------------------------------------
/couponservice/src/main/java/com/bharath/springcloud/repos/RoleRepo.java:
--------------------------------------------------------------------------------
1 | package com.bharath.springcloud.repos;
2 |
3 | import org.springframework.data.jpa.repository.JpaRepository;
4 |
5 | import com.bharath.springcloud.model.Role;
6 |
7 | public interface RoleRepo extends JpaRepository {
8 |
9 | }
10 |
--------------------------------------------------------------------------------
/couponservice/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | spring.datasource.url=jdbc:mysql://localhost:3306/mydb
2 | spring.datasource.username=root
3 | spring.datasource.password=test1234
4 |
5 | server.port=9091
6 |
7 | spring.thymeleaf.cache=false
8 |
9 | security.oauth2.resource.jwt.key-uri=http://localhost:9092/oauth/token_key
--------------------------------------------------------------------------------
/couponservice/src/main/resources/templates/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Coupon Home
6 |
7 |
8 | Create Coupon
9 | Get Coupon
10 | Logout
11 |
12 |
--------------------------------------------------------------------------------
/productservice/src/main/java/com/bharath/springcloud/repos/ProductRepo.java:
--------------------------------------------------------------------------------
1 | package com.bharath.springcloud.repos;
2 |
3 | import org.springframework.data.jpa.repository.JpaRepository;
4 |
5 | import com.bharath.springcloud.model.Product;
6 |
7 | public interface ProductRepo extends JpaRepository {
8 |
9 | }
10 |
--------------------------------------------------------------------------------
/couponservice/src/main/resources/templates/getCoupon.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Get Coupon
6 |
7 |
8 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/couponreactclient/src/App.test.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import { render } from '@testing-library/react';
3 | import App from './App';
4 |
5 | test('renders learn react link', () => {
6 | const { getByText } = render();
7 | const linkElement = getByText(/learn react/i);
8 | expect(linkElement).toBeInTheDocument();
9 | });
10 |
--------------------------------------------------------------------------------
/couponservice/src/main/java/com/bharath/springcloud/repos/UserRepo.java:
--------------------------------------------------------------------------------
1 | package com.bharath.springcloud.repos;
2 |
3 | import org.springframework.data.jpa.repository.JpaRepository;
4 |
5 | import com.bharath.springcloud.model.User;
6 |
7 | public interface UserRepo extends JpaRepository {
8 | User findByEmail(String email);
9 | }
10 |
--------------------------------------------------------------------------------
/couponservice/sql/tables.sql:
--------------------------------------------------------------------------------
1 | use mydb;
2 |
3 | create table product(
4 | id int AUTO_INCREMENT PRIMARY KEY,
5 | name varchar(20),
6 | description varchar(100),
7 | price decimal(8,3)
8 | );
9 |
10 | create table coupon(
11 | id int AUTO_INCREMENT PRIMARY KEY,
12 | code varchar(20) UNIQUE,
13 | discount decimal(8,3),
14 | exp_date varchar(100)
15 | );
--------------------------------------------------------------------------------
/authserver/src/test/java/com/bharath/springcloud/security/AuthserverApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.bharath.springcloud.security;
2 |
3 | import org.junit.jupiter.api.Test;
4 | import org.springframework.boot.test.context.SpringBootTest;
5 |
6 | @SpringBootTest
7 | class AuthserverApplicationTests {
8 |
9 | @Test
10 | void contextLoads() {
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/couponservice/src/main/java/com/bharath/springcloud/repos/CouponRepo.java:
--------------------------------------------------------------------------------
1 | package com.bharath.springcloud.repos;
2 |
3 | import org.springframework.data.jpa.repository.JpaRepository;
4 |
5 | import com.bharath.springcloud.model.Coupon;
6 |
7 | public interface CouponRepo extends JpaRepository {
8 |
9 | Coupon findByCode(String code);
10 |
11 | }
12 |
--------------------------------------------------------------------------------
/couponservice/src/main/resources/templates/couponDetails.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Coupon Details
6 |
7 |
8 | Coupon Details
9 | Code:
10 | Discount:
11 | Expiry Date:
12 |
13 |
--------------------------------------------------------------------------------
/firstapp/src/main/java/com/bharath/spring/security/HelloController.java:
--------------------------------------------------------------------------------
1 | package com.bharath.spring.security;
2 |
3 | import org.springframework.web.bind.annotation.GetMapping;
4 | import org.springframework.web.bind.annotation.RestController;
5 |
6 | @RestController
7 | public class HelloController {
8 |
9 | @GetMapping("/hello")
10 | public String hello() {
11 | return "Spring Security Rocks!!";
12 |
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/couponreactclient/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | /node_modules
5 | /.pnp
6 | .pnp.js
7 |
8 | # testing
9 | /coverage
10 |
11 | # production
12 | /build
13 |
14 | # misc
15 | .DS_Store
16 | .env.local
17 | .env.development.local
18 | .env.test.local
19 | .env.production.local
20 |
21 | npm-debug.log*
22 | yarn-debug.log*
23 | yarn-error.log*
24 |
--------------------------------------------------------------------------------
/couponreactclient/src/index.css:
--------------------------------------------------------------------------------
1 | body {
2 | margin: 0;
3 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
4 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
5 | sans-serif;
6 | -webkit-font-smoothing: antialiased;
7 | -moz-osx-font-smoothing: grayscale;
8 | }
9 |
10 | code {
11 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
12 | monospace;
13 | }
14 |
--------------------------------------------------------------------------------
/firstapp/src/main/java/com/bharath/spring/security/FirstappApplication.java:
--------------------------------------------------------------------------------
1 | package com.bharath.spring.security;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class FirstappApplication {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(FirstappApplication.class, args);
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/couponservice/src/main/java/com/bharath/springcloud/CouponserviceApplication.java:
--------------------------------------------------------------------------------
1 | package com.bharath.springcloud;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class CouponserviceApplication {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(CouponserviceApplication.class, args);
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/authserver/src/main/java/com/bharath/springcloud/security/AuthserverApplication.java:
--------------------------------------------------------------------------------
1 | package com.bharath.springcloud.security;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class AuthserverApplication {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(AuthserverApplication.class, args);
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/couponservice/.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 |
--------------------------------------------------------------------------------
/couponservice/src/main/resources/templates/testcors.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/productservice/.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 |
--------------------------------------------------------------------------------
/productservice/src/test/java/com/bharath/springcloud/ProductserviceApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.bharath.springcloud;
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 ProductserviceApplicationTests {
11 |
12 | @Test
13 | public void contextLoads() {
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/couponservice/src/main/resources/templates/createCoupon.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Create Coupon
6 |
7 |
8 | Create Coupon
9 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/authserver/.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 |
--------------------------------------------------------------------------------
/firstapp/.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 |
--------------------------------------------------------------------------------
/couponreactclient/src/index.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import ReactDOM from 'react-dom';
3 | import './index.css';
4 | import App from './App';
5 | import * as serviceWorker from './serviceWorker';
6 |
7 | ReactDOM.render(
8 |
9 |
10 | ,
11 | document.getElementById('root')
12 | );
13 |
14 | // If you want your app to work offline and load faster, you can change
15 | // unregister() to register() below. Note this comes with some pitfalls.
16 | // Learn more about service workers: https://bit.ly/CRA-PWA
17 | serviceWorker.unregister();
18 |
--------------------------------------------------------------------------------
/couponreactclient/src/App.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import axios from "axios";
3 | import {useEffect} from "react";
4 |
5 |
6 | function App() {
7 |
8 | useEffect(()=>{
9 | axios.get('http://localhost:9091/couponapi/coupons/SUPERSALE').then((response) => {
10 | document.write("Coupon Code: "+response.data.code+"
")
11 | document.write("Coupon Discount: "+response.data.discount+"
")
12 | document.write("Coupon Expiry Date: "+response.data.expDate+"
")
13 | });
14 |
15 | },[])
16 |
17 | return (
18 |
19 |
20 | );
21 |
22 | }
23 |
24 | export default App;
25 |
--------------------------------------------------------------------------------
/couponreactclient/public/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "short_name": "React App",
3 | "name": "Create React App Sample",
4 | "icons": [
5 | {
6 | "src": "favicon.ico",
7 | "sizes": "64x64 32x32 24x24 16x16",
8 | "type": "image/x-icon"
9 | },
10 | {
11 | "src": "logo192.png",
12 | "type": "image/png",
13 | "sizes": "192x192"
14 | },
15 | {
16 | "src": "logo512.png",
17 | "type": "image/png",
18 | "sizes": "512x512"
19 | }
20 | ],
21 | "start_url": ".",
22 | "display": "standalone",
23 | "theme_color": "#000000",
24 | "background_color": "#ffffff"
25 | }
26 |
--------------------------------------------------------------------------------
/couponservice/src/main/resources/templates/login.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | User Login
6 |
7 |
8 | Login:
9 |
18 |
19 |
--------------------------------------------------------------------------------
/couponservice/src/main/resources/templates/registerUser.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Register User
5 |
6 |
7 | User Registration:
8 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/productservice/src/main/java/com/bharath/springcloud/ProductserviceApplication.java:
--------------------------------------------------------------------------------
1 | package com.bharath.springcloud;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.context.annotation.Bean;
6 | import org.springframework.web.client.RestTemplate;
7 |
8 | @SpringBootApplication
9 | public class ProductserviceApplication {
10 |
11 | @Bean
12 | public RestTemplate restTemplate() {
13 | return new RestTemplate();
14 | }
15 |
16 | public static void main(String[] args) {
17 | SpringApplication.run(ProductserviceApplication.class, args);
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/couponreactclient/src/App.css:
--------------------------------------------------------------------------------
1 | .App {
2 | text-align: center;
3 | }
4 |
5 | .App-logo {
6 | height: 40vmin;
7 | pointer-events: none;
8 | }
9 |
10 | @media (prefers-reduced-motion: no-preference) {
11 | .App-logo {
12 | animation: App-logo-spin infinite 20s linear;
13 | }
14 | }
15 |
16 | .App-header {
17 | background-color: #282c34;
18 | min-height: 100vh;
19 | display: flex;
20 | flex-direction: column;
21 | align-items: center;
22 | justify-content: center;
23 | font-size: calc(10px + 2vmin);
24 | color: white;
25 | }
26 |
27 | .App-link {
28 | color: #61dafb;
29 | }
30 |
31 | @keyframes App-logo-spin {
32 | from {
33 | transform: rotate(0deg);
34 | }
35 | to {
36 | transform: rotate(360deg);
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/productservice/src/main/java/com/bharath/springcloud/dto/Coupon.java:
--------------------------------------------------------------------------------
1 | package com.bharath.springcloud.dto;
2 |
3 | import java.math.BigDecimal;
4 |
5 | public class Coupon {
6 | private Long id;
7 | private String code;
8 | private BigDecimal discount;
9 | private String expDate;
10 |
11 | public String getCode() {
12 | return code;
13 | }
14 |
15 | public void setCode(String code) {
16 | this.code = code;
17 | }
18 |
19 | public BigDecimal getDiscount() {
20 | return discount;
21 | }
22 |
23 | public void setDiscount(BigDecimal discount) {
24 | this.discount = discount;
25 | }
26 |
27 | public String getExpDate() {
28 | return expDate;
29 | }
30 |
31 | public void setExpDate(String expDate) {
32 | this.expDate = expDate;
33 | }
34 |
35 | public Long getId() {
36 | return id;
37 | }
38 |
39 | public void setId(Long id) {
40 | this.id = id;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/authserver/src/main/java/com/bharath/springcloud/security/OAuth2SecurityConfig.java:
--------------------------------------------------------------------------------
1 | package com.bharath.springcloud.security;
2 |
3 | import org.springframework.context.annotation.Bean;
4 | import org.springframework.context.annotation.Configuration;
5 | import org.springframework.security.authentication.AuthenticationManager;
6 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
7 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
8 |
9 | @Configuration
10 | public class OAuth2SecurityConfig extends WebSecurityConfigurerAdapter {
11 |
12 | @Override
13 | @Bean
14 | public AuthenticationManager authenticationManagerBean() throws Exception {
15 | return super.authenticationManagerBean();
16 | }
17 |
18 | @Bean
19 | public BCryptPasswordEncoder bCryptPasswordEncoder() {
20 | return new BCryptPasswordEncoder();
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/couponservice/src/main/java/com/bharath/springcloud/security/config/OAuth2SecurityConfig.java:
--------------------------------------------------------------------------------
1 | package com.bharath.springcloud.security.config;
2 |
3 | import org.springframework.context.annotation.Bean;
4 | import org.springframework.context.annotation.Configuration;
5 | import org.springframework.security.authentication.AuthenticationManager;
6 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
7 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
8 |
9 | @Configuration
10 | public class OAuth2SecurityConfig extends WebSecurityConfigurerAdapter {
11 |
12 | @Override
13 | @Bean
14 | public AuthenticationManager authenticationManagerBean() throws Exception {
15 | return super.authenticationManagerBean();
16 | }
17 |
18 | @Bean
19 | public BCryptPasswordEncoder bCryptPasswordEncoder() {
20 | return new BCryptPasswordEncoder();
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/couponreactclient/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "couponreactclient",
3 | "version": "0.1.0",
4 | "private": true,
5 | "dependencies": {
6 | "@testing-library/jest-dom": "^4.2.4",
7 | "@testing-library/react": "^9.5.0",
8 | "@testing-library/user-event": "^7.2.1",
9 | "axios": "^0.20.0",
10 | "react": "^17.0.1",
11 | "react-dom": "^17.0.1",
12 | "react-scripts": "3.4.4"
13 | },
14 | "scripts": {
15 | "start": "react-scripts start",
16 | "build": "react-scripts build",
17 | "test": "react-scripts test",
18 | "eject": "react-scripts eject"
19 | },
20 | "eslintConfig": {
21 | "extends": "react-app"
22 | },
23 | "browserslist": {
24 | "production": [
25 | ">0.2%",
26 | "not dead",
27 | "not op_mini all"
28 | ],
29 | "development": [
30 | "last 1 chrome version",
31 | "last 1 firefox version",
32 | "last 1 safari version"
33 | ]
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/authserver/src/main/java/com/bharath/springcloud/security/UserDetailsServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.bharath.springcloud.security;
2 |
3 | import org.springframework.beans.factory.annotation.Autowired;
4 | import org.springframework.security.core.userdetails.UserDetails;
5 | import org.springframework.security.core.userdetails.UserDetailsService;
6 | import org.springframework.security.core.userdetails.UsernameNotFoundException;
7 | import org.springframework.stereotype.Service;
8 |
9 |
10 | @Service
11 | public class UserDetailsServiceImpl implements UserDetailsService {
12 |
13 | @Autowired
14 | UserRepo userRepo;
15 |
16 | @Override
17 | public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
18 |
19 | User user = userRepo.findByEmail(username);
20 | if (user == null) {
21 | throw new UsernameNotFoundException("User not found for email" + username);
22 | }
23 | return new org.springframework.security.core.userdetails.User(user.getEmail(), user.getPassword(),
24 | user.getRoles());
25 | }
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/couponservice/src/main/java/com/bharath/springcloud/model/Role.java:
--------------------------------------------------------------------------------
1 | package com.bharath.springcloud.model;
2 |
3 | import java.util.Set;
4 |
5 | import javax.persistence.Entity;
6 | import javax.persistence.GeneratedValue;
7 | import javax.persistence.GenerationType;
8 | import javax.persistence.Id;
9 | import javax.persistence.ManyToMany;
10 |
11 | import org.springframework.security.core.GrantedAuthority;
12 |
13 | @Entity
14 | public class Role implements GrantedAuthority {
15 |
16 | private static final long serialVersionUID = 1L;
17 | @Id
18 | @GeneratedValue(strategy = GenerationType.IDENTITY)
19 | private Long id;
20 | private String name;
21 | @ManyToMany(mappedBy = "roles")
22 | private Set users;
23 |
24 | public Long getId() {
25 | return id;
26 | }
27 |
28 | public void setId(Long id) {
29 | this.id = id;
30 | }
31 |
32 | public String getName() {
33 | return name;
34 | }
35 |
36 | public void setName(String name) {
37 | this.name = name;
38 | }
39 |
40 | @Override
41 | public String getAuthority() {
42 | return name;
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/authserver/src/main/java/com/bharath/springcloud/security/Role.java:
--------------------------------------------------------------------------------
1 | package com.bharath.springcloud.security;
2 |
3 | import java.util.Set;
4 |
5 | import javax.persistence.Entity;
6 | import javax.persistence.GeneratedValue;
7 | import javax.persistence.GenerationType;
8 | import javax.persistence.Id;
9 | import javax.persistence.ManyToMany;
10 |
11 | import org.springframework.security.core.GrantedAuthority;
12 |
13 | @Entity
14 | public class Role implements GrantedAuthority {
15 |
16 | private static final long serialVersionUID = 1L;
17 | @Id
18 | @GeneratedValue(strategy = GenerationType.IDENTITY)
19 | private Long id;
20 | private String name;
21 | @ManyToMany(mappedBy = "roles")
22 | private Set users;
23 |
24 | public Long getId() {
25 | return id;
26 | }
27 |
28 | public void setId(Long id) {
29 | this.id = id;
30 | }
31 |
32 | public String getName() {
33 | return name;
34 | }
35 |
36 | public void setName(String name) {
37 | this.name = name;
38 | }
39 |
40 | @Override
41 | public String getAuthority() {
42 | return name;
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/couponservice/src/main/java/com/bharath/springcloud/model/Coupon.java:
--------------------------------------------------------------------------------
1 | package com.bharath.springcloud.model;
2 |
3 | import java.math.BigDecimal;
4 |
5 | import javax.persistence.Entity;
6 | import javax.persistence.GeneratedValue;
7 | import javax.persistence.GenerationType;
8 | import javax.persistence.Id;
9 |
10 | @Entity
11 | public class Coupon {
12 |
13 | @Id
14 | @GeneratedValue(strategy = GenerationType.IDENTITY)
15 | private Long id;
16 | private String code;
17 | private BigDecimal discount;
18 | private String expDate;
19 |
20 | public String getCode() {
21 | return code;
22 | }
23 |
24 | public void setCode(String code) {
25 | this.code = code;
26 | }
27 |
28 | public BigDecimal getDiscount() {
29 | return discount;
30 | }
31 |
32 | public void setDiscount(BigDecimal discount) {
33 | this.discount = discount;
34 | }
35 |
36 | public String getExpDate() {
37 | return expDate;
38 | }
39 |
40 | public void setExpDate(String expDate) {
41 | this.expDate = expDate;
42 | }
43 |
44 | public Long getId() {
45 | return id;
46 | }
47 |
48 | public void setId(Long id) {
49 | this.id = id;
50 | }
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/couponservice/src/main/java/com/bharath/springcloud/security/UserDetailsServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.bharath.springcloud.security;
2 |
3 | import org.springframework.beans.factory.annotation.Autowired;
4 | import org.springframework.security.core.userdetails.UserDetails;
5 | import org.springframework.security.core.userdetails.UserDetailsService;
6 | import org.springframework.security.core.userdetails.UsernameNotFoundException;
7 | import org.springframework.stereotype.Service;
8 |
9 | import com.bharath.springcloud.model.User;
10 | import com.bharath.springcloud.repos.UserRepo;
11 |
12 | @Service
13 | public class UserDetailsServiceImpl implements UserDetailsService {
14 |
15 | @Autowired
16 | UserRepo userRepo;
17 |
18 | @Override
19 | public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
20 |
21 | User user = userRepo.findByEmail(username);
22 | if (user == null) {
23 | throw new UsernameNotFoundException("User not found for email" + username);
24 | }
25 | return new org.springframework.security.core.userdetails.User(user.getEmail(), user.getPassword(),
26 | user.getRoles());
27 | }
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/couponservice/src/main/java/com/bharath/springcloud/controllers/CouponRestController.java:
--------------------------------------------------------------------------------
1 | package com.bharath.springcloud.controllers;
2 |
3 | import org.springframework.beans.factory.annotation.Autowired;
4 | import org.springframework.web.bind.annotation.CrossOrigin;
5 | import org.springframework.web.bind.annotation.GetMapping;
6 | import org.springframework.web.bind.annotation.PathVariable;
7 | import org.springframework.web.bind.annotation.PostMapping;
8 | import org.springframework.web.bind.annotation.RequestBody;
9 | import org.springframework.web.bind.annotation.RequestMapping;
10 | import org.springframework.web.bind.annotation.RestController;
11 |
12 | import com.bharath.springcloud.model.Coupon;
13 | import com.bharath.springcloud.repos.CouponRepo;
14 |
15 | @RestController
16 | @RequestMapping("/couponapi")
17 | @CrossOrigin
18 | public class CouponRestController {
19 |
20 | @Autowired
21 | CouponRepo repo;
22 |
23 | @PostMapping("/coupons")
24 | public Coupon create(@RequestBody Coupon coupon) {
25 |
26 | return repo.save(coupon);
27 |
28 | }
29 |
30 | @GetMapping("/coupons/{code}")
31 | public Coupon getCoupon(@PathVariable("code") String code) {
32 | return repo.findByCode(code);
33 |
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/couponservice/src/main/java/com/bharath/springcloud/controllers/CouponController.java:
--------------------------------------------------------------------------------
1 | package com.bharath.springcloud.controllers;
2 |
3 | import org.springframework.beans.factory.annotation.Autowired;
4 | import org.springframework.stereotype.Controller;
5 | import org.springframework.web.bind.annotation.GetMapping;
6 | import org.springframework.web.bind.annotation.PostMapping;
7 | import org.springframework.web.servlet.ModelAndView;
8 |
9 | import com.bharath.springcloud.model.Coupon;
10 | import com.bharath.springcloud.repos.CouponRepo;
11 |
12 | @Controller
13 | public class CouponController {
14 |
15 | @Autowired
16 | private CouponRepo repo;
17 |
18 | @GetMapping("/showCreateCoupon")
19 | public String showCreateCoupon() {
20 | return "createCoupon";
21 | }
22 |
23 | @PostMapping("/saveCoupon")
24 | public String save(Coupon coupon) {
25 | repo.save(coupon);
26 | return "createResponse";
27 | }
28 |
29 | @GetMapping("/showGetCoupon")
30 | public String showGetCoupon() {
31 | return "getCoupon";
32 | }
33 |
34 | @PostMapping("/getCoupon")
35 | public ModelAndView getCoupon(String code) {
36 | ModelAndView mav = new ModelAndView("couponDetails");
37 | mav.addObject(repo.findByCode(code));
38 | return mav;
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/firstapp/src/test/java/com/bharath/spring/security/FirstappApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.bharath.spring.security;
2 |
3 | import java.util.HashMap;
4 | import java.util.Map;
5 |
6 | import org.junit.jupiter.api.Test;
7 | import org.springframework.boot.test.context.SpringBootTest;
8 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
9 | import org.springframework.security.crypto.password.DelegatingPasswordEncoder;
10 | import org.springframework.security.crypto.password.PasswordEncoder;
11 | import org.springframework.security.crypto.password.Pbkdf2PasswordEncoder;
12 | import org.springframework.security.crypto.scrypt.SCryptPasswordEncoder;
13 |
14 | @SpringBootTest
15 | class FirstappApplicationTests {
16 |
17 | @Test
18 | void testPasswordEncoders() {
19 | System.out.println(new BCryptPasswordEncoder().encode("password"));
20 | System.out.println(new Pbkdf2PasswordEncoder().encode("password"));
21 | System.out.println(new SCryptPasswordEncoder().encode("password"));
22 |
23 | Map encoders =new HashMap<>();
24 | encoders.put("bcrypt", new BCryptPasswordEncoder());
25 | encoders.put("scrypt", new SCryptPasswordEncoder());
26 |
27 | System.out.println(new DelegatingPasswordEncoder("bcrypt", encoders).encode("password"));
28 |
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/firstapp/src/main/java/com/bharath/spring/security/MyAuthenticationProvider.java:
--------------------------------------------------------------------------------
1 | package com.bharath.spring.security;
2 |
3 | import java.util.Arrays;
4 |
5 | import org.springframework.security.authentication.AuthenticationProvider;
6 | import org.springframework.security.authentication.BadCredentialsException;
7 | import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
8 | import org.springframework.security.core.Authentication;
9 | import org.springframework.security.core.AuthenticationException;
10 | import org.springframework.stereotype.Component;
11 |
12 | @Component
13 | public class MyAuthenticationProvider implements AuthenticationProvider {
14 |
15 | @Override
16 | public Authentication authenticate(Authentication authentication) throws AuthenticationException {
17 | String userName = authentication.getName();
18 | String password = authentication.getCredentials().toString();
19 | if ("tom".equals(userName) && "cruise".equals(password)) {
20 | return new UsernamePasswordAuthenticationToken(userName, password, Arrays.asList());
21 | } else {
22 | throw new BadCredentialsException("Invalid Username or Passwrod");
23 | }
24 | }
25 |
26 | @Override
27 | public boolean supports(Class> authentication) {
28 | return authentication.equals(UsernamePasswordAuthenticationToken.class);
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/couponservice/src/main/java/com/bharath/springcloud/security/config/ResouceServerConfig.java:
--------------------------------------------------------------------------------
1 | package com.bharath.springcloud.security.config;
2 |
3 | import org.springframework.context.annotation.Configuration;
4 | import org.springframework.http.HttpMethod;
5 | import org.springframework.security.config.annotation.web.builders.HttpSecurity;
6 | import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
7 | import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;
8 | import org.springframework.security.oauth2.config.annotation.web.configurers.ResourceServerSecurityConfigurer;
9 |
10 | @Configuration
11 | @EnableResourceServer
12 | public class ResouceServerConfig extends ResourceServerConfigurerAdapter {
13 | private static final String RESOURCE_ID = "couponservice";
14 |
15 | @Override
16 | public void configure(ResourceServerSecurityConfigurer resources) throws Exception {
17 | resources.resourceId(RESOURCE_ID);
18 | }
19 |
20 | @Override
21 | public void configure(HttpSecurity http) throws Exception {
22 | http.authorizeRequests().mvcMatchers(HttpMethod.GET, "/couponapi/coupons/{code:^[A-Z]*$}")
23 | .hasAnyRole("USER", "ADMIN").mvcMatchers(HttpMethod.POST, "/couponapi/coupons").hasRole("ADMIN")
24 | .anyRequest().denyAll().and().csrf().disable();
25 |
26 | }
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/couponservice/src/main/java/com/bharath/springcloud/security/SecurityServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.bharath.springcloud.security;
2 |
3 | import org.springframework.beans.factory.annotation.Autowired;
4 | import org.springframework.security.authentication.AuthenticationManager;
5 | import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
6 | import org.springframework.security.core.context.SecurityContextHolder;
7 | import org.springframework.security.core.userdetails.UserDetails;
8 | import org.springframework.security.core.userdetails.UserDetailsService;
9 | import org.springframework.stereotype.Service;
10 |
11 | @Service
12 | public class SecurityServiceImpl implements SecurityService {
13 |
14 | @Autowired
15 | UserDetailsService userDetailsService;
16 |
17 | @Autowired
18 | AuthenticationManager authenticationManger;
19 |
20 | @Override
21 | public boolean login(String userName, String password) {
22 | UserDetails userDetails = userDetailsService.loadUserByUsername(userName);
23 | UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(userDetails, password,
24 | userDetails.getAuthorities());
25 | authenticationManger.authenticate(token);
26 | boolean result = token.isAuthenticated();
27 |
28 | if (result) {
29 | SecurityContextHolder.getContext().setAuthentication(token);
30 | }
31 | return result;
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/productservice/src/main/java/com/bharath/springcloud/controllers/ProductRestController.java:
--------------------------------------------------------------------------------
1 | package com.bharath.springcloud.controllers;
2 |
3 | import org.springframework.beans.factory.annotation.Autowired;
4 | import org.springframework.beans.factory.annotation.Value;
5 | import org.springframework.web.bind.annotation.RequestBody;
6 | import org.springframework.web.bind.annotation.RequestMapping;
7 | import org.springframework.web.bind.annotation.RequestMethod;
8 | import org.springframework.web.bind.annotation.RestController;
9 | import org.springframework.web.client.RestTemplate;
10 |
11 | import com.bharath.springcloud.dto.Coupon;
12 | import com.bharath.springcloud.model.Product;
13 | import com.bharath.springcloud.repos.ProductRepo;
14 |
15 | @RestController
16 | @RequestMapping("/productapi")
17 | public class ProductRestController {
18 |
19 | @Autowired
20 | private ProductRepo repo;
21 |
22 | @Autowired
23 | private RestTemplate restTemplate;
24 |
25 | @Value("${couponService.url}")
26 | private String couponServiceURL;
27 |
28 | @RequestMapping(value = "/products", method = RequestMethod.POST)
29 | public Product create(@RequestBody Product product) {
30 | Coupon coupon = restTemplate.getForObject(couponServiceURL + product.getCouponCode(), Coupon.class);
31 | product.setPrice(product.getPrice().subtract(coupon.getDiscount()));
32 | return repo.save(product);
33 |
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/productservice/src/main/java/com/bharath/springcloud/model/Product.java:
--------------------------------------------------------------------------------
1 | package com.bharath.springcloud.model;
2 |
3 | import java.math.BigDecimal;
4 |
5 | import javax.persistence.Entity;
6 | import javax.persistence.GeneratedValue;
7 | import javax.persistence.GenerationType;
8 | import javax.persistence.Id;
9 | import javax.persistence.Transient;
10 |
11 | @Entity
12 | public class Product {
13 |
14 | @Id
15 | @GeneratedValue(strategy = GenerationType.IDENTITY)
16 | private Long id;
17 | private String name;
18 | private String description;
19 | private BigDecimal price;
20 | @Transient
21 | private String couponCode;
22 |
23 | public Long getId() {
24 | return id;
25 | }
26 |
27 | public void setId(Long id) {
28 | this.id = id;
29 | }
30 |
31 | public String getName() {
32 | return name;
33 | }
34 |
35 | public void setName(String name) {
36 | this.name = name;
37 | }
38 |
39 | public String getDescription() {
40 | return description;
41 | }
42 |
43 | public void setDescription(String description) {
44 | this.description = description;
45 | }
46 |
47 | public BigDecimal getPrice() {
48 | return price;
49 | }
50 |
51 | public void setPrice(BigDecimal price) {
52 | this.price = price;
53 | }
54 |
55 | public String getCouponCode() {
56 | return couponCode;
57 | }
58 |
59 | public void setCouponCode(String couponCode) {
60 | this.couponCode = couponCode;
61 | }
62 |
63 | }
64 |
--------------------------------------------------------------------------------
/couponservice/src/main/java/com/bharath/springcloud/controllers/UserController.java:
--------------------------------------------------------------------------------
1 | package com.bharath.springcloud.controllers;
2 |
3 | import org.springframework.beans.factory.annotation.Autowired;
4 | import org.springframework.security.crypto.password.PasswordEncoder;
5 | import org.springframework.stereotype.Controller;
6 | import org.springframework.web.bind.annotation.GetMapping;
7 | import org.springframework.web.bind.annotation.PostMapping;
8 |
9 | import com.bharath.springcloud.model.User;
10 | import com.bharath.springcloud.repos.UserRepo;
11 | import com.bharath.springcloud.security.SecurityService;
12 |
13 | @Controller
14 | public class UserController {
15 |
16 | @Autowired
17 | private SecurityService securityService;
18 |
19 | @Autowired
20 | private UserRepo userRepo;
21 |
22 | @Autowired
23 | private PasswordEncoder encoder;
24 |
25 | @GetMapping("/showReg")
26 | public String showRegistrationPage() {
27 | return "registerUser";
28 |
29 | }
30 |
31 | @PostMapping("/registerUser")
32 | public String register(User user) {
33 | user.setPassword(encoder.encode(user.getPassword()));
34 | userRepo.save(user);
35 | return "login";
36 | }
37 |
38 | @GetMapping("/")
39 | public String showLoginPage() {
40 | return "login";
41 | }
42 |
43 | @PostMapping("/login")
44 | public String login(String email, String password) {
45 | boolean loginResponse = securityService.login(email, password);
46 | if (loginResponse) {
47 | return "index";
48 | }
49 | return "login";
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/authserver/src/main/java/com/bharath/springcloud/security/User.java:
--------------------------------------------------------------------------------
1 | package com.bharath.springcloud.security;
2 |
3 | import java.util.Set;
4 |
5 | import javax.persistence.Entity;
6 | import javax.persistence.FetchType;
7 | import javax.persistence.GeneratedValue;
8 | import javax.persistence.GenerationType;
9 | import javax.persistence.Id;
10 | import javax.persistence.JoinColumn;
11 | import javax.persistence.JoinTable;
12 | import javax.persistence.ManyToMany;
13 |
14 | @Entity
15 | public class User {
16 | @Id
17 | @GeneratedValue(strategy = GenerationType.IDENTITY)
18 | private Long id;
19 | private String firstName;
20 | private String lastName;
21 | private String email;
22 | private String password;
23 | @ManyToMany(fetch = FetchType.EAGER)
24 | @JoinTable(name = "user_role", joinColumns = @JoinColumn(name = "user_id"), inverseJoinColumns = @JoinColumn(name = "role_id"))
25 | private Set roles;
26 |
27 | public Long getId() {
28 | return id;
29 | }
30 |
31 | public void setId(Long id) {
32 | this.id = id;
33 | }
34 |
35 | public String getFirstName() {
36 | return firstName;
37 | }
38 |
39 | public void setFirstName(String firstName) {
40 | this.firstName = firstName;
41 | }
42 |
43 | public String getLastName() {
44 | return lastName;
45 | }
46 |
47 | public void setLastName(String lastName) {
48 | this.lastName = lastName;
49 | }
50 |
51 | public String getEmail() {
52 | return email;
53 | }
54 |
55 | public void setEmail(String email) {
56 | this.email = email;
57 | }
58 |
59 | public String getPassword() {
60 | return password;
61 | }
62 |
63 | public void setPassword(String password) {
64 | this.password = password;
65 | }
66 |
67 | public Set getRoles() {
68 | return roles;
69 | }
70 |
71 | public void setRoles(Set roles) {
72 | this.roles = roles;
73 | }
74 |
75 | }
76 |
--------------------------------------------------------------------------------
/couponservice/src/main/java/com/bharath/springcloud/model/User.java:
--------------------------------------------------------------------------------
1 | package com.bharath.springcloud.model;
2 |
3 | import java.util.Set;
4 |
5 | import javax.persistence.Entity;
6 | import javax.persistence.FetchType;
7 | import javax.persistence.GeneratedValue;
8 | import javax.persistence.GenerationType;
9 | import javax.persistence.Id;
10 | import javax.persistence.JoinColumn;
11 | import javax.persistence.JoinTable;
12 | import javax.persistence.ManyToMany;
13 |
14 | @Entity
15 | public class User {
16 | @Id
17 | @GeneratedValue(strategy = GenerationType.IDENTITY)
18 | private Long id;
19 | private String firstName;
20 | private String lastName;
21 | private String email;
22 | private String password;
23 | @ManyToMany(fetch = FetchType.EAGER)
24 | @JoinTable(name = "user_role", joinColumns = @JoinColumn(name = "user_id"), inverseJoinColumns = @JoinColumn(name = "role_id"))
25 | private Set roles;
26 |
27 | public Long getId() {
28 | return id;
29 | }
30 |
31 | public void setId(Long id) {
32 | this.id = id;
33 | }
34 |
35 | public String getFirstName() {
36 | return firstName;
37 | }
38 |
39 | public void setFirstName(String firstName) {
40 | this.firstName = firstName;
41 | }
42 |
43 | public String getLastName() {
44 | return lastName;
45 | }
46 |
47 | public void setLastName(String lastName) {
48 | this.lastName = lastName;
49 | }
50 |
51 | public String getEmail() {
52 | return email;
53 | }
54 |
55 | public void setEmail(String email) {
56 | this.email = email;
57 | }
58 |
59 | public String getPassword() {
60 | return password;
61 | }
62 |
63 | public void setPassword(String password) {
64 | this.password = password;
65 | }
66 |
67 | public Set getRoles() {
68 | return roles;
69 | }
70 |
71 | public void setRoles(Set roles) {
72 | this.roles = roles;
73 | }
74 |
75 | }
76 |
--------------------------------------------------------------------------------
/couponreactclient/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
12 |
13 |
17 |
18 |
27 | React App
28 |
29 |
30 |
31 |
32 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/firstapp/src/main/java/com/bharath/spring/security/MySecurityConfig.java:
--------------------------------------------------------------------------------
1 | package com.bharath.spring.security;
2 |
3 | import org.springframework.beans.factory.annotation.Autowired;
4 | import org.springframework.context.annotation.Bean;
5 | import org.springframework.context.annotation.Configuration;
6 | import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
7 | import org.springframework.security.config.annotation.web.builders.HttpSecurity;
8 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
9 | import org.springframework.security.core.userdetails.User;
10 | import org.springframework.security.core.userdetails.UserDetails;
11 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
12 | import org.springframework.security.crypto.password.PasswordEncoder;
13 | import org.springframework.security.provisioning.InMemoryUserDetailsManager;
14 |
15 | @Configuration
16 | public class MySecurityConfig extends WebSecurityConfigurerAdapter {
17 |
18 | @Autowired
19 | private PasswordEncoder passwordEncoder;
20 |
21 | @Autowired
22 | private MyAuthenticationProvider authenticationProvider;
23 |
24 | // @Override
25 | // protected void configure(AuthenticationManagerBuilder auth) throws Exception {
26 | // InMemoryUserDetailsManager userDetailsService = new InMemoryUserDetailsManager();
27 | // UserDetails user = User.withUsername("tom").password(passwordEncoder.encode("cruise")).authorities("read").build();
28 | // userDetailsService.createUser(user);
29 | //
30 | // auth.userDetailsService(userDetailsService);
31 | // }
32 |
33 | @Override
34 | protected void configure(AuthenticationManagerBuilder auth) throws Exception {
35 | auth.authenticationProvider(authenticationProvider);
36 | }
37 |
38 | @Override
39 | protected void configure(HttpSecurity http) throws Exception {
40 | http.formLogin();
41 | http.authorizeRequests().anyRequest().authenticated();
42 | }
43 |
44 | @Bean
45 | public BCryptPasswordEncoder passwordEncoder() {
46 | return new BCryptPasswordEncoder();
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/productservice/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | org.springframework.boot
8 | spring-boot-starter-parent
9 | 2.2.6.RELEASE
10 |
11 |
12 | com.bharath.springcloud
13 | productservice
14 | 0.0.1-SNAPSHOT
15 | productservice
16 | Product Service
17 |
18 |
19 | 1.8
20 | Greenwich.SR3
21 |
22 |
23 |
24 |
25 | org.springframework.boot
26 | spring-boot-starter-data-jpa
27 |
28 |
29 | org.springframework.boot
30 | spring-boot-starter-web
31 |
32 |
33 | org.springframework.boot
34 | spring-boot-starter-actuator
35 |
36 |
37 |
38 | mysql
39 | mysql-connector-java
40 | runtime
41 |
42 |
43 | org.springframework.boot
44 | spring-boot-starter-test
45 | test
46 |
47 |
48 | org.springframework.boot
49 | spring-boot-starter
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 | org.springframework.boot
58 | spring-boot-maven-plugin
59 |
60 |
61 |
62 |
63 |
64 |
--------------------------------------------------------------------------------
/couponservice/src/test/java/com/bharath/springcloud/CouponserviceApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.bharath.springcloud;
2 |
3 | import java.util.HashMap;
4 | import java.util.Map;
5 |
6 | import org.junit.Test;
7 | import org.junit.runner.RunWith;
8 | import org.springframework.beans.factory.annotation.Autowired;
9 | import org.springframework.boot.test.context.SpringBootTest;
10 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
11 | import org.springframework.security.crypto.password.DelegatingPasswordEncoder;
12 | import org.springframework.security.crypto.password.PasswordEncoder;
13 | import org.springframework.security.crypto.password.Pbkdf2PasswordEncoder;
14 | import org.springframework.security.crypto.scrypt.SCryptPasswordEncoder;
15 | import org.springframework.security.oauth2.client.OAuth2RestTemplate;
16 | import org.springframework.test.context.junit4.SpringRunner;
17 |
18 | import com.bharath.springcloud.model.Coupon;
19 |
20 | @RunWith(SpringRunner.class)
21 | @SpringBootTest
22 | public class CouponserviceApplicationTests {
23 |
24 | @Autowired
25 | private OAuth2RestTemplate restTemplate;
26 |
27 | @Test
28 | public void contextLoads() {
29 | System.out.println(new Pbkdf2PasswordEncoder("secret", 10000, 128).encode("password"));
30 | System.out.println(new SCryptPasswordEncoder().encode("password"));
31 | System.out.println(new BCryptPasswordEncoder().encode("password"));
32 |
33 | Map encoders = new HashMap<>();
34 | encoders.put("bcrypt", new BCryptPasswordEncoder());
35 | encoders.put("scrypt", new SCryptPasswordEncoder());
36 | encoders.put("pbkdf2", new Pbkdf2PasswordEncoder());
37 |
38 | System.out.println(new DelegatingPasswordEncoder("pbkdf2", encoders).encode("password"));
39 |
40 | }
41 |
42 | @Test
43 | public void testOauth() {
44 | restTemplate.getOAuth2ClientContext().getAccessTokenRequest().set("username", "doug@bailey.com");
45 | restTemplate.getOAuth2ClientContext().getAccessTokenRequest().set("password", "doug");
46 | System.out.println(restTemplate.getForObject("http://localhost:9091/couponapi/coupons/SUPERSALE", Coupon.class));
47 | }
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/firstapp/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | org.springframework.boot
8 | spring-boot-starter-parent
9 | 2.3.4.RELEASE
10 |
11 |
12 | com.bharath.spring.security
13 | firstapp
14 | 0.0.1-SNAPSHOT
15 | firstapp
16 | First Secured App
17 |
18 |
19 | 11
20 |
21 |
22 |
23 |
24 | org.springframework.boot
25 | spring-boot-starter-security
26 |
27 |
28 | org.springframework.boot
29 | spring-boot-starter-web
30 |
31 |
32 | org.springframework.boot
33 | spring-boot-starter-thymeleaf
34 |
35 |
36 | org.bouncycastle
37 | bcprov-jdk15on
38 | 1.66
39 |
40 |
41 |
42 |
43 | org.springframework.boot
44 | spring-boot-starter-test
45 | test
46 |
47 |
48 | org.junit.vintage
49 | junit-vintage-engine
50 |
51 |
52 |
53 |
54 | org.springframework.security
55 | spring-security-test
56 | test
57 |
58 |
59 |
60 |
61 |
62 |
63 | org.springframework.boot
64 | spring-boot-maven-plugin
65 |
66 |
67 |
68 |
69 |
70 |
--------------------------------------------------------------------------------
/couponservice/src/main/java/com/bharath/springcloud/security/config/WebSecurityConfig.java:
--------------------------------------------------------------------------------
1 | package com.bharath.springcloud.security.config;
2 |
3 | import java.util.List;
4 |
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.context.annotation.Bean;
7 | import org.springframework.context.annotation.Configuration;
8 | import org.springframework.http.HttpMethod;
9 | import org.springframework.security.authentication.AuthenticationManager;
10 | import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
11 | import org.springframework.security.config.annotation.web.builders.HttpSecurity;
12 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
13 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
14 | import org.springframework.web.cors.CorsConfiguration;
15 | import org.springframework.web.cors.CorsConfigurationSource;
16 |
17 | import com.bharath.springcloud.security.UserDetailsServiceImpl;
18 |
19 | //@Configuration
20 | public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
21 |
22 | @Autowired
23 | UserDetailsServiceImpl userDetailsService;
24 |
25 | @Override
26 | protected void configure(AuthenticationManagerBuilder auth) throws Exception {
27 | auth.userDetailsService(userDetailsService);
28 | }
29 |
30 | @Override
31 | protected void configure(HttpSecurity http) throws Exception {
32 | http.authorizeRequests()
33 | .mvcMatchers(HttpMethod.GET, "/couponapi/coupons/{code:^[A-Z]*$}", "/index", "/showGetCoupon",
34 | "/getCoupon", "/couponDetails")
35 | .hasAnyRole("USER", "ADMIN")
36 | .mvcMatchers(HttpMethod.GET, "/showCreateCoupon", "/createCoupon", "/createResponse").hasRole("ADMIN")
37 | .mvcMatchers(HttpMethod.POST, "/getCoupon").hasAnyRole("USER", "ADMIN")
38 | .mvcMatchers(HttpMethod.POST, "/couponapi/coupons", "/saveCoupon", "/getCoupon").hasRole("ADMIN")
39 | .mvcMatchers("/", "/login", "/logout", "/showReg", "/registerUser").permitAll().anyRequest().denyAll()
40 | .and().logout().logoutSuccessUrl("/");
41 |
42 | }
43 |
44 | @Bean
45 | public BCryptPasswordEncoder bCryptPasswordEncoder() {
46 | return new BCryptPasswordEncoder();
47 | }
48 |
49 | @Override
50 | @Bean
51 | public AuthenticationManager authenticationManagerBean() throws Exception {
52 | return super.authenticationManagerBean();
53 | }
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/authserver/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | org.springframework.boot
8 | spring-boot-starter-parent
9 | 2.2.6.RELEASE
10 |
11 |
12 | com.bharath.springcloud.security
13 | authserver
14 | 0.0.1-SNAPSHOT
15 | authserver
16 | Auth Server
17 |
18 |
19 | 1.8
20 | Greenwich.SR3
21 |
22 |
23 |
24 |
25 | org.springframework.boot
26 | spring-boot-starter-data-jpa
27 |
28 |
29 | org.springframework.boot
30 | spring-boot-starter-web
31 |
32 |
33 | org.springframework.boot
34 | spring-boot-starter-security
35 |
36 |
37 | org.springframework.cloud
38 | spring-cloud-starter-oauth2
39 |
40 |
41 | org.springframework.boot
42 | spring-boot-starter-thymeleaf
43 |
44 |
45 | mysql
46 | mysql-connector-java
47 | runtime
48 |
49 |
50 | org.springframework.boot
51 | spring-boot-starter-test
52 | test
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 | org.springframework.boot
61 | spring-boot-maven-plugin
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 | org.springframework.cloud
70 | spring-cloud-dependencies
71 | Hoxton.SR1
72 | pom
73 | import
74 |
75 |
76 |
77 |
78 |
79 |
--------------------------------------------------------------------------------
/couponservice/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | org.springframework.boot
8 | spring-boot-starter-parent
9 | 2.2.6.RELEASE
10 |
11 |
12 | com.bharath.springcloud
13 | couponservice
14 | 0.0.1-SNAPSHOT
15 | couponservice
16 | Coupon Service
17 |
18 |
19 | 1.8
20 | Greenwich.SR3
21 |
22 |
23 |
24 |
25 | org.springframework.boot
26 | spring-boot-starter-data-jpa
27 |
28 |
29 | org.springframework.boot
30 | spring-boot-starter-web
31 |
32 |
33 | org.springframework.boot
34 | spring-boot-starter-security
35 |
36 |
37 | org.springframework.cloud
38 | spring-cloud-starter-oauth2
39 |
40 |
41 | org.springframework.boot
42 | spring-boot-starter-thymeleaf
43 |
44 |
45 | mysql
46 | mysql-connector-java
47 | runtime
48 |
49 |
50 | org.springframework.boot
51 | spring-boot-starter-test
52 | test
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 | org.springframework.boot
61 | spring-boot-maven-plugin
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 | org.springframework.cloud
70 | spring-cloud-dependencies
71 | Hoxton.SR1
72 | pom
73 | import
74 |
75 |
76 |
77 |
78 |
79 |
--------------------------------------------------------------------------------
/couponreactclient/src/logo.svg:
--------------------------------------------------------------------------------
1 |
8 |
--------------------------------------------------------------------------------
/authserver/src/main/java/com/bharath/springcloud/security/AuthorizationServerConfig.java:
--------------------------------------------------------------------------------
1 | package com.bharath.springcloud.security;
2 |
3 | import java.security.KeyPair;
4 |
5 | import javax.sql.DataSource;
6 |
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.beans.factory.annotation.Value;
9 | import org.springframework.context.annotation.Bean;
10 | import org.springframework.context.annotation.Configuration;
11 | import org.springframework.core.io.ClassPathResource;
12 | import org.springframework.security.authentication.AuthenticationManager;
13 | import org.springframework.security.core.userdetails.UserDetailsService;
14 | import org.springframework.security.crypto.password.PasswordEncoder;
15 | import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer;
16 | import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter;
17 | import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer;
18 | import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer;
19 | import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerSecurityConfigurer;
20 | import org.springframework.security.oauth2.provider.token.TokenStore;
21 | import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;
22 | import org.springframework.security.oauth2.provider.token.store.JwtTokenStore;
23 | import org.springframework.security.rsa.crypto.KeyStoreKeyFactory;
24 |
25 | @Configuration
26 | @EnableAuthorizationServer
27 | public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdapter {
28 |
29 | private static final String RESOURCE_ID = "couponservice";
30 |
31 | @Autowired
32 | private AuthenticationManager authenticationManager;
33 |
34 | @Autowired
35 | private UserDetailsService userDetailsService;
36 |
37 | @Autowired
38 | private PasswordEncoder passwordEncoder;
39 |
40 | @Autowired
41 | private DataSource dataSource;
42 |
43 | @Value("${keyFile}")
44 | private String keyFile;
45 | @Value("${password}")
46 | private String password;
47 | @Value("${alias}")
48 | private String alias;
49 |
50 | @Override
51 | public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
52 | endpoints.tokenStore(tokenStore()).accessTokenConverter(jwtAccessTokenConverter())
53 | .authenticationManager(authenticationManager).userDetailsService(userDetailsService);
54 | }
55 |
56 | @Override
57 | public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
58 | clients.inMemory().withClient("couponclientapp").secret(passwordEncoder.encode("9999"))
59 | .authorizedGrantTypes("password", "refresh_token").scopes("read", "write").resourceIds(RESOURCE_ID);
60 | ;
61 | }
62 |
63 | @Override
64 | public void configure(AuthorizationServerSecurityConfigurer security) throws Exception {
65 | security.tokenKeyAccess("permitAll()");
66 | }
67 |
68 |
69 | @Bean
70 | public TokenStore tokenStore() {
71 | return new JwtTokenStore(jwtAccessTokenConverter());
72 | }
73 |
74 | @Bean
75 | public JwtAccessTokenConverter jwtAccessTokenConverter() {
76 | JwtAccessTokenConverter jwtAccessTokenConverter = new JwtAccessTokenConverter();
77 | KeyStoreKeyFactory keyStoreKeyFactory = new KeyStoreKeyFactory(new ClassPathResource(keyFile),
78 | password.toCharArray());
79 | KeyPair keyPair = keyStoreKeyFactory.getKeyPair(alias);
80 | jwtAccessTokenConverter.setKeyPair(keyPair);
81 | return jwtAccessTokenConverter;
82 |
83 | }
84 |
85 | }
86 |
--------------------------------------------------------------------------------
/couponservice/.mvn/wrapper/MavenWrapperDownloader.java:
--------------------------------------------------------------------------------
1 | /*
2 | Licensed to the Apache Software Foundation (ASF) under one
3 | or more contributor license agreements. See the NOTICE file
4 | distributed with this work for additional information
5 | regarding copyright ownership. The ASF licenses this file
6 | to you under the Apache License, Version 2.0 (the
7 | "License"); you may not use this file except in compliance
8 | with the License. You may obtain a copy of the License at
9 |
10 | https://www.apache.org/licenses/LICENSE-2.0
11 |
12 | Unless required by applicable law or agreed to in writing,
13 | software distributed under the License is distributed on an
14 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | KIND, either express or implied. See the License for the
16 | specific language governing permissions and limitations
17 | under the License.
18 | */
19 |
20 | import java.io.File;
21 | import java.io.FileInputStream;
22 | import java.io.FileOutputStream;
23 | import java.io.IOException;
24 | import java.net.URL;
25 | import java.nio.channels.Channels;
26 | import java.nio.channels.ReadableByteChannel;
27 | import java.util.Properties;
28 |
29 | public class MavenWrapperDownloader {
30 |
31 | /**
32 | * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
33 | */
34 | private static final String DEFAULT_DOWNLOAD_URL =
35 | "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar";
36 |
37 | /**
38 | * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
39 | * use instead of the default one.
40 | */
41 | private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
42 | ".mvn/wrapper/maven-wrapper.properties";
43 |
44 | /**
45 | * Path where the maven-wrapper.jar will be saved to.
46 | */
47 | private static final String MAVEN_WRAPPER_JAR_PATH =
48 | ".mvn/wrapper/maven-wrapper.jar";
49 |
50 | /**
51 | * Name of the property which should be used to override the default download url for the wrapper.
52 | */
53 | private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";
54 |
55 | public static void main(String args[]) {
56 | System.out.println("- Downloader started");
57 | File baseDirectory = new File(args[0]);
58 | System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
59 |
60 | // If the maven-wrapper.properties exists, read it and check if it contains a custom
61 | // wrapperUrl parameter.
62 | File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
63 | String url = DEFAULT_DOWNLOAD_URL;
64 | if(mavenWrapperPropertyFile.exists()) {
65 | FileInputStream mavenWrapperPropertyFileInputStream = null;
66 | try {
67 | mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
68 | Properties mavenWrapperProperties = new Properties();
69 | mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
70 | url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
71 | } catch (IOException e) {
72 | System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
73 | } finally {
74 | try {
75 | if(mavenWrapperPropertyFileInputStream != null) {
76 | mavenWrapperPropertyFileInputStream.close();
77 | }
78 | } catch (IOException e) {
79 | // Ignore ...
80 | }
81 | }
82 | }
83 | System.out.println("- Downloading from: : " + url);
84 |
85 | File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
86 | if(!outputFile.getParentFile().exists()) {
87 | if(!outputFile.getParentFile().mkdirs()) {
88 | System.out.println(
89 | "- ERROR creating output direcrory '" + outputFile.getParentFile().getAbsolutePath() + "'");
90 | }
91 | }
92 | System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
93 | try {
94 | downloadFileFromURL(url, outputFile);
95 | System.out.println("Done");
96 | System.exit(0);
97 | } catch (Throwable e) {
98 | System.out.println("- Error downloading");
99 | e.printStackTrace();
100 | System.exit(1);
101 | }
102 | }
103 |
104 | private static void downloadFileFromURL(String urlString, File destination) throws Exception {
105 | URL website = new URL(urlString);
106 | ReadableByteChannel rbc;
107 | rbc = Channels.newChannel(website.openStream());
108 | FileOutputStream fos = new FileOutputStream(destination);
109 | fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
110 | fos.close();
111 | rbc.close();
112 | }
113 |
114 | }
115 |
--------------------------------------------------------------------------------
/productservice/.mvn/wrapper/MavenWrapperDownloader.java:
--------------------------------------------------------------------------------
1 | /*
2 | Licensed to the Apache Software Foundation (ASF) under one
3 | or more contributor license agreements. See the NOTICE file
4 | distributed with this work for additional information
5 | regarding copyright ownership. The ASF licenses this file
6 | to you under the Apache License, Version 2.0 (the
7 | "License"); you may not use this file except in compliance
8 | with the License. You may obtain a copy of the License at
9 |
10 | https://www.apache.org/licenses/LICENSE-2.0
11 |
12 | Unless required by applicable law or agreed to in writing,
13 | software distributed under the License is distributed on an
14 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | KIND, either express or implied. See the License for the
16 | specific language governing permissions and limitations
17 | under the License.
18 | */
19 |
20 | import java.io.File;
21 | import java.io.FileInputStream;
22 | import java.io.FileOutputStream;
23 | import java.io.IOException;
24 | import java.net.URL;
25 | import java.nio.channels.Channels;
26 | import java.nio.channels.ReadableByteChannel;
27 | import java.util.Properties;
28 |
29 | public class MavenWrapperDownloader {
30 |
31 | /**
32 | * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
33 | */
34 | private static final String DEFAULT_DOWNLOAD_URL =
35 | "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar";
36 |
37 | /**
38 | * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
39 | * use instead of the default one.
40 | */
41 | private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
42 | ".mvn/wrapper/maven-wrapper.properties";
43 |
44 | /**
45 | * Path where the maven-wrapper.jar will be saved to.
46 | */
47 | private static final String MAVEN_WRAPPER_JAR_PATH =
48 | ".mvn/wrapper/maven-wrapper.jar";
49 |
50 | /**
51 | * Name of the property which should be used to override the default download url for the wrapper.
52 | */
53 | private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";
54 |
55 | public static void main(String args[]) {
56 | System.out.println("- Downloader started");
57 | File baseDirectory = new File(args[0]);
58 | System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
59 |
60 | // If the maven-wrapper.properties exists, read it and check if it contains a custom
61 | // wrapperUrl parameter.
62 | File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
63 | String url = DEFAULT_DOWNLOAD_URL;
64 | if(mavenWrapperPropertyFile.exists()) {
65 | FileInputStream mavenWrapperPropertyFileInputStream = null;
66 | try {
67 | mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
68 | Properties mavenWrapperProperties = new Properties();
69 | mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
70 | url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
71 | } catch (IOException e) {
72 | System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
73 | } finally {
74 | try {
75 | if(mavenWrapperPropertyFileInputStream != null) {
76 | mavenWrapperPropertyFileInputStream.close();
77 | }
78 | } catch (IOException e) {
79 | // Ignore ...
80 | }
81 | }
82 | }
83 | System.out.println("- Downloading from: : " + url);
84 |
85 | File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
86 | if(!outputFile.getParentFile().exists()) {
87 | if(!outputFile.getParentFile().mkdirs()) {
88 | System.out.println(
89 | "- ERROR creating output direcrory '" + outputFile.getParentFile().getAbsolutePath() + "'");
90 | }
91 | }
92 | System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
93 | try {
94 | downloadFileFromURL(url, outputFile);
95 | System.out.println("Done");
96 | System.exit(0);
97 | } catch (Throwable e) {
98 | System.out.println("- Error downloading");
99 | e.printStackTrace();
100 | System.exit(1);
101 | }
102 | }
103 |
104 | private static void downloadFileFromURL(String urlString, File destination) throws Exception {
105 | URL website = new URL(urlString);
106 | ReadableByteChannel rbc;
107 | rbc = Channels.newChannel(website.openStream());
108 | FileOutputStream fos = new FileOutputStream(destination);
109 | fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
110 | fos.close();
111 | rbc.close();
112 | }
113 |
114 | }
115 |
--------------------------------------------------------------------------------
/authserver/.mvn/wrapper/MavenWrapperDownloader.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2007-present the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://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 | */
16 | import java.net.*;
17 | import java.io.*;
18 | import java.nio.channels.*;
19 | import java.util.Properties;
20 |
21 | public class MavenWrapperDownloader {
22 |
23 | private static final String WRAPPER_VERSION = "0.5.6";
24 | /**
25 | * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
26 | */
27 | private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/"
28 | + WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar";
29 |
30 | /**
31 | * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
32 | * use instead of the default one.
33 | */
34 | private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
35 | ".mvn/wrapper/maven-wrapper.properties";
36 |
37 | /**
38 | * Path where the maven-wrapper.jar will be saved to.
39 | */
40 | private static final String MAVEN_WRAPPER_JAR_PATH =
41 | ".mvn/wrapper/maven-wrapper.jar";
42 |
43 | /**
44 | * Name of the property which should be used to override the default download url for the wrapper.
45 | */
46 | private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";
47 |
48 | public static void main(String args[]) {
49 | System.out.println("- Downloader started");
50 | File baseDirectory = new File(args[0]);
51 | System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
52 |
53 | // If the maven-wrapper.properties exists, read it and check if it contains a custom
54 | // wrapperUrl parameter.
55 | File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
56 | String url = DEFAULT_DOWNLOAD_URL;
57 | if(mavenWrapperPropertyFile.exists()) {
58 | FileInputStream mavenWrapperPropertyFileInputStream = null;
59 | try {
60 | mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
61 | Properties mavenWrapperProperties = new Properties();
62 | mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
63 | url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
64 | } catch (IOException e) {
65 | System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
66 | } finally {
67 | try {
68 | if(mavenWrapperPropertyFileInputStream != null) {
69 | mavenWrapperPropertyFileInputStream.close();
70 | }
71 | } catch (IOException e) {
72 | // Ignore ...
73 | }
74 | }
75 | }
76 | System.out.println("- Downloading from: " + url);
77 |
78 | File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
79 | if(!outputFile.getParentFile().exists()) {
80 | if(!outputFile.getParentFile().mkdirs()) {
81 | System.out.println(
82 | "- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'");
83 | }
84 | }
85 | System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
86 | try {
87 | downloadFileFromURL(url, outputFile);
88 | System.out.println("Done");
89 | System.exit(0);
90 | } catch (Throwable e) {
91 | System.out.println("- Error downloading");
92 | e.printStackTrace();
93 | System.exit(1);
94 | }
95 | }
96 |
97 | private static void downloadFileFromURL(String urlString, File destination) throws Exception {
98 | if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) {
99 | String username = System.getenv("MVNW_USERNAME");
100 | char[] password = System.getenv("MVNW_PASSWORD").toCharArray();
101 | Authenticator.setDefault(new Authenticator() {
102 | @Override
103 | protected PasswordAuthentication getPasswordAuthentication() {
104 | return new PasswordAuthentication(username, password);
105 | }
106 | });
107 | }
108 | URL website = new URL(urlString);
109 | ReadableByteChannel rbc;
110 | rbc = Channels.newChannel(website.openStream());
111 | FileOutputStream fos = new FileOutputStream(destination);
112 | fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
113 | fos.close();
114 | rbc.close();
115 | }
116 |
117 | }
118 |
--------------------------------------------------------------------------------
/firstapp/.mvn/wrapper/MavenWrapperDownloader.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2007-present the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://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 | */
16 | import java.net.*;
17 | import java.io.*;
18 | import java.nio.channels.*;
19 | import java.util.Properties;
20 |
21 | public class MavenWrapperDownloader {
22 |
23 | private static final String WRAPPER_VERSION = "0.5.6";
24 | /**
25 | * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
26 | */
27 | private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/"
28 | + WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar";
29 |
30 | /**
31 | * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
32 | * use instead of the default one.
33 | */
34 | private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
35 | ".mvn/wrapper/maven-wrapper.properties";
36 |
37 | /**
38 | * Path where the maven-wrapper.jar will be saved to.
39 | */
40 | private static final String MAVEN_WRAPPER_JAR_PATH =
41 | ".mvn/wrapper/maven-wrapper.jar";
42 |
43 | /**
44 | * Name of the property which should be used to override the default download url for the wrapper.
45 | */
46 | private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";
47 |
48 | public static void main(String args[]) {
49 | System.out.println("- Downloader started");
50 | File baseDirectory = new File(args[0]);
51 | System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
52 |
53 | // If the maven-wrapper.properties exists, read it and check if it contains a custom
54 | // wrapperUrl parameter.
55 | File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
56 | String url = DEFAULT_DOWNLOAD_URL;
57 | if(mavenWrapperPropertyFile.exists()) {
58 | FileInputStream mavenWrapperPropertyFileInputStream = null;
59 | try {
60 | mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
61 | Properties mavenWrapperProperties = new Properties();
62 | mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
63 | url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
64 | } catch (IOException e) {
65 | System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
66 | } finally {
67 | try {
68 | if(mavenWrapperPropertyFileInputStream != null) {
69 | mavenWrapperPropertyFileInputStream.close();
70 | }
71 | } catch (IOException e) {
72 | // Ignore ...
73 | }
74 | }
75 | }
76 | System.out.println("- Downloading from: " + url);
77 |
78 | File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
79 | if(!outputFile.getParentFile().exists()) {
80 | if(!outputFile.getParentFile().mkdirs()) {
81 | System.out.println(
82 | "- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'");
83 | }
84 | }
85 | System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
86 | try {
87 | downloadFileFromURL(url, outputFile);
88 | System.out.println("Done");
89 | System.exit(0);
90 | } catch (Throwable e) {
91 | System.out.println("- Error downloading");
92 | e.printStackTrace();
93 | System.exit(1);
94 | }
95 | }
96 |
97 | private static void downloadFileFromURL(String urlString, File destination) throws Exception {
98 | if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) {
99 | String username = System.getenv("MVNW_USERNAME");
100 | char[] password = System.getenv("MVNW_PASSWORD").toCharArray();
101 | Authenticator.setDefault(new Authenticator() {
102 | @Override
103 | protected PasswordAuthentication getPasswordAuthentication() {
104 | return new PasswordAuthentication(username, password);
105 | }
106 | });
107 | }
108 | URL website = new URL(urlString);
109 | ReadableByteChannel rbc;
110 | rbc = Channels.newChannel(website.openStream());
111 | FileOutputStream fos = new FileOutputStream(destination);
112 | fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
113 | fos.close();
114 | rbc.close();
115 | }
116 |
117 | }
118 |
--------------------------------------------------------------------------------
/couponreactclient/src/serviceWorker.js:
--------------------------------------------------------------------------------
1 | // This optional code is used to register a service worker.
2 | // register() is not called by default.
3 |
4 | // This lets the app load faster on subsequent visits in production, and gives
5 | // it offline capabilities. However, it also means that developers (and users)
6 | // will only see deployed updates on subsequent visits to a page, after all the
7 | // existing tabs open on the page have been closed, since previously cached
8 | // resources are updated in the background.
9 |
10 | // To learn more about the benefits of this model and instructions on how to
11 | // opt-in, read https://bit.ly/CRA-PWA
12 |
13 | const isLocalhost = Boolean(
14 | window.location.hostname === 'localhost' ||
15 | // [::1] is the IPv6 localhost address.
16 | window.location.hostname === '[::1]' ||
17 | // 127.0.0.0/8 are considered localhost for IPv4.
18 | window.location.hostname.match(
19 | /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
20 | )
21 | );
22 |
23 | export function register(config) {
24 | if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
25 | // The URL constructor is available in all browsers that support SW.
26 | const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href);
27 | if (publicUrl.origin !== window.location.origin) {
28 | // Our service worker won't work if PUBLIC_URL is on a different origin
29 | // from what our page is served on. This might happen if a CDN is used to
30 | // serve assets; see https://github.com/facebook/create-react-app/issues/2374
31 | return;
32 | }
33 |
34 | window.addEventListener('load', () => {
35 | const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
36 |
37 | if (isLocalhost) {
38 | // This is running on localhost. Let's check if a service worker still exists or not.
39 | checkValidServiceWorker(swUrl, config);
40 |
41 | // Add some additional logging to localhost, pointing developers to the
42 | // service worker/PWA documentation.
43 | navigator.serviceWorker.ready.then(() => {
44 | console.log(
45 | 'This web app is being served cache-first by a service ' +
46 | 'worker. To learn more, visit https://bit.ly/CRA-PWA'
47 | );
48 | });
49 | } else {
50 | // Is not localhost. Just register service worker
51 | registerValidSW(swUrl, config);
52 | }
53 | });
54 | }
55 | }
56 |
57 | function registerValidSW(swUrl, config) {
58 | navigator.serviceWorker
59 | .register(swUrl)
60 | .then(registration => {
61 | registration.onupdatefound = () => {
62 | const installingWorker = registration.installing;
63 | if (installingWorker == null) {
64 | return;
65 | }
66 | installingWorker.onstatechange = () => {
67 | if (installingWorker.state === 'installed') {
68 | if (navigator.serviceWorker.controller) {
69 | // At this point, the updated precached content has been fetched,
70 | // but the previous service worker will still serve the older
71 | // content until all client tabs are closed.
72 | console.log(
73 | 'New content is available and will be used when all ' +
74 | 'tabs for this page are closed. See https://bit.ly/CRA-PWA.'
75 | );
76 |
77 | // Execute callback
78 | if (config && config.onUpdate) {
79 | config.onUpdate(registration);
80 | }
81 | } else {
82 | // At this point, everything has been precached.
83 | // It's the perfect time to display a
84 | // "Content is cached for offline use." message.
85 | console.log('Content is cached for offline use.');
86 |
87 | // Execute callback
88 | if (config && config.onSuccess) {
89 | config.onSuccess(registration);
90 | }
91 | }
92 | }
93 | };
94 | };
95 | })
96 | .catch(error => {
97 | console.error('Error during service worker registration:', error);
98 | });
99 | }
100 |
101 | function checkValidServiceWorker(swUrl, config) {
102 | // Check if the service worker can be found. If it can't reload the page.
103 | fetch(swUrl, {
104 | headers: { 'Service-Worker': 'script' },
105 | })
106 | .then(response => {
107 | // Ensure service worker exists, and that we really are getting a JS file.
108 | const contentType = response.headers.get('content-type');
109 | if (
110 | response.status === 404 ||
111 | (contentType != null && contentType.indexOf('javascript') === -1)
112 | ) {
113 | // No service worker found. Probably a different app. Reload the page.
114 | navigator.serviceWorker.ready.then(registration => {
115 | registration.unregister().then(() => {
116 | window.location.reload();
117 | });
118 | });
119 | } else {
120 | // Service worker found. Proceed as normal.
121 | registerValidSW(swUrl, config);
122 | }
123 | })
124 | .catch(() => {
125 | console.log(
126 | 'No internet connection found. App is running in offline mode.'
127 | );
128 | });
129 | }
130 |
131 | export function unregister() {
132 | if ('serviceWorker' in navigator) {
133 | navigator.serviceWorker.ready
134 | .then(registration => {
135 | registration.unregister();
136 | })
137 | .catch(error => {
138 | console.error(error.message);
139 | });
140 | }
141 | }
142 |
--------------------------------------------------------------------------------