Permalink
Browse files

Require user to be logged in so that save/load world functionality can

be provided with each saved world stored out with a combination of the
user's email address and the player-character's name.  (For example,
max@gustavus.edu:Frodo.)
  • Loading branch information...
1 parent 378c419 commit 32eaf7825a2b5dd71d6c73b9e9bec84a8ceea1cd @Max-Hailperin committed Apr 16, 2012
View

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -7,6 +7,7 @@
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;
+import com.google.apphosting.api.ApiProxy;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import edu.gac.mcs270.gack.shared.Persistence;
@@ -19,14 +20,14 @@
private static class SavedPlayer {
@SuppressWarnings("unused")
@PrimaryKey
- private String name;
+ private String emailAndName;
@Persistent(serialized = "true")
private Person player;
- public SavedPlayer(String name, Person player) {
+ public SavedPlayer(String emailAndName, Person player) {
super();
- this.name = name;
+ this.emailAndName = emailAndName;
this.player = player;
}
@@ -36,18 +37,34 @@ public Person getPlayer() {
}
public Person getPlayer(String name){
+ String emailAndName = getEmailAndName(name);
PersistenceManager persistenceManager = PMF.get().getPersistenceManager();
try{
- return persistenceManager.getObjectById(SavedPlayer.class, name).getPlayer();
+ return persistenceManager.getObjectById(SavedPlayer.class, emailAndName).getPlayer();
} catch(JDOObjectNotFoundException e){
return null;
}
}
public void savePlayer(Person player){
- SavedPlayer sp = new SavedPlayer(player.getName(), player);
+ String emailAndName = getEmailAndName(player.getName());
+ SavedPlayer sp = new SavedPlayer(emailAndName, player);
PMF.get().getPersistenceManager().makePersistent(sp);
}
+
+ private String getEmailAndName(String name){
+ // The test below just makes sure we didn't miss the lines in web.xml that
+ // ensure the user has to be logged in. If this exception is thrown, web.xml
+ // needs fixing.
+ if(!ApiProxy.getCurrentEnvironment().isLoggedIn()){
+ throw new IllegalStateException("not logged in");
+ }
+ // In the same way, ApiProxy.getCurrentEnvironment().isAdmin() could be used to
+ // determine whether the currently logged in user is known to AppEngine as an
+ // administrator of this application. I can't think of any reason to demonstrate
+ // thatin the Land of Gack.
+ return ApiProxy.getCurrentEnvironment().getEmail() + ":" + name;
+ }
public PersistenceImpl() {
super();
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
<application>gackgame</application>
- <version>2</version>
+ <version>3</version>
<!--
By default, App Engine sends requests serially to a given web server.
@@ -1,2 +1,4 @@
# Module gack
# RPC service class, partial path of RPC policy file
+edu.gac.mcs270.gack.shared.Persistence, 2F40089372A8BD37BE8E250A42059386.gwt.rpc
+edu.gac.mcs270.gack.shared.Loader, 217F298A506E85F8700D6206527E9DB3.gwt.rpc

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -31,4 +31,15 @@
<welcome-file>Gack.html</welcome-file>
</welcome-file-list>
+ <!-- Require the user to be logged in before accessing any page at all -->
+ <security-constraint>
+ <web-resource-collection>
+ <url-pattern>/*</url-pattern>
+ </web-resource-collection>
+ <auth-constraint>
+ <role-name>*</role-name>
+ </auth-constraint>
+ </security-constraint>
+
+
</web-app>
Oops, something went wrong.

0 comments on commit 32eaf78

Please sign in to comment.