Hello LSC experts,

I try to map one source attribute into 2 destination attribute :
- sAMAccountName -> uid
- {SASL} + sAMAccountName + "@example.com" -> userPassword

I made my own bean (to manager source attributes that are not in
destination directory).

The solution I found is to use a private variable, but maybe there is a
better solution?


My code looks like:

public class inetOrgPersonBean extends AbstractBean implements IBean {
        private static String valTmp = null;
        public static inetOrgPersonBean getInstance(inetOrgPerson myclass) 
throws
IllegalArgumentException, IllegalAccessException,
InvocationTargetException, NamingException {
                inetOrgPersonBean bean = new inetOrgPersonBean() ;
                AbstractBean.mapper(inetOrgPersonBean.class, bean, myclass);
                bean.generateDn();
                return bean;
        }

        public inetOrgPersonBean() {
                super();
        }

        public static void mapSAMAccountName(inetOrgPerson soc, IBean doc, List
values) throws NamingException {
                if (values != null && values.size() > 0) {
                        Vector<String> v = new Vector<String>();
                        Iterator valuesIter = values.iterator();
                        while (valuesIter.hasNext()) {
                                String value = (String) valuesIter.next();
                                if (value != null && value.trim().length() > 0) 
{
                                        mapString(doc, "uid", 
FrenchFilters.filterString(value));
                                        valTmp = value;
                                }
                        }
                }
        }

        public static void mapUserPassword(inetOrgPerson soc, IBean doc, List
values) throws NamingException {
                generateUserPassword(soc,doc);
        }

        public static void generateUserPassword(inetOrgPerson soc, IBean doc)
throws NamingException {
                String value = "{SASL}" + valTmp + "@example.com";
                Attribute attr = new BasicAttribute("userPassword");
                attr.add(value);
                doc.setAttribute(attr);
        }

        public static void mapCn(inetOrgPerson soc, IBean doc, List values)
throws NamingException {
        }

        public static void mapDisplayName(inetOrgPerson soc, IBean doc, String
value) throws NamingException {
                if (value != null && value.trim().length() > 0) {
                        mapString(doc, "cn", FrenchFilters.filterString(value));
                }
        }

        public void generateDn() throws NamingException {
                setDistinguishName("uid=" + getAttributeById("uid").get() + "," 
+
"ou=users" );
        }

}


Thanks for your help,

Cl?ment.

Reply via email to