List of usage examples for io.vertx.core.json JsonObject getJsonArray
public JsonArray getJsonArray(String key)
From source file:org.eclipse.hono.deviceregistry.FileBasedCredentialsService.java
License:Open Source License
private void parseCredentials(final JsonArray credentialsObject) { final AtomicInteger credentialsCount = new AtomicInteger(); log.debug("trying to load credentials for {} tenants", credentialsObject.size()); for (Object obj : credentialsObject) { JsonObject tenant = (JsonObject) obj; String tenantId = tenant.getString(FIELD_TENANT); Map<String, JsonArray> credentialsMap = new HashMap<>(); for (Object credentialsObj : tenant.getJsonArray(ARRAY_CREDENTIALS)) { JsonObject credentials = (JsonObject) credentialsObj; JsonArray authIdCredentials; if (credentialsMap.containsKey(credentials.getString(FIELD_AUTH_ID))) { authIdCredentials = credentialsMap.get(credentials.getString(FIELD_AUTH_ID)); } else { authIdCredentials = new JsonArray(); }//from www. j ava 2s . com authIdCredentials.add(credentials); credentialsMap.put(credentials.getString(FIELD_AUTH_ID), authIdCredentials); credentialsCount.incrementAndGet(); } credentials.put(tenantId, credentialsMap); } log.info("successfully loaded {} credentials from file [{}]", credentialsCount.get(), getConfig().getCredentialsFilename()); }
From source file:org.eclipse.hono.deviceregistry.FileBasedCredentialsService.java
License:Open Source License
private CredentialsResult<JsonObject> getCredentialsResult(final String tenantId, final String authId, final String type) { JsonObject data = getCredentials(tenantId, authId, type); if (data != null) { JsonObject resultPayload = getResultPayload(data.getString(FIELD_DEVICE_ID), data.getString(FIELD_TYPE), data.getString(FIELD_AUTH_ID), data.getBoolean(FIELD_ENABLED), data.getJsonArray(FIELD_SECRETS)); return CredentialsResult.from(HTTP_OK, resultPayload); } else {// w w w. jav a 2s .c om return CredentialsResult.from(HTTP_NOT_FOUND, (JsonObject) null); } }
From source file:org.eclipse.hono.deviceregistry.FileBasedRegistrationService.java
License:Open Source License
Future<Void> loadRegistrationData() { Future<Void> result = Future.future(); if (getConfig().getFilename() == null) { result.fail(new IllegalStateException("device identity filename is not set")); } else {//from ww w. j a va2 s . c o m final FileSystem fs = vertx.fileSystem(); log.debug("trying to load device registration information from file {}", getConfig().getFilename()); if (fs.existsBlocking(getConfig().getFilename())) { final AtomicInteger deviceCount = new AtomicInteger(); fs.readFile(getConfig().getFilename(), readAttempt -> { if (readAttempt.succeeded()) { JsonArray allObjects = new JsonArray(new String(readAttempt.result().getBytes())); for (Object obj : allObjects) { JsonObject tenant = (JsonObject) obj; String tenantId = tenant.getString(FIELD_TENANT); log.debug("loading devices for tenant [{}]", tenantId); Map<String, JsonObject> deviceMap = new HashMap<>(); for (Object deviceObj : tenant.getJsonArray(ARRAY_DEVICES)) { JsonObject device = (JsonObject) deviceObj; String deviceId = device.getString(FIELD_DEVICE_ID); log.debug("loading device [{}]", deviceId); deviceMap.put(deviceId, device.getJsonObject(FIELD_DATA)); deviceCount.incrementAndGet(); } identities.put(tenantId, deviceMap); } log.info("successfully loaded {} device identities from file [{}]", deviceCount.get(), getConfig().getFilename()); result.complete(); } else { log.warn("could not load device identities from file [{}]", getConfig().getFilename()); result.fail(readAttempt.cause()); } }); } else { log.debug("device identity file [{}] does not exist (yet)", getConfig().getFilename()); result.complete(); } } return result; }
From source file:org.eclipse.hono.service.auth.impl.FileBasedAuthenticationService.java
License:Open Source License
private Authorities getAuthorities(final JsonObject user) { AuthoritiesImpl result = new AuthoritiesImpl(); user.getJsonArray(FIELD_AUTHORITIES).forEach(obj -> { final String authority = (String) obj; Authorities roleAuthorities = roles.get(authority); if (roleAuthorities != null) { result.addAll(roleAuthorities); }//from w w w . j a v a2s . com }); return result; }
From source file:org.eclipse.hono.service.credentials.impl.FileBasedCredentialsService.java
License:Open Source License
protected void loadCredentialsData() { if (filename != null) { final FileSystem fs = vertx.fileSystem(); log.debug("trying to load credentials information from file {}", filename); if (fs.existsBlocking(filename)) { final AtomicInteger credentialsCount = new AtomicInteger(); fs.readFile(filename, readAttempt -> { if (readAttempt.succeeded()) { JsonArray allObjects = new JsonArray(new String(readAttempt.result().getBytes())); for (Object obj : allObjects) { JsonObject tenant = (JsonObject) obj; String tenantId = tenant.getString(FIELD_TENANT); Map<String, JsonArray> credentialsMap = new HashMap<>(); for (Object credentialsObj : tenant.getJsonArray(ARRAY_CREDENTIALS)) { JsonObject credentials = (JsonObject) credentialsObj; JsonArray authIdCredentials; if (credentialsMap.containsKey(credentials.getString(FIELD_AUTH_ID))) { authIdCredentials = credentialsMap.get(credentials.getString(FIELD_AUTH_ID)); } else { authIdCredentials = new JsonArray(); }//from w ww.j a va2 s.co m authIdCredentials.add(credentials); credentialsMap.put(credentials.getString(FIELD_AUTH_ID), authIdCredentials); credentialsCount.incrementAndGet(); } credentials.put(tenantId, credentialsMap); } log.info("successfully loaded {} credentials from file [{}]", credentialsCount.get(), filename); } else { log.warn("could not load credentials from file [{}]", filename, readAttempt.cause()); } }); } else { log.debug("credentials file {} does not exist (yet)", filename); } } }
From source file:org.eclipse.hono.service.credentials.impl.FileBasedCredentialsService.java
License:Open Source License
protected CredentialsResult getCredentialsResult(final String tenantId, final String authId, final String type) { JsonObject data = getCredentials(tenantId, authId, type); if (data != null) { JsonObject resultPayload = getResultPayload(data.getString(FIELD_DEVICE_ID), data.getString(FIELD_TYPE), data.getString(FIELD_AUTH_ID), data.getBoolean(FIELD_ENABLED), data.getJsonArray(FIELD_SECRETS)); return CredentialsResult.from(HTTP_OK, resultPayload); } else {//from w w w. j a va 2s .c om return CredentialsResult.from(HTTP_NOT_FOUND); } }
From source file:org.eclipse.hono.service.registration.impl.FileBasedRegistrationService.java
License:Open Source License
private void loadRegistrationData() { if (filename != null) { final FileSystem fs = vertx.fileSystem(); log.debug("trying to load device registration information from file {}", filename); if (fs.existsBlocking(filename)) { final AtomicInteger deviceCount = new AtomicInteger(); fs.readFile(filename, readAttempt -> { if (readAttempt.succeeded()) { JsonArray allObjects = new JsonArray(new String(readAttempt.result().getBytes())); for (Object obj : allObjects) { JsonObject tenant = (JsonObject) obj; String tenantId = tenant.getString(FIELD_TENANT); Map<String, JsonObject> deviceMap = new HashMap<>(); for (Object deviceObj : tenant.getJsonArray(ARRAY_DEVICES)) { JsonObject device = (JsonObject) deviceObj; deviceMap.put(device.getString(FIELD_HONO_ID), device.getJsonObject(FIELD_DATA)); deviceCount.incrementAndGet(); }//from www .jav a2 s. com identities.put(tenantId, deviceMap); } log.info("successfully loaded {} device identities from file [{}]", deviceCount.get(), filename); } else { log.warn("could not load device identities from file [{}]", filename, readAttempt.cause()); } }); } else { log.debug("device identity file {} does not exist (yet)", filename); } } }
From source file:org.eclipse.hono.service.tenant.BaseTenantService.java
License:Open Source License
/** * Add default values for optional fields that are not filled in the payload. * <p>// ww w.ja v a 2 s. c o m * Payload should be checked for validity first, there is no error handling inside this method anymore. * </p> * * @param checkedPayload The checked payload to add optional fields to. * @throws ClassCastException If the {@link TenantConstants#FIELD_ADAPTERS_TYPE} element is not a {@link JsonArray} * or the JsonArray contains elements that are not of type {@link JsonObject}. */ protected final void addNotPresentFieldsWithDefaultValuesForTenant(final JsonObject checkedPayload) { if (!checkedPayload.containsKey(TenantConstants.FIELD_ENABLED)) { log.trace("adding 'enabled' key to payload"); checkedPayload.put(TenantConstants.FIELD_ENABLED, Boolean.TRUE); } final JsonArray adapters = checkedPayload.getJsonArray(TenantConstants.FIELD_ADAPTERS); if (adapters != null) { adapters.forEach(elem -> addNotPresentFieldsWithDefaultValuesForAdapter((JsonObject) elem)); } }
From source file:org.entcore.archive.controllers.ArchiveController.java
License:Open Source License
@Override public void init(Vertx vertx, final JsonObject config, RouteMatcher rm, Map<String, fr.wseduc.webutils.security.SecuredAction> securedActions) { super.init(vertx, config, rm, securedActions); String exportPath = config.getString("export-path", System.getProperty("java.io.tmpdir")); Set<String> expectedExports = new HashSet<>(); final JsonArray e = config.getJsonArray("expected-exports"); for (Object o : e) { if (o instanceof String) { expectedExports.add((String) o); }// w w w. j a v a 2 s . co m } LocalMap<Object, Object> server = vertx.sharedData().getLocalMap("server"); Boolean cluster = (Boolean) server.get("cluster"); final Map<String, Long> userExport = MapFactory.getSyncClusterMap(Archive.ARCHIVES, vertx); EmailFactory emailFactory = new EmailFactory(vertx, config); EmailSender notification = config.getBoolean("send.export.email", false) ? emailFactory.getSender() : null; storage = new StorageFactory(vertx, config).getStorage(); exportService = new FileSystemExportService(vertx.fileSystem(), eb, exportPath, expectedExports, notification, storage, userExport, new TimelineHelper(vertx, eb, config)); eventStore = EventStoreFactory.getFactory().getEventStore(Archive.class.getSimpleName()); Long periodicUserClear = config.getLong("periodicUserClear"); if (periodicUserClear != null) { vertx.setPeriodic(periodicUserClear, new Handler<Long>() { @Override public void handle(Long event) { final long limit = System.currentTimeMillis() - config.getLong("userClearDelay", 3600000l); Set<Map.Entry<String, Long>> entries = new HashSet<>(userExport.entrySet()); for (Map.Entry<String, Long> e : entries) { if (e.getValue() == null || e.getValue() < limit) { userExport.remove(e.getKey()); } } } }); } }
From source file:org.entcore.auth.adapter.UserInfoAdapterV1_0Json.java
License:Open Source License
protected JsonObject getCommonFilteredInfos(JsonObject info, String clientId) { JsonObject filteredInfos = info.copy(); String type = Utils.getOrElse(types.get(info.getString("type", "")), ""); filteredInfos.put("type", type); filteredInfos.remove("cache"); if (filteredInfos.getString("level") == null) { filteredInfos.put("level", ""); } else if (filteredInfos.getString("level").contains("$")) { String[] level = filteredInfos.getString("level").split("\\$"); filteredInfos.put("level", level[level.length - 1]); }/*from ww w.j av a2 s. c o m*/ if (clientId != null && !clientId.trim().isEmpty()) { JsonArray classNames = filteredInfos.getJsonArray("classNames"); filteredInfos.remove("classNames"); JsonArray structureNames = filteredInfos.getJsonArray("structureNames"); filteredInfos.remove("structureNames"); filteredInfos.remove("federated"); if (classNames != null && classNames.size() > 0) { filteredInfos.put("classId", classNames.getString(0)); } if (structureNames != null && structureNames.size() > 0) { filteredInfos.put("schoolName", structureNames.getString(0)); } filteredInfos.remove("functions"); filteredInfos.remove("groupsIds"); filteredInfos.remove("structures"); filteredInfos.remove("classes"); filteredInfos.remove("apps"); filteredInfos.remove("authorizedActions"); filteredInfos.remove("children"); JsonArray authorizedActions = new fr.wseduc.webutils.collections.JsonArray(); for (Object o : info.getJsonArray("authorizedActions")) { JsonObject j = (JsonObject) o; String name = j.getString("name"); if (name != null && name.startsWith(clientId + "|")) { authorizedActions.add(j); } } if (authorizedActions.size() > 0) { filteredInfos.put("authorizedActions", authorizedActions); } } return filteredInfos; }