keycloak
静的公開メンバ関数 | 静的非公開メンバ関数 | 全メンバ一覧
org.keycloak.storage.ldap.idm.store.ldap.LDAPUtil クラス
org.keycloak.storage.ldap.idm.store.ldap.LDAPUtil 連携図
Collaboration graph

静的公開メンバ関数

static final String formatDate (Date date)
 
static final Date parseDate (String date)
 
static String convertObjectGUIToByteString (byte[] objectGUID)
 
static String decodeObjectGUID (byte[] objectGUID)
 

静的非公開メンバ関数

static String convertToDashedString (byte[] objectGUID)
 
static String prefixZeros (int value)
 

詳解

Utility class for working with LDAP.

著者
Pedro Igor

関数詳解

◆ convertObjectGUIToByteString()

static String org.keycloak.storage.ldap.idm.store.ldap.LDAPUtil.convertObjectGUIToByteString ( byte []  objectGUID)
inlinestatic

Creates a byte-based String representation of a raw byte array representing the value of the objectGUID attribute retrieved from Active Directory.

The returned string is useful to perform queries on AD based on the objectGUID value. Eg.:

String filter = "(&(objectClass=*)(objectGUID" + EQUAL + convertObjectGUIToByteString(objectGUID) + "))";

引数
objectGUIDA raw byte array representing the value of the objectGUID attribute retrieved from Active Directory.
戻り値
A byte-based String representation in the form of [0][1][2][3][4][5][6][7][8][9][10][11][12][13][14][15]
100  {
101  StringBuilder result = new StringBuilder();
102 
103  for (int i = 0; i < objectGUID.length; i++) {
104  String transformed = prefixZeros((int) objectGUID[i] & 0xFF);
105  result.append("\\");
106  result.append(transformed);
107  }
108 
109  return result.toString();
110  }
static String prefixZeros(int value)
Definition: LDAPUtil.java:164

◆ convertToDashedString()

static String org.keycloak.storage.ldap.idm.store.ldap.LDAPUtil.convertToDashedString ( byte []  objectGUID)
inlinestaticprivate
137  {
138  StringBuilder displayStr = new StringBuilder();
139 
140  displayStr.append(prefixZeros((int) objectGUID[3] & 0xFF));
141  displayStr.append(prefixZeros((int) objectGUID[2] & 0xFF));
142  displayStr.append(prefixZeros((int) objectGUID[1] & 0xFF));
143  displayStr.append(prefixZeros((int) objectGUID[0] & 0xFF));
144  displayStr.append("-");
145  displayStr.append(prefixZeros((int) objectGUID[5] & 0xFF));
146  displayStr.append(prefixZeros((int) objectGUID[4] & 0xFF));
147  displayStr.append("-");
148  displayStr.append(prefixZeros((int) objectGUID[7] & 0xFF));
149  displayStr.append(prefixZeros((int) objectGUID[6] & 0xFF));
150  displayStr.append("-");
151  displayStr.append(prefixZeros((int) objectGUID[8] & 0xFF));
152  displayStr.append(prefixZeros((int) objectGUID[9] & 0xFF));
153  displayStr.append("-");
154  displayStr.append(prefixZeros((int) objectGUID[10] & 0xFF));
155  displayStr.append(prefixZeros((int) objectGUID[11] & 0xFF));
156  displayStr.append(prefixZeros((int) objectGUID[12] & 0xFF));
157  displayStr.append(prefixZeros((int) objectGUID[13] & 0xFF));
158  displayStr.append(prefixZeros((int) objectGUID[14] & 0xFF));
159  displayStr.append(prefixZeros((int) objectGUID[15] & 0xFF));
160 
161  return displayStr.toString();
162  }
static String prefixZeros(int value)
Definition: LDAPUtil.java:164

◆ decodeObjectGUID()

static String org.keycloak.storage.ldap.idm.store.ldap.LDAPUtil.decodeObjectGUID ( byte []  objectGUID)
inlinestatic

Decode a raw byte array representing the value of the objectGUID attribute retrieved from Active Directory.

The returned string is useful to directly bind an entry. Eg.:

String bindingString = decodeObjectGUID(objectGUID);
Attributes attributes = ctx.getAttributes(bindingString);

引数
objectGUIDA raw byte array representing the value of the objectGUID attribute retrieved from Active Directory.
戻り値
A string representing the decoded value in the form of [3][2][1][0]-[5][4]-[7][6]-[8][9]-[10][11][12][13][14][15].
129  {
130  StringBuilder displayStr = new StringBuilder();
131 
132  displayStr.append(convertToDashedString(objectGUID));
133 
134  return displayStr.toString();
135  }
static String convertToDashedString(byte[] objectGUID)
Definition: LDAPUtil.java:137

◆ formatDate()

static final String org.keycloak.storage.ldap.idm.store.ldap.LDAPUtil.formatDate ( Date  date)
inlinestatic

Formats the given date.

引数
dateThe Date to format.
戻り値
A String representing the formatted date.
40  {
41  if (date == null) {
42  throw new IllegalArgumentException("You must provide a date.");
43  }
44 
45  SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss'.0Z'");
46 
47  dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
48 
49  return dateFormat.format(date);
50  }

◆ parseDate()

static final Date org.keycloak.storage.ldap.idm.store.ldap.LDAPUtil.parseDate ( String  date)
inlinestatic

Parses dates/time stamps stored in LDAP. Some possible values:

  • 20020228150820
  • 20030228150820Z
  • 20050228150820.12
  • 20060711011740.0Z
引数
dateThe date string to parse from.
戻り値
the Date.
67  {
68  SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
69 
70  try {
71  if (date.endsWith("Z")) {
72  dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
73  } else {
74  dateFormat.setTimeZone(TimeZone.getDefault());
75  }
76 
77  return dateFormat.parse(date);
78  } catch (Exception e) {
79  throw new ModelException("Error converting ldap date.", e);
80  }
81  }

◆ prefixZeros()

static String org.keycloak.storage.ldap.idm.store.ldap.LDAPUtil.prefixZeros ( int  value)
inlinestaticprivate
164  {
165  if (value <= 0xF) {
166  StringBuilder sb = new StringBuilder("0");
167  sb.append(Integer.toHexString(value));
168  return sb.toString();
169  } else {
170  return Integer.toHexString(value);
171  }
172  }

このクラス詳解は次のファイルから抽出されました: