Skip to content

Commit

Permalink
Implement SAS-based authentication (#43448)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lakicar95 authored Dec 24, 2024
1 parent 95e085f commit bb947b6
Show file tree
Hide file tree
Showing 19 changed files with 199 additions and 72 deletions.
26 changes: 18 additions & 8 deletions sdk/maps/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ Microsoft Azure Maps provides developers from all industries with powerful geosp
## Getting started

To get started with a specific library, see the **README.md** file located in the library's project folder.
- [Azure Maps Search](https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/maps/azure-maps-search/README.md) contains Search APIs for querying addresses, nearby locations, geopolygons etc.
- [Azure Maps Route](https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/maps/azure-maps-route/README.md) contains Route APIs for calculating matrix of route summaries, returning routes between destinations, etc.
- [Azure Maps Geolocation](https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/maps/azure-maps-geolocation/README.md) contains Geolocation APIs for determining the country/region of an IP address, etc.
- [Azure Maps Render](https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/maps/azure-maps-render/README.md) contains Render APIs to request map tiles, metadata for tilesets, etc.
- [Azure Maps Route](https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/maps/azure-maps-route/README.md) contains Route APIs for calculating matrix of route summaries, returning routes between destinations, etc.
- [Azure Maps Search](https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/maps/azure-maps-search/README.md) contains Search APIs for querying addresses, nearby locations, geopolygons, etc.
- [Azure Maps Timezone](https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/maps/azure-maps-timezone/README.md) contains Timezone APIs for converting between UTC and local times based on geographic locations, etc.
- [Azure Maps Traffic](https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/maps/azure-maps-traffic/README.md) contains Traffic APIs for providing traffic flow and incident information to enhance navigation and routing applications, etc.
- [Azure Maps Weather](https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/maps/azure-maps-weather/README.md) contains Weather APIs for retrieving current weather conditions, forecasts, and weather alerts, etc.

## Key concepts

Expand All @@ -20,9 +24,13 @@ For details on contributing to this repository, see the [contributing guide](htt
## Examples

For examples of each module please see:
- [Azure Maps Search Samples](https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/maps/azure-maps-search/src/samples)
- [Azure Maps Route Samples](https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/maps/azure-maps-route/src/samples)
- [Azure Maps Geolocation Samples](https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/maps/azure-maps-geolocation/src/samples)
- [Azure Maps Render Samples](https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/maps/azure-maps-render/src/samples)
- [Azure Maps Route Samples](https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/maps/azure-maps-route/src/samples)
- [Azure Maps Search Samples](https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/maps/azure-maps-search/src/samples)
- [Azure Maps Timezone Samples](https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/maps/azure-maps-timezone/src/samples)
- [Azure Maps Traffic Samples](https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/maps/azure-maps-traffic/src/samples)
- [Azure Maps Weather Samples](https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/maps/azure-maps-weather/src/samples)

## Troubleshooting
When you interact with the Azure Maps Services, errors returned by the Maps service correspond to the same HTTP status codes returned for REST API requests.
Expand All @@ -32,11 +40,13 @@ For example, if you search with an invalid coordinate, a error is returned, indi
## Next steps

Several Azure Maps Java SDK samples are available to you in the SDK's GitHub repository.
- [Azure Maps Search Samples](https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/maps/azure-maps-search/src/samples)
- [Azure Maps Route Samples](https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/maps/azure-maps-route/src/samples)
)
- [Azure Maps Geolocation Samples](https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/maps/azure-maps-geolocation/src/samples)
- [Azure Maps Render Samples](https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/maps/azure-maps-render/src/samples)
)
- [Azure Maps Route Samples](https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/maps/azure-maps-route/src/samples)
- [Azure Maps Search Samples](https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/maps/azure-maps-search/src/samples)
- [Azure Maps Timezone Samples](https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/maps/azure-maps-timezone/src/samples)
- [Azure Maps Traffic Samples](https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/maps/azure-maps-traffic/src/samples)
- [Azure Maps Weather Samples](https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/maps/azure-maps-weather/src/samples)

## Contributing

Expand Down
6 changes: 6 additions & 0 deletions sdk/maps/azure-maps-geolocation/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Release History

## 1.0.0-beta.3 (Unreleased)

### Features added

- Integrated support for SAS-based authentication

## 1.0.0-beta.2 (2024-11-08)

### Other Changes
Expand Down
8 changes: 6 additions & 2 deletions sdk/maps/azure-maps-geolocation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ Azure Management Libraries require a `TokenCredential` implementation for authen

### Authentication

By default, Azure Active Directory token authentication depends on correct configure of following environment variables.
There are 3 ways to authenticate the client: Shared key authentication, Microsoft Entra ID authentication, and shared access signature (SAS) authentication.

By default, Microsoft Entra ID token authentication depends on correct configure of following environment variables.

- `AZURE_CLIENT_ID` for Azure client ID.
- `AZURE_TENANT_ID` for Azure tenant ID.
Expand All @@ -61,7 +63,9 @@ GeolocationClient client = new GeolocationClientBuilder()
.buildClient();
```

TThe sample code assumes global Azure. Please change `AzureEnvironment.AZURE` variable if otherwise.
The sample code assumes global Azure. Please change `AzureEnvironment.AZURE` variable if otherwise.

For SAS-based authentication, please refer to [AccountsListSasSamples.java][https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/maps/azure-resourcemanager-maps/src/samples/java/com/azure/resourcemanager/maps/generated/AccountsListSasSamples.java].

See [Authentication][authenticate] for more options.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
import com.azure.core.client.traits.EndpointTrait;
import com.azure.core.client.traits.HttpTrait;
import com.azure.core.client.traits.TokenCredentialTrait;
import com.azure.core.client.traits.AzureSasCredentialTrait;
import com.azure.core.credential.AzureKeyCredential;
import com.azure.core.credential.AzureSasCredential;
import com.azure.core.credential.TokenCredential;
import com.azure.core.http.HttpClient;
import com.azure.core.http.HttpHeaderName;
Expand All @@ -28,6 +30,7 @@
import com.azure.core.http.policy.RetryOptions;
import com.azure.core.http.policy.RetryPolicy;
import com.azure.core.http.policy.UserAgentPolicy;
import com.azure.core.http.policy.AzureSasCredentialPolicy;
import com.azure.core.util.ClientOptions;
import com.azure.core.util.Configuration;
import com.azure.core.util.CoreUtils;
Expand Down Expand Up @@ -58,7 +61,8 @@
* <!-- end com.azure.maps.geolocation.sync.builder.ad.instantiation -->
*/
@ServiceClientBuilder(serviceClients = { GeolocationClient.class, GeolocationAsyncClient.class })
public final class GeolocationClientBuilder implements AzureKeyCredentialTrait<GeolocationClientBuilder>,
public final class GeolocationClientBuilder
implements AzureKeyCredentialTrait<GeolocationClientBuilder>, AzureSasCredentialTrait<GeolocationClientBuilder>,
TokenCredentialTrait<GeolocationClientBuilder>, HttpTrait<GeolocationClientBuilder>,
ConfigurationTrait<GeolocationClientBuilder>, EndpointTrait<GeolocationClientBuilder> {

Expand Down Expand Up @@ -98,6 +102,7 @@ public final class GeolocationClientBuilder implements AzureKeyCredentialTrait<G
// credentials
private AzureKeyCredential keyCredential;
private TokenCredential tokenCredential;
private AzureSasCredential sasCredential;

/**
* Default constructor for the builder class.
Expand Down Expand Up @@ -262,6 +267,19 @@ public GeolocationClientBuilder credential(AzureKeyCredential keyCredential) {
return this;
}

/**
* Sets the {@link AzureSasCredential} used to authenticate HTTP requests.
*
* @param sasCredential The {@link AzureSasCredential} used to authenticate HTTP requests.
* @return The updated {@link GeolocationClientBuilder} object.
* @throws NullPointerException If {@code sasCredential} is null.
*/
@Override
public GeolocationClientBuilder credential(AzureSasCredential sasCredential) {
this.sasCredential = Objects.requireNonNull(sasCredential, "'sasCredential' cannot be null.");
return this;
}

/**
* Sets retry options
*
Expand Down Expand Up @@ -339,6 +357,8 @@ private HttpPipeline createHttpPipeline() {
policies.add(new BearerTokenAuthenticationPolicy(tokenCredential, DEFAULT_SCOPES));
} else if (keyCredential != null) {
policies.add(new AzureKeyCredentialPolicy(GEOLOCATION_SUBSCRIPTION_KEY, keyCredential));
} else if (sasCredential != null) {
policies.add(new AzureSasCredentialPolicy(sasCredential));
} else {
// Throw exception that credential and tokenCredential cannot be null
throw LOGGER.logExceptionAsError(
Expand Down
6 changes: 6 additions & 0 deletions sdk/maps/azure-maps-render/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Release History

## 2.0.0-beta.2 (Unreleased)

### Features added

- Integrated support for SAS-based authentication

## 2.0.0-beta.1 (2024-11-08)

### Features Added
Expand Down
6 changes: 5 additions & 1 deletion sdk/maps/azure-maps-render/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ Azure Maps Libraries require a `TokenCredential` implementation for authenticati

### Authentication

By default, Azure Active Directory token authentication depends on correct configure of following environment variables.
There are 3 ways to authenticate the client: Shared key authentication, Microsoft Entra ID authentication, and shared access signature (SAS) authentication.

By default, Microsoft Entra ID token authentication depends on correct configure of following environment variables.

- `AZURE_CLIENT_ID` for Azure client ID.
- `AZURE_TENANT_ID` for Azure tenant ID.
Expand All @@ -66,6 +68,8 @@ MapsRenderClient client = builder.buildClient();

The sample code assumes global Azure. Please change `AzureEnvironment.AZURE` variable if otherwise.

For SAS-based authentication, please refer to [AccountsListSasSamples.java][https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/maps/azure-resourcemanager-maps/src/samples/java/com/azure/resourcemanager/maps/generated/AccountsListSasSamples.java].

See [Authentication][authenticate] for more options.

## Key concepts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
import com.azure.core.client.traits.EndpointTrait;
import com.azure.core.client.traits.HttpTrait;
import com.azure.core.client.traits.TokenCredentialTrait;
import com.azure.core.client.traits.AzureSasCredentialTrait;
import com.azure.core.credential.AzureKeyCredential;
import com.azure.core.credential.AzureSasCredential;
import com.azure.core.credential.TokenCredential;
import com.azure.core.http.HttpClient;
import com.azure.core.http.HttpHeaderName;
Expand All @@ -28,6 +30,7 @@
import com.azure.core.http.policy.RetryOptions;
import com.azure.core.http.policy.RetryPolicy;
import com.azure.core.http.policy.UserAgentPolicy;
import com.azure.core.http.policy.AzureSasCredentialPolicy;
import com.azure.core.util.ClientOptions;
import com.azure.core.util.Configuration;
import com.azure.core.util.CoreUtils;
Expand Down Expand Up @@ -78,7 +81,8 @@
* <!-- end com.azure.maps.render.sync.builder.ad.instantiation -->
*/
@ServiceClientBuilder(serviceClients = { MapsRenderClient.class, MapsRenderAsyncClient.class })
public final class MapsRenderClientBuilder implements AzureKeyCredentialTrait<MapsRenderClientBuilder>,
public final class MapsRenderClientBuilder
implements AzureKeyCredentialTrait<MapsRenderClientBuilder>, AzureSasCredentialTrait<MapsRenderClientBuilder>,
TokenCredentialTrait<MapsRenderClientBuilder>, HttpTrait<MapsRenderClientBuilder>,
ConfigurationTrait<MapsRenderClientBuilder>, EndpointTrait<MapsRenderClientBuilder> {

Expand Down Expand Up @@ -142,6 +146,7 @@ public MapsRenderClientBuilder() {
// credentials
private AzureKeyCredential keyCredential;
private TokenCredential tokenCredential;
private AzureSasCredential sasCredential;

/**
* Sets the Azure Maps client id for use with Azure AD Authentication. This client id
Expand Down Expand Up @@ -297,6 +302,19 @@ public MapsRenderClientBuilder credential(AzureKeyCredential keyCredential) {
return this;
}

/**
* Sets the {@link AzureSasCredential} used to authenticate HTTP requests.
*
* @param sasCredential The {@link AzureSasCredential} used to authenticate HTTP requests.
* @return The updated {@link MapsRenderClientBuilder} object.
* @throws NullPointerException If {@code sasCredential} is null.
*/
@Override
public MapsRenderClientBuilder credential(AzureSasCredential sasCredential) {
this.sasCredential = Objects.requireNonNull(sasCredential, "'sasCredential' cannot be null.");
return this;
}

/**
* Builds an instance of RenderClientImpl with the provided parameters.
*
Expand Down Expand Up @@ -361,6 +379,8 @@ private HttpPipeline createHttpPipeline() {
policies.add(new BearerTokenAuthenticationPolicy(tokenCredential, DEFAULT_SCOPES));
} else if (keyCredential != null) {
policies.add(new AzureKeyCredentialPolicy(RENDER_SUBSCRIPTION_KEY, keyCredential));
} else if (sasCredential != null) {
policies.add(new AzureSasCredentialPolicy(sasCredential));
} else {
// Throw exception that credential and tokenCredential cannot be null
throw LOGGER.logExceptionAsError(
Expand Down
6 changes: 6 additions & 0 deletions sdk/maps/azure-maps-route/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Release History

## 1.0.0-beta.3 (Unreleased)

### Features added

- Integrated support for SAS-based authentication

## 1.0.0-beta.2 (2024-11-08)

### Other Changes
Expand Down
6 changes: 5 additions & 1 deletion sdk/maps/azure-maps-route/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ Azure Maps Libraries require a `TokenCredential` implementation for authenticati

### Authentication

By default, Azure Active Directory token authentication depends on correct configure of following environment variables.
There are 3 ways to authenticate the client: Shared key authentication, Microsoft Entra ID authentication, and shared access signature (SAS) authentication.

By default, Microsoft Entra ID token authentication depends on correct configure of following environment variables.

- `AZURE_CLIENT_ID` for Azure client ID.
- `AZURE_TENANT_ID` for Azure tenant ID.
Expand All @@ -66,6 +68,8 @@ MapsRouteAsyncClient client = builder.buildAsyncClient();

The sample code assumes global Azure. Please change `AzureEnvironment.AZURE` variable if otherwise.

For SAS-based authentication, please refer to [AccountsListSasSamples.java][https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/maps/azure-resourcemanager-maps/src/samples/java/com/azure/resourcemanager/maps/generated/AccountsListSasSamples.java].

See [Authentication][authenticate] for more options.

## Key concepts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
import com.azure.core.client.traits.EndpointTrait;
import com.azure.core.client.traits.HttpTrait;
import com.azure.core.client.traits.TokenCredentialTrait;
import com.azure.core.client.traits.AzureSasCredentialTrait;
import com.azure.core.credential.AzureKeyCredential;
import com.azure.core.credential.AzureSasCredential;
import com.azure.core.credential.TokenCredential;
import com.azure.core.http.HttpClient;
import com.azure.core.http.HttpHeaderName;
Expand All @@ -27,6 +29,7 @@
import com.azure.core.http.policy.RetryOptions;
import com.azure.core.http.policy.RetryPolicy;
import com.azure.core.http.policy.UserAgentPolicy;
import com.azure.core.http.policy.AzureSasCredentialPolicy;
import com.azure.core.util.ClientOptions;
import com.azure.core.util.Configuration;
import com.azure.core.util.CoreUtils;
Expand Down Expand Up @@ -76,7 +79,8 @@
* <!-- end com.azure.maps.route.sync.builder.ad.instantiation -->
*/
@ServiceClientBuilder(serviceClients = { MapsRouteClient.class, MapsRouteAsyncClient.class })
public final class MapsRouteClientBuilder implements AzureKeyCredentialTrait<MapsRouteClientBuilder>,
public final class MapsRouteClientBuilder
implements AzureKeyCredentialTrait<MapsRouteClientBuilder>, AzureSasCredentialTrait<MapsRouteClientBuilder>,
TokenCredentialTrait<MapsRouteClientBuilder>, HttpTrait<MapsRouteClientBuilder>,
ConfigurationTrait<MapsRouteClientBuilder>, EndpointTrait<MapsRouteClientBuilder> {

Expand Down Expand Up @@ -109,6 +113,7 @@ public final class MapsRouteClientBuilder implements AzureKeyCredentialTrait<Map
// credentials
private AzureKeyCredential keyCredential;
private TokenCredential tokenCredential;
private AzureSasCredential sasCredential;

/**
* Default constructor for the builder class.
Expand Down Expand Up @@ -276,6 +281,19 @@ public MapsRouteClientBuilder credential(AzureKeyCredential keyCredential) {
return this;
}

/**
* Sets the {@link AzureSasCredential} used to authenticate HTTP requests.
*
* @param sasCredential The {@link AzureSasCredential} used to authenticate HTTP requests.
* @return The updated {@link MapsRouteClientBuilder} object.
* @throws NullPointerException If {@code sasCredential} is null.
*/
@Override
public MapsRouteClientBuilder credential(AzureSasCredential sasCredential) {
this.sasCredential = Objects.requireNonNull(sasCredential, "'sasCredential' cannot be null.");
return this;
}

/**
* Sets retry options
*
Expand Down Expand Up @@ -353,6 +371,8 @@ private HttpPipeline createHttpPipeline() {
policies.add(new BearerTokenAuthenticationPolicy(tokenCredential, DEFAULT_SCOPES));
} else if (keyCredential != null) {
policies.add(new AzureKeyCredentialPolicy(MAPS_SUBSCRIPTION_KEY, keyCredential));
} else if (sasCredential != null) {
policies.add(new AzureSasCredentialPolicy(sasCredential));
} else {
// Throw exception that credential and tokenCredential cannot be null
throw LOGGER.logExceptionAsError(
Expand Down
8 changes: 2 additions & 6 deletions sdk/maps/azure-maps-search/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,9 @@

## 2.0.0-beta.2 (Unreleased)

### Features Added

### Breaking Changes

### Bugs Fixed
### Features added

### Other Changes
- Integrated support for SAS-based authentication

## 2.0.0-beta.1 (2024-12-17)

Expand Down
6 changes: 5 additions & 1 deletion sdk/maps/azure-maps-search/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ Azure Maps Libraries require a `TokenCredential` implementation for authenticati

### Authentication

By default, Azure Active Directory token authentication depends on correct configure of following environment variables.
There are 3 ways to authenticate the client: Shared key authentication, Microsoft Entra ID authentication, and shared access signature (SAS) authentication.

By default, Microsoft Entra ID token authentication depends on correct configuration of the following environment variables.

- `AZURE_CLIENT_ID` for Azure client ID.
- `AZURE_TENANT_ID` for Azure tenant ID.
Expand All @@ -66,6 +68,8 @@ MapsSearchClient client = builder.buildClient();

The sample code assumes global Azure. Please change `AzureEnvironment.AZURE` variable if otherwise.

For SAS-based authentication, please refer to [AccountsListSasSamples.java][https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/maps/azure-resourcemanager-maps/src/samples/java/com/azure/resourcemanager/maps/generated/AccountsListSasSamples.java].

See [Authentication][authenticate] for more options.

## Key concepts
Expand Down
Loading

0 comments on commit bb947b6

Please sign in to comment.