import org.springframework.ldap.core.LdapTemplate;
@Autowired
private LdapTemplate ldapTemplate;
private class PersonAttributesMapper implements AttributesMapper {
public Object mapFromAttributes(Attributes attrs)
throws NamingException {
Person userInfo = new Person ();
userInfo.setUsername((String) attrs.get("cn").get());
userInfo.setFirstName((String) attrs.get("givenname").get());
userInfo.setLastName((String) attrs.get("sn").get());
userInfo.setDisplayName((String) attrs.get("displayName").get());
userInfo.setApproved(true);
return userInfo;
}
}
try {
String dn=”login”
Person userInfo = (Person) ldapTemplate.lookup(dn,
new PersonAttributesMapper());
} catch (NameNotFoundException e) {
logger.info("Not Found in ldap " + loginId);
}
No comments:
Post a Comment