List of usage examples for io.vertx.core Future failedFuture
static <T> Future<T> failedFuture(String failureMessage)
From source file:org.etourdot.vertx.marklogic.impl.MarkLogicManagementImpl.java
License:Open Source License
private void getNameViewConfig(Handler<AsyncResult<JsonObject>> resultHandler, NameViewOptions option, String baseUrl) {//from w w w. j a v a 2s.c o m MarkLogicRequest marklogicRequest = restService.newMarklogicRequest(); String serverHttpString = getUrlWithInstance(baseUrl, option); marklogicRequest.get(serverHttpString); if (option.hasView()) { marklogicRequest.addParam(VIEW, option.getView()); } marklogicRequest.execute(response -> { if (HttpResponseStatus.OK.code() == response.statusCode()) { response.contentHandler( buffer -> resultHandler.handle(Future.succeededFuture(buffer.toJsonObject()))); } else if (HttpResponseStatus.FOUND.code() == response.statusCode()) { // uri in Location header resultHandler.handle(Future.succeededFuture()); } else { resultHandler.handle(Future.failedFuture(response.statusMessage())); } }); }
From source file:org.etourdot.vertx.marklogic.impl.MarkLogicManagementImpl.java
License:Open Source License
private void getNameViewProperties(Handler<AsyncResult<JsonObject>> resultHandler, NameViewOptions option, String baseUrl) {/* w ww . j a v a2 s . c om*/ MarkLogicRequest marklogicRequest = restService.newMarklogicRequest(); String serverHttpString = getUrlWithInstance(baseUrl, option) + "/properties"; marklogicRequest.get(serverHttpString).execute(response -> { if (HttpResponseStatus.OK.code() == response.statusCode()) { response.contentHandler( buffer -> resultHandler.handle(Future.succeededFuture(buffer.toJsonObject()))); } else { resultHandler.handle(Future.failedFuture(response.statusMessage())); } }); }
From source file:org.etourdot.vertx.marklogic.impl.MarkLogicSearchImpl.java
License:Open Source License
void searchDocuments(SearchOptions searchOptions, Handler<AsyncResult<JsonArray>> resultHandler) { requireNonNull(searchOptions, "searchOptions cannot be null"); requireNonNull(resultHandler, "resultHandler cannot be null"); doSeachDocPage(searchOptions, marklogicResponse -> { JsonArray documents = new JsonArray(); if (HttpResponseStatus.OK.code() == marklogicResponse.statusCode()) { for (Document document : ((MultiPartResponse) marklogicResponse).getDocuments()) { documents.add(document.toJson()); }/*ww w .jav a 2s .co m*/ resultHandler.handle(Future.succeededFuture(documents)); } if (HttpResponseStatus.NOT_FOUND.code() == marklogicResponse.statusCode()) { resultHandler.handle( Future.failedFuture(new ResourceNotFoundException(marklogicResponse.statusMessage()))); } resultHandler.handle(Future.succeededFuture()); }); }
From source file:org.etourdot.vertx.marklogic.impl.MarkLogicSearchImpl.java
License:Open Source License
void searchBatch(SearchOptions searchOptions, Handler<AsyncResult<JsonObject>> resultHandler) { requireNonNull(searchOptions, "searchOptions cannot be null"); requireNonNull(resultHandler, "resultHandler cannot be null"); doSeachDocPage(searchOptions, marklogicResponse -> { if (HttpResponseStatus.OK.code() == marklogicResponse.statusCode()) { SearchResponse searchResponse = (SearchResponse) marklogicResponse; for (Document document : searchResponse.getDocuments()) { resultHandler.handle(Future.succeededFuture(document.toJson())); }//from ww w . j a v a 2 s. c o m if (searchResponse.getStart() + searchResponse.getNbResults() < searchResponse.getEstimate()) { searchOptions.start(searchResponse.getStart() + searchResponse.getPageLen()); searchBatch(searchOptions, resultHandler); } } if (HttpResponseStatus.NOT_FOUND.code() == marklogicResponse.statusCode()) { resultHandler.handle( Future.failedFuture(new ResourceNotFoundException(marklogicResponse.statusMessage()))); } }); }
From source file:org.etourdot.vertx.marklogic.impl.MarkLogicSearchImpl.java
License:Open Source License
void delete(DeleteOptions deleteOptions, Handler<AsyncResult<JsonObject>> resultHandler) { requireNonNull(deleteOptions, "deleteOptions cannot be null"); requireNonNull(resultHandler, "resultHandler cannot be null"); MarkLogicRequest request = restService.newMarklogicRequest(); request.delete(SEARCH_URL);/*w ww.j a v a 2 s.com*/ if (deleteOptions.hasDirectory()) { request.addParam(DIRECTORY, deleteOptions.getDirectory()); } if (deleteOptions.hasCollection()) { request.addParam(COLLECTION, deleteOptions.getCollection()); } if (deleteOptions.hasTxId()) { request.addParam(TXID, deleteOptions.getTxId()); } request.execute(response -> { if (HttpResponseStatus.NO_CONTENT.code() == response.statusCode()) { resultHandler.handle(Future.succeededFuture()); } else { resultHandler.handle(Future.failedFuture(response.statusMessage())); } }); }
From source file:org.folio.auth.login_module.impl.MongoAuthSource.java
@Override public Future<AuthResult> authenticate(JsonObject credentials, String tenant) { Future<AuthResult> future = Future.future(); String username = credentials.getString("username"); String password = credentials.getString("password"); if (username == null || password == null) { return Future.failedFuture("Credentials must contain a username and password"); }//w w w . j a v a2 s .c om JsonObject query = new JsonObject().put("username", username).put("tenant", tenant); logger.debug("Calling MongoDB to retrieve credentials"); mongoClient.find("credentials", query, res -> { if (res.succeeded() && !res.result().isEmpty()) { JsonObject user = res.result().get(0); String storedHash = user.getString("hash"); String storedSalt = user.getString("salt"); String calculatedHash = authUtil.calculateHash(password, storedSalt); if (calculatedHash.equals(storedHash)) { future.complete(new AuthResult(true, username, user.getJsonObject("metadata"))); logger.debug("Future completed (good)"); } else { future.complete(new AuthResult(false, username, user.getJsonObject("metadata"))); logger.debug("Future completed (bad)"); } } else { //username not found logger.error("No such user: " + username); future.complete(new AuthResult(false, username, null)); } logger.debug("Lambda completed"); }); logger.debug("Returning"); return future; }
From source file:org.jspare.forvertx.web.auth.BasicAuthProvider.java
License:Apache License
@Override public void authenticate(JsonObject authData, Handler<AsyncResult<User>> handler) { // Get authorization token String username = authData.getString(USERNAME); String password = authData.getString(PASSWORD); if (StringUtils.isEmpty(username) || StringUtils.isEmpty(password)) { handler.handle(Future.failedFuture(DEFAULT_ERROR)); return;//from w ww. j ava2 s . c o m } doAuthenticate(handler, username, password); }
From source file:org.jspare.forvertx.web.auth.DefaultBasicAuthProvider.java
License:Apache License
@Override protected void doAuthenticate(Handler<AsyncResult<User>> handler, String username, String password) { try {//from w w w. j a va 2 s.c om String users = my(ResourceLoader.class).readFileToString(this.resource); JsonObject data = new JsonObject(users); if (data.containsKey(username) && data.getJsonObject(username).getString(PASSWORD).equals(password)) { handler.handle(Future.succeededFuture(new AbstractUser() { @Override public JsonObject principal() { return data.getJsonObject(username); } @Override public void setAuthProvider(io.vertx.ext.auth.AuthProvider arg0) { } @Override protected void doIsPermitted(String authority, Handler<AsyncResult<Boolean>> resultPermitted) { resultPermitted .handle(Future.succeededFuture(principal().getJsonArray(ROLE).contains(authority))); } })); } return; } catch (IOException e) { log.warn(DEFAULT_ERROR); } handler.handle(Future.failedFuture(DEFAULT_ERROR)); }
From source file:org.pac4j.vertx.auth.Pac4jAuthProvider.java
License:Apache License
@Override public void authenticate(JsonObject jsonObject, Handler<AsyncResult<User>> handler) { // We'll just let the handler delegate back to pac4j, we don't need to do any more than that handler.handle(Future.failedFuture("Delegate to pac4j subsystem for authentication")); }
From source file:org.politrons.auth.impl.MongoAuthImpl.java
License:Open Source License
@Override public void authenticate(JsonObject authInfo, Handler<AsyncResult<User>> resultHandler) { String username = authInfo.getString(this.usernameCredentialField); String password = authInfo.getString(this.passwordCredentialField); // Null username is invalid if (username == null) { resultHandler.handle((Future.failedFuture("Username must be set for auth."))); return;/*from w w w .j av a2 s .c om*/ } if (password == null) { resultHandler.handle((Future.failedFuture("Password must be set for auth."))); return; } AuthToken token = new AuthToken(username, password); JsonObject query = createQuery(username); mongoClient.find(this.collectionName, query, res -> { try { if (res.succeeded()) { User user = handleSelection(res, token); resultHandler.handle(Future.succeededFuture(user)); } else { resultHandler.handle(Future.failedFuture(res.cause())); } } catch (Throwable e) { log.warn(e); resultHandler.handle(Future.failedFuture(e)); } }); }