use of javax.naming.directory.BasicAttributes in project jdk8u_jdk by JetBrains.
the class LdapResult method compareToSearchResult.
// This function turns an LdapResult that came from a compare operation
// into one that looks like it came from a search operation. This is
// useful when the caller asked the context to do a search, but it was
// carried out as a compare. In this case, the client still expects a
// result that looks like it came from a search.
boolean compareToSearchResult(String name) {
boolean successful = false;
switch(status) {
case LdapClient.LDAP_COMPARE_TRUE:
status = LdapClient.LDAP_SUCCESS;
entries = new Vector<>(1, 1);
Attributes attrs = new BasicAttributes(LdapClient.caseIgnore);
LdapEntry entry = new LdapEntry(name, attrs);
entries.addElement(entry);
successful = true;
break;
case LdapClient.LDAP_COMPARE_FALSE:
status = LdapClient.LDAP_SUCCESS;
entries = new Vector<>(0);
successful = true;
break;
default:
successful = false;
break;
}
return successful;
}
use of javax.naming.directory.BasicAttributes in project fess by codelibs.
the class LdapManager method addUserAttributes.
protected void addUserAttributes(final BasicAttributes entry, final User user, final FessConfig fessConfig) {
entry.put(new BasicAttribute("cn", user.getName()));
entry.put(new BasicAttribute("userPassword", user.getOriginalPassword()));
OptionalUtil.ofNullable(user.getSurname()).filter(StringUtil::isNotBlank).ifPresent(s -> entry.put(new BasicAttribute(fessConfig.getLdapAttrSurname(), s)));
OptionalUtil.ofNullable(user.getGivenName()).filter(StringUtil::isNotBlank).ifPresent(s -> entry.put(new BasicAttribute(fessConfig.getLdapAttrGivenName(), s)));
OptionalUtil.ofNullable(user.getMail()).filter(StringUtil::isNotBlank).ifPresent(s -> entry.put(new BasicAttribute(fessConfig.getLdapAttrMail(), s)));
OptionalUtil.ofNullable(user.getEmployeeNumber()).filter(StringUtil::isNotBlank).ifPresent(s -> entry.put(new BasicAttribute(fessConfig.getLdapAttrEmployeeNumber(), s)));
OptionalUtil.ofNullable(user.getTelephoneNumber()).filter(StringUtil::isNotBlank).ifPresent(s -> entry.put(new BasicAttribute(fessConfig.getLdapAttrTelephoneNumber(), s)));
OptionalUtil.ofNullable(user.getHomePhone()).filter(StringUtil::isNotBlank).ifPresent(s -> entry.put(new BasicAttribute(fessConfig.getLdapAttrHomePhone(), s)));
OptionalUtil.ofNullable(user.getHomePostalAddress()).filter(StringUtil::isNotBlank).ifPresent(s -> entry.put(new BasicAttribute(fessConfig.getLdapAttrHomePostalAddress(), s)));
OptionalUtil.ofNullable(user.getLabeledURI()).filter(StringUtil::isNotBlank).ifPresent(s -> entry.put(new BasicAttribute(fessConfig.getLdapAttrLabeleduri(), s)));
OptionalUtil.ofNullable(user.getRoomNumber()).filter(StringUtil::isNotBlank).ifPresent(s -> entry.put(new BasicAttribute(fessConfig.getLdapAttrRoomNumber(), s)));
OptionalUtil.ofNullable(user.getDescription()).filter(StringUtil::isNotBlank).ifPresent(s -> entry.put(new BasicAttribute(fessConfig.getLdapAttrDescription(), s)));
OptionalUtil.ofNullable(user.getTitle()).filter(StringUtil::isNotBlank).ifPresent(s -> entry.put(new BasicAttribute(fessConfig.getLdapAttrTitle(), s)));
OptionalUtil.ofNullable(user.getPager()).filter(StringUtil::isNotBlank).ifPresent(s -> entry.put(new BasicAttribute(fessConfig.getLdapAttrPager(), s)));
OptionalUtil.ofNullable(user.getStreet()).filter(StringUtil::isNotBlank).ifPresent(s -> entry.put(new BasicAttribute(fessConfig.getLdapAttrStreet(), s)));
OptionalUtil.ofNullable(user.getPostalCode()).filter(StringUtil::isNotBlank).ifPresent(s -> entry.put(new BasicAttribute(fessConfig.getLdapAttrPostalCode(), s)));
OptionalUtil.ofNullable(user.getPhysicalDeliveryOfficeName()).filter(StringUtil::isNotBlank).ifPresent(s -> entry.put(new BasicAttribute(fessConfig.getLdapAttrPhysicalDeliveryOfficeName(), s)));
OptionalUtil.ofNullable(user.getDestinationIndicator()).filter(StringUtil::isNotBlank).ifPresent(s -> entry.put(new BasicAttribute(fessConfig.getLdapAttrDestinationIndicator(), s)));
OptionalUtil.ofNullable(user.getInternationaliSDNNumber()).filter(StringUtil::isNotBlank).ifPresent(s -> entry.put(new BasicAttribute(fessConfig.getLdapAttrInternationalisdnNumber(), s)));
OptionalUtil.ofNullable(user.getState()).filter(StringUtil::isNotBlank).ifPresent(s -> entry.put(new BasicAttribute(fessConfig.getLdapAttrState(), s)));
OptionalUtil.ofNullable(user.getEmployeeType()).filter(StringUtil::isNotBlank).ifPresent(s -> entry.put(new BasicAttribute(fessConfig.getLdapAttrEmployeeType(), s)));
OptionalUtil.ofNullable(user.getFacsimileTelephoneNumber()).filter(StringUtil::isNotBlank).ifPresent(s -> entry.put(new BasicAttribute(fessConfig.getLdapAttrFacsimileTelephoneNumber(), s)));
OptionalUtil.ofNullable(user.getPostOfficeBox()).filter(StringUtil::isNotBlank).ifPresent(s -> entry.put(new BasicAttribute(fessConfig.getLdapAttrPostOfficeBox(), s)));
OptionalUtil.ofNullable(user.getInitials()).filter(StringUtil::isNotBlank).ifPresent(s -> entry.put(new BasicAttribute(fessConfig.getLdapAttrInitials(), s)));
OptionalUtil.ofNullable(user.getCarLicense()).filter(StringUtil::isNotBlank).ifPresent(s -> entry.put(new BasicAttribute(fessConfig.getLdapAttrCarLicense(), s)));
OptionalUtil.ofNullable(user.getMobile()).filter(StringUtil::isNotBlank).ifPresent(s -> entry.put(new BasicAttribute(fessConfig.getLdapAttrMobile(), s)));
OptionalUtil.ofNullable(user.getPostalAddress()).filter(StringUtil::isNotBlank).ifPresent(s -> entry.put(new BasicAttribute(fessConfig.getLdapAttrPostalAddress(), s)));
OptionalUtil.ofNullable(user.getCity()).filter(StringUtil::isNotBlank).ifPresent(s -> entry.put(new BasicAttribute(fessConfig.getLdapAttrCity(), s)));
OptionalUtil.ofNullable(user.getTeletexTerminalIdentifier()).filter(StringUtil::isNotBlank).ifPresent(s -> entry.put(new BasicAttribute(fessConfig.getLdapAttrTeletexTerminalIdentifier(), s)));
OptionalUtil.ofNullable(user.getX121Address()).filter(StringUtil::isNotBlank).ifPresent(s -> entry.put(new BasicAttribute(fessConfig.getLdapAttrX121Address(), s)));
OptionalUtil.ofNullable(user.getBusinessCategory()).filter(StringUtil::isNotBlank).ifPresent(s -> entry.put(new BasicAttribute(fessConfig.getLdapAttrBusinessCategory(), s)));
OptionalUtil.ofNullable(user.getRegisteredAddress()).filter(StringUtil::isNotBlank).ifPresent(s -> entry.put(new BasicAttribute(fessConfig.getLdapAttrRegisteredAddress(), s)));
OptionalUtil.ofNullable(user.getDisplayName()).filter(StringUtil::isNotBlank).ifPresent(s -> entry.put(new BasicAttribute(fessConfig.getLdapAttrDisplayName(), s)));
OptionalUtil.ofNullable(user.getPreferredLanguage()).filter(StringUtil::isNotBlank).ifPresent(s -> entry.put(new BasicAttribute(fessConfig.getLdapAttrPreferredLanguage(), s)));
OptionalUtil.ofNullable(user.getDepartmentNumber()).filter(StringUtil::isNotBlank).ifPresent(s -> entry.put(new BasicAttribute(fessConfig.getLdapAttrDepartmentNumber(), s)));
OptionalUtil.ofNullable(user.getUidNumber()).filter(s -> StringUtil.isNotBlank(s.toString())).ifPresent(s -> entry.put(new BasicAttribute(fessConfig.getLdapAttrUidNumber(), s)));
OptionalUtil.ofNullable(user.getGidNumber()).filter(s -> StringUtil.isNotBlank(s.toString())).ifPresent(s -> entry.put(new BasicAttribute(fessConfig.getLdapAttrGidNumber(), s)));
OptionalUtil.ofNullable(user.getHomeDirectory()).filter(StringUtil::isNotBlank).ifPresent(s -> entry.put(new BasicAttribute(fessConfig.getLdapAttrHomeDirectory(), s)));
}
use of javax.naming.directory.BasicAttributes 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.BasicAttributes 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.BasicAttributes in project iaf by ibissource.
the class LdapSender method performOperationDelete.
private String performOperationDelete(String entryName, ParameterResolutionContext prc, Map paramValueMap, Attributes attrs) throws SenderException, ParameterException {
if (manipulationSubject.equals(MANIPULATION_ATTRIBUTE)) {
String result = null;
NamingEnumeration na = attrs.getAll();
while (na.hasMoreElements()) {
Attribute a = (Attribute) na.nextElement();
log.debug("Delete attribute: " + a.getID());
NamingEnumeration values;
try {
values = a.getAll();
} catch (NamingException e1) {
storeLdapException(e1, prc);
throw new SenderException("cannot obtain values of Attribute [" + a.getID() + "]", e1);
}
while (values.hasMoreElements()) {
Attributes partialAttrs = new BasicAttributes();
Attribute singleValuedAttribute;
String id = a.getID();
Object value = values.nextElement();
if (log.isDebugEnabled()) {
if (id.toLowerCase().contains("password") || id.toLowerCase().contains("pwd")) {
log.debug("Delete value: ***");
} else {
log.debug("Delete value: " + value);
}
}
if (unicodePwd && "unicodePwd".equalsIgnoreCase(id)) {
singleValuedAttribute = new BasicAttribute(id, encodeUnicodePwd(value));
} else {
singleValuedAttribute = new BasicAttribute(id, value);
}
partialAttrs.put(singleValuedAttribute);
DirContext dirContext = null;
try {
dirContext = getDirContext(paramValueMap);
dirContext.modifyAttributes(entryName, DirContext.REMOVE_ATTRIBUTE, partialAttrs);
} catch (NamingException e) {
// [LDAP: error code 16 - 00002085: AtrErr: DSID-03151F03, #1...
if (e.getMessage().startsWith("[LDAP: error code 16 - ") || e.getMessage().startsWith("[LDAP: error code 32 - ")) {
if (log.isDebugEnabled())
log.debug("Operation [" + getOperation() + "] successful: " + e.getMessage());
result = DEFAULT_RESULT_DELETE;
} else {
storeLdapException(e, prc);
throw new SenderException("Exception in operation [" + getOperation() + "] entryName [" + entryName + "]", e);
}
} finally {
closeDirContext(dirContext);
}
}
}
if (result != null) {
return result;
}
return DEFAULT_RESULT;
} else {
DirContext dirContext = null;
try {
dirContext = getDirContext(paramValueMap);
dirContext.unbind(entryName);
return DEFAULT_RESULT;
} catch (NamingException e) {
// [LDAP: error code 32 - No Such Object...
if (e.getMessage().startsWith("[LDAP: error code 32 - ")) {
if (log.isDebugEnabled())
log.debug("Operation [" + getOperation() + "] successful: " + e.getMessage());
return DEFAULT_RESULT_DELETE;
} else {
storeLdapException(e, prc);
throw new SenderException("Exception in operation [" + getOperation() + "] entryName [" + entryName + "]", e);
}
} finally {
closeDirContext(dirContext);
}
}
}
Aggregations