use of javax.naming.directory.BasicAttribute in project JGroups by belaban.
the class MockDirContext method addEntry.
public MockDirContext addEntry(String dnsQuery, String dnsResponse, DNSResolver.DNSRecordType recordType) {
Attributes attributes = responseMap.computeIfAbsent(new DNSKey(dnsQuery, recordType), v -> new BasicAttributes());
Attribute attribute = attributes.get(recordType.toString());
if (attribute == null) {
attributes.put(new BasicAttribute(recordType.toString(), dnsResponse));
} else {
attribute.add(dnsResponse);
}
return this;
}
use of javax.naming.directory.BasicAttribute in project Lucee by lucee.
the class LDAPClient method toAttributes.
private static Attributes toAttributes(String strAttributes, String delimiter, String separator) throws PageException {
String[] arrAttr = toStringAttributes(strAttributes, delimiter);
BasicAttributes attributes = new BasicAttributes();
for (int i = 0; i < arrAttr.length; i++) {
String strAttr = arrAttr[i];
// Type
int eqIndex = strAttr.indexOf('=');
Attribute attr = new BasicAttribute((eqIndex != -1) ? strAttr.substring(0, eqIndex).trim() : null);
// Value
String strValue = (eqIndex != -1) ? strAttr.substring(eqIndex + 1) : strAttr;
String[] arrValue = ListUtil.toStringArray(ListUtil.listToArrayRemoveEmpty(strValue, separator));
// Fill
for (int y = 0; y < arrValue.length; y++) {
attr.add(arrValue[y]);
}
attributes.put(attr);
}
return attributes;
}
use of javax.naming.directory.BasicAttribute in project Lucee by lucee.
the class LDAPClient method modify.
public void modify(String dn, int modifytype, String strAttributes, String delimiter, String separator) throws NamingException, PageException {
DirContext context = new InitialDirContext(env);
String[] strArrAttributes = toStringAttributes(strAttributes, delimiter);
int count = 0;
for (int i = 0; i < strArrAttributes.length; i++) {
String[] attributesValues = getAttributesValues(strArrAttributes[i], separator);
if (attributesValues == null)
count++;
else
count += attributesValues.length;
}
ModificationItem[] modItems = new ModificationItem[count];
BasicAttribute basicAttr = null;
int k = 0;
for (int i = 0; i < strArrAttributes.length; i++) {
String attribute = strArrAttributes[i];
String type = getAttrValueType(attribute);
String[] values = getAttributesValues(attribute, separator);
if (modifytype == DirContext.REPLACE_ATTRIBUTE) {
if (values == null)
basicAttr = new BasicAttribute(type);
else
basicAttr = new BasicAttribute(type, values[0]);
modItems[k] = new ModificationItem(modifytype, basicAttr);
k++;
if (values != null && values.length > 1) {
for (int j = 1; j < values.length; j++) {
basicAttr = new BasicAttribute(type, values[j]);
modItems[k] = new ModificationItem(DirContext.ADD_ATTRIBUTE, basicAttr);
k++;
}
}
} else {
for (int j = 0; j < values.length; j++) {
if (type != null || modifytype == DirContext.ADD_ATTRIBUTE)
basicAttr = new BasicAttribute(type, values[j]);
else
basicAttr = new BasicAttribute(values[j]);
modItems[k] = new ModificationItem(modifytype, basicAttr);
k++;
}
}
}
context.modifyAttributes(dn, modItems);
context.close();
}
use of javax.naming.directory.BasicAttribute in project cxf by apache.
the class LdapCertificateRepo method saveCertificate.
private void saveCertificate(X509Certificate cert, String dn, Map<String, String> appAttrs) {
Attributes attribs = new BasicAttributes();
attribs.put(new BasicAttribute(ATTR_OBJECT_CLASS, ldapConfig.getCertObjectClass()));
attribs.put(new BasicAttribute(ldapConfig.getAttrUID(), cert.getSubjectX500Principal().getName()));
attribs.put(new BasicAttribute(ldapConfig.getAttrIssuerID(), cert.getIssuerX500Principal().getName()));
attribs.put(new BasicAttribute(ldapConfig.getAttrSerialNumber(), cert.getSerialNumber().toString(16)));
addConstantAttributes(ldapConfig.getConstAttrNamesCSV(), ldapConfig.getConstAttrValuesCSV(), attribs);
if (appAttrs != null && !appAttrs.isEmpty()) {
for (Map.Entry<String, String> entry : appAttrs.entrySet()) {
attribs.put(new BasicAttribute(entry.getKey(), entry.getValue()));
}
}
try {
attribs.put(new BasicAttribute(ldapConfig.getAttrCrtBinary(), cert.getEncoded()));
ldapSearch.bind(dn, attribs);
} catch (Exception e) {
throw new RuntimeException(e.getMessage(), e);
}
}
use of javax.naming.directory.BasicAttribute in project Payara by payara.
the class ResourceAttributes method getAll.
/**
* Get all attributes.
*/
public NamingEnumeration<? extends Attribute> getAll() {
if (attributes == null) {
Vector<BasicAttribute> attributes = new Vector<BasicAttribute>();
Date creationDate = getCreationDate();
if (creationDate != null) {
attributes.addElement(new BasicAttribute(CREATION_DATE, creationDate));
attributes.addElement(new BasicAttribute(ALTERNATE_CREATION_DATE, creationDate));
}
Date lastModifiedDate = getLastModifiedDate();
if (lastModifiedDate != null) {
attributes.addElement(new BasicAttribute(LAST_MODIFIED, lastModifiedDate));
attributes.addElement(new BasicAttribute(ALTERNATE_LAST_MODIFIED, lastModifiedDate));
}
String name = getName();
if (name != null) {
attributes.addElement(new BasicAttribute(NAME, name));
}
String resourceType = getResourceType();
if (resourceType != null) {
attributes.addElement(new BasicAttribute(TYPE, resourceType));
attributes.addElement(new BasicAttribute(ALTERNATE_TYPE, resourceType));
}
long contentLength = getContentLength();
if (contentLength >= 0) {
Long contentLengthLong = Long.valueOf(contentLength);
attributes.addElement(new BasicAttribute(CONTENT_LENGTH, contentLengthLong));
attributes.addElement(new BasicAttribute(ALTERNATE_CONTENT_LENGTH, contentLengthLong));
}
String etag = getETag();
if (etag != null) {
attributes.addElement(new BasicAttribute(ETAG, etag));
attributes.addElement(new BasicAttribute(ALTERNATE_ETAG, etag));
}
return new RecyclableNamingEnumeration<BasicAttribute>(attributes);
} else {
return attributes.getAll();
}
}
Aggregations