List of usage examples for io.vertx.core.json JsonObject getJsonArray
public JsonArray getJsonArray(String key)
From source file:org.entcore.auth.Auth.java
License:Open Source License
@Override public void start() throws Exception { final EventBus eb = getEventBus(vertx); super.start(); setDefaultResourceFilter(new AuthResourcesProvider(new Neo(vertx, eb, null))); final UserAuthAccount userAuthAccount = new DefaultUserAuthAccount(vertx, config); final EventStore eventStore = EventStoreFactory.getFactory().getEventStore(Auth.class.getSimpleName()); AuthController authController = new AuthController(); authController.setEventStore(eventStore); authController.setUserAuthAccount(userAuthAccount); addController(authController);//from w w w .j ava2 s .co m final ConfigurationController configurationController = new ConfigurationController(); configurationController.setConfigurationService(new DefaultConfigurationService()); addController(configurationController); final String samlMetadataFolder = config.getString("saml-metadata-folder"); if (samlMetadataFolder != null && !samlMetadataFolder.trim().isEmpty()) { vertx.fileSystem().readDir(samlMetadataFolder, new Handler<AsyncResult<List<String>>>() { @Override public void handle(AsyncResult<List<String>> event) { if (event.succeeded() && event.result().size() > 0) { try { SamlController samlController = new SamlController(); JsonObject conf = config; vertx.deployVerticle(SamlValidator.class, new DeploymentOptions().setConfig(conf).setWorker(true)); samlController.setEventStore(eventStore); samlController.setUserAuthAccount(userAuthAccount); samlController.setServiceProviderFactory(new DefaultServiceProviderFactory( config.getJsonObject("saml-services-providers"))); samlController .setSignKey((String) vertx.sharedData().getLocalMap("server").get("signKey")); samlController.setSamlWayfParams(config.getJsonObject("saml-wayf")); samlController.setIgnoreCallBackPattern(config.getString("ignoreCallBackPattern")); addController(samlController); LocalMap<Object, Object> server = vertx.sharedData().getLocalMap("server"); if (server != null) { String loginUri = config.getString("loginUri"); String callbackParam = config.getString("callbackParam"); if (loginUri != null && !loginUri.trim().isEmpty()) { server.putIfAbsent("loginUri", loginUri); } if (callbackParam != null && !callbackParam.trim().isEmpty()) { server.putIfAbsent("callbackParam", callbackParam); } final JsonObject authLocations = config.getJsonObject("authLocations"); if (authLocations != null && authLocations.size() > 0) { server.putIfAbsent("authLocations", authLocations.encode()); } } } catch (ConfigurationException e) { log.error("Saml loading error.", e); } } } }); } final JsonObject openidFederate = config.getJsonObject("openid-federate"); final JsonObject openidConnect = config.getJsonObject("openid-connect"); final OpenIdConnectController openIdConnectController; if (openidFederate != null || openidConnect != null) { openIdConnectController = new OpenIdConnectController(); addController(openIdConnectController); } else { openIdConnectController = null; } if (openidConnect != null) { final String certsPath = openidConnect.getString("certs"); if (isNotEmpty(certsPath)) { JWT.listCertificates(vertx, certsPath, new Handler<JsonObject>() { @Override public void handle(JsonObject certs) { openIdConnectController.setCertificates(certs); } }); } } if (openidFederate != null) { openIdConnectController.setEventStore(eventStore); openIdConnectController.setUserAuthAccount(userAuthAccount); openIdConnectController.setSignKey((String) vertx.sharedData().getLocalMap("server").get("signKey")); openIdConnectController.setOpenIdConnectServiceProviderFactory( new DefaultOpenIdServiceProviderFactory(vertx, openidFederate.getJsonObject("domains"))); openIdConnectController.setSubMapping(openidFederate.getBoolean("authorizeSubMapping", false)); final JsonArray authorizedHostsLogin = openidFederate.getJsonArray("authorizedHostsLogin"); if (authorizedHostsLogin != null && authorizedHostsLogin.size() > 0) { authController.setAuthorizedHostsLogin(authorizedHostsLogin); } } }
From source file:org.entcore.auth.controllers.SamlController.java
License:Open Source License
@Get("/saml/wayf") public void wayf(HttpServerRequest request) { if (samlWayfParams != null) { if (samlWayfMustacheFormat == null) { final JsonArray wmf = new fr.wseduc.webutils.collections.JsonArray(); for (String attr : samlWayfParams.fieldNames()) { JsonObject i = samlWayfParams.getJsonObject(attr); if (i == null) continue; final String acs = i.getString("acs"); if (isEmpty(acs)) continue; URI uri;/*from ww w . ja v a 2 s.c om*/ try { uri = new URI(acs); } catch (URISyntaxException e) { log.error("Invalid acs URI", e); continue; } JsonObject o = new JsonObject().put("name", attr).put("uri", uri.getScheme() + "://" + uri.getHost() + (attr.startsWith("login") ? "/auth/login" : "/auth/saml/authn/" + attr)); wmf.add(o); } samlWayfMustacheFormat = new JsonObject().put("providers", wmf); } String callBack = request.params().get("callBack"); final JsonObject swmf; if (isNotEmpty(callBack) && (ignoreCallBackPattern == null || !callBack.matches(ignoreCallBackPattern))) { try { callBack = URLEncoder.encode(callBack, "UTF-8"); } catch (UnsupportedEncodingException e) { log.error("Error encode wayf callback.", e); } swmf = samlWayfMustacheFormat.copy(); for (Object o : swmf.getJsonArray("providers")) { if (!(o instanceof JsonObject)) continue; final String uri = ((JsonObject) o).getString("uri"); if (isNotEmpty(uri) && !uri.contains("callBack")) { ((JsonObject) o).put("uri", uri + (uri.contains("?") ? "&" : "?") + "callBack=" + callBack); } } } else { swmf = samlWayfMustacheFormat; } renderView(request, swmf, "wayf.html", null); } else { request.response().setStatusCode(401).setStatusMessage("Unauthorized") .putHeader("content-type", "text/html").end(DefaultPages.UNAUTHORIZED.getPage()); } }
From source file:org.entcore.auth.services.impl.FrEduVecteurService.java
License:Open Source License
public void getVectors(final String userId, final Handler<Either<String, JsonArray>> handler) { String queryGetUserProfile = "MATCH (u:User) WHERE u.id = {userId} RETURN u.profiles"; neo4j.execute(queryGetUserProfile, new JsonObject().put("userId", userId), Neo4jResult.validUniqueResultHandler(new Handler<Either<String, JsonObject>>() { @Override/* w w w. j a va2 s . c o m*/ public void handle(final Either<String, JsonObject> event) { if (event.isRight()) { JsonObject value = event.right().getValue(); if (value == null) { handler.handle(new Either.Left<String, JsonArray>("error : user not found")); } else { JsonArray profiles = value.getJsonArray("u.profiles"); if (profiles != null && profiles.size() > 0) { if (profiles.contains("Student")) { // Get student vectors for saml response : "4|"+u.lastName+"|"+u.firstName+"|"+u.externalId+"|"+s.UAI String query = "MATCH u-[:IN]->()-[:DEPENDS]->(s:Structure) " + "WHERE u.id = {userId} " + "RETURN DISTINCT '4|'+u.lastName+'|'+u.firstName+'|'+u.attachmentId+'|'+s.UAI as FrEduVecteur"; neo4j.execute(query, new JsonObject().put("userId", userId), validResultHandler(handler)); } else if (profiles.contains("Relative")) { // Get parent vectors for saml response : '2|'+u.lastName+'|'+u.firstName+'|'+ child.externalId+'|'+s.UAI" String query = "MATCH (child: User)-[:RELATED]->u-[:IN]->()-[:DEPENDS]->(s:Structure) " + "WHERE u.id = {userId} " + "RETURN DISTINCT '2|'+u.lastName+'|'+u.firstName+'|'+ child.attachmentId+'|'+s.UAI as FrEduVecteur"; neo4j.execute(query, new JsonObject().put("userId", userId), validResultHandler(handler)); } else { // We return null for others profiles handler.handle( new Either.Left<String, JsonArray>("error : profil not supported")); } } } } else { handler.handle(new Either.Left<String, JsonArray>("error : user or profile not found")); } } })); }
From source file:org.entcore.auth.users.DefaultUserAuthAccount.java
License:Open Source License
public DefaultUserAuthAccount(Vertx vertx, JsonObject config) { EventBus eb = Server.getEventBus(vertx); this.neo = new Neo(vertx, eb, null); this.vertx = vertx; this.config = config; EmailFactory emailFactory = new EmailFactory(vertx, config); notification = emailFactory.getSender(); render = new Renders(vertx, config); LocalMap<Object, Object> server = vertx.sharedData().getLocalMap("server"); if (server != null && server.get("smsProvider") != null) { smsProvider = (String) server.get("smsProvider"); final String node = (String) server.get("node"); smsAddress = (node != null ? node : "") + "entcore.sms"; } else {/*from w w w.j a v a 2 s.co m*/ smsAddress = "entcore.sms"; } this.allowActivateDuplicateProfiles = getOrElse(config.getJsonArray("allow-activate-duplicate"), new JsonArray().add("Relative")); }
From source file:org.entcore.blog.services.impl.DefaultBlogTimelineService.java
License:Open Source License
private void findRecipiants(String collection, QueryBuilder query, JsonObject keys, final JsonArray fetch, final String filterRights, final UserInfos user, final Handler<Map<String, Object>> handler) { mongo.findOne(collection, MongoQueryBuilder.build(query), keys, fetch, new Handler<Message<JsonObject>>() { @Override//from w w w . ja v a 2 s . c o m public void handle(Message<JsonObject> event) { if ("ok".equals(event.body().getString("status"))) { final JsonObject blog = event.body().getJsonObject("result", new JsonObject()); JsonArray shared; if (fetch == null) { shared = blog.getJsonArray("shared"); } else { shared = blog.getJsonObject("blog", new JsonObject()).getJsonArray("shared"); } if (shared != null) { shared.add(blog.getJsonObject("blog", new JsonObject()).getJsonObject("author")); //Allows owner to get notified for contributors posts List<String> shareIds = getSharedIds(shared, filterRights); if (!shareIds.isEmpty()) { Map<String, Object> params = new HashMap<>(); params.put("userId", user.getUserId()); neo.send(neoQuery(shareIds), params, new Handler<Message<JsonObject>>() { @Override public void handle(Message<JsonObject> res) { if ("ok".equals(res.body().getString("status"))) { JsonObject r = res.body().getJsonObject("result"); List<String> recipients = new ArrayList<>(); for (String attr : r.fieldNames()) { String id = r.getJsonObject(attr).getString("id"); if (id != null) { recipients.add(id); } } Map<String, Object> t = new HashMap<>(); t.put("recipients", recipients); t.put("blog", blog); handler.handle(t); } else { handler.handle(null); } } }); } else { handler.handle(null); } } else { handler.handle(null); } } else { handler.handle(null); } } }); }
From source file:org.entcore.blog.services.impl.DefaultPostService.java
License:Open Source License
private boolean userIsManager(UserInfos user, JsonObject res) { if (res != null && res.getJsonArray("shared") != null) { for (Object o : res.getJsonArray("shared")) { if (!(o instanceof JsonObject)) continue; JsonObject json = (JsonObject) o; return json != null && json.getBoolean("manager", false) && (user.getUserId().equals(json.getString("userId")) || user.getGroupsIds().contains(json.getString("groupId"))); }// ww w . j a v a2 s. c om } return false; }
From source file:org.entcore.cas.controllers.ConfigurationController.java
License:Open Source License
public void loadPatterns() { eb.send("wse.app.registry.bus", new JsonObject().put("action", "list-cas-connectors"), handlerToAsyncHandler(new Handler<Message<JsonObject>>() { @Override//w w w .ja v a2 s .co m public void handle(Message<JsonObject> event) { if ("ok".equals(event.body().getString("status"))) { services.cleanPatterns(); JsonArray externalApps = event.body().getJsonArray("result"); for (Object o : externalApps) { if (!(o instanceof JsonObject)) continue; JsonObject j = (JsonObject) o; String service = j.getString("service"); JsonArray patterns = j.getJsonArray("patterns"); if (service != null && !service.trim().isEmpty() && patterns != null && patterns.size() > 0) { services.addPatterns(service, Arrays.copyOf(patterns.getList().toArray(), patterns.size(), String[].class)); } } } else { log.error(event.body().getString("message")); } } })); }
From source file:org.entcore.cas.services.EnglishAttackRegisteredService.java
License:Open Source License
private void addStringArray(String casLabel, String entLabel, String entLabel2, JsonObject data, Document doc, List<Element> additionalAttributes, Mapper<String, String> mapper) { Element root = createElement(casLabel + "s", doc); if (data.containsKey(entLabel)) { for (Object item : data.getJsonArray(entLabel)) { if (item.getClass().getName().equalsIgnoreCase(JsonObject.class.getName())) { root.appendChild(createTextElement(casLabel, ((JsonObject) item).getString(entLabel2), doc)); } else { root.appendChild(createTextElement(casLabel, mapper.map((String) item), doc)); }/* w w w . ja va 2 s . co m*/ } } additionalAttributes.add(root); }
From source file:org.entcore.cas.services.GRRRegisteredService.java
License:Open Source License
@Override protected void prepareUserCas20(User user, String userId, String service, JsonObject data, Document doc, List<Element> additionnalAttributes) { user.setUser(data.getString(principalAttributeName)); try {//from ww w .ja v a 2 s. com additionnalAttributes.add(createTextElement("user_nom_ldap", data.getString("lastName"), doc)); additionnalAttributes.add(createTextElement("user_prenom_ldap", data.getString("firstName"), doc)); additionnalAttributes.add(createTextElement("user_mail_ldap", data.getString("email"), doc)); // Profile if (data.getJsonArray("type") != null && data.getJsonArray("type").size() > 0) { additionnalAttributes.add( createTextElement("user_code_fonction_ldap", data.getJsonArray("type").getString(0), doc)); additionnalAttributes.add(createTextElement("user_libelle_fonction_ldap", data.getJsonArray("type").getString(0), doc)); } } catch (Exception e) { log.error("Failed to transform User for GRR CAS extension", e); } }
From source file:org.entcore.cas.services.KneRegisteredService.java
License:Open Source License
private void addArray(String casLabel, String entLabel, JsonObject data, Document doc, List<Element> additionalAttributes, Mapper<String, String> mapper) { Element root = createElement(casLabel + "s", doc); if (data.containsKey(entLabel)) { for (Object item : data.getJsonArray(entLabel)) { root.appendChild(createTextElement(casLabel, mapper.map((String) item), doc)); }/*from w w w . ja va 2 s . c o m*/ } additionalAttributes.add(root); }