Le 15/09/15 18:01, Clément OUDOT <[email protected]> a écrit :
>
>
>
>
>
>
>
>
>
> Le 15/09/2015 14:43, "POISSON Frédéric" a écrit :
>
>
> > Hello all,
> >
> > I have an LSC synchronization configuration from DSEE LDAP to OpenLDAP,
> > and some fields on source are stored with ISO-8859-1 charset. And i have to
> > convert them to UTF8.
> >
> > I search around org.lsc.utils.StringUtils and also with Java documentation
> > but i succeed. I try also some example of code like :
> >
> > byte[] bytesISO = ... ; byte[] bytesUTF8 = new String(bytesISO,
> > "UTF-8").getBytes(); But without success when LSC try to evaluate
> > thejava_script code. Do you have already done that before ?
> >
>
> Hi,
>
> I did not do that before, but it seems that can be done injava_script or
> groovy:
> *
> http://stackoverflow.com/questions/5396560/how-do-i-convert-special-utf-8-chars-to-their-iso-8859-1-equivalent-using-javasc
> *
> http://stackoverflow.com/questions/7281583/convert-iso-8859-1-to-utf-8-using-groovy
>
> That could work in LSC.
>
>
> -- Clément OUDOT
> Consultant en logiciels libres, Expert infrastructure et sécurité
> Savoir-faire Linux
>
>
>
>
Hi,
Thanks Clément for the proposal. Finally i found a solution without any
specific Javascript code !
The problem is that the source LDAP directory (an old Sun iPlanet Directory
server) accept the non standard schema value of DirectoryString (which must be
UTF8 i suppose). And so the JVM of LSC must have the same encoding parameter.
So i configure my SHELL environment with LANG=en_US.iso88591, then i configure
the attribute as <binaryAttributes> inside my source connection (in my case cn,
description, etc.).
And inside dataset configuration i put something like that :
<dataset>
<name>cn</name>
<policy>FORCE</policy>
<forceValues>
<string>js:srcBean.getDatasetFirstValueById("cn")+""</string>
</forceValues>
</dataset>
This configuration has the disadvantage of getting CN attribute value as a
Javascript Object instead of simple Javascript String. Which was a problem for
me for memberOf attribute manipulation.
So for the memberOf manipulation (which contains cn of groups) i do this
conversion code (red line):
function memberOfDataset()
{
var main = new javax.naming.ldap.LdapName( srcBean.getMainIdentifier() );
var LdapDestbase = new javax.naming.ldap.LdapName('dc=test');
var LdapSrcbase = new javax.naming.ldap.LdapName('dc=example');
var domaine;
if ( main.getPrefix(1).equals(LdapSrcbase) )
{
domaine = main.getPrefix( main.size()-3 ).getSuffix(1);
//ou=groups,ou=public,o=domain.tld,dc=example
try {
var org = srcLdap.search("ou=public,"+domaine, "(ou=groups)");
try {
var groups = srcLdap.attribute(srcLdap.search(org,"(uniqueMember=" +
srcBean.getMainIdentifier() + ")"), 'cn').toArray();
var tab = new Array();
for (var i=0; i < groups.length; i++ ) {
// La valeur d'un cn est codé en binaire il faut donc convertir les codes ASCII
var groupText = "";
for(var j=0; j < groups[i].length; j++)
groupText += String.fromCharCode(groups[i][j]);
tab[i] = new javax.naming.ldap.LdapName("cn="
+ groupText
+ ",ou=Groups,"
+ main.getPrefix( main.size()-3 ).getSuffix(1)
+ ","
+ LdapDestbase ) + "";
}
return tab;
} catch(e) {
println("ERROR " + e);
}
} catch(e) {
println("ERROR " + e);
}
}
}
Voilà :-)
Hoping this could help someone, if it has this type of problem...
Regards,
--
Frederic Poisson
_______________________________________________________________
Ldap Synchronization Connector (LSC) - http://lsc-project.org
lsc-users mailing list
[email protected]
http://lists.lsc-project.org/listinfo/lsc-users