You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/app-service/tutorial-java-tomcat-connect-managed-identity-postgresql-database.md
+1-54Lines changed: 1 addition & 54 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,7 @@ title: 'Tutorial: Access data with managed identity in Java'
3
3
description: Secure Azure Database for PostgreSQL connectivity with managed identity from a sample Java Tomcat app, and apply it to other Azure services.
@@ -59,8 +59,6 @@ Follow these steps to create an Azure Database for Postgres in your subscription
59
59
60
60
1. Create an Azure Database for PostgreSQL server. The server is created with an administrator account, but it isn't used because we're going to use the Microsoft Entra admin account to perform administrative tasks.
61
61
62
-
### [Flexible Server](#tab/flexible)
63
-
64
62
```azurecli-interactive
65
63
export POSTGRESQL_ADMIN_USER=azureuser
66
64
# PostgreSQL admin access rights won't be used because Azure AD authentication is leveraged to administer the database.
@@ -78,29 +76,8 @@ Follow these steps to create an Azure Database for Postgres in your subscription
78
76
--sku-name Standard_D2s_v3
79
77
```
80
78
81
-
### [Single Server](#tab/single)
82
-
83
-
```azurecli-interactive
84
-
export POSTGRESQL_ADMIN_USER=azureuser
85
-
# PostgreSQL admin access rights won't be used because Azure AD authentication is leveraged to administer the database.
86
-
export POSTGRESQL_ADMIN_PASSWORD=<admin-password>
87
-
export POSTGRESQL_HOST=<postgresql-host-name>
88
-
89
-
# Create a PostgreSQL server.
90
-
az postgres server create \
91
-
--resource-group $RESOURCE_GROUP \
92
-
--name $POSTGRESQL_HOST \
93
-
--location $LOCATION \
94
-
--admin-user $POSTGRESQL_ADMIN_USER \
95
-
--admin-password $POSTGRESQL_ADMIN_PASSWORD \
96
-
--public-access 0.0.0.0 \
97
-
--sku-name B_Gen5_1
98
-
```
99
-
100
79
1. Create a database for the application.
101
80
102
-
### [Flexible Server](#tab/flexible)
103
-
104
81
```azurecli-interactive
105
82
export DATABASE_NAME=checklist
106
83
@@ -110,17 +87,6 @@ Follow these steps to create an Azure Database for Postgres in your subscription
110
87
--database-name $DATABASE_NAME
111
88
```
112
89
113
-
### [Single Server](#tab/single)
114
-
115
-
```azurecli-interactive
116
-
export DATABASE_NAME=checklist
117
-
118
-
az postgres db create \
119
-
--resource-group $RESOURCE_GROUP \
120
-
--server-name $POSTGRESQL_HOST \
121
-
--name $DATABASE_NAME
122
-
```
123
-
124
90
## Deploy the application to App Service
125
91
126
92
Follow these steps to build a WAR file and deploy to Azure App Service on Tomcat using a WAR packaging.
@@ -174,8 +140,6 @@ az extension add --name serviceconnector-passwordless --upgrade
174
140
175
141
Then, connect your app to a Postgres database with a system-assigned managed identity using Service Connector.
176
142
177
-
### [Flexible Server](#tab/flexible)
178
-
179
143
To make this connection, run the [az webapp connection create](/cli/azure/webapp/connection/create#az-webapp-connection-create-postgres-flexible) command.
180
144
181
145
```azurecli-interactive
@@ -189,23 +153,6 @@ az webapp connection create postgres-flexible \
189
153
--client-type java
190
154
```
191
155
192
-
### [Single Server](#tab/single)
193
-
194
-
To make this connection, run the [az webapp connection create](/cli/azure/webapp/connection/create#az-webapp-connection-create-postgres) command.
195
-
196
-
```azurecli-interactive
197
-
az webapp connection create postgres \
198
-
--resource-group $RESOURCE_GROUP \
199
-
--name $APPSERVICE_NAME \
200
-
--target-resource-group $RESOURCE_GROUP \
201
-
--server $POSTGRESQL_HOST \
202
-
--database $DATABASE_NAME \
203
-
--system-identity \
204
-
--client-type java
205
-
```
206
-
207
-
---
208
-
209
156
This command creates a connection between your web app and your PostgreSQL server, and manages authentication through a system-assigned managed identity.
210
157
211
158
Next, update App Settings and add plugin in connection string
# Bind an Azure Database for PostgreSQL to your application in Azure Spring Apps
@@ -28,8 +26,6 @@ Microsoft Entra authentication is a mechanism for connecting to Azure Database f
28
26
29
27
PostgreSQL authentication uses accounts stored in PostgreSQL. If you choose to use passwords as credentials for the accounts, these credentials are stored in the user table. Because these passwords are stored in PostgreSQL, you need to manage the rotation of the passwords by yourself.
30
28
31
-
::: zone pivot="postgresql-passwordless-flexible-server"
32
-
33
29
## Prerequisites
34
30
35
31
* An application deployed to Azure Spring Apps. For more information, see [Quickstart: Deploy your first application to Azure Spring Apps](./quickstart.md).
@@ -121,100 +117,6 @@ Use the following steps to bind your app using a secret.
121
117
122
118
---
123
119
124
-
::: zone-end
125
-
126
-
::: zone pivot="postgresql-passwordless-single-server"
127
-
128
-
## Prerequisites
129
-
130
-
* An application deployed to Azure Spring Apps. For more information, see [Quickstart: Deploy your first application to Azure Spring Apps](./quickstart.md).
131
-
* An Azure Database for PostgreSQL Single Server instance.
132
-
* [Azure CLI](/cli/azure/install-azure-cli) version 2.45.0 or higher.
133
-
134
-
## Prepare your project
135
-
136
-
### [Java](#tab/JavaSingle)
137
-
138
-
Use the following steps to prepare your project.
139
-
140
-
1. In your project's *pom.xml* file, add the following dependency:
1. In the *application.properties* file, remove any `spring.datasource.*` properties.
154
-
155
-
1. Update the current app by running `az spring app deploy`, or create a new deployment for this change by running `az spring app deployment create`.
156
-
157
-
### [Polyglot](#tab/PolyglotSingle)
158
-
159
-
All the connection strings and credentials will be injected as the environment variables, which can be referenced in your application codes.
160
-
161
-
You can find the default environment variable names in this doc: [Integrate Azure Database for PostgreSQL with Service Connector](../../service-connector/how-to-integrate-postgres.md#default-environment-variable-names-or-application-properties-and-sample-code)
162
-
163
-
---
164
-
165
-
## Bind your app to the Azure Database for PostgreSQL instance
166
-
167
-
> [!NOTE]
168
-
> Service Connectors are created at the deployment level. So if another deployment is created, you need to create the connections again.
169
-
170
-
### [Passwordless](#tab/PasswordlessSingle)
171
-
172
-
1. Install the [Service Connector](../../service-connector/overview.md) passwordless extension for the Azure CLI:
173
-
174
-
```azurecli
175
-
az extension add --name serviceconnector-passwordless --upgrade
176
-
```
177
-
178
-
1. Configure Azure Spring Apps to connect to the PostgreSQL Database with a system-assigned managed identity using the `az spring connection create` command.
In this article, you learned how to bind an application in Azure Spring Apps to an Azure Database for PostgreSQL instance. To learn more about binding services to an application, see [Bind an Azure Cosmos DB database to an application in Azure Spring Apps](./how-to-bind-cosmos.md).
0 commit comments