Announcement Announcement Module
Collapse
No announcement yet.
Bitfields (disabled users) Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Bitfields (disabled users)

    Hi,

    Is there a way to filter on bitfields in Spring-LDAP? Specifically, I'm trying to filter to find only active (non-disabled) users in Active Directory. I can do it directly with (!(userAccountControl:1.2.840.113556.1.4.803:=2)) but there doesn't seem to be any way to do this with the filters. Is there a way besides plugging into LdapTemplate directly? For example, some sort of way to do:

    AndFilter filter = new AndFilter();
    filter.and(new NotFilter(new BitAndFilter("userAccountControl",2)));

    If not, I'll subclass my own filter, but this seems like it would be something that'd come up more than just for me.

  • #2
    No, this isn't anything we've come across before. I guess a specific filter implementation would probably be the way to do it. If you happen to invent a good solution and would like to share it, we'd probably be interested in including it in the library.

    Comment


    • #3
      I don't know if this is what would constitute a good solution, but it certainly works for me. At last, we can now use arcane Active Directory operations.

      Code:
      package org.springframework.ldap.support.filter;
      
      /**
       * A filter for a bitwise AND in Active Directory. E.g.:
       * 
       * <pre>
       *     BitwiseAndFilter filter = new BitwiseAndFilter(&quot;userAccountControl&quot;, 2);
       *     System.out.println(filter.encode());    
       * </pre>
       * 
       * would result in: <code>(userAccountControl:1.2.840.113556.1.4.803:=2)</code>
       * 
       * @author Jonathan Eisenstein
       */
      public class BitwiseAndFilter extends CompareFilter {
      
          private static final String LDAP_MATCHING_RULE_BIT_AND = "1.2.840.113556.1.4.803";
      
      
          /**
           * @param attribute
           * @param value
           */
          public BitwiseAndFilter(String attribute, int value) {
              super(attribute, value);
          }
          
          protected String getCompareString() {
              return ":"+LDAP_MATCHING_RULE_BIT_AND+":=";
          }
      }
      
      
      
      package org.springframework.ldap.support.filter;
      
      /**
       * A filter for a bitwise OR in Active Directory. E.g.:
       * 
       * <pre>
       *     BitwiseOrFilter filter = new BitwiseOrFilter(&quot;userAccountControl&quot;, 2);
       *     System.out.println(filter.encode());    
       * </pre>
       * 
       * would result in: <code>(userAccountControl:1.2.840.113556.1.4.804:=2)</code>
       * 
       * @author Jonathan Eisenstein
       */
      public class BitwiseOrFilter extends CompareFilter {
      
          private static final String LDAP_MATCHING_RULE_BIT_OR = "1.2.840.113556.1.4.804";
      
      
          /**
           * @param attribute
           * @param value
           */
          public BitwiseOrFilter(String attribute, int value) {
              super(attribute, value);
          }
          
          protected String getCompareString() {
              return ":"+LDAP_MATCHING_RULE_BIT_OR+":=";
          }
      }

      Comment

      Working...
      X