forked from GoogleCloudPlatform/java-docs-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into update-migration-sample
- Loading branch information
Showing
22 changed files
with
810 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Copyright 2017 Google Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License.import org.apache.tools.ant.filters.ReplaceTokens | ||
|
||
buildscript { | ||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
classpath 'com.google.cloud.tools:endpoints-framework-gradle-plugin:+' | ||
classpath 'com.google.cloud.tools:appengine-gradle-plugin:+' | ||
} | ||
} | ||
|
||
repositories { | ||
maven { | ||
url 'https://maven-central.storage.googleapis.com' | ||
} | ||
jcenter() | ||
mavenCentral() | ||
} | ||
|
||
task wrapper(type: Wrapper) { | ||
gradleVersion = '3.5' | ||
} | ||
|
||
def projectId = 'YOUR_PROJECT_ID' | ||
|
||
apply plugin: 'java' | ||
apply plugin: 'war' | ||
apply plugin: 'com.google.cloud.tools.endpoints-framework-server' | ||
apply plugin: 'com.google.cloud.tools.appengine' | ||
|
||
dependencies { | ||
// For real projects: use concrete versions here instead of the '+' to make your build consistent | ||
compile 'com.google.endpoints:endpoints-framework:+' | ||
compile 'com.google.endpoints:endpoints-management-control-appengine:+' | ||
compile 'com.google.endpoints:endpoints-framework-auth:+' | ||
} | ||
|
||
endpointsServer { | ||
// Endpoints Framework Plugin server-side configuration | ||
hostname = "echo-api.endpoints.${projectId}.cloud.goog" | ||
} | ||
|
||
sourceCompatibility = 1.7 // App Engine Standard uses Java 7 | ||
targetCompatibility = 1.7 // App Engine Standard uses Java 7 | ||
|
||
// this replaces the ${endpoints.project.id} in appengine-web.xml and web.xml | ||
task replaceProjectId(type: Copy) { | ||
from 'src/main/webapp/WEB-INF/' | ||
include '*.xml' | ||
into 'build/exploded-backend/WEB-INF' | ||
expand(endpoints:[project:[id:projectId]]) | ||
filteringCharset = 'UTF-8' | ||
} | ||
assemble.dependsOn replaceProjectId |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Cloud Identity-Aware Proxy sample for Google App Engine | ||
|
||
This sample demonstrates how to use the [Cloud Identity-Aware Proxy][iap-docs] on [Google App | ||
Engine][ae-docs]. | ||
|
||
[iap-docs]: https://cloud.google.com/iap/docs/ | ||
[ae-docs]: https://cloud.google.com/appengine/docs/java/ | ||
|
||
## Setup | ||
|
||
Install the [Google Cloud SDK](https://cloud.google.com/sdk/) and run: | ||
``` | ||
gcloud init | ||
``` | ||
If this is your first time creating an App engine application: | ||
``` | ||
gcloud app create | ||
``` | ||
|
||
## Running locally | ||
|
||
This application depends on being enabled behind an IAP, so this program should not be run locally. | ||
|
||
## Deploying | ||
|
||
- Deploy the application to the project | ||
``` | ||
mvn clean appengine:deploy | ||
``` | ||
- [Enable](https://cloud.google.com/iap/docs/app-engine-quickstart) Identity-Aware Proxy on the App Engine app. | ||
- Add the email account you'll be running the test as to the Identity-Aware Proxy access list for the project. | ||
## Test | ||
Once deployed, access `https://your-project-id.appspot.com` . This should now prompt you to sign in for access. | ||
Sign in with the email account that was added to the Identity-Aware proxy access list. | ||
You should now see the jwt token that was received from the IAP server. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<!-- | ||
Copyright 2017 Google Inc. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
<project> | ||
<modelVersion>4.0.0</modelVersion> | ||
<packaging>war</packaging> | ||
<version>1.0-SNAPSHOT</version> | ||
<groupId>com.example.appengine</groupId> | ||
<artifactId>appengine-iap</artifactId> | ||
|
||
<parent> | ||
<groupId>com.google.cloud</groupId> | ||
<artifactId>appengine-doc-samples</artifactId> | ||
<version>1.0.0</version> | ||
<relativePath>..</relativePath> | ||
</parent> | ||
<dependencies> | ||
<dependency> | ||
<groupId>javax.servlet</groupId> | ||
<artifactId>servlet-api</artifactId> | ||
<version>2.5</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<!-- for hot reload of the web application --> | ||
<outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/classes</outputDirectory> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<version>3.3</version> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<source>1.7</source> | ||
<target>1.7</target> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>com.google.cloud.tools</groupId> | ||
<artifactId>appengine-maven-plugin</artifactId> | ||
<version>1.3.1</version> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
34 changes: 34 additions & 0 deletions
34
appengine/iap/src/main/java/com/example/appengine/iap/JwtServlet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** | ||
* Copyright 2017 Google Inc. | ||
* | ||
* <p>Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file | ||
* except in compliance with the License. You may obtain a copy of the License at | ||
* | ||
* <p>http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* <p>Unless required by applicable law or agreed to in writing, software distributed under the | ||
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.example.appengine.iap; | ||
|
||
import java.io.IOException; | ||
import javax.servlet.http.HttpServlet; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
/** | ||
* Identity Aware Proxy (IAP) Test application to reflect jwt token issued by IAP. IAP must be | ||
* enabled on application. {@see https://cloud.google.com/iap/docs/app-engine-quickstart} | ||
*/ | ||
@SuppressWarnings("serial") | ||
public class JwtServlet extends HttpServlet { | ||
|
||
private static final String IAP_JWT_HEADER = "x-goog-authenticated-user-jwt"; | ||
|
||
@Override | ||
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { | ||
resp.getWriter().print(IAP_JWT_HEADER + ":" + req.getHeader(IAP_JWT_HEADER)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- | ||
Copyright 2017 Google Inc. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0"> | ||
<threadsafe>true</threadsafe> | ||
</appengine-web-app> |
Oops, something went wrong.