Splitting LDAP commonname (cn) into firstname, other stuff - SOLVED
Eric Wedaa
Eric.Wedaa at marist.edu
Mon Nov 16 16:13:04 EST 2015
All;
This solved my problem of our LDAP does not populate the firstname attribute.
I couldn't get regex stuff to work. What did work was javascript to split cn (commonname) at the first "space". Yes, I know there are people with firstnames with spaces in them, as well as all the other corner cases. Management has decided to split their "cn" at the first space and call it good.
What follows works for me with IDP 2.4.0
If you want to split on a period (.), then you neet to add brackets "[.]" in your split string.
>>>>>>>>Ericw
in attribute-resolver.xml...
<!-- This Works -->
<!-- Script is really javascript. -->
<!-- Script to set to dash "-" if cn is empty, AND split on " " on LDAP cn-->
<!-- -->
<!-- You have to copy cn to another value (gnvalue) because cn is a -->
<!-- special variable WITHOUT all the standard javascript string functions -->
<!-- The "var" declaration is a way of passing a shibboleth LDAP attribute -->
<!-- to the javascript. -->
<resolver:AttributeDefinition id="firstname" xsi:type="Script"
xmlns="urn:mace:shibboleth:2.0:resolver:ad" sourceAttributeID="cn">
<resolver:Dependency ref="myLDAP" />
<resolver:AttributeEncoder xsi:type="SAML2String"
xmlns="urn:mace:shibboleth:2.0:attribute:encoder" name="firstname" />
<Script><![CDATA[
importPackage(Packages.edu.internet2.middleware.shibboleth.common.attribute.provider);
firstname = new BasicAttribute("firstname");
var cn;
if (cn != null && cn.getValues().size() > 0) {
gnvalue = cn.getValues().get(0);
result=gnvalue.split(" ");
gnvalue = result[0];
} else {
gnvalue = "-";
}
firstname.getValues().add(gnvalue);
]]></Script>
</resolver:AttributeDefinition>
More information about the users
mailing list