View Full Version : Bitfields (disabled users)
JEisen
May 1st, 2007, 10:20 AM
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.
rasky
May 1st, 2007, 12:51 PM
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.
JEisen
May 1st, 2007, 04:00 PM
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.
package org.springframework.ldap.support.filter;
/**
* A filter for a bitwise AND in Active Directory. E.g.:
*
* <pre>
* BitwiseAndFilter filter = new BitwiseAndFilter("userAccountControl", 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("userAccountControl", 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+":=";
}
}
Powered by vBulletin® Version 4.2.1 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.