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
+65-30Lines changed: 65 additions & 30 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,15 +3,15 @@ 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.
# Tutorial: Connect to a PostgreSQL Database from Java Tomcat App Service without secrets using a managed identity
13
13
14
-
[Azure App Service](overview.md) provides a highly scalable, self-patching web hosting service in Azure. It also provides a [managed identity](overview-managed-identity.md) for your app, which is a turn-key solution for securing access to [Azure Database for PostgreSQL](../postgresql/index.yml) and other Azure services. Managed identities in App Service make your app more secure by eliminating secrets from your app, such as credentials in the environment variables. In this tutorial, you will learn how to:
14
+
[Azure App Service](overview.md) provides a highly scalable, self-patching web hosting service in Azure. It also provides a [managed identity](overview-managed-identity.md) for your app, which is a turn-key solution for securing access to [Azure Database for PostgreSQL](../postgresql/index.yml) and other Azure services. Managed identities in App Service make your app more secure by eliminating secrets from your app, such as credentials in the environment variables. In this tutorial, you learn how to:
15
15
16
16
> [!div class="checklist"]
17
17
> * Create a PostgreSQL database.
@@ -39,7 +39,7 @@ cd Passwordless-Connections-for-Java-Apps/Tomcat/
39
39
40
40
## Create an Azure Database for PostgreSQL
41
41
42
-
Follow these steps to create an Azure Database for Postgres in your subscription. The Spring Boot app will connect to this database and store its data when running, persisting the application state no matter where you run the application.
42
+
Follow these steps to create an Azure Database for Postgres in your subscription. The Spring Boot app connects to this database and store its data when running, persisting the application state no matter where you run the application.
43
43
44
44
1. Sign into the Azure CLI, and optionally set your subscription if you have more than one connected to your login credentials.
45
45
@@ -51,21 +51,21 @@ Follow these steps to create an Azure Database for Postgres in your subscription
51
51
1. Create an Azure Resource Group, noting the resource group name.
52
52
53
53
```azurecli-interactive
54
-
RESOURCE_GROUP=<resource-group-name>
55
-
LOCATION=eastus
54
+
export RESOURCE_GROUP=<resource-group-name>
55
+
export LOCATION=eastus
56
56
57
57
az group create --name $RESOURCE_GROUP --location $LOCATION
58
58
```
59
59
60
-
1. Create an Azure Database for PostgreSQL server. The server is created with an administrator account, but it won't be used because we'll use the Azure Active Directory (Azure AD) admin account to perform administrative tasks.
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 Azure Active Directory (Azure AD) admin account to perform administrative tasks.
61
61
62
62
### [Flexible Server](#tab/flexible)
63
63
64
64
```azurecli-interactive
65
-
POSTGRESQL_ADMIN_USER=azureuser
65
+
export POSTGRESQL_ADMIN_USER=azureuser
66
66
# PostgreSQL admin access rights won't be used because Azure AD authentication is leveraged to administer the database.
67
-
POSTGRESQL_ADMIN_PASSWORD=<admin-password>
68
-
POSTGRESQL_HOST=<postgresql-host-name>
67
+
export POSTGRESQL_ADMIN_PASSWORD=<admin-password>
68
+
export POSTGRESQL_HOST=<postgresql-host-name>
69
69
70
70
# Create a PostgreSQL server.
71
71
az postgres flexible-server create \
@@ -75,16 +75,16 @@ Follow these steps to create an Azure Database for Postgres in your subscription
75
75
--admin-user $POSTGRESQL_ADMIN_USER \
76
76
--admin-password $POSTGRESQL_ADMIN_PASSWORD \
77
77
--public-access 0.0.0.0 \
78
-
--sku-name Standard_D2s_v3
78
+
--sku-name Standard_D2s_v3
79
79
```
80
80
81
81
### [Single Server](#tab/single)
82
82
83
83
```azurecli-interactive
84
-
POSTGRESQL_ADMIN_USER=azureuser
84
+
export POSTGRESQL_ADMIN_USER=azureuser
85
85
# PostgreSQL admin access rights won't be used because Azure AD authentication is leveraged to administer the database.
86
-
POSTGRESQL_ADMIN_PASSWORD=<admin-password>
87
-
POSTGRESQL_HOST=<postgresql-host-name>
86
+
export POSTGRESQL_ADMIN_PASSWORD=<admin-password>
87
+
export POSTGRESQL_HOST=<postgresql-host-name>
88
88
89
89
# Create a PostgreSQL server.
90
90
az postgres server create \
@@ -93,16 +93,16 @@ Follow these steps to create an Azure Database for Postgres in your subscription
93
93
--location $LOCATION \
94
94
--admin-user $POSTGRESQL_ADMIN_USER \
95
95
--admin-password $POSTGRESQL_ADMIN_PASSWORD \
96
-
--public-network-access 0.0.0.0 \
97
-
--sku-name B_Gen5_1
96
+
--public-access 0.0.0.0 \
97
+
--sku-name B_Gen5_1
98
98
```
99
99
100
100
1. Create a database for the application.
101
101
102
102
### [Flexible Server](#tab/flexible)
103
103
104
104
```azurecli-interactive
105
-
DATABASE_NAME=checklist
105
+
export DATABASE_NAME=checklist
106
106
107
107
az postgres flexible-server db create \
108
108
--resource-group $RESOURCE_GROUP \
@@ -113,7 +113,7 @@ Follow these steps to create an Azure Database for Postgres in your subscription
113
113
### [Single Server](#tab/single)
114
114
115
115
```azurecli-interactive
116
-
DATABASE_NAME=checklist
116
+
export DATABASE_NAME=checklist
117
117
118
118
az postgres db create \
119
119
--resource-group $RESOURCE_GROUP \
@@ -134,8 +134,8 @@ Follow these steps to build a WAR file and deploy to Azure App Service on Tomcat
134
134
1. Create an Azure App Service resource on Linux using Tomcat 9.0.
135
135
136
136
```azurecli-interactive
137
-
APPSERVICE_PLAN=<app-service-plan>
138
-
APPSERVICE_NAME=<app-service-name>
137
+
export APPSERVICE_PLAN=<app-service-plan>
138
+
export APPSERVICE_NAME=<app-service-name>
139
139
# Create an App Service plan
140
140
az appservice plan create \
141
141
--resource-group $RESOURCE_GROUP \
@@ -149,7 +149,7 @@ Follow these steps to build a WAR file and deploy to Azure App Service on Tomcat
149
149
--resource-group $RESOURCE_GROUP \
150
150
--name $APPSERVICE_NAME \
151
151
--plan $APPSERVICE_PLAN \
152
-
--runtime "TOMCAT:9.0-jre8"
152
+
--runtime "TOMCAT:10.0-java11"
153
153
```
154
154
155
155
1. Deploy the WAR package to App Service.
@@ -176,7 +176,7 @@ Then, connect your app to a Postgres database with a system-assigned managed ide
176
176
177
177
### [Flexible Server](#tab/flexible)
178
178
179
-
To do this, run the [az webapp connection create](/cli/azure/webapp/connection/create#az-webapp-connection-create-postgres-flexible) command.
179
+
To make this connection, run the [az webapp connection create](/cli/azure/webapp/connection/create#az-webapp-connection-create-postgres-flexible) command.
180
180
181
181
```azurecli-interactive
182
182
az webapp connection create postgres-flexible \
@@ -185,12 +185,13 @@ az webapp connection create postgres-flexible \
185
185
--target-resource-group $RESOURCE_GROUP \
186
186
--server $POSTGRESQL_HOST \
187
187
--database $DATABASE_NAME \
188
-
--system-identity
188
+
--system-identity \
189
+
--client-type java
189
190
```
190
191
191
192
### [Single Server](#tab/single)
192
193
193
-
To do this, run the [az webapp connection create](/cli/azure/webapp/connection/create#az-webapp-connection-create-postgres) command.
194
+
To make this connection, run the [az webapp connection create](/cli/azure/webapp/connection/create#az-webapp-connection-create-postgres) command.
194
195
195
196
```azurecli-interactive
196
197
az webapp connection create postgres \
@@ -199,21 +200,55 @@ az webapp connection create postgres \
199
200
--target-resource-group $RESOURCE_GROUP \
200
201
--server $POSTGRESQL_HOST \
201
202
--database $DATABASE_NAME \
202
-
--system-identity
203
+
--system-identity \
204
+
--client-type java
203
205
```
204
206
205
207
---
206
-
This command creates a connection between your web app and your PostgreSQL server, and manages authentication through a system-assigned managed identity.
207
208
208
-
## View sample web app
209
+
This command creates a connection between your web app and your PostgreSQL server, and manages authentication through a system-assigned managed identity.
209
210
210
-
Run the following command to open the deployed web app in your browser.
211
+
Next, update App Settings and add plugin in connection string
0 commit comments