Comment récupérer les données en sortie d'un connecteur LDAP ?

1
0
-1

Bonjour, Je cherche à créer un sous-processus d'identification via un Active Directory que je pourrais intégrer à différents processus, celui-ci doit retourner les informations (toutes de préférence) de l'utilisateur. Pour cela, je cherche à stocker les données en sortie du connecteur LDAP (la variable s'appelle ldapAttributeList) et c'est là que je bloque.

Pouvez-vous m'aider à configurer un tel connecteur pour récupérer les données de l'utilisateur ? Je prends tout ! Conseils, exemples, recommandation. Je suis en version Community (et Community seulement).

3 answers

1
+3
-1
This one is the BEST answer!

Bonjour, Mon problème est résolu ! En réalité des caractères incompatible avec la norme XML provoquaient ces erreurs !

Voici le code me permettant de créer mon hashmap avec les vérifications :

import org.bonitasoft.connectors.ldap.LdapAttribute;
import java.text.AttributedCharacterIterator.Attribute;
import java.util.HashMap;
import java.util.Map;

//res_hashmap is the dictionnary returned
HashMap<String, HashMap<String, String>> res_hashmap = new HashMap<String, HashMap<String, String>>();

//Creating working variables
String temp_value = new String()
String temp_name = new String()

// Creating patterns (regexp based) matching illegal xml caracters (XML1.0 & XML1.1)
String xml10pattern = "[^" + "\u0009\r\n" + "\u0020-\uD7FF"     + "\uE000-\uFFFD" + "\ud800\udc00-\udbff\udfff" + "]";
String xml11pattern = "[^" + "\u0001-\uD7FF" + "\uE000-\uFFFD" + "\ud800\udc00-\udbff\udfff" + "]+";

for (user in ldapAttributeList){
        //Creating temp_hashmap for storing the users attribute
        HashMap<String, String> temp_hashmap = new HashMap<String, String>();
       
        for (attr in user){
               
                if (attr.getValue() != null & attr.getName() != null & attr != null){
                        //Converting value of attribute in UTF8
                        try{
                                temp_value = attr.getValue().replaceAll(xml10pattern, "").replaceAll(xml11pattern, "")
                                temp_value = new String(temp_value.getBytes("UTF8"), "UTF8");
                        }
                        catch (UnsupportedEncodingException e) {
                                temp_value = e.printStackTrace();
                        }
                       
                        //Converting name of attribute in UTF8
                        try{
                                temp_name = attr.getName().replaceAll(xml10pattern, "").replaceAll(xml11pattern, "")
                                temp_name = new String(temp_name.getBytes("UTF8"), "UTF8");
                        }
                        catch (UnsupportedEncodingException e) {
                                temp_name = e.printStackTrace();
                        }
                }
                //Storing them into the temp_hashmap
                temp_hashmap.put(temp_name, temp_value)
        }
        //Adding user attrs hasmap to the hashmap of user attrs
        res_hashmap.put(temp_hashmap["cn"], temp_hashmap);
}
return new HashMap<String, HashMap<String, String>>(res_hashmap)

En espérant que ça en aide certains dans l'avenir !

1
0
-1

Bonjour, J'ai essayé le code suivant qui me retourne une map fonctionnelle (en mode test dans l'écran de configuration du connecteur LDAP):

import org.bonitasoft.connectors.ldap.LdapAttribute;

//Res map is the dictionnary returned
HashMap<String, Object> result_hashmap = new HashMap<String, Object>();

for (user in ldapAttributeList){
        //Creating temp_hashmap for storing the users attribute
        HashMap<String, Object> temp_hashmap = new HashMap<String, Object>();
       
        for (attr in user){
                temp_hashmap.put(attr.getName(), attr.getValue())
        }
       
        result_hashmap.put(temp_hashmap["cn"], temp_hashmap);
}

return result_hashmap

Cependant, lorsque j'essais de le stocker dans une variable de type java.util.Map, même après avoir configuré l'output du script, le connecteur est en état d'échec. Alors que ce code est fonctionnel. Avez-vous une idée ?

Comments

Submitted by guilleminotvincent on Wed, 06/04/2014 - 16:12

Est-ce que le fait de stocker le résultat de ce script dans une variable de type java.util.Map provoque cette erreur ? Je pose cette question car cet objet est une interface ! Cependant, même en essayant de stocker la résultat du script dans une variable de même type que le résultat (HashMap) cela ne fonctionne pas !

1
0
-1

Bonjour,

la variable de retour ldapAttributeList s'est une List<List> de la class org.bonitasoft.connectors.ldap.LdapAttribute

pour transformer c'est list of lists d'attributes vous pouvez utiliser un script de Groovy pour retourner a List<List> et montrer ce resultat dans une table.

par exemple:

import org.bonitasoft.connectors.ldap.*;

def table = []

// get the attribute names to create the table's Header
def singleRow = ldapAttributeList[0]
def headers = []
for (att in singleRow) {
  headers.add(att.getName())
}
table.add(headers)

// get all attribute values
for (user in ldapAttributeList) {
  def userAttributes = []
  for (att in user) {
        userAttributes.add(att.getValue())
  }
  table.add(userAttributes)
}
return table

Important! le return type doit etre: java.util.List Vous devez assigner ce resultat a une variable Java du même type.

si vous voulez traiter le resultat comme un java.util.Map vouz pouvez utiliser le meme code que l'utilisateur @guilleminotvincent a partagé dans une autre questione recent:

import org.bonitasoft.connectors.ldap.LdapAttribute;
def temp_list = [:]
ldapAttributeList[0].each {
temp_list.put((it.getName()), (it.getValue()))
}
return new HashMap<String, String>(temp_list)

Important! **le return type doit etre: **java.util.Map

Bon chance! Jordi

Comments

Submitted by guilleminotvincent on Thu, 06/05/2014 - 09:27

Bonjour, J'ai modifié le code d'origine pour retourner un hashmap mieux formé :

import org.bonitasoft.connectors.ldap.LdapAttribute;

//Res is the dictionnary returned
HashMap<String, Object> res_hashmap = new HashMap<String, Object>();

for (user in ldapAttributeList){
       
        //Creating temp_hashmap for storing the users attribute
        HashMap<String, Object> temp_hashmap = new HashMap<String, Object>();
       
        for (attr in user){
                temp_hashmap.put(attr.getName(),attr.getValue())
        }
       
        res_hashmap.put(temp_hashmap["cn"], temp_hashmap);
}

return res_hashmap

L'objet retourné est conforme à mes attentes, les tests fonctionnent, cependant lorsque je tente de stocker l'objet retourné dans un objet java de type hashmap ou map, une erreur se produit. -- Le stockage est donc la partie qui pose problèmes. -- J'ai essayé plusieurs paramétrages, sans succès.

Avez-vous une idée ? Peut-être qu'il n'est pas possible de stocker dans un objet map car celui-ci est une interface ?

Submitted by jordi.anguela_1 on Thu, 06/05/2014 - 13:07

Bonjour, je viens d'essayer votre code et ç'a marché pour moi: * Meme script * Variable de retour du script : java.util.Map * Variable de processus : java.util.Map (listLdapUsers)

J'ai pu recuperer les donnes d'un utilisateur de mons LDAP avec: listLdapUsers.get("Harish") par example, sans problème.

Peut-être qu'il n'est pas possible de stocker dans un objet map car celui-ci est une interface ? NO, c'est ne pas vrai. on peut stocker l'information dans une variable même si on utilise une interface

revisez les donnes que vous recouperer dans votre requet LDAP. Regardez les traces avec des possibles Exceptions Java qui vous aviez dans les fichiers des logs du Moteur ou du Studio.

Jordi

Submitted by guilleminotvincent on Thu, 06/05/2014 - 13:43

Bonjour, Comment est-il possible d'accéder aux log du studio ? Merci

Submitted by guilleminotvincent on Thu, 06/05/2014 - 13:54

J'ai réussi à trouver les logs ! Voici le stacktrace :

juin 05, 2014 1:52:33 PM org.bonitasoft.engine.log.technical.TechnicalLoggerSLF4JImpl log
WARNING: Error while executing connector with id 57
com.thoughtworks.xstream.converters.ConversionException:  : ParseError at [row,col]:[1,3533]
Message: Un caractère XML non valide (Unicode : 0x5) a été détecté dans le contenu d'élément du document. :  : ParseError at [row,col]:[1,3533]
Message: Un caractère XML non valide (Unicode : 0x5) a été détecté dans le contenu d'
élément du document.
---- Debugging information ----
message             :  : ParseError at [row,col]:[1,3533]
Message: Un caractère XML non valide (Unicode : 0x5) a été détecté dans le contenu d'élément du document.
cause-exception     : com.thoughtworks.xstream.io.StreamException
cause-message       :  : ParseError at [row,col]:[1,3533]
Message: Un caractère XML non valide (Unicode : 0x5) a été détecté dans le contenu d'
élément du document.
class               : java.lang.String
required-type       : java.lang.String
converter-type      : com.thoughtworks.xstream.converters.SingleValueConverterWrapper
wrapped-converter   : com.thoughtworks.xstream.converters.basic.StringConverter
path                : /map/entry[2]/map/entry[7]/string[2]
line number         : 1
class[1]            : java.util.HashMap
converter-type[1]   : com.thoughtworks.xstream.converters.collections.MapConverter
version             : null
-------------------------------
        at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:79)
        at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:65)
        at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:66)
        at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:50)
        at com.thoughtworks.xstream.converters.collections.AbstractCollectionConverter.readItem(AbstractCollectionConverter.java:71)
        at com.thoughtworks.xstream.converters.collections.MapConverter.putCurrentEntryIntoMap(MapConverter.java:89)
        at com.thoughtworks.xstream.converters.collections.MapConverter.populateMap(MapConverter.java:77)
        at com.thoughtworks.xstream.converters.collections.MapConverter.populateMap(MapConverter.java:71)
        at com.thoughtworks.xstream.converters.collections.MapConverter.unmarshal(MapConverter.java:66)
        at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:72)
        at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:65)
        at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:66)
        at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:50)
        at com.thoughtworks.xstream.converters.collections.AbstractCollectionConverter.readItem(AbstractCollectionConverter.java:71)
        at com.thoughtworks.xstream.converters.collections.MapConverter.putCurrentEntryIntoMap(MapConverter.java:89)
        at com.thoughtworks.xstream.converters.collections.MapConverter.populateMap(MapConverter.java:77)
        at com.thoughtworks.xstream.converters.collections.MapConverter.populateMap(MapConverter.java:71)
        at com.thoughtworks.xstream.converters.collections.MapConverter.unmarshal(MapConverter.java:66)
        at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:72)
        at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:65)
        at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:66)
        at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:50)
        at com.thoughtworks.xstream.core.TreeUnmarshaller.start(TreeUnmarshaller.java:134)
        at com.thoughtworks.xstream.core.AbstractTreeMarshallingStrategy.unmarshal(AbstractTreeMarshallingStrategy.java:32)
        at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:1052)
        at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:1036)
        at com.thoughtworks.xstream.XStream.fromXML(XStream.java:912)
        at com.thoughtworks.xstream.XStream.fromXML(XStream.java:903)
        at org.bonitasoft.engine.data.instance.model.impl.SXMLObjectDataInstanceImpl.revert(SXMLObjectDataInstanceImpl.java:64)
        at org.bonitasoft.engine.data.instance.model.impl.SXMLObjectDataInstanceImpl.getValue(SXMLObjectDataInstanceImpl.java:43)
        at org.bonitasoft.engine.data.instance.model.archive.impl.SAXMLObjectDataInstanceImpl.<init>(SAXMLObjectDataInstanceImpl.java:39)
        at org.bonitasoft.engine.data.instance.model.archive.builder.impl.SADataInstanceBuilderFactoryImpl.createNewInstance(SADataInstanceBuilderFactoryImpl.java:58)
        at org.bonitasoft.engine.data.instance.api.impl.DataInstanceServiceImpl.archiveDataInstance(DataInstanceServiceImpl.java:144)
        at org.bonitasoft.engine.data.instance.api.impl.DataInstanceServiceImpl.archiveDataInstance(DataInstanceServiceImpl.java:138)
        at org.bonitasoft.engine.data.instance.api.impl.DataInstanceServiceImpl.updateDataInstance(DataInstanceServiceImpl.java:766)
        at org.bonitasoft.engine.core.operation.impl.UpdateOperationExecutorStrategy.update(UpdateOperationExecutorStrategy.java:42)
        at org.bonitasoft.engine.core.operation.impl.UpdateOperationExecutorStrategy.updateDataInstance(UpdateOperationExecutorStrategy.java:69)
        at org.bonitasoft.engine.core.operation.impl.UpdateOperationExecutorStrategy.update(UpdateOperationExecutorStrategy.java:54)
        at org.bonitasoft.engine.core.operation.impl.OperationServiceImpl.execute(OperationServiceImpl.java:141)
        at org.bonitasoft.engine.core.connector.impl.ConnectorServiceImpl.executeOutputOperation(ConnectorServiceImpl.java:204)
        at org.bonitasoft.engine.connector.ConnectorServiceDecorator.executeOutputOperation(ConnectorServiceDecorator.java:111)
        at org.bonitasoft.engine.execution.work.ExecuteConnectorWork.evaluateOutput(ExecuteConnectorWork.java:103)
        at org.bonitasoft.engine.execution.work.ExecuteConnectorOfActivity.evaluateOutput(ExecuteConnectorOfActivity.java:77)
        at org.bonitasoft.engine.execution.work.ExecuteConnectorWork$EvaluateConnectorOutputsTxContent.call(ExecuteConnectorWork.java:269)
        at org.bonitasoft.engine.execution.work.ExecuteConnectorWork$EvaluateConnectorOutputsTxContent.call(ExecuteConnectorWork.java:252)
        at org.bonitasoft.engine.transaction.JTATransactionServiceImpl.executeInTransaction(JTATransactionServiceImpl.java:257)
        at org.bonitasoft.engine.execution.work.ExecuteConnectorWork.work(ExecuteConnectorWork.java:127)
        at org.bonitasoft.engine.execution.work.FailureHandlingBonitaWork.work(FailureHandlingBonitaWork.java:73)
        at org.bonitasoft.engine.work.BonitaWork.run(BonitaWork.java:56)
        at org.bonitasoft.engine.work.SequenceRunnableExecutor.innerRun(SequenceRunnableExecutor.java:45)
        at org.bonitasoft.engine.work.BonitaRunnable.run(BonitaRunnable.java:35)
        at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
        at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
        at java.util.concurrent.FutureTask.run(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)
Caused by: com.thoughtworks.xstream.io.StreamException:  : ParseError at [row,col]:[1,3533]
Message: Un caractère XML non valide (Unicode : 0x5) a été détecté dans le contenu d'élément du document.
        at com.thoughtworks.xstream.io.xml.StaxReader.pullNextEvent(StaxReader.java:73)
        at com.thoughtworks.xstream.io.xml.AbstractPullReader.readRealEvent(AbstractPullReader.java:148)
        at com.thoughtworks.xstream.io.xml.AbstractPullReader.readEvent(AbstractPullReader.java:135)
        at com.thoughtworks.xstream.io.xml.AbstractPullReader.getValue(AbstractPullReader.java:180)
        at com.thoughtworks.xstream.io.ReaderWrapper.getValue(ReaderWrapper.java:48)
        at com.thoughtworks.xstream.converters.SingleValueConverterWrapper.unmarshal(SingleValueConverterWrapper.java:49)
        at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:72)
        ... 56 more
Caused by: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,3533]
Message: Un caractère XML non valide (Unicode : 0x5) a été détecté dans le contenu d'
élément du document.
        at com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.next(Unknown Source)
        at com.thoughtworks.xstream.io.xml.StaxReader.pullNextEvent(StaxReader.java:58)
        ... 62 more
Submitted by jordi.anguela_1 on Thu, 06/05/2014 - 15:00
Submitted by jordi.anguela_1 on Thu, 06/05/2014 - 18:58

Re-salut,

je l'impression que ça viens d'un problème avec l'information que vous recouperez de votre LDAP --> caractères non reconnus (c'est qui dit votre trace d'exception)

Je vous propos de limiter votre requête LDAP a un seul utilisateur en utilisant un filtre. exemple: (&(objectClass=person)(uid=john))

et de bien regarder qu'il n'y pas de caracteres bizarres dans la reponse avant de lancer le connecteur

Bon chance!

Submitted by guilleminotvincent on Fri, 06/06/2014 - 10:27

Le problème est d'ores et déjà résolu, (cf. début du thread).

Merci beaucoup pour votre implication !

Submitted by jordi.anguela_1 on Fri, 06/06/2014 - 11:12

de rien, merci d'avoir partagé la solution!

Notifications