---
title: "How to Add Auth0 Authentication to a Java Application in 5 Mins
"
description: "Learn how to integrate a Java web application with Auth0 and implement OIDC/OAuth SSO for a Java"
authors:
  - name: "Weiyu Fang"
    url: "https://auth0.com/blog/authors/weiyu-fang/"
date: "Dec 10, 2021"
category: "Developers,Tutorial,Java"
tags: ["jwt", "auth0", "java"]
url: "https://auth0.com/blog/auth0-authentication-java-web-application/"
---

# How to Add Auth0 Authentication to a Java Application in 5 Mins


In this step-by-step tutorial, you will learn how to integrate a Java web application with Auth0 using Datawiza to implement OIDC/OAuth SSO for the Java web application.

## Prerequisites

*   A favorite text editor or IDE
*   [JDK 1.8](http://www.oracle.com/technetwork/java/javase/downloads/index.html) or later
*   [Gradle 4+](http://www.gradle.org/downloads) or [Maven 3.2+](https://maven.apache.org/download.cgi)
*   [Docker](https://docs.docker.com/get-docker/) (18.03+)
*   [Docker Compose](https://docs.docker.com/compose/install/)

## Run a Java Web Application

We use the sample offered in [Spring.io official Building an Application with Spring Boot](https://spring.io/guides/gs/spring-boot/#initial) as the example in this section. The application running at port 8080 simply returns “Greetings from Spring Boot!”

![Java Web Application](https://images.ctfassets.net/23aumh6u8s0i/4XcFQXlX8odLIEORRMXePX/e4857dbc14b281600d7016416cb2de77/java_01.png)

Suppose you want to add SSO authentication for a Java web application using Auth0. In that case, Auth0 provides quickstarts on adding the user login to [a Java EE web application](https://auth0.com/docs/quickstart/webapp/java-ee) or [a Java Servlet application](https://auth0.com/docs/quickstart/webapp/java) and integrating Auth0 with any new or existing Spring Boot 2 web application. What’s more, there is [an official Java client library for the Auth0 platform](https://github.com/auth0/auth0-java) and [a Java implementation of JSON Web Token (JWT)](https://github.com/auth0/java-jwt). However, you will still need to invest significant time to clearly understand concepts related to Auth0, OIDC, Oauth2, JWT, and so on. And you cannot avoid heavy code changes. You deserve a better solution, and we are building one that will reduce the required time from weeks to just minutes.

## Introduction to the Datawiza Platform

The Datawiza Platform is a cloud-delivered, [SaaS-based access management solution](https://www.datawiza.com/blogs/why-access-management-as-a-service-amaas-why-now). It includes a data plane and a control plane: Datawiza Access Broker (DAB) and Datawiza Cloud Management Console (DCMC).

**DAB** is a lightweight, container-based access proxy deployed close to your application via the sidecar (agent) or gateway mode. It talks to Auth0 on behalf of your applications, so you don’t need to worry about the integration work. **DCMC** is a cloud-based management console where you can configure and manage the policies of DABs. Such a SaaS-based design makes the whole platform much easier to use.

## Step 1: Create an Application in Auth0

First, we need to create an [Auth0 application](https://auth0.com/docs/applications) in the [Auth0 console](https://manage.auth0.com/dashboard). When performing this step, make sure to log in to your account on Auth0. Visit the link [here](https://auth0.com/) to create a developer account.

You can skip this step if you already have an application with the following values: Domain, Client ID, and Client Secret.

Create an application after you log in to Auth0.

![Auth0](https://images.ctfassets.net/23aumh6u8s0i/5KPM1zIMEVCS02gsenU3AQ/48ba320672eb660458c28ffcc6600578/java_02.png)

Enter the application name and choose **Regular Web Applications**, then click **CREATE**.

![Web Applications](https://images.ctfassets.net/23aumh6u8s0i/36tWZTXSdPv0B4aDfeXqnv/3de24e44791a7abd6a3499f284679786/Uploaded_from_How_to_Add_Auth0_Authentication_to_Java_Application_in_5_Mins)


Select the **Settings** tab and fill out the form. Follow the steps below:

*   **Allowed Callback URLs**: e.g., http://localhost:9772/authorization-code/callback
*   **Allowed Logout URLs**: e.g., http://localhost:9772
*   Use the default settings for the remaining fields

Then click **SAVE CHANGES.**

![Settings](https://images.ctfassets.net/23aumh6u8s0i/7BslNzTcUIOHNTBjtcscMd/c5f92a9e9e2f246a07eb2fbe2d4bae6e/java_03.png)

On the same page, be sure to save a copy of **Domain**, **Client ID,** and **Client Secret**. You will need these values later when establishing the connection.

![Domain](https://images.ctfassets.net/23aumh6u8s0i/12JKUSCw0J4xGMFZHEFWM4/d3b70060bdb20ce32290cf0a8088281a/java_04.png)

Choose Users under the **Users & Roles** Tab and create a test user.

![Users & Roles](https://images.ctfassets.net/23aumh6u8s0i/2L6ryltJG4griEOuFLlzUJ/65aad91e89a23cc2309381b7ec5a0702/java_05.png)

![Users & Roles](https://images.ctfassets.net/23aumh6u8s0i/57E0DP3e3qZEhzTYkO8Prj/5b1093bd7494bebae007ff643c946f9a/Uploaded_from_How_to_Add_Auth0_Authentication_to_Java_Application_in_5_Mins)

You have now registered a web application on Auth0. Next, you will create a simple configuration in the DCMC.

## Step 2: Configurations in Datawiza Cloud Management Console

Then, log in to the [Datawiza Cloud Management Console (DCMC)](https://console.datawiza.com/). If you do not have a DCMC account, you can create one by email from the DCMC login page. Also, we provide social login and SSO functionality with Microsoft, GitHub, and Google to simplify logins for you.

The **Get started** function will guide you through the configuration. After logging in to the DCMC, click on the yellow “Get started” button and follow the steps.

![Get started](https://images.ctfassets.net/23aumh6u8s0i/1qnlBAo4ObfXE6kOPNEExN/3ac984608b96227445f338b5fbf90cfd/Uploaded_from_How_to_Add_Auth0_Authentication_to_Java_Application_in_5_Mins)

Enter some basic information, such as the deployment name and provisioning key name:

![Information](https://images.ctfassets.net/23aumh6u8s0i/3QrulTuioxuOFocdMZz0HN/abc2a1ee268182235313546f04127c1c/java_06.png)

![Information](https://images.ctfassets.net/23aumh6u8s0i/3MZTaEuTTgp90bZ7rnugK5/87494ca141c7507833b8bbcdd367d6a5/java_07.png)

Now **Add an Application**:

![Add an Application](https://images.ctfassets.net/23aumh6u8s0i/2FHLJeyXB9W9MDLaKEK1YC/fe5ca0c3fcb584b4a211ccb358f4e3f7/java_08.png)

Configure your application with the following values:

*   **Platform**: _Web_
*   **App Name**: _Demo App_
*   **Public Domain**: _http://localhost:9772_
*   **Listen Port**: _9772_
*   **Upstream Servers**: _http://host.docker.internal:8080_
*   **Default Action**: _Allow_

Note that **Upstream Servers** is the address of the Java application.

*   If you use Mac or Windows, then set the Upstream Servers to _http://host.docker.internal:8080_ (requires Docker 18.03+).
*   If you use Linux, use _ip addr show docker0_ to get the docker host IP (e.g., 172.17.0.1) and then set Upstream Servers to http://172.17.0.1:8080 (see [this](https://stackoverflow.com/questions/24319662/from-inside-of-a-docker-container-how-do-i-connect-to-the-localhost-of-the-mach) for more details).

Next **Configure the IdP**:

![Configure the IdP](https://images.ctfassets.net/23aumh6u8s0i/3NJsB2nqQyhVWaFcRwDv1h/04db1d78ff8749138eb4d3d7b21dda3d/java_09.png)

Select **OIDC** as the Protocol and **Auth0** as the Identity Provider. Input the **Domain**, **Client ID,** and the **Client Secret** you saved when creating the app in Auth0. Then click **Create**.

In the last step, we will provide the command lines to pull the DAB image and the docker-compose file to run the DAB.

Execute the command lines in steps 1 & 2 and note down the docker-compose file in step 3.

![Add Auth0 Authentication](https://images.ctfassets.net/23aumh6u8s0i/6VDmHW6PtR3WzOyNcdysD5/292d99c072ab54d0927a4b07b829a764/java_10.jpg)

## Step 3: Run DAB as a Sidecar (Agent) to Your Application

After finishing the configuration in DCMC, you can run the DAB with the YAML file noted in the previous step. The docker-compose YAML file, named _datawiza-access-broker.yaml_ should then appear like this:

```
version: '3'  
services:  
datawiza-access-broker:  
image: registry.gitlab.com/datawiza/access-broker  
container\_name: datawiza-access-broker  
restart: always  
ports:  
- "9772:9772"  
environment:  
PROVISIONING\_KEY: #############################  
PROVISIONING\_SECRET: #############################
```

Now, we can use docker-compose to create and start the DAB:

```
docker-compose -f datawiza-access-broker.yaml up -d
```

That's it. After executing the command above, the Node.js application should have SSO enabled with Auth0.

Now, let's give it a try.

Open a browser and type in **http://localhost:9772**. You should see the Auth0 login page as follows:

![Auth0 login](https://images.ctfassets.net/23aumh6u8s0i/7vZUQEx0L1ahWKl3DSB5le/42b46194e44dec3c510900bce5f8a0ba/Uploaded_from_How_to_Add_Auth0_Authentication_to_Java_Application_in_5_Mins)

After logging in to Auth0, the Java web application will be shown.

![Auth0](https://images.ctfassets.net/23aumh6u8s0i/1xKW0FnBZnh3QMK5d3MiLB/443be2a918e0f2d08f9b3f7d9c7c8884/java_11.png)

## Summary

Congratulations! You secured a Java web application by adding Auth0 authentication using Datawiza -- in minutes instead of weeks or months. This is only a small sampling of what Datawiza can do. See [Datawiza’s online docs](https://docs.datawiza.com) or [official website](https://datawiza.com) for much more information.