Penrose 0.9.9 Mapping Rules

Dynamic Entry with One Source

Here we will generate a mapping that can map each row in the "groups" table to an entry in the virtual directory. Assume that we have defined a source called "g" to represent the "groups" table.

<entry dn="cn=...,ou=groups,dc=penrose,dc=safehaus,dc=org">
    <oc>groupOfUniqueNames</oc>
    <at name="cn" rdn="true">
        <expression>g.groupname</expression>
    </at>
    <at name="description">
        <expression>g.description</expression>
    </at>

    <source name="g">
        <source-name>groups</source-name>
        <field name="groupname">
            <expression>cn</expression>
        </field>
        <field name="description">
            <expression>description</expression>
        </field>
    </source>
</entry>

The "..." in the dn indicates that the values of the cn attribute are dynamically generated. In the attribute definition, cn attribute gets the values from the groupname field in source g. The rdn="true" indicates that the cn attribute will be used in the rdn.

The description attribute gets its values from the description field in source g.

In g's groupname field, we define that it will get the value from the cn attribute. Similarly, the description field will get the value from the description attribute.

Dynamic Entry with Multiple Sources

Here we will add another source to the previous example to map the user-group membership. Assume we have defined a source called "ug" that represents the "usergroups" table.

<entry dn="cn=...,ou=groups,dc=penrose,dc=safehaus,dc=org">
    <oc>groupOfUniqueNames</oc>
    <at name="cn" rdn="true">
        <expression>g.groupname</expression>
    </at>
    <at name="description">
        <expression>g.description</expression>
    </at>
    <at name="uniqueMember">
        <expression>
if (ug == void || ug == null) return null;
return "uid="+ug.username+",ou=users,dc=penrose,dc=safehaus,dc=org";
        </expression>
    </at>

    <source name="g">
        <source-name>groups</source-name>
        <field name="groupname">
            <expression>cn</expression>
        </field>
        <field name="description">
            <expression>description</expression>
        </field>
    </source>

    <source name="ug">
        <source-name>usergroups</source-name>
        <field name="groupname">
            <expression>cn</expression>
        </field>
        <field name="username">
            <expression>
if (uniqueMember == void || uniqueMember == null) return null;
int i = uniqueMember.indexOf("=");
int j = uniqueMember.indexOf(",", i+1);
return uniqueMember.substring(i+1, j);
            </expression>
        </field>
    </source>

    <relationship>
        <expression>g.groupname = ug.groupname</expression>
    </relationship>

</entry>

Notice that we define the relationship between the two sources as g.groupname = ug.groupname.

The uniqueMember attribute will get the values from the ug's username column. In reverse, ug's username will get the values from the uniqueMember attribute.

Nested Mapping

Here we will define the mapping for the children of the above mapping. This mapping will map users that belong to the parent group. Assume we have defined a source called "u" that represents the "users" table. We can link this mapping to the parent mapping by adding a relationship ug.username = u.username where ug has been defined above.

<entry dn="uid=...,cn=...,ou=groups,dc=penrose,dc=safehaus,dc=org">
    <oc>person</oc>
    <oc>inetOrgPerson</oc>
    <at name="uid" rdn="true">
      <expression>u.username</expression>
    </at>
    <at name="cn">
      <expression>u.firstName+" "+u.lastName</expression>
    </at>
    <at name="sn">
      <expression>u.lastName</expression>
    </at>
    <at name="userPassword">
      <expression>u.password</expression>
    </at>
    <source name="u">
      <source-name>users</source-name>
      <field name="username">
        <expression>uid</expression>
      </field>
      <field name="firstName">
        <expression>
if (cn == void || cn == null) return null;
int i = cn.lastIndexOf(" ");
return cn.substring(0, i);
        </expression>
      </field>
      <field name="lastName">
        <expression>
if (cn == void || cn == null) return null;
int i = cn.lastIndexOf(" ");
return cn.substring(i+1);
        </expression>
      </field>
      <field name="password">
        <expression>userPassword</expression>
      </field>
    </source>
    <relationship>
      <expression>ug.username = u.username</expression>
    </relationship>
</entry>