User Authentication with Azure Active Directory with Spring Boot

In this quick guide, you will learn about what an active directory is, how you can create an instance on Azure’s Active Directory, and also how to configure it from Spring boot which means how we can access the instance by configuring the instance properties

GraphQL has a role beyond API Query Language- being the backbone of application Integration
background Coditation

User Authentication with Azure Active Directory with Spring Boot

What is Active Directory?

  • Active Directory(AD) is a directory service developed by Microsoft for the Windows domain
  • It authenticates and authorizes all users and computers in a Windows domain type network. It helps in the organization
  • Active Directory allows network administrators to create and manage domains, users, and objects within a network. For example, an admin can create a group of users and give them specific access privileges to certain directories on the server

Why use Active Directory?A cloud-native directory and identity platform offering these key advantages:

  • Single sign-on for multiple applications
  • Azure AD multi-factor authentication and conditional access
  • Multiple platform functionality
  • Azure AD works with more than just Microsoft software
  • Azure AD reduces risk
  • Global availability

Who should use Active Directory?

Active Directory (AD) is a powerful tool for streamlining organizational data management. Administrators leverage AD to establish a clear hierarchical structure, assigning users to specific networks, defining profile pictures, and granting access permissions to resources like storage rooms. By centralizing these functions, AD significantly enhances efficiency and security.For instance, IT organizations can leverage this solution to safeguard sensitive employee information by implementing robust authentication and authorization protocols.Architecture of Active Directory

This shows the Active Directory workflow.

  • Azure AD is a cloud-based identity and access management service. The first user tries to access the application by entering the details like username and password
  • The application finds the identity provider to authenticate the user. It generates authentication request and redirects the user’s browser to the Azure page
  • Here Azure’s Active Directory tries to find out the user details and generate the token
  • The application verifies the token sent by Azure AD and processes the sign-in

Creating Azure Active Directory Instance

1. Create an account on https://portal.azure.com then create a resource/tenant, then Identity, and then Azure Active Directory.

2. Enter your organization name and your Initial domain name. Copy the full URL of your directory; you will use that to add user accounts later in this tutorial. (For example: azureADsampledirectory.onmicrosoft.com.) Copy the full URL of your directory; you will use that to add user accounts later. (For example: azureADsampledirectory.onmicrosoft.com.)

When you have finished, select Create. It will take a few minutes to create the new resource.

3. When complete, select to access the new directory.

4. Copy the Tenant ID; you will use that value to configure your application.properties file later.

5. From the portal menu, select App registrations and then select Register an application.

6. Specify your application, and then select Register. When the page for your app registration appears, copy your Application ID and the Tenant ID.

7. Now, Click Certificates & secrets in the left navigation pane. Then select New client secret.

Add a Description and select duration in the Expires list. Click Add. The value for the key will be automatically filled in.

8. Now go to API permissions in the left navigation pane. Click Microsoft Graph and tick Access the directory as the signed-in user and Sign in and read user profile. Click Grant Permissions… and Yes when prompted.Click Grant admin consent for Azure Sample and select Yes.

9. After this, select Authentication and select Add a platform. Then select Web applications.Enter an endpoint URL that can accept data from azure as a new Redirect URI/Callback Response, and then select Configure to configure it.

10. Now we need to add a user to Active Directory. From the Overview page of your Active Directory, select Users, and then select New user.

When the User panel is displayed, enter the User name and Name. Then select Create.

Also, create a group of users for authentication. For this, we can select the user which we have created and form groups. Go back to the Users panel, select your test user, and select Reset password and reset it which we will be needed at the time of login.

Configure Active Directory through the app

  • Create a spring starter project and Navigate to the src/main/resources folder in your project, then open the properties file.
  • Here we are specifying settings that we are going to connect for AD.

Also, we need to configure WebSecurityConfig for authentication. This is how we can get connected to AD using spring boot.

Active Directory Advantages and Disadvantages:

Advantages

  • Enables users to sign in using usernames and passwords that are used elsewhere
  • Creating and maintaining user accounts is no longer needed
  • Computer policies can be created to automatically update and secure workstations
  • Sharing resources such as files and printers is easier all users have access to set permissions
  • No longer need to provide a username and password for Outlook emails
  • It is more secure than other directory services (Login Authentication)
  • It is easy to manage, administrate and control
  • Increased scalability
  • The speed at which it is able to provide domain names
  • Simple identity management as you can view all user information
  • Let’s you manage your network from one point
  • It is also easy to set up and use

Disadvantages

  • It can be expensive as you will need Windows Server 2000 licenses and you may need to upgrade the hardware on the server so it can run Windows Server 2000
  • Active directory is OS-dependent
  • High maintenance cost
  • If the Active Directory goes down so does your network
  • If it is set up wrong it can take time and money to remove it and set it up again
  • It is prone to be hacked
  • The cost of the infrastructure can be high
  • You need to have good planning to set it up properly
  • It also has a complex infrastructure for the user

Conclusion

This concise guide explores Active Directory on Azure. We'll delve into its fundamental concepts, the steps to create an Azure AD instance, and the practical application of integrating it with a Spring Boot application. By configuring the appropriate properties, you'll gain direct access to your Azure AD instance. Do check out our other blogs here.

Want to receive update about our upcoming podcast?

Thanks for joining our newsletter.
Oops! Something went wrong.

Latest Articles

Designing multi-agent systems using LangGraph for collaborative problem-solving

Learn how to build sophisticated multi-agent systems using LangGraph for collaborative problem-solving. This comprehensive guide covers the implementation of a software development team of AI agents, including task breakdown, code implementation, and review processes. Discover practical patterns for state management, agent communication, error handling, and system monitoring. With real-world examples and code implementations, you'll understand how to orchestrate multiple AI agents to tackle complex problems effectively. Perfect for developers looking to create robust, production-grade multi-agent systems that can handle iterative development workflows and maintain reliable state management.

time
7
 min read

Designing event-driven microservices architectures using Apache Kafka and Kafka Streams

Dive into the world of event-driven microservices architecture with Apache Kafka and Kafka Streams. This comprehensive guide explores core concepts, implementation patterns, and best practices for building scalable distributed systems. Learn how to design event schemas, process streams effectively, and handle failures gracefully. With practical Java code examples and real-world architectural patterns, discover how companies like Netflix and LinkedIn process billions of events daily. Whether you're new to event-driven architecture or looking to optimize your existing system, this guide provides valuable insights into building robust, loosely coupled microservices.

time
12
 min read

Implementing Custom Instrumentation for Application Performance Monitoring (APM) Using OpenTelemetry

Application Performance Monitoring (APM) has become crucial for businesses to ensure optimal software performance and user experience. As applications grow more complex and distributed, the need for comprehensive monitoring solutions has never been greater. OpenTelemetry has emerged as a powerful, vendor-neutral framework for instrumenting, generating, collecting, and exporting telemetry data. This article explores how to implement custom instrumentation using OpenTelemetry for effective APM.

Mobile Engineering
time
5
 min read