Skip to content

Commit c8c2799

Browse files
authored
Undo deleted IAP sample (GoogleCloudPlatform#2057)
* Readd sample * Update ReadMe.md
1 parent deb71c6 commit c8c2799

File tree

6 files changed

+182
-1
lines changed

6 files changed

+182
-1
lines changed

appengine-java8/iap/README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Cloud Identity-Aware Proxy sample for Google App Engine
2+
3+
This sample demonstrates how to use the [Cloud Identity-Aware Proxy][iap-docs] on [Google App
4+
Engine][ae-docs].
5+
6+
[iap-docs]: https://cloud.google.com/iap/docs/
7+
[ae-docs]: https://cloud.google.com/appengine/docs/java/
8+
9+
## Setup
10+
11+
Install the [Google Cloud SDK](https://cloud.google.com/sdk/) and run:
12+
```
13+
gcloud init
14+
```
15+
If this is your first time creating an App engine application:
16+
```
17+
gcloud app create
18+
```
19+
20+
## Running locally
21+
22+
This application depends on being enabled behind an IAP, so this program should not be run locally.
23+
24+
## Deploying
25+
26+
- Deploy the application to the project
27+
```
28+
mvn clean appengine:deploy
29+
```
30+
- [Enable](https://cloud.google.com/iap/docs/app-engine-quickstart) Identity-Aware Proxy on the App Engine app.
31+
- Add the email account you'll be running the test as to the Identity-Aware Proxy access list for the project.
32+
33+
## Test
34+
35+
Once deployed, access `https://your-project-id.appspot.com` . This should now prompt you to sign in for access.
36+
Sign in with the email account that was added to the Identity-Aware proxy access list.
37+
You should now see the jwt token that was received from the IAP server.

appengine-java8/iap/pom.xml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<!--
2+
Copyright 2017 Google Inc.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
-->
16+
<project>
17+
<modelVersion>4.0.0</modelVersion>
18+
<packaging>war</packaging>
19+
<version>1.0-SNAPSHOT</version>
20+
<groupId>com.example.appengine</groupId>
21+
<artifactId>appengine-iap</artifactId>
22+
23+
<!--
24+
The parent pom defines common style checks and testing strategies for our samples.
25+
Removing or replacing it should not effect the execution of the samples in anyway.
26+
-->
27+
<parent>
28+
<groupId>com.google.cloud.samples</groupId>
29+
<artifactId>shared-configuration</artifactId>
30+
<version>1.0.11</version>
31+
</parent>
32+
33+
<properties>
34+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
35+
<maven.compiler.source>1.8</maven.compiler.source>
36+
<maven.compiler.target>1.8</maven.compiler.target>
37+
</properties>
38+
39+
<dependencies>
40+
<dependency>
41+
<groupId>javax.servlet</groupId>
42+
<artifactId>servlet-api</artifactId>
43+
<version>2.5</version>
44+
<scope>provided</scope>
45+
</dependency>
46+
</dependencies>
47+
<build>
48+
<!-- for hot reload of the web application -->
49+
<outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/classes</outputDirectory>
50+
<plugins>
51+
<plugin>
52+
<groupId>org.apache.maven.plugins</groupId>
53+
<artifactId>maven-compiler-plugin</artifactId>
54+
<version>3.8.1</version>
55+
<configuration>
56+
<compilerArgs>
57+
<arg>-XDcompilePolicy=simple</arg>
58+
<arg>-Xplugin:ErrorProne</arg>
59+
</compilerArgs>
60+
<annotationProcessorPaths>
61+
<path>
62+
<groupId>com.google.errorprone</groupId>
63+
<artifactId>error_prone_core</artifactId>
64+
<version>2.3.3</version>
65+
</path>
66+
</annotationProcessorPaths>
67+
</configuration>
68+
</plugin>
69+
<plugin>
70+
<groupId>com.google.cloud.tools</groupId>
71+
<artifactId>appengine-maven-plugin</artifactId>
72+
<version>1.9.76</version>
73+
</plugin>
74+
</plugins>
75+
</build>
76+
</project>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright 2017 Google Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.example.appengine.iap;
18+
19+
import java.io.IOException;
20+
import javax.servlet.http.HttpServlet;
21+
import javax.servlet.http.HttpServletRequest;
22+
import javax.servlet.http.HttpServletResponse;
23+
24+
/**
25+
* Identity Aware Proxy (IAP) Test application to reflect jwt token issued by IAP. IAP must be
26+
* enabled on application. {@see https://cloud.google.com/iap/docs/app-engine-quickstart}
27+
*/
28+
@SuppressWarnings("serial")
29+
public class JwtServlet extends HttpServlet {
30+
31+
private static final String IAP_JWT_HEADER = "x-goog-iap-jwt-assertion";
32+
private static final String IAP_AUTHENTICATED_USER_HEADER = "x-goog-authenticated-user-jwt";
33+
34+
@Override
35+
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
36+
resp.getWriter().print(IAP_AUTHENTICATED_USER_HEADER + ":" + req.getHeader(IAP_JWT_HEADER));
37+
}
38+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
Copyright 2017 Google Inc.
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
Unless required by applicable law or agreed to in writing, software
9+
distributed under the License is distributed on an "AS IS" BASIS,
10+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
See the License for the specific language governing permissions and
12+
limitations under the License.
13+
-->
14+
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
15+
<threadsafe>true</threadsafe>
16+
</appengine-web-app>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee"
3+
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
4+
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
5+
version="2.5">
6+
<servlet>
7+
<servlet-name>hello</servlet-name>
8+
<servlet-class>com.example.appengine.iap.JwtServlet</servlet-class>
9+
</servlet>
10+
<servlet-mapping>
11+
<servlet-name>hello</servlet-name>
12+
<url-pattern>/</url-pattern>
13+
</servlet-mapping>
14+
</web-app>

iap/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ enabling you to adopt an application-level access control model instead of relyi
2525
verify the JWT token in an incoming request to an IAP protected resource.
2626

2727
## Testing
28-
- Deploy the [demo app engine application](../appengine/iap/README.md). This application will return the JWT token to an authorized incoming request.
28+
- Deploy the [demo app engine application](../appengine-java8/iap/README.md). This application will return the JWT token to an authorized incoming request.
2929
It will be used to test both the authorization of an incoming request to an IAP protected resource and the JWT token returned from IAP.
3030

3131
- [Enable](https://cloud.google.com/iap/docs/app-engine-quickstart) Identity-Aware Proxy on the App Engine app.

0 commit comments

Comments
 (0)