use of com.bluenimble.platform.json.JsonObject in project serverless by bluenimble.
the class SecurityUtils method tokenAndExpiration.
public static String[] tokenAndExpiration(Api api, JsonObject entity, Date now) throws ApiServiceExecutionException {
String thing = salt(api, entity);
JsonObject auth = Json.getObject(Json.getObject(Json.getObject(api.getSecurity(), Api.Spec.Security.Schemes), Schemes.Token), Api.Spec.Security.Auth);
if (auth == null) {
auth = Json.getObject(Json.getObject(Json.getObject(api.getSecurity(), Api.Spec.Security.Schemes), Schemes.Cookie), Api.Spec.Security.Auth);
}
String secretsName = Json.getString(auth, ApiSpace.Spec.secrets.class.getSimpleName(), ApiSpace.Secrets.Default);
// encrypt
JsonObject secrets;
try {
secrets = api.space().getSecrets(secretsName);
} catch (ApiManagementException e) {
throw new ApiServiceExecutionException(e.getMessage(), e);
}
if (secrets == null || !secrets.containsKey(ApiSpace.Spec.secrets.Key)) {
throw new ApiServiceExecutionException("space secrets '" + secretsName + "' not found").status(ApiResponse.SERVICE_UNAVAILABLE);
}
Crypto.Algorithm alg = null;
try {
alg = Crypto.Algorithm.valueOf(Json.getString(secrets, ApiSpace.Spec.secrets.Algorithm, Crypto.Algorithm.AES.name()).toUpperCase());
} catch (Exception ex) {
alg = Crypto.Algorithm.AES;
}
long expiresOn = now.getTime() + Json.getLong(secrets, ApiSpace.Spec.secrets.Age, 60) * 60 * 1000;
String toEncrypt = expiresOn + Lang.SPACE + thing;
try {
return new String[] { new String(Lang.encodeHex(Crypto.encrypt(toEncrypt.getBytes(), Json.getString(secrets, ApiSpace.Spec.secrets.Key), alg))), Lang.toUTC(new Date(expiresOn)) };
} catch (Exception ex) {
throw new ApiServiceExecutionException(ex.getMessage(), ex);
}
}
use of com.bluenimble.platform.json.JsonObject in project serverless by bluenimble.
the class OrientDatabase method describe.
@Override
public JsonObject describe() {
JsonObject describe = new JsonObject();
describe.set(Describe.Size, db.getSize());
Collection<OClass> entities = db.getMetadata().getSchema().getClasses();
if (entities == null || entities.isEmpty()) {
return describe;
}
JsonArray aEntities = new JsonArray();
describe.set(Describe.Entities, aEntities);
for (OClass entity : entities) {
if (SystemEntities.contains(entity.getName())) {
continue;
}
JsonObject oEntity = new JsonObject();
oEntity.set(Describe.Name, entity.getName());
oEntity.set(Describe.Count, entity.count());
aEntities.add(oEntity);
}
return describe;
}
use of com.bluenimble.platform.json.JsonObject in project serverless by bluenimble.
the class Create method main.
public static void main(String[] args) throws DatabaseException {
Database db = new DatabaseServer().get();
DatabaseObject employee = db.create("Employees");
JsonArray names = new JsonArray();
names.add(new JsonObject().set("number", "4098776623").set("weight", 40));
employee.set("name", "Simo");
employee.set("age", 34);
employee.set("active", true);
employee.set("salary", 43.98);
employee.set("names", names);
employee.save();
System.out.println(employee.toJson(null));
}
use of com.bluenimble.platform.json.JsonObject in project serverless by bluenimble.
the class CreateOne2One method main.
public static void main(String[] args) throws DatabaseException {
Database db = new DatabaseServer().get();
// create driver
DatabaseObject driver = db.create("Drivers");
driver.set("name", "One2One-New-1");
driver.set("info", new JsonObject().set("x", "40987").set("y", 76623));
driver.set("salary", 48.50);
// create car
DatabaseObject car = db.create("Cars");
car.set("model", "Honda");
car.set("year", "2040");
driver.set("car", car);
driver.save();
System.out.println(driver.toJson(null));
}
use of com.bluenimble.platform.json.JsonObject in project serverless by bluenimble.
the class ResourceTemplateLoader method sourceAt.
@Override
public TemplateSource sourceAt(String name) throws IOException {
JsonObject runtime = api.getRuntime();
String templatesPath = Json.getString(runtime, Templates, DefaultTemplatesPath);
if (templatesPath.startsWith(Lang.SLASH)) {
templatesPath = templatesPath.substring(1);
}
if (templatesPath.endsWith(Lang.SLASH)) {
templatesPath = templatesPath.substring(0, templatesPath.length() - 1);
}
String templateExt = Json.getString(runtime, TemplateExtension, DotHtml);
final String fileName = templatesPath + Lang.SLASH + name + templateExt;
ApiResource res;
try {
res = api.getResourcesManager().get(Lang.split(fileName, Lang.SLASH));
} catch (ApiResourcesManagerException e) {
throw new IOException(e.getMessage(), e);
}
final ApiResource resource = res;
return new TemplateSource() {
@Override
public long lastModified() {
return resource.timestamp().getTime();
}
@Override
public String filename() {
return fileName;
}
@Override
public String content() throws IOException {
InputStream is = null;
try {
is = resource.toInput();
return IOUtils.toString(is);
} finally {
IOUtils.closeQuietly(is);
}
}
};
}
Aggregations