Table of Contents

How to Add Azure AD Authentication to Java Web Application in 5 Mins

5 minutes read
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 Azure AD using Datawiza to implement OIDC/OAuth SSO without writing code. A working example is also available in this GitHub repository.

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 Building an Application with Spring Boot as the example in this section. The application running at port 8080 simply returns “Greetings from Spring Boot!”

Spring.io Building an Application with Spring Boot

Suppose you want to add SSO authentication for a Java web application using Azure AD, you may search on Google for the Java library for Azure AD. And you can find the Microsoft Authentication Library for Java (MSAL4J), which is used to enable applications to integrate with the Microsoft identity platform. What’s more, there are many code samples, built and maintained by Microsoft, that demonstrate authentication and authorization by using Azure AD and the Microsoft identity platform in several application types, development languages, and frameworks. However, you still need to spend a lot of time to clearly understand the concepts about Azure AD, OIDC, OAuth2, JWT, and so on. You deserve a better solution, and we are building a no-code solution that will reduce the time required down to hours or days, even 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 Azure AD 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.

Step 1: Configurations in Datawiza Cloud Management Console

First, use your Azure AD Admin Account (this account should have the permission to create an application registration in your Azure AD tenant) to log in to the Datawiza Cloud Management Console (DCMC).

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

Access Broker

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

Deployment Name

Now Add an Application:

Add Application

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

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:

Configure IdP

Select the Microsoft Azure Active Directory as the Identity Provider and keep the Automatic Generator option enabled. Automatic Generator is an advanced feature offered by Datawiza and Azure AD. It automatically creates a new application registration on your behalf in your Azure AD tenant. Click Create and wait for interaction with Azure AD. All the configurations are now automatically set.

Alternatively, if you want to use an existing web application in your Azure AD tenant, you can disable the option and populate the fields of the form. The Tenant ID, Client ID, and Client Secret are needed. You can follow the tutorial on the right side or the documentation to find out how to create an application registration on Azure AD and get these values in your tenant.

Configure IdP

In the last step, we 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 as shown below.

An image of login docker registry

Step 2: 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:

Now, we can use docker-compose to create and start the Datawiza Access Proxy:

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

That’s it. After executing the command above, the Java application should have SSO enabled with Azure AD.

Now, let’s give it a try.

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

Microsoft Sign on

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

Local host

Summary

Congratulations! You secured a Java web application by adding Azure AD 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 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
+