I have a Spring Boot App with AzureAD Authentication. This App generates a Username and Password for another page which can't have SSO (only htaccess). When I generate the Credentials for an authenticated user I want to recheck every 24 hours if the user is still enabled in the Active Directory. If the User is disabled, I will delete the generated Credentials, so they can't be used anymore by the user.
My question is: How can I check if a user by its unique Email is enabled/disabled in AAD from the backend site without the user beeing currently authenticated?
When the user is authenticated I use this to access the information for the current user:
public String getLdapUserEmail() {
Map<String , Object> userDetails = ((DefaultOidcUser)SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getAttributes();
return userDetails.get("preferred_username").toString();
}
But in this case I want to check all users I have given credentials to every 24 hours if they are still enabled in AAD, so I have to use something else than the SecurityContext Holder - but I don't know what.
In my pom I have following dependencies for the AAD and in the application.properties the tenant-id/client-id/client-secret are set up.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-oauth2-client</artifactId>
</dependency>
<dependency>
<groupId>com.azure.spring</groupId>
<artifactId>azure-spring-boot-starter-active-directory</artifactId>
<version>3.14.0</version>
</dependency>