Spring Cloud servers publishing a RESTful Web Service with OAuth2.
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.
- I suggest use an Java IDE. I'm using Eclipse with Spring plugin.
- PostgreSQL or other database (need edit the config).
- An client to consume and test the service. I suggest Rest Web Service Client for Chrome or RESTClient for Firefox.
- Download the project by clicking the "Clone or download" button.
- Unzip the project into the directory of your choice.
- Using Eclipse (or another IDE), open the project you saved in the directory of your choice.
- Run the project.
You can use another project like Client android-microservices or any Web Service RESTful Client extension for browser (Chrome or Firefox).
You can download the WAR file on Releases Page, install on your host server and test the project.
- Run as > Maven clean
- Run as > Maven build
- Run as > Spring Boot App
Command:
curl -i http://localhost:9020/
Server Response:
{
"_links" : {
"user" : {
"href" : "http://localhost:9020/user{?page,size,sort}",
"templated" : true
},
"authorities" : {
"href" : "http://localhost:9020/authorities{?page,size,sort}",
"templated" : true
},
"product" : {
"href" : "http://localhost:9020/product{?page,size,sort}",
"templated" : true
},
"person" : {
"href" : "http://localhost:9020/person{?page,size,sort}",
"templated" : true
},
"profile" : {
"href" : "http://localhost:9020/alps"
}
}
}
Command:
curl -i http://localhost:9020/product/
Server Response:
{
"timestamp":1444985908768,
"status":401,
"error":"Unauthorized",
"message":"Access Denied",
"path":"/product/"
}
Command:
curl -vu wsapp:secret 'http://localhost:9020/oauth/token?username=admin@admin.com&password=12345678&grant_type=password'
Server Response:
{
"access_token":"92457844-4d4f-4f5a-b053-7f5074d6y892",
"token_type":"bearer",
"refresh_token":"e6f8624f-213d-4343-a971-980e83f734be",
"expires_in":1738,
"scope":"read write"
}
Command:
curl -vu wsapp:secret 'http://localhost:9020/oauth/token?grant_type=refresh_token&refresh_token=<refresh_token>'
Server Response:
{
"access_token":"821c99d4-2c9f-4990-b68d-18eacaff54b2",
"token_type":"bearer",
"refresh_token":"e6f8624f-213d-4343-a971-980e83f734be",
"expires_in":1799,
"scope":"read write"
}
Command:
curl -i -H "Authorization: Bearer <access_token>" http://localhost:9020/product/
Server Response:
{
"_links" : {
"self" : {
"href" : "http://localhost:9020/product{?page,size,sort}",
"templated" : true
},
"search" : {
"href" : "http://localhost:9020/product/search"
}
},
"_embedded" : {
"product" : [ {
"name" : "Bermuda",
"description" : "Bermuda Adidas",
"cost" : 50.5,
"_links" : {
"self" : {
"href" : "http://localhost:9020/product/3"
}
}
}, {
"name" : "Meia",
"description" : "Meia Rebook",
"cost" : 15.7,
"_links" : {
"self" : {
"href" : "http://localhost:9020/product/4"
}
}
}, {
"name" : "Camisa",
"description" : "Camisa Nike",
"cost" : 10.5,
"_links" : {
"self" : {
"href" : "http://localhost:9020/product/6"
}
}
}, {
"name" : "Bone",
"description" : "Do Milan",
"cost" : 34.98,
"_links" : {
"self" : {
"href" : "http://localhost:9020/product/19"
}
}
}, {
"name" : "Cueca",
"description" : "Cueca Polo Assassin",
"cost" : 25.9,
"_links" : {
"self" : {
"href" : "http://localhost:9020/product/5"
}
}
}, {
"name" : "Tenis",
"description" : "Tenis Nike Air",
"cost" : 32.5,
"_links" : {
"self" : {
"href" : "http://localhost:9020/product/2"
}
}
} ]
},
"page" : {
"size" : 20,
"totalElements" : 6,
"totalPages" : 1,
"number" : 0
}
}
- Port: 9000
- User: config
- Password: $2a$10$r0RFDmpneBVryx.ihHK9gu6FFJQi4nTxQUqzdSTvrPpaKZMxigqpy (123456)
- Port: 9010
- User: discovery
- Password: $2a$10$r0RFDmpneBVryx.ihHK9gu6FFJQi4nTxQUqzdSTvrPpaKZMxigqpy (123456)
- Port: 9020
- User: gateway
- Password: $2a$10$r0RFDmpneBVryx.ihHK9gu6FFJQi4nTxQUqzdSTvrPpaKZMxigqpy (123456)
- OAuth2
- User: admin
- Password: $2a$10$r0RFDmpneBVryx.ihHK9gu6FFJQi4nTxQUqzdSTvrPpaKZMxigqpy (123456)
- client-id: microservices
- client-secret: $2a$10$r0RFDmpneBVryx.ihHK9gu6FFJQi4nTxQUqzdSTvrPpaKZMxigqpy (123456)
- client-id:client-secret (Base64): bWljcm9zZXJ2aWNlczokMmEkMTAkcjBSRkRtcG5lQlZyeXguaWhISzlndTZGRkpRaTRuVHhRVXF6ZFNUdnJQcGFLWk14aWdxcHk=
- Port: 9030
- Port: 9031
- Spring Cloud - Spring Cloud provides tools for developers to quickly build some of the common patterns in distributed systems.
- Spring Cloud Netflix - With a few simple annotations you can quickly enable and configure the common patterns inside your application and build large distributed systems with battle-tested Netflix components.
- Netflix Zuul - Zuul is a JVM-based router and server-side load balancer from Netflix.
- Netflix Feign - Is a declarative and easier way to write a web service client.
- Netflix Ribbon - Is a client-side load balancer that gives you a lot of control over the behavior of HTTP and TCP clients.
- Spring Data REST - Makes it easy to build hypermedia-driven REST web services on top of Spring Data repositories.
- Spring Boot - Makes it easy to create stand-alone, production-grade Spring based Applications that you can "just run".
- Spring Data JPA - It eases development of applications that need to access JPA data sources.
- Spring HATEOAS - Provides some APIs to ease creating REST representations that follow the HATEOAS principle when working with Spring and especially Spring MVC.
- Spring Security - Is a framework that focuses on providing both authentication and authorization to Java applications.
- Spring Boot - Makes it easy to create stand-alone, production-grade Spring based Applications that you can "just run".
- Spring Data JPA - It eases development of applications that need to access JPA data sources.
- OAuth2 - Industry-standard protocol for authorization.
- PostgreSQL - is a powerful, open source object-relational database system.
- Maven - Dependency Management.
- Microservices with Spring Cloud - Udemy Course
- Arquitetura de MicroServices com Spring Cloud e Spring Boot
- Accessing a Spring Data REST API With Feign
- Spring Cloud – Securing Services
- Secure a Spring Microservices Architecture with Spring Security and OAuth 2.0
- Spring Cloud – Bootstrapping
- Spring Cloud Netflix with PATCH
We use Git for versioning.
Diogo - Initial work - diogoaltoe
This project is licensed under the MIT License.