* @throws NamingException if an LDAP naming exception occurs
*/
protected void readUserProfile(DirContext dirContext, User user)
throws NamingException {
LdapNameMapping nameMap = getConfiguration().getUserProperties().getUserProfileMapping();
UserAttributeMap userProf = user.getProfile();
UserAttributeMap configured = getConfiguration().getIdentityConfiguration().getUserAttributeMap();
/* There were some issues with the initial integration of
* Apache's LDAP implementation. The section below ensures that a user's
* profile contains all configured attributes, even if they do not exist on
* the LDAP side.
*/
boolean bEnsureAllAttributes = true;
if (bEnsureAllAttributes) {
for (UserAttribute attr: configured.values()) {
if (!userProf.containsKey(attr.getKey())) {
userProf.set(attr.getKey(),"");
}
}
}
String sUserDN = user.getDistinguishedName();
if (sUserDN.length() > 0) {
// read current LDAP attribute values
NamingEnumeration<?> enAttr = null;
try {
Attributes attributes = dirContext.getAttributes(sUserDN);
if (attributes != null) {
enAttr = attributes.getAll();
while (enAttr.hasMore()) {
Object oAttr = enAttr.next();
if (oAttr instanceof Attribute) {
Attribute attr = (Attribute)oAttr;
String sLdapKey = attr.getID();
Object oVal = attr.get();
// set the corresponding application user attribute
String sAppKey = Val.chkStr(nameMap.findApplicationName(sLdapKey));
if ((sAppKey.length() > 0) && configured.containsKey(sAppKey)) {
if (oVal instanceof String) {
userProf.set(sAppKey,(String)oVal);
} else if (oVal == null) {
userProf.set(sAppKey,"");
}