use of com.unboundid.ldap.sdk.Attribute in project gocd by gocd.
the class InMemoryLdapServerForTests method addOrganizationalUnit.
public LDIFRecord addOrganizationalUnit(String nameOfOU, String dnOfOU) throws LDAPException {
LDIFAddChangeRecord record = new LDIFAddChangeRecord(dnOfOU, new Attribute("objectClass", "top", "organizationalUnit"), new Attribute("ou", nameOfOU));
record.processChange(server);
return record;
}
use of com.unboundid.ldap.sdk.Attribute in project oxCore by GluuFederation.
the class LdapEntryManager method persist.
@Override
protected void persist(String dn, List<AttributeData> attributes) {
List<Attribute> ldapAttributes = new ArrayList<Attribute>(attributes.size());
for (AttributeData attribute : attributes) {
String attributeName = attribute.getName();
String[] attributeValues = attribute.getValues();
if (ArrayHelper.isNotEmpty(attributeValues) && StringHelper.isNotEmpty(attributeValues[0])) {
if (ldapOperationService.isCertificateAttribute(attributeName)) {
byte[][] binaryValues = toBinaryValues(attributeValues);
ldapAttributes.add(new Attribute(attributeName + ";binary", binaryValues));
} else {
ldapAttributes.add(new Attribute(attributeName, attributeValues));
}
}
}
// Persist entry
try {
boolean result = this.ldapOperationService.addEntry(dn, ldapAttributes);
if (!result) {
throw new EntryPersistenceException(String.format("Failed to persist entry: %s", dn));
}
} catch (ConnectionException ex) {
throw new EntryPersistenceException(String.format("Failed to persist entry: %s", dn), ex.getCause());
} catch (Exception ex) {
throw new EntryPersistenceException(String.format("Failed to persist entry: %s", dn), ex);
}
}
use of com.unboundid.ldap.sdk.Attribute in project oxCore by GluuFederation.
the class LdapEntryManager method getAttributeDataList.
private List<AttributeData> getAttributeDataList(SearchResultEntry entry) {
if (entry == null) {
return null;
}
List<AttributeData> result = new ArrayList<AttributeData>();
for (Attribute attribute : entry.getAttributes()) {
String[] attributeValueStrings = NO_STRINGS;
String attributeName = attribute.getName();
if (LOG.isTraceEnabled()) {
if (attribute.needsBase64Encoding()) {
LOG.trace("Found binary attribute: " + attributeName + ". Is defined in LDAP config: " + ldapOperationService.isBinaryAttribute(attributeName));
}
}
attributeValueStrings = attribute.getValues();
if (attribute.needsBase64Encoding()) {
boolean binaryAttribute = ldapOperationService.isBinaryAttribute(attributeName);
boolean certificateAttribute = ldapOperationService.isCertificateAttribute(attributeName);
if (binaryAttribute || certificateAttribute) {
byte[][] attributeValues = attribute.getValueByteArrays();
if (attributeValues != null) {
attributeValueStrings = new String[attributeValues.length];
for (int i = 0; i < attributeValues.length; i++) {
attributeValueStrings[i] = Base64.encodeBase64String(attributeValues[i]);
LOG.trace("Binary attribute: " + attribute.getName() + " value (hex): " + org.apache.commons.codec.binary.Hex.encodeHexString(attributeValues[i]) + " value (base64): " + attributeValueStrings[i]);
}
}
}
if (certificateAttribute) {
attributeName = ldapOperationService.getCertificateAttributeName(attributeName);
}
}
AttributeData tmpAttribute = new AttributeData(attributeName, attributeValueStrings);
result.add(tmpAttribute);
}
return result;
}
use of com.unboundid.ldap.sdk.Attribute in project cas by apereo.
the class LdapTestUtils method createLdapEntries.
/**
* Creates the given LDAP entries.
*
* @param connection Open LDAP connection used to connect to directory.
* @param entries Collection of LDAP entries.
*/
public static void createLdapEntries(final LDAPConnection connection, final Collection<LdapEntry> entries) {
try {
for (final LdapEntry entry : entries) {
final Collection<Attribute> attrs = new ArrayList<>(entry.getAttributeNames().length);
attrs.addAll(entry.getAttributes().stream().map(a -> new Attribute(a.getName(), a.getStringValues())).collect(Collectors.toList()));
final AddRequest ad = new AddRequest(entry.getDn(), attrs);
connection.add(ad);
}
} catch (final Exception e) {
LOGGER.error(e.getLocalizedMessage());
}
}
use of com.unboundid.ldap.sdk.Attribute in project vertx-auth by vert-x3.
the class LDAPShiroAuthProviderTest method insertTestUsers.
/*
* insert test users (only one currently), if we need more users, it would be
* better to use a ldif file
*/
private void insertTestUsers() throws LDAPException {
LDAPConnection connection = null;
try {
connection = new LDAPConnection("localhost", 10389);
// entry tim/sausages
List<Attribute> addRequest = new ArrayList<>();
addRequest.add(new Attribute("objectClass", "top"));
addRequest.add(new Attribute("objectClass", "person"));
addRequest.add(new Attribute("objectClass", "organizationalPerson"));
addRequest.add(new Attribute("objectClass", "inetOrgPerson"));
addRequest.add(new Attribute("cn", "Tim Fox"));
addRequest.add(new Attribute("sn", "Fox"));
addRequest.add(new Attribute("mail", "tim@example.com"));
addRequest.add(new Attribute("uid", "tim"));
addRequest.add(new Attribute("userPassword", "{ssha}d0M5Z2qjOOCSCQInvZHgVAleCqU5I+ag9ZHXMw=="));
connection.add("uid=tim,ou=users,dc=foo,dc=com", addRequest);
} finally {
if (connection != null) {
connection.close();
}
}
}
Aggregations