public class LdapAttrDef
extends java.lang.Object
Each LdapSecurityProvider references a map of attribute definitions of type Map<String,LdapAttrDef>. The default definitions of an LdapSecurityProvider are determined by the ldap.disposition property. In practice, users will rarely if ever want to query or modify these default definitions.
Each LdapAttrDef object has type, flags and conv members. As attribute values are retrieved and set, their attribute definitions are used to determine if a value should be represented a List (because it is multi-valued) or to optionally convert values transparently to and from representations more suitable for use internally to Java.
Consider the following code fragment which creates and inserts a new attribute definition for a custom attribute. The attribute is defined as binary, single-valued and will automatically be converted to and from Base64 encoding for use within Java.
LdapSecurityProvider lsp = new LdapSecurityProvider(props); try { Map<String,LdapAttrDef> attrdefs = (Map)lsp.getProperty("ldap.attributes.definitions"); LdapAttrDef def = new LdapAttrDef( LdapAttrDef.TYPE_BINARY, LdapAttrDef.FLAG_SINGLE_VALUED, LdapAttrDef.CONV_BASE64_X_BINARY); attrdefs.put("someAttribute", def); lsp.setProperty("ldap.attributes.definitions", attrdefs); Map entry = lsp.getEntry(dn, new String[] { "someAttribute" }); String someAttribute = (String)entry.get("someAttribute"); System.out.println("someAttribute: " + someAttribute); } finally { lsp.dispose(); }
Although it is possible and valid to change the type and flags of existing attribute definitions, it is much more common to change only the conv member.
Constant Identifier | Value | Java Type | Description |
---|---|---|---|
TYPE_STRING | 1 | String | A string presumably containing text. This is the most common attribute type. Fortunately regardless of how strings are stored within the directory, they are always represented within the LDAP communications protocol as UTF-8 and the default behavior is to convert these strings into a standard Java String (unless converted otherwise using an attribute conversion). |
TYPE_BOOLEAN | 2 |
String | A true or false value.
Because Map.get() and other methods used to retrieve and set attribute values cannot return the Java boolean type, a String "true" or "false" is used to represent boolean values (unless converted otherwise using an attribute conversion).
To manually convert a boolean attribute value into a boolean Java type, use the expression "true".equals(sval) .
|
TYPE_BINARY | 3 |
byte[] | An squence of bytes. By default this attribute value will be represented as a byte[] array. However, in practice, most binary attributes have default attribute definition conversions that return a Base64 String, jespa.util.SID or another more user-friendly type. If this behavior is not desired, these default conversions can be disabled by setting the attribute definition conv member to 0. |
TYPE_TIME | 4 |
String | A type that represents a time or date and time.
Within the directory these attribute values are usually represented as either timestamps or 64 bit integers.
Because Map.get() and other methods for retrieving and setting attribute values cannot return a long, the Java type used to represent these values is always String (unless converted otherwise using an attribute conversion).
In practice, default attribute definitions convert known date and time attributes into a 64 bit integer String representing the number of milliseconds since January 1, 1970, 00:00:00 GMT.
To manually convert this value into a long, use an expression like Long.parseLong(sval) .
To manually convert this value into a java.util.Date, use an expression like new Date(Long.parseLong(sval)) .
|
TYPE_INT32 | 5 |
String |
Because Map.get() and other methods for retrieving and setting attribute values cannot return an int type, the Java type used is always a String representing a 32 bit integer (unless converted otherwise using an attribute conversion).
To manually convert this value to an int, use an expression like Integer.parseInt(sval) .
Note: Beware that because Java integers are always signed, int values larger than 2^31 will be considered less than zero in conditional expressions.
|
TYPE_INT64 | 6 |
String |
Because the Map.get() method and other methods for retrieving and setting attribute values cannot return a long type, the Java type used is always a String representing a 64 bit integer (unless converted otherwise using an attribute conversion).
To manually convert this value to a long, use an expression like Long.parseLong(sval) .
Note: Beware that because Java integers are always signed, long values larger than 2^63 will be considered less than zero in conditional expressions.
|
Constant Identifier | Value | Description |
---|---|---|
FLAG_SINGLE_VALUED |
0x04
|
Indicates that the value is single-valued. If this flag is not set, the attribute is multi-valued. |
FLAG_DN |
0x10
|
Indicates that the value is a Distinguished Name (DN). |
FLAG_PROTECTED |
0x20
|
Indicates that the attribute is special and cannot be set. Currently the only attribute definition that has this flag is the distinguishedName attribute and currently no logic within the Jespa implementation actually uses this flag. |
FLAG_CONSTRUCTED |
0x40
|
Indicates that the attribute value is dynamically generated on the LDAP server when the attribute is queried. Currently only the default attribute definitions for the tokenGroups and unicodePwd attributes have this flag although there are many other Active Directory attributes that are constructed. |
The programming constant identifiers for conv values are always organized as CONV_<int>_X_<dir> where <int> is the internal representation within Java to and from which the value will be converted and <dir> is the directory representation of values in the LDAP directory. For example, CONV_TIME1970M_X_TIMEUTC means UTC date strings in the directory will be automatically converted to and from milliseconds since 1970 for use internally with Java. The conversion CONV_BASE64_X_BINARY means binary attributes will be automatically converted to and from Base64 encoding within your Java code.
Conversion | Value | Description |
---|---|---|
CONV_BASE64_X_BINARY | 3 |
Convert the attribute value between a Base64 encoded string within Java and binary within the directory. |
CONV_SID_X_BINARY | 4 |
Convert the attribute value between a jespa.util.SID Object and a binary SID within the directory.
Even though the jespa.util.SID class is not documented, it's equals method may be used to compare SID Objects and it's toString method may be used to return the common textual representation of a Windows SID like This is the default conversion for the Active Directory attributes objectSid and tokenGroups. To obtain the binary representation of these attributes, it will be necessary to turn this conversion off by setting the attribute definition's conv member to 0. |
CONV_TIME1970M_X_TIMEUTC | 5 |
Convert the attribute value between an integer representing a time in milliseconds since 1970 and a UTC date string within the directory.
For example, a UTC date string like 20100419233721.0Z will be automatically converted to and from the integer 1271720241414 representing the same time in milliseconds since 1970.
Note: Even though the ideal Java type for milliseconds would be long, Map.get() and other methods for retrieving attribute values always return Objects and therefore a String object representing an integer is returned. To convert this to a long it will be necessary to use an expression like
long lval = Long.parseLong(sval) .
|
CONV_TIME1970M_X_TIME1601 | 6 |
Convert the attribute value between an integer representing a time in milliseconds since 1970 and the Active Directory specific nanoseconds since 1601 time representation in the directory.
For example, a nanoseconds since 1601 time like 128980276368532080 will be automatically converted to and from the integer 1253554036853 representing the same time in milliseconds since 1970.
Note: Even though the ideal Java type for milliseconds would be long, Map.get() and other methods for retrieving attribute values always return Objects and therefore a String object representing an integer is returned. To convert this to a long it will be necessary to use an expression like
long lval = Long.parseLong(sval) .
|
CONV_DATESTR_X_TIMEUTC | 8 |
Convert the attribute value between a formatted date string and a UTC date string within the directory.
For example, a UTC date string like 20100419233721.0Z will be automatically converted to and from a formatted date string like 2010-04-19 19:37:21 .
Note: The date string format can be changed by setting the ldap.attributes.date.format property for the LdapSecurityProvider being used.
|
CONV_DATESTR_X_TIME1601 | 9 |
Convert the attribute value between a formatted date string and the Active Directory specific nanoseconds since 1601 time representation in the directory.
For example, a nanoseconds since 1601 time like 128980276368532080 will be automatically converted to and from a formatted date string like 2009-09-21 13:27:16 .
Note: The date string format can be changed by setting the ldap.attributes.date.format property for the LdapSecurityProvider being used.
|
LdapSecurityProvider lsp = new LdapSecurityProvider(props); try { Map<String,LdapAttrDef> attrdefs = (Map)lsp.getProperty("ldap.attributes.definitions"); LdapAttrDef def = attrdefs.get("nTSecurityDescriptor"); // This turns off the default automatic conversion of nTSecurityDescriptor value to Base64 string def.conv = 0; lsp.setProperty("ldap.attributes.definitions", attrdefs); Map entry = lsp.getEntry(dn, new String[] { "nTSecurityDescriptor" }); // Note: You must be an Administrator to query this attribute byte[] nTSecurityDescriptor = (byte[])entry.get("nTSecurityDescriptor"); jespa.util.Hexdump.hexdump(System.out, nTSecurityDescriptor, 0, nTSecurityDescriptor.length); } finally { lsp.dispose(); } -- output -- 00000: 01 00 14 8C F4 09 00 00 10 0A 00 00 14 00 00 00 |....ô...........| 00010: 8C 00 00 00 04 00 78 00 02 00 00 00 07 5A 38 00 |......x......Z8.| 00020: 20 00 00 00 03 00 00 00 BE 3B 0E F3 F0 9F D1 11 | .......¾;.óð.Ñ.| 00030: B6 03 00 00 F8 03 67 C1 A5 7A 96 BF E6 0D D0 11 |¶...ø.gÁ¥z.¿æ.Ð.| ...
The following example (from the LdapSearch
utility) illustrates how to change time conversions from milliseconds to formatted date strings ideal for displaying directly to users.
Meaning instead of returning and accepting attribute values that represent times as milliseconds since 1970 like 1200075597043
, time values are formatted localized date strings like 2010-04-19 19:37:21
.
LdapSecurityProvider provider = new LdapSecurityProvider(props); try { HashMap<String,LdapAttrDef> attrdefs = (HashMap)provider.getProperty("ldap.attributes.definitions"); Iterator<String> iter = attrdefs.keySet().iterator(); while (iter.hasNext()) { String key = iter.next(); LdapAttrDef def = attrdefs.get(key); if (def.conv == LdapAttrDef.CONV_TIME1970M_X_TIMEUTC) { def.conv = LdapAttrDef.CONV_DATESTR_X_TIMEUTC; } else if (def.conv == LdapAttrDef.CONV_TIME1970M_X_TIME1601) { def.conv = LdapAttrDef.CONV_DATESTR_X_TIME1601; } } provider.setProperty("ldap.attributes.definitions", attrdefs); ... } finally { provider.dispose(); }
Default attibute definitions for Active directory and RFC based servers are hardcoded into the Jespa implementation. Additionally, some attribute definitions are deliberately incorrect. For example, the description attribute is defined in the Active Directory schema as multi-valued although the default Jespa attribute definition defines it as single-valued because Microsoft utilities that use this attribute always treat it as single-valued.
Modifier and Type | Field and Description |
---|---|
int |
conv |
static int |
CONV_BASE64_X_BINARY
See table in Attribute Definition Conversions section
|
static int |
CONV_DATESTR_X_TIME1601
See table in Attribute Definition Conversions section
|
static int |
CONV_DATESTR_X_TIMEUTC
See table in Attribute Definition Conversions section
|
static int |
CONV_HEXSTRING_X_BINARY
Reserved, do not use.
|
static int |
CONV_INT32_X_STRING
Reserved, do not use.
|
static int |
CONV_SID_X_BINARY
See table in Attribute Definition Conversions section
|
static int |
CONV_STRING_X_BINARY
Reserved, do not use.
|
static int |
CONV_TIME1970M_X_TIME1601
See table in Attribute Definition Conversions section
|
static int |
CONV_TIME1970M_X_TIMEUTC
See table in Attribute Definition Conversions section
|
static int |
FLAG_CASE_EXACT
See table in Attribute Definition Flags section
|
static int |
FLAG_CONSTRUCTED
See table in Attribute Definition Flags section
|
static int |
FLAG_DN
See table in Attribute Definition Flags section
|
static int |
FLAG_PROTECTED
See table in Attribute Definition Flags section
|
static int |
FLAG_SINGLE_VALUED
See table in Attribute Definition Flags section
|
static int |
FLAG_UNDEFINED
Reserved, do not use.
|
int |
flags |
int |
type |
static int |
TYPE_BINARY
See table in Attribute Definition Types section
|
static int |
TYPE_BOOLEAN
See table in Attribute Definition Types section
|
static int |
TYPE_INT32
See table in Attribute Definition Types section
|
static int |
TYPE_INT64
See table in Attribute Definition Types section
|
static int |
TYPE_STRING
See table in Attribute Definition Types section
|
static int |
TYPE_TIME
See table in Attribute Definition Types section
|
Constructor and Description |
---|
LdapAttrDef(int type,
int flags,
int conv) |
Modifier and Type | Method and Description |
---|---|
static java.util.HashMap |
getDefaults(java.lang.String disposition) |
java.lang.String |
toString() |
public static final int TYPE_STRING
public static final int TYPE_BOOLEAN
public static final int TYPE_BINARY
public static final int TYPE_TIME
public static final int TYPE_INT32
public static final int TYPE_INT64
public static final int FLAG_UNDEFINED
public static final int FLAG_SINGLE_VALUED
public static final int FLAG_CASE_EXACT
public static final int FLAG_DN
public static final int FLAG_PROTECTED
public static final int FLAG_CONSTRUCTED
public static final int CONV_INT32_X_STRING
public static final int CONV_STRING_X_BINARY
public static final int CONV_BASE64_X_BINARY
public static final int CONV_SID_X_BINARY
public static final int CONV_TIME1970M_X_TIMEUTC
public static final int CONV_TIME1970M_X_TIME1601
public static final int CONV_HEXSTRING_X_BINARY
public static final int CONV_DATESTR_X_TIMEUTC
public static final int CONV_DATESTR_X_TIME1601
public int type
public int flags
public int conv