List of usage examples for io.vertx.core Future succeededFuture
static <T> Future<T> succeededFuture(T result)
From source file:io.gravitee.am.gateway.handler.vertx.auth.provider.ClientAuthenticationProvider.java
License:Apache License
@Override public void authenticate(JsonObject credentials, Handler<AsyncResult<User>> authHandler) { String clientId = credentials.getString(USERNAME_FIELD); String clientSecret = credentials.getString(PASSWORD_FIELD); logger.debug("Trying to authenticate a client: clientId[{}]", clientId); clientService.findByClientId(clientId).subscribe(client -> { if (client.getClientSecret().equals(clientSecret)) { authHandler.handle(Future.succeededFuture(new Client(client))); } else {/* w ww . j a va 2 s .co m*/ authHandler.handle(Future.failedFuture(new BadClientCredentialsException())); } }, error -> { logger.error("Unexpected error while looking for a client: clientId[{}]", clientId, error); authHandler.handle(Future.failedFuture(error)); }, () -> authHandler.handle(Future.failedFuture(new BadClientCredentialsException()))); }
From source file:io.gravitee.am.gateway.handler.vertx.auth.provider.OAuth2ClientAuthenticationProvider.java
License:Apache License
@Override public void authenticate(JsonObject authInfo, Handler<AsyncResult<User>> resultHandler) { identityProviderManager.get(authInfo.getString(PROVIDER_PARAMETER)).flatMap(authenticationProvider -> { String username = authInfo.getString(USERNAME_PARAMETER); String password = authInfo.getString(PASSWORD_PARAMETER); EndUserAuthentication endUserAuthentication = new EndUserAuthentication(username, password); endUserAuthentication.setAdditionalInformation(Collections.singletonMap(OAuth2Constants.REDIRECT_URI, authInfo.getString(OAuth2Constants.REDIRECT_URI))); return authenticationProvider.loadUserByUsername(endUserAuthentication); }).switchIfEmpty(Maybe.error(new BadCredentialsException())).flatMapSingle(user -> { // set source and client for the current authenticated end-user Map<String, Object> additionalInformation = user.getAdditionalInformation() == null ? new HashMap<>() : new HashMap<>(user.getAdditionalInformation()); additionalInformation.put("source", authInfo.getString(PROVIDER_PARAMETER)); additionalInformation.put(OAuth2Constants.CLIENT_ID, authInfo.getString(OAuth2Constants.CLIENT_ID)); ((DefaultUser) user).setAdditonalInformation(additionalInformation); return userService.findOrCreate(user); }).subscribe(/*from w ww. j av a 2 s . c om*/ user -> resultHandler.handle( Future.succeededFuture(new io.gravitee.am.gateway.handler.vertx.auth.user.User(user))), error -> { logger.error("Unable to authenticate oauth2 provider", error); resultHandler.handle(Future.failedFuture(error)); }); }
From source file:io.gravitee.am.gateway.handler.vertx.auth.provider.UserAuthenticationProvider.java
License:Apache License
@Override public void authenticate(JsonObject authInfo, Handler<AsyncResult<User>> resultHandler) { String username = authInfo.getString(USERNAME_PARAMETER); String password = authInfo.getString(PASSWORD_PARAMETER); String clientId = authInfo.getString(OAuth2Constants.CLIENT_ID); userAuthenticationManager.authenticate(clientId, new EndUserAuthentication(username, password)).subscribe( user -> resultHandler.handle( Future.succeededFuture(new io.gravitee.am.gateway.handler.vertx.auth.user.User(user))), error -> resultHandler.handle(Future.failedFuture(error))); }
From source file:io.hijynx.ensemble.identity.PrivilegeServiceVertxEBProxy.java
License:Apache License
public PrivilegeService addPrivilege(Privilege privilege, Handler<AsyncResult<Void>> resultHandler) { if (closed) { resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed"))); return this; }/* w ww.ja v a 2 s . c o m*/ JsonObject _json = new JsonObject(); _json.put("privilege", privilege == null ? null : privilege.toJson()); DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions(); _deliveryOptions.addHeader("action", "addPrivilege"); _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())); } }); return this; }
From source file:io.hijynx.ensemble.identity.PrivilegeServiceVertxEBProxy.java
License:Apache License
public PrivilegeService retrievePrivilege(String id, Handler<AsyncResult<Privilege>> resultHandler) { if (closed) { resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed"))); return this; }// w w w .j a v a 2s . c o m JsonObject _json = new JsonObject(); _json.put("id", id); DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions(); _deliveryOptions.addHeader("action", "retrievePrivilege"); _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 Privilege(res.result().body()))); } }); return this; }
From source file:io.hijynx.ensemble.identity.PrivilegeServiceVertxEBProxy.java
License:Apache License
public PrivilegeService retrievePrivilegeByName(String privilegeName, Handler<AsyncResult<Privilege>> resultHandler) { if (closed) { resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed"))); return this; }/*from ww w . j a v a 2s . co m*/ JsonObject _json = new JsonObject(); _json.put("privilegeName", privilegeName); DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions(); _deliveryOptions.addHeader("action", "retrievePrivilegeByName"); _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 Privilege(res.result().body()))); } }); return this; }
From source file:io.hijynx.ensemble.identity.PrivilegeServiceVertxEBProxy.java
License:Apache License
public PrivilegeService retrieveAllPrivileges(Handler<AsyncResult<List<Privilege>>> resultHandler) { if (closed) { resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed"))); return this; }//from www .ja va 2 s. co m JsonObject _json = new JsonObject(); DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions(); _deliveryOptions.addHeader("action", "retrieveAllPrivileges"); _vertx.eventBus().<JsonArray>send(_address, _json, _deliveryOptions, res -> { if (res.failed()) { resultHandler.handle(Future.failedFuture(res.cause())); } else { resultHandler .handle(Future .succeededFuture( res.result().body().stream() .map(o -> o instanceof Map ? new Privilege(new JsonObject((Map) o)) : new Privilege((JsonObject) o)) .collect(Collectors.toList()))); } }); return this; }
From source file:io.hijynx.ensemble.identity.PrivilegeServiceVertxEBProxy.java
License:Apache License
public PrivilegeService updatePrivilege(Privilege privilege, Handler<AsyncResult<Privilege>> resultHandler) { if (closed) { resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed"))); return this; }/*from w ww . jav a2 s .co m*/ JsonObject _json = new JsonObject(); _json.put("privilege", privilege == null ? null : privilege.toJson()); DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions(); _deliveryOptions.addHeader("action", "updatePrivilege"); _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 Privilege(res.result().body()))); } }); return this; }
From source file:io.hijynx.ensemble.identity.PrivilegeServiceVertxEBProxy.java
License:Apache License
public PrivilegeService deletePrivilege(String id, Handler<AsyncResult<Void>> resultHandler) { if (closed) { resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed"))); return this; }//from w w w .j a v a 2 s.com JsonObject _json = new JsonObject(); _json.put("id", id); DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions(); _deliveryOptions.addHeader("action", "deletePrivilege"); _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())); } }); return this; }
From source file:io.hijynx.ensemble.identity.RoleServiceVertxEBProxy.java
License:Apache License
public RoleService addRole(Role role, Handler<AsyncResult<Void>> resultHandler) { if (closed) { resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed"))); return this; }//from w w w.j a v a 2s . c o m JsonObject _json = new JsonObject(); _json.put("role", role == null ? null : role.toJson()); DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions(); _deliveryOptions.addHeader("action", "addRole"); _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())); } }); return this; }