List of usage examples for io.vertx.core Future succeededFuture
static <T> Future<T> succeededFuture(T result)
From source file:org.folio.auth.login_module.impl.DummyAuthSource.java
@Override public Future<Boolean> deleteAuth(String username, String tenant) { return Future.succeededFuture(true); }
From source file:org.jberet.vertx.shell.CommandPack.java
License:Open Source License
@Override public void resolver(final Vertx vertx, final Handler<AsyncResult<CommandResolver>> resolveHandler) { List<Command> commands = new ArrayList<>(); commands.add(Command.create(vertx, StartJobCommand.class)); commands.add(Command.create(vertx, ListJobsCommand.class)); commands.add(Command.create(vertx, AbandonJobExecutionCommand.class)); commands.add(Command.create(vertx, CountJobInstancesCommand.class)); commands.add(Command.create(vertx, GetJobExecutionCommand.class)); commands.add(Command.create(vertx, GetStepExecutionCommand.class)); commands.add(Command.create(vertx, ListJobExecutionsCommand.class)); commands.add(Command.create(vertx, ListJobInstancesCommand.class)); commands.add(Command.create(vertx, ListStepExecutionsCommand.class)); commands.add(Command.create(vertx, RestartJobExecutionCommand.class)); commands.add(Command.create(vertx, StopJobExecutionCommand.class)); // Add another command // commands.add(CommandBuilder.command("another-command").processHandler(process -> { // Handle process // }).build(vertx)); resolveHandler.handle(Future.succeededFuture(() -> commands)); }
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 ww w .j ava2 s . c o m 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.Pac4jUser.java
License:Apache License
@Override protected void doIsPermitted(String permission, Handler<AsyncResult<Boolean>> resultHandler) { if (userProfile.getPermissions().contains(permission)) { resultHandler.handle(Future.succeededFuture(true)); } else {/*from ww w . ja va 2 s. c o m*/ resultHandler.handle(Future.succeededFuture(false)); } }
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.jav a 2s. c o m } 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)); } }); }
From source file:org.politrons.auth.impl.MongoUser.java
License:Open Source License
/** * check wether the current user has the given role * //from w w w .j av a2s. co m * @param role * the role to be checked * @param resultHandler * resultHandler gets true, if role is valid, otherwise false */ protected void doHasRole(String role, Handler<AsyncResult<Boolean>> resultHandler) { try { JsonArray roles = principal.getJsonArray(mongoAuth.getRoleField()); resultHandler.handle(Future.succeededFuture(roles != null && roles.contains(role))); } catch (Throwable e) { resultHandler.handle(Future.failedFuture(e)); } }
From source file:org.politrons.auth.impl.MongoUser.java
License:Open Source License
/** * Check wether the current user has the given permission * /*from ww w . j ava2s . com*/ * @param permission * the permission to be checked * @param resultHandler * resulthandler gets true, if permission is valid, otherwise false * */ protected void doHasPermission(String permission, Handler<AsyncResult<Boolean>> resultHandler) { try { JsonArray userPermissions = principal.getJsonArray(mongoAuth.getPermissionField()); resultHandler.handle( Future.succeededFuture(userPermissions != null && userPermissions.contains(permission))); } catch (Throwable e) { resultHandler.handle(Future.failedFuture(e)); } }
From source file:org.sfs.io.AsyncFileReaderImpl.java
License:Apache License
private void doRead(final Buffer writeBuff, final int offset, final ByteBuffer buff, final long position, final Handler<AsyncResult<Buffer>> handler) { ch.read(buff, position, null, new java.nio.channels.CompletionHandler<Integer, Object>() { long pos = position; private void done(boolean eof) { context.runOnContext(event -> { buff.flip();//from w w w . ja v a2 s. com writeBuff.setBytes(offset, buff); Future.succeededFuture(writeBuff).setHandler(handler); }); } public void completed(Integer bytesRead, Object attachment) { if (bytesRead == -1) { //End of file done(true); } else if (buff.hasRemaining()) { // partial read pos += bytesRead; // resubmit doRead(writeBuff, offset, buff, pos, handler); } else { // It's been fully written done(false); } } public void failed(final Throwable t, Object attachment) { context.runOnContext(event -> Future.<Buffer>failedFuture(t).setHandler(handler)); } }); }
From source file:org.sub.bug.BugCRUDServiceVertxEBProxy.java
License:Apache License
public void saveBug(Bug bug, Handler<AsyncResult<Void>> resultHandler) { if (closed) { resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed"))); return;//from w w w .j av a 2s.c o m } JsonObject _json = new JsonObject(); _json.put("bug", bug == null ? null : bug.toJson()); DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions(); _deliveryOptions.addHeader("action", "saveBug"); _vertx.eventBus().<Void>send(_address, _json, _deliveryOptions, res -> { if (res.failed()) { resultHandler.handle(Future.failedFuture(res.cause())); } else { resultHandler.handle(Future.succeededFuture(res.result().body())); } }); }
From source file:org.sub.bug.BugCRUDServiceVertxEBProxy.java
License:Apache License
public void retrieveBug(String bugId, Handler<AsyncResult<Bug>> resultHandler) { if (closed) { resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed"))); return;// ww w. j a v a2s . co m } JsonObject _json = new JsonObject(); _json.put("bugId", bugId); DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions(); _deliveryOptions.addHeader("action", "retrieveBug"); _vertx.eventBus().<JsonObject>send(_address, _json, _deliveryOptions, res -> { if (res.failed()) { resultHandler.handle(Future.failedFuture(res.cause())); } else { resultHandler.handle( Future.succeededFuture(res.result().body() == null ? null : new Bug(res.result().body()))); } }); }