Example usage for io.vertx.core.json JsonObject getJsonArray

List of usage examples for io.vertx.core.json JsonObject getJsonArray

Introduction

In this page you can find the example usage for io.vertx.core.json JsonObject getJsonArray.

Prototype

public JsonArray getJsonArray(String key, JsonArray def) 

Source Link

Document

Like #getJsonArray(String) but specifying a default value to return if there is no entry.

Usage

From source file:net.kuujo.vertigo.network.impl.ComponentConfigImpl.java

License:Apache License

@Override
@SuppressWarnings("unchecked")
public void update(JsonObject component) {
    if (this.name == null) {
        this.name = component.getString(COMPONENT_NAME, UUID.randomUUID().toString());
    }//from w  w w  . ja  va2 s  . c  om
    if (this.identifier == null) {
        this.identifier = component.getString(COMPONENT_IDENTIFIER);
        if (this.identifier == null) {
            throw new NetworkFormatException("Component " + this.name + " did not specify an identifier.");
        }
    }
    if (component.containsKey(COMPONENT_CONFIG)) {
        this.config = component.getJsonObject(COMPONENT_CONFIG);
    }
    if (component.containsKey(COMPONENT_WORKER)) {
        this.worker = component.getBoolean(COMPONENT_WORKER);
    }
    if (component.containsKey(COMPONENT_MULTI_THREADED)) {
        this.multiThreaded = component.getBoolean(COMPONENT_MULTI_THREADED);
    }
    if (component.containsKey(COMPONENT_STATEFUL)) {
        this.stateful = component.getBoolean(COMPONENT_STATEFUL);
    }
    if (component.containsKey(COMPONENT_REPLICAS)) {
        this.replicas = component.getInteger(COMPONENT_REPLICAS, 1);
    }
    if (component.containsKey(COMPONENT_RESOURCES)) {
        this.resources.addAll(component.getJsonArray(COMPONENT_RESOURCES, new JsonArray()).getList());
    }
    JsonObject inputs = component.getJsonObject(COMPONENT_INPUT);
    if (inputs == null) {
        inputs = new JsonObject();
    }
    if (this.input == null) {
        this.input = new InputConfigImpl(inputs).setComponent(this);
    } else {
        this.input.update(inputs);
    }
    JsonObject outputs = component.getJsonObject(COMPONENT_OUTPUT);
    if (outputs == null) {
        outputs = new JsonObject();
    }
    if (this.output == null) {
        this.output = new OutputConfigImpl(outputs).setComponent(this);
    } else {
        this.output.update(outputs);
    }
}

From source file:org.eclipse.hono.service.auth.impl.FileBasedAuthenticationService.java

License:Open Source License

private Authorities toAuthorities(final JsonArray authorities) {

    AuthoritiesImpl result = new AuthoritiesImpl();
    Objects.requireNonNull(authorities).stream().filter(obj -> obj instanceof JsonObject).forEach(obj -> {
        final JsonObject authSpec = (JsonObject) obj;
        final JsonArray activities = authSpec.getJsonArray(FIELD_ACTIVITIES, new JsonArray());
        final String resource = authSpec.getString(FIELD_RESOURCE);
        final String operation = authSpec.getString(FIELD_OPERATION);
        if (resource != null) {
            List<Activity> activityList = new ArrayList<>();
            activities.forEach(s -> {
                Activity act = Activity.valueOf((String) s);
                if (act != null) {
                    activityList.add(act);
                }/* w  w w. j  a va2  s  .c o  m*/
            });
            result.addResource(resource, activityList.toArray(new Activity[activityList.size()]));
        } else if (operation != null) {
            String[] parts = operation.split(":", 2);
            if (parts.length == 2) {
                result.addOperation(parts[0], parts[1]);
            } else {
                log.debug("ignoring malformed operation spec [{}], operation name missing", operation);
            }
        } else {
            throw new IllegalArgumentException("malformed authorities");
        }
    });
    return result;
}

From source file:org.eclipse.hono.service.auth.impl.FileBasedAuthenticationService.java

License:Open Source License

private boolean hasAuthority(final JsonObject user, final String role) {
    return user.getJsonArray(FIELD_AUTHORITIES, new JsonArray()).contains(role);
}

From source file:org.entcore.auth.controllers.AuthController.java

License:Open Source License

@Override
public void init(Vertx vertx, JsonObject config, RouteMatcher rm,
        Map<String, fr.wseduc.webutils.security.SecuredAction> securedActions) {
    super.init(vertx, config, rm, securedActions);
    JsonObject oic = config.getJsonObject("openid-connect");
    OpenIdConnectService openIdConnectService = (oic != null)
            ? new DefaultOpendIdConnectService(oic.getString("iss"), vertx, oic.getString("keys"))
            : null;//  w ww  .j a  v  a  2s  .  c o  m
    checkFederatedLogin = config.getBoolean("check-federated-login", false);
    oauthDataFactory = new OAuthDataHandlerFactory(Neo4j.getInstance(), MongoDb.getInstance(),
            openIdConnectService, checkFederatedLogin);
    GrantHandlerProvider grantHandlerProvider = new DefaultGrantHandlerProvider();
    ClientCredentialFetcher clientCredentialFetcher = new ClientCredentialFetcherImpl();
    token = new Token();
    token.setDataHandlerFactory(oauthDataFactory);
    token.setGrantHandlerProvider(grantHandlerProvider);
    token.setClientCredentialFetcher(clientCredentialFetcher);
    AccessTokenFetcherProvider accessTokenFetcherProvider = new DefaultAccessTokenFetcherProvider();
    protectedResource = new ProtectedResource();
    protectedResource.setDataHandlerFactory(oauthDataFactory);
    protectedResource.setAccessTokenFetcherProvider(accessTokenFetcherProvider);
    passwordPattern = Pattern.compile(config.getString("passwordRegex", ".{8}.*"));
    LocalMap<Object, Object> server = vertx.sharedData().getLocalMap("server");
    if (server != null && server.get("smsProvider") != null)
        smsProvider = (String) server.get("smsProvider");
    slo = config.getBoolean("slo", false);
    //      if (server != null) {
    //         Boolean cluster = (Boolean) server.get("cluster");
    //         if (Boolean.TRUE.equals(cluster)) {
    //            ClusterManager cm = ((VertxInternal) vertx).clusterManager();
    //            invalidEmails = cm.getSyncMap("invalidEmails");
    //         } else {
    //            invalidEmails = vertx.sharedData().getMap("invalidEmails");
    //         }
    //      } else {
    invalidEmails = MapFactory.getSyncClusterMap("invalidEmails", vertx);
    internalAddress = config.getJsonArray("internalAddress",
            new fr.wseduc.webutils.collections.JsonArray().add("localhost").add("127.0.0.1")).getList();
}

From source file:org.entcore.auth.oauth.OAuthDataHandler.java

License:Open Source License

public void createOrUpdateAuthInfo(final String clientId, final String userId, final String scope,
        final String redirectUri, final Handler<AuthInfo> handler) {
    if (clientId != null && userId != null && !clientId.trim().isEmpty() && !userId.trim().isEmpty()) {
        if (scope != null && !scope.trim().isEmpty()) {
            String query = "MATCH (app:`Application` {name:{clientId}}) RETURN app.scope as scope";
            neo.execute(query, new JsonObject().put("clientId", clientId),
                    new io.vertx.core.Handler<Message<JsonObject>>() {
                        @Override
                        public void handle(Message<JsonObject> res) {
                            JsonArray r = res.body().getJsonArray("result");

                            if ("ok".equals(res.body().getString("status")) && r != null && r.size() == 1) {
                                JsonObject j = r.getJsonObject(0);
                                if (j != null && j
                                        .getJsonArray("scope", new fr.wseduc.webutils.collections.JsonArray())
                                        .getList().containsAll(Arrays.asList(scope.split("\\s")))) {
                                    createAuthInfo(clientId, userId, scope, redirectUri, handler);
                                } else {
                                    handler.handle(null);
                                }/*from w  w  w .  j a v a2  s. c  o  m*/
                            } else {
                                handler.handle(null);
                            }
                        }
                    });
        } else {
            createAuthInfo(clientId, userId, scope, redirectUri, handler);
        }
    } else {
        handler.handle(null);
    }
}

From source file:org.entcore.blog.services.impl.DefaultPostService.java

License:Open Source License

@Override
public void listComment(String blogId, String postId, final UserInfos user,
        final Handler<Either<String, JsonArray>> result) {
    final QueryBuilder query = QueryBuilder.start("_id").is(postId).put("blog.$id").is(blogId);
    JsonObject keys = new JsonObject().put("comments", 1).put("blog", 1);
    JsonArray fetch = new JsonArray().add("blog");
    mongo.findOne(POST_COLLECTION, MongoQueryBuilder.build(query), keys, fetch,
            new Handler<Message<JsonObject>>() {
                @Override// w  ww.ja  v  a2 s  .c  o  m
                public void handle(Message<JsonObject> event) {
                    JsonArray comments = new JsonArray();
                    if ("ok".equals(event.body().getString("status"))
                            && event.body().getJsonObject("result", new JsonObject()).size() > 0) {
                        JsonObject res = event.body().getJsonObject("result");
                        boolean userIsManager = userIsManager(user, res.getJsonObject("blog"));
                        for (Object o : res.getJsonArray("comments", new JsonArray())) {
                            if (!(o instanceof JsonObject))
                                continue;
                            JsonObject j = (JsonObject) o;
                            if (userIsManager || StateType.PUBLISHED.name().equals(j.getString("state"))
                                    || user.getUserId().equals(
                                            j.getJsonObject("author", new JsonObject()).getString("userId"))) {
                                comments.add(j);
                            }
                        }
                    }
                    result.handle(new Either.Right<String, JsonArray>(comments));
                }
            });
}

From source file:org.entcore.cas.data.EntCoreDataHandlerFactory.java

License:Open Source License

public EntCoreDataHandlerFactory(EventBus eb, JsonObject conf) {
    this.eb = eb;

    JsonArray confServices = conf.getJsonArray(CONF_SERVICES, new fr.wseduc.webutils.collections.JsonArray());
    for (Object confObject : confServices) {
        try {// w  ww. j ava2s. c o m
            Map<String, Object> confService = ((JsonObject) confObject).getMap();
            String className = String.valueOf(confService.get(CONF_SERVICE_CLASS));
            if (className != null) {
                RegisteredService service = (RegisteredService) Class.forName(className).newInstance();
                service.configure(eb, confService);
                services.add(service);
            }
        } catch (PatternSyntaxException pe) {
            log.error("Invalid Authorized Service pattern", pe);
        } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
            log.error("Failed to instantiate Service", e);
        }
    }
}

From source file:org.entcore.cas.services.BRNERegisteredService.java

License:Open Source License

@Override
protected void prepareUser(User user, String userId, String service, JsonObject data) {
    //return the first uai as principalAttributeName
    for (Object s : data.getJsonArray("structureNodes", new fr.wseduc.webutils.collections.JsonArray())) {
        if (s == null || !(s instanceof JsonObject))
            continue;
        JsonObject structure = (JsonObject) s;
        String uai = structure.getString("UAI", "");
        if (!uai.isEmpty()) {
            user.setUser(uai);//  w w  w .  jav  a2  s  . c  om
            break;
        }
    }

    user.setAttributes(new HashMap<String, String>());

    // Profile
    JsonArray profiles = data.getJsonArray("type", new fr.wseduc.webutils.collections.JsonArray());
    if (profiles.contains("Teacher")) {
        user.getAttributes().put(PROFIL, "National_3");
    } else if (profiles.contains("Student")) {
        user.getAttributes().put(PROFIL, "National_1");
    }
}

From source file:org.entcore.cas.services.CIDJRegisteredService.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 w ww.  j  a v  a 2s  .  c  o  m*/

        // Uid
        if (data.containsKey("externalId")) {
            additionnalAttributes.add(createTextElement(CIDJ_ID, data.getString("externalId"), doc));
        }

        // Structures
        for (Object o : data.getJsonArray("structures", new fr.wseduc.webutils.collections.JsonArray())
                .getList()) {
            if (o == null || !(o instanceof JsonObject))
                continue;
            JsonObject structure = (JsonObject) o;
            if (structure.containsKey("UAI")) {
                additionnalAttributes
                        .add(createTextElement(CIDJ_STRUCTURE_CODERNE, structure.getString("UAI"), doc));
            }
        }

    } catch (Exception e) {
        log.error("Failed to transform User for CIDJ", e);
    }
}

From source file:org.entcore.cas.services.EducagriRegisteredService.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 {//  w w  w .  j a  v a  2s .  c o  m
        //uid
        if (data.containsKey("externalId")) {
            additionnalAttributes.add(createTextElement(EA_ID, data.getString("externalId"), doc));
        }

        // Structures
        for (Object o : data.getJsonArray("structures", new fr.wseduc.webutils.collections.JsonArray())
                .getList()) {
            if (o == null || !(o instanceof JsonObject))
                continue;
            JsonObject structure = (JsonObject) o;
            if (structure.containsKey("UAI")) {
                additionnalAttributes
                        .add(createTextElement(EA_STRUCTURE_UAI, structure.getString("UAI").toString(), doc));
            }
        }

        // Profile
        switch (data.getString("type")) {
        case "Student":
            additionnalAttributes.add(createTextElement(EA_PROFILES, "National_1", doc));
            break;
        case "Teacher":
            additionnalAttributes.add(createTextElement(EA_PROFILES, "National_3", doc));
            break;
        case "Personnel":
            additionnalAttributes.add(createTextElement(EA_PROFILES, "National_4", doc));
            break;
        }
    } catch (Exception e) {
        log.error("Failed to transform User for Educagri", e);
    }
}