Search code examples
azurespring-bootdependency-injectionazure-active-directoryspring-boot-starter

How to create a bean of AADAuthenticationProperties (azure)?


I cannot create a bean of AADAuthenticationProperties, and the reason sais that the property activeDirectoryGroups cannot be empty.

The error is the following:

Binding to target org.springframework.boot.context.properties.bind.BindException: Failed to bind properties under 'azure.activedirectory' to com.microsoft.azure.spring.autoconfigure.aad.AADAuthenticationProperties failed:

Property: azure.activedirectory.activeDirectoryGroups
Value: null
Reason: no puede estar vacío

This is the two ways a tried:

    //1st option
    @Bean
    @ConditionalOnMissingBean
    public AADAuthenticationProperties aadAuthenticationPropertiesFactory() {
        return new AADAuthenticationProperties();
    }

    //2nd option
    @Bean
    @ConditionalOnMissingBean
    public AADAuthenticationProperties aadAuthenticationPropertiesFactory() {
        AADAuthenticationProperties aadAuthenticationProperties = new AADAuthenticationProperties();
        aadAuthenticationProperties.setactiveDirectoryGroups(new ArrayList<>());
        return aadAuthenticationProperties;
}

But the error remains the same, so any idea about what is the activeDirectoryGroups property and how can I create a bean of AADAuthenticationProperties? I am using Java 8.

Thank you so much!


Solution

  • Just like @M.Deinum said in the comment, you just need to specify the properties in your application.properties. The bean will be generated by the azure auto configuration. Refer to this document for more details.

    azure.activedirectory.active-directory-groups=group1, group2