spring-projects / spring-projects/spring-ldap

Attribute Name Case Sensitive - Bug or User Error?

Open
#11 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
375
Forks
501
Avg merge
6h 4m
Merged PRs (30d)
63

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with NameAwareAttribute.equals(Object o), especially the attribute-ID comparison around line 281, and trace how it produces the two modifications in DirContextAdapter during ldapTemplate.update(ldapUser). Reproduce the case difference using the provided LdapUser and Active Directory example; done means the behavior for differently cased attribute names is clearly established and covered by an appropriate regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.