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

Optimizing Databricks Spark jobs using dynamic partition pruning and AQE

Learn how to supercharge your Databricks Spark jobs using Dynamic Partition Pruning (DPP) and Adaptive Query Execution (AQE). This comprehensive guide walks through practical implementations, real-world scenarios, and best practices for optimizing large-scale data processing. Discover how to significantly reduce query execution time and resource usage through intelligent partition handling and runtime optimizations. Perfect for data engineers and architects looking to enhance their Spark job performance in Databricks environments.

time
8
 min read

Implementing custom serialization and deserialization in Apache Kafka for optimized event processing performance

Dive deep into implementing custom serialization and deserialization in Apache Kafka to optimize event processing performance. This comprehensive guide covers building efficient binary serializers, implementing buffer pooling for reduced garbage collection, managing schema versions, and integrating compression techniques. With practical code examples and performance metrics, learn how to achieve up to 65% higher producer throughput, 45% better consumer throughput, and 60% reduction in network bandwidth usage. Perfect for developers looking to enhance their Kafka implementations with advanced serialization strategies.

time
11
 min read

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