use of com.unboundid.ldap.sdk.Entry 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.Entry 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.Entry in project spring-security by spring-projects.
the class UnboundIdContainer method start.
@Override
public void start() {
if (isRunning()) {
return;
}
try {
InMemoryDirectoryServerConfig config = new InMemoryDirectoryServerConfig(this.defaultPartitionSuffix);
config.addAdditionalBindCredentials("uid=admin,ou=system", "secret");
config.setListenerConfigs(InMemoryListenerConfig.createLDAPConfig("LDAP", this.port));
config.setEnforceSingleStructuralObjectClass(false);
config.setEnforceAttributeSyntaxCompliance(true);
DN dn = new DN(this.defaultPartitionSuffix);
Entry entry = new Entry(dn);
entry.addAttribute("objectClass", "top", "domain", "extensibleObject");
entry.addAttribute("dc", dn.getRDN().getAttributeValues()[0]);
InMemoryDirectoryServer directoryServer = new InMemoryDirectoryServer(config);
directoryServer.add(entry);
importLdif(directoryServer);
directoryServer.startListening();
this.port = directoryServer.getListenPort();
this.directoryServer = directoryServer;
this.running = true;
} catch (LDAPException ex) {
throw new RuntimeException("Server startup failed", ex);
}
}
use of com.unboundid.ldap.sdk.Entry in project graylog2-server by Graylog2.
the class UnboundLDAPConnector method search.
public ImmutableList<LDAPEntry> search(LDAPConnection connection, String searchBase, Filter filter, String uniqueIdAttribute, Set<String> attributes) throws LDAPException {
final ImmutableSet<String> allAttributes = ImmutableSet.<String>builder().add(OBJECT_CLASS_ATTRIBUTE).addAll(attributes).build();
// TODO: Use LDAPEntrySource for a more memory efficient search
final SearchRequest searchRequest = new SearchRequest(searchBase, SearchScope.SUB, filter, allAttributes.toArray(new String[0]));
searchRequest.setTimeLimitSeconds(requestTimeoutSeconds);
if (LOG.isTraceEnabled()) {
LOG.trace("Search LDAP for <{}> using search base <{}>", filter.toNormalizedString(), searchBase);
}
final SearchResult searchResult = connection.search(searchRequest);
if (searchResult.getSearchEntries().isEmpty()) {
LOG.trace("No LDAP entry found for filter <{}>", filter.toNormalizedString());
return ImmutableList.of();
}
return searchResult.getSearchEntries().stream().map(entry -> createLDAPEntry(entry, uniqueIdAttribute)).collect(ImmutableList.toImmutableList());
}
Aggregations