Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
Initial commit. Primarily webauthn objects and simple tests.
  • Loading branch information
cpiper authored and Casey Piper committed May 17, 2017
0 parents commit 6272229
Show file tree
Hide file tree
Showing 70 changed files with 3,817 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
target/
.settings/
.classpath
.project
154 changes: 154 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>

<groupId>com.google.webauthn</groupId>
<artifactId>gaedemo</artifactId>

<!-- [START set_versions] -->
<properties>
<appengine.app.version>1</appengine.app.version>
<appengine.sdk.version>1.9.48</appengine.sdk.version>

<objectify.version>5.1.5</objectify.version>
<guava.version>18.0</guava.version>

<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<prerequisites>
<maven>3.1.0</maven>
</prerequisites>
<!-- [END set_versions] -->

<dependencies>
<!-- Compile/runtime dependencies -->
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-api-1.0-sdk</artifactId>
<version>${appengine.sdk.version}</version>
</dependency>
<dependency>
<groupId>co.nstant.in</groupId>
<artifactId>cbor</artifactId>
<version>0.7</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>

<!-- [START Objectify_Dependencies] -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
<dependency>
<groupId>com.googlecode.objectify</groupId>
<artifactId>objectify</artifactId>
<version>${objectify.version}</version>
</dependency>
<!-- [END Objectify_Dependencies] -->

<!-- Test Dependencies -->
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-testing</artifactId>
<version>${appengine.sdk.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-api-stubs</artifactId>
<version>${appengine.sdk.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
<version>1.56</version>
</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.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>display-dependency-updates</goal>
<goal>display-plugin-updates</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<version>3.2</version>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<archiveClasses>true</archiveClasses>
<webResources>
<!-- in order to interpolate version from pom into appengine-web.xml -->
<resource>
<directory>${basedir}/src/main/webapp/WEB-INF</directory>
<filtering>true</filtering>
<targetPath>WEB-INF</targetPath>
</resource>
</webResources>
</configuration>
</plugin>

<plugin>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-maven-plugin</artifactId>
<version>${appengine.sdk.version}</version>
<configuration>
<enableJarClasses>false</enableJarClasses>
<!-- Comment in the below snippet to bind to all IPs instead of just localhost -->
<!-- address>0.0.0.0</address> <port>8080</port -->
<!-- Comment in the below snippet to enable local debugging with a remote
debugger like those included with Eclipse or IntelliJ -->
<!-- jvmFlags> <jvmFlag>-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n</jvmFlag>
</jvmFlags -->
</configuration>
</plugin>
</plugins>
</build>
</project>
78 changes: 78 additions & 0 deletions src/main/java/com/example/guestbook/Greeting.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/**
* Copyright 2014-2015 Google Inc. All Rights Reserved.
*
* 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.
*/

//[START all]
package com.example.guestbook;

import com.google.webauthn.gaedemo.server.OfyHelper;
import com.googlecode.objectify.Key;
import com.googlecode.objectify.annotation.*;

import java.lang.String;
import java.util.*;

/**
* The @Entity tells Objectify about our entity. We also register it in {@link OfyHelper}
* Our primary key @Id is set automatically by the Google Datastore for us.
*
* We add a @Parent to tell the object about its ancestor. We are doing this to support many
* guestbooks. Objectify, unlike the AppEngine library requires that you specify the fields you
* want to index using @Index. Only indexing the fields you need can lead to substantial gains in
* performance -- though if not indexing your data from the start will require indexing it later.
*
* NOTE - all the properties are PUBLIC so that we can keep the code simple.
**/
@Entity
public class Greeting {
@Parent Key<Guestbook> theBook;
@Id public Long id;

public String author_email;
public String author_id;
public String content;
@Index public Date date;

/**
* Simple constructor just sets the date
**/
public Greeting() {
date = new Date();
}

/**
* A convenience constructor
**/
public Greeting(String book, String content) {
this();
if( book != null ) {
theBook = Key.create(Guestbook.class, book); // Creating the Ancestor key
} else {
theBook = Key.create(Guestbook.class, "default");
}
this.content = content;
}

/**
* Takes all important fields
**/
public Greeting(String book, String content, String id, String email) {
this(book, content);
author_email = email;
author_id = id;
}

}
//[END all]
33 changes: 33 additions & 0 deletions src/main/java/com/example/guestbook/Guestbook.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* Copyright 2014-2015 Google Inc. All Rights Reserved.
*
* 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.
*/

//[START all]
package com.example.guestbook;

import com.googlecode.objectify.annotation.Entity;
import com.googlecode.objectify.annotation.Id;

/**
* The @Entity tells Objectify about our entity. We also register it in
* OfyHelper.java -- very important.
*
* This is never actually created, but gives a hint to Objectify about our Ancestor key.
*/
@Entity
public class Guestbook {
@Id public String book;
}
//[END all]
49 changes: 49 additions & 0 deletions src/main/java/com/example/guestbook/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.example.guestbook;

import co.nstant.in.cbor.CborBuilder;
import co.nstant.in.cbor.model.ByteString;
import co.nstant.in.cbor.model.DataItem;
import co.nstant.in.cbor.model.MajorType;
import co.nstant.in.cbor.model.Map;
import co.nstant.in.cbor.model.UnicodeString;
import java.util.List;

public class Main {

/**
* @param args
*/
public static void main(String[] args) {
// TODO(piperc): Auto-generated method stub

List<DataItem> l = new CborBuilder()
.addMap()
.put(new UnicodeString("authData"), new ByteString(new byte[4]))
.put(new UnicodeString("fmt"), new UnicodeString("u2f"))
.put(new UnicodeString("attStmt"), new ByteString(new byte[1]))
.end()
.build();

for (DataItem i : l) {
System.out.println(i.getMajorType());
System.out.println(i.getTag());
System.out.println("done");
if (i.getMajorType() == MajorType.MAP) {
System.out.println(i instanceof Map);
Map m = (Map) i;
for (DataItem mi : m.getKeys()) {
System.out.print("\t" + mi.getMajorType());

DataItem value = m.get(mi);
System.out.println(": " + value.getMajorType());
if (value.getMajorType() == MajorType.UNICODE_STRING) {
System.out.println(((UnicodeString)value).getString());
System.out.println(value instanceof UnicodeString);
}
}
}

}
}

}
70 changes: 70 additions & 0 deletions src/main/java/com/example/guestbook/SignGuestbookServlet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/**
* Copyright 2014-2015 Google Inc. All Rights Reserved.
*
* 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.
*/

//[START all]
package com.example.guestbook;

import com.google.appengine.api.datastore.DatastoreService;
import com.google.appengine.api.datastore.DatastoreServiceFactory;
import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;
import com.google.appengine.api.users.User;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;

import java.io.IOException;
import java.util.Date;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.googlecode.objectify.ObjectifyService;

/**
* Form Handling Servlet
* Most of the action for this sample is in webapp/guestbook.jsp, which displays the
* {@link Greeting}'s. This servlet has one method
* {@link #doPost(<#HttpServletRequest req#>, <#HttpServletResponse resp#>)} which takes the form
* data and saves it.
*/
public class SignGuestbookServlet extends HttpServlet {

// Process the http POST of the form
@Override
public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
Greeting greeting;

UserService userService = UserServiceFactory.getUserService();
User user = userService.getCurrentUser(); // Find out who the user is.

String guestbookName = req.getParameter("guestbookName");
String content = req.getParameter("content");
if (user != null) {
greeting = new Greeting(guestbookName, content, user.getUserId(), user.getEmail());
} else {
greeting = new Greeting(guestbookName, content);
}

// Use Objectify to save the greeting and now() is used to make the call synchronously as we
// will immediately get a new page using redirect and we want the data to be present.
ObjectifyService.ofy().save().entity(greeting).now();

resp.sendRedirect("/guestbook.jsp?guestbookName=" + guestbookName);
}
}
//[END all]
Loading

0 comments on commit 6272229

Please sign in to comment.