List of usage examples for io.vertx.core.json JsonObject getString
public String getString(String key)
From source file:org.entcore.cas.services.AcademicSuffixRegisteredService.java
License:Open Source License
/** * Replace or format cas-user attribute response with formated externalId * In all case : remove prefix ENT$ if is at the beginning * Split externalId with - character, if we have only one - : remove the prefix and add the correct suffix * In other case, keep the same externalId * @param user : authenticated user//from w w w . j a v a2 s .c o m * @param userId * @param service * @param data * @param doc * @param additionnalAttributes */ @Override protected void prepareUserCas20(User user, String userId, String service, JsonObject data, Document doc, List<Element> additionnalAttributes) { user.setUser(data.getString(principalAttributeName)); log.debug("conf : eip : " + externalIdPrefix + ", acp : " + academicConfPattern + ", map : " + ACADEMIC_SUFFIX.toString()); try { // Define attribute : cas:user if (data.containsKey("externalId")) { String initialExternalId = data.getString("externalId"); log.debug("PrepareUserCas20 : ExternalId Initial : " + initialExternalId); // Replace first conf prefix if it's at the beginning. initialExternalId = initialExternalId.replaceFirst(this.externalIdPrefix, "$1"); // We verify REXEXP Matcher academyMatcher = this.academicPattern.matcher(initialExternalId); String externalId = ""; if (academyMatcher.matches()) { externalId = academyMatcher.group(2) + ACADEMIC_SUFFIX.get(academyMatcher.group(1)); log.debug("ExternalId target : " + externalId); } else { externalId = initialExternalId; log.debug("External id could not be processed, Initial External id is used : " + initialExternalId); } log.debug("ExternalId Final : " + externalId); user.setUser(externalId); } } catch (Exception e) { log.error("Failed to transform User for Uid service : ", e); } }
From source file:org.entcore.cas.services.CIDJRegisteredService.java
License:Open Source License
@Override protected void prepareUserCas20(User user, String userId, String service, JsonObject data, Document doc, List<Element> additionnalAttributes) { user.setUser(data.getString(principalAttributeName)); try {/*w w w .j ava2 s. c o m*/ // Uid if (data.containsKey("externalId")) { additionnalAttributes.add(createTextElement(CIDJ_ID, data.getString("externalId"), doc)); } // Structures for (Object o : data.getJsonArray("structures", new fr.wseduc.webutils.collections.JsonArray()) .getList()) { if (o == null || !(o instanceof JsonObject)) continue; JsonObject structure = (JsonObject) o; if (structure.containsKey("UAI")) { additionnalAttributes .add(createTextElement(CIDJ_STRUCTURE_CODERNE, structure.getString("UAI"), doc)); } } } catch (Exception e) { log.error("Failed to transform User for CIDJ", e); } }
From source file:org.entcore.cas.services.DefaultRegisteredService.java
License:Open Source License
protected void prepareUser(final User user, final String userId, String service, final JsonObject data) { if (principalAttributeName != null) { user.setUser(data.getString(principalAttributeName)); data.remove(principalAttributeName); } else {//from w w w . ja v a 2 s. c o m user.setUser(userId); } data.remove("password"); Map<String, String> attributes = new HashMap<>(); for (String attr : data.fieldNames()) { attributes.put(attr, data.getValue(attr).toString()); } user.setAttributes(attributes); }
From source file:org.entcore.cas.services.EducagriRegisteredService.java
License:Open Source License
@Override protected void prepareUserCas20(User user, String userId, String service, JsonObject data, Document doc, List<Element> additionnalAttributes) { user.setUser(data.getString(principalAttributeName)); try {/* w w w . j a v a2 s . c o m*/ //uid if (data.containsKey("externalId")) { additionnalAttributes.add(createTextElement(EA_ID, data.getString("externalId"), doc)); } // Structures for (Object o : data.getJsonArray("structures", new fr.wseduc.webutils.collections.JsonArray()) .getList()) { if (o == null || !(o instanceof JsonObject)) continue; JsonObject structure = (JsonObject) o; if (structure.containsKey("UAI")) { additionnalAttributes .add(createTextElement(EA_STRUCTURE_UAI, structure.getString("UAI").toString(), doc)); } } // Profile switch (data.getString("type")) { case "Student": additionnalAttributes.add(createTextElement(EA_PROFILES, "National_1", doc)); break; case "Teacher": additionnalAttributes.add(createTextElement(EA_PROFILES, "National_3", doc)); break; case "Personnel": additionnalAttributes.add(createTextElement(EA_PROFILES, "National_4", doc)); break; } } catch (Exception e) { log.error("Failed to transform User for Educagri", e); } }
From source file:org.entcore.cas.services.EduMediaRegisteredService.java
License:Open Source License
@Override protected void prepareUserCas20(User user, String userId, String service, JsonObject data, Document doc, List<Element> additionnalAttributes) { user.setUser(data.getString(principalAttributeName)); try {//w w w . j ava 2s . c om //uid if (data.containsKey("externalId")) { additionnalAttributes.add(createTextElement(EM_ID, data.getString("externalId"), doc)); } // Structures for (Object o : data.getJsonArray("structures", new fr.wseduc.webutils.collections.JsonArray()) .getList()) { if (o == null || !(o instanceof JsonObject)) continue; JsonObject structure = (JsonObject) o; if (structure.containsKey("UAI")) { additionnalAttributes.add(createTextElement(EM_STRUCTURE_UAI, structure.getString("UAI"), doc)); } } // Profile switch (data.getString("type")) { case "Student": additionnalAttributes.add(createTextElement(EM_PROFILES, "National_1", doc)); break; case "Teacher": additionnalAttributes.add(createTextElement(EM_PROFILES, "National_3", doc)); break; case "Personnel": additionnalAttributes.add(createTextElement(EM_PROFILES, "National_4", doc)); break; } } catch (Exception e) { log.error("Failed to transform User for Edumedia", e); } }
From source file:org.entcore.cas.services.EliotRegisteredService.java
License:Open Source License
@Override protected void prepareUser(final User user, final String userId, String service, final JsonObject data) { if (principalAttributeName != null) { user.setUser(data.getString(principalAttributeName)); data.remove(principalAttributeName); } else {/*from ww w . j a v a 2 s . co m*/ user.setUser(userId); } }
From source file:org.entcore.cas.services.EnglishAttackRegisteredService.java
License:Open Source License
@Override protected void prepareUserCas20(User user, final String userId, String service, final JsonObject data, final Document doc, final List<Element> additionnalAttributes) { user.setUser(data.getString(principalAttributeName)); if (log.isDebugEnabled()) { log.debug("START : prepareUserCas20 userId : " + userId); }// w w w .j a v a 2 s.com try { if (log.isDebugEnabled()) { log.debug("DATA : prepareUserCas20 data : " + data); } String query = "MATCH (u:`User` { id : {id}}) return u"; JsonObject params = new JsonObject().put("id", userId); neo.execute(query, params, new Handler<Message<JsonObject>>() { @Override public void handle(Message<JsonObject> m) { // Uid if (data.containsKey("externalId")) { additionnalAttributes.add(createTextElement(EA_ID, data.getString("externalId"), doc)); } // Structures Element rootStructures = createElement(EA_STRUCTURE + "s", doc); for (Object o : data.getJsonArray("structures", new fr.wseduc.webutils.collections.JsonArray()) .getList()) { if (o == null || !(o instanceof JsonObject)) continue; JsonObject structure = (JsonObject) o; Element rootStructure = createElement(EA_STRUCTURE, doc); if (structure.containsKey("UAI")) { rootStructure.appendChild( createTextElement(EA_STRUCTURE_UAI, structure.getString("UAI"), doc)); } if (structure.containsKey("name")) { rootStructure.appendChild( createTextElement(EA_STRUCTURE_NAME, structure.getString("name"), doc)); } rootStructures.appendChild(rootStructure); } additionnalAttributes.add(rootStructures); // Profile switch (data.getString("type")) { case "Student": additionnalAttributes.add(createTextElement(EA_PROFILES, "National_1", doc)); addStringArray(EA_CLASSE, "classes", "name", data, doc, additionnalAttributes, new Mapper<String, String>() { String map(String input) { Matcher m = classGroupPattern.matcher(input); if (m.matches() && m.groupCount() >= 1) { return m.group(1); } return input; } }); // Email if (data.containsKey("email")) { additionnalAttributes.add(createTextElement(EA_EMAIL, data.getString("email"), doc)); } break; case "Teacher": additionnalAttributes.add(createTextElement(EA_PROFILES, "National_3", doc)); addStringArray(EA_CLASSE, "classes", "name", data, doc, additionnalAttributes, new Mapper<String, String>() { String map(String input) { Matcher m = classGroupPattern.matcher(input); if (m.matches() && m.groupCount() >= 1) { return m.group(1); } return input; } }); //Discipline Either<String, JsonObject> res = validUniqueResult(m); if (res.isRight()) { JsonObject j = res.right().getValue(); if (null != j.getJsonObject("u") && null != j.getJsonObject("u").getJsonObject("data") && null != j.getJsonObject("u").getJsonObject("data") .getJsonArray("functions")) { JsonArray jsonArrayFunctions = j.getJsonObject("u").getJsonObject("data") .getJsonArray("functions"); if (jsonArrayFunctions.size() > 0) { Element rootDisciplines = createElement(EA_DISCIPLINE + "s", doc); List<String> vTempListDiscipline = new ArrayList<>(); for (int i = 0; i < jsonArrayFunctions.size(); i++) { String fonction = jsonArrayFunctions.getString(i); String[] elements = fonction.split("\\$"); if (elements.length > 1) { String discipline = elements[elements.length - 2] + "$" + elements[elements.length - 1]; if (!vTempListDiscipline.contains(discipline)) { vTempListDiscipline.add(discipline); rootDisciplines.appendChild( createTextElement(EA_DISCIPLINE, discipline, doc)); } } else { log.error("Failed to get User functions userID, : " + userId + " fonction : " + fonction); } } additionnalAttributes.add(rootDisciplines); } } else { log.error("Failed to get User functions userID, user empty : " + userId + " j : " + j); } } else { log.error("Failed to get User functions userID : " + userId); } // Email if (data.containsKey("emailAcademy")) { additionnalAttributes .add(createTextElement(EA_EMAIL, data.getString("emailAcademy"), doc)); } else if (data.containsKey("email")) { additionnalAttributes.add(createTextElement(EA_EMAIL, data.getString("email"), doc)); } break; case "Relative": additionnalAttributes.add(createTextElement(EA_PROFILES, "National_2", doc)); break; case "Personnel": additionnalAttributes.add(createTextElement(EA_PROFILES, "National_4", doc)); break; } // Lastname if (data.containsKey("lastName")) { additionnalAttributes.add(createTextElement(EA_LASTNAME, data.getString("lastName"), doc)); } // Firstname if (data.containsKey("firstName")) { additionnalAttributes .add(createTextElement(EA_FIRSTNAME, data.getString("firstName"), doc)); } } }); } catch (Exception e) { log.error("Failed to transform User for EnglishAttack", e); } if (log.isDebugEnabled()) { log.debug("START : prepareUserCas20 userId : " + userId); } }
From source file:org.entcore.cas.services.GepiRegisteredService.java
License:Open Source License
@Override protected void prepareUserCas20(User user, String userId, String service, JsonObject data, Document doc, List<Element> additionnalAttributes) { user.setUser(data.getString(principalAttributeName)); try {/* w w w .j a v a 2 s . c o m*/ //uid if (data.containsKey("externalId")) { additionnalAttributes.add(createTextElement(GP_ID, data.getString("externalId"), doc)); } // Profile switch (data.getString("type")) { case "Student": additionnalAttributes.add(createTextElement(GP_PROFILES, "National_1", doc)); break; case "Teacher": additionnalAttributes.add(createTextElement(GP_PROFILES, "National_3", doc)); break; case "Relative": additionnalAttributes.add(createTextElement(GP_PROFILES, "National_2", doc)); break; case "Personnel": additionnalAttributes.add(createTextElement(GP_PROFILES, "National_4", doc)); break; } } catch (Exception e) { log.error("Failed to transform User for GEPI", e); } }
From source file:org.entcore.cas.services.GRRRegisteredService.java
License:Open Source License
@Override protected void prepareUserCas20(User user, String userId, String service, JsonObject data, Document doc, List<Element> additionnalAttributes) { user.setUser(data.getString(principalAttributeName)); try {/*ww w . j av a2 s . co m*/ additionnalAttributes.add(createTextElement("user_nom_ldap", data.getString("lastName"), doc)); additionnalAttributes.add(createTextElement("user_prenom_ldap", data.getString("firstName"), doc)); additionnalAttributes.add(createTextElement("user_mail_ldap", data.getString("email"), doc)); // Profile if (data.getJsonArray("type") != null && data.getJsonArray("type").size() > 0) { additionnalAttributes.add( createTextElement("user_code_fonction_ldap", data.getJsonArray("type").getString(0), doc)); additionnalAttributes.add(createTextElement("user_libelle_fonction_ldap", data.getJsonArray("type").getString(0), doc)); } } catch (Exception e) { log.error("Failed to transform User for GRR CAS extension", e); } }
From source file:org.entcore.cas.services.KneRegisteredService.java
License:Open Source License
@Override protected void prepareUserCas20(User user, String userId, String service, JsonObject data, Document doc, List<Element> additionalAttributes) { user.setUser(data.getString(principalAttributeName)); try {/*from w w w . j a v a2s .com*/ String queryParams = new URI(service).getQuery(); String[] pairs; if (queryParams != null && queryParams.length() > 0 && (pairs = queryParams.split("&")).length > 0) { for (String pair : pairs) { String key = pair.substring(0, pair.indexOf('=')); if ("UAI".equals(key)) { String value = pair.substring(pair.indexOf('=') + 1); additionalAttributes.add(createTextElement("ENTPersonStructRattachUAI", value, doc)); for (Object o : data .getJsonArray("structureNodes", new fr.wseduc.webutils.collections.JsonArray()) .getList()) { if (o == null || !(o instanceof JsonObject)) continue; JsonObject structure = (JsonObject) o; if (value.equals(structure.getString("UAI"))) { if (structure.containsKey("type")) { String type = structure.getString("type"); switch (type) { case "ECOLE DE NIVEAU ELEMENTAIRE": additionalAttributes .add(createTextElement("ENTStructureTypeStruct", "1ORD", doc)); break; case "COLLEGE": case "COLLEGE CLIMATIQUE": additionalAttributes .add(createTextElement("ENTStructureTypeStruct", "CLG", doc)); break; case "LYCEE D ENSEIGNEMENT GENERAL": case "LYCEE POLYVALENT": additionalAttributes .add(createTextElement("ENTStructureTypeStruct", "LYC", doc)); break; case "LYCEE PROFESSIONNEL": additionalAttributes .add(createTextElement("ENTStructureTypeStruct", "LP", doc)); break; default: additionalAttributes .add(createTextElement("ENTStructureTypeStruct", type, doc)); } } break; } } break; } } } Element rootProfiles; String profile = data.getJsonArray("type", new fr.wseduc.webutils.collections.JsonArray()).size() > 0 ? data.getJsonArray("type").getString(0) : ""; switch (profile) { case "Student": rootProfiles = createElement("ENTPersonProfils", doc); rootProfiles.appendChild(createTextElement("ENTPersonProfil", "National_ELV", doc)); additionalAttributes.add(rootProfiles); additionalAttributes.add(createTextElement("ENTEleveMEF", data.getString("module", ""), doc)); addArray("ENTEleveCodeEnseignement", "fieldOfStudy", data, doc, additionalAttributes, new DefaultMapper<String>()); addArray("ENTEleveClasse", "classes", data, doc, additionalAttributes, new Mapper<String, String>() { String map(String input) { Matcher m = classGroupPattern.matcher(input); if (m.matches() && m.groupCount() >= 1) { return m.group(1); } return input; } }); addArray("ENTEleveGroupe", "groups", data, doc, additionalAttributes, new Mapper<String, String>() { String map(String input) { Matcher m = classGroupPattern.matcher(input); if (m.matches() && m.groupCount() >= 1) { return m.group(1); } return input; } }); additionalAttributes.add(createTextElement("ENTAuxEnsClassesMatieres", "", doc)); additionalAttributes.add(createTextElement("ENTAuxEnsGroupes", "", doc)); additionalAttributes.add(createTextElement("ENTAuxEnsClasses", "", doc)); additionalAttributes.add(createTextElement("ENTAuxEnsMEFs", "", doc)); break; case "Teacher": rootProfiles = createElement("ENTPersonProfils", doc); rootProfiles.appendChild(createTextElement("ENTPersonProfil", "National_ENS", doc)); //rootProfiles.appendChild(createTextElement("ENTPersonProfil", "National_TUT", doc)); additionalAttributes.add(rootProfiles); additionalAttributes.add(createTextElement("ENTEleveMEF", "", doc)); additionalAttributes.add(createTextElement("ENTEleveCodeEnseignements", "", doc)); additionalAttributes.add(createTextElement("ENTEleveClasses", "", doc)); additionalAttributes.add(createTextElement("ENTEleveGroupes", "", doc)); addArray("ENTAuxEnsClassesMatiere", "classesFieldOfStudy", data, doc, additionalAttributes, new Mapper<String, String>() { String map(String input) { Matcher m = matPattern.matcher(input); if (m.matches() && m.groupCount() >= 1) { return m.group(1); } return input; } }); addArray("ENTAuxEnsGroupe", "groups", data, doc, additionalAttributes, new Mapper<String, String>() { String map(String input) { Matcher m = classGroupPattern.matcher(input); if (m.matches() && m.groupCount() >= 1) { return m.group(1); } return input; } }); addArray("ENTAuxEnsClasse", "classes", data, doc, additionalAttributes, new Mapper<String, String>() { String map(String input) { Matcher m = classGroupPattern.matcher(input); if (m.matches() && m.groupCount() >= 1) { return m.group(1); } return input; } }); addArray("ENTAuxEnsMEF", "modules", data, doc, additionalAttributes, new Mapper<String, String>() { String map(String input) { Matcher m = mefStatPattern.matcher(input); if (m.matches() && m.groupCount() >= 1) { return m.group(1); } return input; } }); break; case "Relative": rootProfiles = createElement("ENTPersonProfils", doc); rootProfiles.appendChild(createTextElement("ENTPersonProfil", "National_TUT", doc)); additionalAttributes.add(rootProfiles); additionalAttributes.add(createTextElement("ENTEleveMEF", "", doc)); additionalAttributes.add(createTextElement("ENTEleveCodeEnseignements", "", doc)); additionalAttributes.add(createTextElement("ENTEleveClasses", "", doc)); additionalAttributes.add(createTextElement("ENTEleveGroupes", "", doc)); additionalAttributes.add(createTextElement("ENTAuxEnsClassesMatieres", "", doc)); additionalAttributes.add(createTextElement("ENTAuxEnsGroupes", "", doc)); additionalAttributes.add(createTextElement("ENTAuxEnsClasses", "", doc)); additionalAttributes.add(createTextElement("ENTAuxEnsMEFs", "", doc)); break; case "Personnel": rootProfiles = createElement("ENTPersonProfils", doc); rootProfiles.appendChild(createTextElement("ENTPersonProfil", "National_DOC", doc)); additionalAttributes.add(rootProfiles); additionalAttributes.add(createTextElement("ENTEleveMEF", "", doc)); additionalAttributes.add(createTextElement("ENTEleveCodeEnseignements", "", doc)); additionalAttributes.add(createTextElement("ENTEleveClasses", "", doc)); additionalAttributes.add(createTextElement("ENTEleveGroupes", "", doc)); additionalAttributes.add(createTextElement("ENTAuxEnsClassesMatieres", "", doc)); additionalAttributes.add(createTextElement("ENTAuxEnsGroupes", "", doc)); additionalAttributes.add(createTextElement("ENTAuxEnsClasses", "", doc)); additionalAttributes.add(createTextElement("ENTAuxEnsMEFs", "", doc)); break; } } catch (Exception e) { log.error("Failed to transform User for KNE", e); } }