com.unboundid.ldap.sdk.Attribute类的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(11.9k)|赞(0)|评价(0)|浏览(210)

本文整理了Java中com.unboundid.ldap.sdk.Attribute类的一些代码示例,展示了Attribute类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Attribute类的具体详情如下:
包路径:com.unboundid.ldap.sdk.Attribute
类名称:Attribute

Attribute介绍

[英]This class provides a data structure for holding information about an LDAP attribute, which includes an attribute name (which may include a set of attribute options) and zero or more values. Attribute objects are immutable and cannot be altered. However, if an attribute is included in an Entry object, then it is possible to add and remove attribute values from the entry (which will actually create new Attribute object instances), although this is not allowed for instances of ReadOnlyEntry and its subclasses.

This class uses the term "attribute name" as an equivalent of what the LDAP specification refers to as an "attribute description". An attribute description consists of an attribute type name or object identifier (which this class refers to as the "base name") followed by zero or more attribute options, each of which should be prefixed by a semicolon. Attribute options may be used to provide additional metadata for the attribute and/or its values, or to indicate special handling for the values. For example, RFC 3866 describes the use of attribute options to indicate that a value may be associated with a particular language (e.g., "cn;lang-en-US" indicates that the values of that cn attribute should be treated as U.S. English values), and RFC 4522 describes a binary encoding option that indicates that the server should only attempt to interact with the values as binary data (e.g., "userCertificate;binary") and should not treat them as strings. An attribute name (which is technically referred to as an "attribute description" in the protocol specification) may have zero, one, or multiple attribute options. If there are any attribute options, then a semicolon is used to separate the first option from the base attribute name, and to separate each subsequent attribute option from the previous option.

Attribute values can be treated as either strings or byte arrays. In LDAP, they are always transferred using a binary encoding, but applications frequently treat them as strings and it is often more convenient to do so. However, for some kinds of data (e.g., certificates, images, audio clips, and other "blobs") it may be desirable to only treat them as binary data and only interact with the values as byte arrays. If you do intend to interact with string values as byte arrays, then it is important to ensure that you use a UTF-8 representation for those values unless you are confident that the directory server will not attempt to treat the value as a string.
[中]此类提供了一个数据结构,用于保存有关LDAP属性的信息,其中包括属性名称(可能包括一组属性选项)和零个或多个值。属性对象是不可变的,不能更改。但是,如果条目对象中包含属性,则可以从条目中添加和删除属性值(这将实际创建新的属性对象实例),尽管ReadOnlyEntry及其子类的实例不允许这样做。
此类使用术语“属性名称”作为LDAP规范所指的“属性描述”的等价物。属性描述由属性类型名称或对象标识符(此类称之为“基本名称”)和零个或多个属性选项组成,每个属性选项的前缀应为分号。属性选项可用于为属性和/或其值提供附加元数据,或指示对值的特殊处理。例如,RFC 3866描述了属性选项的使用,以指示某个值可能与特定语言相关联(例如,“cn;lang en US”表示该cn属性的值应被视为美国英语值),RFC 4522描述了一个二进制编码选项,该选项指示服务器只应尝试将值作为二进制数据(例如,“userCertificate;binary”)进行交互,而不应将其视为字符串。属性名称(在协议规范中技术上称为“属性描述”)可以有零个、一个或多个属性选项。如果存在任何属性选项,则使用分号将第一个选项与基本属性名称分隔,并将每个后续属性选项与前一个选项分隔。
属性值可以被视为字符串或字节数组。在LDAP中,它们总是使用二进制编码进行传输,但应用程序经常将它们视为字符串,这样做通常更方便。然而,对于某些类型的数据(例如,证书、图像、音频剪辑和其他“blob”),可能希望仅将其视为二进制数据,并且仅与值作为字节数组进行交互。如果您确实打算将字符串值作为字节数组进行交互,则必须确保对这些值使用UTF-8表示,除非您确信目录服务器不会尝试将该值视为字符串。

代码示例

代码示例来源:origin: com.unboundid/unboundid-ldapsdk-commercial-edition

/**
  * Retrieves an attribute that is equivalent to this compact attribute.
  *
  * @return  An attribute that is equivalent to this compact attribute.
  */
 Attribute toAttribute()
 {
  return new Attribute(name, values);
 }
}

代码示例来源:origin: com.unboundid/unboundid-ldapsdk-commercial-edition

/**
 * Adds the provided value to the set of values for this attribute.
 *
 * @param  attrBytes  The value to add to this attribute.
 */
public void addValue(final byte[] attrBytes)
{
 attribute = Attribute.mergeAttributes(attribute,
    new Attribute(attribute.getName(), attrBytes));
}

代码示例来源:origin: apiman/apiman

@Override
public String getAsString() {
  return attribute.getValue();
}

代码示例来源:origin: com.unboundid/unboundid-ldapsdk-commercial-edition

/**
 * Removes the provided value from this attribute.
 *
 * @param  attrValue  The value to remove.
 */
public void removeValue(final String attrValue)
{
 attribute = Attribute.removeValues(attribute,
    new Attribute(attribute.getName(), attrValue));
}

代码示例来源:origin: com.unboundid/unboundid-ldapsdk-commercial-edition

/**
 * Creates a compact attribute from the provided attribute.
 *
 * @param  attribute  The attribute to use to create this compact attribute.
 */
CompactAttribute(final Attribute attribute)
{
 name = internName(attribute.getName());
 values = attribute.getValueByteArrays();
}

代码示例来源:origin: com.unboundid/unboundid-ldapsdk-commercial-edition

final String baseName = StaticUtils.toLowerCase(a.getBaseName());
if (baseSourceNames.contains(baseName))
 if (a.hasOptions())
  for (final String option : a.getOptions())
 newName = a.getName();
     instanceof DistinguishedNameMatchingRule))
 final String[] originalValues = a.getValues();
 newValues = new String[originalValues.length];
 for (int i=0; i < originalValues.length; i++)
 newValues = a.getValues();
newAttributes.add(new Attribute(newName, schema, newValues));

代码示例来源:origin: com.nimbusds/common

} else {
  attrList.add(new Attribute("x-name", dir.ldapValue()));
    for(String opt: a.getOptions()) {
    putMember(out, key, a.getValue(), langTag, dir.ldapValueMatchingPattern());
    for (String v: attrList.get(0).getValues()) {
    jsonString = attrList.get(0).getValue();
String[] array = attrList.get(0).getValues();
Boolean bool = attrList.get(0).getValueAsBoolean();
putMember(out, key, attrList.get(0).getValueAsInteger(), null, dir.ldapValueMatchingPattern());
  String genTimeStr = attrList.get(0).getValue();
  Long timeStamp = StaticUtils.decodeGeneralizedTime(genTimeStr).getTime() / 1000;
  putMember(out, key, timeStamp, null, dir.ldapValueMatchingPattern());
  putMember(out, key, attrList.get(0).getValueAsLong(), null, dir.ldapValueMatchingPattern());
putMember(out, key, JSONValue.parse(attrList.get(0).getValue()), null, null);

代码示例来源:origin: com.unboundid/unboundid-ldapsdk-commercial-edition

attrList.add(new Attribute(attrName, attrValue));
 for (int i=0; i < attrList.size(); i++)
  valueArray[i] = attrList.get(i).getValueByteArray();
 oldAttributes.add(new Attribute(attrList.get(0).getName(), valueArray));

代码示例来源:origin: com.unboundid/unboundid-ldapsdk-commercial-edition

/**
 * {@inheritDoc}
 */
public Entry transformEntry(final Entry e)
{
 if (e == null)
 {
  return null;
 }
 // Iterate through the attributes in the entry and make any appropriate DN
 // replacements
 final Collection<Attribute> originalAttributes = e.getAttributes();
 final ArrayList<Attribute> newAttributes =
    new ArrayList<Attribute>(originalAttributes.size());
 for (final Attribute a : originalAttributes)
 {
  final String[] originalValues = a.getValues();
  final String[] newValues = new String[originalValues.length];
  for (int i=0; i < originalValues.length; i++)
  {
   newValues[i] = processString(originalValues[i]);
  }
  newAttributes.add(new Attribute(a.getName(), newValues));
 }
 return new Entry(processString(e.getDN()), newAttributes);
}

代码示例来源:origin: com.nimbusds/infinispan-cachestore-ldap

/**
 * Composes an LDAP modify request for the specified entry.
 *
 * @param entry The entry. Must not be {@code null}.
 *
 * @return The modify request.
 */
public ModifyRequest composeModifyRequest(final Entry entry) {
  List<Modification> mods = new LinkedList<>();
  // Compose list of attribute updates
  List<String> updatedAttributes = new LinkedList<>();
  for (com.unboundid.ldap.sdk.Attribute attr: entry.getAttributes()) {
    if (! getModifiableAttributes().contains(attr.getBaseName())) {
      continue; // skip, attribute not modifiable
    }
    // Flag attribute for replace, set new value(s)
    mods.add(new Modification(ModificationType.REPLACE, attr.getName(), attr.getValues()));
    updatedAttributes.add(attr.getBaseName()); // trim any lang-tags
  }
  // Compose list of attribute deletions
  for (String supAttr: getModifiableAttributes()) {
    if (! updatedAttributes.contains(supAttr)) {
      // Flag for delete via replace
      mods.add(new Modification(ModificationType.REPLACE, supAttr));
    }
  }
  return new ModifyRequest(entry.getDN(), mods);
}

代码示例来源:origin: com.gitblit.fathom/fathom-security-ldap

private void setAccountRoles(LDAPConnection ldapConnection, SearchResultEntry accountSearchResult, Account account) {
  String accountDN = accountSearchResult.getDN();
  String groupMemberPattern = this.groupMemberPattern.replace("${dn}", escapeLDAPSearchFilter(accountDN));
  groupMemberPattern = groupMemberPattern.replace("${username}", escapeLDAPSearchFilter(account.getUsername()));
  // Fill in attributes into groupMemberPattern
  for (Attribute attribute : accountSearchResult.getAttributes()) {
    groupMemberPattern = groupMemberPattern.replace("${" + attribute.getName() + "}", escapeLDAPSearchFilter(attribute.getValue()));
  }
  SearchResult groupsSearchResult = doSearch(ldapConnection, groupBase, true, groupMemberPattern, Arrays.asList("cn"));
  if (groupsSearchResult != null && groupsSearchResult.getEntryCount() > 0) {
    for (int i = 0; i < groupsSearchResult.getEntryCount(); i++) {
      SearchResultEntry groupEntry = groupsSearchResult.getSearchEntries().get(i);
      String roleName = groupEntry.getAttribute("cn").getValue();
      account.getAuthorizations().addRole(roleName);
    }
  }
}

代码示例来源:origin: com.gitblit.fathom/fathom-security-ldap

pattern = pattern.replace("${" + userAttribute.getName() + "}", userAttribute.getValue());
if (attribute != null && attribute.hasValue()) {
  account.setName(attribute.getValue());
  pattern = pattern.replace("${" + userAttribute.getName() + "}", userAttribute.getValue());
if (attribute != null && attribute.hasValue()) {
  account.addEmailAddress(attribute.getValue());

代码示例来源:origin: com.unboundid/unboundid-ldapsdk-commercial-edition

/**
 * Retrieves the set of parsed monitor attributes for this monitor entry,
 * mapped from a unique identifier (in all lowercase characters) to the
 * corresponding monitor attribute.
 *
 * @return  The set of parsed monitor attributes for this monitor entry.
 */
public Map<String,MonitorAttribute> getMonitorAttributes()
{
 // Retrieve a map of all attributes in the entry except cn and objectClass.
 final LinkedHashMap<String,MonitorAttribute> attrs =
    new LinkedHashMap<String,MonitorAttribute>();
 for (final Attribute a : entry.getAttributes())
 {
  final String lowerName = toLowerCase(a.getName());
  if (lowerName.equals("cn") || lowerName.equals("objectclass"))
  {
   continue;
  }
  attrs.put(lowerName,
     new MonitorAttribute(lowerName, a.getName(), "", a.getValues()));
 }
 return Collections.unmodifiableMap(attrs);
}

代码示例来源:origin: com.unboundid/unboundid-ldapsdk-commercial-edition

if ((changesAttr == null) || (! changesAttr.hasValue()))
final byte[] valueBytes = changesAttr.getValueByteArray();
if (valueBytes.length == 0)
if ((valueBytes.length > 0) && (valueBytes[valueBytes.length-1] == 0x00))
 final String fullValue = changesAttr.getValue();
 final String realValue = fullValue.substring(0, fullValue.length()-2);
 tokenizer = new StringTokenizer(realValue, "\r\n");
 tokenizer = new StringTokenizer(changesAttr.getValue(), "\r\n");

代码示例来源:origin: apiman/apiman

@Override
public String[] getValuesAsStringArray() {
  return attribute.getValues();
}

代码示例来源:origin: com.unboundid/unboundid-ldapsdk-minimal-edition

/**
 * Retrieves the base name for this attribute, which is the name or OID of the
 * attribute type, without any attribute options.  For an attribute without
 * any options, the value returned by this method will be identical the value
 * returned by the {@code getName} method.
 *
 * @return  The base name for this attribute.
 */
public String getBaseName()
{
 return getBaseName(name);
}

代码示例来源:origin: com.unboundid/unboundid-ldapsdk-commercial-edition

/**
 * Retrieves the name for this attribute.
 *
 * @return  The name for this attribute.
 */
public String getName()
{
 return attribute.getName();
}

代码示例来源:origin: com.unboundid/unboundid-ldapsdk-commercial-edition

final String lowerName = StaticUtils.toLowerCase(a.getName());
if (lowerName.startsWith("extended-op-") &&
  lowerName.endsWith("-total-count"))
 final long total = a.getValueAsLong();
 final long failed = entry.getLong(
    "extended-op-" + dashedOID + "-failed-count");

代码示例来源:origin: com.unboundid/unboundid-ldapsdk-commercial-edition

for (final Attribute a : attrList)
 final Set<String> attrOptions = a.getOptions();
 String attrName = null;
 for (final String s : attrOptions)
      a.getName());

代码示例来源:origin: com.unboundid/unboundid-ldapsdk-commercial-edition

rdnNameList.add(a.getName());
rdnValueList.add(a.getValueByteArray());
rdnNameList.add(a.getName());
rdnValueList.add(a.getValueByteArray());

相关文章