All Projects → oktadeveloper → Java Microservices Examples

oktadeveloper / Java Microservices Examples

Licence: apache-2.0
Java Microservices: Spring Boot, Spring Cloud, JHipster, Spring Cloud Config, and Spring Cloud Gateway

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Java Microservices Examples

Okta Blog Archive
Okta Developer Blog
Stars: ✭ 74 (-61.86%)
Mutual labels:  microservices, spring-boot, spring-cloud, jhipster, oauth2
Spring Cloud Security
Security concerns for distributed applications implemented in Spring
Stars: ✭ 488 (+151.55%)
Mutual labels:  microservices, spring-boot, spring-cloud, oauth2
Microservices Platform
基于SpringBoot2.x、SpringCloud和SpringCloudAlibaba并采用前后端分离的企业级微服务多租户系统架构。并引入组件化的思想实现高内聚低耦合,项目代码简洁注释丰富上手容易,适合学习和企业中使用。真正实现了基于RBAC、jwt和oauth2的无状态统一权限认证的解决方案,面向互联网设计同时适合B端和C端用户,支持CI/CD多环境部署,并提供应用管理方便第三方系统接入;同时还集合各种微服务治理功能和监控功能。模块包括:企业级的认证系统、开发平台、应用监控、慢sql监控、统一日志、单点登录、Redis分布式高速缓存、配置中心、分布式任务调度、接口文档、代码生成等等。
Stars: ✭ 3,274 (+1587.63%)
Mutual labels:  microservices, spring-boot, spring-cloud, oauth2
Microservices Example
Example of a microservices architecture on the modern stack of Java technologies
Stars: ✭ 66 (-65.98%)
Mutual labels:  microservices, spring-boot, spring-cloud, microservices-architecture
Febs Cloud
基于Spring Cloud Hoxton.RELEASE、Spring Cloud OAuth2 & Spring Cloud Alibaba & Element 微服务权限系统,开箱即用。预览地址:https://cloud.mrbird.cn
Stars: ✭ 1,295 (+567.53%)
Mutual labels:  spring-boot, spring-cloud, oauth2
Microservice Patterns
Code to share the knowledge I gained while designing and implementing micro services
Stars: ✭ 87 (-55.15%)
Mutual labels:  microservices, spring-boot, microservices-architecture
Sample Spring Oauth2 Microservices
some examples that show basic and more advanced implementations of oauth2 authorization mechanism in spring-cloud microservices environment
Stars: ✭ 109 (-43.81%)
Mutual labels:  spring-boot, spring-cloud, oauth2
Sample Spring Microservices Advanced
More advanced samples of spring boot and spring cloud microservices showing usage of such tools like api Swagger2 on Zuul, integraction with MongoDB, configuration server, testing with Spring Cloud Contract or Hoverfly
Stars: ✭ 112 (-42.27%)
Mutual labels:  microservices, spring-boot, spring-cloud
Spring Cloud Sleuth
Distributed tracing for spring cloud
Stars: ✭ 1,531 (+689.18%)
Mutual labels:  microservices, spring-boot, spring-cloud
Event Sourcing Microservices Example
Learn about building microservices with event sourcing using Spring Boot and how to deploy a social network to Kubernetes using Docker Compose or Helm.
Stars: ✭ 167 (-13.92%)
Mutual labels:  microservices, spring-boot, spring-cloud
Piggymetrics
Microservice Architecture with Spring Boot, Spring Cloud and Docker
Stars: ✭ 11,161 (+5653.09%)
Mutual labels:  microservices, spring-boot, spring-cloud
Spring Cloud Dubbo Together
Spring Cloud与Dubbo共存方案
Stars: ✭ 155 (-20.1%)
Mutual labels:  microservices, spring-boot, spring-cloud
Spring Cloud Cloudfoundry
Integration between Cloudfoundry and the Spring Cloud APIs
Stars: ✭ 83 (-57.22%)
Mutual labels:  microservices, spring-boot, spring-cloud
Jhipster Microservices Example
JHipster Microservices Example using Spring Cloud, Spring Boot, Angular, Docker, and Kubernetes
Stars: ✭ 100 (-48.45%)
Mutual labels:  spring-boot, spring-cloud, jhipster
Cas
Apereo CAS - Enterprise Single Sign On for all earthlings and beyond.
Stars: ✭ 9,154 (+4618.56%)
Mutual labels:  spring-boot, spring-cloud, oauth2
Spring Cloud Example
Stars: ✭ 111 (-42.78%)
Mutual labels:  microservices, spring-boot, spring-cloud
Learning Path Spring Boot Microservices
Curated path for learning Spring Boot & Microservices based on published videos in TechPrimers
Stars: ✭ 116 (-40.21%)
Mutual labels:  microservices, spring-boot, spring-cloud
Mcloud
基于Spring Cloud,实现微服务中常用的基础模块,包括 OAuth2 认证服务,统一注册中心,系统监控中心, 统一配置中心,API网关以及熔断器
Stars: ✭ 185 (-4.64%)
Mutual labels:  spring-boot, spring-cloud, oauth2
Bookstoreapp Distributed Application
Ecommerce project is being developed using Spring Boot Microservices and Spring Cloud (Backend) and React (Frontend). Splitting the Ecommerce functionality into various individual microservices so that they can be distributed, scale really well and make use of resources efficiently.
Stars: ✭ 63 (-67.53%)
Mutual labels:  microservices, spring-boot, spring-cloud
Spring Cloud Cli
Spring Cloud CLI features
Stars: ✭ 139 (-28.35%)
Mutual labels:  microservices, spring-boot, spring-cloud

Java Microservices with Spring Boot & Spring Cloud 🍃☁️

This repository contains examples of how to build a Java microservices architecture with Spring Boot, Spring Cloud, and Netflix Eureka.

This repository has four examples in it:

  1. The first is a bare-bones microservices architecture with Spring Boot, Spring Cloud, Eureka Server, and Zuul.
  2. The second is one that's built with JHipster and configured centrally with Spring Cloud Config.
  3. The third uses Spring Cloud Gateway and Spring WebFlux to show reactive microservices.
  4. The fourth uses JHipster 7 to generate a reactive microservices architecture with Spring Cloud Gateway and Spring WebFlux.

We think you'll enjoy them all!

Prerequisites: Java 11 and an internet connection.

Spring Boot + Spring Cloud Example

To install this example, run the following commands:

git clone https://github.com/oktadeveloper/java-microservices-examples.git
cd java-microservices-examples/spring-boot+cloud

The api-gateway and car-service projects are already pre-configured to be locked down with OAuth 2.0 and Okta. That means if you try to run them, you won't be able to login until you create an account, and an application in it.

Create a Web Application in Okta

Log in to your Okta Developer account (or sign up if you don't have an account).

  1. From the Applications page, choose Add Application.
  2. On the Create New Application page, select Web.
  3. Give your app a memorable name, add http://localhost:8080/login/oauth2/code/okta as a Login redirect URI, select Refresh Token (in addition to Authorization Code), and click Done.

Copy the issuer (found under API > Authorization Servers), client ID, and client secret into the application.properties of the api-gateway and car-service projects.

okta.oauth2.issuer=https://{yourOktaDomain}/oauth2/default
okta.oauth2.client-id=$clientId
okta.oauth2.client-secret=$clientSecret

Then, run all the projects with ./mvnw in separate terminal windows. You should be able to navigate to http://localhost:8761 and see the apps have been registered with Eureka.

Then, navigate to http://localhost:8080/cool-cars in your browser, log in with Okta, and see the resulting JSON.

JHipster + Spring Cloud Config Example

To install this example, run the following commands:

git clone https://github.com/oktadeveloper/java-microservices-examples.git
cd java-microservices-examples/jhipster

Create Docker containers for all gateway and microservice applications:

mvn -Pprod verify com.google.cloud.tools:jib-maven-plugin:dockerBuild

Create a Web Application in Okta

Log in to your Okta Developer account (or sign up if you don't have an account).

  1. From the Applications page, choose Add Application.
  2. On the Create New Application page, select Web.
  3. Give your app a memorable name, add http://localhost:8080/login/oauth2/code/okta as a Login redirect URI, select Refresh Token (in addition to Authorization Code), and click Done.
  4. To configure Logout to work in JHipster, Edit your app, add http://localhost:8080 as a Logout redirect URI, then click Save.

Rather than modifying each of your apps for Okta, you can use Spring Cloud Config in JHipster Registry to do it. Open docker-compose/central-server-config/application.yml and add your Okta settings.

The client ID and secret are available on your app settings page. You can find the issuer under API > Authorization Servers.

spring:
  security:
    oauth2:
      client:
        provider:
          oidc:
            issuer-uri: https://{yourOktaDomain}/oauth2/default
        registration:
          oidc:
            client-id: {yourClientId}
            client-secret: {yourClientSecret}

The registry, gateway, blog, and store applications are all configured to read this configuration on startup.

Start all your containers from the docker-compose directory:

docker-compose up -d

Before you can log in to the registry, you'll need to add redirect URIs for JHipster Registry, ensure your user is in a ROLE_ADMIN group and that groups are included in the ID token.

Log in to your Okta dashboard, edit your OIDC app, and add the following Login redirect URI:

  • http://localhost:8761/login/oauth2/code/oidc

You'll also need to add a Logout redirect URI:

  • http://localhost:8761

Then, click Save.

Create Groups and Add Them as Claims to the ID Token

JHipster is configured by default to work with two types of users: administrators and users. Keycloak is configured with users and groups automatically, but you need to do some one-time configuration for your Okta organization.

Create a ROLE_ADMIN group (Users > Groups > Add Group) and add your user to it. Navigate to API > Authorization Servers, and click on the the default server. Click the Claims tab and Add Claim. Name it groups, and include it in the ID Token. Set the value type to Groups and set the filter to be a Regex of .*. Click Create.

Now when you hit http://localhost:8761 or http://localhost:8080, you should be able to log in with Okta!

Spring Cloud Gateway Example

To install this example, run the following commands:

git clone https://github.com/oktadeveloper/java-microservices-examples.git
cd java-microservices-examples/spring-cloud-gateway

The api-gateway and car-service projects are already pre-configured to be locked down with OAuth 2.0 and Okta. That means if you try to run them, you won't be able to login until you create an account, and an application in it.

If you already have an Okta account, see the Create a Web Application in Okta section below. Otherwise, we created a Maven plugin that configures a free Okta developer account + an OIDC app (in under a minute!).

To use it, run ./mvnw com.okta:okta-maven-plugin:setup to create an account and configure the gateway to work with Okta.

Copy the okta.* properties from the gateway's src/main/resources/application.properties to the same file in the car-service project.

Then, run all the projects with ./mvnw in separate terminal windows. You should be able to navigate to http://localhost:8761 and see the apps have been registered with Eureka.

Then, navigate to http://localhost:8080/cars in your browser, log in with Okta, and see the resulting JSON.

Create a Web Application in Okta

Log in to your Okta Developer account (or sign up if you don't have an account).

  1. From the Applications page, choose Add Application.
  2. On the Create New Application page, select Web.
  3. Give your app a memorable name, add http://localhost:8080/login/oauth2/code/okta as a Login redirect URI and click Done.

Copy the issuer (found under API > Authorization Servers), client ID, and client secret into the application.properties of the api-gateway and car-service projects.

okta.oauth2.issuer=https://{yourOktaDomain}/oauth2/default
okta.oauth2.client-id=$clientId
okta.oauth2.client-secret=$clientSecret

Reactive Microservices with JHipster Example

To install this example, run the following commands:

git clone https://github.com/oktadeveloper/java-microservices-examples.git
cd java-microservices-examples/reactive-jhipster

The JHipster Registry and Spring Cloud Config are pre-configured to use Okta. That means if you try to run them, you won't be able to login until you create an account, and an application in it.

Install the Okta CLI using the instructions on cli.okta.com and come back here when you're done. If you don't have an Okta developer account, run okta register.

NOTE: You can also use your browser and Okta's developer console to register an app. See JHipster's security documentation for those instructions.

From the gateway project's directory, run okta apps create jhipster. Accept the default redirect URIs.

This process does several things:

  1. Registers an OIDC app in Okta with JHipster's configured redirect URIs.
  2. Creates ROLE_ADMIN and ROLE_USER groups and adds your user to both.
  3. Creates a groups claim and adds it to ID tokens.
  4. Creates a .okta.env file with the values you'll need to talk to Okta.

Spring Cloud Config allows you to distribute Spring's configuration between apps. Update gateway/src/main/docker/central-server-config/localhost-config/application.yml to use your Okta app settings. You can find the values for each property in the .okta.env file.

spring:
  security:
    oauth2:
      client:
        provider:
          oidc:
            issuer-uri: https://<your-okta-domain>/oauth2/default
        registration:
          oidc:
            client-id: <client-id>
            client-secret: <client-secret>

Save your changes. These values will be distributed to the JHipster Registry, gateway, blog, and store apps. Start all the services and apps using the following commands:

cd gateway
docker-compose -f src/main/docker/keycloak.yml up -d #jhkeycloakup
docker-compose -f src/main/docker/postgresql.yml up -d #jhpostgresqlup
docker-compose -f src/main/docker/jhipster-registery up -d #jhregistryup
./gradlew

Open a new terminal window, start the blog app's Neo4j database, and then the app itself.

cd ../blog
docker-compose -f src/main/docker/neo4j.yml up -d #jhneo4jup
./gradlew

Then, open another terminal window, start the store app's MongoDB database, and the microservice.

cd ../store
docker-compose -f src/main/docker/mongodb.yml up -d #jhmongoup
./gradlew

Now, open a new incognito browser window, go to http://localhost:8080, and sign in. Rejoice that using Okta for authentication works!

TIP: You can also run everything using Docker Compose. See the blog post for how to do that.

Links

These examples uses the following open source libraries:

Help

Please post any questions as comments on the example's blog post, or on the Okta Developer Forums.

License

Apache 2.0, see LICENSE.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].