diff --git a/spotBugsExcludeFilter.xml b/spotBugsExcludeFilter.xml index c6b2fff2e..fd404c285 100644 --- a/spotBugsExcludeFilter.xml +++ b/spotBugsExcludeFilter.xml @@ -17,4 +17,8 @@ xsi:schemaLocation="https://github.com/spotbugs/filter/3.0.0 https://raw.githubu + + + + \ No newline at end of file diff --git a/src/main/java/com/microsoft/graph/authentication/AzureIdentityAccessTokenProvider.java b/src/main/java/com/microsoft/graph/authentication/AzureIdentityAccessTokenProvider.java new file mode 100644 index 000000000..ad7f12431 --- /dev/null +++ b/src/main/java/com/microsoft/graph/authentication/AzureIdentityAccessTokenProvider.java @@ -0,0 +1,37 @@ +package com.microsoft.graph.authentication; + +import java.util.HashSet; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +import com.azure.core.credential.TokenCredential; +import com.microsoft.kiota.authentication.ObservabilityOptions; + +/** AzureIdentityAccessTokenProvider wrapper from Kiota library with Microsoft Graph defaults. */ +public class AzureIdentityAccessTokenProvider extends com.microsoft.kiota.authentication.AzureIdentityAccessTokenProvider { + /** + * Creates a new instance of AzureIdentityAccessTokenProvider. + * @param tokenCredential The Azure.Identity.TokenCredential implementation to use. + */ + public AzureIdentityAccessTokenProvider(@Nonnull TokenCredential tokenCredential) { + this(tokenCredential, new String[] {}, null); + } + /** {@inheritDoc} */ + @SuppressWarnings("LambdaLast") + public AzureIdentityAccessTokenProvider(@Nonnull final TokenCredential tokenCredential, @Nonnull final String[] allowedHosts, + @Nullable final ObservabilityOptions observabilityOptions, @Nonnull final String... scopes) { + super(tokenCredential, allowedHosts, observabilityOptions, scopes); + if (allowedHosts.length == 0) { + final HashSet allowedHostsSet = new HashSet(); + allowedHostsSet.add("graph.microsoft.com"); + allowedHostsSet.add("graph.microsoft.us"); + allowedHostsSet.add("dod-graph.microsoft.us"); + allowedHostsSet.add("graph.microsoft.de"); + allowedHostsSet.add("microsoftgraph.chinacloudapi.cn"); + allowedHostsSet.add("canary.graph.microsoft.com"); + this.getAllowedHostsValidator().setAllowedHosts(allowedHostsSet); + } + } + +} diff --git a/src/main/java/com/microsoft/graph/authentication/AzureIdentityAuthenticationProvider.java b/src/main/java/com/microsoft/graph/authentication/AzureIdentityAuthenticationProvider.java new file mode 100644 index 000000000..7af941ac0 --- /dev/null +++ b/src/main/java/com/microsoft/graph/authentication/AzureIdentityAuthenticationProvider.java @@ -0,0 +1,32 @@ +package com.microsoft.graph.authentication; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +import com.azure.core.credential.TokenCredential; +import com.microsoft.kiota.authentication.BaseBearerTokenAuthenticationProvider; +import com.microsoft.kiota.authentication.ObservabilityOptions; +/** Implementation of Authentication provider for Azure Identity with Microsoft Graph defaults */ +public class AzureIdentityAuthenticationProvider extends BaseBearerTokenAuthenticationProvider { + /** + * Creates a new instance of AzureIdentityAuthenticationProvider. + * @param tokenCredential The Azure.Identity.TokenCredential implementation to use. + * @param allowedHosts The list of allowed hosts for which to request access tokens. + * @param scopes The scopes to request access tokens for. + */ + @SuppressWarnings("LambdaLast") + public AzureIdentityAuthenticationProvider(@Nonnull final TokenCredential tokenCredential, @Nonnull final String[] allowedHosts, @Nonnull final String... scopes) { + this(tokenCredential, allowedHosts, null, scopes); + } + /** + * Creates a new instance of AzureIdentityAuthenticationProvider. + * @param tokenCredential The Azure.Identity.TokenCredential implementation to use. + * @param allowedHosts The list of allowed hosts for which to request access tokens. + * @param observabilityOptions The observability options to use. + * @param scopes The scopes to request access tokens for. + */ + @SuppressWarnings("LambdaLast") + public AzureIdentityAuthenticationProvider(@Nonnull final TokenCredential tokenCredential, @Nonnull final String[] allowedHosts, @Nullable final ObservabilityOptions observabilityOptions, @Nonnull final String... scopes) { + super(new AzureIdentityAccessTokenProvider(tokenCredential, allowedHosts, observabilityOptions, scopes)); + } +}