spring-ldap icon indicating copy to clipboard operation
spring-ldap copied to clipboard

Attribute Name Case Sensitive - Bug or User Error?

Open fmvintu opened this issue 11 years ago • 0 comments
trafficstars

Hi All,

I am not sure if it is a bug or a user error, that's why I am posting here. I have found a "problem" with Spring Ldap, and, as it is a user added attribute to the class, I am not sure if it is a bug or a user error. In my model class, LdapUser, I have added an attribute with the following:

@Attribute(name="lastLogonTimeStamp")
private String lastLogonTimeStamp;

But the correct attribute name in AD is: lastLogonTimestamp (lowercase "s").

Using ODM, If I search for an object (LdapUser) in AD, this attribute lastLogonTimeStamp, is filled, but if I try to update using: ldapTemplate.update(ldapUser); , as the attributes names are different: - AD: lastLogonTimestamp - My: lastLogonTimeStamp

this attribute is marked to be updated, and an attempt is made to update it, but as it is an immutable attribute in AD, an error is reported:

Exception in thread "main" org.springframework.ldap.OperationNotSupportedException: [LDAP: error code 53 - 0000209A: SvcErr: DSID-031A0DD5, problem 5003 (WILL_NOT_PERFORM), data 0
]; nested exception is javax.naming.OperationNotSupportedException: [LDAP: error code 53 - 0000209A: SvcErr: DSID-031A0DD5, problem 5003 (WILL_NOT_PERFORM), data 0
]; remaining name 'CN=test name,OU=Test OU'
    at org.springframework.ldap.support.LdapUtils.convertLdapException(LdapUtils.java:212)
    at org.springframework.ldap.core.LdapTemplate.executeWithContext(LdapTemplate.java:820)
    at org.springframework.ldap.core.LdapTemplate.executeReadWrite(LdapTemplate.java:812)
    at org.springframework.ldap.core.LdapTemplate.modifyAttributes(LdapTemplate.java:964)
    at org.springframework.ldap.core.LdapTemplate.modifyAttributes(LdapTemplate.java:1317)
    at org.springframework.ldap.core.LdapTemplate.update(LdapTemplate.java:1778)
    at com.br.xxxxx.ldap.dao.generic.abstrac.AbstractLdapOdmDAOImpl.update(AbstractLdapOdmDAOImpl.java:71)
    at com.br.xxxxx.ldap.dao.user.LdapUserOdmDAOImpl.update(LdapUserOdmDAOImpl.java:41)
    at com.br.xxxxx.main.LdapReportUsers.updateUserAttribute(LdapReportUsers.java:379)
    at com.br.xxxxx.main.LdapReportUsers.mainInternal(LdapReportUsers.java:458)
    at com.br.xxxxx.main.LdapReportUsers.main(LdapReportUsers.java:474)

The possible bug is in class: NameAwareAttribute, method: equals(Object o), where it compares the attribute IDs (names) (line 281):

     if (id != null ? !id.equals(that.id) : that.id != null) return false;

The values for the variables are (debugging with eclipse): - AD: lastLogonTimestamp - [l, a, s, t, L, o, g, o, n, T, i, m, e, s, t, a, m, p] - My: lastLogonTimeStamp - [l, a, s, t, L, o, g, o, n, T, i, m, e, S, t, a, m, p]

Here it is marked to be updated:

DEBUG org.springframework.ldap.core.DirContextAdapter  - Number of modifications:**2**

I don't know a lot about Ldap servers (if there is one that is case sensitive), but one possible solution would be, as id is String (private final String id), to use:

     if (id != null ? !id.**equalsIgnoreCase**(that.id) : that.id != null) return false;

My test code is:

    public void updateUserAttribute(String userName) {
        LdapUser ldapUser = localLdapDAOProvider.getLdapUserDAO().findOneBySAMAccountName(userName);
        logger.info("ldapUser: [" + ldapUser + "]");

        String message = "Test: " + DateUtil.getSystemFormattedDate(new Date());

        // Sets AD "description" field
        ldapUser.setDescription(ldapUser.getDescription().trim() + " - " + message);
        logger.info("ldapUser: [" + ldapUser.getDescription() + "]. Updating...");

        // This calls ldapTemplate.update(ldapUser);
        localLdapDAOProvider.getLdapUserDAO().update(ldapUser);
    }

Sorry if the problem is not clear and if so, let me know and I will try to explain it better.

I am using Spring Ldap version 2.0.2, java JDK version 1.7.0_51-b13

Thanks and regards.

fmvintu avatar Sep 05 '14 14:09 fmvintu