@@ -0,0 +1,1909 @@
+package com.google.sps.authentication;%0A%0Aimport java.io.IOException;%0Aimport java.util.List;%0Aimport java.util.Objects;%0A%0Aimport com.google.appengine.api.datastore.DatastoreService;%0Aimport com.google.appengine.api.datastore.DatastoreServiceFactory;%0Aimport com.google.appengine.api.datastore.FetchOptions;%0Aimport com.google.appengine.api.datastore.Key;%0Aimport com.google.appengine.api.datastore.KeyFactory;%0Aimport com.google.appengine.api.datastore.PreparedQuery;%0Aimport com.google.appengine.api.datastore.Query;%0Aimport com.google.appengine.api.datastore.Query.FilterOperator;%0Aimport com.google.firebase.auth.FirebaseAuth;%0Aimport com.google.firebase.auth.FirebaseAuthException;%0Aimport com.google.firebase.auth.FirebaseToken;%0Aimport com.google.sps.firebase.FirebaseAppManager;%0Aimport com.google.appengine.api.datastore.Query.FilterPredicate;%0A%0Apublic class Authenticator %7B%0A  private FirebaseAuth auth;%0A  private DatastoreService datastore;%0A%0A  public Authenticator() throws IOException %7B%0A    this(FirebaseAuth.getInstance(FirebaseAppManager.getApp()));%0A  %7D%0A%0A  protected Authenticator(FirebaseAuth auth) %7B%0A    this.auth = Objects.requireNonNull(auth);%0A    datastore = DatastoreServiceFactory.getDatastoreService();%0A  %7D%0A%0A  public boolean verifyTaOrOwner(String idToken, Key classKey) %7B%0A    try %7B%0A      FirebaseToken tok = auth.verifyIdToken(idToken);%0A      PreparedQuery q = datastore.prepare(new Query(%22User%22).setFilter(%0A        new FilterPredicate(%22userEmail%22, FilterOperator.EQUAL, tok.getEmail())%0A      ));%0A%0A      if(q.countEntities(FetchOptions.Builder.withLimit(1)) %3E 0) %7B%0A        return ((List%3CKey%3E) q.asSingleEntity().getProperty(%22taClasses%22)).contains(classKey) %7C%7C%0A               ((List%3CKey%3E) q.asSingleEntity().getProperty(%22ownedClasses%22)).contains(classKey);%0A      %7D else %7B%0A        return false;%0A      %7D%0A    %7D catch (FirebaseAuthException %7C IllegalArgumentException e) %7B%0A      return false;%0A    %7D%0A    %0A  %7D %0A%7D

Add authenticator class to handle servlet authentication.