List of usage examples for io.vertx.core.eventbus Message body
@CacheReturn T body();
From source file:org.entcore.auth.oauth.OAuthDataHandler.java
License:Open Source License
private void upgradeOldPassword(final String username, String password) { String query = "MATCH (u:User {login: {login}}) SET u.password = {password} " + "RETURN u.id as id, HEAD(u.profiles) as profile "; JsonObject params = new JsonObject().put("login", username).put("password", BCrypt.hashpw(password, BCrypt.gensalt())); neo.execute(query, params, new io.vertx.core.Handler<Message<JsonObject>>() { @Override// w w w . j a v a 2 s .c o m public void handle(Message<JsonObject> event) { if (!"ok".equals(event.body().getString("status"))) { log.error("Error updating old password for user " + username + " : " + event.body().getString("message")); } else if (event.body().getJsonArray("result") != null && event.body().getJsonArray("result").size() == 1) { // welcome message JsonObject message = new JsonObject() .put("userId", event.body().getJsonArray("result").getJsonObject(0).getString("id")) .put("profile", event.body().getJsonArray("result").getJsonObject(0).getString("profile")) .put("request", new JsonObject().put("headers", new JsonObject() .put("Accept-Language", getRequest().getHeader("Accept-Language")) .put("Host", getRequest().getHeader("Host")) .put("X-Forwarded-Host", getRequest().getHeader("X-Forwarded-Host")))); neo.getEventBus().publish("send.welcome.message", message); } } }); }
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.ja va2 s . c om*/ } else { handler.handle(null); } } }); } else { createAuthInfo(clientId, userId, scope, redirectUri, handler); } } else { handler.handle(null); } }
From source file:org.entcore.auth.oauth.OAuthDataHandler.java
License:Open Source License
private void createAuthInfo(String clientId, String userId, String scope, String redirectUri, final Handler<AuthInfo> handler) { final JsonObject auth = new JsonObject().put("clientId", clientId).put("userId", userId).put("scope", scope) .put("createdAt", MongoDb.now()).put("refreshToken", UUID.randomUUID().toString()); if (redirectUri != null) { auth.put("redirectUri", redirectUri).put("code", UUID.randomUUID().toString()); }/*from ww w .j a va 2 s .com*/ mongo.save(AUTH_INFO_COLLECTION, auth, new io.vertx.core.Handler<Message<JsonObject>>() { @Override public void handle(Message<JsonObject> res) { if ("ok".equals(res.body().getString("status"))) { auth.put("id", res.body().getString("_id")); auth.remove("createdAt"); ObjectMapper mapper = new ObjectMapper(); try { handler.handle(mapper.readValue(auth.encode(), AuthInfo.class)); } catch (IOException e) { handler.handle(null); } } else { handler.handle(null); } } }); }
From source file:org.entcore.auth.oauth.OAuthDataHandler.java
License:Open Source License
@Override public void createOrUpdateAccessToken(final AuthInfo authInfo, final Handler<AccessToken> handler) { if (authInfo != null) { final JsonObject query = new JsonObject().put("authId", authInfo.getId()); mongo.count(ACCESS_TOKEN_COLLECTION, query, new io.vertx.core.Handler<Message<JsonObject>>() { @Override//from ww w .ja v a 2 s . c o m public void handle(Message<JsonObject> event) { if ("ok".equals(event.body().getString("status")) && (event.body().getInteger("count", 1) == 0 || isNotEmpty(authInfo.getRefreshToken()))) { final JsonObject token = new JsonObject().put("authId", authInfo.getId()) .put("token", UUID.randomUUID().toString()).put("createdOn", MongoDb.now()) .put("expiresIn", 3600); if (openIdConnectService != null && authInfo.getScope() != null && authInfo.getScope().contains("openid")) { //"2.0".equals(RequestUtils.getAcceptVersion(getRequest().getHeader("Accept")))) { openIdConnectService.generateIdToken(authInfo.getUserId(), authInfo.getClientId(), new io.vertx.core.Handler<AsyncResult<String>>() { @Override public void handle(AsyncResult<String> ar) { if (ar.succeeded()) { token.put("id_token", ar.result()); persistToken(token); } else { log.error("Error generating id_token.", ar.cause()); handler.handle(null); } } }); } else { persistToken(token); } } else { // revoke existing token and code with same authId mongo.delete(ACCESS_TOKEN_COLLECTION, query); mongo.delete(AUTH_INFO_COLLECTION, new JsonObject().put("_id", authInfo.getId())); handler.handle(null); } } private void persistToken(final JsonObject token) { mongo.save(ACCESS_TOKEN_COLLECTION, token, new io.vertx.core.Handler<Message<JsonObject>>() { @Override public void handle(Message<JsonObject> res) { if ("ok".equals(res.body().getString("status"))) { AccessToken t = new AccessToken(); t.setAuthId(authInfo.getId()); t.setToken(token.getString("token")); t.setCreatedOn(new Date(token.getJsonObject("createdOn").getLong("$date"))); t.setExpiresIn(3600); if (token.containsKey("id_token")) { t.setIdToken(token.getString("id_token")); } handler.handle(t); } else { handler.handle(null); } } }); } }); } else { handler.handle(null); } }
From source file:org.entcore.auth.oauth.OAuthDataHandler.java
License:Open Source License
@Override public void getAuthInfoByCode(String code, final Handler<AuthInfo> handler) { if (code != null && !code.trim().isEmpty()) { JsonObject query = new JsonObject().put("code", code).put("createdAt", new JsonObject().put("$gte", new JsonObject().put("$date", System.currentTimeMillis() - CODE_EXPIRES))); mongo.findOne(AUTH_INFO_COLLECTION, query, new io.vertx.core.Handler<Message<JsonObject>>() { @Override// w w w .j a v a2 s .c o m public void handle(Message<JsonObject> res) { JsonObject r = res.body().getJsonObject("result"); if ("ok".equals(res.body().getString("status")) && r != null && r.size() > 0) { r.put("id", r.getString("_id")); r.remove("_id"); r.remove("createdAt"); ObjectMapper mapper = new ObjectMapper(); try { handler.handle(mapper.readValue(r.encode(), AuthInfo.class)); } catch (IOException e) { handler.handle(null); } } else { handler.handle(null); } } }); } else { handler.handle(null); } }
From source file:org.entcore.auth.oauth.OAuthDataHandler.java
License:Open Source License
@Override public void getAuthInfoByRefreshToken(String refreshToken, final Handler<AuthInfo> handler) { if (refreshToken != null && !refreshToken.trim().isEmpty()) { JsonObject query = new JsonObject().put("refreshToken", refreshToken); mongo.findOne(AUTH_INFO_COLLECTION, query, new io.vertx.core.Handler<Message<JsonObject>>() { @Override/*from ww w . j a v a 2 s. c om*/ public void handle(Message<JsonObject> res) { if ("ok".equals(res.body().getString("status"))) { JsonObject r = res.body().getJsonObject("result"); if (r == null) { handler.handle(null); return; } r.put("id", r.getString("_id")); r.remove("_id"); r.remove("createdAt"); ObjectMapper mapper = new ObjectMapper(); try { handler.handle(mapper.readValue(r.encode(), AuthInfo.class)); } catch (IOException e) { handler.handle(null); } } else { handler.handle(null); } } }); } else { handler.handle(null); } }
From source file:org.entcore.auth.oauth.OAuthDataHandler.java
License:Open Source License
@Override public void validateClientById(String clientId, final Handler<Boolean> handler) { if (clientId != null && !clientId.trim().isEmpty()) { String query = "MATCH (n:Application) " + "WHERE n.name = {clientId} " + "RETURN count(n) as nb"; Map<String, Object> params = new HashMap<>(); params.put("clientId", clientId); neo.execute(query, params, new io.vertx.core.Handler<Message<JsonObject>>() { @Override/*from w w w .j ava 2 s .co m*/ public void handle(Message<JsonObject> res) { JsonArray a = res.body().getJsonArray("result"); if ("ok".equals(res.body().getString("status")) && a != null && a.size() == 1) { JsonObject r = a.getJsonObject(0); handler.handle(r != null && r.getInteger("nb") == 1); } else { handler.handle(false); } } }); } else { handler.handle(false); } }
From source file:org.entcore.auth.oauth.OAuthDataHandler.java
License:Open Source License
@Override public void validateUserById(String userId, final Handler<Boolean> handler) { if (userId != null && !userId.trim().isEmpty()) { String query = "MATCH (n:User) " + "WHERE n.id = {userId} " + "RETURN count(n) as nb"; Map<String, Object> params = new HashMap<>(); params.put("userId", userId); neo.execute(query, params, new io.vertx.core.Handler<Message<JsonObject>>() { @Override/* www .j a va2 s .c o m*/ public void handle(Message<JsonObject> res) { JsonArray a = res.body().getJsonArray("result"); if ("ok".equals(res.body().getString("status")) && a != null && a.size() == 1) { JsonObject r = a.getJsonObject(0); handler.handle(r != null && r.getInteger("nb") == 1); } else { handler.handle(false); } } }); } else { handler.handle(false); } }
From source file:org.entcore.auth.oauth.OAuthDataHandler.java
License:Open Source License
@Override public void getAccessToken(String token, final Handler<AccessToken> handler) { if (token != null && !token.trim().isEmpty()) { JsonObject query = new JsonObject().put("token", token); mongo.findOne(ACCESS_TOKEN_COLLECTION, query, new io.vertx.core.Handler<Message<JsonObject>>() { @Override/* ww w. j ava2 s. c o m*/ public void handle(Message<JsonObject> res) { JsonObject r = res.body().getJsonObject("result"); if ("ok".equals(res.body().getString("status")) && r != null && r.size() > 0) { AccessToken t = new AccessToken(); t.setAuthId(r.getString("authId")); t.setToken(r.getString("token")); t.setCreatedOn(MongoDb.parseIsoDate(r.getJsonObject("createdOn"))); t.setExpiresIn(r.getInteger("expiresIn")); handler.handle(t); } else { handler.handle(null); } } }); } else { handler.handle(null); } }
From source file:org.entcore.auth.oauth.OAuthDataHandler.java
License:Open Source License
@Override public void getAuthInfoById(String id, final Handler<AuthInfo> handler) { if (id != null && !id.trim().isEmpty()) { JsonObject query = new JsonObject().put("_id", id); mongo.findOne(AUTH_INFO_COLLECTION, query, new io.vertx.core.Handler<Message<JsonObject>>() { @Override/*from w w w.jav a2s .c om*/ public void handle(Message<JsonObject> res) { if ("ok".equals(res.body().getString("status"))) { JsonObject r = res.body().getJsonObject("result"); r.put("id", r.getString("_id")); r.remove("_id"); r.remove("createdAt"); ObjectMapper mapper = new ObjectMapper(); try { handler.handle(mapper.readValue(r.encode(), AuthInfo.class)); } catch (IOException e) { handler.handle(null); } } else { handler.handle(null); } } }); } else { handler.handle(null); } }