Class TokenProvider
- java.lang.Object
-
- com.microsoft.azure.servicebus.security.TokenProvider
-
- Direct Known Subclasses:
AzureActiveDirectoryTokenProvider,ManagedIdentityTokenProvider,SharedAccessSignatureTokenProvider
public abstract class TokenProvider extends Object
This abstract class defines the contract of a token provider. All token providers should inherit from this class. An instance of token provider is used to obtain a security token for a given audience.- Since:
- 1.2.0
-
-
Constructor Summary
Constructors Constructor Description TokenProvider()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static TokenProvidercreateAzureActiveDirectoryTokenProvider(AzureActiveDirectoryTokenProvider.AuthenticationCallback callback, String authority, Object callbackState)Creates a Azure Active Directory token provider that creates a token with the user defined AuthenticationCallback.static TokenProvidercreateManagedIdentityTokenProvider()Creates a Managed Identity token provider.static TokenProvidercreateSharedAccessSignatureTokenProvider(String sasKeyName, String sasKey)Creates a Shared Access Signature token provider with the given key name and key value.static TokenProvidercreateSharedAccessSignatureTokenProvider(String sasToken, Instant sasTokenValidUntil)Creates a Shared Access Signature token provider that always returns an already created token.abstract CompletableFuture<SecurityToken>getSecurityTokenAsync(String audience)Asynchronously gets a security token for the given audience.
-
-
-
Method Detail
-
getSecurityTokenAsync
public abstract CompletableFuture<SecurityToken> getSecurityTokenAsync(String audience)
Asynchronously gets a security token for the given audience. Implementations of this method may choose to create a new token for every call or return a cached token. But the token returned must be valid.- Parameters:
audience- path of the entity for which this security token is to be presented- Returns:
- an instance of CompletableFuture which returns a
SecurityTokenon completion.
-
createSharedAccessSignatureTokenProvider
public static TokenProvider createSharedAccessSignatureTokenProvider(String sasKeyName, String sasKey)
Creates a Shared Access Signature token provider with the given key name and key value. Returned token provider creates tokens with validity of 20 minutes. This is a utility method.- Parameters:
sasKeyName- SAS key namesasKey- SAS key value- Returns:
- an instance of Shared Access Signature token provider with the given key name, key value.
-
createSharedAccessSignatureTokenProvider
public static TokenProvider createSharedAccessSignatureTokenProvider(String sasToken, Instant sasTokenValidUntil)
Creates a Shared Access Signature token provider that always returns an already created token. This is a utility method.- Parameters:
sasToken- Already created Shared Access Signature token to be returned bygetSecurityTokenAsync(String)method.sasTokenValidUntil- Instant when the token expires- Returns:
- an instance of Shared Access Signature token provider that always returns an already created token.
-
createAzureActiveDirectoryTokenProvider
public static TokenProvider createAzureActiveDirectoryTokenProvider(AzureActiveDirectoryTokenProvider.AuthenticationCallback callback, String authority, Object callbackState)
Creates a Azure Active Directory token provider that creates a token with the user defined AuthenticationCallback. This is a utility method.- Parameters:
callback- A custom AuthenticationCallback that takes in the target resource and address of the authority to issue token and provides a security token for the target urlauthority- URL of the Azure Active Directory instancecallbackState- Custom parameter that may be provided to the AuthenticationCallback- Returns:
- an instance of Azure Active Directory token provider
-
createManagedIdentityTokenProvider
public static TokenProvider createManagedIdentityTokenProvider()
Creates a Managed Identity token provider. This is a utility method.- Returns:
- an instance of Managed Identity token provider
-
-