List of usage examples for io.vertx.core.eventbus Message body
@CacheReturn T body();
From source file:org.entcore.registry.services.impl.DefaultAppRegistryService.java
License:Open Source License
@Override public void getApplication(String applicationId, final Handler<Either<String, JsonObject>> handler) { String query = "MATCH (n:Application) " + "WHERE n.id = {id} " + "RETURN n.id as id, n.name as name, " + "n.grantType as grantType, n.secret as secret, n.address as address, " + "n.icon as icon, n.target as target, n.displayName as displayName, " + "n.scope as scope, n.pattern as pattern, n.casType as casType"; JsonObject params = new JsonObject().put("id", applicationId); neo.execute(query, params, new Handler<Message<JsonObject>>() { @Override//from w w w .j a va 2 s.c om public void handle(Message<JsonObject> res) { JsonArray r = res.body().getJsonArray("result"); if (r != null && r.size() == 1) { JsonObject j = r.getJsonObject(0); JsonArray scope = j.getJsonArray("scope"); if (scope != null && scope.size() > 0) { j.put("scope", Joiner.on(" ").join(scope)); } else { j.put("scope", ""); } } handler.handle(validUniqueResult(res)); } }); }
From source file:org.entcore.registry.services.impl.DefaultExternalApplicationService.java
License:Open Source License
@Override public void createExternalApplication(String structureId, final JsonObject application, final Handler<Either<String, JsonObject>> handler) { if (defaultValidationParamsNull(handler, application, application.getString("name"), structureId, application.getString("address"))) return;/* www. ja va 2 s .c om*/ final String applicationName = application.getString("name"); final String id = UUID.randomUUID().toString(); application.put("scope", new fr.wseduc.webutils.collections.JsonArray( "[\"" + application.getString("scope", "").replaceAll("\\s", "\",\"") + "\"]")); application.put("id", id); application.put("structureId", structureId); /* App creation query */ final String createApplicationQuery = "MATCH (n:Application) " + "WHERE n.name = {applicationName} " + "WITH count(*) AS exists " + "WHERE exists=0 " + "CREATE (m:Application:External {props}) " + "RETURN m.id as id"; final StatementsBuilder b = new StatementsBuilder().add(createApplicationQuery, new JsonObject().put("applicationName", applicationName).put("props", application)); /* Underlying action & role creation query */ String createActionsAndRolesQuery = "MATCH (n:Application) " + "WHERE n.id = {id} " + "CREATE UNIQUE n-[r:PROVIDE]->(a:Action:WorkflowAction {type: {type}, " + "name:{name}, displayName:{displayName}}) " + "WITH a " + "CREATE UNIQUE (r:Role {id: {roleId}, name: {roleName}, structureId: {structureId}})-[:AUTHORIZE]->(a) " + "RETURN r.id as roleId"; b.add(createActionsAndRolesQuery, new JsonObject().put("id", id).put("roleId", UUID.randomUUID().toString()) .put("type", "SECURED_ACTION_WORKFLOW").put("name", applicationName + "|address") .put("roleName", applicationName + "- ACCESS ").put("structureId", structureId) .put("displayName", applicationName + ".address")); neo.executeTransaction(b.build(), null, true, new Handler<Message<JsonObject>>() { @Override public void handle(Message<JsonObject> m) { JsonArray results = m.body().getJsonArray("results"); if ("ok".equals(m.body().getString("status")) && results != null) { JsonArray appRes = results.getJsonArray(0); JsonArray roleRes = results.getJsonArray(1); JsonObject j = new JsonObject() .mergeIn(appRes.size() > 0 ? appRes.getJsonObject(0) : new JsonObject()) .mergeIn(roleRes.size() > 0 ? roleRes.getJsonObject(0) : new JsonObject()); handler.handle(new Either.Right<String, JsonObject>(j)); } else { handler.handle(new Either.Left<String, JsonObject>(m.body().getString("message"))); } } }); }
From source file:org.entcore.session.AuthManager.java
License:Open Source License
@Override public void handle(Message<JsonObject> message) { String action = message.body().getString("action"); if (action == null) { sendError(message, "action must be specified"); return;/*from w ww .j ava2 s. c o m*/ } switch (action) { case "find": doFind(message); break; case "findByUserId": doFindByUserId(message); break; case "create": doCreate(message); break; case "drop": doDrop(message); break; case "dropCacheSession": doDropCacheSession(message); break; case "dropPermanentSessions": doDropPermanentSessions(message); break; case "addAttribute": doAddAttribute(message); break; case "removeAttribute": doRemoveAttribute(message); break; default: sendError(message, "Invalid action: " + action); } }
From source file:org.entcore.session.AuthManager.java
License:Open Source License
private void doDropCacheSession(Message<JsonObject> message) { final String userId = message.body().getString("userId"); if (userId == null || userId.trim().isEmpty()) { sendError(message, "[doDropCacheSession] Invalid userId : " + message.body().encode()); return;//from ww w . ja v a 2 s . c om } final List<LoginInfo> loginInfos = logins.get(userId); if (loginInfos != null) { final List<String> sessionIds = new ArrayList<>(); for (LoginInfo loginInfo : loginInfos) { sessionIds.add(loginInfo.sessionId); } for (String sessionId : sessionIds) { dropSession(null, sessionId, null); } } sendOK(message); }
From source file:org.entcore.session.AuthManager.java
License:Open Source License
private void doDropPermanentSessions(final Message<JsonObject> message) { String userId = message.body().getString("userId"); String currentSessionId = message.body().getString("currentSessionId"); if (userId == null || userId.trim().isEmpty()) { sendError(message, "[doDropPermanentSessions] Invalid userId : " + message.body().encode()); return;/* ww w.j av a 2 s.c om*/ } JsonObject query = new JsonObject().put("userId", userId); if (currentSessionId != null) { query.put("_id", new JsonObject().put("$ne", currentSessionId)); } mongo.delete(SESSIONS_COLLECTION, query, new Handler<Message<JsonObject>>() { @Override public void handle(Message<JsonObject> event) { if ("ok".equals(event.body().getString("status"))) { sendOK(message); } else { sendError(message, event.body().getString("message")); } } }); }
From source file:org.entcore.session.AuthManager.java
License:Open Source License
private void doFindByUserId(final Message<JsonObject> message) { final String userId = message.body().getString("userId"); if (userId == null || userId.trim().isEmpty()) { sendError(message, "[doFindByUserId] Invalid userId : " + message.body().encode()); return;/* www . j a v a 2 s .co m*/ } LoginInfo info = getLoginInfo(userId); if (info == null && !getOrElse(message.body().getBoolean("allowDisconnectedUser"), false)) { sendError(message, "[doFindByUserId] info is null - Invalid userId : " + message.body().encode()); return; } else if (info == null) { generateSessionInfos(userId, new Handler<JsonObject>() { @Override public void handle(JsonObject infos) { if (infos != null) { sendOK(message, new JsonObject().put("status", "ok").put("session", infos)); } else { sendError(message, "Invalid userId : " + userId); } } }); return; } JsonObject session = null; try { session = unmarshal(sessions.get(info.sessionId)); } catch (Exception e) { logger.error("Error in deserializing hazelcast session " + info.sessionId, e); } if (session == null) { sendError(message, "Session not found. 6"); return; } sendOK(message, new JsonObject().put("status", "ok").put("session", session)); }
From source file:org.entcore.session.AuthManager.java
License:Open Source License
private void doFind(final Message<JsonObject> message) { final String sessionId = message.body().getString("sessionId"); if (sessionId == null || sessionId.trim().isEmpty()) { sendError(message, "Invalid sessionId."); return;/* w w w . j a v a 2s.c o m*/ } JsonObject session = null; try { session = unmarshal(sessions.get(sessionId)); } catch (Exception e) { logger.warn("Error in deserializing hazelcast session " + sessionId); try { // if (sessions instanceof BaseMap) { // ((BaseMap) sessions).delete(sessionId); // } else { sessions.remove(sessionId); // } } catch (Exception e1) { logger.warn("Error getting object after removing hazelcast session " + sessionId); } } if (session == null) { final JsonObject query = new JsonObject().put("_id", sessionId); mongo.findOne(SESSIONS_COLLECTION, query, new Handler<Message<JsonObject>>() { @Override public void handle(Message<JsonObject> event) { JsonObject res = event.body().getJsonObject("result"); String userId; if ("ok".equals(event.body().getString("status")) && res != null && (userId = res.getString("userId")) != null && !userId.trim().isEmpty()) { final String uId = userId; createSession(userId, sessionId, res.getString("SessionIndex"), res.getString("NameID"), new Handler<String>() { @Override public void handle(String sId) { if (sId != null) { try { JsonObject s = unmarshal(sessions.get(sId)); if (s != null) { JsonObject sessionResponse = new JsonObject() .put("status", "ok").put("session", s); sendOK(message, sessionResponse); } else { sendError(message, "Session not found. 1"); } } catch (Exception e) { logger.warn("Error in deserializing new hazelcast session " + sId); generateSessionInfos(uId, new Handler<JsonObject>() { @Override public void handle(JsonObject event) { if (event != null) { logger.info("Session with hazelcast problem : " + event.encode()); sendOK(message, new JsonObject().put("status", "ok") .put("session", event)); } else { sendError(message, "Session not found. 2"); } } }); } } else { sendError(message, "Session not found. 3"); } } }); } else { sendError(message, "Session not found. 4"); } } }); } else { sendOK(message, new JsonObject().put("status", "ok").put("session", session)); if (inactivity != null) { Long lastActivity = inactivity.get(sessionId); String userId = sessions.get(sessionId); if (userId != null && (lastActivity == null || (lastActivity + LAST_ACTIVITY_DELAY) < System.currentTimeMillis())) { inactivity.put(sessionId, System.currentTimeMillis()); } } } }
From source file:org.entcore.session.AuthManager.java
License:Open Source License
private void doCreate(final Message<JsonObject> message) { final String userId = message.body().getString("userId"); final String sessionIndex = message.body().getString("SessionIndex"); final String nameID = message.body().getString("NameID"); if (userId == null || userId.trim().isEmpty()) { sendError(message, "[doCreate] Invalid userId : " + message.body().encode()); return;/* w w w . ja va 2 s . c om*/ } createSession(userId, null, sessionIndex, nameID, new Handler<String>() { @Override public void handle(String sessionId) { if (sessionId != null) { sendOK(message, new JsonObject().put("status", "ok").put("sessionId", sessionId)); } else { sendError(message, "Invalid userId : " + userId); } } }); }
From source file:org.entcore.session.AuthManager.java
License:Open Source License
private void doDrop(final Message<JsonObject> message) { final String sessionId = message.body().getString("sessionId"); boolean sessionMeta = getOrElse(message.body().getBoolean("sessionMetadata"), false); if (sessionId == null || sessionId.trim().isEmpty()) { sendError(message, "Invalid sessionId."); return;/*from w w w . ja v a2 s. com*/ } if (sessionMeta) { final JsonObject query = new JsonObject().put("_id", sessionId); mongo.findOne(SESSIONS_COLLECTION, query, new Handler<Message<JsonObject>>() { @Override public void handle(Message<JsonObject> event) { JsonObject res = event.body().getJsonObject("result"); dropSession(message, sessionId, res); } }); } else { dropSession(message, sessionId, null); } }
From source file:org.entcore.session.AuthManager.java
License:Open Source License
private void doAddAttribute(Message<JsonObject> message) { JsonObject session = getSessionByUserId(message); if (session == null) { return;/*ww w. j a v a2s . c om*/ } String key = message.body().getString("key"); if (key == null || key.trim().isEmpty()) { sendError(message, "Invalid key."); return; } Object value = message.body().getValue("value"); if (value == null) { sendError(message, "Invalid value."); return; } session.getJsonObject("cache").put(key, value); updateSessionByUserId(message, session); sendOK(message); }