@Test public void setLdapUser_test() { AcmLdapSyncConfig acmLdapSyncConfig = new AcmLdapSyncConfig(); acmLdapSyncConfig.setUserIdAttributeName("samAccountName"); acmLdapSyncConfig.setMailAttributeName("mail"); acmLdapSyncConfig.setBaseDC("dc=armedia"); acmLdapSyncConfig.setAllUsersSortingAttribute("cn"); acmLdapSyncConfig.setDirectoryType("openldap"); acmLdapSyncConfig.setUserDomain("armedia.com"); unit = new AcmUserContextMapper(acmLdapSyncConfig); DirContextAdapter dirContextAdapter = new DirContextAdapter(); dirContextAdapter.setAttributeValue("cn", "common"); dirContextAdapter.setAttributeValue("userAccountControl", "user account control"); dirContextAdapter.setAttributeValue("givenName", "given name"); dirContextAdapter.setAttributeValue("mail", "ann-acm@armedia.com"); dirContextAdapter.setAttributeValue("co", "United States of America"); dirContextAdapter.setAttributeValue("c", "USA"); dirContextAdapter.setAttributeValue("company", "armedia"); dirContextAdapter.setAttributeValue("department", "technical"); dirContextAdapter.setAttributeValue("title", "admin"); dirContextAdapter.setAttributeValue("samAccountName", "ann-acm"); dirContextAdapter.setAttributeValue("userPrincipalName", "ann-acm"); dirContextAdapter.setAttributeValue("uid", null); dirContextAdapter.setAttributeValue("memberOf", "arkcase"); LdapUser user = unit.mapToLdapUser(dirContextAdapter); assertNotNull(user); assertNotNull(user.getUserId()); assertEquals(user.getUserId(), "ann-acm@armedia.com"); assertNotNull(user.getMail()); assertEquals(user.getMail(), "ann-acm@armedia.com"); assertNotNull(user.getCountry()); assertEquals(user.getCountry(), "United States of America"); assertNotNull(user.getCountryAbbreviation()); assertEquals(user.getCountryAbbreviation(), "USA"); assertNotNull(user.getCompany()); assertEquals(user.getCompany(), "armedia"); assertNotNull(user.getDepartment()); assertEquals(user.getDepartment(), "technical"); assertNotNull(user.getTitle()); assertEquals(user.getTitle(), "admin"); }
protected LdapUser mapToLdapUser(DirContextAdapter adapter) { LdapUser user = new LdapUser(); user.setDirectoryName(acmLdapSyncConfig.getDirectoryName()); user.setLastName(MapperUtils.getAttribute(adapter, "sn")); user.setFirstName(MapperUtils.getAttribute(adapter, "givenName")); String fullName = String.format("%s %s", user.getFirstName(), user.getLastName()); user.setFullName(fullName); String uac = MapperUtils.getAttribute(adapter, "userAccountControl"); if (isUserDisabled(uac)) { log.debug("User [{}] is disabled and won't be synced", fullName); user.setState(AcmUserState.DISABLED.name()); } else { user.setState(AcmUserState.VALID.name()); } user.setDistinguishedName(MapperUtils.appendToDn(adapter.getDn().toString(), acmLdapSyncConfig.getBaseDC())); String userId = MapperUtils.getAttribute(adapter, acmLdapSyncConfig.getUserIdAttributeName()); user.setUserId(MapperUtils.buildUserId(userId, acmLdapSyncConfig.getUserDomain())); user.setMail(MapperUtils.getAttribute(adapter, acmLdapSyncConfig.getMailAttributeName())); user.setCountry(MapperUtils.getAttribute(adapter, "co")); user.setCountryAbbreviation(MapperUtils.getAttribute(adapter, "c")); user.setCompany(MapperUtils.getAttribute(adapter, "company")); user.setDepartment(MapperUtils.getAttribute(adapter, "department")); user.setTitle(MapperUtils.getAttribute(adapter, "title")); user.setsAMAccountName(MapperUtils.getAttribute(adapter, "samAccountName")); user.setUserPrincipalName(MapperUtils.getAttribute(adapter, "userPrincipalName")); user.setUid(MapperUtils.getAttribute(adapter, "uid")); user.setSortableValue(MapperUtils.getAttribute(adapter, acmLdapSyncConfig.getAllUsersSortingAttribute())); user.setPasswordExpirationDate(Directory.valueOf(acmLdapSyncConfig.getDirectoryType()).getPasswordExpirationDate(adapter)); return user; }
AcmUserContextMapper implements ContextMapper { protected LdapUser mapToLdapUser(DirContextAdapter adapter) { LdapUser user = new LdapUser(); user.setDirectoryName(acmLdapSyncConfig.getDirectoryName()); user.setLastName(MapperUtils.getAttribute(adapter, "sn")); user.setFirstName(MapperUtils.getAttribute(adapter, "givenName")); String fullName = String.format("%s %s", user.getFirstName(), user.getLastName()); user.setFullName(fullName); String uac = MapperUtils.getAttribute(adapter, "userAccountControl"); if (isUserDisabled(uac)) { log.debug("User [{}] is disabled and won't be synced", fullName); user.setState(AcmUserState.DISABLED.name()); } else { user.setState(AcmUserState.VALID.name()); } user.setDistinguishedName(MapperUtils.appendToDn(adapter.getDn().toString(), acmLdapSyncConfig.getBaseDC())); String userId = MapperUtils.getAttribute(adapter, acmLdapSyncConfig.getUserIdAttributeName()); user.setUserId(MapperUtils.buildUserId(userId, acmLdapSyncConfig.getUserDomain())); user.setMail(MapperUtils.getAttribute(adapter, acmLdapSyncConfig.getMailAttributeName())); user.setCountry(MapperUtils.getAttribute(adapter, "co")); user.setCountryAbbreviation(MapperUtils.getAttribute(adapter, "c")); user.setCompany(MapperUtils.getAttribute(adapter, "company")); user.setDepartment(MapperUtils.getAttribute(adapter, "department")); user.setTitle(MapperUtils.getAttribute(adapter, "title")); user.setsAMAccountName(MapperUtils.getAttribute(adapter, "samAccountName")); user.setUserPrincipalName(MapperUtils.getAttribute(adapter, "userPrincipalName")); user.setUid(MapperUtils.getAttribute(adapter, "uid")); user.setSortableValue(MapperUtils.getAttribute(adapter, acmLdapSyncConfig.getAllUsersSortingAttribute())); user.setPasswordExpirationDate(Directory.valueOf(acmLdapSyncConfig.getDirectoryType()).getPasswordExpirationDate(adapter)); return user; } }
AcmUserContextMapper implements ContextMapper { protected LdapUser mapToLdapUser(DirContextAdapter adapter) { LdapUser user = new LdapUser(); user.setDirectoryName(acmLdapSyncConfig.getDirectoryName()); user.setLastName(MapperUtils.getAttribute(adapter, "sn")); user.setFirstName(MapperUtils.getAttribute(adapter, "givenName")); String fullName = String.format("%s %s", user.getFirstName(), user.getLastName()); user.setFullName(fullName); String uac = MapperUtils.getAttribute(adapter, "userAccountControl"); if (isUserDisabled(uac)) { log.debug("User [{}] is disabled and won't be synced", fullName); user.setState(AcmUserState.DISABLED.name()); } else { user.setState(AcmUserState.VALID.name()); } user.setDistinguishedName(MapperUtils.appendToDn(adapter.getDn().toString(), acmLdapSyncConfig.getBaseDC())); String userId = MapperUtils.getAttribute(adapter, acmLdapSyncConfig.getUserIdAttributeName()); user.setUserId(MapperUtils.buildUserId(userId, acmLdapSyncConfig.getUserDomain())); user.setMail(MapperUtils.getAttribute(adapter, acmLdapSyncConfig.getMailAttributeName())); user.setCountry(MapperUtils.getAttribute(adapter, "co")); user.setCountryAbbreviation(MapperUtils.getAttribute(adapter, "c")); user.setCompany(MapperUtils.getAttribute(adapter, "company")); user.setDepartment(MapperUtils.getAttribute(adapter, "department")); user.setTitle(MapperUtils.getAttribute(adapter, "title")); user.setsAMAccountName(MapperUtils.getAttribute(adapter, "samAccountName")); user.setUserPrincipalName(MapperUtils.getAttribute(adapter, "userPrincipalName")); user.setUid(MapperUtils.getAttribute(adapter, "uid")); user.setSortableValue(MapperUtils.getAttribute(adapter, acmLdapSyncConfig.getAllUsersSortingAttribute())); user.setPasswordExpirationDate(Directory.valueOf(acmLdapSyncConfig.getDirectoryType()).getPasswordExpirationDate(adapter)); return user; } AcmUserContextMapper(AcmLdapSyncConfig acmLdapSyncConfig); }
AcmUserContextMapper implements ContextMapper { protected LdapUser mapToLdapUser(DirContextAdapter adapter) { LdapUser user = new LdapUser(); user.setDirectoryName(acmLdapSyncConfig.getDirectoryName()); user.setLastName(MapperUtils.getAttribute(adapter, "sn")); user.setFirstName(MapperUtils.getAttribute(adapter, "givenName")); String fullName = String.format("%s %s", user.getFirstName(), user.getLastName()); user.setFullName(fullName); String uac = MapperUtils.getAttribute(adapter, "userAccountControl"); if (isUserDisabled(uac)) { log.debug("User [{}] is disabled and won't be synced", fullName); user.setState(AcmUserState.DISABLED.name()); } else { user.setState(AcmUserState.VALID.name()); } user.setDistinguishedName(MapperUtils.appendToDn(adapter.getDn().toString(), acmLdapSyncConfig.getBaseDC())); String userId = MapperUtils.getAttribute(adapter, acmLdapSyncConfig.getUserIdAttributeName()); user.setUserId(MapperUtils.buildUserId(userId, acmLdapSyncConfig.getUserDomain())); user.setMail(MapperUtils.getAttribute(adapter, acmLdapSyncConfig.getMailAttributeName())); user.setCountry(MapperUtils.getAttribute(adapter, "co")); user.setCountryAbbreviation(MapperUtils.getAttribute(adapter, "c")); user.setCompany(MapperUtils.getAttribute(adapter, "company")); user.setDepartment(MapperUtils.getAttribute(adapter, "department")); user.setTitle(MapperUtils.getAttribute(adapter, "title")); user.setsAMAccountName(MapperUtils.getAttribute(adapter, "samAccountName")); user.setUserPrincipalName(MapperUtils.getAttribute(adapter, "userPrincipalName")); user.setUid(MapperUtils.getAttribute(adapter, "uid")); user.setSortableValue(MapperUtils.getAttribute(adapter, acmLdapSyncConfig.getAllUsersSortingAttribute())); user.setPasswordExpirationDate(Directory.valueOf(acmLdapSyncConfig.getDirectoryType()).getPasswordExpirationDate(adapter)); return user; } AcmUserContextMapper(AcmLdapSyncConfig acmLdapSyncConfig); @Override LdapUser mapFromContext(Object ctx); }
AcmUserContextMapper implements ContextMapper { protected LdapUser mapToLdapUser(DirContextAdapter adapter) { LdapUser user = new LdapUser(); user.setDirectoryName(acmLdapSyncConfig.getDirectoryName()); user.setLastName(MapperUtils.getAttribute(adapter, "sn")); user.setFirstName(MapperUtils.getAttribute(adapter, "givenName")); String fullName = String.format("%s %s", user.getFirstName(), user.getLastName()); user.setFullName(fullName); String uac = MapperUtils.getAttribute(adapter, "userAccountControl"); if (isUserDisabled(uac)) { log.debug("User [{}] is disabled and won't be synced", fullName); user.setState(AcmUserState.DISABLED.name()); } else { user.setState(AcmUserState.VALID.name()); } user.setDistinguishedName(MapperUtils.appendToDn(adapter.getDn().toString(), acmLdapSyncConfig.getBaseDC())); String userId = MapperUtils.getAttribute(adapter, acmLdapSyncConfig.getUserIdAttributeName()); user.setUserId(MapperUtils.buildUserId(userId, acmLdapSyncConfig.getUserDomain())); user.setMail(MapperUtils.getAttribute(adapter, acmLdapSyncConfig.getMailAttributeName())); user.setCountry(MapperUtils.getAttribute(adapter, "co")); user.setCountryAbbreviation(MapperUtils.getAttribute(adapter, "c")); user.setCompany(MapperUtils.getAttribute(adapter, "company")); user.setDepartment(MapperUtils.getAttribute(adapter, "department")); user.setTitle(MapperUtils.getAttribute(adapter, "title")); user.setsAMAccountName(MapperUtils.getAttribute(adapter, "samAccountName")); user.setUserPrincipalName(MapperUtils.getAttribute(adapter, "userPrincipalName")); user.setUid(MapperUtils.getAttribute(adapter, "uid")); user.setSortableValue(MapperUtils.getAttribute(adapter, acmLdapSyncConfig.getAllUsersSortingAttribute())); user.setPasswordExpirationDate(Directory.valueOf(acmLdapSyncConfig.getDirectoryType()).getPasswordExpirationDate(adapter)); return user; } AcmUserContextMapper(AcmLdapSyncConfig acmLdapSyncConfig); @Override LdapUser mapFromContext(Object ctx);  }