List of usage examples for io.vertx.core.json JsonObject JsonObject
public JsonObject()
From source file:imbrobits.loosh.handler.TodoistApiService.java
License:Open Source License
@Override public Handler<RoutingContext> authenticate() { // This handler will be called for every request return routingContext -> { String authorizeUrl = auth .authorizeURL(new JsonObject().put("redirect_uri", "http://localhost:8080/callback/todoist") .put("scope", "data:read_write,data:delete").put("state", "3(#0/!~")); HttpServerResponse response = routingContext.request().response(); response.putHeader("Location", authorizeUrl).setStatusCode(302).end(); };/*from w w w . j a v a2 s . c o m*/ }
From source file:imbrobits.loosh.handler.TodoistApiService.java
License:Open Source License
@Override public Handler<RoutingContext> callback() { return routingContext -> { String code = routingContext.request().getParam("code"); auth.getToken(new JsonObject().put("client_id", appConfig.getString(Config.TODOIST_CLIENT_ID)) .put("client_secret", appConfig.getString(Config.TODOIST_CLIENT_SECRET)) .put("redirect_uri", "http://localhost:8080").put("code", code), res -> { if (res.failed()) { LOGGER.error("[OAuth2] Fail to get token:" + res.cause().getMessage()); } else { accessToken = res.result(); getProjects(null); }//from ww w . ja v a 2 s.com }); routingContext.response().write("Hello").end(); }; }
From source file:imbrobits.loosh.handler.TodoistApiService.java
License:Open Source License
@Override public void getProjects(Action1<List<Project>> callback) { auth.api(HttpMethod.POST, "/API/v7/sync", new JsonObject().put("token", accessToken.principal().getString("access_token")) .put("sync_token", "*").put("resource_types", "[\"all\"]"), event -> {/*w w w.j av a 2 s. c om*/ event.result(); // TODO mapping result to List<Project> callback.call(new ArrayList<Project>()); }); }
From source file:io.andromeda.logconsumer.MongoWriter.java
License:Apache License
@Override public void start() throws Exception { LOGGER.info("ConsoleWriter Verticle starting"); mongo = MongoClient.createShared(new Vertx(vertx), config().getJsonObject("mongoConfig")); Observable.from(config().getJsonArray("files")).map(el -> (String) el) .flatMap(path -> MessageConsumer.<String>create(vertx, rec -> rec.getName().equals(path))) .flatMap(el -> nextId().map(_id -> new JsonObject().put("_id", _id).put("i", el))) .flatMap(el -> mongo.saveObservable(today, el)).subscribe(logSuccess, logError); }
From source file:io.apiman.gateway.engine.vertx.polling.fetchers.auth.AbstractOAuth2Base.java
License:Apache License
protected static JsonObject mapToJson(Map<String, String> map) { JsonObject root = new JsonObject(); for (Entry<String, String> entry : map.entrySet()) { String[] split = StringUtils.split(entry.getKey(), '.'); ArrayDeque<String> dq = new ArrayDeque<>(Arrays.asList(split)); createOrDescend(root, dq, entry.getValue()); }//from w ww.j ava 2 s . co m return root; }
From source file:io.apiman.gateway.engine.vertx.polling.fetchers.auth.AbstractOAuth2Base.java
License:Apache License
protected static void createOrDescend(JsonObject root, Deque<String> keyPath, String value) { // If there are still key-path elements remaining to traverse. if (keyPath.size() > 1) { // If there's no object already at this key-path create a new JsonObject. if (root.getJsonObject(keyPath.peek()) == null) { JsonObject newJson = new JsonObject(); String val = keyPath.pop(); root.put(val, newJson); createOrDescend(newJson, keyPath, value); } else { // If there's already an existing object on key-path, grab it and traverse. createOrDescend(root.getJsonObject(keyPath.pop()), keyPath, value); }/*from ww w. j a v a2 s . c o m*/ } else { // Set the value. Boolean boolObj = BooleanUtils.toBooleanObject(value); if (boolObj != null) { root.put(keyPath.pop(), boolObj); } else if (StringUtils.isNumeric(value)) { root.put(keyPath.pop(), Long.parseLong(value)); } else { root.put(keyPath.pop(), value); } } }
From source file:io.apiman.gateway.engine.vertx.polling.fetchers.auth.KeycloakOAuth2.java
License:Apache License
@Override public Authenticator authenticate(Vertx vertx, Map<String, String> config, MultiMap headerMap, Handler<AsyncResult<Void>> resultHandler) { OAuth2FlowType flowType = getFlowType(config.get("flowType")); JsonObject params = new JsonObject(); if (config.get("username") != null) { params.put("username", config.get("username")); }/* ww w .j a va 2 s.c o m*/ if (config.get("password") != null) { params.put("password", config.get("password")); } OAuth2Auth oauth2 = KeycloakAuth.create(vertx, flowType, mapToJson(config)); oauth2.getToken(params, tokenResult -> { if (tokenResult.succeeded()) { log.debug("OAuth2 Keycloak exchange succeeded."); AccessToken token = tokenResult.result(); headerMap.set("Authorization", "Bearer " + token.principal().getString("access_token")); resultHandler.handle(Future.succeededFuture()); } else { log.error("Access Token Error: {0}.", tokenResult.cause().getMessage()); resultHandler.handle(Future.failedFuture(tokenResult.cause())); } }); return this; }
From source file:io.apiman.gateway.engine.vertx.polling.fetchers.auth.KeycloakOAuth2Client.java
License:Apache License
@Override public Authenticator authenticate(Vertx vertx, Map<String, String> config, MultiMap headerMap, AsyncResultHandler<Void> resultHandler) { OAuth2FlowType flowType = getFlowType(config.get("flowType")); JsonObject params = new JsonObject(); if (config.get("username") != null) { params.put("username", config.get("username")); }/* ww w. j a va 2 s . c o m*/ if (config.get("password") != null) { params.put("password", config.get("password")); } OAuth2Auth oauth2 = OAuth2Auth.createKeycloak(vertx, flowType, mapToJson(config)); oauth2.getToken(params, tokenResult -> { if (tokenResult.succeeded()) { log.debug("OAuth2 Keycloak exchange succeeded."); AccessToken token = tokenResult.result(); headerMap.set("Authorization", "Bearer " + token.principal().getString("access_token")); resultHandler.handle(Future.succeededFuture()); } else { log.error("Access Token Error: {0}.", tokenResult.cause().getMessage()); resultHandler.handle(Future.failedFuture(tokenResult.cause())); } }); return this; }
From source file:io.apiman.gateway.engine.vertx.polling.fetchers.auth.OAuth2.java
License:Apache License
@Override public Authenticator authenticate(Vertx vertx, Map<String, String> config, MultiMap headerMap, Handler<AsyncResult<Void>> resultHandler) { OAuth2ClientOptions credentials = new OAuth2ClientOptions(mapToJson(config)); if (config.get("oauthUri") != null) { credentials.setSite(config.get("oauthUri")); }// w w w . java 2s .c o m if (config.get("clientId") != null) { credentials.setClientID(config.get("clientId")); } OAuth2FlowType flowType = getFlowType(config.get("flowType")); JsonObject params = new JsonObject(); if (config.get("username") != null) { params.put("username", config.get("username")); } if (config.get("password") != null) { params.put("password", config.get("password")); } OAuth2Auth oauth2 = OAuth2Auth.create(vertx, flowType, credentials); oauth2.getToken(params, tokenResult -> { if (tokenResult.succeeded()) { log.debug("OAuth2 exchange succeeded."); AccessToken token = tokenResult.result(); headerMap.set("Authorization", "Bearer " + token.principal().getString("access_token")); resultHandler.handle(Future.succeededFuture()); } else { log.error("Access Token Error: {0}.", tokenResult.cause().getMessage()); resultHandler.handle(Future.failedFuture(tokenResult.cause())); } }); return this; }
From source file:io.apiman.gateway.engine.vertx.polling.fetchers.auth.OAuth2Client.java
License:Apache License
@Override public Authenticator authenticate(Vertx vertx, Map<String, String> config, MultiMap headerMap, AsyncResultHandler<Void> resultHandler) { OAuth2ClientOptions credentials = new OAuth2ClientOptions(mapToJson(config)); if (config.get("oauthUri") != null) { credentials.setSite(config.get("oauthUri")); }/*w ww . j av a 2 s. co m*/ if (config.get("clientId") != null) { credentials.setClientID(config.get("clientId")); } OAuth2FlowType flowType = getFlowType(config.get("flowType")); JsonObject params = new JsonObject(); if (config.get("username") != null) { params.put("username", config.get("username")); } if (config.get("password") != null) { params.put("password", config.get("password")); } OAuth2Auth oauth2 = OAuth2Auth.create(vertx, flowType, credentials); oauth2.getToken(params, tokenResult -> { if (tokenResult.succeeded()) { log.debug("OAuth2 exchange succeeded."); AccessToken token = tokenResult.result(); headerMap.set("Authorization", "Bearer " + token.principal().getString("access_token")); resultHandler.handle(Future.succeededFuture()); } else { log.error("Access Token Error: {0}.", tokenResult.cause().getMessage()); resultHandler.handle(Future.failedFuture(tokenResult.cause())); } }); return this; }