Table of Contents

How to Add Auth0 authentication to a Java application using Datawiza in 5 mins

5 minutes read
Coder creating computer software
Table of Contents

Do you want to learn how to add authentication to your Java application? 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 without writing code.

The benefits of using Datawiza

  • No need to learn complex OIDC/OAuth or SAML protocols
  • No need to manage refresh tokens, access tokens or ID tokens
  • No need to manage user sessions
  • No need to use SDKs, call APIs or write code
  • Reduce weeks of engineering work to hours, even minutes
  • Avoid security vulnerabilities with a No-Code product developed by security experts

Ready to see how easy it is?  Let’s get started!

Prerequisites

Run a Java web application

We use the sample offered in Spring.io official Building an Application with Spring Boot as the example in this section. The application running at port 8080 simply returns “Greetings from Spring Boot!”

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 or a Java Servlet application 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 and a Java implementation of JSON Web Token (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. It includes a data plane and a control plane: Datawiza Access Proxy and Datawiza Cloud Management Console (DCMC).

Datawiza Access Proxy 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 Datawiza Access Proxy. Such a SaaS-based design makes the whole platform much easier to use.

Step1: Create an application in Auth0

First, we need to create an Auth0 application in the Auth0 console. When performing this step, make sure to log in to your account on Auth0. Visit the link here 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.

Image of Auth0 application

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

Image of Auth0 create applicaton

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.

Auth0 application url

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

Image of Auth0 My App web application

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

Image of Auth0 User Management
Image of Auth0 Create Users

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). 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.

Image of Datawiza Access Broker

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

Image of Deployment Name
Image Datawiza on how to Create Provisioning Key

Now Add an Application:

Configure your application with the following values:

  • PlatformWeb
  • App NameDemo App
  • Public Domainhttp://localhost:9772
  • Listen Port9772
  • Upstream Servershttp://host.docker.internal:8080

Default ActionAllow

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 for more details).

Next Configure the IdP:

Image of Configure IdP

Select OIDC as the Protocol and Auth0 as the Identity Provider. Input the DomainClient 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 Datawiza Access Proxy image and the docker-compose file to run the Datawiza Access Proxy.

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

Image of Login Docker Registry

Step 3: Run Datawiza Access Proxy as a sidecar (agent) to your application

After finishing the configuration in DCMC, you can run the Datawiza Access Proxy 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'
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 Datawiza Access Proxy:

docker-compose -f datawiza-access-broker 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:

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

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 or official website for much more information. You can also get a free trial by signing up/in here!

Written by the Datawiza team — hope you enjoyed! Join us if you have any questions or need any help on our Discord server. 

Join our Discord server today! 👋Join
+