use of com.unboundid.ldap.sdk.Attribute in project gocd by gocd.
the class InMemoryLdapServerForTests method startServer.
private InMemoryDirectoryServer startServer(int port, String baseDn, String bindDn, String bindPassword) throws LDAPException, BindException {
InMemoryListenerConfig listenerConfig = InMemoryListenerConfig.createLDAPConfig("default", port);
InMemoryDirectoryServerConfig serverConfig = new InMemoryDirectoryServerConfig(new DN(baseDn));
/* Ignore schema so that it does not complain that some attributes (like sAMAccountName) are not valid. */
serverConfig.setSchema(null);
serverConfig.setListenerConfigs(listenerConfig);
serverConfig.addAdditionalBindCredentials(bindDn, bindPassword);
InMemoryDirectoryServer server = new InMemoryDirectoryServer(serverConfig);
try {
server.startListening();
} catch (LDAPException e) {
throw new RuntimeException(e);
}
new LDIFAddChangeRecord(baseDn, new Attribute("objectClass", "domain", "top")).processChange(server);
return server;
}
use of com.unboundid.ldap.sdk.Attribute in project oxCore by GluuFederation.
the class LdapOperationsServiceImpl method populateAttributeDataTypesMapping.
private void populateAttributeDataTypesMapping(String schemaEntryDn) {
try {
if (ATTRIBUTE_DATA_TYPES.size() == 0) {
// schemaEntryDn="ou=schema";
SearchResultEntry entry = lookup(schemaEntryDn, "attributeTypes");
Attribute attrAttributeTypes = entry.getAttribute("attributeTypes");
Map<String, Pair<String, String>> tmpMap = new HashMap<String, Pair<String, String>>();
for (String strAttributeType : attrAttributeTypes.getValues()) {
AttributeTypeDefinition attrTypeDef = new AttributeTypeDefinition(strAttributeType);
String[] names = attrTypeDef.getNames();
if (names != null) {
for (String name : names) {
tmpMap.put(name, new Pair<String, String>(attrTypeDef.getBaseSyntaxOID(), attrTypeDef.getSuperiorType()));
}
}
}
// Fill missing values
for (String name : tmpMap.keySet()) {
Pair<String, String> currPair = tmpMap.get(name);
String sup = currPair.getSecond();
if (currPair.getFirst() == null && sup != null) {
// No OID syntax?
// Try to lookup superior type
Pair<String, String> pair = tmpMap.get(sup);
if (pair != null) {
currPair.setFirst(pair.getFirst());
}
}
}
// Populate map of attribute names vs. Java classes
for (String name : tmpMap.keySet()) {
String syntaxOID = tmpMap.get(name).getFirst();
if (syntaxOID != null) {
Class<?> cls = OID_SYNTAX_CLASS_MAPPING.get(syntaxOID);
if (cls != null) {
ATTRIBUTE_DATA_TYPES.put(name, cls);
}
}
}
}
} catch (Exception e) {
LOG.error(e.getMessage(), e);
}
}
use of com.unboundid.ldap.sdk.Attribute in project oxTrust by GluuFederation.
the class LdifService method performImport.
@SuppressWarnings("resource")
public void performImport(Class entryClass, InputStream inputStream) {
final ArrayList<Entry> entryList = new ArrayList<Entry>();
final LDIFReader reader = new LDIFReader(inputStream);
while (true) {
try {
final Entry entry = reader.readEntry();
if (entry == null) {
break;
} else {
entryList.add(entry);
}
} catch (final Exception e) {
log.error("", e);
}
}
entryList.stream().forEach(e -> {
Collection<Attribute> attributes = e.getAttributes();
List<Attribute> values = new ArrayList<>();
values.addAll(attributes);
ArrayList<AttributeData> datas = new ArrayList<>();
values.stream().forEach(value -> {
datas.add(new AttributeData(value.getName(), value.getValues(), (value.getValues().length > 1) ? true : false));
});
try {
persistenceManager.importEntry(e.getDN(), entryClass, datas);
} catch (Exception ex) {
log.info("=========", ex);
}
});
}
use of com.unboundid.ldap.sdk.Attribute in project zm-mailbox by Zimbra.
the class UBIDUserCertificateAttributeTest method getMultiAttrStringShouldReturnCertificateForAttributeNameWithBinary.
@Test
public void getMultiAttrStringShouldReturnCertificateForAttributeNameWithBinary() {
Attribute attr = new Attribute(lookupAttr, certBase64);
Entry entry = PowerMockito.mock(Entry.class);
UBIDAttributes attributes = new UBIDAttributes(entry);
// entry does not contain "userCertificate" attribute
Mockito.when(entry.getAttribute(ContactConstants.A_userCertificate)).thenReturn(null);
// entry contains "userCertificate;binary" attribute
Mockito.when(entry.getAttribute(lookupAttr)).thenReturn(attr);
try {
assertEquals(attributes.getMultiAttrString(lookupAttr, false)[0], certBase64);
} catch (com.zimbra.cs.ldap.LdapException e) {
fail("Exception thrown");
}
}
use of com.unboundid.ldap.sdk.Attribute in project zm-mailbox by Zimbra.
the class UBIDMutableEntry method mapToAttrs.
// ZMutableEntry
@Override
public void mapToAttrs(Map<String, Object> mapAttrs) {
AttributeManager attrMgr = AttributeManager.getInst();
for (Map.Entry<String, Object> me : mapAttrs.entrySet()) {
String attrName = me.getKey();
Object v = me.getValue();
boolean containsBinaryData = attrMgr == null ? false : attrMgr.containsBinaryData(attrName);
boolean isBinaryTransfer = attrMgr == null ? false : attrMgr.isBinaryTransfer(attrName);
if (v instanceof String) {
ASN1OctetString value = UBIDUtil.newASN1OctetString(containsBinaryData, (String) v);
Attribute a = UBIDUtil.newAttribute(isBinaryTransfer, attrName, value);
entry.addAttribute(a);
} else if (v instanceof String[]) {
String[] sa = (String[]) v;
ASN1OctetString[] values = new ASN1OctetString[sa.length];
for (int i = 0; i < sa.length; i++) {
values[i] = UBIDUtil.newASN1OctetString(containsBinaryData, sa[i]);
}
Attribute a = UBIDUtil.newAttribute(isBinaryTransfer, attrName, values);
entry.addAttribute(a);
} else if (v instanceof Collection) {
Collection c = (Collection) v;
ASN1OctetString[] values = new ASN1OctetString[c.size()];
int i = 0;
for (Object o : c) {
values[i] = UBIDUtil.newASN1OctetString(containsBinaryData, o.toString());
i++;
}
Attribute a = UBIDUtil.newAttribute(isBinaryTransfer, attrName, values);
entry.addAttribute(a);
}
}
}
Aggregations