use of com.google.appengine.api.datastore.DatastoreService in project iosched by google.
the class ApiKeyInitializer method contextInitialized.
@Override
public void contextInitialized(ServletContextEvent event) {
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
Key key = KeyFactory.createKey(ENTITY_KIND, ENTITY_KEY);
Entity entity;
try {
entity = datastore.get(key);
} catch (EntityNotFoundException e) {
entity = new Entity(key);
// NOTE: it's not possible to change entities in the local server, so
// it will be necessary to hardcode the API key below if you are running
// it locally.
entity.setProperty(ACCESS_KEY_FIELD, API_KEY);
datastore.put(entity);
mLogger.severe("Created fake key. Please go to App Engine admin " + "console, change its value to your API Key (the entity " + "type is '" + ENTITY_KIND + "' and its field to be changed is '" + ACCESS_KEY_FIELD + "'), then restart the server!");
}
String accessKey = (String) entity.getProperty(ACCESS_KEY_FIELD);
event.getServletContext().setAttribute(ATTRIBUTE_ACCESS_KEY, accessKey);
}
use of com.google.appengine.api.datastore.DatastoreService in project spring-security by spring-projects.
the class GaeDatastoreUserRegistry method registerUser.
public void registerUser(GaeUser newUser) {
logger.debug("Attempting to create new user " + newUser);
Key key = KeyFactory.createKey(USER_TYPE, newUser.getUserId());
Entity user = new Entity(key);
user.setProperty(USER_EMAIL, newUser.getEmail());
user.setProperty(USER_NICKNAME, newUser.getNickname());
user.setProperty(USER_FORENAME, newUser.getForename());
user.setProperty(USER_SURNAME, newUser.getSurname());
user.setUnindexedProperty(USER_ENABLED, newUser.isEnabled());
Collection<AppRole> roles = newUser.getAuthorities();
long binaryAuthorities = 0;
for (AppRole r : roles) {
binaryAuthorities |= 1 << r.getBit();
}
user.setUnindexedProperty(USER_AUTHORITIES, binaryAuthorities);
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
datastore.put(user);
}
use of com.google.appengine.api.datastore.DatastoreService in project spring-security by spring-projects.
the class GaeDatastoreUserRegistry method findUser.
public GaeUser findUser(String userId) {
Key key = KeyFactory.createKey(USER_TYPE, userId);
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
try {
Entity user = datastore.get(key);
long binaryAuthorities = (Long) user.getProperty(USER_AUTHORITIES);
Set<AppRole> roles = EnumSet.noneOf(AppRole.class);
for (AppRole r : AppRole.values()) {
if ((binaryAuthorities & (1 << r.getBit())) != 0) {
roles.add(r);
}
}
GaeUser gaeUser = new GaeUser(user.getKey().getName(), (String) user.getProperty(USER_NICKNAME), (String) user.getProperty(USER_EMAIL), (String) user.getProperty(USER_FORENAME), (String) user.getProperty(USER_SURNAME), roles, (Boolean) user.getProperty(USER_ENABLED));
return gaeUser;
} catch (EntityNotFoundException e) {
logger.debug(userId + " not found in datastore");
return null;
}
}
use of com.google.appengine.api.datastore.DatastoreService in project spring-security by spring-projects.
the class GaeDatastoreUserRegistry method removeUser.
public void removeUser(String userId) {
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
Key key = KeyFactory.createKey(USER_TYPE, userId);
datastore.delete(key);
}
use of com.google.appengine.api.datastore.DatastoreService in project java-docs-samples by GoogleCloudPlatform.
the class RemoteApiExample method main.
public static void main(String[] args) throws IOException {
String serverString = args[0];
RemoteApiOptions options;
if (serverString.equals("localhost")) {
options = new RemoteApiOptions().server(serverString, 8080).useDevelopmentServerCredential();
} else {
options = new RemoteApiOptions().server(serverString, 443).useApplicationDefaultCredential();
}
RemoteApiInstaller installer = new RemoteApiInstaller();
installer.install(options);
try {
DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
System.out.println("Key of new entity is " + ds.put(new Entity("Hello Remote API!")));
} finally {
installer.uninstall();
}
}
Aggregations